diff --git a/src/core/const.js b/src/core/const.js index c14e9ab..cd86b8b 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -172,6 +172,12 @@ MIRRORED_REPEAT:2 }, + GC_MODES: { + DEFAULT: 0, + AUTO: 0, + MANUAL: 1, + }, + /** * If set to true WebGL will attempt make textures mimpaped by default * Mipmapping will only succeed if the base texture uploaded has power of two dimensions diff --git a/src/core/const.js b/src/core/const.js index c14e9ab..cd86b8b 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -172,6 +172,12 @@ MIRRORED_REPEAT:2 }, + GC_MODES: { + DEFAULT: 0, + AUTO: 0, + MANUAL: 1, + }, + /** * If set to true WebGL will attempt make textures mimpaped by default * Mipmapping will only succeed if the base texture uploaded has power of two dimensions diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 6fcbc29..550fadf 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,4 +1,6 @@ - + +var CONST = require('../../const'); + /** * @class * @memberof PIXI @@ -13,7 +15,7 @@ this.maxIdle = 60 * 60; this.checkCountMax = 60 * 10; - this.enabled = true; + this.mode = CONST.GC_MODES.DEFAULT; } TextueGarbageCollector.prototype.constructor = TextueGarbageCollector; @@ -21,28 +23,34 @@ TextueGarbageCollector.prototype.update = function() { - if(! this.enabled )return; + if(this.mode === CONST.GC_MODES.MANUAL)return; this.count++; this.checkCount++; - var managedTextures = this.renderer.textureManager._managedTextures; - + if(this.checkCount > this.checkCountMax) { this.checkCount = 0; - for (var i = 0; i < managedTextures.length; i++) { - - var texture = managedTextures[i]; - - // only supports non generated textures at the moment! - if( !texture._glRenderTargets && this.count - texture.touched > this.maxIdle) - { - texture.dispose(); - i--; - } - - }; + this.run(); } -} \ No newline at end of file +} + +TextueGarbageCollector.prototype.run = function() +{ + var managedTextures = this.renderer.textureManager._managedTextures; + + for (var i = 0; i < managedTextures.length; i++) { + + var texture = managedTextures[i]; + + // only supports non generated textures at the moment! + if( !texture._glRenderTargets && this.count - texture.touched > this.maxIdle) + { + texture.dispose(); + i--; + } + + }; +}