Does a VAO remember both a EBO/IBO (elements or indices) and a VBO?

…衆ロ難τιáo~ 提交于 2019-11-30 19:26:43

Addressing your questions:

A. Do I need to bind the IBO after I set the VertexAttribPointers? If so, why?

No. You could bind the element array (IBO in your terminology) first, and do the vertex attributes later, but generally speaking, they're separate bindings within the VAO. For example, you could bind your IBO as well as several VBOs, and render with either glDrawElements (and variants) using the data in the IBO, or using glDrawArrays (and variants) using only the sequential vertex data in your VBOs - the rendering command determines if the IBO is used or not.

B. Does the VAO really store both the VBO and the IBO?

Yes. A VAO can store the binding information for a single IBO, and at least 16 VBOs.

I've heard it only stores the last buffer that was bound, meaning I have to render like this:

Bind VAO
Bind VBO
Draw Elements
Unbind VAO

As you surmised in your original post, this statement is incorrect, and the binding of the VBO you include is unnecessary. A VAO can store up the implementation-dependent maximum (which is at least 16) number of VBOs, each of which can be bound to a vertex attribute.

Also, isn't it cleaner if I put it like this:

  1. Gen and bind VAO
  2. Gen and bind IBO and BufferData
  3. Gen and bind VBO and BufferData
  4. EnableVertexAttribArrays that I need and set VertexAttribPointers
  5. Unbind VAO (binding to 0)

Yes. As you point out, that allows you to bind, render, and clean-up in only three commands.

Really, that's the entire point of VAOs, to collect all those binding and vertex attribute associations so you can do all the plumbing once, and then fire-and-forget later.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!