mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:47:35 +00:00
LibGL: Implement "mirrored repeat" wrap mode
This commit is contained in:
parent
8902efa52d
commit
e0fef60241
2 changed files with 17 additions and 0 deletions
|
@ -201,6 +201,7 @@ extern "C" {
|
||||||
#define GL_NEAREST_MIPMAP_LINEAR 0x2602
|
#define GL_NEAREST_MIPMAP_LINEAR 0x2602
|
||||||
#define GL_CLAMP 0x2900
|
#define GL_CLAMP 0x2900
|
||||||
#define GL_REPEAT 0x2901
|
#define GL_REPEAT 0x2901
|
||||||
|
#define GL_MIRRORED_REPEAT 0x8370
|
||||||
#define GL_CLAMP_TO_BORDER 0x812D
|
#define GL_CLAMP_TO_BORDER 0x812D
|
||||||
#define GL_CLAMP_TO_EDGE 0x812F
|
#define GL_CLAMP_TO_EDGE 0x812F
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,14 @@ static constexpr float wrap_repeat(float value)
|
||||||
return value - floorf(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)
|
static constexpr float wrap_clamp(float value)
|
||||||
{
|
{
|
||||||
return clamp(value, 0.0f, 1.0f);
|
return clamp(value, 0.0f, 1.0f);
|
||||||
|
@ -43,6 +51,10 @@ FloatVector4 Sampler2D::sample(FloatVector2 const& uv) const
|
||||||
x = wrap_clamp(x);
|
x = wrap_clamp(x);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case GL_MIRRORED_REPEAT:
|
||||||
|
x = wrap_mirrored_repeat(x);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
@ -59,6 +71,10 @@ FloatVector4 Sampler2D::sample(FloatVector2 const& uv) const
|
||||||
y = wrap_clamp(y);
|
y = wrap_clamp(y);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case GL_MIRRORED_REPEAT:
|
||||||
|
y = wrap_mirrored_repeat(y);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue