diff --git a/src/core/particles/ParticleContainer.js b/src/core/particles/ParticleContainer.js index 00e9fdc..11ba115 100644 --- a/src/core/particles/ParticleContainer.js +++ b/src/core/particles/ParticleContainer.js @@ -79,7 +79,7 @@ /** * Used for canvas renderering. If true then the elements will be positioned at the nearest pixel. This provides a nice speed boost. - * + * * @member {boolean} * @default true; */ @@ -115,7 +115,7 @@ */ ParticleContainer.prototype.updateTransform = function () { - + // TODO don't need to! this.displayObjectUpdateTransform(); // PIXI.Container.prototype.updateTransform.call( this ); @@ -207,7 +207,7 @@ var context = renderer.context; var transform = this.worldTransform; var isRotated = true; - + var positionX = 0; var positionY = 0; @@ -253,7 +253,7 @@ finalWidth = frame.width * child.scale.x; finalHeight = frame.height * child.scale.y; - + } else { @@ -309,3 +309,21 @@ ); } }; + +/** + * Destroys the container + * + * @param [destroyChildren=false] {boolean} if set to true, all the children will have their destroy method called as well + */ +ParticleContainer.prototype.destroy = function () { + Container.prototype.destroy.apply(this, arguments); + + if (this._buffers) { + for (var i = 0; i < this._buffers.length; ++i) { + this._buffers.destroy(); + } + } + + this._properties = null; + this._buffers = null; +}; diff --git a/src/core/particles/ParticleContainer.js b/src/core/particles/ParticleContainer.js index 00e9fdc..11ba115 100644 --- a/src/core/particles/ParticleContainer.js +++ b/src/core/particles/ParticleContainer.js @@ -79,7 +79,7 @@ /** * Used for canvas renderering. If true then the elements will be positioned at the nearest pixel. This provides a nice speed boost. - * + * * @member {boolean} * @default true; */ @@ -115,7 +115,7 @@ */ ParticleContainer.prototype.updateTransform = function () { - + // TODO don't need to! this.displayObjectUpdateTransform(); // PIXI.Container.prototype.updateTransform.call( this ); @@ -207,7 +207,7 @@ var context = renderer.context; var transform = this.worldTransform; var isRotated = true; - + var positionX = 0; var positionY = 0; @@ -253,7 +253,7 @@ finalWidth = frame.width * child.scale.x; finalHeight = frame.height * child.scale.y; - + } else { @@ -309,3 +309,21 @@ ); } }; + +/** + * Destroys the container + * + * @param [destroyChildren=false] {boolean} if set to true, all the children will have their destroy method called as well + */ +ParticleContainer.prototype.destroy = function () { + Container.prototype.destroy.apply(this, arguments); + + if (this._buffers) { + for (var i = 0; i < this._buffers.length; ++i) { + this._buffers.destroy(); + } + } + + this._properties = null; + this._buffers = null; +}; diff --git a/src/core/particles/webgl/ParticleBuffer.js b/src/core/particles/webgl/ParticleBuffer.js index 6fad028..44ed52d 100644 --- a/src/core/particles/webgl/ParticleBuffer.js +++ b/src/core/particles/webgl/ParticleBuffer.js @@ -47,14 +47,14 @@ this.size = size; /** - * + * * * @member {Array} */ this.dynamicProperties = []; /** - * + * * * @member {Array} */ @@ -201,5 +201,11 @@ */ ParticleBuffer.prototype.destroy = function () { - //TODO implement this :) to busy making the fun bits.. + this.dynamicProperties = null; + this.dynamicData = null; + this.gl.deleteBuffer(this.dynamicBuffer); + + this.staticProperties = null; + this.staticData = null; + this.gl.deleteBuffer(this.staticBuffer); }; diff --git a/src/core/particles/ParticleContainer.js b/src/core/particles/ParticleContainer.js index 00e9fdc..11ba115 100644 --- a/src/core/particles/ParticleContainer.js +++ b/src/core/particles/ParticleContainer.js @@ -79,7 +79,7 @@ /** * Used for canvas renderering. If true then the elements will be positioned at the nearest pixel. This provides a nice speed boost. - * + * * @member {boolean} * @default true; */ @@ -115,7 +115,7 @@ */ ParticleContainer.prototype.updateTransform = function () { - + // TODO don't need to! this.displayObjectUpdateTransform(); // PIXI.Container.prototype.updateTransform.call( this ); @@ -207,7 +207,7 @@ var context = renderer.context; var transform = this.worldTransform; var isRotated = true; - + var positionX = 0; var positionY = 0; @@ -253,7 +253,7 @@ finalWidth = frame.width * child.scale.x; finalHeight = frame.height * child.scale.y; - + } else { @@ -309,3 +309,21 @@ ); } }; + +/** + * Destroys the container + * + * @param [destroyChildren=false] {boolean} if set to true, all the children will have their destroy method called as well + */ +ParticleContainer.prototype.destroy = function () { + Container.prototype.destroy.apply(this, arguments); + + if (this._buffers) { + for (var i = 0; i < this._buffers.length; ++i) { + this._buffers.destroy(); + } + } + + this._properties = null; + this._buffers = null; +}; diff --git a/src/core/particles/webgl/ParticleBuffer.js b/src/core/particles/webgl/ParticleBuffer.js index 6fad028..44ed52d 100644 --- a/src/core/particles/webgl/ParticleBuffer.js +++ b/src/core/particles/webgl/ParticleBuffer.js @@ -47,14 +47,14 @@ this.size = size; /** - * + * * * @member {Array} */ this.dynamicProperties = []; /** - * + * * * @member {Array} */ @@ -201,5 +201,11 @@ */ ParticleBuffer.prototype.destroy = function () { - //TODO implement this :) to busy making the fun bits.. + this.dynamicProperties = null; + this.dynamicData = null; + this.gl.deleteBuffer(this.dynamicBuffer); + + this.staticProperties = null; + this.staticData = null; + this.gl.deleteBuffer(this.staticBuffer); }; diff --git a/src/core/particles/webgl/ParticleRenderer.js b/src/core/particles/webgl/ParticleRenderer.js index 122e539..9f0f79d 100644 --- a/src/core/particles/webgl/ParticleRenderer.js +++ b/src/core/particles/webgl/ParticleRenderer.js @@ -26,7 +26,6 @@ { ObjectRenderer.call(this, renderer); - /** * The number of images in the Particle before it flushes. * @@ -36,7 +35,6 @@ var numIndices = this.size * 6; - /** * Holds the indices * @@ -61,11 +59,11 @@ */ this.shader = null; + this.indexBuffer = null; + + this.properties = null; + this.tempMatrix = new math.Matrix(); - - - - } ParticleRenderer.prototype = Object.create(ObjectRenderer.prototype); @@ -95,49 +93,48 @@ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW); - this.properties = [ - //verticesData - { - attribute:this.shader.attributes.aVertexPosition, - dynamic:false, - size:2, - uploadFunction:this.uploadVertices, - offset:0 - }, - // positionData - { - attribute:this.shader.attributes.aPositionCoord, - dynamic:true, - size:2, - uploadFunction:this.uploadPosition, - offset:0 - }, - // rotationData - { - attribute:this.shader.attributes.aRotation, - dynamic:false, - size:1, - uploadFunction:this.uploadRotation, - offset:0 - }, - //u vsData - { - attribute:this.shader.attributes.aTextureCoord, - dynamic:false, - size:2, - uploadFunction:this.uploadUvs, - offset:0 - }, - // alphaData - { - attribute:this.shader.attributes.aColor, - dynamic:false, - size:1, - uploadFunction:this.uploadAlpha, - offset:0 - }]; - + // verticesData + { + attribute:this.shader.attributes.aVertexPosition, + dynamic:false, + size:2, + uploadFunction:this.uploadVertices, + offset:0 + }, + // positionData + { + attribute:this.shader.attributes.aPositionCoord, + dynamic:true, + size:2, + uploadFunction:this.uploadPosition, + offset:0 + }, + // rotationData + { + attribute:this.shader.attributes.aRotation, + dynamic:false, + size:1, + uploadFunction:this.uploadRotation, + offset:0 + }, + // uvsData + { + attribute:this.shader.attributes.aTextureCoord, + dynamic:false, + size:2, + uploadFunction:this.uploadUvs, + offset:0 + }, + // alphaData + { + attribute:this.shader.attributes.aColor, + dynamic:false, + size:1, + uploadFunction:this.uploadAlpha, + offset:0 + } + ]; }; /** @@ -190,7 +187,7 @@ // if the uvs have not updated then no point rendering just yet! this.renderer.blendModeManager.setBlendMode(container.blendMode); - + var gl = this.renderer.gl; var m = container.worldTransform.copy( this.tempMatrix ); @@ -483,8 +480,14 @@ */ ParticleRenderer.prototype.destroy = function () { + if (this.renderer.gl) { + this.renderer.gl.deleteBuffer(this.indexBuffer); + } + + ObjectRenderer.prototype.destroy.apply(this, arguments); this.shader.destroy(); - //TODO implement this! + this.indices = null; + this.tempMatrix = null; };