diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 6023bcb..8e5c8e7 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -2,6 +2,8 @@ var CONST = require('../../const'); /** + * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. + * * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. @@ -21,6 +23,10 @@ TextureGarbageCollector.prototype.constructor = TextureGarbageCollector; module.exports = TextureGarbageCollector; +/** + * Checks to see when the last time a texture was used + * if the texture has not been used for a specified amount of time it will be removed from the GPU + */ TextureGarbageCollector.prototype.update = function() { this.count++; @@ -41,6 +47,10 @@ } }; +/** + * Checks to see when the last time a texture was used + * if the texture has not been used for a specified amount of time it will be removed from the GPU + */ TextureGarbageCollector.prototype.run = function() { var tm = this.renderer.textureManager; @@ -76,3 +86,24 @@ managedTextures.length = j; } }; + +/** + * Removes all the textures within the specified displayObject and its children from the GPU + * + * @param displayObject {PIXI.DisplayObject} the displayObject to remove the textures from. + */ +TextureGarbageCollector.prototype.unload = function( displayObject ) +{ + var tm = this.renderer.textureManager; + + if(displayObject._texture) + { + tm.destroyTexture(displayObject._texture, true); + } + + for (var i = displayObject.children.length - 1; i >= 0; i--) { + + this.unload(displayObject.children[i]); + + }; +}