#blend #formula #macro #gpu #formulae #blend-equation

macro blend-formula-proc-macro

macros for blend-formula crate

3 releases

0.1.2 Sep 11, 2023
0.1.1 Sep 11, 2023
0.1.0 Sep 11, 2023

#18 in #blend

50 downloads per month
Used in blend-formula

MIT license

30KB
933 lines

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.

Provides conversion traits for the corresponding wgpu types through the feature flag wgpu.

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),
});

No runtime deps