SDL_HINT_RENDER_BATCHING question

I explicitly specify the OpenGL backend using SDL_HINT_RENDER_DRIVER, so I’m not getting batching by default in SDL 2.0.10. Can it be enabled at any time using SDL_HINT_RENDER_BATCHING, or is this (undocumented) hint only recognised if it is issued before the renderer is created?

1 Like

The hint is checked during SDL_CreateRenderer(), and can not be changed for a renderer once created (but this means you can have two separate renderers exist at the same time that have this hint set differently).

If you’re explicitly setting the RENDER_DRIVER hint, you should set the RENDER_BATCHING hint too (if you don’t, it should still perform about at least as well as SDL 2.0.0 through 2.0.9 did!).

Will that work on all platforms, including Android and iOS, or only on desktop platforms?

I may try that but it will impact my code elsewhere because I call glLogicOp() to set ‘logical’ plotting modes (AND, OR, XOR) - that’s the very reason that I force the OpenGL backend - so I will at least have to call SDL_RenderFlush() before doing so.

It will work if you can have two renderers at the same time on Android, as batching isn’t a platform-specific thing, but I don’t know if that is possible or not.

Yep, that’s exactly what RenderFlush is used for!

What is the recommended cross-platform approach for calling SDL_RenderFlush() when you can’t be sure it’s available (in my Linux releases I rely on the pre-built SDL2 binary from the relevant repository, so I don’t know what version it will be)? I can try to find its address at run time using dlopen() / dlsym() or LoadLibrary() / GetProcAddress() depending on the platform, but that’s really quite messy.

Could I cheat by calling another SDL2 function (one that exists in all versions) that has the side-effect of flushing the batching queue? I’m thinking of perhaps a dummy call like:

 SDL_SetRenderTarget(renderer, SDL_GetRenderTarget(renderer));

but I’d only want to do that if the overhead is low.

You can check the linked SDL version at runtime:
https://hg.libsdl.org/SDL/file/default/test/testver.c

Yes, I do, but my code won’t even run if it calls SDL_RenderFlush() and that function is not in the SDL2 DLL or binary installed from the repository (there will be a fatal error at load time because of the missing function)! So I would need to get the function’s address at run-time anyway, and if I’m doing that it’s a more direct way of ascertaining whether it’s available than testing the SDL version.

Hints being just that, is there a way of checking, after the renderer has been created, whether batching is indeed enabled? I know I could call SDL_GetHint() but I’m unsure whether that reliably reports the batching state, or simply the fact that the hint was recognised.

Testing confirms it doesn’t. Even on SDL 2.0.9 it returns “1” if the hint was accepted, even though there is no render batching in that version. So I’m still looking for some way to find out if batching is active (I know it should be ‘transparent’ but I would expect there to be a renderer flag or some other way of confirming it).