mgpuWriteTextureRegion2D function
Implementation
int mgpuWriteTextureRegion2D(
MGPUTexture texture,
Uint8List bytes,
int x,
int y,
int width,
int height,
int mipLevel,
int arrayLayer,
) {
if (x < 0 ||
x >= 32768 ||
y < 0 ||
y >= 32768 ||
width <= 0 ||
width > 32768 ||
height <= 0 ||
height > 32768 ||
mipLevel < 0 ||
mipLevel > 15 ||
arrayLayer < 0 ||
arrayLayer >= 32768 ||
bytes.isEmpty ||
bytes.lengthInBytes > 0x7fffffff) {
throw ArgumentError('Invalid texture region upload');
}
if (!hasTextureRegionUploadV1) {
throw UnsupportedError('Region uploads are unsupported by this module');
}
final pointer = _malloc(bytes.lengthInBytes.toJS);
final start = pointer.toDartInt;
try {
if (start <= 0 || start + bytes.lengthInBytes > _heapU8.length) {
throw StateError('Texture region upload allocation failed');
}
HEAPU8.set(Uint8ListToJSUint8Array(bytes).toJS, start);
return _mgpuWriteTextureRegion2D(
texture,
pointer,
bytes.lengthInBytes.toJS,
x.toJS,
y.toJS,
width.toJS,
height.toJS,
mipLevel.toJS,
arrayLayer.toJS,
).toDartInt;
} finally {
_free(pointer);
}
}