diff options
author | Stephan Unverwerth <s.unverwerth@serenityos.org> | 2022-03-07 22:36:43 +0100 |
---|---|---|
committer | Idan Horowitz <idan.horowitz@gmail.com> | 2022-03-08 00:49:31 +0200 |
commit | 8165346ae4ab1fbc05a5fc3d2f05427dce7f8c90 (patch) | |
tree | 716818979e1702f19e8b51999fa8a272968ab58b | |
parent | 29eee390ec42f7b3693430f7b2928dd2ecb39ca3 (diff) | |
download | serenity-8165346ae4ab1fbc05a5fc3d2f05427dce7f8c90.zip |
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.
-rw-r--r-- | Userland/Libraries/LibSoftGPU/Sampler.cpp | 11 |
1 files 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<AK::SIMD::f32x4> Sampler::sample_2d(Vector2<AK::SIMD::f32x4> 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<float>(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)); } |