The usual sequence in a rendering engine is the following ;
-
Application phase
Application modify scenegraph according to user input and application specific behavior.
-
Culling phase
The scenegraph is traversed, nodes that are (likely) visible are inserted to a “display list” (not an opengl display list).
The display list is then sorted.
-
Drawing phase
The display list is rendered.
A BSP, octreee, quadtree, portal engine, or whatever system is used in the culling phase to avoid having to traverse the complete scenegraph and therefore save time. The usual way to do this is to hve a separate data structure, let’s say a scene manager, that will hold the spatial coherence of your scene. This scene manager will be able to quickly mark which nodes are inside or outside its space subdivisions. This can be rather fast since the scenegraph is a hierarchical system where you can state that if a group bounding volume is entirely in a space subdivision then all its children are.
The state/depth sorting happens after this scenegraph traversal. Therefore the two optimizations are not linked.
It is important to note that these 2 optimizations serves different purposes ;
- spatial culling mainly optimizes the CPU work (and eventually the GPU vertex processing phase),
- state/depth sorting mainly optimizes the GPU work (and puts a little bit more stress on the CPU).
To finish with that, I would add that all space subdivision techniques are designed for big scenes where only a small part of the scene is visble at one time. If it is not your case, simple bound base culling is far enough and before diving in one of the space division techniques (which can be quite heavy work), I think you should profile your engine.
About your question on the garbage collector, the answer is yes and no… I mean ‘yes’ java manages memory for you but ‘no’ the default memory management provided does not suit the needs of realtime applications. The main problem is that realtime applications need to have a predictive execution time. The garbage collector breaks this since when it executes, it will slow done the speed of your system and its execution is not plannable. The consequence is that your animation looks choppy.
There are different ways to handle this and you will find quite a lot of messages on the subject in this forum. I did not find any perfect solutions but just using the concurrent garbage collector and lowering the amount of garbage generated was enough for my needs.
Vincent