cginternals / globjects

C++ library strictly wrapping OpenGL objects.
https://globjects.org
MIT License
538 stars 59 forks source link

glVertexArrayElementBuffer for VertexArray #346

Closed itsuhane closed 7 years ago

itsuhane commented 7 years ago

Currently, to use index buffer object, one has to manually bind VAO then bind IBO with GL_ELEMENT_ARRAY_BUFFER:

vao->bind();
// :::
ibo->bind(gl::GL_ELEMENT_ARRAY_BUFFER);
// :::
vao->unbind();

In OpenGL 4.5, glVertexArrayElementBuffer was introduced as a part of DSA. VertexArray should add an interface, setIndexBuffer for example, to support this. In this case, one could write:

// :::
vao->setIndexBuffer(ibo);
// :::

without explicitly bind/unbind VAO. This should make the program logically more clear and consistent.

Without DSA, this new interface could be emulated as

void VertexArray::setIndexBuffer(Buffer *ibo) {
    bind();
    ibo->bind(gl::GL_ELEMENT_ARRAY_BUFFER);
}
scheibel commented 7 years ago

Seems like I have missed this function while integrating the DSA strategies. I'll provide an example implementation for testing.