LibSoftGPU: Move alpha test into separate function

This commit is contained in:
Stephan Unverwerth 2022-01-06 21:28:16 +01:00 committed by Ali Mohammad Pur
parent 68a1727547
commit 941e9d9922
Notes: sideshowbarker 2024-07-17 21:19:14 +09:00
2 changed files with 37 additions and 24 deletions

View file

@ -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();

View file

@ -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;