gtc_half_float.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2011-05-32
  5. // Updated : 2011-05-32
  6. // Licence : This source is under MIT licence
  7. // File : test/gtc/half_float.cpp
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. #include <glm/glm.hpp>
  10. #include <glm/gtc/half_float.hpp>
  11. int test_half_precision_scalar()
  12. {
  13. int Error = 0;
  14. Error += sizeof(glm::half) == 2 ? 0 : 1;
  15. return Error;
  16. }
  17. int test_half_precision_vec()
  18. {
  19. int Error = 0;
  20. Error += sizeof(glm::hvec2) == 4 ? 0 : 1;
  21. Error += sizeof(glm::hvec3) == 6 ? 0 : 1;
  22. Error += sizeof(glm::hvec4) == 8 ? 0 : 1;
  23. return Error;
  24. }
  25. int test_half_precision_mat()
  26. {
  27. int Error = 0;
  28. Error += sizeof(glm::hmat2) == 8 ? 0 : 1;
  29. Error += sizeof(glm::hmat3) == 18 ? 0 : 1;
  30. Error += sizeof(glm::hmat4) == 32 ? 0 : 1;
  31. Error += sizeof(glm::hmat2x2) == 8 ? 0 : 1;
  32. Error += sizeof(glm::hmat2x3) == 12 ? 0 : 1;
  33. Error += sizeof(glm::hmat2x4) == 16 ? 0 : 1;
  34. Error += sizeof(glm::hmat3x2) == 12 ? 0 : 1;
  35. Error += sizeof(glm::hmat3x3) == 18 ? 0 : 1;
  36. Error += sizeof(glm::hmat3x4) == 24 ? 0 : 1;
  37. Error += sizeof(glm::hmat4x2) == 16 ? 0 : 1;
  38. Error += sizeof(glm::hmat4x3) == 24 ? 0 : 1;
  39. Error += sizeof(glm::hmat4x4) == 32 ? 0 : 1;
  40. return Error;
  41. }
  42. int test_half_ctor_mat2x2()
  43. {
  44. int Error = 0;
  45. {
  46. glm::hvec2 A(1, 2);
  47. glm::hvec2 B(3, 4);
  48. glm::hmat2 C(A, B);//, 2.0f, 3.0f, 4.0f);
  49. glm::hmat2 D(1, 2, 3, 4);
  50. Error += C[0] == D[0] ? 0 : 1;
  51. Error += C[1] == D[1] ? 0 : 1;
  52. }
  53. {
  54. glm::hvec2 A(1, 2.0);
  55. glm::hvec2 B(3, 4.0);
  56. glm::hmat2 C(A, B);//, 2.0f, 3.0f, 4.0f);
  57. glm::hmat2 D(1, 2.0, 3u, 4.0f);
  58. Error += C[0] == D[0] ? 0 : 1;
  59. Error += C[1] == D[1] ? 0 : 1;
  60. }
  61. return Error;
  62. }
  63. int test_half_ctor_mat2x3()
  64. {
  65. int Error = 0;
  66. return Error;
  67. }
  68. int test_half_ctor_mat2x4()
  69. {
  70. int Error = 0;
  71. return Error;
  72. }
  73. int test_half_ctor_mat3x2()
  74. {
  75. int Error = 0;
  76. return Error;
  77. }
  78. int test_half_ctor_mat3x3()
  79. {
  80. int Error = 0;
  81. return Error;
  82. }
  83. int test_half_ctor_mat3x4()
  84. {
  85. int Error = 0;
  86. return Error;
  87. }
  88. int test_half_ctor_mat4x2()
  89. {
  90. int Error = 0;
  91. return Error;
  92. }
  93. int test_half_ctor_mat4x3()
  94. {
  95. int Error = 0;
  96. return Error;
  97. }
  98. int test_half_ctor_mat4x4()
  99. {
  100. int Error = 0;
  101. return Error;
  102. }
  103. int test_half_ctor_vec2()
  104. {
  105. int Error = 0;
  106. {
  107. glm::hvec2 A(1, 2);
  108. glm::hvec2 B(A);
  109. glm::vec2 C(1, 2);
  110. glm::hvec2 D(C);
  111. glm::dvec2 E(1, 2);
  112. glm::hvec2 F(E);
  113. glm::hvec2 G(1, 2.0);
  114. glm::hvec2 H;
  115. H = A;
  116. Error += A == B ? 0 : 1;
  117. //Error += C == D ? 0 : 1; //Error
  118. //Error += E == F ? 0 : 1; //Error
  119. Error += A == G ? 0 : 1;
  120. Error += A == H ? 0 : 1;
  121. }
  122. {
  123. glm::hvec2 A(1);
  124. glm::vec2 B(1);
  125. //Error += A == B ? 0 : 1; //Error
  126. }
  127. return Error;
  128. }
  129. int test_half_ctor_vec3()
  130. {
  131. return 0;
  132. }
  133. int test_half_ctor_vec4()
  134. {
  135. return 0;
  136. }
  137. int main()
  138. {
  139. int Error = 0;
  140. Error += test_half_ctor_vec2();
  141. Error += test_half_ctor_vec3();
  142. Error += test_half_ctor_vec4();
  143. Error += test_half_ctor_mat2x2();
  144. Error += test_half_precision_scalar();
  145. Error += test_half_precision_vec();
  146. Error += test_half_precision_mat();
  147. return Error;
  148. }