Platformer in OpenGL
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
3.1 KiB

5 years ago
  1. #define GLM_FORCE_SWIZZLE
  2. #include <glm/vector_relational.hpp>
  3. #include <glm/gtc/vec1.hpp>
  4. #include <vector>
  5. static glm::vec1 g1;
  6. static glm::vec1 g2(1);
  7. static int test_vec1_operators()
  8. {
  9. int Error(0);
  10. glm::ivec1 A(1);
  11. glm::ivec1 B(1);
  12. {
  13. bool R = A != B;
  14. bool S = A == B;
  15. Error += (S && !R) ? 0 : 1;
  16. }
  17. {
  18. A *= 1;
  19. B *= 1;
  20. A += 1;
  21. B += 1;
  22. bool R = A != B;
  23. bool S = A == B;
  24. Error += (S && !R) ? 0 : 1;
  25. }
  26. return Error;
  27. }
  28. static int test_vec1_ctor()
  29. {
  30. int Error = 0;
  31. # if GLM_HAS_TRIVIAL_QUERIES
  32. // Error += std::is_trivially_default_constructible<glm::vec1>::value ? 0 : 1;
  33. // Error += std::is_trivially_copy_assignable<glm::vec1>::value ? 0 : 1;
  34. Error += std::is_trivially_copyable<glm::vec1>::value ? 0 : 1;
  35. Error += std::is_trivially_copyable<glm::dvec1>::value ? 0 : 1;
  36. Error += std::is_trivially_copyable<glm::ivec1>::value ? 0 : 1;
  37. Error += std::is_trivially_copyable<glm::uvec1>::value ? 0 : 1;
  38. Error += std::is_copy_constructible<glm::vec1>::value ? 0 : 1;
  39. # endif
  40. {
  41. glm::ivec1 A = glm::vec1(2.0f);
  42. glm::ivec1 E(glm::dvec1(2.0));
  43. Error += A == E ? 0 : 1;
  44. glm::ivec1 F(glm::ivec1(2));
  45. Error += A == F ? 0 : 1;
  46. }
  47. return Error;
  48. }
  49. static int test_vec1_size()
  50. {
  51. int Error = 0;
  52. Error += sizeof(glm::vec1) == sizeof(glm::mediump_vec1) ? 0 : 1;
  53. Error += 4 == sizeof(glm::mediump_vec1) ? 0 : 1;
  54. Error += sizeof(glm::dvec1) == sizeof(glm::highp_dvec1) ? 0 : 1;
  55. Error += 8 == sizeof(glm::highp_dvec1) ? 0 : 1;
  56. Error += glm::vec1().length() == 1 ? 0 : 1;
  57. Error += glm::dvec1().length() == 1 ? 0 : 1;
  58. Error += glm::vec1::length() == 1 ? 0 : 1;
  59. Error += glm::dvec1::length() == 1 ? 0 : 1;
  60. GLM_CONSTEXPR std::size_t Length = glm::vec1::length();
  61. Error += Length == 1 ? 0 : 1;
  62. return Error;
  63. }
  64. static int test_vec1_operator_increment()
  65. {
  66. int Error(0);
  67. glm::ivec1 v0(1);
  68. glm::ivec1 v1(v0);
  69. glm::ivec1 v2(v0);
  70. glm::ivec1 v3 = ++v1;
  71. glm::ivec1 v4 = v2++;
  72. Error += glm::all(glm::equal(v0, v4)) ? 0 : 1;
  73. Error += glm::all(glm::equal(v1, v2)) ? 0 : 1;
  74. Error += glm::all(glm::equal(v1, v3)) ? 0 : 1;
  75. int i0(1);
  76. int i1(i0);
  77. int i2(i0);
  78. int i3 = ++i1;
  79. int i4 = i2++;
  80. Error += i0 == i4 ? 0 : 1;
  81. Error += i1 == i2 ? 0 : 1;
  82. Error += i1 == i3 ? 0 : 1;
  83. return Error;
  84. }
  85. static int test_bvec1_ctor()
  86. {
  87. int Error = 0;
  88. glm::bvec1 const A(true);
  89. glm::bvec1 const B(true);
  90. glm::bvec1 const C(false);
  91. glm::bvec1 const D = A && B;
  92. glm::bvec1 const E = A && C;
  93. glm::bvec1 const F = A || C;
  94. Error += D == glm::bvec1(true) ? 0 : 1;
  95. Error += E == glm::bvec1(false) ? 0 : 1;
  96. Error += F == glm::bvec1(true) ? 0 : 1;
  97. bool const G = A == C;
  98. bool const H = A != C;
  99. Error += !G ? 0 : 1;
  100. Error += H ? 0 : 1;
  101. return Error;
  102. }
  103. static int test_constexpr()
  104. {
  105. #if GLM_HAS_CONSTEXPR
  106. static_assert(glm::vec1::length() == 1, "GLM: Failed constexpr");
  107. static_assert(glm::vec1(1.0f).x > 0.0f, "GLM: Failed constexpr");
  108. #endif
  109. return 0;
  110. }
  111. int main()
  112. {
  113. int Error = 0;
  114. Error += test_vec1_size();
  115. Error += test_vec1_ctor();
  116. Error += test_bvec1_ctor();
  117. Error += test_vec1_operators();
  118. Error += test_vec1_operator_increment();
  119. Error += test_constexpr();
  120. return Error;
  121. }