overwrite method
Overwrites a mip level (and slice for cubemap textures) of this
Texture with the contents of sourceBytes.
mipLevel selects which mip level to write to. Defaults to 0 (base
level). Must be in the range [0, mipLevelCount).
slice selects which slice to write to for cubemap textures, where
each face is a separate slice in the order
+X, -X, +Y, -Y, +Z, -Z. Must be 0 for non-cubemap textures.
The length of sourceBytes must exactly match the size returned by
getMipLevelSizeInBytes for the requested mipLevel. For
block-compressed formats, this is the number of whole-block-rounded
blocks times the bytes per block.
Throws an exception if the write fails due to an internal error or if any of the parameters are out of range.
Implementation
void overwrite(ByteData sourceBytes, {int mipLevel = 0, int slice = 0}) {
_validateMipLevelAndSlice(mipLevel, slice);
final int expectedSize = getMipLevelSizeInBytes(mipLevel);
if (sourceBytes.lengthInBytes != expectedSize) {
throw Exception(
'The length of sourceBytes (bytes: ${sourceBytes.lengthInBytes}) must exactly match the size of mip level $mipLevel (bytes: $expectedSize)',
);
}
bool success = _overwrite(_gpuContext, sourceBytes, mipLevel, slice);
if (!success) {
throw Exception("Texture overwrite failed");
}
}