Game Development Reference
In-Depth Information
To do this, we need to call SpriteBatch->Begin() before we draw anything. For
our purposes, we can just call Begin without any parameters; however, if you want
to alter the GPU state during the batch, or change the batching mode, you would do
that here.
Sorting modes
There are a few different modes available for batching, so you can choose the best
one for your situation:
SpriteSortMode_Deferred
SpriteSortMode_Immediate
SpriteSortMode_FrontToBack
SpriteSortMode_BackToFront
SpriteSortMode_Texture
Deferred is the default option, and this takes the sprites in the order you submit
them, waits until End is called, and then submits them to be drawn.
Immediate removes the benefit of batching by sending draw calls for every sprite
you draw, as soon as you call Draw . This is useful in some cases where batching is
giving you issues or you just want to use SpriteBatch as an easy way to do 2D.
FrontToBack sorts the sprites by their depth parameter, drawing the sprites closest
to the screen (0.0f) first. BackToFront does the opposite, and draws the sprites
behind first. This is where you need to look at what you're drawing and make a de-
cision. By rendering FrontToBack you make the most of the depth culling func-
tionality on modern GPUs. As the closest sprites are drawn first, the GPU knows
that those pixels are now occluded and minimizes overdraw in those regions. Back-
ToFront is often necessary when you are working with transparent sprites, often in
particle effects. To keep using depth culling with other objects, you need to render
these back to front to ensure that the particles can blend together without artifacts.
Finally, texture is a special sorting mode, where the batch will look at the textures
you're drawing and determine if you're reusing the same texture anywhere. If you
are, it can batch the calls together for each texture, optimizing the number of texture
Search WWH ::




Custom Search