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.

186 lines
7.1 KiB

5 years ago
  1. #define GLM_ENABLE_EXPERIMENTAL
  2. #include <glm/glm.hpp>
  3. #if GLM_LANG & GLM_LANG_CXXMS_FLAG
  4. #include <glm/gtc/type_precision.hpp>
  5. #include <glm/gtx/io.hpp>
  6. #include <iostream>
  7. #include <sstream>
  8. #include <typeinfo>
  9. namespace
  10. {
  11. template<typename CTy, typename CTr>
  12. std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, glm::qualifier const& a)
  13. {
  14. typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
  15. if (cerberus)
  16. {
  17. switch (a) {
  18. case glm::highp: os << "uhi"; break;
  19. case glm::mediump: os << "umd"; break;
  20. case glm::lowp: os << "ulo"; break;
  21. # if GLM_CONFIG_ALIGNED_GENTYPES == GLM_ENABLE
  22. case glm::aligned_highp: os << "ahi"; break;
  23. case glm::aligned_mediump: os << "amd"; break;
  24. case glm::aligned_lowp: os << "alo"; break;
  25. # endif
  26. }
  27. }
  28. return os;
  29. }
  30. template<typename U, glm::qualifier P, typename T, typename CTy, typename CTr>
  31. std::basic_string<CTy> type_name(std::basic_ostream<CTy,CTr>&, T const&)
  32. {
  33. std::basic_ostringstream<CTy,CTr> ostr;
  34. if (typeid(T) == typeid(glm::qua<U,P>)) { ostr << "quat"; }
  35. else if (typeid(T) == typeid(glm::vec<2, U,P>)) { ostr << "vec2"; }
  36. else if (typeid(T) == typeid(glm::vec<3, U,P>)) { ostr << "vec3"; }
  37. else if (typeid(T) == typeid(glm::vec<4, U,P>)) { ostr << "vec4"; }
  38. else if (typeid(T) == typeid(glm::mat<2, 2, U,P>)) { ostr << "mat2x2"; }
  39. else if (typeid(T) == typeid(glm::mat<2, 3, U,P>)) { ostr << "mat2x3"; }
  40. else if (typeid(T) == typeid(glm::mat<2, 4, U,P>)) { ostr << "mat2x4"; }
  41. else if (typeid(T) == typeid(glm::mat<3, 2, U,P>)) { ostr << "mat3x2"; }
  42. else if (typeid(T) == typeid(glm::mat<3, 3, U,P>)) { ostr << "mat3x3"; }
  43. else if (typeid(T) == typeid(glm::mat<3, 4, U,P>)) { ostr << "mat3x4"; }
  44. else if (typeid(T) == typeid(glm::mat<4, 2, U,P>)) { ostr << "mat4x2"; }
  45. else if (typeid(T) == typeid(glm::mat<4, 3, U,P>)) { ostr << "mat4x3"; }
  46. else if (typeid(T) == typeid(glm::mat<4, 4, U,P>)) { ostr << "mat4x4"; }
  47. else { ostr << "unknown"; }
  48. ostr << '<' << typeid(U).name() << ',' << P << '>';
  49. return ostr.str();
  50. }
  51. } // namespace {
  52. template<typename T, glm::qualifier P, typename OS>
  53. int test_io_quat(OS& os)
  54. {
  55. os << '\n' << typeid(OS).name() << '\n';
  56. glm::qua<T, P> const q(1, 0, 0, 0);
  57. {
  58. glm::io::basic_format_saver<typename OS::char_type> const iofs(os);
  59. os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2)
  60. << type_name<T, P>(os, q) << ": " << q << '\n';
  61. }
  62. {
  63. glm::io::basic_format_saver<typename OS::char_type> const iofs(os);
  64. os << glm::io::unformatted
  65. << type_name<T, P>(os, q) << ": " << q << '\n';
  66. }
  67. return 0;
  68. }
  69. template<typename T, glm::qualifier P, typename OS>
  70. int test_io_vec(OS& os)
  71. {
  72. os << '\n' << typeid(OS).name() << '\n';
  73. glm::vec<2, T,P> const v2(0, 1);
  74. glm::vec<3, T,P> const v3(2, 3, 4);
  75. glm::vec<4, T,P> const v4(5, 6, 7, 8);
  76. os << type_name<T,P>(os, v2) << ": " << v2 << '\n'
  77. << type_name<T,P>(os, v3) << ": " << v3 << '\n'
  78. << type_name<T,P>(os, v4) << ": " << v4 << '\n';
  79. glm::io::basic_format_saver<typename OS::char_type> const iofs(os);
  80. os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2)
  81. << type_name<T,P>(os, v2) << ": " << v2 << '\n'
  82. << type_name<T,P>(os, v3) << ": " << v3 << '\n'
  83. << type_name<T,P>(os, v4) << ": " << v4 << '\n';
  84. return 0;
  85. }
  86. template<typename T, glm::qualifier P, typename OS>
  87. int test_io_mat(OS& os, glm::io::order_type otype)
  88. {
  89. os << '\n' << typeid(OS).name() << '\n';
  90. glm::vec<2, T,P> const v2_1( 0, 1);
  91. glm::vec<2, T,P> const v2_2( 2, 3);
  92. glm::vec<2, T,P> const v2_3( 4, 5);
  93. glm::vec<2, T,P> const v2_4( 6, 7);
  94. glm::vec<3, T,P> const v3_1( 8, 9, 10);
  95. glm::vec<3, T,P> const v3_2(11, 12, 13);
  96. glm::vec<3, T,P> const v3_3(14, 15, 16);
  97. glm::vec<3, T,P> const v3_4(17, 18, 19);
  98. glm::vec<4, T,P> const v4_1(20, 21, 22, 23);
  99. glm::vec<4, T,P> const v4_2(24, 25, 26, 27);
  100. glm::vec<4, T,P> const v4_3(28, 29, 30, 31);
  101. glm::vec<4, T,P> const v4_4(32, 33, 34, 35);
  102. glm::io::basic_format_saver<typename OS::char_type> const iofs(os);
  103. os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2)
  104. << glm::io::order(otype)
  105. << "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::mat<2, 2, T,P>(v2_1, v2_2) << '\n'
  106. << "mat2x3<" << typeid(T).name() << ',' << P << ">: " << glm::mat<2, 3, T,P>(v3_1, v3_2) << '\n'
  107. << "mat2x4<" << typeid(T).name() << ',' << P << ">: " << glm::mat<2, 4, T,P>(v4_1, v4_2) << '\n'
  108. << "mat3x2<" << typeid(T).name() << ',' << P << ">: " << glm::mat<3, 2, T,P>(v2_1, v2_2, v2_3) << '\n'
  109. << "mat3x3<" << typeid(T).name() << ',' << P << ">: " << glm::mat<3, 3, T,P>(v3_1, v3_2, v3_3) << '\n'
  110. << "mat3x4<" << typeid(T).name() << ',' << P << ">: " << glm::mat<3, 4, T,P>(v4_1, v4_2, v4_3) << '\n'
  111. << "mat4x2<" << typeid(T).name() << ',' << P << ">: " << glm::mat<4, 2, T,P>(v2_1, v2_2, v2_3, v2_4) << '\n'
  112. << "mat4x3<" << typeid(T).name() << ',' << P << ">: " << glm::mat<4, 3, T,P>(v3_1, v3_2, v3_3, v3_4) << '\n'
  113. << "mat4x4<" << typeid(T).name() << ',' << P << ">: " << glm::mat<4, 4, T,P>(v4_1, v4_2, v4_3, v4_4) << '\n';
  114. os << glm::io::unformatted
  115. << glm::io::order(otype)
  116. << "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::mat<2, 2, T,P>(v2_1, v2_2) << '\n'
  117. << "mat2x3<" << typeid(T).name() << ',' << P << ">: " << glm::mat<2, 3, T,P>(v3_1, v3_2) << '\n'
  118. << "mat2x4<" << typeid(T).name() << ',' << P << ">: " << glm::mat<2, 4, T,P>(v4_1, v4_2) << '\n'
  119. << "mat3x2<" << typeid(T).name() << ',' << P << ">: " << glm::mat<3, 2, T,P>(v2_1, v2_2, v2_3) << '\n'
  120. << "mat3x3<" << typeid(T).name() << ',' << P << ">: " << glm::mat<3, 3, T,P>(v3_1, v3_2, v3_3) << '\n'
  121. << "mat3x4<" << typeid(T).name() << ',' << P << ">: " << glm::mat<3, 4, T,P>(v4_1, v4_2, v4_3) << '\n'
  122. << "mat4x2<" << typeid(T).name() << ',' << P << ">: " << glm::mat<4, 2, T,P>(v2_1, v2_2, v2_3, v2_4) << '\n'
  123. << "mat4x3<" << typeid(T).name() << ',' << P << ">: " << glm::mat<4, 3, T,P>(v3_1, v3_2, v3_3, v3_4) << '\n'
  124. << "mat4x4<" << typeid(T).name() << ',' << P << ">: " << glm::mat<4, 4, T,P>(v4_1, v4_2, v4_3, v4_4) << '\n';
  125. return 0;
  126. }
  127. int main()
  128. {
  129. int Error(0);
  130. Error += test_io_quat<float, glm::highp>(std::cout);
  131. Error += test_io_quat<float, glm::highp>(std::wcout);
  132. Error += test_io_quat<int, glm::mediump>(std::cout);
  133. Error += test_io_quat<int, glm::mediump>(std::wcout);
  134. Error += test_io_quat<glm::uint, glm::lowp>(std::cout);
  135. Error += test_io_quat<glm::uint, glm::lowp>(std::wcout);
  136. Error += test_io_vec<float, glm::highp>(std::cout);
  137. Error += test_io_vec<float, glm::highp>(std::wcout);
  138. Error += test_io_vec<int, glm::mediump>(std::cout);
  139. Error += test_io_vec<int, glm::mediump>(std::wcout);
  140. Error += test_io_vec<glm::uint, glm::lowp>(std::cout);
  141. Error += test_io_vec<glm::uint, glm::lowp>(std::wcout);
  142. Error += test_io_mat<float, glm::highp>(std::cout, glm::io::column_major);
  143. Error += test_io_mat<float, glm::lowp>(std::wcout, glm::io::column_major);
  144. Error += test_io_mat<float, glm::highp>(std::cout, glm::io::row_major);
  145. Error += test_io_mat<float, glm::lowp>(std::wcout, glm::io::row_major);
  146. return Error;
  147. }
  148. #else
  149. int main()
  150. {
  151. return 0;
  152. }
  153. #endif// GLM_LANG & GLM_LANG_CXXMS_FLAG