Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

*BaseVertex and gl_VertexID

Tags:

opengl

glsl

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.

like image 239
palle8x Avatar asked Sep 17 '11 07:09

palle8x


People also ask

What is gl_VertexID?

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.

Is Glsl a language?

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.

What are the inputs and outputs of a vertex shader?

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.


2 Answers

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.

like image 115
datenwolf Avatar answered Dec 03 '22 14:12

datenwolf


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.

like image 42
Ryhor Spivak Avatar answered Dec 03 '22 14:12

Ryhor Spivak