GLUNIFORM(3G)
okay bestie, welcome to GLUNIFORM(3G) β yes, the headerβs got a lil [FIXME: manual] stamp on it β and this is the page that tells you how to poke at uniform variables in the current program object π
π NAME π
the whole uniform-updating squad is here, and every single one of these cuties specifies the value of a uniform variable for the current program object:
- float scalars:
glUniform1f,glUniform2f,glUniform3f,glUniform4f - int scalars:
glUniform1i,glUniform2i,glUniform3i,glUniform4i - uint scalars:
glUniform1ui,glUniform2ui,glUniform3ui,glUniform4ui - float vectors:
glUniform1fv,glUniform2fv,glUniform3fv,glUniform4fv - int vectors:
glUniform1iv,glUniform2iv,glUniform3iv,glUniform4iv - uint vectors:
glUniform1uiv,glUniform2uiv,glUniform3uiv,glUniform4uiv - matrix vibe:
glUniformMatrix2fv,glUniformMatrix3fv,glUniformMatrix4fv,glUniformMatrix2x3fv,glUniformMatrix3x2fv,glUniformMatrix2x4fv,glUniformMatrix4x2fv,glUniformMatrix3x4fv,glUniformMatrix4x3fv
β¨ C SPECIFICATION β¨
hereβs the exact C shape of the whole squad β donβt let the wall of signatures scare you, itβs just every scalar/vector/matrix flavor doing its thing:
void glUniform1f(GLint location, GLfloat v0);
void glUniform2f(GLint location, GLfloat v0, GLfloat v1);
void glUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
void glUniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2,
GLfloat v3);
void glUniform1i(GLint location, GLint v0);
void glUniform2i(GLint location, GLint v0, GLint v1);
void glUniform3i(GLint location, GLint v0, GLint v1, GLint v2);
void glUniform4i(GLint location, GLint v0, GLint v1, GLint v2,
GLint v3);
void glUniform1ui(GLint location, GLuint v0);
void glUniform2ui(GLint location, GLuint v0, GLuint v1);
void glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2);
void glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2,
GLuint v3);
void glUniform1fv(GLint location, GLsizei count, const GLfloat *value);
void glUniform2fv(GLint location, GLsizei count, const GLfloat *value);
void glUniform3fv(GLint location, GLsizei count, const GLfloat *value);
void glUniform4fv(GLint location, GLsizei count, const GLfloat *value);
void glUniform1iv(GLint location, GLsizei count, const GLint *value);
void glUniform2iv(GLint location, GLsizei count, const GLint *value);
void glUniform3iv(GLint location, GLsizei count, const GLint *value);
void glUniform4iv(GLint location, GLsizei count, const GLint *value);
void glUniform1uiv(GLint location, GLsizei count, const GLuint *value);
void glUniform2uiv(GLint location, GLsizei count, const GLuint *value);
void glUniform3uiv(GLint location, GLsizei count, const GLuint *value);
void glUniform4uiv(GLint location, GLsizei count, const GLuint *value);
void glUniformMatrix2fv(GLint location, GLsizei count,
GLboolean transpose, const GLfloat *value);
void glUniformMatrix3fv(GLint location, GLsizei count,
GLboolean transpose, const GLfloat *value);
void glUniformMatrix4fv(GLint location, GLsizei count,
GLboolean transpose, const GLfloat *value);
void glUniformMatrix2x3fv(GLint location, GLsizei count,
GLboolean transpose, const GLfloat *value);
void glUniformMatrix3x2fv(GLint location, GLsizei count,
GLboolean transpose, const GLfloat *value);
void glUniformMatrix2x4fv(GLint location, GLsizei count,
GLboolean transpose, const GLfloat *value);
void glUniformMatrix4x2fv(GLint location, GLsizei count,
GLboolean transpose, const GLfloat *value);
void glUniformMatrix3x4fv(GLint location, GLsizei count,
GLboolean transpose, const GLfloat *value);
void glUniformMatrix4x3fv(GLint location, GLsizei count,
GLboolean transpose, const GLfloat *value);
π PARAMETERS π
locationβ specifies the location of the uniform variable to be modified.countβ for the vector (glUniform*v) commands, this is the number of elements that are to be modified. it should be1if the targeted uniform variable is not an array, and1or more if it is an array. for the matrix (glUniformMatrix*) commands, this is the number of matrices that are to be modified. it should be1if the targeted uniform variable is not an array of matrices, and1or more if it is an array of matrices.transposeβ for the matrix commands, this specifies whether to transpose the matrix as the values are loaded into the uniform variable.v0,v1,v2,v3β for the scalar commands, these specify the new values to be used for the specified uniform variable.valueβ for the vector and matrix commands, this specifies a pointer to an array ofcountvalues that will be used to update the specified uniform variable.
π¦ DESCRIPTION π¦
okay so glUniform modifies the value of a uniform variable or a uniform variable array. the location of the uniform variable to be modified is specified by location, which should be a value returned by glGetUniformLocation(). glUniform operates on the program object that was made part of current state by calling glUseProgram().
the commands glUniform{1|2|3|4}{f|i|ui} are used to change the value of the uniform variable specified by location using the values passed as arguments. the number specified in the command should match the number of components in the data type of the specified uniform variable (e.g., 1 for float, int, unsigned int, bool; 2 for vec2, ivec2, uvec2, bvec2, etc.). the suffix f indicates that floating-point values are being passed; the suffix i indicates that integer values are being passed; the suffix ui indicates that unsigned integer values are being passed, and this type should also match the data type of the specified uniform variable. the i variants of this function should be used to provide values for uniform variables defined as int, ivec2, ivec3, ivec4, or arrays of these. the ui variants of this function should be used to provide values for uniform variables defined as unsigned int, uvec2, uvec3, uvec4, or arrays of these. the f variants should be used to provide values for uniform variables of type float, vec2, vec3, vec4, or arrays of these. either the i, ui or f variants may be used to provide values for uniform variables of type bool, bvec2, bvec3, bvec4, or arrays of these. the uniform variable will be set to false if the input value is 0 or 0.0f, and it will be set to true otherwise.
all active uniform variables defined in a program object are initialized to 0 when the program object is linked successfully. they retain the values assigned to them by a call to glUniform until the next successful link operation occurs on the program object, when they are once again initialized to 0.
the commands glUniform{1|2|3|4}{f|i|ui}v can be used to modify a single uniform variable or a uniform variable array. these commands pass a count and a pointer to the values to be loaded into a uniform variable or a uniform variable array. a count of 1 should be used if modifying the value of a single uniform variable, and a count of 1 or greater can be used to modify an entire array or part of an array. when loading n elements starting at an arbitrary position m in a uniform variable array, elements m + n - 1 in the array will be replaced with the new values. if m + n - 1 is larger than the size of the uniform variable array, values for all array elements beyond the end of the array will be ignored. the number specified in the name of the command indicates the number of components for each element in value, and it should match the number of components in the data type of the specified uniform variable (e.g., 1 for float, int, bool; 2 for vec2, ivec2, bvec2, etc.). the data type specified in the name of the command must match the data type for the specified uniform variable as described previously for glUniform{1|2|3|4}{f|i|ui}.
for uniform variable arrays, each element of the array is considered to be of the type indicated in the name of the command (e.g., glUniform3f or glUniform3fv can be used to load a uniform variable array of type vec3). the number of elements of the uniform variable array to be modified is specified by count.
the commands glUniformMatrix{2|3|4|2x3|3x2|2x4|4x2|3x4|4x3}fv are used to modify a matrix or an array of matrices. the numbers in the command name are interpreted as the dimensionality of the matrix. the number 2 indicates a 2 Γ 2 matrix (i.e., 4 values), the number 3 indicates a 3 Γ 3 matrix (i.e., 9 values), and the number 4 indicates a 4 Γ 4 matrix (i.e., 16 values). non-square matrix dimensionality is explicit, with the first number representing the number of columns and the second number representing the number of rows. for example, 2x4 indicates a 2 Γ 4 matrix with 2 columns and 4 rows (i.e., 8 values). if transpose is GL_FALSE, each matrix is assumed to be supplied in column major order. if transpose is GL_TRUE, each matrix is assumed to be supplied in row major order. the count argument indicates the number of matrices to be passed. a count of 1 should be used if modifying the value of a single matrix, and a count greater than 1 can be used to modify an array of matrices.
πΈ NOTES πΈ
glUniform1iandglUniform1ivare the only two functions that may be used to load uniform variables defined as sampler types. loading samplers with any other function will result in aGL_INVALID_OPERATIONerror.- if
countis greater than1and the indicated uniform variable is not an array, aGL_INVALID_OPERATIONerror is generated and the specified uniform variable will remain unchanged. - other than the preceding exceptions, if the type and size of the uniform variable as defined in the shader do not match the type and size specified in the name of the command used to load its value, a
GL_INVALID_OPERATIONerror will be generated and the specified uniform variable will remain unchanged. - if
locationis a value other than-1and it does not represent a valid uniform variable location in the current program object, an error will be generated, and no changes will be made to the uniform variable storage of the current program object. iflocationis equal to-1, the data passed in will be silently ignored and the specified uniform variable will not be changed.
π ERRORS π
okay bestie, here's the thing β OpenGL is very dramatic about its error codes, and glUniform has a whole laundry list of ways to make it yell at you. Let's go through every single one so you're never blindsided fr fr π
GL_INVALID_OPERATIONβ thrown when there is literally no current program object. like... you forgot to bind one first? no program, no uniforms, no vibes. πGL_INVALID_OPERATIONβ thrown when the size of the uniform variable declared in the shader does not match the size indicated by theglUniformcommand. the shader said 4 and you sent 3? caught. not cute. πGL_INVALID_OPERATIONβ thrown if one of the signed or unsigned integer variants of this function is used to load a uniform variable of typefloat,vec2,vec3,vec4, or an array of these β or if one of the floating-point variants of this function is used to load a uniform variable of typeint,ivec2,ivec3,ivec4,unsigned int,uvec2,uvec3,uvec4, or an array of these. mismatched types are a hard no, periodt. πGL_INVALID_OPERATIONβ thrown if one of the signed integer variants of this function is used to load a uniform variable of typeunsigned int,uvec2,uvec3,uvec4, or an array of these. signedβunsigned? the audacity. π€GL_INVALID_OPERATIONβ thrown if one of the unsigned integer variants of this function is used to load a uniform variable of typeint,ivec2,ivec3,ivec4, or an array of these. same energy, reversed. read the room. β¨GL_INVALID_OPERATIONβ thrown if location is an invalid uniform location for the current program object and location is not equal to-1. (so yes,-1gets a lil grace pass β everything else has to be valid π₯)GL_INVALID_VALUEβ thrown if count is less than0. negative counts are giving "what was the thought process". π«GL_INVALID_OPERATIONβ thrown if count is greater than1and the indicated uniform variable is not an array variable. you can't batch-send a single scalar, bestie. πΈGL_INVALID_OPERATIONβ thrown if a sampler is loaded using a command other thanglUniform1iandglUniform1iv. samplers are picky and honestly iconic for it. π
lowkey memorize this list β the error checker will find you, and it will not be gentle π΅οΈββοΈ
π ASSOCIATED GETS π
wanna interrogate the state and see what's actually going on? these are your girls. go ask them everything π«Ά
glGet()with the argumentGL_CURRENT_PROGRAMglGetActiveUniform()with the handle of a program object and the index of an active uniform variableglGetUniform()with the handle of a program object and the location of a uniform variableglGetUniformLocation()with the handle of a program object and the name of a uniform variable
verifying your own work is main character energy, ngl π
π VERSION SUPPORT π
okay bestie this part is basically the compatibility vibe check π
the columns are all the OpenGL versions β 2.0, 2.1, 3.0, 3.1, 3.2, 3.3, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5 β and a β means "yep, this one's got it", while a - means "nope, not in that version, don't come for me". no cap, the unsigned-integer girlies (ui / uiv) lowkey didn't exist until 3.0, which is so real of them π
glUniform1fβ β in literally all twelve,2.0all the way through4.5β¨glUniform1fvβ β in all twelve,2.0β4.5β¨glUniform1iβ β in all twelve,2.0β4.5β¨glUniform1ivβ β in all twelve,2.0β4.5β¨glUniform1uiβ-in2.0and2.1, then β in everything from3.0onward through4.5πΈglUniform1uivβ-in2.0and2.1, then β from3.0through4.5πΈglUniform2fβ β in all twelve,2.0β4.5β¨glUniform2fvβ β in all twelve,2.0β4.5β¨glUniform2iβ β in all twelve,2.0β4.5β¨glUniform2ivβ β in all twelve,2.0β4.5β¨glUniform2uiβ-in2.0and2.1, then β from3.0through4.5πΈglUniform2uivβ-in2.0and2.1, then β from3.0through4.5πΈglUniform3fβ β in all twelve,2.0β4.5β¨glUniform3fvβ β in all twelve,2.0β4.5β¨glUniform3iβ β in all twelve,2.0β4.5β¨glUniform3ivβ β in all twelve,2.0β4.5β¨glUniform3uiβ-in2.0and2.1, then β from3.0through4.5πΈglUniform3uivβ-in2.0and2.1, then β from3.0through4.5πΈglUniform4fβ β in all twelve,2.0β4.5β¨glUniform4fvβ β in all twelve,2.0β4.5β¨glUniform4iβ β in all twelve,2.0β4.5β¨glUniform4ivβ β in all twelve,2.0β4.5β¨glUniform4uiβ-in2.0and2.1, then β from3.0through4.5πΈ
the pattern is giving main character consistency fr fr β everyf/fv/i/ivvariant is day-one iconic from2.0, and everyui/uivvariant showed up fashionably late at3.0π¦
glUniform4uivβ--βββββββββββ so like, nope in the first two columns, then slay in all ten of the rest β¨glUniformMatrix2fvββββββββββββββ full sweep, every single column, no notes πglUniformMatrix2x3fvβ-ββββββββββββ one lil-up front, then β all the way down πglUniformMatrix2x4fvβ-ββββββββββββ same vibe, first column says nope, rest say yes π¦glUniformMatrix3fvββββββββββββββ a clean twelve for twelve, we love a consistent icon πglUniformMatrix3x2fvβ-ββββββββββββ first column-, everything after is a β πΈglUniformMatrix3x4fvβ-ββββββββββββ same pattern bestie, don't overthink it πglUniformMatrix4fvββββββββββββββ all checks, all columns, all the time π₯glUniformMatrix4x2fvβ-ββββββββββββ leading-, then eleven βs, cute πglUniformMatrix4x3fvβ-ββββββββββββ last row, last pattern, we made it ππ«Ά
Ok so reading the grid: the columns run left to right across the version numbers2.02.13.03.13.23.34.04.14.24.34.44.5β a-means that version doesn't have it, aβmeans it does. That's the whole vibe check π«
π SEE ALSO π
Honestly just two, and they're both main characters:
glLinkProgram()glUseProgram()
π 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 (yes, again, the page really does it twice) π
Copyright Β© 2003-2005 3Dlabs Inc. Ltd. Copyright Β© 2010-2014 Khronos Group
and that's the whole page bestie, we ate and left absolutely no crumbs πβ¨ shoutout to the good people at [FIXME: source] for whatever the source field was gonna be, stamped 08/09/2021, filed under GLUNIFORM(3G) β go forth and set your uniforms, ily, bye ππ¦π
π¦ 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