0

So I recently learned about VAO (Vertex Array Object), and so far they seem pretty awesome, but I have a problem I cant seem to solve. I have a bunch of models, their vertex-states are stored in separate VAOs, so a single call to

    glBindVertexArray(VAO);

is all that is needed to begin draw an instance of this. The problem lies in that I have to bind an additional VAO, one containing the data for a

    glDrawElementsInstanced();

call. So it contains data like offset, UV-offset, color-overlay etc. When I bind this, the previous one seem to unbind itself, which makes sense in OpenGL I guess, but I'm not sure what to do to have both active?

The idea is to draw all static objects that shares the same model without uploading any data per-frame. Is this a wrong approach entirely?

Jacob Kofoed
  • 141
  • 3
  • 9

1 Answers1

3

When I bind this, the previous one seem to unbind itself, which makes sense in OpenGL I guess, but I'm not sure what to do to have both active?

Of course it unbinds. That is how OpenGL works. It is a state machine, and you want to have two states active at the same time.

The idea is to draw all static objects that shares the same model without uploading any data per-frame.

If they do not change, then do not change them. You just have to bind and activate the vertex components (as explained here).

BЈовић
  • 62,405
  • 41
  • 173
  • 273
  • This doesn't seem to help me much, I know that OpenGL is a state Machine, so what I am asking is how to combine the states from two VAOs, in need of better word. So the first VAO contain all the states for the vertecies, while the second hold all states for the instance-data. I need a combination of the states, right now it works when I bind all the VBOs instead of using the VAOs. – Jacob Kofoed Nov 05 '13 at 17:20
  • 1
    That is a pretty poor design. VAOs are little more than state containers... if you want to use two VAOs with different index buffers, then go ahead and do that. But do not make one VAO dependent on the state of another VAO. To this end, in OpenGL 3.2 core, you always have to use at least one VAO because VAOs are the context with which you bind VBOs. If none is active, then an entire set of GL commands will have no valid context. The one area where VAOs can make things complicated is memory management, if you delete a VBO that is bound by an inactive VAO, the memory is not freed immediately. – Andon M. Coleman Nov 05 '13 at 23:14
  • So there are circumstances where you would use VBOs without a VAO? – Jacob Kofoed Nov 07 '13 at 18:30
  • @JacobKofoed: In a compatibility profile you are allowed to do this. In OpenGL 3.2 core+, you must have a VAO bound in order to use a VBO. But you are free to have VBOs floating around that are not bound to a VAO if that is what you were asking? Likewise, you can have VAOs with no VBOs attached. It is just when you go to use a VBO for a draw call, vertex pointer, etc... that it must be in the context of a VAO. – Andon M. Coleman Nov 08 '13 at 00:16
  • @AndonM.Coleman What will happen if you try to render with VAO, without VBO? – BЈовић Nov 08 '13 at 07:00