GLSELECTBUFFER(3G)

πŸ“¦ version 1.1, in centos-stream 9, fedora 43, fedora 44

✨ glSelectBuffer β€” bestie, let's set up a whole buffer for selection mode values ✨

okay so this is a 3G manual page, aka OpenGL-adjacent chaos, and it's literally called glSelectBuffer πŸ’–. She sets up the spot where selection-mode values get dumped. That's it, that's the job, and she eats.


πŸ“œ C SPECIFICATION πŸ“œ

void glSelectBuffer( GLsizei size,
                     GLuint *buffer )

no cap, that's the whole signature. two args, both doing the most.


πŸŽ€ PARAMETERS πŸŽ€

  • size β€” the size of buffer, bestie. how much room we're giving her.
  • buffer β€” this one returns the selection data. she's not just sitting there, she's giving back. 🫢

πŸ’– DESCRIPTION πŸ’–

okay so glSelectBuffer has two arguments: buffer is a pointer to an array of unsigned integers, and size indicates the size of that array. And buffer is the one that returns values from the name stack (peep glInitNames, glLoadName, glPushName) when the rendering mode is GL_SELECT (peep glRenderMode). 🌈

THE RULES, and I mean the rules: glSelectBuffer must be issued before selection mode is enabled, and it must not be issued while the rendering mode is GL_SELECT. do not play with this. fr fr. πŸ’€

A programmer can use selection to figure out which primitives are drawn into some region of a window. That region is defined by the current modelview and perspective matrices. main character region energy. ✨

In selection mode, no pixel fragments are produced from rasterization. not a single one. Instead, if a primitive or a raster position intersects the clipping volume defined by the viewing frustum and the user-defined clipping planes, this primitive causes a selection hit. (And with polygons? No hit occurs if the polygon is culled. πŸ’…)

When a change is made to the name stack, or when glRenderMode is called, a hit record is copied to buffer if any hits have occurred since the last such event (name stack change or glRenderMode call). And the hit record is, in order:

  1. the number of names in the name stack at the time of the event,
  2. followed by the minimum and maximum depth values of all vertices that hit since the previous event,
  3. followed by the name stack contents, bottom name first.

Depth values (which are in the range [0,1]) are multiplied by 2^32 - 1 before being placed in the hit record. yes, that number. big number. iconic. πŸ”₯

An internal index into buffer is reset to 0 whenever selection mode is entered. Each time a hit record is copied into buffer, the index is incremented to point to the cell just past the end of the block of names β€” that is, to the next available cell. πŸ“

If the hit record is larger than the number of remaining locations in buffer, as much data as can fit is copied, and the overflow flag is set. overflow. not cute. be careful. 😭

If the name stack is empty when a hit record is copied, that record consists of 0 followed by the minimum and maximum depth values.

To exit selection mode, call glRenderMode with an argument other than GL_SELECT. Whenever glRenderMode is called while the render mode is GL_SELECT, it:

  • returns the number of hit records copied to buffer,
  • resets the overflow flag and the selection buffer pointer,
  • and initializes the name stack to be empty.

and if the overflow bit was set when glRenderMode was called, a negative hit record count is returned. negative. as in, bad vibes. as in, the count is telling you it overflowed. πŸ’€


🌸 NOTES 🌸

  • The contents of buffer are undefined until glRenderMode is called with an argument other than GL_SELECT. undefined means undefined, bestie, don't read it and act surprised. πŸ™ˆ
  • glBegin/glEnd primitives and calls to glRasterPos can result in hits. sneaky little hits. ✨

πŸ’€ ERRORS πŸ’€

  • GL_INVALID_VALUE is generated if size is negative. negative size? jail.
  • GL_INVALID_OPERATION is generated if glSelectBuffer is called while the render mode is GL_SELECT, or if glRenderMode is called with argument GL_SELECT before glSelectBuffer is called at least once. order matters, periodt.
  • GL_INVALID_OPERATION is generated if glSelectBuffer is executed between the execution of glBegin and the corresponding execution of glEnd. no glSelectBuffer mid-primitive. absolutely not.

πŸ¦‹ ASSOCIATED GETS πŸ¦‹

you can go get these, she's not hiding:

  • glGet with argument GL_NAME_STACK_DEPTH
  • glGet with argument GL_SELECTION_BUFFER_SIZE
  • glGetPointerv with argument GL_SELECTION_BUFFER_POINTER

πŸ‘‘ SEE ALSO πŸ‘‘

  • glFeedbackBuffer(3G)
  • glInitNames(3G)
  • glLoadName(3G)
  • glPushName(3G)
  • glRenderMode(3G)

go read those too, they're all in the same friend group. 🫢


and that's the whole page, bestie!! πŸ’– this was the GLSELECTBUFFER(3G) page from the 3G manual section β€” so if you ever need to cite her, it's glSelectBuffer, section 3G, page name GLSELECTBUFFER(3G). no date on this one, just the name, so that's what we're rolling with. now go call glRenderMode and exit selection mode like a responsible icon. mwah. πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from