关于 EBO 如何工作的一些说明(元素数组缓冲区)

A bit of clarification on how EBOs work (Element array buffers)

我知道 EBO 可以绑定到 VAO,这与其他 OpenGL 缓冲区对象不同。我还知道,如果在绑定 EBO 时没有绑定 VAO,则 EBO 将绑定到 OpenGL 上下文或全局状态。我的问题是,当您将 EBO 绑定到 VAO,然后解除绑定 VAO,然后再次绑定 EBO 时,EBO 是绑定到 VAO、全局状态还是两者?在此先感谢您的帮助。

来自 OpenGL 规范:

A buffer object is created by binding a name returned by GenBuffers to a buffer target. The binding is effected by calling void [gl]BindBuffer( enum target, uint buffer ); target must be one of the targets listed in table...

绑定缓冲区描述了它将如何使用。例如,使用 target =GL_ELEMENT_ARRAY_BUFFERbind 缓冲区作为 EBO。

DrawElements, DrawRangeElements, and DrawElementsInstanced source their indices from the buffer object whose name is bound to [GL_]ELEMENT_ ARRAY_BUFFER,

因此,使用了当前绑定的 [elements] 缓冲区。

VAO 存储绑定。当你再次 "active" VAO 时 glBindVertexArray EBO 再次绑定 "automagically".

I understand that a EBO can be bound to a VAO, unlike the other OpenGL buffer objects.

首先,一些术语。

在 OpenGL 中,您不会将一个对象绑定到另一个对象。您 将一个对象附加 到另一个对象。 "Bind" 仅在将对象放入上下文时使用。

当您调用 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,...) 时,您正在 附加 缓冲区到当前的 VAO。是的,我知道这个函数说 "bind",它的行为很像一个常规的上下文绑定点,但是 OpenGL 函数说了很多愚蠢的事情。 DSA-equivalent 被称为 glVertexArrayElementBuffer 是有原因的,看不到 "bind"。

I also know that if no VAO is bound at the time of binding the EBO, the EBO is bound to the OpenGL context or the global state.

这话只对了一半。在兼容性上下文中,VAO 0 是默认的 VAO 对象。也就是说,glBindVertexArray(0) 是一个有效的对象。因此,如果您调用 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,...) 并绑定 VAO 对象 0,则您会将缓冲区附加到 VAO 0。

在核心上下文中,没有 VAO 0。因此,glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ...) 将导致 GL_INVALID_OPERATION 错误。

My question is when you bind a EBO to a VAO, then unbind the VAO, and bind the EBO again, is the EBO bound to the VAO, the global state, or both?

缓冲区可以附加到任意数量的 VAO。因此,您将缓冲区附加到 VAO 0 的事实不会改变它附加到其他一些 VAO 的事实。