Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// the total number of bytes in our batch
// let numVerts = this.size * 4 * this.vertByteSize;
this.buffers = [];
for (let i = 1; i <= bitTwiddle.nextPow2(this.size); i *= 2)
{
this.buffers.push(new BatchBuffer(i * 4 * this.vertByteSize));
}
/**
* Holds the indices of the geometry (quads) to draw
*
* @member {Uint16Array}
*/
this.indices = createIndicesForQuads(this.size);
this.indexBuffer = new Buffer(this.indices, true, true);
/**
* The default shaders that is used if a sprite doesn't have a more specific one.
* there is a shader for each number of textures that can be rendered.
* These shaders will also be generated on the fly as required.
* @member {PIXI.Shader[]}
*/
this.shader = null;
this.currentIndex = 0;
this.groups = [];
for (let k = 0; k < this.size; k++)
{
this.groups[k] = { textures: [], textureCount: 0, ids: [], size: 0, start: 0, blend: 0 };
}
{
// step 1: first check max textures the GPU can handle.
this.MAX_TEXTURES = Math.min(gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS), settings.SPRITE_MAX_TEXTURES);
// step 2: check the maximum number of if statements the shader can have too..
this.MAX_TEXTURES = checkMaxIfStatementsInShader(this.MAX_TEXTURES, gl);
}
// generate generateMultiTextureProgram, may be a better move?
this.shader = generateMultiTextureShader(gl, this.MAX_TEXTURES);
// we use the second shader as the first one depending on your browser may omit aTextureId
// as it is not used by the shader so is optimized out.
for (let i = 0; i < this.vaoMax; i++)
{
const buffer = new Buffer(null, false);
/* eslint-disable max-len */
this.vaos[i] = new Geometry()
.addAttribute('aVertexPosition', buffer, 2, false, gl.FLOAT)
.addAttribute('aTextureCoord', buffer, 2, true, gl.UNSIGNED_SHORT)
.addAttribute('aColor', buffer, 4, true, gl.UNSIGNED_BYTE)
.addAttribute('aTextureId', buffer, 1, true, gl.FLOAT)
.addIndex(this.indexBuffer);
/* eslint-enable max-len */
this.vertexBuffers[i] = buffer;
}
}
this.dynamicStride = 0;
for (let i = 0; i < this.dynamicProperties.length; ++i)
{
const property = this.dynamicProperties[i];
property.offset = dynamicOffset;
dynamicOffset += property.size;
this.dynamicStride += property.size;
}
const dynBuffer = new ArrayBuffer(this.size * this.dynamicStride * 4 * 4);
this.dynamicData = new Float32Array(dynBuffer);
this.dynamicDataUint32 = new Uint32Array(dynBuffer);
this.dynamicBuffer = new Buffer(this.dynamicData, false, false);
// static //
let staticOffset = 0;
this.staticStride = 0;
for (let i = 0; i < this.staticProperties.length; ++i)
{
const property = this.staticProperties[i];
property.offset = staticOffset;
staticOffset += property.size;
this.staticStride += property.size;
}
const statBuffer = new ArrayBuffer(this.size * this.staticStride * 4 * 4);
/* eslint-enable max-len */
index += 20;
}
currentGroup.size = i - currentGroup.start;
if (!settings.CAN_UPLOAD_SAME_BUFFER)
{
// this is still needed for IOS performance..
// it really does not like uploading to the same buffer in a single frame!
if (this.vaoMax <= this.vertexCount)
{
this.vaoMax++;
const buffer = new Buffer(null, false);
/* eslint-disable max-len */
this.vaos[this.vertexCount] = new Geometry()
.addAttribute('aVertexPosition', buffer, 2, false, gl.FLOAT)
.addAttribute('aTextureCoord', buffer, 2, true, gl.UNSIGNED_SHORT)
.addAttribute('aColor', buffer, 4, true, gl.UNSIGNED_BYTE)
.addAttribute('aTextureId', buffer, 1, true, gl.FLOAT)
.addIndex(this.indexBuffer);
/* eslint-enable max-len */
this.vertexBuffers[this.vertexCount] = buffer;
}
this.vertexBuffers[this.vertexCount].update(buffer.vertices, 0);
this.renderer.geometry.bind(this.vaos[this.vertexCount]);
/**
* The indices of the vertices
* @member {number[]}
*/
this.indices = [];
/**
* The main buffer
* @member {WebGLBuffer}
*/
this.buffer = new Buffer();
/**
* The index buffer
* @member {WebGLBuffer}
*/
this.indexBuffer = new Buffer();
/**
* Whether this graphics is dirty or not
* @member {boolean}
*/
this.dirty = true;
/**
* Whether this graphics is nativeLines or not
* @member {boolean}
*/
this.nativeLines = false;
this.glPoints = null;
this.glIndices = null;
this.staticStride = 0;
for (let i = 0; i < this.staticProperties.length; ++i)
{
const property = this.staticProperties[i];
property.offset = staticOffset;
staticOffset += property.size;
this.staticStride += property.size;
}
const statBuffer = new ArrayBuffer(this.size * this.staticStride * 4 * 4);
this.staticData = new Float32Array(statBuffer);
this.staticDataUint32 = new Uint32Array(statBuffer);
this.staticBuffer = new Buffer(this.staticData, true, false);
for (let i = 0; i < this.dynamicProperties.length; ++i)
{
const property = this.dynamicProperties[i];
geometry.addAttribute(
property.attributeName,
this.dynamicBuffer,
0,
property.type === TYPES.UNSIGNED_BYTE,
property.type,
this.dynamicStride * 4,
property.offset * 4
);
}
constructor(vertices, uvs, index)
{
super();
const verticesBuffer = new Buffer(vertices);
const uvsBuffer = new Buffer(uvs, true);
const indexBuffer = new Buffer(index, true, true);
this.addAttribute('aVertexPosition', verticesBuffer, 2, false, TYPES.FLOAT)
.addAttribute('aTextureCoord', uvsBuffer, 2, false, TYPES.FLOAT)
.addIndex(indexBuffer);
/**
* Dirty flag to limit update calls on Mesh. For example,
* limiting updates on a single Mesh instance with a shared Geometry
* within the render loop.
* @private
* @member {number}
* @default -1
*/
this._updateId = -1;
initBuffers()
{
const geometry = this.geometry;
let dynamicOffset = 0;
/**
* Holds the indices of the geometry (quads) to draw
*
* @member {Uint16Array}
* @private
*/
this.indexBuffer = new Buffer(createIndicesForQuads(this.size), true, true);
geometry.addIndex(this.indexBuffer);
this.dynamicStride = 0;
for (let i = 0; i < this.dynamicProperties.length; ++i)
{
const property = this.dynamicProperties[i];
property.offset = dynamicOffset;
dynamicOffset += property.size;
this.dynamicStride += property.size;
}
const dynBuffer = new ArrayBuffer(this.size * this.dynamicStride * 4 * 4);
this.dynamicData = new Float32Array(dynBuffer);
constructor(vertices, uvs, index)
{
super();
const verticesBuffer = new Buffer(vertices);
const uvsBuffer = new Buffer(uvs, true);
const indexBuffer = new Buffer(index, true, true);
this.addAttribute('aVertexPosition', verticesBuffer, 2, false, TYPES.FLOAT)
.addAttribute('aTextureCoord', uvsBuffer, 2, false, TYPES.FLOAT)
.addIndex(indexBuffer);
/**
* Dirty flag to limit update calls on Mesh. For example,
* limiting updates on a single Mesh instance with a shared Geometry
* within the render loop.
* @private
* @member {number}
* @default -1
*/
this._updateId = -1;
}