IMG_LOADGPUTEXTURETYPED_IO(3)

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

πŸ’– 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 β€” the SDL_GPUDevice you're using to create the GPU texture.
  • copy_pass β€” the SDL_GPUCopyPass used to upload the loaded image onto the GPU texture.
  • src β€” an SDL_IOStream that the data gets read from.
  • closeio β€” true to close/free the SDL_IOStream before returning, false to 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 be NULL.
  • height β€” a pointer filled in with the width of the GPU texture. may be NULL. (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