aurora: Support BM_SUBTRACT, fix alpha blend op

This commit is contained in:
Luke Street 2022-03-19 21:40:48 -04:00
parent 9bcb06d92a
commit a42769627c
1 changed files with 21 additions and 5 deletions

View File

@ -283,15 +283,31 @@ static inline wgpu::CompareFunction to_compare_function(GX::Compare func) {
static inline wgpu::BlendState to_blend_state(GX::BlendMode mode, GX::BlendFactor srcFac, GX::BlendFactor dstFac,
std::optional<float> dstAlpha) {
if (mode != GX::BM_BLEND) {
Log.report(logvisor::Fatal, FMT_STRING("How to {}?"), mode);
}
const auto colorBlendComponent = wgpu::BlendComponent{
wgpu::BlendComponent colorBlendComponent;
switch (mode) {
case GX::BM_BLEND:
colorBlendComponent = {
.operation = wgpu::BlendOperation::Add,
.srcFactor = to_blend_factor(srcFac),
.dstFactor = to_blend_factor(dstFac),
};
auto alphaBlendComponent = colorBlendComponent;
break;
case GX::BM_SUBTRACT:
colorBlendComponent = {
.operation = wgpu::BlendOperation::Subtract,
.srcFactor = wgpu::BlendFactor::Src,
.dstFactor = wgpu::BlendFactor::Dst,
};
break;
default:
Log.report(logvisor::Fatal, FMT_STRING("How to {}?"), mode);
unreachable();
}
wgpu::BlendComponent alphaBlendComponent{
.operation = wgpu::BlendOperation::Add,
.srcFactor = wgpu::BlendFactor::Zero,
.dstFactor = wgpu::BlendFactor::One,
};
if (dstAlpha) {
alphaBlendComponent = wgpu::BlendComponent{
.operation = wgpu::BlendOperation::Add,