View Full Version : gl_VertexID and *BaseVertex

07-02-2014, 10:16 AM
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 :

Note: gl_VertexID​ will have the base vertex (http://www.opengl.org/wiki/Vertex_Rendering#Base_Index) applied to it.

And another one here http://www.opengl.org/wiki/GLAPI/glDrawElementsBaseVertex :

The gl_VertexID​ passed to the Vertex Shader (http://www.opengl.org/wiki/Vertex_Shader) will be the index after being offset by basevertex​, not the index fetched from the buffer.

And at least on AMD HD 5650 with latest drivers it works this way.
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:

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 GL 3.3 spec:

gl_VertexID holds the integer index i implicitly passed by DrawArrays or
one of the other drawing commands defined in section 2.8.3.

And section 2.8.3 "Drawing Commands" didn't say anything about which value should go into gl_VertexID.

(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:
http://www.faogen.com/files/base_vertex.zip (http://www.faogen.com/files/base_vertex.zip)

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.

07-02-2014, 10:37 AM
maybe it is a bug in the specification

Read ARB_shader_draw_parameters (http://www.opengl.org/registry/specs/ARB/shader_draw_parameters.txt).