1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:37:35 +00:00

LibGL: Implement "mirrored repeat" wrap mode

This commit is contained in:
Stephan Unverwerth 2021-08-11 22:06:07 +02:00 committed by Andreas Kling
parent 8902efa52d
commit e0fef60241
2 changed files with 17 additions and 0 deletions

View file

@ -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();
}