From f856f49edb35e0267798f121cb031b82ca34a62e Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Sun, 26 Dec 2021 23:38:51 +0100 Subject: [PATCH] LibSoftGPU: Clamp to edge instead of border According to the Khronos FAQ on texture edge sampling, the `GL_CLAMP` option was never implemented in hardware and as such, it was deprecated. A lot of applications and games depend on `GL_CLAMP` not really meaning `GL_CLAMP` but `GL_CLAMP_TO_EDGE`, so we introduce an option to toggle this behavior at compile-time. --- Userland/Libraries/LibSoftGPU/Sampler.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibSoftGPU/Sampler.cpp b/Userland/Libraries/LibSoftGPU/Sampler.cpp index fe6b5db98a..7730a3934e 100644 --- a/Userland/Libraries/LibSoftGPU/Sampler.cpp +++ b/Userland/Libraries/LibSoftGPU/Sampler.cpp @@ -10,12 +10,16 @@ namespace SoftGPU { -constexpr static float fracf(float value) +// See: https://www.khronos.org/opengl/wiki/Common_Mistakes#Texture_edge_color_problem +// FIXME: make this dynamically configurable through ConfigServer +static constexpr bool CLAMP_DEPRECATED_BEHAVIOR = false; + +static constexpr float fracf(float value) { return value - floorf(value); } -constexpr static float wrap_repeat(float value) +static constexpr float wrap_repeat(float value) { return fracf(value); } @@ -39,7 +43,7 @@ static constexpr float wrap_mirrored_repeat(float value, unsigned num_texels) return wrap_clamp_to_edge(iseven ? frac : 1 - frac, num_texels); } -constexpr static float wrap(float value, TextureWrapMode mode, unsigned num_texels) +static constexpr float wrap(float value, TextureWrapMode mode, unsigned num_texels) { switch (mode) { case TextureWrapMode::Repeat: @@ -47,7 +51,10 @@ constexpr static float wrap(float value, TextureWrapMode mode, unsigned num_texe case TextureWrapMode::MirroredRepeat: return wrap_mirrored_repeat(value, num_texels); case TextureWrapMode::Clamp: - return wrap_clamp(value); + if constexpr (CLAMP_DEPRECATED_BEHAVIOR) { + return wrap_clamp(value); + } + return wrap_clamp_to_edge(value, num_texels); case TextureWrapMode::ClampToBorder: case TextureWrapMode::ClampToEdge: return wrap_clamp_to_edge(value, num_texels);