I've created a practice application for rendering triangles/squares/cubes using VBOs. This is mainly so I can get it right before upgrading a 3D block world game I've written that currently is using display lists to cache block rendering.
I have a 3D cube rendering with an interleaved VBO and I recreated a basic chunk/block system that does the following:
- Loads chunks in a 10x10 area
- Each chunk creates its own float buffer and adds 16x16x16 cube vertices, colors, texture coordinates.
- Each chunk then is rendered via its own VBO.
The VBO rendering code, called per-chunk, looks like this:
interleavedBuffer.flip();
glGenBuffersARB(ib);
int vHandle = ib.get(0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vHandle);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, interleavedBuffer, GL_STATIC_DRAW_ARB);
glVertexPointer(3, GL_FLOAT, 32, 0);
glColorPointer(3, GL_FLOAT, 32, 12);
glTexCoordPointer(3, GL_FLOAT, 32, 24);
glDrawArrays(GL_QUADS, 0, vertexCount);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
ib.put(0, vHandle);
glDeleteBuffersARB(ib);
clear();
This method renders everything perfectly, however it suffers from performance problems. A few chunks of 16x5x16 are fine, 60 fps. Increasing them to 16^3 and loading 10x10 chunks, the performance drops to 8fps.
I'm preparing to use VBOs on a game that loads at most 20x20 chunks of 16x128x16 dimensions so I need resolve this performance issue.
What are my choices?
- I have yet to look into interfaced/indexed VBOs. I've heard those are good choices when rendering many of the same thing?
- My game currently uses display lists to cache chunk rendering, and I only refresh that cache when a block change is made that requires it. Is there something similar I can do with VBOs?
For reference, my code for the chunk loading and chunk rendering can be perused.