How to attach an element buffer to a VAO with DSA?

For OpenGL 3.3 conformance, I am updating some Direct State Access code to use VAO. Problem: I have no idea how to attach an element buffer to a VAO with DSA.

Example of VAO code with ‘bind and edit’:


glBindVertexArray(VertexArrayName);
  glBindBuffer(GL_ARRAY_BUFFER, ArrayBufferName);
  glVertexAttribPointer(semantic::attr::POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);

  glEnableVertexAttribArray(semantic::attr::POSITION);
  glBindBuffer(GL_ARRAY_BUFFER, 0);

  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBufferName);
glBindVertexArray(0);

So far what I have with VAO code with ‘direct state access’:


glVertexArrayVertexAttribOffsetEXT(VertexArrayName, ArrayBufferName, semantic::attr::POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexArrayAttribEXT(VertexArrayName, semantic::attr::POSITION);

???

Thanks!

I had the same problem. I am not aware of any solution. I had to ‘bind’.

OWNED
VAO fail again? I am so evil with VAO! XD

I have no idea how to attach an element buffer to a VAO with DSA.

That’s because you can’t. DSA was released alongside GL 3.0, so it originally didn’t encapsulate any 3.0 functionality. They modified the extension to do so (unfortunately), but this was apparently done in haste. And they missed this particular case.

I came across this thread from time to time, so despite its age i shall add that by now,
OpenGL 4.5 provides glVertexArrayElementBuffer which provides the needed functionality.

Hi…your buffer sources will also have its own offset, which is the base from where to start reading. So you might have a model’s vertex data stored in a vertex buffer, but it’s at offset 320 bytes from the start. You can set this offset on the vertex buffer and the format doesn’t have to take this into account as it and the buffer source are separated