type_int.hpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /// @ref core
  2. /// @file glm/detail/type_int.hpp
  3. #pragma once
  4. #include "setup.hpp"
  5. #if GLM_HAS_MAKE_SIGNED
  6. # include <type_traits>
  7. #endif
  8. #if GLM_HAS_EXTENDED_INTEGER_TYPE
  9. # include <cstdint>
  10. #endif
  11. namespace glm{
  12. namespace detail
  13. {
  14. # if GLM_HAS_EXTENDED_INTEGER_TYPE
  15. typedef std::int8_t int8;
  16. typedef std::int16_t int16;
  17. typedef std::int32_t int32;
  18. typedef std::int64_t int64;
  19. typedef std::uint8_t uint8;
  20. typedef std::uint16_t uint16;
  21. typedef std::uint32_t uint32;
  22. typedef std::uint64_t uint64;
  23. # else
  24. # if(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) // C99 detected, 64 bit types available
  25. typedef int64_t sint64;
  26. typedef uint64_t uint64;
  27. # elif GLM_COMPILER & GLM_COMPILER_VC
  28. typedef signed __int64 sint64;
  29. typedef unsigned __int64 uint64;
  30. # elif GLM_COMPILER & GLM_COMPILER_GCC
  31. # pragma GCC diagnostic push
  32. # pragma GCC diagnostic ignored "-Wno-long-long"
  33. __extension__ typedef signed long long sint64;
  34. __extension__ typedef unsigned long long uint64;
  35. # pragma GCC diagnostic pop
  36. # elif GLM_COMPILER & GLM_COMPILER_CLANG
  37. # pragma clang diagnostic push
  38. # pragma clang diagnostic ignored "-Wno-c++11-long-long"
  39. typedef signed long long sint64;
  40. typedef unsigned long long uint64;
  41. # pragma clang diagnostic pop
  42. # else//unknown compiler
  43. typedef signed long long sint64;
  44. typedef unsigned long long uint64;
  45. # endif//GLM_COMPILER
  46. typedef signed char int8;
  47. typedef signed short int16;
  48. typedef signed int int32;
  49. typedef sint64 int64;
  50. typedef unsigned char uint8;
  51. typedef unsigned short uint16;
  52. typedef unsigned int uint32;
  53. typedef uint64 uint64;
  54. #endif//
  55. typedef signed int lowp_int_t;
  56. typedef signed int mediump_int_t;
  57. typedef signed int highp_int_t;
  58. typedef unsigned int lowp_uint_t;
  59. typedef unsigned int mediump_uint_t;
  60. typedef unsigned int highp_uint_t;
  61. # if GLM_HAS_MAKE_SIGNED
  62. using std::make_signed;
  63. using std::make_unsigned;
  64. # else//GLM_HAS_MAKE_SIGNED
  65. template <typename genType>
  66. struct make_signed
  67. {};
  68. template <>
  69. struct make_signed<char>
  70. {
  71. typedef char type;
  72. };
  73. template <>
  74. struct make_signed<short>
  75. {
  76. typedef short type;
  77. };
  78. template <>
  79. struct make_signed<int>
  80. {
  81. typedef int type;
  82. };
  83. template <>
  84. struct make_signed<long>
  85. {
  86. typedef long type;
  87. };
  88. template <>
  89. struct make_signed<long long>
  90. {
  91. typedef long long type;
  92. };
  93. template <>
  94. struct make_signed<unsigned char>
  95. {
  96. typedef char type;
  97. };
  98. template <>
  99. struct make_signed<unsigned short>
  100. {
  101. typedef short type;
  102. };
  103. template <>
  104. struct make_signed<unsigned int>
  105. {
  106. typedef int type;
  107. };
  108. template <>
  109. struct make_signed<unsigned long>
  110. {
  111. typedef long type;
  112. };
  113. template <>
  114. struct make_signed<unsigned long long>
  115. {
  116. typedef long long type;
  117. };
  118. template <typename genType>
  119. struct make_unsigned
  120. {};
  121. template <>
  122. struct make_unsigned<char>
  123. {
  124. typedef unsigned char type;
  125. };
  126. template <>
  127. struct make_unsigned<short>
  128. {
  129. typedef unsigned short type;
  130. };
  131. template <>
  132. struct make_unsigned<int>
  133. {
  134. typedef unsigned int type;
  135. };
  136. template <>
  137. struct make_unsigned<long>
  138. {
  139. typedef unsigned long type;
  140. };
  141. template <>
  142. struct make_unsigned<long long>
  143. {
  144. typedef unsigned long long type;
  145. };
  146. template <>
  147. struct make_unsigned<unsigned char>
  148. {
  149. typedef unsigned char type;
  150. };
  151. template <>
  152. struct make_unsigned<unsigned short>
  153. {
  154. typedef unsigned short type;
  155. };
  156. template <>
  157. struct make_unsigned<unsigned int>
  158. {
  159. typedef unsigned int type;
  160. };
  161. template <>
  162. struct make_unsigned<unsigned long>
  163. {
  164. typedef unsigned long type;
  165. };
  166. template <>
  167. struct make_unsigned<unsigned long long>
  168. {
  169. typedef unsigned long long type;
  170. };
  171. # endif//GLM_HAS_MAKE_SIGNED
  172. }//namespace detail
  173. typedef detail::int8 int8;
  174. typedef detail::int16 int16;
  175. typedef detail::int32 int32;
  176. typedef detail::int64 int64;
  177. typedef detail::uint8 uint8;
  178. typedef detail::uint16 uint16;
  179. typedef detail::uint32 uint32;
  180. typedef detail::uint64 uint64;
  181. /// @addtogroup core_precision
  182. /// @{
  183. /// Low precision signed integer.
  184. /// There is no guarantee on the actual precision.
  185. ///
  186. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.3 Integers</a>
  187. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
  188. typedef detail::lowp_int_t lowp_int;
  189. /// Medium precision signed integer.
  190. /// There is no guarantee on the actual precision.
  191. ///
  192. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.3 Integers</a>
  193. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
  194. typedef detail::mediump_int_t mediump_int;
  195. /// High precision signed integer.
  196. /// There is no guarantee on the actual precision.
  197. ///
  198. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.3 Integers</a>
  199. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
  200. typedef detail::highp_int_t highp_int;
  201. /// Low precision unsigned integer.
  202. /// There is no guarantee on the actual precision.
  203. ///
  204. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.3 Integers</a>
  205. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
  206. typedef detail::lowp_uint_t lowp_uint;
  207. /// Medium precision unsigned integer.
  208. /// There is no guarantee on the actual precision.
  209. ///
  210. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.3 Integers</a>
  211. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
  212. typedef detail::mediump_uint_t mediump_uint;
  213. /// High precision unsigned integer.
  214. /// There is no guarantee on the actual precision.
  215. ///
  216. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.3 Integers</a>
  217. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.7.2 Precision Qualifier</a>
  218. typedef detail::highp_uint_t highp_uint;
  219. #if(!defined(GLM_PRECISION_HIGHP_INT) && !defined(GLM_PRECISION_MEDIUMP_INT) && !defined(GLM_PRECISION_LOWP_INT))
  220. typedef mediump_int int_t;
  221. #elif(defined(GLM_PRECISION_HIGHP_INT) && !defined(GLM_PRECISION_MEDIUMP_INT) && !defined(GLM_PRECISION_LOWP_INT))
  222. typedef highp_int int_t;
  223. #elif(!defined(GLM_PRECISION_HIGHP_INT) && defined(GLM_PRECISION_MEDIUMP_INT) && !defined(GLM_PRECISION_LOWP_INT))
  224. typedef mediump_int int_t;
  225. #elif(!defined(GLM_PRECISION_HIGHP_INT) && !defined(GLM_PRECISION_MEDIUMP_INT) && defined(GLM_PRECISION_LOWP_INT))
  226. typedef lowp_int int_t;
  227. #else
  228. # error "GLM error: multiple default precision requested for signed integer types"
  229. #endif
  230. #if(!defined(GLM_PRECISION_HIGHP_UINT) && !defined(GLM_PRECISION_MEDIUMP_UINT) && !defined(GLM_PRECISION_LOWP_UINT))
  231. typedef mediump_uint uint_t;
  232. #elif(defined(GLM_PRECISION_HIGHP_UINT) && !defined(GLM_PRECISION_MEDIUMP_UINT) && !defined(GLM_PRECISION_LOWP_UINT))
  233. typedef highp_uint uint_t;
  234. #elif(!defined(GLM_PRECISION_HIGHP_UINT) && defined(GLM_PRECISION_MEDIUMP_UINT) && !defined(GLM_PRECISION_LOWP_UINT))
  235. typedef mediump_uint uint_t;
  236. #elif(!defined(GLM_PRECISION_HIGHP_UINT) && !defined(GLM_PRECISION_MEDIUMP_UINT) && defined(GLM_PRECISION_LOWP_UINT))
  237. typedef lowp_uint uint_t;
  238. #else
  239. # error "GLM error: multiple default precision requested for unsigned integer types"
  240. #endif
  241. /// Unsigned integer type.
  242. ///
  243. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 4.1.3 Integers</a>
  244. typedef unsigned int uint;
  245. /// @}
  246. ////////////////////
  247. // check type sizes
  248. #ifndef GLM_STATIC_ASSERT_NULL
  249. GLM_STATIC_ASSERT(sizeof(glm::int8) == 1, "int8 size isn't 1 byte on this platform");
  250. GLM_STATIC_ASSERT(sizeof(glm::int16) == 2, "int16 size isn't 2 bytes on this platform");
  251. GLM_STATIC_ASSERT(sizeof(glm::int32) == 4, "int32 size isn't 4 bytes on this platform");
  252. GLM_STATIC_ASSERT(sizeof(glm::int64) == 8, "int64 size isn't 8 bytes on this platform");
  253. GLM_STATIC_ASSERT(sizeof(glm::uint8) == 1, "uint8 size isn't 1 byte on this platform");
  254. GLM_STATIC_ASSERT(sizeof(glm::uint16) == 2, "uint16 size isn't 2 bytes on this platform");
  255. GLM_STATIC_ASSERT(sizeof(glm::uint32) == 4, "uint32 size isn't 4 bytes on this platform");
  256. GLM_STATIC_ASSERT(sizeof(glm::uint64) == 8, "uint64 size isn't 8 bytes on this platform");
  257. #endif//GLM_STATIC_ASSERT_NULL
  258. }//namespace glm