Click or drag to resize

glStencilOperation Method

Set front and back stencil test actions.

Namespace:  Ooogles
Assembly:  Ooogles (in Ooogles.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public static void StencilOperation(
	glStencilOp stencilFail = glStencilOp.Keep,
	glStencilOp depthFail = glStencilOp.Keep,
	glStencilOp bothPass = glStencilOp.Keep
)

Parameters

stencilFail (Optional)
Type: OooglesglStencilOp
(optional) value that specifies the action to take when the stencil test fails. The initial value is Keep.
depthFail (Optional)
Type: OooglesglStencilOp
(optional) value that specifies the action to take when the stencil test passes, but the depth test fails. The initial value is Keep.
bothPass (Optional)
Type: OooglesglStencilOp
(optional) value that specifies the action to take when both the stencil test and depth test pass, or when the stencil test passes and either there is no depth buffer or depth testing is not enabled. The initial value is Keep.
Remarks
Stenciling, like depth-buffering, enables and disables drawing on a per-pixel basis. You draw into the stencil planes using GL drawing primitives, then render geometry and images, using the stencil planes to mask out portions of the screen. Stenciling is typically used in multi-pass 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. To enable and disable the test, call Enable(glCapability) and Disable(glCapability) with argument StencilTest; to control it, call StencilFunc(glCompareFunc, Int32, UInt32) or StencilFuncSeparate(glFace, glCompareFunc, Int32, UInt32).

There can be two separate sets of stencilFail, depthFail and bothPass parameters; one affects back-facing polygons, and the other affects front-facing polygons as well as other non-polygon primitives. StencilOperation sets both front and back stencil state to the same values. Use StencilOperationSeparate(glFace, glStencilOp, glStencilOp, glStencilOp) to set front and back stencil state to different values.

StencilOperation 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 stencilFail specifies what happens to the stencil buffer contents.

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 StencilBits.

The other two arguments to StencilOperation specify stencil buffer actions that depend on whether subsequent depth buffer tests succeed (bothPass) or fail (depthFail) (see DepthFunc(glCompareFunc)). Note that depthFail is ignored when there is no depth buffer, or when the depth buffer is not enabled. In these cases, stencilFail and bothPass specify stencil action when the stencil test fails and passes, respectively.

Note: 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 StencilOperation.

Note: StencilOperation is the same as calling StencilOperationSeparate(glFace, glStencilOp, glStencilOp, glStencilOp) with face set to FrontAndBack.

OpenGL API: glStencilOp

See Also

Reference