BlitterBatch will now flush if you try to add too many Bobs (avoids index error).

This commit is contained in:
Richard Davey 2017-02-13 21:50:41 +00:00
parent 36d627d165
commit d480263fa9
5 changed files with 13 additions and 13 deletions

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: '9783ae10-f200-11e6-8fd1-91715dad763f'
build: '1ab7d5b0-f236-11e6-867a-17ae0be84b32'
};
module.exports = CHECKSUM;

View file

@ -1,4 +1,3 @@
var BlitterWebGLRenderer = function (renderer, src, interpolationPercentage)
{
var worldAlpha = src.color.worldAlpha;
@ -12,16 +11,12 @@ var BlitterWebGLRenderer = function (renderer, src, interpolationPercentage)
}
// Render bobs
for (var i = 0; i <= len; ++i)
{
var bob = src.children.list[i];
var frame = bob.frame;
// if (!bob.visible)
// {
// continue;
// }
renderer.blitterBatch.add(bob.x, bob.y, frame, worldAlpha);
}
};

View file

@ -7,7 +7,7 @@
var ProcessKeyDown = function (event, list, prevent)
{
if (prevent === undefined) { prevent = false; }
if (prevent === undefined) { prevent = false; }
if (list)
{

View file

@ -86,6 +86,7 @@ BlitterBatch.prototype = {
this.indexBufferObject = indexBufferObject;
this.vertexArray = vertexArray;
this.viewMatrixLocation = viewMatrixLocation;
this.maxParticles = max;
// Populate the index buffer only once
for (var indexA = 0, indexB = 0; indexA < max; indexA += CONST.PARTICLE_INDEX_COUNT, indexB += CONST.PARTICLE_VERTEX_COUNT)
@ -115,16 +116,20 @@ BlitterBatch.prototype = {
{
this.manager.setBatch(this, frame.texture.source[frame.sourceIndex].glTexture);
// The user must check if the buffers are full before flushing
// this is to give freedom of when should the renderer flush. var vertexDataBuffer = this.vertexDataBuffer;
if (this.elementCount >= this.maxParticles)
{
this.flush();
}
var vertexDataBuffer = this.vertexDataBuffer;
var vertexBuffer = vertexDataBuffer.floatView;
var vertexOffset = vertexDataBuffer.allocate(CONST.PARTICLE_VERTEX_COMPONENT_COUNT * CONST.PARTICLE_VERTEX_COUNT);
var uvs = frame.uvs;
var width = frame.width;
var height = frame.height;
x += frame.x
y += frame.y
x += frame.x;
y += frame.y;
vertexBuffer[vertexOffset++] = x;
vertexBuffer[vertexOffset++] = y;

View file

@ -12,7 +12,7 @@ var CONST = {
// How many 32-bit components does the vertex have.
PARTICLE_VERTEX_COMPONENT_COUNT: 5,
// Can't be bigger since index are 16-bit
// Can't be bigger than 10,000 since index are 16-bit
MAX_PARTICLES: 2000,
VERTEX_SHADER_SOURCE: VertexShader,