mgpuWriteInt8 function

void mgpuWriteInt8(
  1. MGPUBuffer buffer,
  2. Int8List inputData,
  3. int size
)

Implementation

void mgpuWriteInt8(MGPUBuffer buffer, Int8List inputData, int size) {
  final int elementsToWrite = size > 0 ? size : inputData.length;
  final int byteSize = elementsToWrite * Int8List.bytesPerElement;
  final JSNumber ptr = _malloc(byteSize.toJS);
  final int startIndex = ptr.toDartInt;
  try {
    final int actualElements = elementsToWrite <= inputData.length
        ? elementsToWrite
        : inputData.length;
    _heapU8.setRange(
      startIndex,
      startIndex + actualElements,
      inputData.sublist(0, actualElements),
    );
    _mgpuWriteInt8(buffer, ptr, byteSize.toJS);
  } finally {
    _free(ptr);
  }
}