4
$\begingroup$

I know that when you call glVertexAttribPointer, you are specifying how the buffer currently binded should take its own data. But if you can have binded one buffer per type (Let's say GL_ARRAY_BUFFER and GL_ELEMENT_ARRAY_BUFFER) then, Are you specifying two buffers simultaneously? In this tutorial says:

glVertexAttribPointer always refers to whatever buffer is bound to GL_ARRAY_BUFFER at the time that this function is called. Therefore it does not take a buffer object handle; it simply uses the handle we bound previously.

If glVertexAttribPointer refers to the GL_ARRAY_BUFFER buffer currently binded, How I call glVertexAttribPointer for the GL_ELEMENT_ARRAY_BUFFER buffer?

$\endgroup$

2 Answers 2

4
$\begingroup$

How I call glVertexAttribPointer for the GL_ELEMENT_ARRAY_BUFFER buffer?

You don't. The element array buffer is used to store vertex indices, not vertex attribute data and therefore it doesn't have attribute pointers. The count, size, and offset for index data is specified in the draw call, e.g. glDrawElements.

$\endgroup$
5
$\begingroup$

A VAO holds the attribute information. This means that for each attribute it has a buffer, offset, size, type, stride and whether it's normalized. Separately from those is the element buffer binding that is set by binding the GL_ELEMENT_ARRAY_BUFFER while the VAO is bound.

Yes that odd but the reason this is the case is because VAO's were added after VBO and EBO.

In 4.5 (or with the Direct_state_access extension) you can instead use glVertexArrayElementBuffer to directly set the element buffer of a vao.

$\endgroup$
1
  • $\begingroup$ This answer is very helpful. In Example 3.5 of the Ninth Edition of the OpenGL Programming Guide, the EBO is bound before the VAO is bound, which doesn't work on my computer. After reading this answer I switched the order, which made it work. In Joey de Vries' "learnopengl.com" website, the correct order is given. $\endgroup$
    – Simon
    Sep 25, 2022 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.