mgpuWriteTexture2D function

int mgpuWriteTexture2D(
  1. MGPUTexture texture,
  2. Uint8List bytes,
  3. int mipLevel,
  4. int arrayLayer,
)

Implementation

int mgpuWriteTexture2D(
  MGPUTexture texture,
  Uint8List bytes,
  int mipLevel,
  int arrayLayer,
) {
  final pointer = _malloc(bytes.lengthInBytes.toJS);
  final start = pointer.toDartInt;
  try {
    if (start <= 0 || start + bytes.lengthInBytes > _heapU8.length) {
      throw StateError('Texture upload allocation failed');
    }
    HEAPU8.set(Uint8ListToJSUint8Array(bytes).toJS, start);
    return _mgpuWriteTexture2D(
      texture,
      pointer,
      bytes.lengthInBytes.toJS,
      mipLevel.toJS,
      arrayLayer.toJS,
    ).toDartInt;
  } finally {
    _free(pointer);
  }
}