Is it possible for a vertex attribute to be an arr

2019-02-16 23:26发布

问题:

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.