diff --git a/src/pixi/renderers/webgl/utils/WebGLFilterManager.js b/src/pixi/renderers/webgl/utils/WebGLFilterManager.js index e726891bf..c242a4bdd 100644 --- a/src/pixi/renderers/webgl/utils/WebGLFilterManager.js +++ b/src/pixi/renderers/webgl/utils/WebGLFilterManager.js @@ -73,7 +73,14 @@ PIXI.WebGLFilterManager.prototype.pushFilter = function(filterBlock) var offset = this.renderSession.offset; filterBlock._filterArea = filterBlock.target.filterArea || filterBlock.target.getBounds(); - + + // >>> modify by nextht + filterBlock._previous_stencil_mgr = this.renderSession.stencilManager; + this.renderSession.stencilManager = new PIXI.WebGLStencilManager(); + this.renderSession.stencilManager.setContext(gl); + gl.disable(gl.STENCIL_TEST); + // <<< modify by nextht + // filter program // OPTIMISATION - the first filter is free if its a simple color change? this.filterStack.push(filterBlock); @@ -298,6 +305,20 @@ PIXI.WebGLFilterManager.prototype.popFilter = function() gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, texture.texture); + // >>> modify by nextht + if (this.renderSession.stencilManager) { + this.renderSession.stencilManager.destroy(); + } + this.renderSession.stencilManager = filterBlock._previous_stencil_mgr; + filterBlock._previous_stencil_mgr = null; + if (this.renderSession.stencilManager.count > 0) { + gl.enable(gl.STENCIL_TEST); + } + else { + gl.disable(gl.STENCIL_TEST); + } + // <<< modify by nextht + // apply! this.applyFilterPass(filter, filterArea, sizeX, sizeY);