mgpuWriteInt32 function
Implementation
void mgpuWriteInt32(MGPUBuffer buffer, Int32List inputData, int size) {
final int elementsToWrite = size > 0 ? size : inputData.length;
final int byteSize = elementsToWrite * Int32List.bytesPerElement;
final JSNumber ptr = _malloc(byteSize.toJS);
final int startByteIndex = ptr.toDartInt;
try {
final int startElementIndex = startByteIndex ~/ Int32List.bytesPerElement;
final int actualElements = elementsToWrite <= inputData.length
? elementsToWrite
: inputData.length;
if (startElementIndex + actualElements > _heapI32.length) {
throw StateError('Int32 buffer allocation would exceed heap bounds');
}
_heapI32.setRange(
startElementIndex,
startElementIndex + actualElements,
inputData.sublist(0, actualElements),
);
_mgpuWriteInt32(buffer, ptr, byteSize.toJS);
} finally {
_free(ptr);
}
}