mgpuSetBufferData function

void mgpuSetBufferData(
  1. MGPUBuffer buffer,
  2. Float32List inputData,
  3. int size
)

Implementation

void mgpuSetBufferData(MGPUBuffer buffer, Float32List inputData, int size) {
  final byteSize = inputData.length * Float32List.bytesPerElement;
  final ptr = _malloc(byteSize.toJS);

  final startIndex = ptr.toDartInt ~/ 4;
  final endIndex = startIndex + inputData.length;

  try {
    // Copy inputData to HEAPF32 starting at the calculated index
    _heapF32.setRange(startIndex, endIndex, inputData);

    // Call the WASM function with the pointer
    _mgpuSetBufferData(buffer, ptr, byteSize.toJS);
  } finally {}
}