beginFrame method

  1. @override
void beginFrame()

Rewinds the three frame arenas, then hands over what the browser said since the last frame.

This is the member GraphicsDevice.beginFrame exists for, and the one backend of the four with something real to do in it. See webgpu_resources.dart for why rewinding under a frame the GPU has not finished with is safe, which is the only surprising thing about it.

Reports what the browser refused on errors, once, at the start of the frame after the call: a DeviceError carrying a ShaderCompileException for WGSL that did not compile, or a DeviceResourceException for any other refusal — the earliest a synchronous caller can hear an answer that arrives as a promise. Never thrown, since 1.0.0-rc.1, as the contract now says of every backend's beginFrame: a throw here failed the frame that happened to start next, for a call it never made. Nothing is reported once the device is lost; lost says that.

Implementation

@override
void beginFrame() {
  _frame++;
  _timer.endFrame(_timing ? _reportTimings : null);
  _uniformArena.reset();
  _vertexArena.reset();
  _indexArena.reset();
  final error = _ledger.takeFrame(deviceLost: _isLost);
  if (error != null && !_deviceErrors.isClosed) _deviceErrors.add(error);
}