GL_VERTEXID(3G)

πŸ’– GL_VERTEXID πŸ’–

okay bestie so this is a page from the 3G manual section (that's the OpenGL-adjacent girlies, iykyk) and we're talking about one very specific little variable. she's small, she's an integer, she's the main character of your vertex shader. let's get into it ✨


🌸 NAME 🌸

gl_VertexID β€” literally just holds the index of the current vertex. that's it. that's her whole job πŸ’…


πŸ¦‹ DECLARATION πŸ¦‹

in int gl_VertexID ;

(no cap, that stray space before the semicolon is in the original. we respect the original here 🫢)


⭐ DESCRIPTION ⭐

so gl_VertexID is a vertex language input variable β€” a shader input, basically β€” and it holds an integer index for the vertex you're currently shading. think of it as the bouncer handing you a wristband number πŸŽ€

where does that number come from? two ways, bestie:

  • implicitly generated by glDrawArrays and other commands that do not reference the content of the GL_ELEMENT_ARRAY_BUFFER β€” you didn't ask for an index, the system just handed you one πŸ’«
  • explicitly generated from the content of the GL_ELEMENT_ARRAY_BUFFER, by commands such as glDrawElements β€” here the index comes straight out of the buffer 🌈

and here's the lil detail that matters: for the glDrawElements forms that take a basevertex, gl_VertexID will have this value added to the index from the buffer. so it's not just the raw buffer index β€” basevertex gets folded in. noted. memorised. obsessed πŸ”₯


✨ VERSION SUPPORT ✨

okay so the original had a whole giant table and we're gonna give you the same facts, just with more glitter and less spreadsheet energy πŸ’€ the columns are OpenGL Shading Language Versions, the row is gl_VertexID:

  • 1.10 β€” - (nope, not yet πŸ™ˆ)
  • 1.20 β€” - (still nope 😭)
  • 1.30 β€” βœ” (she's here!! πŸŽ‰)
  • 1.40 β€” βœ”
  • 1.50 β€” βœ”
  • 3.30 β€” βœ”
  • 4.00 β€” βœ”
  • 4.10 β€” βœ”
  • 4.20 β€” βœ”
  • 4.30 β€” βœ”
  • 4.40 β€” βœ”
  • 4.50 β€” βœ”

so tldr: gl_VertexID said "not me in 1.10 and 1.20" and then showed up for everything from 1.30 onward and never left. consistent queen πŸ‘‘


🧚 SEE ALSO 🧚

  • gl_InstanceID()

(her bestie. her ride-or-die. go read that one next, fr fr 🫢)


Copyright Β© 2011-2014 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 Β© 2011-2014 Khronos Group


okay that's the whole page bestie, go forth and index your vertices πŸ’…βœ¨

and a lil sign-off: this one came from [FIXME: source], dated 08/09/2021, and lives at GL_VERTEXID(3G) in the 3G manual. mwah πŸŽ€πŸ’–

πŸ“¦ where this page comes from