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.

878 lines
18 KiB

5 years ago
  1. #include <glm/packing.hpp>
  2. #include <glm/gtc/packing.hpp>
  3. #include <glm/gtc/epsilon.hpp>
  4. #include <glm/ext/vector_relational.hpp>
  5. #include <cstdio>
  6. #include <vector>
  7. void print_bits(float const& s)
  8. {
  9. union
  10. {
  11. float f;
  12. unsigned int i;
  13. } uif;
  14. uif.f = s;
  15. printf("f32: ");
  16. for(std::size_t j = sizeof(s) * 8; j > 0; --j)
  17. {
  18. if(j == 23 || j == 31)
  19. printf(" ");
  20. printf("%d", (uif.i & (1 << (j - 1))) ? 1 : 0);
  21. }
  22. }
  23. void print_10bits(glm::uint const& s)
  24. {
  25. printf("10b: ");
  26. for(std::size_t j = 10; j > 0; --j)
  27. {
  28. if(j == 5)
  29. printf(" ");
  30. printf("%d", (s & (1 << (j - 1))) ? 1 : 0);
  31. }
  32. }
  33. void print_11bits(glm::uint const& s)
  34. {
  35. printf("11b: ");
  36. for(std::size_t j = 11; j > 0; --j)
  37. {
  38. if(j == 6)
  39. printf(" ");
  40. printf("%d", (s & (1 << (j - 1))) ? 1 : 0);
  41. }
  42. }
  43. void print_value(float const& s)
  44. {
  45. printf("%2.5f, ", static_cast<double>(s));
  46. print_bits(s);
  47. printf(", ");
  48. // print_11bits(detail::floatTo11bit(s));
  49. // printf(", ");
  50. // print_10bits(detail::floatTo10bit(s));
  51. printf("\n");
  52. }
  53. int test_Half1x16()
  54. {
  55. int Error = 0;
  56. std::vector<float> Tests;
  57. Tests.push_back(0.0f);
  58. Tests.push_back(1.0f);
  59. Tests.push_back(-1.0f);
  60. Tests.push_back(2.0f);
  61. Tests.push_back(-2.0f);
  62. Tests.push_back(1.9f);
  63. for(std::size_t i = 0; i < Tests.size(); ++i)
  64. {
  65. glm::uint16 p0 = glm::packHalf1x16(Tests[i]);
  66. float v0 = glm::unpackHalf1x16(p0);
  67. glm::uint16 p1 = glm::packHalf1x16(v0);
  68. float v1 = glm::unpackHalf1x16(p1);
  69. Error += glm::epsilonEqual(v0, v1, glm::epsilon<float>()) ? 0 : 1;
  70. }
  71. return Error;
  72. }
  73. int test_Half4x16()
  74. {
  75. int Error = 0;
  76. std::vector<glm::vec4> Tests;
  77. Tests.push_back(glm::vec4(1.0f));
  78. Tests.push_back(glm::vec4(0.0f));
  79. Tests.push_back(glm::vec4(2.0f));
  80. Tests.push_back(glm::vec4(0.1f));
  81. Tests.push_back(glm::vec4(0.5f));
  82. Tests.push_back(glm::vec4(-0.9f));
  83. for(std::size_t i = 0; i < Tests.size(); ++i)
  84. {
  85. glm::uint64 p0 = glm::packHalf4x16(Tests[i]);
  86. glm::vec4 v0 = glm::unpackHalf4x16(p0);
  87. glm::uint64 p1 = glm::packHalf4x16(v0);
  88. glm::vec4 v1 = glm::unpackHalf4x16(p1);
  89. glm::u16vec4 p2 = glm::packHalf(v0);
  90. glm::vec4 v2 = glm::unpackHalf(p2);
  91. Error += glm::all(glm::equal(v0, v1, glm::epsilon<float>())) ? 0 : 1;
  92. Error += glm::all(glm::equal(v0, v2, glm::epsilon<float>())) ? 0 : 1;
  93. }
  94. return Error;
  95. }
  96. int test_I3x10_1x2()
  97. {
  98. int Error = 0;
  99. std::vector<glm::ivec4> Tests;
  100. Tests.push_back(glm::ivec4(0));
  101. Tests.push_back(glm::ivec4(1));
  102. Tests.push_back(glm::ivec4(-1));
  103. Tests.push_back(glm::ivec4(2));
  104. Tests.push_back(glm::ivec4(-2));
  105. Tests.push_back(glm::ivec4(3));
  106. for(std::size_t i = 0; i < Tests.size(); ++i)
  107. {
  108. glm::uint32 p0 = glm::packI3x10_1x2(Tests[i]);
  109. glm::ivec4 v0 = glm::unpackI3x10_1x2(p0);
  110. glm::uint32 p1 = glm::packI3x10_1x2(v0);
  111. glm::ivec4 v1 = glm::unpackI3x10_1x2(p1);
  112. Error += glm::all(glm::equal(v0, v1)) ? 0 : 1;
  113. }
  114. return Error;
  115. }
  116. int test_U3x10_1x2()
  117. {
  118. int Error = 0;
  119. std::vector<glm::uvec4> Tests;
  120. Tests.push_back(glm::uvec4(0));
  121. Tests.push_back(glm::uvec4(1));
  122. Tests.push_back(glm::uvec4(2));
  123. Tests.push_back(glm::uvec4(3));
  124. Tests.push_back(glm::uvec4(4));
  125. Tests.push_back(glm::uvec4(5));
  126. for(std::size_t i = 0; i < Tests.size(); ++i)
  127. {
  128. glm::uint32 p0 = glm::packU3x10_1x2(Tests[i]);
  129. glm::uvec4 v0 = glm::unpackU3x10_1x2(p0);
  130. glm::uint32 p1 = glm::packU3x10_1x2(v0);
  131. glm::uvec4 v1 = glm::unpackU3x10_1x2(p1);
  132. Error += glm::all(glm::equal(v0, v1)) ? 0 : 1;
  133. }
  134. glm::u8vec4 const v0(0xff, 0x77, 0x0, 0x33);
  135. glm::uint32 const p0 = *reinterpret_cast<glm::uint32 const*>(&v0[0]);
  136. glm::uint32 const r0 = 0x330077ff;
  137. Error += p0 == r0 ? 0 : 1;
  138. glm::uvec4 const v1(0xff, 0x77, 0x0, 0x33);
  139. glm::uint32 const p1 = glm::packU3x10_1x2(v1);
  140. glm::uint32 const r1 = 0xc001dcff;
  141. Error += p1 == r1 ? 0 : 1;
  142. return Error;
  143. }
  144. int test_Snorm3x10_1x2()
  145. {
  146. int Error = 0;
  147. std::vector<glm::vec4> Tests;
  148. Tests.push_back(glm::vec4(1.0f));
  149. Tests.push_back(glm::vec4(0.0f));
  150. Tests.push_back(glm::vec4(2.0f));
  151. Tests.push_back(glm::vec4(0.1f));
  152. Tests.push_back(glm::vec4(0.5f));
  153. Tests.push_back(glm::vec4(0.9f));
  154. for(std::size_t i = 0; i < Tests.size(); ++i)
  155. {
  156. glm::uint32 p0 = glm::packSnorm3x10_1x2(Tests[i]);
  157. glm::vec4 v0 = glm::unpackSnorm3x10_1x2(p0);
  158. glm::uint32 p1 = glm::packSnorm3x10_1x2(v0);
  159. glm::vec4 v1 = glm::unpackSnorm3x10_1x2(p1);
  160. Error += glm::all(glm::epsilonEqual(v0, v1, 0.01f)) ? 0 : 1;
  161. }
  162. return Error;
  163. }
  164. int test_Unorm3x10_1x2()
  165. {
  166. int Error = 0;
  167. std::vector<glm::vec4> Tests;
  168. Tests.push_back(glm::vec4(1.0f));
  169. Tests.push_back(glm::vec4(0.0f));
  170. Tests.push_back(glm::vec4(2.0f));
  171. Tests.push_back(glm::vec4(0.1f));
  172. Tests.push_back(glm::vec4(0.5f));
  173. Tests.push_back(glm::vec4(0.9f));
  174. for(std::size_t i = 0; i < Tests.size(); ++i)
  175. {
  176. glm::uint32 p0 = glm::packUnorm3x10_1x2(Tests[i]);
  177. glm::vec4 v0 = glm::unpackUnorm3x10_1x2(p0);
  178. glm::uint32 p1 = glm::packUnorm3x10_1x2(v0);
  179. glm::vec4 v1 = glm::unpackUnorm3x10_1x2(p1);
  180. Error += glm::all(glm::epsilonEqual(v0, v1, 0.001f)) ? 0 : 1;
  181. }
  182. return Error;
  183. }
  184. int test_F2x11_1x10()
  185. {
  186. int Error = 0;
  187. std::vector<glm::vec3> Tests;
  188. Tests.push_back(glm::vec3(1.0f));
  189. Tests.push_back(glm::vec3(0.0f));
  190. Tests.push_back(glm::vec3(2.0f));
  191. Tests.push_back(glm::vec3(0.1f));
  192. Tests.push_back(glm::vec3(0.5f));
  193. Tests.push_back(glm::vec3(0.9f));
  194. for(std::size_t i = 0; i < Tests.size(); ++i)
  195. {
  196. glm::uint32 p0 = glm::packF2x11_1x10(Tests[i]);
  197. glm::vec3 v0 = glm::unpackF2x11_1x10(p0);
  198. glm::uint32 p1 = glm::packF2x11_1x10(v0);
  199. glm::vec3 v1 = glm::unpackF2x11_1x10(p1);
  200. Error += glm::all(glm::equal(v0, v1, glm::epsilon<float>())) ? 0 : 1;
  201. }
  202. return Error;
  203. }
  204. int test_F3x9_E1x5()
  205. {
  206. int Error = 0;
  207. std::vector<glm::vec3> Tests;
  208. Tests.push_back(glm::vec3(1.0f));
  209. Tests.push_back(glm::vec3(0.0f));
  210. Tests.push_back(glm::vec3(2.0f));
  211. Tests.push_back(glm::vec3(0.1f));
  212. Tests.push_back(glm::vec3(0.5f));
  213. Tests.push_back(glm::vec3(0.9f));
  214. for(std::size_t i = 0; i < Tests.size(); ++i)
  215. {
  216. glm::uint32 p0 = glm::packF3x9_E1x5(Tests[i]);
  217. glm::vec3 v0 = glm::unpackF3x9_E1x5(p0);
  218. glm::uint32 p1 = glm::packF3x9_E1x5(v0);
  219. glm::vec3 v1 = glm::unpackF3x9_E1x5(p1);
  220. Error += glm::all(glm::equal(v0, v1, glm::epsilon<float>())) ? 0 : 1;
  221. }
  222. return Error;
  223. }
  224. int test_RGBM()
  225. {
  226. int Error = 0;
  227. for(std::size_t i = 0; i < 1024; ++i)
  228. {
  229. glm::vec3 const Color(static_cast<float>(i));
  230. glm::vec4 const RGBM = glm::packRGBM(Color);
  231. glm::vec3 const Result= glm::unpackRGBM(RGBM);
  232. Error += glm::all(glm::equal(Color, Result, 0.01f)) ? 0 : 1;
  233. }
  234. return Error;
  235. }
  236. int test_packUnorm1x16()
  237. {
  238. int Error = 0;
  239. std::vector<glm::vec1> A;
  240. A.push_back(glm::vec1(1.0f));
  241. A.push_back(glm::vec1(0.5f));
  242. A.push_back(glm::vec1(0.1f));
  243. A.push_back(glm::vec1(0.0f));
  244. for(std::size_t i = 0; i < A.size(); ++i)
  245. {
  246. glm::vec1 B(A[i]);
  247. glm::uint16 C = glm::packUnorm1x16(B.x);
  248. glm::vec1 D(glm::unpackUnorm1x16(C));
  249. Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 65535.f)) ? 0 : 1;
  250. assert(!Error);
  251. }
  252. return Error;
  253. }
  254. int test_packSnorm1x16()
  255. {
  256. int Error = 0;
  257. std::vector<glm::vec1> A;
  258. A.push_back(glm::vec1( 1.0f));
  259. A.push_back(glm::vec1( 0.0f));
  260. A.push_back(glm::vec1(-0.5f));
  261. A.push_back(glm::vec1(-0.1f));
  262. for(std::size_t i = 0; i < A.size(); ++i)
  263. {
  264. glm::vec1 B(A[i]);
  265. glm::uint16 C = glm::packSnorm1x16(B.x);
  266. glm::vec1 D(glm::unpackSnorm1x16(C));
  267. Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
  268. }
  269. return Error;
  270. }
  271. int test_packUnorm2x16()
  272. {
  273. int Error = 0;
  274. std::vector<glm::vec2> A;
  275. A.push_back(glm::vec2(1.0f, 0.0f));
  276. A.push_back(glm::vec2(0.5f, 0.7f));
  277. A.push_back(glm::vec2(0.1f, 0.2f));
  278. for(std::size_t i = 0; i < A.size(); ++i)
  279. {
  280. glm::vec2 B(A[i]);
  281. glm::uint32 C = glm::packUnorm2x16(B);
  282. glm::vec2 D = glm::unpackUnorm2x16(C);
  283. Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 65535.f)) ? 0 : 1;
  284. assert(!Error);
  285. }
  286. return Error;
  287. }
  288. int test_packSnorm2x16()
  289. {
  290. int Error = 0;
  291. std::vector<glm::vec2> A;
  292. A.push_back(glm::vec2( 1.0f, 0.0f));
  293. A.push_back(glm::vec2(-0.5f,-0.7f));
  294. A.push_back(glm::vec2(-0.1f, 0.1f));
  295. for(std::size_t i = 0; i < A.size(); ++i)
  296. {
  297. glm::vec2 B(A[i]);
  298. glm::uint32 C = glm::packSnorm2x16(B);
  299. glm::vec2 D = glm::unpackSnorm2x16(C);
  300. Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
  301. assert(!Error);
  302. }
  303. return Error;
  304. }
  305. int test_packUnorm4x16()
  306. {
  307. int Error = 0;
  308. std::vector<glm::vec4> A;
  309. A.push_back(glm::vec4(1.0f));
  310. A.push_back(glm::vec4(0.5f));
  311. A.push_back(glm::vec4(0.1f));
  312. A.push_back(glm::vec4(0.0f));
  313. for(std::size_t i = 0; i < A.size(); ++i)
  314. {
  315. glm::vec4 B(A[i]);
  316. glm::uint64 C = glm::packUnorm4x16(B);
  317. glm::vec4 D(glm::unpackUnorm4x16(C));
  318. Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 65535.f)) ? 0 : 1;
  319. assert(!Error);
  320. }
  321. return Error;
  322. }
  323. int test_packSnorm4x16()
  324. {
  325. int Error = 0;
  326. std::vector<glm::vec4> A;
  327. A.push_back(glm::vec4( 1.0f, 0.0f, -0.5f, 0.5f));
  328. A.push_back(glm::vec4(-0.3f,-0.7f, 0.3f, 0.7f));
  329. A.push_back(glm::vec4(-0.1f, 0.1f, -0.2f, 0.2f));
  330. for(std::size_t i = 0; i < A.size(); ++i)
  331. {
  332. glm::vec4 B(A[i]);
  333. glm::uint64 C = glm::packSnorm4x16(B);
  334. glm::vec4 D(glm::unpackSnorm4x16(C));
  335. Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
  336. assert(!Error);
  337. }
  338. return Error;
  339. }
  340. int test_packUnorm1x8()
  341. {
  342. int Error = 0;
  343. std::vector<glm::vec1> A;
  344. A.push_back(glm::vec1(1.0f));
  345. A.push_back(glm::vec1(0.5f));
  346. A.push_back(glm::vec1(0.0f));
  347. for(std::size_t i = 0; i < A.size(); ++i)
  348. {
  349. glm::vec1 B(A[i]);
  350. glm::uint8 C = glm::packUnorm1x8(B.x);
  351. glm::vec1 D(glm::unpackUnorm1x8(C));
  352. Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1;
  353. assert(!Error);
  354. }
  355. return Error;
  356. }
  357. int test_packSnorm1x8()
  358. {
  359. int Error = 0;
  360. std::vector<glm::vec1> A;
  361. A.push_back(glm::vec1( 1.0f));
  362. A.push_back(glm::vec1(-0.7f));
  363. A.push_back(glm::vec1(-1.0f));
  364. for(std::size_t i = 0; i < A.size(); ++i)
  365. {
  366. glm::vec1 B(A[i]);
  367. glm::uint8 C = glm::packSnorm1x8(B.x);
  368. glm::vec1 D(glm::unpackSnorm1x8(C));
  369. Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1;
  370. }
  371. return Error;
  372. }
  373. int test_packUnorm2x8()
  374. {
  375. int Error = 0;
  376. std::vector<glm::vec2> A;
  377. A.push_back(glm::vec2(1.0f, 0.7f));
  378. A.push_back(glm::vec2(0.5f, 0.1f));
  379. for(std::size_t i = 0; i < A.size(); ++i)
  380. {
  381. glm::vec2 B(A[i]);
  382. glm::uint16 C = glm::packUnorm2x8(B);
  383. glm::vec2 D = glm::unpackUnorm2x8(C);
  384. Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1;
  385. assert(!Error);
  386. }
  387. return Error;
  388. }
  389. int test_packSnorm2x8()
  390. {
  391. int Error = 0;
  392. std::vector<glm::vec2> A;
  393. A.push_back(glm::vec2( 1.0f, 0.0f));
  394. A.push_back(glm::vec2(-0.7f,-0.1f));
  395. for(std::size_t i = 0; i < A.size(); ++i)
  396. {
  397. glm::vec2 B(A[i]);
  398. glm::uint16 C = glm::packSnorm2x8(B);
  399. glm::vec2 D = glm::unpackSnorm2x8(C);
  400. Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1;
  401. }
  402. return Error;
  403. }
  404. int test_packUnorm4x8()
  405. {
  406. int Error = 0;
  407. std::vector<glm::vec4> A;
  408. A.push_back(glm::vec4(1.0f, 0.7f, 0.3f, 0.0f));
  409. A.push_back(glm::vec4(0.5f, 0.1f, 0.2f, 0.3f));
  410. for(std::size_t i = 0; i < A.size(); ++i)
  411. {
  412. glm::vec4 B(A[i]);
  413. glm::uint32 C = glm::packUnorm4x8(B);
  414. glm::vec4 D = glm::unpackUnorm4x8(C);
  415. Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1;
  416. assert(!Error);
  417. }
  418. return Error;
  419. }
  420. int test_packSnorm4x8()
  421. {
  422. int Error = 0;
  423. std::vector<glm::vec4> A;
  424. A.push_back(glm::vec4( 1.0f, 0.0f,-0.5f,-1.0f));
  425. A.push_back(glm::vec4(-0.7f,-0.1f, 0.1f, 0.7f));
  426. for(std::size_t i = 0; i < A.size(); ++i)
  427. {
  428. glm::vec4 B(A[i]);
  429. glm::uint32 C = glm::packSnorm4x8(B);
  430. glm::vec4 D = glm::unpackSnorm4x8(C);
  431. Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1;
  432. assert(!Error);
  433. }
  434. return Error;
  435. }
  436. int test_packUnorm()
  437. {
  438. int Error = 0;
  439. std::vector<glm::vec2> A;
  440. A.push_back(glm::vec2(1.0f, 0.7f));
  441. A.push_back(glm::vec2(0.5f, 0.1f));
  442. for(std::size_t i = 0; i < A.size(); ++i)
  443. {
  444. glm::vec2 B(A[i]);
  445. glm::u16vec2 C = glm::packUnorm<glm::uint16>(B);
  446. glm::vec2 D = glm::unpackUnorm<float>(C);
  447. Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1;
  448. assert(!Error);
  449. }
  450. return Error;
  451. }
  452. int test_packSnorm()
  453. {
  454. int Error = 0;
  455. std::vector<glm::vec2> A;
  456. A.push_back(glm::vec2( 1.0f, 0.0f));
  457. A.push_back(glm::vec2(-0.5f,-0.7f));
  458. A.push_back(glm::vec2(-0.1f, 0.1f));
  459. for(std::size_t i = 0; i < A.size(); ++i)
  460. {
  461. glm::vec2 B(A[i]);
  462. glm::i16vec2 C = glm::packSnorm<glm::int16>(B);
  463. glm::vec2 D = glm::unpackSnorm<float>(C);
  464. Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
  465. assert(!Error);
  466. }
  467. return Error;
  468. }
  469. int test_packUnorm2x4()
  470. {
  471. int Error = 0;
  472. std::vector<glm::vec2> A;
  473. A.push_back(glm::vec2(1.0f, 0.7f));
  474. A.push_back(glm::vec2(0.5f, 0.0f));
  475. for(std::size_t i = 0; i < A.size(); ++i)
  476. {
  477. glm::vec2 B(A[i]);
  478. glm::uint8 C = glm::packUnorm2x4(B);
  479. glm::vec2 D = glm::unpackUnorm2x4(C);
  480. Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 15.f)) ? 0 : 1;
  481. assert(!Error);
  482. }
  483. return Error;
  484. }
  485. int test_packUnorm4x4()
  486. {
  487. int Error = 0;
  488. std::vector<glm::vec4> A;
  489. A.push_back(glm::vec4(1.0f, 0.7f, 0.5f, 0.0f));
  490. A.push_back(glm::vec4(0.5f, 0.1f, 0.0f, 1.0f));
  491. for(std::size_t i = 0; i < A.size(); ++i)
  492. {
  493. glm::vec4 B(A[i]);
  494. glm::uint16 C = glm::packUnorm4x4(B);
  495. glm::vec4 D = glm::unpackUnorm4x4(C);
  496. Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 15.f)) ? 0 : 1;
  497. assert(!Error);
  498. }
  499. return Error;
  500. }
  501. int test_packUnorm3x5_1x1()
  502. {
  503. int Error = 0;
  504. std::vector<glm::vec4> A;
  505. A.push_back(glm::vec4(1.0f, 0.7f, 0.5f, 0.0f));
  506. A.push_back(glm::vec4(0.5f, 0.1f, 0.0f, 1.0f));
  507. for(std::size_t i = 0; i < A.size(); ++i)
  508. {
  509. glm::vec4 B(A[i]);
  510. glm::uint16 C = glm::packUnorm3x5_1x1(B);
  511. glm::vec4 D = glm::unpackUnorm3x5_1x1(C);
  512. Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 15.f)) ? 0 : 1;
  513. assert(!Error);
  514. }
  515. return Error;
  516. }
  517. int test_packUnorm1x5_1x6_1x5()
  518. {
  519. int Error = 0;
  520. std::vector<glm::vec3> A;
  521. A.push_back(glm::vec3(1.0f, 0.7f, 0.5f));
  522. A.push_back(glm::vec3(0.5f, 0.1f, 0.0f));
  523. for(std::size_t i = 0; i < A.size(); ++i)
  524. {
  525. glm::vec3 B(A[i]);
  526. glm::uint16 C = glm::packUnorm1x5_1x6_1x5(B);
  527. glm::vec3 D = glm::unpackUnorm1x5_1x6_1x5(C);
  528. Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 15.f)) ? 0 : 1;
  529. assert(!Error);
  530. }
  531. return Error;
  532. }
  533. int test_packUnorm2x3_1x2()
  534. {
  535. int Error = 0;
  536. std::vector<glm::vec3> A;
  537. A.push_back(glm::vec3(1.0f, 0.7f, 0.5f));
  538. A.push_back(glm::vec3(0.5f, 0.1f, 0.0f));
  539. for(std::size_t i = 0; i < A.size(); ++i)
  540. {
  541. glm::vec3 B(A[i]);
  542. glm::uint8 C = glm::packUnorm2x3_1x2(B);
  543. glm::vec3 D = glm::unpackUnorm2x3_1x2(C);
  544. Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 3.f)) ? 0 : 1;
  545. assert(!Error);
  546. }
  547. return Error;
  548. }
  549. int test_packUint2x8()
  550. {
  551. int Error = 0;
  552. glm::u8vec2 const Source(1, 2);
  553. glm::uint16 const Packed = glm::packUint2x8(Source);
  554. Error += Packed != 0 ? 0 : 1;
  555. glm::u8vec2 const Unpacked = glm::unpackUint2x8(Packed);
  556. Error += Source == Unpacked ? 0 : 1;
  557. return Error;
  558. }
  559. int test_packUint4x8()
  560. {
  561. int Error = 0;
  562. glm::u8vec4 const Source(1, 2, 3, 4);
  563. glm::uint32 const Packed = glm::packUint4x8(Source);
  564. Error += Packed != 0 ? 0 : 1;
  565. glm::u8vec4 const Unpacked = glm::unpackUint4x8(Packed);
  566. Error += Source == Unpacked ? 0 : 1;
  567. return Error;
  568. }
  569. int test_packUint2x16()
  570. {
  571. int Error = 0;
  572. glm::u16vec2 const Source(1, 2);
  573. glm::uint32 const Packed = glm::packUint2x16(Source);
  574. Error += Packed != 0 ? 0 : 1;
  575. glm::u16vec2 const Unpacked = glm::unpackUint2x16(Packed);
  576. Error += Source == Unpacked ? 0 : 1;
  577. return Error;
  578. }
  579. int test_packUint4x16()
  580. {
  581. int Error = 0;
  582. glm::u16vec4 const Source(1, 2, 3, 4);
  583. glm::uint64 const Packed = glm::packUint4x16(Source);
  584. Error += Packed != 0 ? 0 : 1;
  585. glm::u16vec4 const Unpacked = glm::unpackUint4x16(Packed);
  586. Error += Source == Unpacked ? 0 : 1;
  587. return Error;
  588. }
  589. int test_packUint2x32()
  590. {
  591. int Error = 0;
  592. glm::u32vec2 const Source(1, 2);
  593. glm::uint64 const Packed = glm::packUint2x32(Source);
  594. Error += Packed != 0 ? 0 : 1;
  595. glm::u32vec2 const Unpacked = glm::unpackUint2x32(Packed);
  596. Error += Source == Unpacked ? 0 : 1;
  597. return Error;
  598. }
  599. int test_packInt2x8()
  600. {
  601. int Error = 0;
  602. glm::i8vec2 const Source(1, 2);
  603. glm::int16 const Packed = glm::packInt2x8(Source);
  604. Error += Packed != 0 ? 0 : 1;
  605. glm::i8vec2 const Unpacked = glm::unpackInt2x8(Packed);
  606. Error += Source == Unpacked ? 0 : 1;
  607. return Error;
  608. }
  609. int test_packInt4x8()
  610. {
  611. int Error = 0;
  612. glm::i8vec4 const Source(1, 2, 3, 4);
  613. glm::int32 const Packed = glm::packInt4x8(Source);
  614. Error += Packed != 0 ? 0 : 1;
  615. glm::i8vec4 const Unpacked = glm::unpackInt4x8(Packed);
  616. Error += Source == Unpacked ? 0 : 1;
  617. return Error;
  618. }
  619. int test_packInt2x16()
  620. {
  621. int Error = 0;
  622. glm::i16vec2 const Source(1, 2);
  623. glm::int32 const Packed = glm::packInt2x16(Source);
  624. Error += Packed != 0 ? 0 : 1;
  625. glm::i16vec2 const Unpacked = glm::unpackInt2x16(Packed);
  626. Error += Source == Unpacked ? 0 : 1;
  627. return Error;
  628. }
  629. int test_packInt4x16()
  630. {
  631. int Error = 0;
  632. glm::i16vec4 const Source(1, 2, 3, 4);
  633. glm::int64 const Packed = glm::packInt4x16(Source);
  634. Error += Packed != 0 ? 0 : 1;
  635. glm::i16vec4 const Unpacked = glm::unpackInt4x16(Packed);
  636. Error += Source == Unpacked ? 0 : 1;
  637. return Error;
  638. }
  639. int test_packInt2x32()
  640. {
  641. int Error = 0;
  642. glm::i32vec2 const Source(1, 2);
  643. glm::int64 const Packed = glm::packInt2x32(Source);
  644. Error += Packed != 0 ? 0 : 1;
  645. glm::i32vec2 const Unpacked = glm::unpackInt2x32(Packed);
  646. Error += Source == Unpacked ? 0 : 1;
  647. return Error;
  648. }
  649. int main()
  650. {
  651. int Error = 0;
  652. Error += test_packUnorm();
  653. Error += test_packSnorm();
  654. Error += test_packSnorm1x16();
  655. Error += test_packSnorm2x16();
  656. Error += test_packSnorm4x16();
  657. Error += test_packSnorm1x8();
  658. Error += test_packSnorm2x8();
  659. Error += test_packSnorm4x8();
  660. Error += test_packUnorm1x16();
  661. Error += test_packUnorm2x16();
  662. Error += test_packUnorm4x16();
  663. Error += test_packUnorm1x8();
  664. Error += test_packUnorm2x8();
  665. Error += test_packUnorm4x8();
  666. Error += test_packUnorm2x4();
  667. Error += test_packUnorm4x4();
  668. Error += test_packUnorm3x5_1x1();
  669. Error += test_packUnorm1x5_1x6_1x5();
  670. Error += test_packUnorm2x3_1x2();
  671. Error += test_packUint2x8();
  672. Error += test_packUint4x8();
  673. Error += test_packUint2x16();
  674. Error += test_packUint4x16();
  675. Error += test_packUint2x32();
  676. Error += test_packInt2x8();
  677. Error += test_packInt4x8();
  678. Error += test_packInt2x16();
  679. Error += test_packInt4x16();
  680. Error += test_packInt2x32();
  681. Error += test_F2x11_1x10();
  682. Error += test_F3x9_E1x5();
  683. Error += test_RGBM();
  684. Error += test_Unorm3x10_1x2();
  685. Error += test_Snorm3x10_1x2();
  686. Error += test_I3x10_1x2();
  687. Error += test_U3x10_1x2();
  688. Error += test_Half1x16();
  689. Error += test_Half4x16();
  690. return Error;
  691. }