diff options
author | Stephan Unverwerth <s.unverwerth@serenityos.org> | 2021-08-16 19:08:16 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-18 20:30:58 +0200 |
commit | 39ff1459f81b484eec888ab82bf941a404f8d982 (patch) | |
tree | 8a94152e86ffbf80faec15acb3606c5b54844c36 /Userland/Libraries/LibGL/Tex/Sampler2D.cpp | |
parent | 59998ff0b297d614274068c2e08158a4169ec64f (diff) | |
download | serenity-39ff1459f81b484eec888ab82bf941a404f8d982.zip |
LibGL: Improve texture sampling performance
GL_NEAREST: Remove unnecessary modulo. UV is always in range due to
wrapping.
GL_LINEAR: Rewrite filter equation to save a few math operations.
Diffstat (limited to 'Userland/Libraries/LibGL/Tex/Sampler2D.cpp')
-rw-r--r-- | Userland/Libraries/LibGL/Tex/Sampler2D.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGL/Tex/Sampler2D.cpp b/Userland/Libraries/LibGL/Tex/Sampler2D.cpp index d72fc0fe82..caf3efc1cb 100644 --- a/Userland/Libraries/LibGL/Tex/Sampler2D.cpp +++ b/Userland/Libraries/LibGL/Tex/Sampler2D.cpp @@ -68,7 +68,7 @@ FloatVector4 Sampler2D::sample(FloatVector2 const& uv) const // Sampling implemented according to https://www.khronos.org/registry/OpenGL/specs/gl/glspec121.pdf Chapter 3.8 if (m_mag_filter == GL_NEAREST) { - return mip.texel(static_cast<unsigned>(x) % mip.width(), static_cast<unsigned>(y) % mip.height()); + return mip.texel(static_cast<unsigned>(x), static_cast<unsigned>(y)); } else if (m_mag_filter == GL_LINEAR) { // FIXME: Implement different sampling points for wrap modes other than GL_REPEAT @@ -88,8 +88,11 @@ FloatVector4 Sampler2D::sample(FloatVector2 const& uv) const float frac_x = x - floorf(x); float frac_y = y - floorf(y); + float one_minus_frac_x = 1 - frac_x; - return t0 * (1 - frac_x) * (1 - frac_y) + t1 * frac_x * (1 - frac_y) + t2 * (1 - frac_x) * frac_y + t3 * frac_x * frac_y; + auto h1 = t0 * one_minus_frac_x + t1 * frac_x; + auto h2 = t2 * one_minus_frac_x + t3 * frac_x; + return h1 * (1 - frac_y) + h2 * frac_y; } else { VERIFY_NOT_REACHED(); } |