My code is working as it should but it might be a coincidence and I don\'t want to dwell on a bug later so I\'m trying to keep it as clean as possible:
I do the foll
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:
- Gen and bind VAO
- Gen and bind IBO and BufferData
- Gen and bind VBO and BufferData
- EnableVertexAttribArrays that I need and set VertexAttribPointers
- 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.