mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-14 13:32:23 +00:00
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.
This commit is contained in:
parent
59998ff0b2
commit
39ff1459f8
Notes:
sideshowbarker
2024-07-18 05:30:22 +09:00
Author: https://github.com/sunverwerth
Commit: 39ff1459f8
Pull-request: https://github.com/SerenityOS/serenity/pull/9451
Reviewed-by: https://github.com/Quaker762 ✅
Reviewed-by: https://github.com/alimpfard
1 changed files with 5 additions and 2 deletions
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue