core_func_packing.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2011-01-15
  5. // Updated : 2011-09-13
  6. // Licence : This source is under MIT licence
  7. // File : test/core/func_packing.cpp
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. #include <glm/glm.hpp>
  10. #include <glm/gtc/half_float.hpp>
  11. #include <vector>
  12. int test_packHalf2x16()
  13. {
  14. int Error = 0;
  15. std::vector<glm::hvec2> A;
  16. A.push_back(glm::hvec2(glm::half( 1.0f), glm::half( 2.0f)));
  17. A.push_back(glm::hvec2(glm::half(-1.0f), glm::half(-2.0f)));
  18. A.push_back(glm::hvec2(glm::half(-1.1f), glm::half( 1.1f)));
  19. for(std::size_t i = 0; i < A.size(); ++i)
  20. {
  21. glm::vec2 B(A[i]);
  22. glm::uint C = glm::packHalf2x16(B);
  23. glm::vec2 D = glm::unpackHalf2x16(C);
  24. Error += B == D ? 0 : 1;
  25. }
  26. return Error;
  27. }
  28. int main()
  29. {
  30. int Error = 0;
  31. Error += test_packHalf2x16();
  32. return Error;
  33. }