关于使用 glVertexAttribPointer 绑定不存在的属性的索引的困惑
Confusion about binding the index of a non-existent attribute using glVertexAttribPointer
使用 glVertexAttribPointer 绑定属性索引时,如果关联程序在所述索引处不包含属性,会发生什么情况?
行为是否未定义,或者属性是否被完全忽略?
我已经广泛地搜索了文档,但没能找到很多关于程序和动态属性绑定之间的 link 的信息。
程序未关联到顶点数组对象。顶点属性索引是绑定点。如果绑定点不是程序的 "needed",这不会导致任何问题。
[...] What about if there is an attribute at that index but it is of a different type than of that earlier specified using glVertexAttribPointer
[...]
OpenGL 4.6 API Core Profile Specification - 10.2.1 Current Generic Attributes,第 349 页:
When values for a vertex shader attribute variable are sourced from a current generic attribute value, the attribute must be specified by a command compatible with the data type of the variable.
这意味着如果属性的数据类型是浮点数,那么你必须通过glVertexAttribPointer
. If the data type is integral the you've to use glVertexAttribIPointer
指定顶点属性数据的数组(重点在I
)。
如果您忽略它,那么顶点数组缓冲区中的数据将被误解。
OpenGL 4.6 API Core Profile Specification - 10.3.5 Transferring Array Elements,第 361 页:
When a vertex is transferred to the GL by DrawArrays
, DrawElements
, or the other Draw*
commands described below, each generic attribute is expanded to four components. If size is one then the x component of the attribute is specified by the array; the y, z, and w components are implicitly set to 0, 0, and 1, respectively. If size is two then the x and y components of the attribute are specified by the array; the z and w components are implicitly set to 0 and 1, respectively. If size is three then x, y, and z are specified, and w is implicitly set to 1. If size is four then all components are specified.
因此顶点数据的元组大小和着色器程序中顶点属性的数据类型的元组大小(例如float
、vec2
、vec3
、. ..) 允许不同。
如果程序中顶点属性的元组大小更大,则数据分别对第 2md 和第 3 个扩展 0,对第 4 个组件扩展 1。
如果程序中顶点属性的元组大小较少,则顶点数组中的附加组件为"not used"。
使用 glVertexAttribPointer 绑定属性索引时,如果关联程序在所述索引处不包含属性,会发生什么情况?
行为是否未定义,或者属性是否被完全忽略?
我已经广泛地搜索了文档,但没能找到很多关于程序和动态属性绑定之间的 link 的信息。
程序未关联到顶点数组对象。顶点属性索引是绑定点。如果绑定点不是程序的 "needed",这不会导致任何问题。
[...] What about if there is an attribute at that index but it is of a different type than of that earlier specified using
glVertexAttribPointer
[...]
OpenGL 4.6 API Core Profile Specification - 10.2.1 Current Generic Attributes,第 349 页:
When values for a vertex shader attribute variable are sourced from a current generic attribute value, the attribute must be specified by a command compatible with the data type of the variable.
这意味着如果属性的数据类型是浮点数,那么你必须通过glVertexAttribPointer
. If the data type is integral the you've to use glVertexAttribIPointer
指定顶点属性数据的数组(重点在I
)。
如果您忽略它,那么顶点数组缓冲区中的数据将被误解。
OpenGL 4.6 API Core Profile Specification - 10.3.5 Transferring Array Elements,第 361 页:
When a vertex is transferred to the GL by
DrawArrays
,DrawElements
, or the otherDraw*
commands described below, each generic attribute is expanded to four components. If size is one then the x component of the attribute is specified by the array; the y, z, and w components are implicitly set to 0, 0, and 1, respectively. If size is two then the x and y components of the attribute are specified by the array; the z and w components are implicitly set to 0 and 1, respectively. If size is three then x, y, and z are specified, and w is implicitly set to 1. If size is four then all components are specified.
因此顶点数据的元组大小和着色器程序中顶点属性的数据类型的元组大小(例如float
、vec2
、vec3
、. ..) 允许不同。
如果程序中顶点属性的元组大小更大,则数据分别对第 2md 和第 3 个扩展 0,对第 4 个组件扩展 1。
如果程序中顶点属性的元组大小较少,则顶点数组中的附加组件为"not used"。