getNextSwapchainColorTexture method

Texture getNextSwapchainColorTexture(
  1. Size size
)

Returns the next 8-bit color texture in the rotating swapchain ring, allocating one when the ring isn't yet full. The ring (and the transient texture pool) are dropped and rebuilt whenever size changes from the previous call.

Implementation

gpu.Texture getNextSwapchainColorTexture(Size size) {
  transientTexturePool.beginFrame();
  if (size != _previousSize) {
    _cursor = 0;
    _swapchainColors.clear();
    transientTexturePool.clear();
    _previousSize = size;
  }
  if (_cursor == _swapchainColors.length) {
    _swapchainColors.add(
      gpu.gpuContext.createTexture(
        gpu.StorageMode.devicePrivate,
        size.width.toInt(),
        size.height.toInt(),
        enableRenderTargetUsage: true,
        enableShaderReadUsage: true,
        coordinateSystem: gpu.TextureCoordinateSystem.renderToTexture,
      ),
    );
  }
  final result = _swapchainColors[_cursor];
  _cursor = (_cursor + 1) % _maxFramesInFlight;
  return result;
}