Add color blend modes

This commit is contained in:
Connor Fitzgerald 2021-03-27 19:01:29 -04:00
parent b7ba481a91
commit 0616a08c65

View File

@ -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)]