I’m gonna say it…
Try implementing VBOs! :
My MvR engine was mostly DisplayLists and the like. With my new engine, I switched over to VBOs (which I admit, took some restructuring). The speed increase was VERY noticeable. I even switched my font rendering class over (which is basically like your sprite rendering) and noticed a big leap there as well. I have to wonder if the drivers these days are just geared that way.
The other big leap I saw was when I moved from individual textures for sprites to a single, larger texture with all the sprite graphics in it. It didn’t help much when I was using DisplayLists, but with VBOs it was a different story.
NOW, my engine isn’t just for sprites, so your mileage may vary.
Here, this will help you on your way (it’s the least I can do for the help you’ve given me):
package com.tommyengine.utils;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.Sys;
import org.lwjgl.opengl.ARBVertexBufferObject;
import org.lwjgl.opengl.GLContext;
public class VBOUtil {
/*
* To create a VBO ID
*/
public static int createVBOID() {
if (GLContext.getCapabilities().GL_ARB_vertex_buffer_object) {
IntBuffer buffer = BufferUtils.createIntBuffer(1);
ARBVertexBufferObject.glGenBuffersARB(buffer);
return buffer.get(0);
} else {
Sys.alert("ERROR", "VBOs not supported on this hardware");
System.exit(0);
return 0;
}
}
public static void destroyVBOID(int id) {
ARBVertexBufferObject.glUnmapBufferARB(id);
}
public static void bufferDynamicData(int id, FloatBuffer buffer) {
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, id);
ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, buffer, ARBVertexBufferObject.GL_DYNAMIC_DRAW_ARB);
}
public static void bufferStaticData(int id, FloatBuffer buffer) {
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, id);
ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, buffer, ARBVertexBufferObject.GL_STATIC_DRAW_ARB);
}
public static void updateBufferData(int id, FloatBuffer buffer) {
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, id);
ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, buffer, ARBVertexBufferObject.GL_DYNAMIC_DRAW_ARB);
}
public static void bind(int vboID) {
ARBVertexBufferObject.glBindBufferARB( ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vboID );
}
//////////////////////////////////////
//// For Index Buffers (IDOs) ////////
//////////////////////////////////////
public static void bindIndex(int vboID) {
ARBVertexBufferObject.glBindBufferARB( ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, vboID );
}
public static void bufferIndexData(int id, IntBuffer buffer) {
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, id);
ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, buffer, ARBVertexBufferObject.GL_STATIC_DRAW_ARB);
}
}
A sample VBO creation using that code:
// Geometry = FloatBuffer() -- but I'm guessing you knew that
// .put() all of your vertice information into geometry here
coordsVBOID = VBOUtil.createVBOID();
geometry.flip();
VBOUtil.bufferDynamicData(coordsVBOID, geometry);
// .put() all of your vertice information into textureCoords here
textureVBOID = VBOUtil.createVBOID();
textureCoords.flip();
VBOUtil.bufferDynamicData(textureVBOID, textureCoords);
A sample draw routine:
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
VBOUtil.bind(coordsVBOID);
GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);
GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
VBOUtil.bind(textureVBOID);
GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertexCount);
GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
Good luck!