SpriteSortMode.Immediate in XNA Game Studio 4.0

Originally posted to Shawn Hargreaves Blog on MSDN, Monday, April 5, 2010

Every now and then, a Game Studio 3.1 customer tries something like:

    spriteBatch.Begin(SpriteSortMode.Immediate);

    SetRenderStateFoo();
    spriteBatch.Draw(...);

    SetRenderStateBar();
    spriteBatch.Draw(...);

But this does not work! Sadness ensues.

The problem is that SpriteSortMode.Immediate did not really mean "immediate". A more accurate name would have been "inelegant hack that was added to enable drawing sprites with custom renderstates or shaders, but which still does some minimal amount of batching in the interest of having the aforementioned sprite drawing not be ridiculously slow when there are large numbers of such sprites". That's too long to make a good enum name, though, so we just went with "immediate" :-)

Prior to Game Studio 4.0, the way SpriteSortMode.Immediate actually worked was:

That really only allowed one usage pattern:

Any time you wanted to change state, you had to End the current batch, then Begin a new one.

As of Game Studio 4.0, it is now possible to use custom renderstates and custom shaders with any SpriteSortMode, so Immediate mode no longer has to worry so much about batch performance.

So, we changed SpriteSortMode.Immediate to work the way people always expected it to. Every Immediate mode SpriteBatch.Draw call now generates a separate GPU draw call, exactly like the name implies, really truly immediately with no batching whatsoever.

Implications:

Blog index   -   Back to my homepage