Code coverage report for src/pixi/renderers/webgl/utils/WebGLMaskManager.js

Statements: 13.33% (4 / 30)      Branches: 0% (0 / 6)      Functions: 0% (0 / 4)      Lines: 13.79% (4 / 29)     

All files » src/pixi/renderers/webgl/utils\ » WebGLMaskManager.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63        1               1         1                                               1                                          
/**
 * @author Mat Groves http://matgroves.com/ @Doormat23
 */
 
PIXI.WebGLMaskManager = function(gl)
{
    this.maskStack = [];
    this.maskPosition = 0;
 
    this.setContext(gl);
};
 
PIXI.WebGLMaskManager.prototype.setContext = function(gl)
{
    this.gl = gl;
};
 
PIXI.WebGLMaskManager.prototype.pushMask = function(maskData, renderSession)
{
    var gl = this.gl;
 
    if(this.maskStack.length === 0)
    {
        gl.enable(gl.STENCIL_TEST);
        gl.stencilFunc(gl.ALWAYS,1,1);
    }
    
  //  maskData.visible = false;
 
    this.maskStack.push(maskData);
    
    gl.colorMask(false, false, false, true);
    gl.stencilOp(gl.KEEP,gl.KEEP,gl.INCR);
 
    PIXI.WebGLGraphics.renderGraphics(maskData, renderSession);
 
    gl.colorMask(true, true, true, true);
    gl.stencilFunc(gl.NOTEQUAL,0, this.maskStack.length);
    gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP);
};
 
PIXI.WebGLMaskManager.prototype.popMask = function(renderSession)
{
    var gl = this.gl;
 
    var maskData = this.maskStack.pop();
 
    if(maskData)
    {
        gl.colorMask(false, false, false, false);
 
        //gl.stencilFunc(gl.ALWAYS,1,1);
        gl.stencilOp(gl.KEEP,gl.KEEP,gl.DECR);
 
        PIXI.WebGLGraphics.renderGraphics(maskData, renderSession);
 
        gl.colorMask(true, true, true, true);
        gl.stencilFunc(gl.NOTEQUAL,0,this.maskStack.length);
        gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP);
    }
   
    if(this.maskStack.length === 0)gl.disable(gl.STENCIL_TEST);
};