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 int.
So I thought maybe if I make a_vertexCounter a 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 gl_VertexID ?
uniformthen just use thegl_VertexID % 6(or some ES 2 equivalent) to access the appropriate vertex from theuniform. Sprites would get transformed via matrices I will pass in as anattributebuffer. Maybe there's no way to achieve this without OpenGL ES 3 then? Or maybe that won't even work given things may happen in parallel. Perhaps I have no choice but to pass in 6 canonical vertices per sprite? \$\endgroup\$uniformbut seems this is not possible then. Your solution of just sending in an id which indexes into theuniformwould work. Thank you. New to all this, so just reading up on this: glslstudio.com/primer \$\endgroup\$