The WebGLRenderingContext.stencilOp()
method of the WebGL API sets both the front and back-facing stencil test actions.
void gl.stencilOp(fail, zfail, zpass);
All three parameters accept all constants listed below.
fail
GLenum
specifying the function to use when the stencil test fails. The default value is gl.KEEP
.zfail
GLenum
specifying the function to use when the stencil test passes, but the depth test fails. The default value is gl.KEEP
.zpass
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.
gl.KEEP
gl.ZERO
gl.REPLACE
WebGLRenderingContext.stencilFunc()
.gl.INCR
gl.INCR_WRAP
gl.DECR
gl.DECR_WRAP
gl.INVERT
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.stencilOp(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 | Status | Comment |
---|---|---|
WebGL 1.0 The definition of 'stencilOp' in that specification. | Recommendation | Initial definition. |
OpenGL ES 2.0 The definition of 'glStencilOp' in that specification. | Standard | Man page of the OpenGL API. |
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 9 | 12 | 4 | 11 | 12 | 5.1 |
Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic support | Yes | 25 | Yes | Yes | 11 | 12 | 8.1 |
WebGLRenderingContext.stencilOpSeparate()
WebGLRenderingContext.stencilFunc()
WebGLRenderingContext.stencilFuncSeparate()
WebGLRenderingContext.stencilMask()
WebGLRenderingContext.stencilMaskSeparate()
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/stencilOp