diff --git a/src/particles/ParticleContainer.js b/src/particles/ParticleContainer.js index 5827c3b..566c749 100644 --- a/src/particles/ParticleContainer.js +++ b/src/particles/ParticleContainer.js @@ -88,10 +88,18 @@ this._glBuffers = {}; /** - * @member {number} + * for every batch stores _updateID corresponding to the last change in that batch + * @member {number[]} * @private */ - this._bufferToUpdate = 0; + this._bufferUpdateIDs = []; + + /** + * when child inserted, removed or changes position this number goes up + * @member {number[]} + * @private + */ + this._updateID = 0; /** * @member {boolean} @@ -233,10 +241,11 @@ { const bufferIndex = Math.floor(smallestChildIndex / this._batchSize); - if (bufferIndex < this._bufferToUpdate) + while (this._bufferUpdateIDs.length < bufferIndex) { - this._bufferToUpdate = bufferIndex; + this._bufferUpdateIDs.push(0); } + this._bufferUpdateIDs[bufferIndex] = ++this._updateID; } /** @@ -387,5 +396,6 @@ this._properties = null; this._buffers = null; + this._bufferUpdateIDs = null; } } diff --git a/src/particles/ParticleContainer.js b/src/particles/ParticleContainer.js index 5827c3b..566c749 100644 --- a/src/particles/ParticleContainer.js +++ b/src/particles/ParticleContainer.js @@ -88,10 +88,18 @@ this._glBuffers = {}; /** - * @member {number} + * for every batch stores _updateID corresponding to the last change in that batch + * @member {number[]} * @private */ - this._bufferToUpdate = 0; + this._bufferUpdateIDs = []; + + /** + * when child inserted, removed or changes position this number goes up + * @member {number[]} + * @private + */ + this._updateID = 0; /** * @member {boolean} @@ -233,10 +241,11 @@ { const bufferIndex = Math.floor(smallestChildIndex / this._batchSize); - if (bufferIndex < this._bufferToUpdate) + while (this._bufferUpdateIDs.length < bufferIndex) { - this._bufferToUpdate = bufferIndex; + this._bufferUpdateIDs.push(0); } + this._bufferUpdateIDs[bufferIndex] = ++this._updateID; } /** @@ -387,5 +396,6 @@ this._properties = null; this._buffers = null; + this._bufferUpdateIDs = null; } } diff --git a/src/particles/webgl/ParticleBuffer.js b/src/particles/webgl/ParticleBuffer.js index e118769..beb07f3 100644 --- a/src/particles/webgl/ParticleBuffer.js +++ b/src/particles/webgl/ParticleBuffer.js @@ -92,6 +92,8 @@ this.dynamicData = null; this.dynamicDataUint32 = null; + this._updateID = 0; + this.initBuffers(); } diff --git a/src/particles/ParticleContainer.js b/src/particles/ParticleContainer.js index 5827c3b..566c749 100644 --- a/src/particles/ParticleContainer.js +++ b/src/particles/ParticleContainer.js @@ -88,10 +88,18 @@ this._glBuffers = {}; /** - * @member {number} + * for every batch stores _updateID corresponding to the last change in that batch + * @member {number[]} * @private */ - this._bufferToUpdate = 0; + this._bufferUpdateIDs = []; + + /** + * when child inserted, removed or changes position this number goes up + * @member {number[]} + * @private + */ + this._updateID = 0; /** * @member {boolean} @@ -233,10 +241,11 @@ { const bufferIndex = Math.floor(smallestChildIndex / this._batchSize); - if (bufferIndex < this._bufferToUpdate) + while (this._bufferUpdateIDs.length < bufferIndex) { - this._bufferToUpdate = bufferIndex; + this._bufferUpdateIDs.push(0); } + this._bufferUpdateIDs[bufferIndex] = ++this._updateID; } /** @@ -387,5 +396,6 @@ this._properties = null; this._buffers = null; + this._bufferUpdateIDs = null; } } diff --git a/src/particles/webgl/ParticleBuffer.js b/src/particles/webgl/ParticleBuffer.js index e118769..beb07f3 100644 --- a/src/particles/webgl/ParticleBuffer.js +++ b/src/particles/webgl/ParticleBuffer.js @@ -92,6 +92,8 @@ this.dynamicData = null; this.dynamicDataUint32 = null; + this._updateID = 0; + this.initBuffers(); } diff --git a/src/particles/webgl/ParticleRenderer.js b/src/particles/webgl/ParticleRenderer.js index 1ae869e..16b8236 100644 --- a/src/particles/webgl/ParticleRenderer.js +++ b/src/particles/webgl/ParticleRenderer.js @@ -163,6 +163,8 @@ // make sure the texture is bound.. this.shader.uniforms.uSampler = renderer.bindTexture(baseTexture); + let updateStatic = false; + // now lets upload and render the buffers.. for (let i = 0, j = 0; i < totalChildren; i += batchSize, j += 1) { @@ -187,11 +189,14 @@ // we always upload the dynamic buffer.uploadDynamic(children, i, amount); + const bid = container._bufferUpdateIDs[i] || 0; + + updateStatic = updateStatic || (buffer._updateID < bid); // we only upload the static content when we have to! - if (container._bufferToUpdate === j) + if (updateStatic) { + buffer._updateID = container._updateID; buffer.uploadStatic(children, i, amount); - container._bufferToUpdate = j + 1; } // bind the buffer