开发者

*BaseVertex and gl_VertexID

开发者 https://www.devze.com 2023-04-05 07:08 出处:网络
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开发者_运

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消