Expand description
Provides two macros, blend_formula! and
blend_equation!, used to evaluate an arbitrary formula
to its equivalent GPU blend mode. If none exist, it’s a compile-time error.
Valid formulae are equivalent to some Term*Factor Op Term*Factor, where:
- Each
Termis either “src” or “dst” (mutually exclusive). - Each
Factoris aBlendFactor. Opis aBlendOperation.
If a formula is for a color or alpha equation, non-scalar
terms must be “converted” using the appropriate accessor (.rgb or .a).
For convenience, any valid operator can be used to combine the source and
destination without a factor (+, -, <, >, *).
§Examples
use blend_formula::*;
// Formulae:
assert_eq!(blend_formula!(src*src.a + dst*(1 - src.a)), BlendFormula {
src_factor: BlendFactor::SrcAlpha,
dst_factor: BlendFactor::OneMinusSrcAlpha,
operation: BlendOperation::Add
});
assert_eq!(blend_formula!(-src), BlendFormula {
src_factor: BlendFactor::One,
dst_factor: BlendFactor::Zero,
operation: BlendOperation::RevSub
});
assert_eq!(blend_formula!(dst < src*c), BlendFormula {
src_factor: BlendFactor::Constant,
dst_factor: BlendFactor::One,
operation: BlendOperation::Min
});
// Equations:
assert_eq!(blend_equation!(src + dst*(1-src.a)),
BlendEquation::PREMULTIPLIED_ALPHA_BLENDING
);
assert_eq!(blend_equation!((dst+(src-dst)*src.a).rgb, (dst+src-dst*src).a),
BlendEquation::ALPHA_BLENDING
);
// Shortcuts:
assert_eq!(blend_formula!(+), blend_formula!(src+dst));
assert_eq!(blend_formula!(*), blend_formula!(src*dst));
assert_eq!(blend_equation!(-, dst.a), BlendEquation {
color: blend_formula!(src-dst),
alpha: blend_formula!(dst),
});§Conversion
If the feature wgpu is enabled, conversion traits are implemented for the
corresponding types of the wgpu crate.
blend_formula::BlendFactor->wgpu::BlendFactorblend_formula::BlendOperation->wgpu::BlendOperationblend_formula::BlendComponent->wgpu::BlendComponentblend_formula::BlendState->wgpu::BlendState
Macros§
- blend_
equation - Produces a
BlendEquationequivalent to some formulae, if one exists. - blend_
formula - Produces a
BlendFormulaequivalent to some formula, if one exists.
Structs§
- Blend
Equation - Corresponds to
wgpu::BlendState. - Blend
Formula - Corresponds to
wgpu::BlendComponent.
Enums§
- Blend
Factor - Corresponds to
wgpu::BlendFactor. - Blend
Operation - Corresponds to
wgpu::BlendOperation.