2012-04-06 75 views
6

我想通过动态计算顶点位置来创建点的网格,这取决于它们在发送到着色器的顶点数组中的索引。是否有我可以在我的着色器中调用的gl_VertexID变量的等价物?或者另一种访问阵列位置的方式,而无需向GPU发送更多数据?谢谢,乔希。OpenGLES 2.0:gl_VertexID等效吗?

这里是我的顶点着色器:

attribute vec4 vertexPosition; 
uniform mat4 modelViewProjectionMatrix; 
vec4 temp; 
uniform float width; 

void main() 
{  
    temp = vertexPosition; 

    // Calculate x and y values based on index: 
    temp.y = floor(gl_VertexID/width); 
    temp.x = gl_VertexID - width*temp.y; 

    gl_Position = modelViewProjectionMatrix * temp; 
} 
+3

不是您的原始问题的答案,但是这是在GLES 3.0中添加的。 http://www.khronos.org/registry/gles/specs/3.0/es_spec_3.0.0.pdf – nullspace 2012-11-12 08:54:56

回答

12

不幸的是没有gl_VertexID相当于GLES2。您必须自己创建并传递其他数据。