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
Notes: sideshowbarker 2024-07-18 07:04:59 +09:00
2 changed files with 17 additions and 0 deletions

View File

@ -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

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