GLSTENCILFUNCSEPARAT(3G)

πŸ‘‘ NAME πŸ‘‘

okay so bestie, gather round, because this is the glow-up of glStencilFuncSeparate β€” and yes, the page title up top is literally GLSTENCILFUNCSEPARAT(3G) (the header cut the E off, which is honestly iconic of it 😭), and the manual it lives in is the [FIXME: manual] one. We move.

It sets the front and/or back function and reference value for stencil testing. That's the whole vibe. πŸ’…


🌸 C SPECIFICATION 🌸

void glStencilFuncSeparate(GLenum face, GLenum func, GLint ref,
                           GLuint mask);

πŸŽ€ PARAMETERS πŸŽ€

  • face β€” which stencil state is getting updated: front, back, or both. Three symbolic constants are valid here: GL_FRONT, GL_BACK, and GL_FRONT_AND_BACK. Pick your fighter 🫢
  • func β€” the test function, bestie. 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. (Yep, eight. Count 'em. I'll wait β˜•)
  • ref β€” the reference value for the stencil test. ref gets 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 the ones. Every single one of them. πŸ”₯

πŸ¦‹ DESCRIPTION πŸ¦‹

Stenciling, like depth-buffering, enables and disables drawing on a per-pixel basis β€” which is genuinely so powerful, no cap. 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 multipass rendering algorithms to achieve special effects, such as decals, outlining, and constructive solid geometry rendering. It's giving layers. It's giving range. 🎨

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, as if glStencilFuncSeparate() were called with face set to GL_FRONT_AND_BACK. Twins, basically. πŸ‘―β€β™€οΈ

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 following values are accepted by func:

  • GL_NEVER β€” Always fails. Down bad. πŸ’€
  • 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, truly. ✨

πŸ’œ NOTES πŸ’œ

Initially, the stencil test is disabled β€” put that in your notes app fr fr. If there is no stencil buffer, no stencil modification can occur and it is as if the stencil test always passes.


🌈 ERRORS 🌈

  • GL_INVALID_ENUM is generated if func is not one of the eight accepted values. So like, don't invent a ninth one. I'm begging. πŸ™ˆ

⭐ 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 🧚

glStencilFuncSeparate is supported in every version listed here β€” yes, all of them, a full sweep, we love a consistent queen πŸ‘‘:

  • OpenGL 2.0 β€” βœ”
  • OpenGL 2.1 β€” βœ”
  • OpenGL 3.0 β€” βœ”
  • OpenGL 3.1 β€” βœ”
  • OpenGL 3.2 β€” βœ”
  • OpenGL 3.3 β€” βœ”
  • OpenGL 4.0 β€” βœ”
  • OpenGL 4.1 β€” βœ”
  • OpenGL 4.2 β€” βœ”
  • OpenGL 4.3 β€” βœ”
  • OpenGL 4.4 β€” βœ”
  • OpenGL 4.5 β€” βœ”

(The original packs all this into a big Function / Feature Name grid, but the takeaway is the same: glStencilFuncSeparate ate and left no crumbs. πŸ“)


πŸ“ SEE ALSO πŸ“

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


Copyright Β© 2006 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. http://opencontent.org/openpub/.

Copyright Β© 1991-2006 Silicon Graphics, Inc.


okay that's the whole page, bestie β€” every flag, every number, every checkmark, nothing skipped, periodt. 🫢

and for the cute sign-off: this came from [FIXME: source], dated 08/09/2021, filed under GLSTENCILFUNCSEPARAT(3G) β€” go stencil something gorgeous with it. πŸ’…βœ¨

πŸ“¦ where this page comes from