Well its a little hard to post a snippet since this is running in our Xith3d renderer off of a Java3d scenegraph. The renderer is sitting at 12,000 lines of code as of tonight. (wow, I have been busy the last 2 weeks).
But basically the test scene is just two nested transform groups, one for rotation and one for translation. So a mass of cubes are randomly placed around the origin and then the mass is rotated and translated on each frame
Random ran = new Random(35354);
for (int i=0;i<900;i++)
{
Shape3D shape = new Shape3D();
Appearance a = new Appearance();
a.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_FILL,PolygonAttributes.CULL_BACK,0));
Geometry g = createCube(1-2*ran.nextFloat(), 1-2*ran.nextFloat(), 1-2*ran.nextFloat(), .5f, true);
// Geometry g = createCube(0.5f-ran.nextFloat(),0.5f-ran.nextFloat(),ran.nextFloat()-0.5f,0.5f,true);
shape.setAppearance(a);
shape.setGeometry(g);
tf_2.addChild(shape);
ShapeAtom atom = new ShapeAtom(shape);
r.addAtom(atom);
}
nothing special about the cubes. I am not lighting them, just rendering them with vertex colors. Since the engine sorts states and transforms and only switches the openGL states on changes we basically will have the following rendering pipeline:
- setup view
- set model transform
- set polygon attributes
- set rendering attributes
- setup vertex array and draw
repeat step 5 for each shape, which is 900 in the last test case.
I am going to add an enhancement that detects duplicate geometry and sorts dup geometry seperatly, so we should be able to use the same vertex array over and over… should be faster.