# Render batching clarifications

**URL:** <https://discourse.libsdl.org/t/render-batching-clarifications/26113>\
**Category:** SDL Development\
**Created:** [May 3, 2019, 11:36am UTC](https://discourse.libsdl.org/t/render-batching-clarifications/26113 "2019-05-03T11:36:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nmviper](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/nmviper/32/4974_2.png) [@nmviper](https://discourse.libsdl.org/u/nmviper)\
**Post date:** [May 3, 2019, 11:36am UTC](https://discourse.libsdl.org/t/render-batching-clarifications/26113/1 "2019-05-03T11:36:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sjr](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sjr/32/5749_2.png) [@sjr](https://discourse.libsdl.org/u/sjr)\
**Post date:** [May 8, 2019, 3:32am UTC](https://discourse.libsdl.org/t/render-batching-clarifications/26113/2 "2019-05-08T03:32:07Z")

</div>

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)
