sdlUpdateTexture function

bool sdlUpdateTexture(
  1. Pointer<SdlTexture> texture,
  2. Pointer<SdlRect> rect,
  3. Pointer<NativeType> pixels,
  4. int pitch,
)

Update the given texture rectangle with new pixel data.

The pixel data must be in the pixel format of the texture, which can be queried using the SDL_PROP_TEXTURE_FORMAT_NUMBER property.

This is a fairly slow function, intended for use with static textures that do not change often.

If the texture is intended to be updated often, it is preferred to create the texture as streaming and use the locking functions referenced below. While this function will work with streaming textures, for optimization reasons you may not get the pixels back if you lock the texture afterward.

\param texture the texture to update. \param rect an SDL_Rect structure representing the area to update, or NULL to update the entire texture. \param pixels the raw pixel data in the format of the texture. \param pitch the number of bytes in a row of pixel data, including padding between lines. \returns true on success or false on failure; call SDL_GetError() for more information.

\threadsafety This function should only be called on the main thread.

\since This function is available since SDL 3.1.3.

\sa SDL_LockTexture \sa SDL_UnlockTexture \sa SDL_UpdateNVTexture \sa SDL_UpdateYUVTexture

extern SDL_DECLSPEC bool SDLCALL SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch)

Implementation

bool sdlUpdateTexture(Pointer<SdlTexture> texture, Pointer<SdlRect> rect,
    Pointer<NativeType> pixels, int pitch) {
  final sdlUpdateTextureLookupFunction = libSdl3.lookupFunction<
      Uint8 Function(Pointer<SdlTexture> texture, Pointer<SdlRect> rect,
          Pointer<NativeType> pixels, Int32 pitch),
      int Function(Pointer<SdlTexture> texture, Pointer<SdlRect> rect,
          Pointer<NativeType> pixels, int pitch)>('SDL_UpdateTexture');
  return sdlUpdateTextureLookupFunction(texture, rect, pixels, pitch) == 1;
}