opengl - 非索引渲染中的 gl_VertexID

标签 opengl opengl-4

OpenGL gl_VertexID页面明确指出:

gl_VertexID is a vertex language input variable that holds an integer index for the vertex



而 OpenGL Vertex Shader页面说是

the index of the vertex currently being processed. When using non-indexed rendering, it is the effective index of the current vertex (the number of vertices processed + the first​ value).



我可以假设 100% 在非索引渲染命令中 gl_VertexID 是绑定(bind)顶点缓冲区中的 int 顶点索引吗?或者它是由渲染命令处理的顶点的索引(可能会或可能不会遵循顶点缓冲区中的顺序)

疑问来自()里面的描述部分,至于处理的顶点数要等于当前顶点在顶点缓冲区中的索引,顶点必须是线性处理的。我可以假设它永远都是这样吗?或者也许有 OpenGL 实现可以向后处理顶点,或者在桶中等等。

最佳答案

tl;博士:是的,gl_VertexID将始终是绘制调用指定的图元序列中各个顶点的逻辑索引(实际上是从顶点缓冲区中读取顶点数据的位置的索引)。它不依赖于实际处理顶点的方式或顺序(如果这样做,那将使它成为一个相当无用的功能,因为它不会提供任何可靠的行为)。

来自 OpenGL 4.6 specification (11.1.3.9 着色器输入):

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



从 10.4 开始:

The index of any element transferred to the GL by DrawArraysOneInstance is referred to as its vertex ID, and may be read by a vertex shader as gl_VertexID. The vertex ID of the ith element transferred is first + i.





The index of any element transferred to the GL by DrawElementsOneInstance is referred to as its vertex ID, and may be read by a vertex shader as gl_VertexID. The vertex ID of the ith element transferred is the sum of basevertex and the value stored in the currently bound element array buffer at offset indices + i.



现在,所有非索引绘制调用的行为都以抽象 DrawArraysOneInstance 的形式指定。命令。并且所有索引绘制调用的行为都以抽象 DrawElementsOneInstance 的形式指定。命令。没有更多的细节(你可以在第 10.4 节中挖掘。如果你想了解更多),以上所有基本上意味着如果你使用索引缓冲区绘制,那么 gl_VertexID将是由索引缓冲区指定的顶点的索引,如果您在没有索引缓冲区的情况下绘制,则 gl_VertexID将是原始序列给出的顶点索引……

关于opengl - 非索引渲染中的 gl_VertexID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54807694/

相关文章:

c++ - Phong-Alpha Material 透明度

macos - 在OSX上使用Waf编译OpenGL/SDL应用程序时,如何抑制 '-arch'和 'x86_64'标志?

python - 3D 纹理的 OpenGL 4.2+ 和 shader_image_load_store 不起作用?

c++ - glDebugMessageCallback 导致段错误

c - 你如何在 Ubuntu 上编译 OpenGL 程序?

c++ - OpenGL 似乎没有读取我的顶点/索引

c - 我的数学观点错了吗?

c - glUniformMatrix4fv - 无效操作

c++ - 设置 OpenGL 4 构建/单元测试服务器?