updateTextureData method

void updateTextureData(
  1. Uint8List data
)

Updates the texture's pixel data on the GPU with the provided data.

  • data: The new Uint8List of pixel data (RGBA format).

This method should only be called when isLoading is false. If TextureFlags.mipmap is set, mipmaps are regenerated.

Implementation

void updateTextureData(Uint8List data) {
  if (isLoading) {
    error('Cannot update texture data while the texture is still loading.');
    return;
  }

  final expectedLength = width * height * 4;
  if (data.length != expectedLength) {
    die(
      'Provided data length (${data.length}) does not match expected length ($expectedLength) for texture dimensions ${width}x$height.',
    );
  }

  if (handle != null) {
    _renderer.updateTexture(handle!, 0, 0, width, height, data, flags);
  }

  pixelData = Uint8List.fromList(data);
}