overwriteGeometry method

  1. @override
void overwriteGeometry(
  1. GeometryBuffer target,
  2. int offsetInBytes,
  3. ByteData bytes
)
override

Writes bytes into target starting offsetInBytes into it, in place.

Visible starting the next pass, never the one already encoded. None of the four backends here promise anything about a draw already recorded against the old bytes — WebGL2's bufferSubData, WebGPU's queue.writeBuffer and flutter_gpu's DeviceBuffer.overwrite are all queued relative to submission, not to the moment this call returns, so a pass encoded and submitted before this call still draws what it was given. A caller that needs the new bytes in the frame being built has to call this before recording the draw, not after.

offsetInBytes and bytes.lengthInBytes must together fit inside targetoffsetInBytes + bytes.lengthInBytes <= target.lengthInBytes — checked here rather than left to a backend, because a backend that caught it would report three different exceptions for one mistake.

target must be a buffer this device itself returned from uploadGeometry, not a slice of unrelated bytes — the same requirement releaseGeometry already carries.

Implementation

@override
void overwriteGeometry(
  GeometryBuffer target,
  int offsetInBytes,
  ByteData bytes,
) {
  if (offsetInBytes < 0 ||
      offsetInBytes + bytes.lengthInBytes > target.lengthInBytes) {
    throw ArgumentError(
      'overwriteGeometry: $offsetInBytes + ${bytes.lengthInBytes} does not '
      'fit inside a ${target.lengthInBytes}-byte buffer',
    );
  }
  overwrites.add((
    backend: target.backend,
    offsetInBytes: target.offsetInBytes + offsetInBytes,
    lengthInBytes: bytes.lengthInBytes,
  ));
}