WebGpuEncoder constructor

WebGpuEncoder(
  1. WebGpuDevice _device,
  2. RenderPassDescriptor descriptor
)

Implementation

WebGpuEncoder(this._device, RenderPassDescriptor descriptor)
  : _colorFormats = <String>[
      for (final target in descriptor.colors)
        gpuTextureFormat(target.texture.format)!,
    ],
    _blends = <BlendState?>[for (final _ in descriptor.colors) null],
    _depthFormat = descriptor.depth == null
        ? null
        : gpuTextureFormat(descriptor.depth!.texture.format),
    _sampleCount = descriptor.colors.isNotEmpty
        ? descriptor.colors.first.texture.sampleCount
        : (descriptor.depth?.texture.sampleCount ?? 1) {
  final colors = <GPURenderPassColorAttachment>[
    for (final target in descriptor.colors) _colorAttachment(target),
  ];
  final depth = descriptor.depth;
  _encoder = _device.gpuDevice.createCommandEncoder();
  _pass = _encoder.beginRenderPass(
    depth == null
        ? GPURenderPassDescriptor(
            colorAttachments: colors.toJS,
            label: 'flutter3d pass',
          )
        : GPURenderPassDescriptor.withDepth(
            colorAttachments: colors.toJS,
            depthStencilAttachment: _depthAttachment(depth),
            label: 'flutter3d pass',
          ),
  );
}