glUniform
Name
glUniform1f, glUniform2f, glUniform3f, glUniform4f, glUniform1i, glUniform2i, glUniform3i, glUniform4i, glUniform1fv, glUniform2fv, glUniform3fv, glUniform4fv, glUniform1iv, glUniform2iv, glUniform3iv, glUniform4iv, glUniformMatrix2fv, glUniformMatrix3fv, glUniformMatrix4fv Specify the value of a uniform variable for the current program object
C Specification
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)
Parameters
location | Specifies the location of the uniform variable to be modified. | v0, v1, v2, v3 | Specify the new values to be used for the specified uniform variable. |
C Specification
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)
Parameters
location | Specifies the location of the uniform value to be modified. | count | Specifies the number of elements that are to be modified (this should be 1 if the targeted uniform variable is not an array, 1 or more if it is an array). | value | Specifies a pointer to an array of count values that are used to update the specified uniform variable. |
C Specification
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)
Parameters
location | Specifies the location of the uniform value to be modified. | count | Specifies the number of elements that are to be modified (this should be 1 if the targeted uniform variable is not an array, 1 or more if it is an array). | transpose | Specifies whether to transpose the matrix as the values are loaded into the uniform variable. | value | Specifies a pointer to an array of count values that are used to update the specified uniform variable. |
Description
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 with glUseProgram.
The commands glUniform{1|2|3|4}{f|i} 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, bool; 2 for vec2, ivec2, bvec2). The suffix f means that floating-point values are being passed; the suffix i means that 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 provide values for uniform variables defined as int, ivec2, ivec3, ivec4, or arrays of these. The f variants provide values for uniform variables of type float, vec2, vec3, vec4, or arrays of these. Either the i or the f variants can provide values for uniform variables of type bool, bvec2, bvec3, bvec4, or arrays of these. The uniform variable is set to false if the input value is 0 or 0.0f, and it is 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 with 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}v 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. Use a count of 1 if modifying the value of a single uniform variable, and a count of 1 or greater if modifying an entire array or part of an array. When n elements starting at an arbitrary position m in a uniform variable array are loaded, elements m + n 1 in the array are 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 are 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). 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}.
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 glUniformFloatMatrix{2|3|4}fv modify a matrix or an array of matrices. The number in the command name is interpreted as the dimensionality of the matrix. The number 2 indicates a 2 x 2 matrix (i.e., 4 values), the number 3 indicates a 3 x 3 matrix (i.e., 9 values), and the number 4 indicates a 4 x 4 matrix (i.e., 16 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 specifies the number of matrices to be passed. Use a count of 1 if modifying the value of a single matrix, and a count greater than 1 if modifying an array of matrices.
Notes
glUniform is available only if the GL version is 2.0 or greater.
glUniform1i and glUniform1iv are the only two functions that may load uniform variables defined as sampler types. Loading samplers with any other function results in a GL_INVALID_OPERATION error.
If count is greater than 1 and the indicated uniform variable is not an array, a GL_INVALID_OPERATION error is generated and the specified uniform variable remains 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 a value for the uniform variable, a GL_INVALID_OPERATION error is generated and the specified uniform variable remains unchanged.
If location is a value other than 1 and it does not represent a valid uniform variable location in the current program object, an error is generated, and no changes are made to the uniform variable storage of the current program object. If location is equal to 1, the data passed in is silently ignored and the specified uniform variable is unchanged.
Errors
GL_INVALID_OPERATION is generated if there is no current program object.
GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader does not match the size indicated by the glUniform command.
GL_INVALID_OPERATION is generated if one of the integer variants of this function loads a uniform variable of type float, vec2, vec3, vec4, or an array of these, or if one of the floating-point variants of this function loads a uniform variable of type int, ivec2, ivec3, or ivec4, or an array of these.
GL_INVALID_OPERATION is generated if location is an invalid uniform location for the current program object and location is not equal to 1.
GL_INVALID_VALUE is generated if count is less than 0.
GL_INVALID_OPERATION is generated if count is greater than 1 and the indicated uniform variable is not an array variable.
GL_INVALID_OPERATION is generated if a sampler is loaded with a command other than glUniform1i and glUniform1iv.
GL_INVALID_OPERATION is generated if glUniform is executed between the execution of glBegin and the corresponding execution of glEnd.
Associated Gets
glGet with the argument GL_CURRENT_PROGRAM
glGetActiveUniform with the handle of a program object and the index of an active uniform variable
glGetUniform with the handle of a program object and the location of a uniform variable
glGetUniformLocation with the handle of a program object and the name of a uniform variable
See Also
glLinkProgram, glUseProgram
|