This is a continuation of this thread.
[quote="<MagicSpark.org [ BlueSky ]>,post:11,topic:28379"]
…or at least can you explain what is really going to be changed ? And if a node is moved on the scenegraph, will the renderbin(s) be destroyed and recreated or will it be reused ? What is exactly a RenderBin ? If my idea on renderbins is right how costly it is to translate a node into a RenderBin ?
[/quote]
Well then… I’ll try to explain, what I’ve done so far in this concern and what I’m planning to do…
First about the RenderBins: A RenderBin is a class that imitates a dynamic array like Vector or ArrayList. I guess it was written before these ones were present in Java or before they were performand. (In the future) I’ll check if we can replace this functionality of the RenderBin with an ArrayList.
It further holds a list of RenderBuckets, which on their part hold exactly one instance of RenderAtom and some additional information. I think we can move these additional information into the RenderAtom class to have less objects in the boat. But that’s for the future, too.
A RenderAtom holds exactly the information of one Shape3D that’s needed by OpenGL to render it. You can regard it as a “flatten” version of the shape taken out of the scenegraph. So the localToVWorld Transform3D is one of the information.
There’re more than one RenderBin in the system but two of them are the most important ones: the opaque and transparent bin. The opaque bin holds all opaque shapes and the transparent bin all transparent ones. There’re more RenderBins and to sum them up:
- RenderSetupBin: So far it only holds the information about a background color. I’ve set this feature to deprecated to be able to waste this RenderBin in the future to not have to maintain it and gain performance. The background color funktionality is now a simple setter of the Canvas3D class. Which is btwe even more logic. The background color is nothing more than the color, OpenGL clears the screen with.
- BackgroundBin: Holds all information about Background Nodes with NORMAL camera mode except the background color which resides in RenderSetupBin.
- BackgroundBin: Holds all information about Background Nodes with FIXED camera mode except the background color which resides in RenderSetupBin.
- BackgroundBin: Holds all information about Background Nodes with FIXED_POSITION camera mode except the background color which resides in RenderSetupBin.
- ForegroundBin: Holds all information about Foreground Nodes with NORMAL camera mode
- ForegroundBin: Holds all information about Foreground Nodes with FIXED camera mode
- ForegroundBin: Holds all information about Foreground Nodes with FIXED_POSITION
- ShadowBin: Holds all Shadow Nodes.
- OpaqueBin: Holds all transparent (translutient) Nodes.
- TransparentBin: Holds all opaque Nodes.
The last two will always be the most inhabited ones.
The Shapes are spread over all these RenderBins to sort them by states. OpenGL can them get one state change (glEnable) before a whole bin is rendered and not one state change before each shape. States changes are said to be expensive.
Before each and every single frame all RenderBins are cleared and refilled by traversing the whole scenegraph. If we can track all changes to be known of to spread the shapes over the bins (this is the thing I need to check), we can put the shapes into a differen bin, in the moment the appropriate change is done. Maybe it would be a first pragmatic thing to but them all into one big RenderBin when the’re created (not each frame) and iterate to bin 10 times (as often as how much RenderBins are present now) and render only the Atoms (Shape3Ds) that match the current state. I guess this is possible anyway and will be less expensive than traversing the whole scenegraph and clearing and filling the RenderBins each frame.
During the necessary changes for the “low level multipass rendering” I moved the RenderBins from the Renderer class to the BranchGroup class to have one set of RenderBins for each pass. The place in the BranchGroup offers another important advantage: When a modification on a shape has been done, we can move upwards in the scenegraph tree and find the root BranchGroup (if the shape is live) and make the necessary changes in the RenderBinProvider (which holds the 10 RenderBins), which is assotiated with the BranchGroup. When a Node is not live this can’t be done and doesn’t need to be done. When a Node is added to a parent, the modifiacation in the RenderBinProvider is done for the Node itself and possibly in it’s subnodes if it is a Group.
Any questions? I hope this explains my plans ;D
Marvin