gtc_swizzle.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2010-09-16
  5. // Updated : 2010-09-16
  6. // Licence : This source is under MIT licence
  7. // File : test/gtc/swizzle.cpp
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. #define GLM_MESSAGES
  10. #include <glm/glm.hpp>
  11. #include <glm/gtc/swizzle.hpp>
  12. int test_swizzle_vec4_ref_dynamic()
  13. {
  14. {
  15. glm::ivec4 A(0, 1, 2, 3);
  16. glm::ivec4 B(2, 1, 0, 3);
  17. glm::swizzle(A, glm::Z, glm::Y, glm::X, glm::W) = B;
  18. assert(A.x == B.x && A.y == B.y && A.z == B.z && A.w == B.w);
  19. }
  20. {
  21. glm::ivec4 A(0, 1, 2, 3);
  22. glm::ivec3 B(2, 1, 0);
  23. glm::swizzle(A, glm::Z, glm::Y, glm::X) = B;
  24. assert(A.x == B.x && A.y == B.y && A.z == B.z);
  25. }
  26. {
  27. glm::ivec4 A(0, 1, 2, 3);
  28. glm::ivec2 B(2, 1);
  29. glm::swizzle(A, glm::Z, glm::Y) = B;
  30. assert(A.x == B.x && A.y == B.y);
  31. }
  32. {
  33. glm::ivec4 A(0, 1, 2, 3);
  34. int B(2);
  35. glm::swizzle(A, glm::Z) = B;
  36. assert(A.x == B);
  37. }
  38. return 0;
  39. }
  40. int test_swizzle_vec4_ref_static()
  41. {
  42. {
  43. glm::ivec4 A(0, 1, 2, 3);
  44. glm::ivec4 B(2, 1, 0, 3);
  45. glm::swizzle<glm::Z, glm::Y, glm::X, glm::W>(A) = B;
  46. assert(A.x == B.x && A.y == B.y && A.z == B.z && A.w == B.w);
  47. }
  48. {
  49. glm::ivec4 A(0, 1, 2, 3);
  50. glm::ivec3 B(2, 1, 0);
  51. glm::swizzle<glm::Z, glm::Y, glm::X>(A) = B;
  52. assert(A.x == B.x && A.y == B.y && A.z == B.z);
  53. }
  54. {
  55. glm::ivec4 A(0, 1, 2, 3);
  56. glm::ivec2 B(2, 1);
  57. glm::swizzle<glm::Z, glm::Y>(A) = B;
  58. assert(A.x == B.x && A.y == B.y);
  59. }
  60. {
  61. glm::ivec4 A(0, 1, 2, 3);
  62. int B(2);
  63. glm::swizzle<glm::Z>(A) = B;
  64. assert(A.x == B);
  65. }
  66. return 0;
  67. }
  68. int test_swizzle_vec4_const_dynamic()
  69. {
  70. glm::ivec4 A(0, 1, 2, 3);
  71. glm::ivec4 B = glm::swizzle(A, glm::B, glm::G, glm::R, glm::A);
  72. assert(glm::all(glm::equal(A, B)));
  73. glm::ivec3 C = glm::swizzle(A, glm::W, glm::Y, glm::Z);
  74. assert(glm::all(glm::equal(glm::ivec3(A), C)));
  75. glm::ivec2 D = glm::swizzle(A, glm::W, glm::X);
  76. assert(glm::all(glm::equal(glm::ivec2(A), D)));
  77. int E = glm::swizzle(A, glm::Q);
  78. assert(E == A.q);
  79. return 0;
  80. }
  81. int test_swizzle_vec4_const_static()
  82. {
  83. glm::ivec4 A(0, 1, 2, 3);
  84. glm::ivec4 B = glm::swizzle<glm::B, glm::G, glm::R, glm::A>(A);
  85. assert(glm::all(glm::equal(A, B)));
  86. glm::ivec3 C = glm::swizzle<glm::W, glm::Y, glm::Z>(A);
  87. assert(glm::all(glm::equal(glm::ivec3(A), C)));
  88. glm::ivec2 D = glm::swizzle<glm::W, glm::X>(A);
  89. assert(glm::all(glm::equal(glm::ivec2(A), D)));
  90. int E = glm::swizzle<glm::Q>(A);
  91. assert(E == A.q);
  92. return 0;
  93. }
  94. int main()
  95. {
  96. int Failed = 0;
  97. Failed += test_swizzle_vec4_ref_dynamic();
  98. Failed += test_swizzle_vec4_ref_static();
  99. Failed += test_swizzle_vec4_const_dynamic();
  100. Failed += test_swizzle_vec4_const_static();
  101. return Failed;
  102. }