Is it possible for a vertex attribute to be an array in GLSL-ES 2.0?

微笑、不失礼 提交于 2019-11-30 03:25:11

问题


In GLSL-ES it's possible to have arrays. For example, the GLSL ES Specification gives the following example of a uniform variable that's an array:

uniform vec4 lightPosition[4];

Is it possible to have vertex attributes that are arrays? In other words, is the following legal according to the spec?

attribute vec4 foo[3];  // three vec4s per vertex

Is the answer (either yes or no) explicitly mentioned anywhere in the GLSL ES Specification? (I can't find it, but I haven't read every line of the spec.)

Also, if it is legal, how does one initialize such an attribute using the OpenGL ES 2.0 API? (Assuming glVertexAttribPointer would be used, what is the layout of the vertices/array-elements/vector-elements?)


回答1:


The GLSL ES 2.0 specification states that attributes cannot be declared as arrays.

In desktop GL, you can have attribute arrays. When the attribute is assigned an attribute index (either with glBindAttribLocation or automatically by the shader being linked), it will get consecutive attributes, starting with the one you requested if you used glBindAttribLocation. So if foo was given the location 5, foo[0] would be 5, foo[1] would be 6, and foo[2] would be 7.

If there is some ES 2.0 extension to allow attribute arrays, it would likely work like this.



来源:https://stackoverflow.com/questions/8220484/is-it-possible-for-a-vertex-attribute-to-be-an-array-in-glsl-es-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!