summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibSoftGPU
diff options
context:
space:
mode:
authorStephan Unverwerth <s.unverwerth@serenityos.org>2022-01-06 21:28:16 +0100
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-01-09 16:21:13 +0330
commit941e9d9922d8e613d83e5dfd75ebc4009bd65dfa (patch)
treeb0de8aaffa5c85bee00e4e567df8aa819716287f /Userland/Libraries/LibSoftGPU
parent68a1727547c1bfeb87b6ef5e4fb796ae7782d213 (diff)
downloadserenity-941e9d9922d8e613d83e5dfd75ebc4009bd65dfa.zip
LibSoftGPU: Move alpha test into separate function
Diffstat (limited to 'Userland/Libraries/LibSoftGPU')
-rw-r--r--Userland/Libraries/LibSoftGPU/Device.cpp60
-rw-r--r--Userland/Libraries/LibSoftGPU/Device.h1
2 files changed, 37 insertions, 24 deletions
diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp
index 22572d88a1..c5f601b1df 100644
--- a/Userland/Libraries/LibSoftGPU/Device.cpp
+++ b/Userland/Libraries/LibSoftGPU/Device.cpp
@@ -29,6 +29,7 @@ static long long g_num_quads;
using IntVector2 = Gfx::Vector2<int>;
using IntVector3 = Gfx::Vector3<int>;
+using AK::SIMD::any;
using AK::SIMD::exp;
using AK::SIMD::expand4;
using AK::SIMD::f32x4;
@@ -401,30 +402,8 @@ void Device::rasterize_triangle(const Triangle& triangle)
shade_fragments(quad);
- if (m_options.enable_alpha_test && m_options.alpha_test_func != AlphaTestFunction::Always) {
- switch (m_options.alpha_test_func) {
- case AlphaTestFunction::Less:
- quad.mask &= quad.out_color.w() < m_options.alpha_test_ref_value;
- break;
- case AlphaTestFunction::Equal:
- quad.mask &= quad.out_color.w() == m_options.alpha_test_ref_value;
- break;
- case AlphaTestFunction::LessOrEqual:
- quad.mask &= quad.out_color.w() <= m_options.alpha_test_ref_value;
- break;
- case AlphaTestFunction::Greater:
- quad.mask &= quad.out_color.w() > m_options.alpha_test_ref_value;
- break;
- case AlphaTestFunction::NotEqual:
- quad.mask &= quad.out_color.w() != m_options.alpha_test_ref_value;
- break;
- case AlphaTestFunction::GreaterOrEqual:
- quad.mask &= quad.out_color.w() >= m_options.alpha_test_ref_value;
- break;
- case AlphaTestFunction::Never:
- case AlphaTestFunction::Always:
- VERIFY_NOT_REACHED();
- }
+ if (m_options.enable_alpha_test && m_options.alpha_test_func != AlphaTestFunction::Always && !test_alpha(quad)) {
+ continue;
}
// Write to depth buffer
@@ -817,6 +796,39 @@ ALWAYS_INLINE void Device::shade_fragments(PixelQuad& quad)
}
}
+ALWAYS_INLINE bool 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 AlphaTestFunction::Less:
+ quad.mask &= alpha < ref_value;
+ break;
+ case AlphaTestFunction::Equal:
+ quad.mask &= alpha == ref_value;
+ break;
+ case AlphaTestFunction::LessOrEqual:
+ quad.mask &= alpha <= ref_value;
+ break;
+ case AlphaTestFunction::Greater:
+ quad.mask &= alpha > ref_value;
+ break;
+ case AlphaTestFunction::NotEqual:
+ quad.mask &= alpha != ref_value;
+ break;
+ case AlphaTestFunction::GreaterOrEqual:
+ quad.mask &= alpha >= ref_value;
+ break;
+ case AlphaTestFunction::Never:
+ case AlphaTestFunction::Always:
+ default:
+ VERIFY_NOT_REACHED();
+ }
+
+ return any(quad.mask);
+}
+
void Device::resize(const Gfx::IntSize& min_size)
{
wait_for_all_threads();
diff --git a/Userland/Libraries/LibSoftGPU/Device.h b/Userland/Libraries/LibSoftGPU/Device.h
index 63621689a0..dbd32b3967 100644
--- a/Userland/Libraries/LibSoftGPU/Device.h
+++ b/Userland/Libraries/LibSoftGPU/Device.h
@@ -98,6 +98,7 @@ private:
void rasterize_triangle(const Triangle& triangle);
void setup_blend_factors();
void shade_fragments(PixelQuad&);
+ bool test_alpha(PixelQuad&);
private:
RefPtr<Gfx::Bitmap> m_render_target;