Question: SDL-GPU uses and improvements over vanilla SDL

I have stumbled upon SDL-GPU ( https://github.com/grimfang4/sdl-gpu ), seems it is an optimized library for 2d rendering in GPUs. Seems the main feature is Batch rendering (for transfer optimization), a shader API and float point coordinates for subpixel precision (as far as I know vanilla SDL already implemented).

Since I’m still studying the available technologies in GameDevelopment world I would like to know how these improvements impact 2d game development, is possible to do batch rendering with vanilla SDL? How to handle shaders in SDL without sdl-gpu?

Yes, batching is on by default since SDL 2.0.10 and can be explicitly enabled using:

	SDL_SetHint ("SDL_RENDER_BATCHING", "1") ;

(I’ve used the literal string rather than the #defined SDL_HINT_RENDER_BATCHING so it will still build with older SDL headers).

Thanks!

So the advantages left in SDL-GPU are:

  1. Shader helper functions (IO handlers/load/compile/link/logging);
  2. GPU direct primitives;
  3. GPU Matrix math calls (that I don’t know if they use compute shaders).

SDL is eventually filling in some of the gaps that made me write SDL_gpu. Batching, floating point positions, blend modes/factors/operations, and some other small things. One of the long-term goals of SDL_gpu has been to see more of these features integrated into SDL by serving as a reference.

There are a lot of things that are just easier to do with SDL_gpu, but you can write your own functions to abstract how SDL needs to do it. That’s mostly a difference on the style side of things.

Shaders are definitely easier to do with SDL_gpu right now. I don’t recall if SDL added arbitrary 3D geometry yet, but people had been working on an implementation of that and SDL_gpu has had it. I also don’t know if SDL exposes the handles for its underlying GL objects yet.

Besides that, SDL_gpu has some quality-of-life additions that SDL should never adopt, including: integration of STB image for loading and saving images, and 2D primitive rendering. SDL_gpu does not use compute shaders and its matrix operations support its old-school stack-based MVP matrix just for the ease of setting up hierarchical transforms on geometry.

1 Like