diff --git a/src/particles/ParticleContainer.js b/src/particles/ParticleContainer.js index 60f7fce..233ee3b 100644 --- a/src/particles/ParticleContainer.js +++ b/src/particles/ParticleContainer.js @@ -28,16 +28,19 @@ export default class ParticleContainer extends core.Container { /** - * @param {number} [maxSize=15000] - The maximum number of particles that can be renderer by the container. + * @param {number} [maxSize=1500] - The maximum number of particles that can be rendered by the container. + * Affects size of allocated buffers. * @param {object} [properties] - The properties of children that should be uploaded to the gpu and applied. * @param {boolean} [properties.scale=false] - When true, scale be uploaded and applied. * @param {boolean} [properties.position=true] - When true, position be uploaded and applied. * @param {boolean} [properties.rotation=false] - When true, rotation be uploaded and applied. * @param {boolean} [properties.uvs=false] - When true, uvs be uploaded and applied. - * @param {boolean} [properties.alpha=false] - When true, alpha be uploaded and applied. - * @param {number} [batchSize=15000] - Number of particles per batch. + * @param {boolean} [properties.tint=false] - When true, alpha and tint be uploaded and applied. + * @param {number} [batchSize=16384] - Number of particles per batch. If less than maxSize, it uses maxSize instead. + * @param {boolean} [autoResize=true] If true, container allocates more batches in case + * there are more than `maxSize` particles. */ - constructor(maxSize = 1500, properties, batchSize = 16384) + constructor(maxSize = 1500, properties, batchSize = 16384, autoResize = false) { super(); @@ -105,6 +108,13 @@ this.blendMode = core.BLEND_MODES.NORMAL; /** + * If true, container allocates more batches in case there are more than `maxSize` particles. + * @member {boolean} + * @default false + */ + this.autoResize = autoResize; + + /** * Used for canvas renderering. If true then the elements will be positioned at the * nearest pixel. This provides a nice speed boost. * diff --git a/src/particles/ParticleContainer.js b/src/particles/ParticleContainer.js index 60f7fce..233ee3b 100644 --- a/src/particles/ParticleContainer.js +++ b/src/particles/ParticleContainer.js @@ -28,16 +28,19 @@ export default class ParticleContainer extends core.Container { /** - * @param {number} [maxSize=15000] - The maximum number of particles that can be renderer by the container. + * @param {number} [maxSize=1500] - The maximum number of particles that can be rendered by the container. + * Affects size of allocated buffers. * @param {object} [properties] - The properties of children that should be uploaded to the gpu and applied. * @param {boolean} [properties.scale=false] - When true, scale be uploaded and applied. * @param {boolean} [properties.position=true] - When true, position be uploaded and applied. * @param {boolean} [properties.rotation=false] - When true, rotation be uploaded and applied. * @param {boolean} [properties.uvs=false] - When true, uvs be uploaded and applied. - * @param {boolean} [properties.alpha=false] - When true, alpha be uploaded and applied. - * @param {number} [batchSize=15000] - Number of particles per batch. + * @param {boolean} [properties.tint=false] - When true, alpha and tint be uploaded and applied. + * @param {number} [batchSize=16384] - Number of particles per batch. If less than maxSize, it uses maxSize instead. + * @param {boolean} [autoResize=true] If true, container allocates more batches in case + * there are more than `maxSize` particles. */ - constructor(maxSize = 1500, properties, batchSize = 16384) + constructor(maxSize = 1500, properties, batchSize = 16384, autoResize = false) { super(); @@ -105,6 +108,13 @@ this.blendMode = core.BLEND_MODES.NORMAL; /** + * If true, container allocates more batches in case there are more than `maxSize` particles. + * @member {boolean} + * @default false + */ + this.autoResize = autoResize; + + /** * Used for canvas renderering. If true then the elements will be positioned at the * nearest pixel. This provides a nice speed boost. * diff --git a/src/particles/webgl/ParticleRenderer.js b/src/particles/webgl/ParticleRenderer.js index c1b2d98..1ae869e 100644 --- a/src/particles/webgl/ParticleRenderer.js +++ b/src/particles/webgl/ParticleRenderer.js @@ -173,6 +173,15 @@ amount = batchSize; } + if (j >= buffers.length) + { + if (!container.autoResize) + { + break; + } + buffers.push(this._generateOneMoreBuffer(container)); + } + const buffer = buffers[j]; // we always upload the dynamic @@ -214,6 +223,22 @@ } /** + * Creates one more particle buffer, because container has autoResize feature + * + * @param {PIXI.ParticleContainer} container - The container to render using this ParticleRenderer + * @return {PIXI.ParticleBuffer} generated buffer + * @private + */ + _generateOneMoreBuffer(container) + { + const gl = this.renderer.gl; + const batchSize = container._batchSize; + const dynamicPropertyFlags = container._properties; + + return new ParticleBuffer(gl, this.properties, dynamicPropertyFlags, batchSize); + } + + /** * Uploads the verticies. * * @param {PIXI.DisplayObject[]} children - the array of display objects to render