diff options
author | Jelle Raaijmakers <jelle@gmta.nl> | 2021-12-26 23:38:51 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-12-27 11:58:43 +0100 |
commit | f856f49edb35e0267798f121cb031b82ca34a62e (patch) | |
tree | cc7214eee4b3bad3454806adc78bab3f0c4fe7c9 | |
parent | d9ea1fe4c9156cf33a973174f8f0ac17c76358e9 (diff) | |
download | serenity-f856f49edb35e0267798f121cb031b82ca34a62e.zip |
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.
-rw-r--r-- | Userland/Libraries/LibSoftGPU/Sampler.cpp | 15 |
1 files 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); |