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 in Web Workers.
The WebGLRenderingContext.stencilOpSeparate() method of the WebGL API sets the front and/or back-facing stencil test actions.
stencilOpSeparate(face, fail, zfail, zpass)
faceA GLenum specifying whether the front and/or back stencil state is updated. The possible values are:
gl.FRONTgl.BACKgl.FRONT_AND_BACKfailA GLenum specifying the function to use when the stencil test fails. The default value is gl.KEEP.
zfailA GLenum specifying the function to use when the stencil test passes, but the depth test fails. The default value is gl.KEEP.
zpassA GLenum specifying the function to use when both the stencil test and the depth test pass, or when the stencil test passes and there is no depth buffer or depth testing is disabled. The default value is gl.KEEP.
None (undefined).
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 representable unsigned value.
gl.INCR_WRAPIncrements the current stencil buffer value. Wraps stencil buffer value to zero when incrementing 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 the maximum representable unsigned value when decrementing a stencil buffer value of 0.
gl.INVERTInverts the current stencil buffer value bitwise.
The stencil testing is disabled by default. To enable or disable stencil testing, use the enable() and disable() methods with the argument gl.STENCIL_TEST.
gl.enable(gl.STENCIL_TEST); gl.stencilOpSeparate(gl.FRONT, gl.INCR, gl.DECR, gl.INVERT);
To get the current information about stencil and depth pass or fail, query the following constants with getParameter().
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);
| Specification |
|---|
| WebGL Specification> # 5.14.3> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
stencilOpSeparate |
9 | 12 | 4 | 12 | 5.1 | 25 | 4 | 12 | 8 | 1.5 | 4.4.3 | 8 |
WebGLRenderingContext.stencilOp()WebGLRenderingContext.stencilFunc()WebGLRenderingContext.stencilFuncSeparate()WebGLRenderingContext.stencilMask()WebGLRenderingContext.stencilMaskSeparate()
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/stencilOpSeparate