diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h index 93609a8b271..84f60d96c36 100644 --- a/Userland/Libraries/LibGL/GL/gl.h +++ b/Userland/Libraries/LibGL/GL/gl.h @@ -201,6 +201,7 @@ extern "C" { #define GL_NEAREST_MIPMAP_LINEAR 0x2602 #define GL_CLAMP 0x2900 #define GL_REPEAT 0x2901 +#define GL_MIRRORED_REPEAT 0x8370 #define GL_CLAMP_TO_BORDER 0x812D #define GL_CLAMP_TO_EDGE 0x812F diff --git a/Userland/Libraries/LibGL/Tex/Sampler2D.cpp b/Userland/Libraries/LibGL/Tex/Sampler2D.cpp index f2d1aeeb1f5..45cd98405e0 100644 --- a/Userland/Libraries/LibGL/Tex/Sampler2D.cpp +++ b/Userland/Libraries/LibGL/Tex/Sampler2D.cpp @@ -16,6 +16,14 @@ static constexpr float wrap_repeat(float value) return value - floorf(value); } +static constexpr float wrap_mirrored_repeat(float value) +{ + float integer = floorf(value); + float frac = value - integer; + bool iseven = fmodf(integer, 2.0f) == 0.0f; + return iseven ? frac : 1 - frac; +} + static constexpr float wrap_clamp(float value) { return clamp(value, 0.0f, 1.0f); @@ -43,6 +51,10 @@ FloatVector4 Sampler2D::sample(FloatVector2 const& uv) const x = wrap_clamp(x); break; + case GL_MIRRORED_REPEAT: + x = wrap_mirrored_repeat(x); + break; + default: VERIFY_NOT_REACHED(); } @@ -59,6 +71,10 @@ FloatVector4 Sampler2D::sample(FloatVector2 const& uv) const y = wrap_clamp(y); break; + case GL_MIRRORED_REPEAT: + y = wrap_mirrored_repeat(y); + break; + default: VERIFY_NOT_REACHED(); }