假设我使用新的(从OpenGL 4.3开始)glBindVertexBuffer机制设置了两个VAO:
glGenVertexArrays(1, &vaoIndex0);
glGenVertexArrays(1, &vaoIndex1);
Run Code Online (Sandbox Code Playgroud)
...
glBindVertexArray(vaoIndex0)
glBindVertexBuffer(bindingIndex0, ...)
glEnableVertexAttribArray(0)
glVertexAttribFormat(0, ...)
glVertexAttribBinding(0, bindingIndex0)
...
glBindVertexArray(0)
Run Code Online (Sandbox Code Playgroud)
...
glBindVertexArray(vaoIndex1)
glBindVertexBuffer(bindingIndex1, ...)
glEnableVertexAttribArray(0)
glVertexAttribFormat(0, ...)
glVertexAttribBinding(0, bindingIndex1)
...
glBindVertexArray(0)
Run Code Online (Sandbox Code Playgroud)
并且假设两者是独立的,除非它们存在于相同的OpenGL上下文中; 它们绑定不同的缓冲区,用于绘制不同的东西.
bindingIndex0需要与bindingIndex1不同吗?两个指数的平等(或不平等)是否有任何意义?
...
编辑:
在收到答案后,我开始明白,对于一个真正知道"顶点缓冲区绑定点"是什么的人,特别是它的范围是什么,我的问题似乎是在问一些与我的意图不同的东西.也许一个更好的措辞就是" 为了防止冲突,是否需要尽力避免重复使用OpenGL顶点缓冲区绑定点索引,甚至跨多个VAO?" 但无论如何,似乎现在已经回答了这两个问题:不,你不能重复使用"绑定点",并且不需要以这种方式避免索引冲突.
对于其他缓冲区,有以下功能:
glVertexArrayVertexAttribOffsetEXT(
this->handle, // vao handle
vbo.getHandle(), // vbo handle
index, // specifies the index of the generic vertex attribute to be modified.
size, // number of components per generic vertex attribute
vbo.getType(), // specifies the data type of each component in the array
normalized, // specifies whether fixed-point data values should be normalized
stride, // specifies the byte offset between consecutive generic vertex attributes
offset // specifies a pointer to the first component of the first generic vertex attribute …Run Code Online (Sandbox Code Playgroud) 创建时,VAO 是否仅跟踪 VBO 索引(通过glBindVertexBuffer),或者还跟踪哪些 VBO 名称绑定到这些索引?如果我使用glVertexAttribBinding指定绑定索引,例如 0,我可以在绘制调用之前将不同的 VBO 绑定到索引 0 并让它使用该 VBO 的内容,还是始终使用任何 VBO创建 VAO 时是否绑定到索引 0?
我问这个问题是因为我发现很多例子都在调用glVertexAttribFormat和glVertexAttribBinding之前调用glBindVertexBuffer,如果 VAO 仅跟踪索引(因为绑定索引在 中给出),则不需要调用glVertexAttribBinding。