I've skimmed through the specs and OpenGL forum but couldn't really make sense of this:
Are the *BaseVertex
version of the drawing commands supposed to add to the GLSL variable gl_VertexID
? As it works, gl_VertexID
contains the index taken from the the bound ELEMENT_ARRAY_BUFFER
before basevertex
is added to it.
So, my question is: Is this the correct behavior? I would assume that gl_VertexID
should contain the index used to fetch the vertex.
gl_VertexID is a vertex language input variable that holds an integer index for the vertex. while the OpenGL Vertex Shader page says it is. the index of the vertex currently being processed.
GLSL is a C-style language. The language has undergone a number of version changes, and it shares the deprecation model of OpenGL. The current version of GLSL is 4.60.
The Vertex-shader Each vertex shader input vertex can be comprised of up to 16 32-bit vectors (up to 4 components each) and each output vertex can be comprised of as many as 16 32-bit 4-component vectors. All vertex-shaders must have a minimum of one input and one output, which can be as little as one scalar value.
Yes this is the correct bahviour. The usage scenario of BaseVertex is, that you have to switch only this one value, instead of adjusting the buffer offsets into the vertex arrays with the gl*Pointer
functions.
The idea is, that you can load the data from multiple meshes (model files) into a single VBO, without the need to adjust the indices.
Your assumption is right. gl_VertexID should include BaseVertex offset.
opengl wiki about GLSL built-in vars:
Note: gl_VertexID will have the base vertex applied to it.
about glDrawElementsBaseVertex:
The gl_VertexID passed to the Vertex Shader will be the index after being offset by basevertex, not the index fetched from the buffer.
Unfortunately, some old drivers didn't implement it correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With