mgpuLoadKernel function

void mgpuLoadKernel(
  1. MGPUComputeShader shader,
  2. String kernelString
)

Implementation

void mgpuLoadKernel(MGPUComputeShader shader, String kernelString) {
  final bytes = utf8.encode(kernelString);
  final kernelBytes =
      Uint8List(bytes.length + 1)
        ..setRange(0, bytes.length, bytes)
        ..[bytes.length] = 0; // null terminator

  // Allocate memory for the string.
  final allocSize = kernelBytes.length * kernelBytes.elementSizeInBytes;
  final ptr = _malloc(allocSize.toJS);
  try {
    _heapU8.setAll(ptr.toDartInt, kernelBytes);
    _mgpuLoadKernel(shader, ptr);
  } finally {
    _free(ptr);
  }
}