gl_VertexID 在非索引渲染中
gl_VertexID in non-indexed rendering
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 是绑定顶点缓冲区中的 int 顶点索引吗?或者它是由渲染命令处理的顶点索引(可能遵循也可能不遵循顶点缓冲区中的顺序)
疑惑来自()里面的描述部分,至于处理的顶点数等于当前顶点在顶点缓冲区中的索引,顶点必须线性处理。我可以假设情况总是如此吗?或者也许有 OpenGL 实现可以向后处理顶点,或者在桶中等。
tl;dr:是的,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 页面明确指出:
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 是绑定顶点缓冲区中的 int 顶点索引吗?或者它是由渲染命令处理的顶点索引(可能遵循也可能不遵循顶点缓冲区中的顺序)
疑惑来自()里面的描述部分,至于处理的顶点数等于当前顶点在顶点缓冲区中的索引,顶点必须线性处理。我可以假设情况总是如此吗?或者也许有 OpenGL 实现可以向后处理顶点,或者在桶中等。
tl;dr:是的,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 asgl_VertexID
. Thevertex 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 asgl_VertexID
. Thevertex 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
将成为原始序列给定的顶点索引…