GLDRAWRANGEELEMENTS(3G)

πŸ“¦ version 24.3.3, in opensuse-leap 16.0

πŸ’… GLDRAWRANGEELEMENTS (3G) πŸ’…

okay so bestie, this is a page from the 3G manual β€” the OpenGL one β€” and it's literally the whole vibe of "draw a bunch of shapes, but tell the driver up front which slice of your index array you're gonna touch." no cap, it's a glow-up of glDrawElements with ✨boundaries✨. let's get into it 🫢


🌈 C SPECIFICATION 🌈

void glDrawRangeElements( GLenum mode,
                          GLuint start,
                          GLuint end,
                          GLsizei count,
                          GLenum type,
                          const GLvoid *indices )

that's the whole signature, character for character, don't come for me 😌


πŸŽ€ PARAMETERS πŸŽ€

  • mode β€” tells it what kind of primitives to render, like, what shape are we even making here. the accepted symbolic constants are GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_TRIANGLES, GL_QUAD_STRIP, GL_QUADS, and GL_POLYGON. that's the whole guest list, nobody else gets in πŸ’…
  • start β€” the minimum array index contained in indices. the floor, basically. 🧚
  • end β€” the maximum array index contained in indices. the ceiling, the final boss. πŸ‘‘
  • count β€” how many elements are gonna be rendered. the headcount for the party πŸŽ‰
  • type β€” the type of the values in count. must be one of GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, or GL_UNSIGNED_INT. those three, periodt. no other types allowed πŸ™…β€β™€οΈ
  • indices β€” a pointer to the location where the indices are stored. like, "here's where the receipts live" πŸ“

🌸 DESCRIPTION 🌸

so glDrawRangeElements is a restricted form of glDrawElements. mode, start, end, and count match the corresponding arguments to glDrawElements, but with one extra rule on top: all values in the arrays count must lie between start and end, inclusive. that's the whole gimmick, and honestly? it ate. πŸ”₯

implementations denote recommended maximum amounts of vertex and index data, and you can query those by calling glGet with argument GL_MAX_ELEMENTS_VERTICES and GL_MAX_ELEMENTS_INDICES. so if endβˆ’start+1 is greater than the value of GL_MAX_ELEMENTS_VERTICES, or if count is greater than the value of GL_MAX_ELEMENTS_INDICES, then the call may operate at reduced performance. not an error, just... the vibe check failing 😭

and like, there is no requirement that all vertices in the range [start, end] be referenced. so yeah, you can be lazy about it. however β€” the implementation may partially process unused vertices, and that reduces performance from what you could've achieved with an optimal index set. so maybe don't be lazy? your call bestie πŸ’€

when glDrawRangeElements is called, it uses start sequential elements from an enabled array, starting at count, to construct a sequence of geometric primitives. mode specifies what kind of primitives are constructed, and how the array elements construct these primitives. if more than one array is enabled, each is used. and listen β€” if GL_VERTEX_ARRAY is not enabled, no geometric primitives are constructed. like, nothing happens. silence. crickets πŸ¦—

vertex attributes that are modified by glDrawRangeElements have an unspecified value after glDrawRangeElements returns. for example, if GL_COLOR_ARRAY is enabled, the value of the current color is undefined after glDrawRangeElements executes. not a typo, not a bug, just how it is πŸ™ˆ attributes that aren't modified maintain their previous values, so at least those are safe 🫢


✨ NOTES ✨

  • glDrawRangeElements is available only if the GL version is 1.2 or greater. old-GL girlies, this one's not for you πŸ’”
  • glDrawRangeElements is included in display lists. and not just the call β€” if glDrawRangeElements is entered into a display list, the necessary array data (determined by the array pointers and enables) is also entered into the display list. so the whole fit gets archived πŸ“Έ
  • because the array pointers and enables are client-side state, their values affect display lists when the lists are created, not when the lists are executed. read that twice, it's important, iykyk πŸ‘€

πŸ’€ ERRORS πŸ’€

okay bestie, this is the part where you pay attention:

  • it is an error for indices to lie outside the range [start, end], but implementations may not check for this situation. and such indices cause implementation-dependent behavior. so like... you're on your own, and nobody's coming to save you 😭
  • GL_INVALID_ENUM is generated if mode is not an accepted value.
  • GL_INVALID_VALUE is generated if count is negative. (negative count?? girl. no. πŸ™…β€β™€οΈ)
  • GL_INVALID_VALUE is generated if end < start. the floor can't be above the ceiling, bestie, that's not how buildings work πŸ—οΈ
  • GL_INVALID_OPERATION is generated if glDrawRangeElements is executed between the execution of glBegin and the corresponding glEnd. like, not inside a glBegin/glEnd sandwich. that's illegal 🚫

πŸ” ASSOCIATED GETS πŸ”

  • glGet with argument GL_MAX_ELEMENTS_VERTICES
  • glGet with argument GL_MAX_ELEMENTS_INDICES

that's the tea you can go query β˜•


πŸ¦‹ SEE ALSO πŸ¦‹

  • glArrayElement(3G)
  • glColorPointer(3G)
  • glDrawArrays(3G)
  • glDrawElements(3G)
  • glEdgeFlagPointer(3G)
  • glGetPointerv(3G)
  • glIndexPointer(3G)
  • glInterleavedArrays(3G)
  • glNormalPointer(3G)
  • glTexCoordPointer(3G)
  • glVertexPointer(3G)

the whole friend group, go read up πŸ’–


and that's the page!! mwah πŸ’‹ this was GLDRAWRANGEELEMENTS(3G), living in the 3G manual β€” standard-issue version/source line energy, no fancy date on this one, so we're keeping it iconic and undated. slay, go draw some triangles in a very well-defined range. periodt. πŸŽ€βœ¨πŸ‘‘

πŸ“¦ where this page comes from