wrap.inl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /// @ref gtx_wrap
  2. namespace glm
  3. {
  4. template<length_t L, typename T, qualifier Q>
  5. GLM_FUNC_QUALIFIER vec<L, T, Q> clamp(vec<L, T, Q> const& Texcoord)
  6. {
  7. return glm::clamp(Texcoord, vec<L, T, Q>(0), vec<L, T, Q>(1));
  8. }
  9. template<typename genType>
  10. GLM_FUNC_QUALIFIER genType clamp(genType const& Texcoord)
  11. {
  12. return clamp(vec<1, genType, defaultp>(Texcoord)).x;
  13. }
  14. template<length_t L, typename T, qualifier Q>
  15. GLM_FUNC_QUALIFIER vec<L, T, Q> repeat(vec<L, T, Q> const& Texcoord)
  16. {
  17. return glm::fract(Texcoord);
  18. }
  19. template<typename genType>
  20. GLM_FUNC_QUALIFIER genType repeat(genType const& Texcoord)
  21. {
  22. return repeat(vec<1, genType, defaultp>(Texcoord)).x;
  23. }
  24. template<length_t L, typename T, qualifier Q>
  25. GLM_FUNC_QUALIFIER vec<L, T, Q> mirrorClamp(vec<L, T, Q> const& Texcoord)
  26. {
  27. return glm::fract(glm::abs(Texcoord));
  28. }
  29. template<typename genType>
  30. GLM_FUNC_QUALIFIER genType mirrorClamp(genType const& Texcoord)
  31. {
  32. return mirrorClamp(vec<1, genType, defaultp>(Texcoord)).x;
  33. }
  34. template<length_t L, typename T, qualifier Q>
  35. GLM_FUNC_QUALIFIER vec<L, T, Q> mirrorRepeat(vec<L, T, Q> const& Texcoord)
  36. {
  37. vec<L, T, Q> const Abs = glm::abs(Texcoord);
  38. vec<L, T, Q> const Clamp = glm::mod(glm::floor(Abs), vec<L, T, Q>(2));
  39. vec<L, T, Q> const Floor = glm::floor(Abs);
  40. vec<L, T, Q> const Rest = Abs - Floor;
  41. vec<L, T, Q> const Mirror = Clamp + Rest;
  42. return mix(Rest, vec<L, T, Q>(1) - Rest, glm::greaterThanEqual(Mirror, vec<L, T, Q>(1)));
  43. }
  44. template<typename genType>
  45. GLM_FUNC_QUALIFIER genType mirrorRepeat(genType const& Texcoord)
  46. {
  47. return mirrorRepeat(vec<1, genType, defaultp>(Texcoord)).x;
  48. }
  49. }//namespace glm