1
\$\begingroup\$

I'm just messing around with OpenGL and getting some basic structures in place and my first attempt resulted in each SceneObject class (just contains vertex information right now) having it's own VBO inside it, however I've read that it might be better to share VBOs across multiple objects.

Also, I read that you should avoid resizing a VBO (repeated calls to glBufferData with different size parameters), and instead choose a fixed size for a VBO, and just try a range from the buffer. I don't think changing the size of the buffer data would happen too often, but surely it would be better to only allocate the data you need? Choosing an arbitrary value seems risky.

I'm looking for some advice on working with individual objects in a scene and their associated buffer data.

\$\endgroup\$

2 Answers 2

3
\$\begingroup\$

Don't create a new VBO for each SceneObject. Instead create a new VBO for each mesh and have multiple SceneObjects reference the same VBO if they are using the same mesh. If you are using shaders you will never be modifying your data within your VBOs since you will be instead sending a set of matricies to the shader which will transform the 'static' verticies.

Your VBOs should almost always be considered static with the exception being streamed geometry such as terrain.

\$\endgroup\$
6
  • \$\begingroup\$ So if I have 2 cubes, would each side of a cube be a mesh, and those meshes be shared amongst both cubes? Then when drawing via the shader, use a matrix to transform from the position of cube1 to cube2? \$\endgroup\$ Commented Sep 3, 2012 at 20:51
  • \$\begingroup\$ @MarkIngram you would have 1 'cube' mesh and you would have 2 transform matricies. It would basically be like SetVBO(Cube); SetMatrix("transform", Cube1Transform); Render(); SetMatrix("transform", Cube2Transform); Render(); \$\endgroup\$
    – NtscCobalt
    Commented Sep 3, 2012 at 20:59
  • \$\begingroup\$ Ah OK, so each object would contain a reference to a potentially shared mesh object. Thanks. \$\endgroup\$ Commented Sep 3, 2012 at 21:12
  • \$\begingroup\$ And what about objects that does change vertices, for example, an arc that is rendered/generated each frame with differents values for startingAngle and sweepAngle? \$\endgroup\$ Commented Mar 31, 2013 at 16:39
  • \$\begingroup\$ @JCM If you can perform all of the calculations for the arc on the GPU in shaders then you can still use a shared static VBO. If not then yeah you will need a separate VBO per object as well as making it dynamic so you can modify the vertices. You will see a significant performance loss if you do this with a large amount of objects or are updating a large amount of vertices every frame. \$\endgroup\$
    – NtscCobalt
    Commented Apr 1, 2013 at 15:29
0
\$\begingroup\$

Sharing a VBO applies for very particular cases, the usual way to go is to have one VBO per mesh. If you have many instances of the same mesh, look at instanced rendering.

It should be noted that glBufferData() allocates memory (on the GPU for almost every modern hardware), which is why it shouldn't be called too often.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .