diff --git a/glm/gtx/wrap.hpp b/glm/gtx/wrap.hpp index cf21d6fe..20566516 100644 --- a/glm/gtx/wrap.hpp +++ b/glm/gtx/wrap.hpp @@ -63,6 +63,11 @@ namespace glm template GLM_FUNC_DECL genType repeat(genType const & Texcoord); + /// Simulate GL_MIRRORED_REPEAT OpenGL wrap mode + /// @see gtx_wrap extension. + template + GLM_FUNC_DECL genType mirrorClamp(genType const & Texcoord); + /// Simulate GL_MIRROR_REPEAT OpenGL wrap mode /// @see gtx_wrap extension. template diff --git a/glm/gtx/wrap.inl b/glm/gtx/wrap.inl index d0d8e256..402e815d 100644 --- a/glm/gtx/wrap.inl +++ b/glm/gtx/wrap.inl @@ -98,6 +98,40 @@ namespace glm return Result; } + template + GLM_FUNC_QUALIFIER genType mirrorClamp(genType const & Texcoord) + { + return glm::fract(glm::abs(Texcoord)); + //return glm::mod(glm::abs(Texcoord), 1.0f); + } + + template + GLM_FUNC_QUALIFIER tvec2 mirrorClamp(tvec2 const & Texcoord) + { + tvec2 Result; + for(typename tvec2::size_type i = 0; i < tvec2::value_size(); ++i) + Result[i] = mirrorClamp(Texcoord[i]); + return Result; + } + + template + GLM_FUNC_QUALIFIER tvec3 mirrorClamp(tvec3 const & Texcoord) + { + tvec3 Result; + for(typename tvec3::size_type i = 0; i < tvec3::value_size(); ++i) + Result[i] = mirrorClamp(Texcoord[i]); + return Result; + } + + template + GLM_FUNC_QUALIFIER tvec4 mirrorClamp(tvec4 const & Texcoord) + { + tvec4 Result; + for(typename tvec4::size_type i = 0; i < tvec4::value_size(); ++i) + Result[i] = mirrorClamp(Texcoord[i]); + return Result; + } + template GLM_FUNC_QUALIFIER genType mirrorRepeat(genType const & Texcoord) { diff --git a/test/gtx/gtx_wrap.cpp b/test/gtx/gtx_wrap.cpp index 2366170e..b65d94ba 100644 --- a/test/gtx/gtx_wrap.cpp +++ b/test/gtx/gtx_wrap.cpp @@ -85,6 +85,43 @@ 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 { int test() @@ -128,6 +165,7 @@ int main() Error += clamp::test(); Error += repeat::test(); + Error += mirrorClamp::test(); Error += mirrorRepeat::test(); return Error;