GLSTENCILFUNC(3G)
π GLSTENCILFUNC(3G) β the stencil vibe check
okay so this is the manual page for glStencilFunc out of section 3G, and the manual name is literally [FIXME: manual] (yes bestie, they shipped a FIXME in the title, we love a lowkey chaotic icon). anyway. sit down, hydrate, and let's talk about stencil testing π«Ά
πΈ NAME
glStencilFunc β set front and back function and reference value for stencil testing. that's the whole name section, slay.
β¨ C SPECIFICATION
void glStencilFunc(GLenum func, GLint ref, GLuint mask);
π PARAMETERS
funcβ the test function, i.e. which comparison the stencil test is gonna run. there are exactly eight symbolic constants that are valid:GL_NEVER,GL_LESS,GL_LEQUAL,GL_GREATER,GL_GEQUAL,GL_EQUAL,GL_NOTEQUAL, andGL_ALWAYS. the initial value isGL_ALWAYS. (yes, eight. not seven, not nine. eight. π)refβ the reference value for the stencil test.refis clamped to the range0to2 n - 1, where n is the number of bitplanes in the stencil buffer. the initial value is0.maskβ a mask that gets ANDed with both the reference value and the stored stencil value when the test is done. the initial value is all 1's. all of them. yes ma'am.
π¦ DESCRIPTION
okay so stenciling β like depth-buffering β enables and disables drawing on a per-pixel basis. stencil planes are first drawn into using GL drawing primitives, and 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. it's giving "the screen is a club and the stencil buffer is the bouncer" π
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() if you want to set front and back stencil state to different values, because sometimes the front and the back are simply not the same person π§
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 to 2 n - 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 to 2 n - 1, where n is the number of bitplanes in the stencil buffer.
π the eight values func accepts
GL_NEVERβ always fails. flop era. does not pass go, does not collect $200, does not render a single pixel π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. main character energy, never misses β¨
β 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 callingglStencilFuncSeparate()with face set toGL_FRONT_AND_BACK.
π₯ ERRORS
GL_INVALID_ENUM is generated if func is not one of the eight accepted values. so like. don't get creative in there, bestie, there are exactly eight slots and you must pick one π
π ASSOCIATED GETS
glGet()with argumentGL_STENCIL_FUNC,GL_STENCIL_VALUE_MASK,GL_STENCIL_REF,GL_STENCIL_BACK_FUNC,GL_STENCIL_BACK_VALUE_MASK,GL_STENCIL_BACK_REF, orGL_STENCIL_BITSglIsEnabled()with argumentGL_STENCIL_TEST
π VERSION SUPPORT
the original ships this as a big grid headed OpenGL Version, with a Function / Feature Name column reading glStencilFunc and a check mark in every single column. so, transcribed for you with identical energy:
- OpenGL Version columns:
2.0,2.1,3.0,3.1,3.2,3.3,4.0,4.1,4.2,4.3,4.4,4.5 - Function / Feature Name:
glStencilFuncββin2.0,βin2.1,βin3.0,βin3.1,βin3.2,βin3.3,βin4.0,βin4.1,βin4.2,βin4.3,βin4.4, andβin4.5
twelve for twelve. she ate and left absolutely no crumbs π
π SEE ALSO
glBlendFunc(), glDepthFunc(), glEnable(), glLogicOp(), glStencilFuncSeparate(), glStencilMask(), glStencilMaskSeparate(), glStencilOp(), glStencilOpSeparate()
π COPYRIGHT
Copyright Β© 1991-2006 Silicon Graphics, Inc. Copyright Β© 2010-2014 Khronos Group. This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/.
π COPYRIGHT (yeah there are two, don't @ me)
Copyright Β© 1991-2006 Silicon Graphics, Inc. Copyright Β© 2010-2014 Khronos Group
and that's the page!! source says [FIXME: source], dated 08/09/2021, filed under GLSTENCILFUNC(3G) β so go forth, mask your bits, clamp your refs, and stencil responsibly, bestie π¦π
π¦ where this page comes from
- centos-stream 9: gl-manpages 1.1-24.20190306.el9 Β· MIT and Open Publication
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms