diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 00e1ca7..fb7095a 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -214,7 +214,8 @@ this.blendModes = null; - utils.webglRenderers.push(this); + this._boundUpdateTexture = this.updateTexture.bind(this); + this._boundDestroyTexture = this.destroyTexture.bind(this); // time init the context.. this._initContext(); @@ -381,6 +382,7 @@ if (!texture._glTextures[gl.id]) { texture._glTextures[gl.id] = gl.createTexture(); texture.on('update', this._boundUpdateTexture); + texture.on('dispose', this._boundDestroyTexture); } gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]); @@ -508,8 +510,6 @@ this.gl = null; this.blendModes = null; - - utils.webglRenderers.splice(utils.webglRenderers.indexOf(this), 1); }; /** diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 00e1ca7..fb7095a 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -214,7 +214,8 @@ this.blendModes = null; - utils.webglRenderers.push(this); + this._boundUpdateTexture = this.updateTexture.bind(this); + this._boundDestroyTexture = this.destroyTexture.bind(this); // time init the context.. this._initContext(); @@ -381,6 +382,7 @@ if (!texture._glTextures[gl.id]) { texture._glTextures[gl.id] = gl.createTexture(); texture.on('update', this._boundUpdateTexture); + texture.on('dispose', this._boundDestroyTexture); } gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]); @@ -508,8 +510,6 @@ this.gl = null; this.blendModes = null; - - utils.webglRenderers.splice(utils.webglRenderers.indexOf(this), 1); }; /** diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index b7b7a28..fe5279d 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -300,10 +300,7 @@ * */ BaseTexture.prototype.dispose = function () { - // delete the webGL textures if any. - for (var i = 0; i < utils.webglRenderers.length; ++i) { - utils.webglRenderers[i].destroyTexture(this); - } + this.emit('dispose', this); }; /**