Added mirror repeat

This commit is contained in:
Christophe Riccio 2015-06-27 20:12:27 +02:00
parent ff1f50bb15
commit 0141954756
3 changed files with 77 additions and 0 deletions

View File

@ -63,6 +63,11 @@ namespace glm
template <typename genType> template <typename genType>
GLM_FUNC_DECL genType repeat(genType const & Texcoord); GLM_FUNC_DECL genType repeat(genType const & Texcoord);
/// Simulate GL_MIRRORED_REPEAT OpenGL wrap mode
/// @see gtx_wrap extension.
template <typename genType>
GLM_FUNC_DECL genType mirrorClamp(genType const & Texcoord);
/// Simulate GL_MIRROR_REPEAT OpenGL wrap mode /// Simulate GL_MIRROR_REPEAT OpenGL wrap mode
/// @see gtx_wrap extension. /// @see gtx_wrap extension.
template <typename genType> template <typename genType>

View File

@ -98,6 +98,40 @@ namespace glm
return Result; return Result;
} }
template <typename genType>
GLM_FUNC_QUALIFIER genType mirrorClamp(genType const & Texcoord)
{
return glm::fract(glm::abs(Texcoord));
//return glm::mod(glm::abs(Texcoord), 1.0f);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P> mirrorClamp(tvec2<T, P> const & Texcoord)
{
tvec2<T, P> Result;
for(typename tvec2<T, P>::size_type i = 0; i < tvec2<T, P>::value_size(); ++i)
Result[i] = mirrorClamp(Texcoord[i]);
return Result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> mirrorClamp(tvec3<T, P> const & Texcoord)
{
tvec3<T, P> Result;
for(typename tvec3<T, P>::size_type i = 0; i < tvec3<T, P>::value_size(); ++i)
Result[i] = mirrorClamp(Texcoord[i]);
return Result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> mirrorClamp(tvec4<T, P> const & Texcoord)
{
tvec4<T, P> Result;
for(typename tvec4<T, P>::size_type i = 0; i < tvec4<T, P>::value_size(); ++i)
Result[i] = mirrorClamp(Texcoord[i]);
return Result;
}
template <typename genType> template <typename genType>
GLM_FUNC_QUALIFIER genType mirrorRepeat(genType const & Texcoord) GLM_FUNC_QUALIFIER genType mirrorRepeat(genType const & Texcoord)
{ {

View File

@ -85,6 +85,43 @@ namespace repeat
} }
}//namespace repeat }//namespace repeat
namespace mirrorClamp
{
int test()
{
int Error(0);
float A = glm::mirrorClamp(0.5f);
Error += glm::epsilonEqual(A, 0.5f, 0.00001f) ? 0 : 1;
float B = glm::mirrorClamp(0.0f);
Error += glm::epsilonEqual(B, 0.0f, 0.00001f) ? 0 : 1;
float C = glm::mirrorClamp(1.1f);
Error += glm::epsilonEqual(C, 0.1f, 0.00001f) ? 0 : 1;
float D = glm::mirrorClamp(-0.5f);
Error += glm::epsilonEqual(D, 0.5f, 0.00001f) ? 0 : 1;
float E = glm::mirrorClamp(1.5f);
Error += glm::epsilonEqual(E, 0.5f, 0.00001f) ? 0 : 1;
float F = glm::mirrorClamp(0.9f);
Error += glm::epsilonEqual(F, 0.9f, 0.00001f) ? 0 : 1;
float G = glm::mirrorClamp(3.1f);
Error += glm::epsilonEqual(G, 0.1f, 0.00001f) ? 0 : 1;
float H = glm::mirrorClamp(-3.1f);
Error += glm::epsilonEqual(H, 0.1f, 0.00001f) ? 0 : 1;
float I = glm::mirrorClamp(-0.9f);
Error += glm::epsilonEqual(I, 0.9f, 0.00001f) ? 0 : 1;
return Error;
}
}//namespace mirrorClamp
namespace mirrorRepeat namespace mirrorRepeat
{ {
int test() int test()
@ -128,6 +165,7 @@ int main()
Error += clamp::test(); Error += clamp::test();
Error += repeat::test(); Error += repeat::test();
Error += mirrorClamp::test();
Error += mirrorRepeat::test(); Error += mirrorRepeat::test();
return Error; return Error;