Sets stencil test actions.
OpenGL C bindings library: libGL.a
void glStencilOp(GLenum Fail, GLenum zFail, GLenum zPass)
|Fail||Specifies the action to take when the stencil test fails. Six symbolic constants are accepted:|
|zFail||Specifies stencil action when the stencil test passes but the depth test fails. zFail accepts the same symbolic constants as Fail.|
|zPass||Specifies stencil action when both the stencil test and the depth test pass, or when the stencil test passes and either there is no depth buffer or depth testing is not enabled. zPass accepts the same symbolic constants as Fail.|
Stenciling, like z-buffering, enables and disables drawing on a per-pixel basis. You draw into the stencil planes using GL drawing primitives, and then render geometry and images, using the stencil planes to mask out portions of the screen. Stenciling is typically used in multipass rendering algorithms to achieve special effects, such as decals, outlining, and constructive solid geometry rendering.
The stencil test conditionally eliminates a pixel based on the outcome of a comparison between the value in the stencil buffer and a reference value. The test is enabled with the glEnable and glDisable subroutine calls with the GL_STENCIL argument, and controlled with the glStencilFunc subroutine.
The glStencilOp subroutine takes three arguments that indicate what happens to the stored stencil value while stenciling is enabled. If the stencil test fails, no change is made to the pixel's color or depth buffers, and the Fail parameter specifies what happens to the stencil buffer contents. The six possible actions are as follows:
|GL_KEEP||Keeps the current value.|
|GL_ZERO||Sets the stencil buffer value to 0 (zero).|
|GL_REPLACE||Sets the stencil buffer value to the Reference parameter, as specified by the glStencilFunc subroutine.|
|GL_INCR||Increments the current stencil buffer value. Clamps to the maximum representable unsigned value.|
|GL_DECR||Decrements the current stencil buffer value. Clamps to 0.|
|GL_INVERT||Bitwise inverts the current stencil buffer value.|
Stencil buffer values are treated as unsigned integers. When incremented and decremented, values are clamped to 0 and 2n-1, where n is the value returned by querying GL_STENCIL_BITS.
The other two arguments to glStencilOp specify stencil buffer actions should subsequent depth buffer tests succeed (the zPass parameter) or fail (the zFail parameter). (See the glDepthFunc for information about specifying the function used for depth buffer comparisons.) They are specified using the same six symbolic constants as the Fail parameter. Note that the zFail parameter is ignored when there is no depth buffer, or when the depth buffer is not enabled. In these cases, the Fail and zPass parameters specify stencil action when the stencil test fails and passes, respectively.
Initially the stencil test is disabled. If there is no stencil buffer, no stencil modification can occur and it is as if the stencil tests always pass, regardless of any call to the glStencilOp subroutine.
|GL_INVALID_ENUM||Fail, zFail, or zPass is any value other than the six defined constant values.|
|GL_INVALID_OPERATION||The glStencilOp subroutine is called between a call to glBegin and the corresponding call to glEnd.|
Associated gets for the glStencilOp subroutine are as follows. (See the glGet subroutine for more information.)
glGet with argument GL_STENCIL_FAIL
glGet with argument GL_STENCIL_PASS_DEPTH_PASS
glGet with argument GL_STENCIL_PASS_DEPTH_FAIL
glGet with argument GL_STENCIL_BITS
glIsEnabled with argument GL_STENCIL_TEST.
|/usr/include/GL/gl.h||Contains C language constants, variable type definitions, and ANSI function prototypes for OpenGL.|
The glAlphaFunc subroutine, glBegin or glEnd subroutine, glBlendFunc subroutine, glDepthFunc subroutine, glEnable or glDisable subroutine, glLogicOp subroutine, glStencilFunc subroutine.