diff --git a/packages/particles/src/ParticleBuffer.js b/packages/particles/src/ParticleBuffer.js index 68f5dc8..97b2452 100644 --- a/packages/particles/src/ParticleBuffer.js +++ b/packages/particles/src/ParticleBuffer.js @@ -89,6 +89,8 @@ this.dynamicData = null; this.dynamicDataUint32 = null; + this._updateID = 0; + this.initBuffers(); } diff --git a/packages/particles/src/ParticleBuffer.js b/packages/particles/src/ParticleBuffer.js index 68f5dc8..97b2452 100644 --- a/packages/particles/src/ParticleBuffer.js +++ b/packages/particles/src/ParticleBuffer.js @@ -89,6 +89,8 @@ this.dynamicData = null; this.dynamicDataUint32 = null; + this._updateID = 0; + this.initBuffers(); } diff --git a/packages/particles/src/ParticleContainer.js b/packages/particles/src/ParticleContainer.js index 22db6f5..10490ad 100644 --- a/packages/particles/src/ParticleContainer.js +++ b/packages/particles/src/ParticleContainer.js @@ -89,10 +89,18 @@ this._buffers = null; /** - * @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} @@ -234,10 +242,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; } dispose() @@ -272,5 +281,7 @@ this.dispose(); this._properties = null; + this._buffers = null; + this._bufferUpdateIDs = null; } } diff --git a/packages/particles/src/ParticleBuffer.js b/packages/particles/src/ParticleBuffer.js index 68f5dc8..97b2452 100644 --- a/packages/particles/src/ParticleBuffer.js +++ b/packages/particles/src/ParticleBuffer.js @@ -89,6 +89,8 @@ this.dynamicData = null; this.dynamicDataUint32 = null; + this._updateID = 0; + this.initBuffers(); } diff --git a/packages/particles/src/ParticleContainer.js b/packages/particles/src/ParticleContainer.js index 22db6f5..10490ad 100644 --- a/packages/particles/src/ParticleContainer.js +++ b/packages/particles/src/ParticleContainer.js @@ -89,10 +89,18 @@ this._buffers = null; /** - * @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} @@ -234,10 +242,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; } dispose() @@ -272,5 +281,7 @@ this.dispose(); this._properties = null; + this._buffers = null; + this._bufferUpdateIDs = null; } } diff --git a/packages/particles/src/ParticleRenderer.js b/packages/particles/src/ParticleRenderer.js index 9c7ac97..062d3b5 100644 --- a/packages/particles/src/ParticleRenderer.js +++ b/packages/particles/src/ParticleRenderer.js @@ -140,6 +140,8 @@ this.renderer.shader.bind(this.shader); + let updateStatic = false; + // now lets upload and render the buffers.. for (let i = 0, j = 0; i < totalChildren; i += batchSize, j += 1) { @@ -164,11 +166,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