hi there,
i want to load a lot of unchanging objects, or create them on the fly, eg. models like spaceships. i just want to move, rotate and scale them once they are in memory.
so i checked for display list support - jme does no use display lists (only in LWJGLFont). any special reason for this? anything faster in it that i missed?
however, the following code snippet (subclass of LoaderNode) boosts my app from 100fps to almost 400fps:
boolean needsCompile = false;
int displayList = 0;
public void freeze() {
needsCompile = true;
}
public void draw(Renderer r) {
if (displayList != 0 && !needsCompile) {
GL11.glCallList(displayList);
} else {
if (needsCompile) {
if (displayList != 0)
GL11.glDeleteLists(displayList, 1);
displayList = GL11.glGenLists(1);
GL11.glNewList(displayList, GL11.GL_COMPILE_AND_EXECUTE);
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
}
Spatial child = null;
for (int i = 0, cSize = children.size(); i < cSize; i++) {
child = (Spatial) children.get(i);
if (child != null)
child.onDraw(r);
}
if (needsCompile) {
GL11.glPopAttrib();
GL11.glPopMatrix();
GL11.glEndList();
needsCompile = false;
}
}
}
this code has some problems, which i did not solve in the hour i played with it. some of my textures are missing. but this might be handable by someone who knows a bit more of the jme system. if i don't push the attributes i destroy the textures of the font... looks like something does not clean up its state after rendering. maybe it's just my mac ;)
my code depends on LWJGL and therefore is not portable. but it should be easy to extract an interface for freezing:
public void freeze() // to tell the node to freeze before draw
public void beginFreeze() // to call newList
public void endFreeze() // to call endList
public void drawFrozen() // to execute the list
public void melt() // to destroy the list
how about this? anyone likes it?
another question:
can i reuse a loaded model a 100 times? right now i load my model into a new node for every ship. i'd like to just have the ship in memory once and reuse the geometry/LoaderNode at a 100 places. is that possible?