GLGETUNIFORMLOCATION(3G)
π GLGETUNIFORMLOCATION(3G) β like, the whole glow-up
okay bestie, so this is the 3G manual page for glGetUniformLocation, and I promise it's gonna make sense. It's one little function that finds out where a uniform variable lives inside a program object. That's the whole vibe. Let's go. β¨
πΈ NAME πΈ
glGetUniformLocation β returns the location of a uniform variable. that's it, that's the tweet. π«Ά
β¨ C SPECIFICATION β¨
GLint glGetUniformLocation(GLuint program, const GLchar *name);
like, two arguments, one GLint back. iconic signature ngl.
π PARAMETERS π
programβ the program object you're querying. this is the thing you're asking questions about, bestie.nameβ points to a null terminated string holding the name of the uniform variable whose location you wanna know. yes, null terminated. yes, it matters. π
π¦ DESCRIPTION π¦
So glGetUniformLocation returns an integer that represents the location of a specific uniform variable within a program object.
Now the rules, and please read them because they will trip you up:
namemust be a null terminated string that contains no white space. none. zero. not a single space.namemust be an active uniform variable name inprogramthat is not a structure, an array of structures, or a subcomponent of a vector or a matrix.
And it returns -1 β the sad number, the "no thoughts head empty" number β if any of these happen:
namedoes not correspond to an active uniform variable inprogramnamestarts with the reserved prefix"gl_"nameis associated with an atomic counter or a named uniform block
Uniform variables that are structures or arrays of structures may be queried by calling glGetUniformLocation for each field within the structure. like, one field at a time, one call at a time. that's the move. π
The array element operator "[]" and the structure field operator "." may be used in name in order to select elements within an array or fields within a structure. Slay. But β and this is the catch β the result of using these operators is not allowed to be another structure, an array of structures, or a subcomponent of a vector or a matrix. so don't try it. π
Except! If the last part of name indicates a uniform variable array, the location of the first element of an array can be retrieved by using the name of the array, or by using the name appended by "[0]". okay so both of those work. both. cute.
Now the timing of it all, because this is the part people get wrong:
The actual locations assigned to uniform variables are not known until the program object is linked successfully. So like, don't come asking before the link. Periodt.
After linking has occurred, the command glGetUniformLocation can be used to obtain the location of a uniform variable. This location value can then be passed to glUniform() to set the value of the uniform variable, or to glGetUniform() in order to query the current value of the uniform variable. π―
After a program object has been linked successfully, the index values for uniform variables remain fixed until the next link command occurs. so they're stable, but only until you relink. keep that in mind.
And one last thing: uniform variable locations and values can only be queried after a link if the link was successful. failed link = no locations for you. π
π₯ ERRORS π₯
GL_INVALID_VALUEis generated ifprogramis not a value generated by OpenGL.GL_INVALID_OPERATIONis generated ifprogramis not a program object.GL_INVALID_OPERATIONis generated ifprogramhas not been successfully linked.
three ways to upset the driver. none of them are fun. π
π ASSOCIATED GETS π
glGetActiveUniform()with argumentsprogramand the index of an active uniform variableglGetProgram()with argumentsprogramandGL_ACTIVE_UNIFORMSorGL_ACTIVE_UNIFORM_MAX_LENGTHglGetUniform()with argumentsprogramand the name of a uniform variableglIsProgram()
β VERSION SUPPORT β
the original ships this as a big grid, but here's the tea in list form β glGetUniformLocation is supported in every single one of these OpenGL versions, all checkmarks, no gaps:
2.0β2.1β3.0β3.1β3.2β3.3β4.0β4.1β4.2β4.3β4.4β4.5β
the row in the original table is glGetUniformLocation, and the column header situation is "OpenGL Version" over "Function / Feature Name". that's the whole grid. ate. π
π SEE ALSO π
glLinkProgram()glUniform()
iykyk π¦
π COPYRIGHT π
Copyright Β© 2003-2005 3Dlabs Inc. Ltd. Copyright Β© 2010-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 Β© 2003-2005 3Dlabs Inc. Ltd. Copyright Β© 2010-2014 Khronos Group
okay that's the whole page bestie, you're officially educated β¨ stay hydrated, link your programs, and remember: no white space in name, ever. mwah π
sign-off szn: this one came from[FIXME: source]and it's dated08/09/2021β that's the version and date on the original footer, so now you know exactly when this lore dropped. π
π¦ where this page comes from
- centos-stream 9: gl-manpages 1.1-24.20190306.el9 Β· MIT and Open Publication
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms