LunchMarble
LunchMarble

Reputation: 5141

How many VBOs do I use?

So I understand how to use a Vertex Buffer Object, and that it offers a large performance increase over immediate mode drawing. I will be drawing a lot of 2D quads (sprites), and I am wanting to know if I am supposed to create a VBO for each one, or create one VBO to hold all of the data?

Upvotes: 11

Views: 10604

Answers (3)

micha
micha

Reputation: 49572

You shouldn't use a new VBO for each sprite/quad. So putting them all in a single VBO would be the better solution in your case.

But in general i don't think this can be answered in one sentence.

Creating a new VBO for each Quad won't give you a real performance increase. If you do so, a lot of time will be wasted with glBindBuffer calls for switching the VBOs. However if you create VBOs that hold too much data you can run into other problems.

Small VBOs:

  • Are often easier to handle in your program code. You can use a new VBO for each Object you render. This way you can manage your objects very easy in your world
  • If VBOs are too small (only a few triangles) you don't gain much benefit. A lot of time will be lost with switching buffers (and maybe switching shaders/textures) between buffers

Large VBOs:

  • You can render tons of objects with a single drawArrays() call for best performance.
  • Depending on your data its possible that you create overhead for managing a lot of objects in a single VBO (what if you want to move one of these objects and rotate another object?).
  • If your VBOs are too large its possible that they can't be moved into VRAM

The following links can help you:

Vertex Specification Best Practices

Upvotes: 19

fen
fen

Reputation: 10115

It also depends what d you want to do with those sprites?

Are they dynamic? Do you want to change only the centre of quad or maybe modify all four points?

This is important because if your data are dynamic then, in the simplest way, you will have to transfer from cpu to gpu each frame. Maybe you could perform all computation on the GPU - for instance by using geometry shaders?

Also for very simple quads/sprites one can use GL_POINT_SPRITE. With that one need to send only one vertex for whole quad. But the drawback is that it is hard to rotate it...

Upvotes: 1

genpfault
genpfault

Reputation: 52083

Use one (or a small number of) VBO(s) to hold all/most of your geometry.

Generally the fewer API calls it takes to render your scene, the better.

Upvotes: 1

Related Questions