GLDEPTHFUNC(3G)

πŸ’– NAME πŸ’–

glDepthFunc β€” bestie, this is the one that picks which depth comparison rule your depth buffer uses πŸŽ€ (it's from the 3G manual, the OpenGL girlies, iykyk)


✨ C SPECIFICATION ✨

void glDepthFunc(GLenum func);

🌸 PARAMETERS 🌸

  • func β€” the depth comparison function, aka the whole vibe check of this call. You pass one of these symbolic constants: GL_NEVER, GL_LESS, GL_EQUAL, GL_LEQUAL, GL_GREATER, GL_NOTEQUAL, GL_GEQUAL, and GL_ALWAYS. The initial value is GL_LESS β€” that's the default she ships with πŸ’…

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so glDepthFunc decides the function used to compare every incoming pixel's depth value against the depth value already sitting in the depth buffer. Iconic. But heads up β€” the comparison only happens if depth testing is enabled. (See glEnable() and

glDisable of GL_DEPTH_TEST.) Yeah, that sentence made me do a double take too 😭

func sets the conditions under which the pixel actually gets drawn. The comparison functions, ranked by how much they let through:

  • GL_NEVER β€” never passes. not once. zero. nothing. πŸ’€
  • GL_LESS β€” passes if the incoming depth value is less than the stored depth value.
  • GL_EQUAL β€” passes if the incoming depth value is equal to the stored depth value.
  • GL_LEQUAL β€” passes if the incoming depth value is less than or equal to the stored depth value.
  • GL_GREATER β€” passes if the incoming depth value is greater than the stored depth value.
  • GL_NOTEQUAL β€” passes if the incoming depth value is not equal to the stored depth value.
  • GL_GEQUAL β€” passes if the incoming depth value is greater than or equal to the stored depth value.
  • GL_ALWAYS β€” always passes. her door is open, everybody come in πŸ‘‘

The initial value of func is GL_LESS. And initially, depth testing is disabled. If depth testing is disabled, or if there's just no depth buffer at all, it behaves as if the depth test always passes β€” yes, even with GL_NEVER set, because the test isn't even running, bestie πŸ™ˆ


πŸ’œ NOTES πŸ’œ

Real talk: even if the depth buffer exists and the depth mask is non-zero, the depth buffer is not updated when the depth test is disabled. Like, it's there, it's ready, and it's getting ignored. To unconditionally write to the depth buffer, you gotta enable the depth test and set it to GL_ALWAYS. That's the move 😌


πŸ”₯ ERRORS πŸ”₯

  • GL_INVALID_ENUM is generated if func is not an accepted value. So like… don't make up constants, she'll know 🫢

🌈 ASSOCIATED GETS 🌈

  • glGet() with argument GL_DEPTH_FUNC
  • glIsEnabled() with argument GL_DEPTH_TEST

⭐ VERSION SUPPORT ⭐

glDepthFunc / feature name: glDepthFunc β€” she's supported across the whole OpenGL glow-up, every single column checked βœ”:

  • 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 β€” βœ”

🧚 SEE ALSO 🧚

  • glDepthRange()
  • glEnable()
  • glPolygonOffset()

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


ngl that's the whole page, no cap. stay hydrated and go set your depth func to something cute πŸ’–

mwah πŸ’‹ β€” this one's sourced from [FIXME: source] and dated 08/09/2021, and yeah the manual page is literally called GLDEPTHFUNC(3G) if anyone asks πŸŽ€

πŸ“¦ where this page comes from