glGetUniformLocation详解

glGetUniformLocation详解

openGL4.5API之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 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

Version Support
OpenGL Version
Function / Feature Name 2.0 2.1 3.0 3.1 3.2 3.3 4.0 4.1 4.2 4.3 4.4 4.5
glGetUniformLocation ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔
See Also
glLinkProgram, glUniform

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

中文版翻译
名称
glGetUniformLocation- 返回统一变量的位置序号,因为位置应该是一个向量vec3,而不是一个整形值,所以只是一个位置序号。

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

参数
program

指定要查询的程序对象。

name

要查询其位置序号的统一变量的名称。

描述
glGetUniformLocation返回一个整数,表示程序对象中特定统一变量的位置(序号)。 name必须是不包含空格的空终止字符串。 name必须是程序中的活动统一变量名,它不能是结构,也不能是结构数组或向量或矩阵的子组件。 如果name与程序中的活动统一变量不对应,或者name以保留前缀“gl_”开头,则此函数返回-1。

可以通过为结构中的每个字段调用glGetUniformLocation来查询作为结构或结构数组的统一变量。 数组元素运算符“[]”和结构字段运算符“.” 可以在name中使用,以便选择数组中的元素或结构中的字段。 使用这些运算符的结果不允许是另一个结构,结构数组或向量或矩阵的子组件。 除非name的最后一部分表示统一变量数组,否则可以使用数组的名称或使用“[0]”附加的名称来检索数组的第一个元素的位置。

在程序对象成功链接之前,分配给统一变量的实际位置是不知道的。发生链接后,命令glGetUniformLocation可用于获取统一变量的位置。 然后可以将此位置值传递给glUniform以设置统一变量的值或glGetUniform以查询统一变量的当前值。成功链接程序对象后,统一变量的索引值保持不变,直到发生下一个链接命令。 如果链接成功,则只能在链接后查询统一变量位置和值。

错误
GL_INVALID_VALUE :program不是OpenGL生成的值。

GL_INVALID_OPERATION :program不是程序对象。

GL_INVALID_OPERATION :program没有成功链接。

相关Gets
glGetActiveUniform 参数program和活动的统一变量索引。

glGetProgramiv 参数program和GL_ACTIVE_UNIFORMS 或 GL_ACTIVE_UNIFORM_MAX_LENGTH

glGetUniform 参数program和统一变量的名称

glIsProgram

另见
glLinkProgram,glUniform

版权
https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glGetUniformLocation.xml

https://blog.csdn.net/flycatdeng

Copyright © 1991-2006 Silicon Graphics, Inc.本文档的许可是根据SGI Free Software B License.详见http://oss.sgi.com/projects/FreeB/.

参考:

  1. 官方glGetUniformLocation解释
  2. 中文glGetUniformLocation解释
    虽然是GLES2.0中文API-glGetUniformLocation,但文档都完全一样
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值