copyBufferToTexture method
- BufferView source,
- TextureRegion destination
Copies tightly packed texel data from source into destination.
Prefer this over Texture.overwrite when uploading more than one texture region. Multiple contiguous copy commands recorded on the same CommandBuffer are batched by Flutter GPU into a single backend blit pass where the backend has such a concept.
Implementation
void copyBufferToTexture(BufferView source, TextureRegion destination) {
destination._validate();
if (source.offsetInBytes < 0 ||
source.lengthInBytes < 0 ||
source.offsetInBytes + source.lengthInBytes >
source.buffer.sizeInBytes) {
throw Exception('BufferView range is out of bounds');
}
final int expectedSize = destination._sizeInBytes();
if (source.lengthInBytes != expectedSize) {
throw Exception(
'The source BufferView length (bytes: ${source.lengthInBytes}) must '
'match the destination texture region size (bytes: $expectedSize)',
);
}
final String? error = _copyBufferToTexture(
source.buffer,
source.offsetInBytes,
source.lengthInBytes,
destination.texture,
destination.x,
destination.y,
destination._resolvedWidth(),
destination._resolvedHeight(),
destination.mipLevel,
destination.slice,
);
if (error != null) {
throw Exception(error);
}
}