VBO with IndexBuffer (and some general VBO stuff)

On my local CVS copy I've hacked in support for using VBO for indices when using TriMeshes. Gave me a nice little boost in FPS for my new terrain engine (which despite it's crawling pace is almost ready now). It works well so far, but the problem is more in how to integrate it properly in the code:

Right now the VBO stuff is nicely split off from draw(TriMesh t). However, using VBO with indices requires a different version of the GL11.glDrawElements method, so it looks extremely hacky right now:

// does not even check for capabilities yet.
if (t.getVBOInfo() != null && t.getVBOInfo().isVBOIndexEnabled() && t.getVBOInfo().getVBOIndexID() > 0) {
         GL11.glDrawElements(GL11.GL_TRIANGLES,t.getTriangleQuantity()*3, GL11.GL_UNSIGNED_INT, 0);           
 else {
          GL11.glDrawElements(GL11.GL_TRIANGLES, indices);

The easy way would be using a boolean return type for predrawGeometry (currently void). Easy.. but too hacky? Any better suggestions?

Secondly, getIndexBuffer is not a Geometry method, but one of TriMesh, CompositeMesh, Line (etc?) so currently I only implemented it for TriMesh. I'll try to implement it for CompositeMesh but preferable after the first check in.

Also, working with VBO can be tricky right now. Many new unneeded VBOs can be created for the same Buffer (right now I'm working around this by setting them manually after the first is created). I assume this means these buffers are stored seperate on the videocard too. I could make something that first checks if a VBO id already exists for a Buffer (rather simple using a WeakHashMap, with no impact for the user). Lasty.. shouldn't VBOs be destroyed when no longer in use (glDeleteBuffersARB)?


Checked in and posted a notice in Dev General: