IMG_LOADGPUTEXTURETYPED_IO(3)
π NAME π
IMG_LoadGPUTextureTyped_IO β bestie, this is the one that loads an image straight from an SDL data source and yeets it into a GPU texture. No disk, no drama. β¨
π«Ά SYNOPSIS π«Ά
#include <SDL3_image/SDL_image.h>
SDL_GPUTexture * IMG_LoadGPUTextureTyped_IO(SDL_GPUDevice *device, SDL_GPUCopyPass *copy_pass, SDL_IOStream *src, bool closeio, const char *type, int *width, int *height);
πΈ DESCRIPTION πΈ
Okay so an SDL_GPUTexture is literally an image living in GPU memory, and SDL's GPU API can use it. Doesn't matter what format the source image was in β this function always hands you back a GPU texture with the format SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM and no mip levels. Periodt. π
Once you've got it, you can bind it as a sampled texture from a graphics or compute pipeline, and also as a readonly storage texture in a compute pipeline. Versatile queen. π
If closeio is true, src gets closed before this function returns β whether it succeeds or not, no exceptions, it's giving closure fr fr. Either way, SDL_image reads everything it needs out of src during this call. So don't worry about it afterwards.
Now, even though this function accepts a file type, SDL_image may still try other decoders that can detect the file type from the contents of the image data itself. But for formats it can't autodetect, it may have to rely on the caller-provided type string. And if type is NULL? Then SDL_image is on its own β relying solely on its ability to guess the format. Vibe check: risky, but iconic. π
There's a separate function for reading files off disk without dealing with SDL_IOStream at all:
IMG_LoadGPUTexture(device, copy_pass, "filename.jpg", width, height)
That one calls this function and manages all those details for you, figuring out the file type from the filename's extension. Convenient much? π
There's also IMG_LoadGPUTexture_IO(), which is equivalent to this function except it lets SDL_image determine what type of data it's loading β basically the same energy as passing NULL for type.
When you're done with the returned texture, the app should dispose of it by calling SDL_ReleaseGPUTexture(). Clean up after yourself, bestie, no leaving mess. π§
β¨ FUNCTION PARAMETERS β¨
deviceβ theSDL_GPUDeviceyou're using to create the GPU texture.copy_passβ theSDL_GPUCopyPassused to upload the loaded image onto the GPU texture.srcβ anSDL_IOStreamthat the data gets read from.closeioβtrueto close/free theSDL_IOStreambefore returning,falseto leave it open.typeβ a filename extension that represents this data ("BMP","GIF","PNG", etc).widthβ a pointer filled in with the width of the GPU texture. may beNULL.heightβ a pointer filled in with the width of the GPU texture. may beNULL. (yes bestie, it says width again on the height one π the page said what it said, I'm just the messenger)
π₯ RETURN VALUE π₯
Returns a new GPU texture, or NULL on error. That's it, that's the whole deal. π
β AVAILABILITY β
This function is available since SDL_image 3.4.0. Baby's not that old, but she's thriving. π
π¦ SEE ALSO π¦
And that's the whole page, bestie! This came to you from the SDL_image crew β SDL_image 3.4.8 β and it's the IMG_LoadGPUTextureTyped_IO(3) entry. Go forth and texture responsibly ππ
π¦ 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