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, orNULLto update the entire texture. yes,NULLmeans 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
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms