GLGETPROGRAMRESOURCE(3G)

πŸ’… GLGETPROGRAMRESOURCE(3G) β€” like, the glGetProgramResourceLocationIndex of it all

okay bestie, so this is a page out of the 3G manual (yes, the OpenGL one) and it's literally about asking your shader program "hey girl, where does this variable live in your fragment color output?" πŸŽ€ buckle up.


✨ NAME ✨

glGetProgramResourceLocationIndex β€” query the fragment color index of a named variable within a program. that's it, that's the whole vibe πŸ¦‹


🌸 C SPECIFICATION 🌸

GLint glGetProgramResourceLocationIndex(GLuint program,
                                        GLenum programInterface,
                                        const char * name);

πŸ’– PARAMETERS πŸ’–

  • program β€” the name of a program object whose resources you wanna query. like, which program are we snooping through πŸ”
  • programInterface β€” a token identifying the interface within program that contains the resource named name. the little doorway you're peeking through πŸšͺ
  • name β€” the name of the resource whose location you're asking about. the actual variable, by name, periodt.

πŸ‘‘ DESCRIPTION πŸ‘‘

so glGetProgramResourceLocationIndex returns the fragment color index assigned to the variable named name in interface programInterface of program object program. πŸ’«

but bestie, the rules: program must be the name of a program that has been linked successfully. no linked program, no answers, i don't make the rules. and programInterface must be GL_PROGRAM_OUTPUT. that's the only accepted one here, no cap.

the value -1 gets returned if an error happens, if name does not identify an active variable on programInterface, or if name identifies an active variable that does not have a valid location assigned, as described above. sad but true 😭

the locations returned by these commands are the same locations returned when querying the GL_LOCATION and GL_LOCATION_INDEX resource properties. consistency, we love to see it πŸ’…


🌈 so when does a string actually match an active variable?

a string you hand to glGetProgramResourceLocationIndex is considered to match an active variable if β€” and only if, iykyk:

  • the string exactly matches the name of the active variable 🎯
  • if the string identifies the base name of an active array, where the string would exactly match the name of the variable if the suffix "[0]" were appended to the string 🧚
  • if the string identifies an active element of the array, where the string ends with the concatenation of the "[" character, an integer with no "+" sign, extra leading zeroes, or whitespace identifying an array element, and the "]" character, the integer is less than the number of active elements of the array variable, and where the string would exactly match the enumerated name of the array if the decimal integer were replaced with zero. (i know. read it twice. it's giving very specific, and that's on purpose πŸ’€)

any other string is considered not to identify an active variable. sorry babe. πŸ™ˆ

if the string specifies an element of an array variable, glGetProgramResourceLocation returns the location assigned to that element. and if it specifies the base name of an array, it identifies the resources associated with the first element of the array. first come, first served ✨

⚠️ heads up: yes, that second-to-last paragraph really does say glGetProgramResourceLocation β€” that's how it's written on the page, so i'm keeping it exactly. not my typo to fix, bestie 🫢

πŸ’€ ERRORS πŸ’€

  • GL_INVALID_VALUE is generated if program is not the name of an existing program object. (it's not a real one, girl πŸ’€)
  • GL_INVALID_ENUM is generated if programInterface is not one of the accepted interface types. wrong token, wrong door 🚫
  • GL_INVALID_OPERATION is generated if program has not been linked successfully. link it first, then come talk to me 😀

🌟 VERSION SUPPORT 🌟

here's the whole roster, 2.0 all the way to 4.5, and the glGetProgramResourceLocationIndex row goes like this:

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

so basically: nothing, nothing, nothing, nothing… and then 4.3 shows up and slays πŸ”₯πŸ‘‘ it's a 4.3+ girlie, fr fr.


πŸ¦‹ SEE ALSO πŸ¦‹

  • glGetProgramResourceName()
  • glGetProgramResourceIndex()
  • glGetProgramResource()
  • glGetProgramResourceLocationIndex() (yes, it references itself. main character energy, honestly πŸ‘‘)

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


okay that's the whole page, you ate that πŸ’… and for the cute little sign-off β€” the footer says the source is [FIXME: source], dated 08/09/2021, closing out under the GLGETPROGRAMRESOURCE(3G) banner. stan a slightly unfinished FIXME, honestly. go query those locations, bestie 🌸✨🫢

πŸ“¦ where this page comes from