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

前端 未结 1 669
温柔的废话
温柔的废话 2021-01-02 09:33

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

1条回答
  •  暖寄归人
    2021-01-02 09:41

    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.

    0 讨论(0)
提交回复
热议问题