1
1
Fork 0
mirror of https://github.com/QB64Official/qb64.git synced 2024-07-07 20:20:25 +00:00
qb64/internal/help/_gltencilFunc.md

4.8 KiB

_glStencilFunc: set front and back function and reference value for stencil testing

Syntax

SUB _glStencilFunc (BYVAL func AS _UNSIGNED LONG, BYVAL ref AS LONG, BYVAL mask AS _UNSIGNED LONG) void _glStencilFunc(GLenum func, GLint ref, GLuint mask);

; func

Specifies the test function. Eight symbolic constants are valid: _GL_NEVER, _GL_LESS, _GL_LEQUAL, _GL_GREATER, _GL_GEQUAL, _GL_EQUAL, _GL_NOTEQUAL, and _GL_ALWAYS. The initial value is _GL_ALWAYS. ; ref Specifies the reference value for the stencil test. ref is clamped to the range [0, 2n - 1, where n is the number of bitplanes in the stencil buffer. The initial value is 0. ; mask Specifies a mask that is ANDed with both the reference value and the stored stencil value when the test is done. The initial value is all 1's.

Description

Stenciling, like depth-buffering, enables and disables drawing on a per-pixel basis. Stencil planes are first drawn into using GL drawing primitives, then geometry and images are rendered 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 reference value and the value in the stencil buffer. To enable and disable the test, call _glEnable and _glDisable with argument _GL_STENCIL_TEST. To specify actions based on the outcome of the stencil test, call _glStencilOp or _glStencilOpSeparate.

There can be two separate sets of func, ref, and mask parameters; one affects back-facing polygons, and the other affects front-facing polygons as well as other non-polygon primitives. _glStencilFunc sets both front and back stencil state to the same values. Use _glStencilFuncSeparate to set front and back stencil state to different values.

func is a symbolic constant that determines the stencil comparison function. It accepts one of eight values, shown in the following list. ref is an integer reference value that is used in the stencil comparison. It is clamped to the range [0, 2n - 1], where n is the number of bitplanes in the stencil buffer. mask is bitwise ANDed with both the reference value and the stored stencil value, with the ANDed values participating in the comparison.

If stencil represents the value stored in the corresponding stencil buffer location, the following list shows the effect of each comparison function that can be specified by func. Only if the comparison succeeds is the pixel passed through to the next stage in the rasterization process (see _glStencilOp). All tests treat stencil values as unsigned integers in the range [0, 2n - 1], where n is the number of bitplanes in the stencil buffer.

The following values are accepted by func:

; _GL_NEVER

Always fails. ; _GL_LESS Passes if ( ref & mask ) < ( stencil & mask ). ; _GL_LEQUAL Passes if ( ref & mask ) <= ( stencil & mask ). ; _GL_GREATER Passes if ( ref & mask ) > ( stencil & mask ). ; _GL_GEQUAL Passes if ( ref & mask ) >= ( stencil & mask ). ; _GL_EQUAL Passes if ( ref & mask ) = ( stencil & mask ). ; _GL_NOTEQUAL Passes if ( ref & mask ) != ( stencil & mask ). ; _GL_ALWAYS Always passes.

Notes

Initially, the stencil test is disabled. If there is no stencil buffer, no stencil modification can occur and it is as if the stencil test always passes.

_glStencilFunc is the same as calling _glStencilFuncSeparate with face set to _GL_FRONT_AND_BACK.

Error(s)

_GL_INVALID_ENUM is generated if func is not one of the eight accepted values.

Use With

_glGet with argument _GL_STENCIL_FUNC, _GL_STENCIL_VALUE_MASK, _GL_STENCIL_REF, _GL_STENCIL_BACK_FUNC, _GL_STENCIL_BACK_VALUE_MASK, _GL_STENCIL_BACK_REF, or _GL_STENCIL_BITS

_glIsEnabled with argument _GL_STENCIL_TEST

See Also

_GL _glEnable, _glLogicOp, _glStencilFuncSeparate, _glStencilMask, _glStencilMaskSeparate, _glStencilOp, _glStencilOpSeparate