glGetUniformLocation

Returns the location of a uniform variable

Signature

glGetUniformLocation( GLuint ( program ) , const GLchar *( name ) )-> GLint
glGetUniformLocation( program , name ) -> <class 'ctypes.c_int'>
Check that name is a string with a null byte at the end of it

Parameters

VariablesDescription
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 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 , if name starts with the reserved prefix "gl_", or if name is 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. 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. 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]".
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
glGetProgram with arguments program and GL_ACTIVE_UNIFORMS or GL_ACTIVE_UNIFORM_MAX_LENGTH
glGetUniform with arguments program and the name of a uniform variable

Version Support

glGetUniformLocation

See Also

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. .

Sample Code References

The following code samples have been found which appear to reference the functions described here. Take care that the code may be old, broken or not even use PyOpenGL.

glGetUniformLocation
OpenGLContext OpenGLContext/scenegraph/shaders.py Lines: 563
OpenGLContext tests/shaders.py Lines: 71
OpenGLContext tests/shader_3.py Lines: 132, 133
OpenGLContext tests/shader_6.py Lines: 222
OpenGLContext tests/pygame_textureatlas.py Lines: 71, 72
OpenGLContext tests/shader_4.py Lines: 104
OpenGLContext tests/shader_11.py Lines: 244
OpenGLContext tests/shader_7.py Lines: 221, 230
OpenGLContext tests/shader_5.py Lines: 272
OpenGLContext tests/shader_9.py Lines: 294, 298
OpenGLContext tests/shader_10.py Lines: 230, 234
OpenGLContext tests/shader_8.py Lines: 171, 175
OpenGLContext tests/shader_4_subset.py Lines: 50, 51
{LGPL} PyMT pymt/graphx/shader.py Lines: 10, 61, 65
{GPL3} OpenGL-Programmable 05-shader.py Lines: 94
{GPL3} OpenGL-Programmable 07-attrib.py Lines: 111
{GPL3} OpenGL-Programmable 09-gles2.py Lines: 125
{GPL3} OpenGL-Programmable 06-perpixel.py Lines: 102
{GPL3} OpenGL-Programmable 10-gl3.2core.py Lines: 133
{GPL3} OpenGL-Programmable 08-pbo.py Lines: 111