SDL_UpdateNVTexture(3)

πŸ’– SDL_UpdateNVTexture β€” the glow-up your NV12/NV21 texture deserves πŸ’–

okay bestie, so this one lives in the SDL3 FUNCTIONS section of the manual, and it's literally the "my pixel planes are NOT cuddling in one contiguous block" edition of texture updating. slay.


✨ NAME ✨

SDL_UpdateNVTexture β€” update a rectangle within a planar NV12 or NV21 texture with new pixels. no cap, that's the whole gig πŸŽ€


✨ SYNOPSIS ✨

#include <SDL3/SDL_render.h>

bool SDL_UpdateNVTexture(SDL_Texture *texture,
                     const SDL_Rect *rect,
                     const Uint8 *Yplane, int Ypitch,
                     const Uint8 *UVplane, int UVpitch);

✨ DESCRIPTION ✨

so here's the tea πŸ«– β€” you can just use SDL_UpdateTexture() as long as your pixel data is one contiguous block of NV12/21 planes sitting in the proper order. that's the easy route.

but if your pixel data is not contiguous? if your planes are living separate lives, doing their own thing, not sharing a memory block? that's when this function shows up like the main character. it's here for exactly that situation. periodt. πŸ’…


✨ FUNCTION PARAMETERS ✨

  • texture β€” the texture you're updating. your canvas, your moment, your icon πŸ‘‘
  • rect β€” a pointer to the rectangle of pixels you wanna update. or pass NULL to update the entire texture, go big or go home 🌈
  • Yplane β€” the raw pixel data for the Y plane. the real ones. πŸ¦‹
  • Ypitch β€” the number of bytes between rows of pixel data for the Y plane. how far apart the rows are emotionally (and in memory) πŸ’€
  • UVplane β€” the raw pixel data for the UV plane. the supporting cast that's actually essential 🌸
  • UVpitch β€” the number of bytes between rows of pixel data for the UV plane. same deal, different plane ✨

✨ RETURN VALUE ✨

returns true on success or false on failure πŸ₯² and if it fails, call SDL_GetError() for more info β€” she will tell you what went wrong, she's not shy.


✨ THREAD SAFETY ✨

🚨 bestie listen. this function should only be called on the main thread. no side quests, no background threads, no "but it worked that one time." main thread only. that's the vibe check and you passed it by reading this. βœ…

✨ AVAILABILITY ✨

this function is available since SDL 3.2.0. if you're on something older, it's giving... not available. πŸ™ˆ


✨ SEE ALSO ✨

go read those too, they're the sister functions and they ate πŸ’…βœ¨


and that's the whole page, bestie!! brought to you by Simple Directmedia Layer, version SDL 3.4.18 🫢 go forth and update those NV12/NV21 planes, you absolute legend πŸŽ€πŸ’–β­

πŸ“¦ where this page comes from