What value should contain gl_VertexID then using *BaseVertex commands? Should it be index before or after applying BaseVertex offset?
There is a note here http://www.opengl.org/wiki/Built-in_Variable_%28GLSL%29 :
And at least on AMD HD 5650 with latest drivers it works this way.The gl_VertexID passed to the Vertex Shader will be the index after being offset by basevertex, not the index fetched from the buffer.
But on NVIDIA GeForce GTX 780 gl_VertexID equals to index directly from index buffer, before offsetting by BaseVertex.
Initially, I was thinking it's NVIDIA driver bug. But after looking in the spec I was surprised by the fact that there is no clear answer which way it should be.
GLSL spec says just that:
And GL 3.3 spec:The variable gl_VertexID is a vertex shader input variable that holds an integer index for the vertex, asdefined under “ShaderInputs” in section 2.11.7 “Varying Variables” in the OpenGL Graphics System
Specification. Whilethe variable gl_VertexID is always present, its value is not always defined.
And section 2.8.3 "Drawing Commands" didn't say anything about which value should go into gl_VertexID.gl_VertexID holds the integer index i implicitly passed by DrawArrays or
one of the other drawing commands defined in section 2.8.3.
(I've used 3.3 spec because I'm targeting 3.3, but latest 4.4 spec also didn't cover this aspect.)
So who is buggy? Is it NVIDIA drivers? Or AMD drivers and GL wiki? Or maybe it is a bug in the specification and HW vendors can implement it any way they like?
Here is a small test app with source:
It should draw two rects, one red and one green if gl_VertexID include BaseVertex offset or two red rects if it comes directly from the index buffer. Both 32 and 64-bit versions included in case there is a difference between 32/64 bit drivers.