SDL_CreateGPURenderer(3)

πŸ“¦
version 3.4.18 Β· 5 versions
, in fedora 43, fedora 44

πŸ’– SDL_CreateGPURenderer πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual β€” this one's SDL_CreateGPURenderer(3) and it's literally the glow-up moment where your 2D rendering gets a whole GPU era. πŸ‘‘


✨ NAME ✨

SDL_CreateGPURenderer β€” spin up a 2D GPU rendering context, no cap. πŸŽ€


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_render.h>

SDL_Renderer * SDL_CreateGPURenderer(SDL_GPUDevice *device, SDL_Window *window);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea, fr fr: the GPU device you wanna use gets passed in as a parameter. If that's NULL, then a device just gets created normally for you, and you can go grab it later with SDL_GetGPURendererDevice(). cute, right? πŸ’…

the window you wanna use also gets passed in as a parameter. If that one's NULL, then this becomes an offscreen renderer ✨. in that case you should call SDL_SetRenderTarget() to set up rendering to a texture, and then call SDL_RenderPresent() like normal to wrap up drawing a frame. that's the whole ritual, periodt. 🫢


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • device β€” the GPU device you wanna use with the renderer, or NULL if you want a device created for you. πŸ’œ
  • window β€” the window where the rendering shows up, or NULL if you want an offscreen renderer instead. πŸͺŸ

πŸ’€ RETURN VALUE πŸ’€

you get back a valid rendering context β€” slay β€” or NULL if something went wrong 😭. in that case, call SDL_GetError() for the deets on what actually happened.


🧚 THREAD SAFETY 🧚

listen, this part matters so don't skip it:

  • If you call this with a valid GPU device, it should be called on the thread that created the device.
  • If you call this with a valid window, it should be called on the thread that created the window.

do not be out here calling it from a random thread, bestie, it's giving chaos energy and we don't want that. πŸ™ˆ


⭐ AVAILABILITY ⭐

this function has been available since SDL 3.4.0. lowkey a newer icon. πŸ‘‘


🌈 SEE ALSO 🌈


okay that's the whole page, go make something iconic with it. πŸ’–

Simple Directmedia Layer πŸ¦‹ SDL 3.4.18 πŸŽ€ SDL_CreateGPURenderer(3) β€” mwah, tysm for reading, ily, go render something gorgeous. βœ¨πŸ’…πŸŒΈ

πŸ“¦ where this page comes from