What Uses Batching?
by practicing01 · in Torque 2D Beginner · 08/21/2013 (1:07 am) · 3 replies
Are composite sprites the only thing that uses "batching"? Can someone explain how this works and why the engine can/can't automatically batch everything, please?
#2
github.com/GarageGames/Torque2D/wiki/Batch-Rendering-Guide
08/25/2013 (4:18 am)
Thanks to the modern wonders of tablets and the mobile internet, I was able to use a long bus ride to the airport to work on Steering Committee business! Now Simon's helpful post and Melv's great write up on batching are immortalized into a wiki guide:github.com/GarageGames/Torque2D/wiki/Batch-Rendering-Guide
#3
08/25/2013 (5:26 am)
Awesome job, Mike!
Associate Simon Love
For example, create a composite sprite and set each SpriteBatchItems on different Depths.
Then, create a Sprite (unrelated to the composite sprite) and set it on the same layer as the composite sprite and at a random depth.
You will see that the independent Sprite will be rendered behind the SpriteBatchItems in the CompositeSprite which are on a higher SpriteDepth.
If you set the CompositeSprite's BatchIsolated property to true, none of that happens, your independent Sprite will either be in front of the CompositeSprite or behind. Now imagine adding Blending options, multiple layers + multiple Sprite Depths and you'll see that the rendering engine can't batch everything and keep this type of complexity.
Melv had written about this in the very first T2D MIT announcement blog. It's a long read but it explains in extreme detail all the batching and sorting options you have with the engine.
Batching is enabled by default, meaning that the engine tries to make the least amount of render passes possible by batching together items which can be rendered in one drawing call.
Another important concept discussed in the article is Sorting.
Each Layer's sorting mode can be changed using the following line of code : OR
You can use any of the following values in the layerSortMode function
Off - No sorting.
Newest - The newest render request (typically the age of the SceneObject) is rendered in front
Oldest - The oldest render request (typically the age of the SceneObject) is rendered in front
Batch - Sorted so that the absolute minimum number of draw-calls are required.
Group - Sorted by each objects assigned render group name.
X - Sort so that things further along the X-Axis are rendered in front
Y - Sort so that things further along the Y-Axis are rendered in front
Z - Sort so that things further along the Z-Axis are rendered in front
-X - Sort so that things further along the X-Axis are rendered at the back
-Y - Sort so that things further along the Y-Axis are rendered at the back
-Z - Sort so that things further along the Z-Axis are rendered at the back
As mentioned by Melv, "Batch" will disregard the 'age' of objects in the layer and provide you with the fastest rendering possible. It could however produce weird results, objects being drawn in front of others, etc.
You could also precisely control batching by using the "Group" sorting mode and setting Sprites into specific render groups by calling
Sprite.setRenderGroup("Group1");Hope this helps!