SDL_UpdateYUVTexture(3)

πŸ’– SDL_UpdateYUVTexture(3) πŸ’–

okay bestie, this one lives in the SDL3 functions lineup, and it's literally the glow-up you need when your pixel data is giving scattered instead of stacked. Let's get into it 🫢


✨ NAME ✨

SDL_UpdateYUVTexture β€” update a rectangle inside a planar YV12 or IYUV texture with brand new pixel data. no cap.


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_render.h>

bool SDL_UpdateYUVTexture(SDL_Texture *texture,
                     const SDL_Rect *rect,
                     const Uint8 *Yplane, int Ypitch,
                     const Uint8 *Uplane, int Upitch,
                     const Uint8 *Vplane, int Vpitch);

πŸ’… DESCRIPTION πŸ’…

so here's the tea β˜• β€” you can just use SDL_UpdateTexture() as long as your pixel data is one contiguous block of Y and U/V planes all sitting in the proper order. that's the chill scenario, the easy path, the main character who has their life together.

BUT. if your pixel data is not contiguous β€” like the planes are living in separate places, doing their own thing, not even texting each other β€” then this function is the one for you. it exists specifically for that situation. periodt. πŸ’–


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • texture β€” the texture you're updating, aka the thing getting the glow-up.
  • rect β€” a pointer to the rectangle of pixels you want to update, or NULL to update the entire texture. yes, NULL means all of it, go big or go home.
  • Yplane β€” the raw pixel data for the Y plane. the raw stuff. unfiltered. πŸ™ˆ
  • Ypitch β€” the number of bytes between rows of pixel data for the Y plane. that's the stride, the step, the how-far-apart-are-my-rows situation.
  • Uplane β€” the raw pixel data for the U plane.
  • Upitch β€” the number of bytes between rows of pixel data for the U plane.
  • Vplane β€” the raw pixel data for the V plane.
  • Vpitch β€” the number of bytes between rows of pixel data for the V plane.

⭐ RETURN VALUE ⭐

returns true on success or false on failure πŸ₯² and if it fails, hit up SDL_GetError() for more info. she will tell you what went wrong, she's very forthcoming.


πŸ¦‹ THREAD SAFETY πŸ¦‹

heads up bestie: this function should only be called on the main thread. do not try to be cute and call it from a worker thread. it's giving "main character energy" for a reason β€” main thread only. πŸ’€

🌈 AVAILABILITY 🌈

this function is available since SDL 3.2.0. so if you're on something older, no dice, sorry babes.


πŸ‘‘ SEE ALSO πŸ‘‘

go read those too, they're also iconic in their own way.


Simple Directmedia Layer Β· SDL 3.4.18 Β· SDL_UpdateYUVTexture(3)

and that's the whole page, bestie πŸŽ€πŸ’– stay planar, stay pitched, and may your rectangles always be within bounds βœ¨πŸ¦‹

πŸ“¦ where this page comes from