3个版本
| 0.1.2 | 2023年9月11日 | 
|---|---|
| 0.1.1 | 2023年9月11日 | 
| 0.1.0 | 2023年9月11日 | 
#1498 in 数学
16KB
234 行
提供两个宏,blend_formula! 和 blend_equation!,用于将任意公式评估为其等效的GPU混合模式。如果不存在,则为编译时错误。
通过功能标志 wgpu 提供相应的 wgpu 类型的转换特征。
示例
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),
});
依赖项
~0–31MB
~456K SLoC