WebGLRenderingContext: stencilOp() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Note: This feature is available inWeb Workers.
TheWebGLRenderingContext.stencilOp() method of theWebGL API sets both the front and back-facingstencil test actions.
In this article
Syntax
stencilOp(fail, zfail, zpass)Parameters
failA
GLenumspecifying the function to use when the stencil test fails.The default value isgl.KEEP.zfailA
GLenumspecifying the function to use when the stencil test passes,but the depth test fails. The default value isgl.KEEP.zpassA
GLenumspecifying the function to use when both the stencil testand the depth test pass, or when the stencil test passes and there is no depth bufferor depth testing is disabled. The default value isgl.KEEP.
Return value
None (undefined).
Constants
gl.KEEPKeeps the current value.
gl.ZEROSets the stencil buffer value to 0.
gl.REPLACESets the stencil buffer value to the reference value as specified by
WebGLRenderingContext.stencilFunc().gl.INCRIncrements the current stencil buffer value. Clamps to the maximum representableunsigned value.
gl.INCR_WRAPIncrements the current stencil buffer value. Wraps stencil buffer value to zero whenincrementing the maximum representable unsigned value.
gl.DECRDecrements the current stencil buffer value. Clamps to 0.
gl.DECR_WRAPDecrements the current stencil buffer value. Wraps stencil buffer value to themaximum representable unsigned value when decrementing a stencil buffer value of 0.
gl.INVERTInverts the current stencil buffer value bitwise.
Examples
The stencil testing is disabled by default. To enable or disable stencil testing, usetheenable() anddisable() methods with the argumentgl.STENCIL_TEST.
gl.enable(gl.STENCIL_TEST);gl.stencilOp(gl.INCR, gl.DECR, gl.INVERT);To get the current information about stencil and depth pass or fail, query thefollowing constants withgetParameter().
gl.getParameter(gl.STENCIL_FAIL);gl.getParameter(gl.STENCIL_PASS_DEPTH_PASS);gl.getParameter(gl.STENCIL_PASS_DEPTH_FAIL);gl.getParameter(gl.STENCIL_BACK_FAIL);gl.getParameter(gl.STENCIL_BACK_PASS_DEPTH_PASS);gl.getParameter(gl.STENCIL_BACK_PASS_DEPTH_FAIL);gl.getParameter(gl.STENCIL_BITS);Specifications
| Specification |
|---|
| WebGL Specification> # 5.14.3> |