1
votes

This is a theoretical question, so I don't have code until now.

Assuming that I have a VBO with vertex position data and am using it within a VAO to render an indexed (glDrawElements()) figure out of triangles with a special index array.

Now I want to reuse this data buffer within a second VAO to render some other figures consisting out of lines, but with a different index array.

How do I need to bind the buffers, so that I can reuse the vertex data of the first VAO?

1
Idk why, but to me it makes more sense to me to create multiple element arrays and change them than multiple vao's.RamblingMad
It seems to me a bit more modular, but I will think again about it. Thanks.user3572032

1 Answers

4
votes

no special code is needed to share the buffers between VAOs just bind them as you normally would.

setting up:

glBindVertexArray(VAO[0]);
glBindBuffer(GL_ARRAY_BUFFER, locBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, triangleBuffer);
glVertexAttrPointer(...);

glBindVertexArray(VAO[1]);
glBindBuffer(GL_ARRAY_BUFFER, locBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, lineBuffer);
glVertexAttrPointer(...);

and when drawing:

glBindVertexArray(VAO[0]);
glDrawElements(...);

glBindVertexArray(VAO[1]);
glDrawElements(...);