2012-04-06 157 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。您必須自己創建並傳遞其他數據。