setBlend method

  1. @override
void setBlend(
  1. BlendState? state, {
  2. int attachment = 0,
})

Blending for one colour attachment; null switches it off.

attachment is honoured, which no other backend here does. Impeller passes it to flutter_gpu, WebGL2 would need EXT_draw_buffers_indexed and the software rasteriser keeps one state for the pass — so both of those write attachment zero whatever index they are handed. WebGPU gives every target its own equation in the pipeline, so the index reaches the hardware and two attachments can genuinely blend differently.

An index outside the pass's attachments is a caller mistake rather than a hint, and is refused: the other backends' silent substitution is what makes it worth stopping for here.

Implementation

@override
void setBlend(BlendState? state, {int attachment = 0}) {
  if (attachment < 0 || attachment >= _blends.length) {
    throw ArgumentError.value(
      attachment,
      'attachment',
      'is not one of this pass\'s ${_blends.length} colour attachments',
    );
  }
  if (state != null && state.usesBlendColor) {
    throw UnsupportedError(
      'this backend answers false to supportsBlendColor, and the state names '
      'one of the four factors that read the constant',
    );
  }
  _blends[attachment] = state;
}