From 8902efa52d805ac87544d0fb990273538e7b668e Mon Sep 17 00:00:00 2001 From: Stephan Unverwerth Date: Wed, 11 Aug 2021 21:18:01 +0200 Subject: [PATCH] LibGL: Implement "clamp" wrap mode --- Userland/Libraries/LibGL/GL/gl.h | 5 ++++- Userland/Libraries/LibGL/Tex/Sampler2D.cpp | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h index 5b632506160..93609a8b271 100644 --- a/Userland/Libraries/LibGL/GL/gl.h +++ b/Userland/Libraries/LibGL/GL/gl.h @@ -199,7 +199,10 @@ extern "C" { #define GL_NEAREST 0x2600 #define GL_LINEAR 0x2601 #define GL_NEAREST_MIPMAP_LINEAR 0x2602 -#define GL_REPEAT 0x2603 +#define GL_CLAMP 0x2900 +#define GL_REPEAT 0x2901 +#define GL_CLAMP_TO_BORDER 0x812D +#define GL_CLAMP_TO_EDGE 0x812F // OpenGL State & GLGet #define GL_MODELVIEW_MATRIX 0x0BA6 diff --git a/Userland/Libraries/LibGL/Tex/Sampler2D.cpp b/Userland/Libraries/LibGL/Tex/Sampler2D.cpp index e88babfae67..f2d1aeeb1f5 100644 --- a/Userland/Libraries/LibGL/Tex/Sampler2D.cpp +++ b/Userland/Libraries/LibGL/Tex/Sampler2D.cpp @@ -16,6 +16,11 @@ static constexpr float wrap_repeat(float value) return value - floorf(value); } +static constexpr float wrap_clamp(float value) +{ + return clamp(value, 0.0f, 1.0f); +} + FloatVector4 Sampler2D::sample(FloatVector2 const& uv) const { // FIXME: Calculate the correct mipmap level here, need to receive uv derivatives for that @@ -31,6 +36,13 @@ FloatVector4 Sampler2D::sample(FloatVector2 const& uv) const x = wrap_repeat(x); break; + // FIXME: These clamp modes actually have slightly different behaviour + case GL_CLAMP: + case GL_CLAMP_TO_BORDER: + case GL_CLAMP_TO_EDGE: + x = wrap_clamp(x); + break; + default: VERIFY_NOT_REACHED(); } @@ -40,6 +52,13 @@ FloatVector4 Sampler2D::sample(FloatVector2 const& uv) const y = wrap_repeat(y); break; + // FIXME: These clamp modes actually have slightly different behaviour + case GL_CLAMP: + case GL_CLAMP_TO_BORDER: + case GL_CLAMP_TO_EDGE: + y = wrap_clamp(y); + break; + default: VERIFY_NOT_REACHED(); }