Should I create a VAO and a VBO for each shape I want to draw?

I am a 3nd-year cs student, and I am new to openGL.

I don’t quite understand the basic concept of openGL.

For example, in Java, I know I should create a class for each kind of entity as Object-Orientation concept asks.

But, is there any similar concept in openGL, such as “creating a VAO and a VBO for each shape”?

I want to draw a robot with 1 torso, 2 arms and 2 leg, and I have done the torso part.

Next I want to draw the legs, but I am not sure if I should put the vertices data and indices data in the same VBO and VAO with the torso.

Should I create a new VAO and a new VBO for the 2 legs?

I think it will be more clearer than putting all data of different shapes into one single VBO and VAO.

If this is the way to do it, am I switching between VAOs and VBOs in display() function?

Thanks in advance!

No. Well, it’s possible to do that, but you shouldn’t.

No.

Forget about object-oriented design, it will lead you in the wrong direction. That’s not to say that you can’t produce an OO structure which works well with OpenGL, but you need to design the structure around what’s convenient for the hardware. If you’re still learning, you’re better off just ignoring OOP concepts entirely.

As a rough guide, all structurally-similar geometry should use a single VAO and a single set of VBOs (this may be one VBO in total, or one VBO per attribute, or somewhere in between). Only use different VAOs for geometry with structural differences: different sets of attributes or different layouts (e.g. static geometry might put all attributes in a single VBO, dynamic geometry might put static and dynamic attributes in separate VBOs for more efficient updates).

Once you start pushing the hardware to its limits (which isn’t exactly an issue here, but it strongly influences the design of the OpenGL API and how its intended to be used), you want to minimise the number of draw calls (glDrawElements() etc). All of the geometry drawn by a single draw call has to use the same VAO. A draw call doesn’t have to use all of the geometry contained in a VAO; you can split drawing the geometry contained in a VAO across multiple draw calls. But you can’t merge geometry split across multiple VAOs into a single draw call. All other factors being equal, the fewer VAOs the better.

[QUOTE=GClements;1293637]No. Well, it’s possible to do that, but you shouldn’t.

No.

Forget about object-oriented design, it will lead you in the wrong direction. That’s not to say that you can’t produce an OO structure which works well with OpenGL, but you need to design the structure around what’s convenient for the hardware. If you’re still learning, you’re better off just ignoring OOP concepts entirely.

As a rough guide, all structurally-similar geometry should use a single VAO and a single set of VBOs (this may be one VBO in total, or one VBO per attribute, or somewhere in between). Only use different VAOs for geometry with structural differences: different sets of attributes or different layouts (e.g. static geometry might put all attributes in a single VBO, dynamic geometry might put static and dynamic attributes in separate VBOs for more efficient updates).

Once you start pushing the hardware to its limits (which isn’t exactly an issue here, but it strongly influences the design of the OpenGL API and how its intended to be used), you want to minimise the number of draw calls (glDrawElements() etc). All of the geometry drawn by a single draw call has to use the same VAO. A draw call doesn’t have to use all of the geometry contained in a VAO; you can split drawing the geometry contained in a VAO across multiple draw calls. But you can’t merge geometry split across multiple VAOs into a single draw call. All other factors being equal, the fewer VAOs the better.[/QUOTE]

Thank you!