summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibSoftGPU/Device.cpp
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2022-05-15 00:02:30 +0200
committerAndreas Kling <kling@serenityos.org>2022-05-15 12:15:12 +0200
commit421a80bf43d7145dae137a22ce4e6317f0ba98a0 (patch)
treeaa3b600a41cdb42b28abd9ef81dda14c06d687aa /Userland/Libraries/LibSoftGPU/Device.cpp
parent1a338844faad968d58036ba8f7143126293b19b4 (diff)
downloadserenity-421a80bf43d7145dae137a22ce4e6317f0ba98a0.zip
LibSoftGPU: Update coverage bits after alpha testing
Also skip the test for the `::Always` alpha test function in the hot loop. This test function is very unlikely to be set, so leave that up to `::test_alpha()`.
Diffstat (limited to 'Userland/Libraries/LibSoftGPU/Device.cpp')
-rw-r--r--Userland/Libraries/LibSoftGPU/Device.cpp33
1 files changed, 19 insertions, 14 deletions
diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp
index 6d90f2df18..14279127f5 100644
--- a/Userland/Libraries/LibSoftGPU/Device.cpp
+++ b/Userland/Libraries/LibSoftGPU/Device.cpp
@@ -431,8 +431,13 @@ ALWAYS_INLINE void Device::rasterize(Gfx::IntRect& render_bounds, CB1 set_covera
set_quad_attributes(quad);
shade_fragments(quad);
- if (m_options.enable_alpha_test && m_options.alpha_test_func != GPU::AlphaTestFunction::Always && !test_alpha(quad))
- continue;
+ // Alpha testing
+ if (m_options.enable_alpha_test) {
+ test_alpha(quad);
+ coverage_bits = maskbits(quad.mask);
+ if (coverage_bits == 0)
+ continue;
+ }
// Write to depth buffer
if (m_options.enable_depth_test && m_options.enable_depth_write)
@@ -1269,37 +1274,37 @@ ALWAYS_INLINE void Device::shade_fragments(PixelQuad& quad)
quad.out_color.set_w(quad.out_color.w() * quad.coverage);
}
-ALWAYS_INLINE bool Device::test_alpha(PixelQuad& quad)
+ALWAYS_INLINE void Device::test_alpha(PixelQuad& quad)
{
auto const alpha = quad.out_color.w();
auto const ref_value = expand4(m_options.alpha_test_ref_value);
switch (m_options.alpha_test_func) {
- case GPU::AlphaTestFunction::Less:
- quad.mask &= alpha < ref_value;
+ case GPU::AlphaTestFunction::Always:
+ quad.mask &= expand4(~0);
break;
case GPU::AlphaTestFunction::Equal:
quad.mask &= alpha == ref_value;
break;
- case GPU::AlphaTestFunction::LessOrEqual:
- quad.mask &= alpha <= ref_value;
- break;
case GPU::AlphaTestFunction::Greater:
quad.mask &= alpha > ref_value;
break;
- case GPU::AlphaTestFunction::NotEqual:
- quad.mask &= alpha != ref_value;
- break;
case GPU::AlphaTestFunction::GreaterOrEqual:
quad.mask &= alpha >= ref_value;
break;
+ case GPU::AlphaTestFunction::Less:
+ quad.mask &= alpha < ref_value;
+ break;
+ case GPU::AlphaTestFunction::LessOrEqual:
+ quad.mask &= alpha <= ref_value;
+ break;
+ case GPU::AlphaTestFunction::NotEqual:
+ quad.mask &= alpha != ref_value;
+ break;
case GPU::AlphaTestFunction::Never:
- case GPU::AlphaTestFunction::Always:
default:
VERIFY_NOT_REACHED();
}
-
- return any(quad.mask);
}
void Device::resize(Gfx::IntSize const& size)