Difference between revisions of "GLAPI/glGetUniformLocation"

From OpenGL.org
Jump to: navigation, search
m (Renaming category: 'GL 4 API Shader Program Query' to 'Core API Ref Shader Program Query'.)
m (Bot: Adding better formatting.)
(3 intermediate revisions by the same user not shown)
Line 8: Line 8:
 
== Function Definition ==
 
== Function Definition ==
  
   GLint '''glGetUniformLocation'''(GLuint ''program'', const GLchar *''name'');
+
   GLint '''glGetUniformLocation'''(GLuint {{param|program}}, const GLchar *{{param|name}});
  
 
; program
 
; program
Line 17: Line 17:
 
== Description ==
 
== 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.
+
'''glGetUniformLocation''' returns an integer that represents the location of a specific uniform variable within a program object. {{param|name}} must be a null terminated string that contains no white space. {{param|name}} must be an active uniform variable name in {{param|program}} that is not a structure, an array of structures, or a subcomponent of a vector or a matrix. This function returns -1 if {{param|name}} does not correspond to an active uniform variable in {{param|program}}, if {{param|name}} starts with the reserved prefix "gl_", or if {{param|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]".
+
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 {{param|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 {{param|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 [[GLAPI/glUniform|glUniform]] to set the value of the uniform variable or to [[GLAPI/glGetUniform|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.
+
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 {{apifunc|glUniform}} to set the value of the uniform variable or to {{apifunc|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 ==
 
== Errors ==
  
{{code|GL_INVALID_VALUE}} is generated if ''program'' is not a value generated by OpenGL.
+
{{enum|GL_INVALID_VALUE}} is generated if {{param|program}} is not a value generated by OpenGL.
  
{{code|GL_INVALID_OPERATION}} is generated if ''program'' is not a program object.
+
{{enum|GL_INVALID_OPERATION}} is generated if {{param|program}} is not a program object.
  
{{code|GL_INVALID_OPERATION}} is generated if ''program'' has not been successfully linked.
+
{{enum|GL_INVALID_OPERATION}} is generated if {{param|program}} has not been successfully linked.
  
 
== Associated Gets ==
 
== Associated Gets ==
  
[[GLAPI/glGetActiveUniform|glGetActiveUniform]] with arguments ''program'' and the index of an active uniform variable
+
{{apifunc|glGetActiveUniform}} with arguments {{param|program}} and the index of an active uniform variable
  
[[GLAPI/glGetProgram|glGetProgram]] with arguments ''program'' and {{code|GL_ACTIVE_UNIFORMS}} or {{code|GL_ACTIVE_UNIFORM_MAX_LENGTH}}
+
{{apifunc|glGetProgram}} with arguments {{param|program}} and {{enum|GL_ACTIVE_UNIFORMS}} or {{enum|GL_ACTIVE_UNIFORM_MAX_LENGTH}}
  
[[GLAPI/glGetUniform|glGetUniform]] with arguments ''program'' and the name of a uniform variable
+
{{apifunc|glGetUniform}} with arguments {{param|program}} and the name of a uniform variable
  
[[GLAPI/glIsProgram|glIsProgram]]
+
{{apifunc|glIsProgram}}
  
 
== See Also ==
 
== See Also ==
  
[[GLAPI/glLinkProgram|glLinkProgram]], [[GLAPI/glUniform|glUniform]]
+
{{apifunc|glUniform}}, {{apifunc|glGetProgramResourceLocation}}
  
 
== Copyright ==
 
== Copyright ==
Line 49: Line 49:
 
Copyright © 2003-2005 3Dlabs Inc. Ltd. © 2011 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/ http://opencontent.org/openpub/].
 
Copyright © 2003-2005 3Dlabs Inc. Ltd. © 2011 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/ http://opencontent.org/openpub/].
  
[[Category:API Reference 4|GetUniformLocation]]
 
 
[[Category:Core API Ref Shader Program Query|GetUniformLocation]]
 
[[Category:Core API Ref Shader Program Query|GetUniformLocation]]
 +
[[Category:Core API Reference|GetUniformLocation]]

Revision as of 15:40, 27 September 2012

glGetUniformLocation
Core in version 4.5
Core since version 2.0

glGetUniformLocation: Returns the location of a uniform variable

Function Definition

 GLint glGetUniformLocation(GLuint program​, const GLchar *name​);
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

glIsProgram

See Also

glUniform, glGetProgramResourceLocation

Copyright

Copyright © 2003-2005 3Dlabs Inc. Ltd. © 2011 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/.