IMG_LoadGPUTexture(3)
π IMG_LoadGPUTexture(3) β the SDL_image3 glow-up π
okay so bestie, welcome to the SDL_image3 functions era β¨ this one lives in section 3 of the manual, and it is literally the "put my picture on the GPU" button. no cap.
πΈ NAME πΈ
IMG_LoadGPUTexture β load an image from a filesystem path straight into a GPU texture. it's giving "file goes in, texture comes out" π
π SYNOPSIS π
#include <SDL3_image/SDL_image.h>
SDL_GPUTexture * IMG_LoadGPUTexture(SDL_GPUDevice *device, SDL_GPUCopyPass *copy_pass, const char *file, int *width, int *height);
π¦ DESCRIPTION π¦
so an SDL_GPUTexture is an image that lives in GPU memory, and SDL's GPU API can actually use it. iconic. π«Ά
and here's the thing that makes this function so slay: no matter what format your source image is in, this function is gonna create a GPU texture with the format SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM, with no mip levels. that's just the deal, fr fr. it can be bound as a sampled texture from a graphics or compute pipeline, and also as a read-only storage texture in a compute pipeline. versatility queen π
now, if you need an i/o abstraction so you can feed data from anywhere instead of a plain old filesystem read, there's a whole separate function for reading from an SDL_IOStream. that one is IMG_LoadGPUTexture_IO(). iykyk π
and when you're done with the texture it hands you? the app should dispose of it by calling SDL_ReleaseGPUTexture(). clean up after yourself bestie, the GPU is not your personal landfill π
β¨ FUNCTION PARAMETERS β¨
deviceβ theSDL_GPUDeviceyou're using to create the GPU texture. this is the main character here.copy_passβ theSDL_GPUCopyPassused to upload the loaded image onto the GPU texture.fileβ a path on the filesystem to load an image from. yes, an actual path, on an actual filesystem πwidthβ a pointer that gets filled in with the width of the GPU texture. it may beNULL, so if you don't care, don't stress πheightβ a pointer that gets filled in with the height of the GPU texture. it may beNULLtoo π§
π₯ RETURN VALUE π₯
returns a new GPU texture, or NULL on error. so if you get NULL, that's your vibe check failing β go check for an error, bestie π
β AVAILABILITY β
this function has been available since SDL_image 3.4.0. she's not new new, but she's not ancient either π
π SEE ALSO π
and that's the whole page, bestie π go forth and texture the GPU, periodt. πΈπβ¨
this page came to you from the SDL_image docs, version SDL_image 3.4.8 β mwah, take care of her π«Ά
π¦ where this page comes from
- fedora 43: SDL3_image-devel 3.4.8-1.fc43 Β· Zlib AND (HPND-Pbmplus AND Zlib) AND MIT AND (MIT OR Unlicense) AND LicenseRef-Fedora-Public-Domain
- fedora 43: SDL3_image-devel 3.4.8-1.fc43 Β· Zlib AND (HPND-Pbmplus AND Zlib) AND MIT AND (MIT OR Unlicense) AND LicenseRef-Fedora-Public-Domain
- fedora 44: SDL3_image-devel 3.4.8-1.fc44 Β· Zlib AND (HPND-Pbmplus AND Zlib) AND MIT AND (MIT OR Unlicense) AND LicenseRef-Fedora-Public-Domain
- fedora 44: SDL3_image-devel 3.4.8-1.fc44 Β· Zlib AND (HPND-Pbmplus AND Zlib) AND MIT AND (MIT OR Unlicense) AND LicenseRef-Fedora-Public-Domain
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms