Light | Dark

glGetUniformLocation

Name

glGetUniformLocation — Returns the location of a uniform variable

C Specification

GLint glGetUniformLocation( GLuint program,
const GLchar *name);

Parameters

program

Specifies the program object to be queried.

name

Points to a null terminated string containing the name of the uniform variable whose location is to be queried.

Description

glGetUniformLocation returns an integer that represents the location of a specific uniform variable within a the default uniform block of a program object. name must be a null terminated string that contains no white space. name must be an active uniform variable name in program that is not a structure, an array of structures, or a subcomponent of a vector or a matrix. This function returns -1 if name does not correspond to an active uniform variable in program or if name is associated with 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. 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. 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. The first element of a uniform array is identified using the name of the uniform array appended with "[0]". If the last part of the string name indicates a uniform array, then the location of the first element of that array can be retrieved by either using the name of the array, or by using the name appended by "[0]".

Locations for sequential array indices are not required to be sequential. The location for "a[1]" may or may not be equal to the location for "a[0]" + 1. Furthermore, since unused elements at the end of uniform arrays may be trimmed the location of the i + 1 array element may not be valid even if the location of the i element is valid. As a direct consequence, the value of the location of "a[0]" + 1 may refer to a different uniform entirely. Applications that wish to set individual array elements should query the locations of each element separately.

The actual locations assigned to uniform variables are not known until the program object is linked successfully. 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. Uniform variable locations and values can only be queried after a link if the link was successful.

Errors

GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.

GL_INVALID_OPERATION is generated if program is not a program object.

GL_INVALID_OPERATION is generated if program has not been successfully linked.

Associated Gets

glGetActiveUniform with arguments program and the index of an active uniform variable

glGetProgramiv with arguments program and GL_ACTIVE_UNIFORMS or GL_ACTIVE_UNIFORM_MAX_LENGTH

glGetUniform with arguments program and the name of a uniform variable

glIsProgram

API Version Support

OpenGL ES API Version
Function Name 2.0 3.0 3.1
glGetUniformLocation
Think you can improve this page? Edit this page on GitHub.