pex-gl / pex-context

Modern WebGL state wrapper for PEX: allocate GPU resources (textures, buffers), setup state pipelines and passes, and combine them into commands.
http://pex-gl.github.io/pex-context/
MIT License
160 stars 12 forks source link

State save/restore for separate/unified stencil{Func,Op}, blend{Equation,Func} wrong #8

Closed automat closed 6 years ago

automat commented 8 years ago

stencilFunc https://github.com/pex-gl/pex-context/blob/master/Context.js#L146 Should be merged into stencilFuncSeparate and be:

this._stencilFuncSeparate = [
    //front
    this._gl.getParameter(this._gl.STENCIL_FUNC),
    this._gl.getParameter(this._gl.STENCIL_REF),
    this._gl.getParameter(this._gl.STENCIL_VALUE_MASK),
     //back
    this._gl.getParameter(this._gl.STENCIL_FUNC),
    this._gl.getParameter(this._gl.STENCIL_REF),
    this._gl.getParameter(this._gl.STENCIL_VALUE_MASK)
];

setStencilFunc then just sets both gl.FRONT and gl.BACK part of stencilFuncSeparate state. Because this here doesnt work as expected: https://github.com/pex-gl/pex-context/blob/master/Context.js#L670.

ctx.setStencilFunc(gl.ALWAYS,1,1);
ctx.pushState(ctx.STENCIL_BIT);
//something
ctx.setStencilFuncSeparate(ctx.FRONT,gl.NEVER,0,1);
ctx.popState(ctx.STENCIL_BIT);
//restores stencil state based on stencilFuncSeparate state, but could differ from unified state set
//before push

also separate getter getStencilFuncSeparate(out) doesnt make sense here anymore, https://github.com/pex-gl/pex-context/blob/master/Context.js#L1058, should be getStencilFuncSeparate(face,out) and https://github.com/pex-gl/pex-context/blob/master/Context.js#L1031 should return both gl.FRONT and gl.BACK state (see top)

Merge all separated states and update getters: stencilFunc=>stencilFuncSeparate stencilOp=>stencilOpSeparate blendEquation=>blendEquationSeparate blendFunc=> blendFuncSeparate

vorg commented 6 years ago

Not applicable since v2.0.0