openglshaderspir-v

Using spirv with OpenGL, gl_VertexIndex is always 0


I am trying to use spirv with OpenGL. Before in my shaders I had gl_VertexID to calculate the uv of a rectangle and now I replaced it with gl_VertexIndex.

If I use gl_VertexID the code works, if I use gl_VertexIndex in spirv with vulkan the code works, but if I use gl_VertexIndex with OpenGL the gl_VertexIndex is always 0.

Here is a test draw command I'm using:

glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 6, 1, 2);

Shouldn't the gl_VertexIndex go from 0 to 5?


Solution

  • There is no gl_VertexIndex in OpenGL, regardless of the shading language you use. When compiling GLSL into SPIR-V for OpenGL, you ought to have gotten a compile error.

    That being said, there's no difference between the values of gl_VertexIndex and gl_VertexID (unlike gl_InstanceIndex vs. gl_InstanceID).