I'm trying to learn how to use GLSL ES 2.0.
In OpenGL ES 2.0, there is no
gl_VertexID keyword to obtain the number of vertices processed so far. So I was wondering if there's a way to make my own counter. I know the vertex shader is executed "per vertex," so if I can increase a counter which persists between executions then that will meet my case.
Now I know I can't use a
uniform because by definition they cannot be altered.
So I thought about using an
attribute, assuming the value will persist between vertex shader executions, but when I write
attribute int a_vertexCounter;
in my vertex shader, the shader compiler says that an attribute cannot have the type
So I thought maybe if I make
vec3 for example, and increment the first component of that vector instead... This works, except that when I try
gl_Position = u_MVPMatrix * u_canPos[int(a_vertexCounter.x)];
the compiler says
Error compiling shader: 0:23: S0027: Cannot modify an input variable
I also tried setting my
attribute variable to be of type
ivec3 but the shader says that's not allowed either.
Maybe there's no way to do this without ES 3.0, where I could simply use