Render batching clarifications


#1

Hello, good people,

Today I found out that there we will (hopefully) have a Render Batching mechanism out-of-the-box with next versions of SDL2 (SDL-2.0.10 I suppose?)
I am extremely happy and grateful about this upcoming feature! Thank you!

In that matter I want to get some things clear about when the internal SDL2 implementation decides to “flush” the stored commands.
If I understood correctly the “flush” happens when certain commands occur (like SDL_RenderPresent, SDL_SetRenderTarget, etc …)

Imagine this situation:

  • You have SDL_Texture’s A and B;
  • The draw order of those texture for a single frame is A, B, A, B, SDL_RenderPresent;

My question is:
Does the change from A to B and vice-versa(because they are different textures) trigger the “flush” of the stored commands for the render batch?
In other words will this sequence “A, B, A, B, SDL_RenderPresent” generate 4 different render batches or a single render batch (with 4 textures inside)?

Bonus question:
I am assuming the sequence “A, B, A, B, SDL_RenderPresent” will generate 1 render batch.
Will the underlying graphics backend suffer a penalty, because the textures are constantly being swapped?
If yes, I assume “A, A, B, B” will generate better results(1 texture switch) than “A, B, A, B”(3 texture switches).

Regards


#2

Anything that causes a state change, like using a different texture, will trigger a flush/new render batch.

So in your example, drawing with texture A, then B, then A, then B, will be 4 render batches. How big of a penalty this is will depend on the hardware. (in this extremely simple example, the hardware would get through it so quickly as to not matter)