gtc_half_float.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. {
  62. glm::hmat2 A(1);
  63. glm::mat2 B(1);
  64. glm::hmat2 C(A);
  65. Error += A == C ? 0 : 1;
  66. }
  67. return Error;
  68. }
  69. int test_half_ctor_mat2x3()
  70. {
  71. int Error = 0;
  72. return Error;
  73. }
  74. int test_half_ctor_mat2x4()
  75. {
  76. int Error = 0;
  77. return Error;
  78. }
  79. int test_half_ctor_mat3x2()
  80. {
  81. int Error = 0;
  82. return Error;
  83. }
  84. int test_half_ctor_mat3x3()
  85. {
  86. int Error = 0;
  87. return Error;
  88. }
  89. int test_half_ctor_mat3x4()
  90. {
  91. int Error = 0;
  92. return Error;
  93. }
  94. int test_half_ctor_mat4x2()
  95. {
  96. int Error = 0;
  97. return Error;
  98. }
  99. int test_half_ctor_mat4x3()
  100. {
  101. int Error = 0;
  102. return Error;
  103. }
  104. int test_half_ctor_mat4x4()
  105. {
  106. int Error = 0;
  107. return Error;
  108. }
  109. int test_half_ctor_vec2()
  110. {
  111. int Error = 0;
  112. {
  113. glm::hvec2 A;
  114. A.x = glm::half(1);
  115. A.y = glm::half(2);
  116. //glm::hvec2 A(1, 2);
  117. glm::hvec2 B(A);
  118. glm::vec2 C(1, 2);
  119. glm::hvec2 D(C);
  120. glm::dvec2 E(1, 2);
  121. glm::hvec2 F(E);
  122. glm::hvec2 G(1, 2.0);
  123. glm::hvec2 H;
  124. H = A;
  125. Error += A == B ? 0 : 1;
  126. //Error += C == D ? 0 : 1; //Error
  127. //Error += E == F ? 0 : 1; //Error
  128. Error += A == G ? 0 : 1;
  129. Error += A == H ? 0 : 1;
  130. }
  131. {
  132. glm::hvec2 A(1);
  133. glm::vec2 B(1);
  134. glm::hvec2 C(A);
  135. Error += A == C ? 0 : 1;
  136. }
  137. return Error;
  138. }
  139. int test_half_ctor_vec3()
  140. {
  141. int Error = 0;
  142. {
  143. glm::hvec3 A(1, 2, 3);
  144. glm::hvec3 B(A);
  145. glm::vec3 C(1, 2, 3);
  146. glm::hvec3 D(C);
  147. glm::dvec3 E(1, 2, 3);
  148. glm::hvec3 F(E);
  149. glm::hvec3 G(1, 2.0, 3);
  150. glm::hvec3 H;
  151. H = A;
  152. Error += A == B ? 0 : 1;
  153. //Error += C == D ? 0 : 1;
  154. //Error += E == F ? 0 : 1;
  155. Error += A == G ? 0 : 1;
  156. Error += A == H ? 0 : 1;
  157. }
  158. {
  159. glm::hvec3 A(1);
  160. glm::vec3 B(1);
  161. glm::hvec3 C(B);
  162. Error += A == C ? 0 : 1;
  163. }
  164. return Error;
  165. }
  166. int test_half_ctor_vec4()
  167. {
  168. int Error = 0;
  169. {
  170. glm::hvec4 A(1, 2, 3, 4);
  171. glm::hvec4 B(A);
  172. glm::vec4 C(1, 2, 3, 4);
  173. glm::hvec4 D(C);
  174. glm::dvec4 E(1, 2, 3, 4);
  175. glm::hvec4 F(E);
  176. glm::hvec4 G(1, 2.0, 3, 4);
  177. glm::hvec4 H;
  178. H = A;
  179. Error += A == B ? 0 : 1;
  180. //Error += C == D ? 0 : 1;
  181. //Error += E == F ? 0 : 1;
  182. Error += A == G ? 0 : 1;
  183. Error += A == H ? 0 : 1;
  184. }
  185. {
  186. glm::hvec4 A(1);
  187. glm::vec4 B(1);
  188. glm::hvec4 C(B);
  189. Error += A == C ? 0 : 1;
  190. }
  191. return Error;
  192. }
  193. int test_hvec2_size()
  194. {
  195. int Error = 0;
  196. Error += sizeof(glm::hvec2) <= sizeof(glm::lowp_vec2) ? 0 : 1;
  197. Error += 4 == sizeof(glm::hvec2) ? 0 : 1;
  198. Error += glm::hvec2().length() == 2 ? 0 : 1;
  199. return Error;
  200. }
  201. int test_hvec3_size()
  202. {
  203. int Error = 0;
  204. Error += sizeof(glm::hvec3) <= sizeof(glm::lowp_vec3) ? 0 : 1;
  205. Error += 6 <= sizeof(glm::hvec3) ? 0 : 1;
  206. Error += glm::hvec3().length() == 3 ? 0 : 1;
  207. return Error;
  208. }
  209. int test_hvec4_size()
  210. {
  211. int Error = 0;
  212. Error += sizeof(glm::hvec4) <= sizeof(glm::lowp_vec4) ? 0 : 1;
  213. Error += 8 <= sizeof(glm::hvec4) ? 0 : 1;
  214. Error += glm::hvec4().length() == 4 ? 0 : 1;
  215. return Error;
  216. }
  217. int main()
  218. {
  219. int Error = 0;
  220. Error += test_hvec2_size();
  221. Error += test_hvec3_size();
  222. Error += test_hvec4_size();
  223. Error += test_half_ctor_vec2();
  224. Error += test_half_ctor_vec3();
  225. Error += test_half_ctor_vec4();
  226. Error += test_half_ctor_mat2x2();
  227. Error += test_half_precision_scalar();
  228. Error += test_half_precision_vec();
  229. Error += test_half_precision_mat();
  230. return Error;
  231. }