VBO Strategies

Started by
1 comment, last by iceware 15 years, 4 months ago
I've never really bothered to learn VBOs (client-side vertex arrays have been fine for my purposes). But vertex arrays are deprecated in GL3, so it's time to learn VBOs. The general concept is fine, but I'm not really sure the best way to actually use them... Should I create one large VBO and stuff one (or more) objects in it at a time? many small VBOs for each object? some combination of the two? My first thought was to do lots of small ones, and let the driver handle deciding which to stick in VRAM, just like for textures. If I do skinning on the GPU, I can just load all the vertex data at the beginning and not worry about it. I don't know if this could cause problems with drivers that don't like to swap out VBOs or something like that, though.
Advertisement
It's best to reduce the number of calls to GL so in order to do that, it is is best to keep many objects in one VBO and do the same for the index buffer object (IBO). You can make each VBO/IBO 1 to 4 MB which is ok for all graphic cards.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
I agree with V-man. In my engine, I keep [up to] several large IBOs and VBOs and fill each with objects that can be rendered with the same shaders. In many cases I can draw all the objects in a VBO with one glDrawElements() call, which reduces "batch" overhead to nearly zero. Actually, a clever programmer can be slightly more efficient by filling up each IBO and VBO from both ends (one end for each of two batches... and let them grow until they meet).

If you have a GL3 capable video card, you probably have plenty of video RAM to hold a large environment without drivers swapping IBOs/VBOs in and out.

This topic is closed to new replies.

Advertisement