diff options
author | Jelle Raaijmakers <jelle@gmta.nl> | 2022-10-09 03:00:22 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-10-19 22:22:58 +0200 |
commit | 681695a07a397c9713c40ccf53dde515a2a4df70 (patch) | |
tree | b1e2628558b09c953692b49c92cc832df0e95138 /Userland/Libraries/LibSoftGPU | |
parent | bdb2be8f9e003b4637d339546b1b043e85a7f03c (diff) | |
download | serenity-681695a07a397c9713c40ccf53dde515a2a4df70.zip |
LibSoftGPU: Make alpha testing a static function
There is no need to access the Device's members for alpha testing; pass
in the required alpha function and reference value.
Diffstat (limited to 'Userland/Libraries/LibSoftGPU')
-rw-r--r-- | Userland/Libraries/LibSoftGPU/Device.cpp | 68 | ||||
-rw-r--r-- | Userland/Libraries/LibSoftGPU/Device.h | 1 |
2 files changed, 34 insertions, 35 deletions
diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp index 441c1a85ec..1208369599 100644 --- a/Userland/Libraries/LibSoftGPU/Device.cpp +++ b/Userland/Libraries/LibSoftGPU/Device.cpp @@ -183,12 +183,45 @@ void Device::setup_blend_factors() } } +ALWAYS_INLINE static void test_alpha(PixelQuad& quad, GPU::AlphaTestFunction alpha_test_function, f32x4 const& reference_value) +{ + auto const alpha = quad.out_color.w(); + + switch (alpha_test_function) { + case GPU::AlphaTestFunction::Always: + quad.mask &= expand4(~0); + break; + case GPU::AlphaTestFunction::Equal: + quad.mask &= alpha == reference_value; + break; + case GPU::AlphaTestFunction::Greater: + quad.mask &= alpha > reference_value; + break; + case GPU::AlphaTestFunction::GreaterOrEqual: + quad.mask &= alpha >= reference_value; + break; + case GPU::AlphaTestFunction::Less: + quad.mask &= alpha < reference_value; + break; + case GPU::AlphaTestFunction::LessOrEqual: + quad.mask &= alpha <= reference_value; + break; + case GPU::AlphaTestFunction::NotEqual: + quad.mask &= alpha != reference_value; + break; + case GPU::AlphaTestFunction::Never: + default: + VERIFY_NOT_REACHED(); + } +} + template<typename CB1, typename CB2, typename CB3> ALWAYS_INLINE void Device::rasterize(Gfx::IntRect& render_bounds, CB1 set_coverage_mask, CB2 set_quad_depth, CB3 set_quad_attributes) { // Return if alpha testing is a no-op if (m_options.enable_alpha_test && m_options.alpha_test_func == GPU::AlphaTestFunction::Never) return; + auto const alpha_test_ref_value = expand4(m_options.alpha_test_ref_value); // Buffers auto color_buffer = m_frame_buffer->color_buffer(); @@ -435,7 +468,7 @@ ALWAYS_INLINE void Device::rasterize(Gfx::IntRect& render_bounds, CB1 set_covera // Alpha testing if (m_options.enable_alpha_test) { - test_alpha(quad); + test_alpha(quad, m_options.alpha_test_func, alpha_test_ref_value); coverage_bits = maskbits(quad.mask); if (coverage_bits == 0) continue; @@ -1327,39 +1360,6 @@ ALWAYS_INLINE void Device::shade_fragments(PixelQuad& quad) quad.out_color.set_w(quad.out_color.w() * quad.coverage); } -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::Always: - quad.mask &= expand4(~0); - break; - case GPU::AlphaTestFunction::Equal: - quad.mask &= alpha == ref_value; - break; - case GPU::AlphaTestFunction::Greater: - 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: - default: - VERIFY_NOT_REACHED(); - } -} - void Device::resize(Gfx::IntSize const& size) { auto frame_buffer_or_error = FrameBuffer<GPU::ColorType, GPU::DepthType, GPU::StencilType>::try_create(size); diff --git a/Userland/Libraries/LibSoftGPU/Device.h b/Userland/Libraries/LibSoftGPU/Device.h index 5641d9b9c0..31e3dc22ee 100644 --- a/Userland/Libraries/LibSoftGPU/Device.h +++ b/Userland/Libraries/LibSoftGPU/Device.h @@ -99,7 +99,6 @@ private: void rasterize_triangle(Triangle&); void setup_blend_factors(); void shade_fragments(PixelQuad&); - void test_alpha(PixelQuad&); RefPtr<FrameBuffer<GPU::ColorType, GPU::DepthType, GPU::StencilType>> m_frame_buffer {}; GPU::RasterizerOptions m_options; |