mgpuWriteDouble function

void mgpuWriteDouble(
  1. MGPUBuffer buffer,
  2. Float64List inputData,
  3. int size
)

Implementation

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

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

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