updateTextureData method
- Uint8List data
Updates the texture's pixel data on the GPU with the provided data
.
data
: The newUint8List
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.',
);
}
_gl.bindTexture(GL.TEXTURE_2D, texture);
_gl.texSubImage2D(GL.TEXTURE_2D, 0, 0, 0, width.toJS, height.toJS, GL.RGBA.toJS, GL.UNSIGNED_BYTE, data.toJS);
if (flags.has(TextureFlags.mipmap)) {
_gl.generateMipmap(GL.TEXTURE_2D);
}
pixelData = Uint8List.fromList(data);
}