mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:27:35 +00:00
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.
This commit is contained in:
parent
bdb2be8f9e
commit
681695a07a
2 changed files with 34 additions and 35 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue