Graphics hardware has gained enourmously in speed over the last few years, and it is still gaining faster than the main processors, even in the light of multi-threading. On the flipside that means that the speed difference between main processor and graphics hardware is getting bigger and it is becoming more difficult to keep the graphics hardware properly fed and busy to take full advantage of the available rendering power. OpenSG provides a number of tools to optionally massage the scene graph data to make it more efficient to draw, and it employs different techniques to optimally use the graphics hardware.
To fully utilize modern graphics hardware it needs to be fed data in relatively large and homogeneous chunks. To simplify and optimize processing the low-level APIs like OpenGL expect the data to be homogeneous, i.e. all vertices in a block have to have the same kinds of attributes with different values. Every block of data also has some setup overhead, and reducing this overhead can make a significant difference. In addition to the raw data there are state changes, i.e. switching between textures or shaders, that need to be minimized to reduce overhead. All of these need to come together to obtain optimal performance.
The best way to optimize data for hardware consumption is to do it once, at load time. OpenSG provides a number of so-called GraphOps that can optionally traverse the scene graph and do optimzation operations on the nodes. Here's a partial list of GraphOps:
- StripeGraphOp: transform individual triangles into connected triangle strips, which can reduce the amount of data that needs to be transfered by a factor of up to 3
- MaterialMergeGraphOp: Analyze all the Materials in the tree and merge the ones that have the same effect into one. Together with the state sorting described below this reduces the number of expensive state changes significantly.
- MergeGraphOp: Merge small (i.e. few polygons) nodes into larger ones to reduce the number of blocks that the graphics hardware needs to handle.
All GraphOps are in the source tree.
One of the big advantages of a scenegraph is the global view that it has. The graphics driver only sees data one piece at a time, while the scenegraph knows the whole scene and can optimize things on a higher level.
In a large, complex scene in general not every piece of the scene is visible at every given time. For example inside a room everything that's behind the viewer is not visible and doesn't need to be processed by the graphics hardware. In addition to these directly invisible parts there can be occluded parts that are hidden by other objects like walls.
OpenSG uses the scenegraph hierachy to build a hierarchy of bounding volumes that are used to quickly decide whether a whole subtree of the graph can be visible and needs to be processed at all. This allows fast pruning of the scene to the potentially visible parts. To reduce the overhead of this processing, it is only done for planes of the viewing frustum that can potentially intersect parts of the traversed scene. This reduces the overhead to a hardly measurable level.
To take advantage of objects hidden by other objects OpenSG employs the graphics-hardware accelerated occlusion queries, that support a conservative visibility check for objects before the effort of a full rendering of the object is spent.
State Change Minimization / Out-of-order rendering
To reduce the number of expensive state changes (like shader or texture switches) the system first traverses the whole scenegraph and collects all nodes that need to be rendered, i.e. all nodes that have been determined to be visible. Before they are actually rendered they are sorted by their state, so that the whole set can be displayed with a minimal amount of overhead. This reshuffling of the nodes can have a significant impact on the performance, as state changes can severly interrupt the flow of data through the graphics hardware and neutralize one of the main techniques to speed up hardware, the pipelining of different operations.
Needs a few more things, this is pretty short.
Due to a variety of techniques employed to speed up processing, OpenSG allows highly optimized use of the available graphics hardware resources to achieve interactive performance even for large and complex scenes.