mgpuWriteUint32 function

void mgpuWriteUint32(
  1. MGPUBuffer buffer,
  2. Uint32List inputData,
  3. int size
)

Implementation

void mgpuWriteUint32(MGPUBuffer buffer, Uint32List inputData, int size) {
  final int elementsToWrite = size > 0 ? size : inputData.length;
  final int byteSize = elementsToWrite * Uint32List.bytesPerElement;
  final JSNumber ptr = _malloc(byteSize.toJS);
  final int startByteIndex = ptr.toDartInt;
  try {
    final int startElementIndex = startByteIndex ~/ Uint32List.bytesPerElement;
    final int actualElements = elementsToWrite <= inputData.length
        ? elementsToWrite
        : inputData.length;

    if (startElementIndex + actualElements > _heapU32.length) {
      throw StateError('Uint32 buffer allocation would exceed heap bounds');
    }

    _heapU32.setRange(
      startElementIndex,
      startElementIndex + actualElements,
      inputData.sublist(0, actualElements),
    );
    _mgpuWriteUint32(buffer, ptr, byteSize.toJS);
  } finally {
    _free(ptr);
  }
}