From 0616a08c658b8b5fdcba1128c51ea1b2cd6a2aa2 Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Sat, 27 Mar 2021 19:01:29 -0400 Subject: [PATCH] Add color blend modes --- wgpu-types/src/lib.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index e5fb6c280..cb167be69 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -764,6 +764,13 @@ impl BlendComponent { operation: BlendOperation::Add, }; + /// Blend state of (1 * src) + ((1 - src_alpha) * dst) + pub const OVER: Self = BlendComponent { + src_factor: BlendFactor::One, + dst_factor: BlendFactor::OneMinusSrcAlpha, + operation: BlendOperation::Add, + }; + /// Returns true if the state relies on the constant color, which is /// set independently on a render command encoder. pub fn uses_color(&self) -> bool { @@ -797,6 +804,30 @@ pub struct BlendState { pub alpha: BlendComponent, } +impl BlendState { + /// Blend mode that does no color blending, just overwrites the output with the contents of the shader. + pub const REPLACE: Self = Self { + color: BlendComponent::REPLACE, + alpha: BlendComponent::REPLACE, + }; + + /// Blend mode that does standard alpha blending with non-premultiplied alpha. + pub const ALPHA_BLENDING: Self = Self { + color: BlendComponent { + src_factor: BlendFactor::SrcAlpha, + dst_factor: BlendFactor::OneMinusSrcAlpha, + operation: BlendOperation::Add, + }, + alpha: BlendComponent::OVER, + }; + + /// Blend mode that does standard alpha blending with premultiplied alpha. + pub const PREMULTIPLIED_ALPHA_BLENDING: Self = Self { + color: BlendComponent::OVER, + alpha: BlendComponent::OVER, + }; +} + /// Describes the color state of a render pipeline. #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]