wrapStorageBuffer function

StorageBuffer wrapStorageBuffer({
  1. required Object backend,
  2. required int lengthInBytes,
  3. bool? hostReadable,
  4. GeometryBuffer? asIndices,
  5. GeometryBuffer? asVertices,
  6. BufferUsage? usage,
  7. GraphicsDevice? owner,
})

A StorageBuffer over a backend's own backend buffer — for a backend, from package:flutter3d_hardware/backend.dart. owner's releaseStorageBuffer is what the handle's dispose calls.

Say what it is for with usage. hostReadable is the pre-1.0 way to say one bit of it, still read when usage is absent: the buffer is then BufferUsage.standardStorage, with BufferUsage.hostReadable when it is true. When both are given they must agree, or this throws an ArgumentError rather than make a handle whose two fields disagree.

Implementation

StorageBuffer wrapStorageBuffer({
  required Object backend,
  required int lengthInBytes,
  bool? hostReadable,
  GeometryBuffer? asIndices,
  GeometryBuffer? asVertices,
  BufferUsage? usage,
  GraphicsDevice? owner,
}) {
  if (hostReadable != null &&
      usage != null &&
      hostReadable != usage.contains(BufferUsage.hostReadable)) {
    throw ArgumentError(
      'wrapStorageBuffer was told hostReadable: $hostReadable and $usage, '
          'which disagree. Say it with usage alone.',
      'hostReadable',
    );
  }
  return StorageBuffer._(
    owner?.releaseStorageBuffer,
    backend: backend,
    lengthInBytes: lengthInBytes,
    usage:
        usage ??
        (hostReadable ?? false
            ? BufferUsage.standardStorage | BufferUsage.hostReadable
            : BufferUsage.standardStorage),
    asIndices: asIndices,
    asVertices: asVertices,
  );
}