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, and GL_ALWAYS. the initial value is GL_ALWAYS. (yes, eight. not seven, not nine. eight. πŸ’€)
  • ref β€” the reference value for the stencil test. ref is clamped to the range 0 to 2 n - 1, where n is the number of bitplanes in the stencil buffer. the initial value is 0.
  • 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 calling glStencilFuncSeparate() with face set to GL_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 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

πŸ’œ 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 β†’ βœ” in 2.0, βœ” in 2.1, βœ” in 3.0, βœ” in 3.1, βœ” in 3.2, βœ” in 3.3, βœ” in 4.0, βœ” in 4.1, βœ” in 4.2, βœ” in 4.3, βœ” in 4.4, and βœ” in 4.5

twelve for twelve. she ate and left absolutely no crumbs πŸ‘‘

🐚 SEE ALSO

glBlendFunc(), glDepthFunc(), glEnable(), glLogicOp(), glStencilFuncSeparate(), glStencilMask(), glStencilMaskSeparate(), glStencilOp(), glStencilOpSeparate()

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 Β© 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