IMG_LoadGPUTexture_IO(3)
π IMG_LoadGPUTexture_IO π
okay bestie, gather round, because this one is from the SDL_image3 functions crew and it's genuinely iconic. it's the move where you take an image sitting in an SDL data source and yeet it straight into a GPU texture. no disk drama, no nothing. π
β¨ SYNOPSIS β¨
#include <SDL3_image/SDL_image.h>
SDL_GPUTexture * IMG_LoadGPUTexture_IO(SDL_GPUDevice *device, SDL_GPUCopyPass *copy_pass, SDL_IOStream *src, bool closeio, int *width, int *height);
πΈ DESCRIPTION πΈ
so. an SDL_GPUTexture is basically an image that lives in GPU memory, and SDL's GPU API can actually use it. and no matter what format your source image was in β doesn't matter, doesn't care β this function will hand you back a GPU texture with the format SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM and no mip levels. periodt. π
that texture can then be bound as a sampled texture from a graphics or compute pipeline, and also as a readonly storage texture in a compute pipeline. versatile queen behavior, honestly. π
now, the closeio tea: if closeio is true, then src gets closed before the function returns, whether it succeeded or not. no hard feelings either way. and lowkey it doesn't even matter for correctness, because SDL_image reads everything it needs from src during this call in any case. π«Ά
there's a separate function for reading files straight off disk without having to deal with SDL_IOStream at all:
IMG_LoadGPUTexture(device, copy_pass, "filename.jpg", width, height)
that one will call this function and manage all those little details for you, figuring out the file type from the filename's extension. so cute of it.
there's also IMG_LoadGPUTextureTyped_IO(), which is literally the same thing as this function except you can specify a file extension (like "BMP", "JPG", etc), which is your save when SDL_image can't autodetect the file format. not me needing the backup plan π
and when you're done with the texture that comes back? the app should dispose of it with a call to SDL_ReleaseGPUTexture(). don't just leave it there, that's not main character energy, that's littering. ποΈβ¨
π¦ FUNCTION PARAMETERS π¦
deviceβ theSDL_GPUDeviceyou're using to create the GPU texture.copy_passβ theSDL_GPUCopyPassused to upload the loaded image into the GPU texture.srcβ anSDL_IOStreamthat the data will be read from.closeioβtrueto close/free theSDL_IOStreambefore returning,falseto leave it open.widthβ a pointer that gets filled in with the width of the GPU texture. may beNULL.heightβ a pointer that gets filled in with the width of the GPU texture. may beNULL. (yes, the manpage fr fr says width again, i'm just the messenger π)
π« RETURN VALUE π«
returns a new GPU texture. or NULL on error. that's the whole vibe check. π
π AVAILABILITY π
this function has been available since SDL_image 3.4.0. she's not new new, but she's established.
β SEE ALSO β
and that's the page bestie!! this whole thing comes to you courtesy of SDL_image, version SDL_image 3.4.8 β go load some textures, release them when you're done, and slay πππ¦β¨
π¦ 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