From 8165346ae4ab1fbc05a5fc3d2f05427dce7f8c90 Mon Sep 17 00:00:00 2001 From: Stephan Unverwerth Date: Mon, 7 Mar 2022 22:36:43 +0100 Subject: [PATCH] LibSoftGPU: Choose correct texture filter based on scale factor Previously the test determining whether to use texture maginifaction or texture minification was reversed. This commit fixes the test and also provides an early out of the sampler in case of texture magnification since magnification does not make use of mipmaps. --- Userland/Libraries/LibSoftGPU/Sampler.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibSoftGPU/Sampler.cpp b/Userland/Libraries/LibSoftGPU/Sampler.cpp index 58b7fa6605..baefdac247 100644 --- a/Userland/Libraries/LibSoftGPU/Sampler.cpp +++ b/Userland/Libraries/LibSoftGPU/Sampler.cpp @@ -127,22 +127,25 @@ Vector4 Sampler::sample_2d(Vector2 const& uv) // FIXME: Here we simply determine the filter based on the single scale factor of the upper left pixel. // Actually, we could end up with different scale factors for each pixel. This however would break our // parallelisation as we could also end up with different filter modes per pixel. - auto filter = scale_factor[0] > 1 ? m_config.texture_mag_filter : m_config.texture_min_filter; + + // Note: scale_factor approximates texels per pixel. This means a scale factor less than 1 indicates texture magnification. + if (scale_factor[0] < 1) + return sample_2d_lod(uv, expand4(base_level), m_config.texture_mag_filter); if (m_config.mipmap_filter == MipMapFilter::None) - return sample_2d_lod(uv, expand4(base_level), filter); + return sample_2d_lod(uv, expand4(base_level), m_config.texture_min_filter); // FIXME: Instead of clamping to num_levels - 1, actually make the max mipmap level configurable with glTexParameteri(GL_TEXTURE_MAX_LEVEL, max_level) auto min_level = expand4(static_cast(base_level)); auto max_level = expand4(image.num_levels() - 1.0f); auto level = min(max(log2_approximate(scale_factor) * 0.5f, min_level), max_level); - auto lower_level_texel = sample_2d_lod(uv, to_u32x4(level), filter); + auto lower_level_texel = sample_2d_lod(uv, to_u32x4(level), m_config.texture_min_filter); if (m_config.mipmap_filter == MipMapFilter::Nearest) return lower_level_texel; - auto higher_level_texel = sample_2d_lod(uv, to_u32x4(min(level + 1.f, max_level)), filter); + auto higher_level_texel = sample_2d_lod(uv, to_u32x4(min(level + 1.f, max_level)), m_config.texture_min_filter); return mix(lower_level_texel, higher_level_texel, frac_int_range(level)); }