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.

482 lines
10 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  5. /// Permission is hereby granted, free of charge, to any person obtaining a copy
  6. /// of this software and associated documentation files (the "Software"), to deal
  7. /// in the Software without restriction, including without limitation the rights
  8. /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. /// copies of the Software, and to permit persons to whom the Software is
  10. /// furnished to do so, subject to the following conditions:
  11. ///
  12. /// The above copyright notice and this permission notice shall be included in
  13. /// all copies or substantial portions of the Software.
  14. ///
  15. /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. /// THE SOFTWARE.
  22. ///
  23. /// @ref core
  24. /// @file glm/core/_detail.hpp
  25. /// @date 2008-07-24 / 2011-06-14
  26. /// @author Christophe Riccio
  27. ///////////////////////////////////////////////////////////////////////////////////
  28. #ifndef glm_core_detail
  29. #define glm_core_detail
  30. #include "setup.hpp"
  31. #include <cassert>
  32. #if(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
  33. #include <cstdint>
  34. #endif
  35. namespace glm{
  36. namespace detail
  37. {
  38. class half;
  39. #if(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) // C99 detected, 64 bit types available
  40. typedef int64_t sint64;
  41. typedef uint64_t uint64;
  42. #elif(GLM_COMPILER & GLM_COMPILER_VC)
  43. typedef signed __int64 sint64;
  44. typedef unsigned __int64 uint64;
  45. #elif(GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_LLVM_GCC | GLM_COMPILER_CLANG))
  46. __extension__ typedef signed long long sint64;
  47. __extension__ typedef unsigned long long uint64;
  48. #elif(GLM_COMPILER & GLM_COMPILER_BC)
  49. typedef Int64 sint64;
  50. typedef Uint64 uint64;
  51. #else//unknown compiler
  52. typedef signed long long sint64;
  53. typedef unsigned long long uint64;
  54. #endif//GLM_COMPILER
  55. template<bool C>
  56. struct If
  57. {
  58. template<typename F, typename T>
  59. static GLM_FUNC_QUALIFIER T apply(F functor, const T& val)
  60. {
  61. return functor(val);
  62. }
  63. };
  64. template<>
  65. struct If<false>
  66. {
  67. template<typename F, typename T>
  68. static GLM_FUNC_QUALIFIER T apply(F, const T& val)
  69. {
  70. return val;
  71. }
  72. };
  73. //template <typename T>
  74. //struct traits
  75. //{
  76. // static const bool is_signed = false;
  77. // static const bool is_float = false;
  78. // static const bool is_vector = false;
  79. // static const bool is_matrix = false;
  80. // static const bool is_genType = false;
  81. // static const bool is_genIType = false;
  82. // static const bool is_genUType = false;
  83. //};
  84. //template <>
  85. //struct traits<half>
  86. //{
  87. // static const bool is_float = true;
  88. // static const bool is_genType = true;
  89. //};
  90. //template <>
  91. //struct traits<float>
  92. //{
  93. // static const bool is_float = true;
  94. // static const bool is_genType = true;
  95. //};
  96. //template <>
  97. //struct traits<double>
  98. //{
  99. // static const bool is_float = true;
  100. // static const bool is_genType = true;
  101. //};
  102. //template <typename genType>
  103. //struct desc
  104. //{
  105. // typedef genType type;
  106. // typedef genType * pointer;
  107. // typedef genType const* const_pointer;
  108. // typedef genType const *const const_pointer_const;
  109. // typedef genType *const pointer_const;
  110. // typedef genType & reference;
  111. // typedef genType const& const_reference;
  112. // typedef genType const& param_type;
  113. // typedef typename genType::value_type value_type;
  114. // typedef typename genType::size_type size_type;
  115. // static const typename size_type value_size;
  116. //};
  117. //template <typename genType>
  118. //const typename desc<genType>::size_type desc<genType>::value_size = genType::value_size();
  119. union uif32
  120. {
  121. GLM_FUNC_QUALIFIER uif32() :
  122. i(0)
  123. {}
  124. GLM_FUNC_QUALIFIER uif32(float f) :
  125. f(f)
  126. {}
  127. GLM_FUNC_QUALIFIER uif32(unsigned int i) :
  128. i(i)
  129. {}
  130. float f;
  131. unsigned int i;
  132. };
  133. union uif64
  134. {
  135. GLM_FUNC_QUALIFIER uif64() :
  136. i(0)
  137. {}
  138. GLM_FUNC_QUALIFIER uif64(double f) :
  139. f(f)
  140. {}
  141. GLM_FUNC_QUALIFIER uif64(uint64 i) :
  142. i(i)
  143. {}
  144. double f;
  145. uint64 i;
  146. };
  147. typedef uif32 uif;
  148. //////////////////
  149. // int
  150. template <typename T>
  151. struct is_int
  152. {
  153. enum is_int_enum
  154. {
  155. _YES = 0,
  156. _NO = 1
  157. };
  158. };
  159. #define GLM_DETAIL_IS_INT(T) \
  160. template <> \
  161. struct is_int<T> \
  162. { \
  163. enum is_int_enum \
  164. { \
  165. _YES = 1, \
  166. _NO = 0 \
  167. }; \
  168. }
  169. //////////////////
  170. // uint
  171. template <typename T>
  172. struct is_uint
  173. {
  174. enum is_uint_enum
  175. {
  176. _YES = 0,
  177. _NO = 1
  178. };
  179. };
  180. #define GLM_DETAIL_IS_UINT(T) \
  181. template <> \
  182. struct is_uint<T> \
  183. { \
  184. enum is_uint_enum \
  185. { \
  186. _YES = 1, \
  187. _NO = 0 \
  188. }; \
  189. }
  190. //GLM_DETAIL_IS_UINT(unsigned long long)
  191. //////////////////
  192. // float
  193. template <typename T>
  194. struct is_float
  195. {
  196. enum is_float_enum
  197. {
  198. _YES = 0,
  199. _NO = 1
  200. };
  201. };
  202. #define GLM_DETAIL_IS_FLOAT(T) \
  203. template <> \
  204. struct is_float<T> \
  205. { \
  206. enum is_float_enum \
  207. { \
  208. _YES = 1, \
  209. _NO = 0 \
  210. }; \
  211. }
  212. GLM_DETAIL_IS_FLOAT(detail::half);
  213. GLM_DETAIL_IS_FLOAT(float);
  214. GLM_DETAIL_IS_FLOAT(double);
  215. GLM_DETAIL_IS_FLOAT(long double);
  216. //////////////////
  217. // bool
  218. template <typename T>
  219. struct is_bool
  220. {
  221. enum is_bool_enum
  222. {
  223. _YES = 0,
  224. _NO = 1
  225. };
  226. };
  227. template <>
  228. struct is_bool<bool>
  229. {
  230. enum is_bool_enum
  231. {
  232. _YES = 1,
  233. _NO = 0
  234. };
  235. };
  236. //////////////////
  237. // vector
  238. template <typename T>
  239. struct is_vector
  240. {
  241. enum is_vector_enum
  242. {
  243. _YES = 0,
  244. _NO = 1
  245. };
  246. };
  247. # define GLM_DETAIL_IS_VECTOR(TYPE) \
  248. template <typename T> \
  249. struct is_vector<TYPE<T> > \
  250. { \
  251. enum is_vector_enum \
  252. { \
  253. _YES = 1, \
  254. _NO = 0 \
  255. }; \
  256. }
  257. //////////////////
  258. // matrix
  259. template <typename T>
  260. struct is_matrix
  261. {
  262. enum is_matrix_enum
  263. {
  264. _YES = 0,
  265. _NO = 1
  266. };
  267. };
  268. #define GLM_DETAIL_IS_MATRIX(T) \
  269. template <> \
  270. struct is_matrix \
  271. { \
  272. enum is_matrix_enum \
  273. { \
  274. _YES = 1, \
  275. _NO = 0 \
  276. }; \
  277. }
  278. //////////////////
  279. // type
  280. template <typename T>
  281. struct type
  282. {
  283. enum type_enum
  284. {
  285. is_float = is_float<T>::_YES,
  286. is_int = is_int<T>::_YES,
  287. is_uint = is_uint<T>::_YES,
  288. is_bool = is_bool<T>::_YES
  289. };
  290. };
  291. //////////////////
  292. // type
  293. typedef signed char int8;
  294. typedef signed short int16;
  295. typedef signed int int32;
  296. typedef detail::sint64 int64;
  297. typedef unsigned char uint8;
  298. typedef unsigned short uint16;
  299. typedef unsigned int uint32;
  300. typedef detail::uint64 uint64;
  301. typedef detail::half float16;
  302. typedef float float32;
  303. typedef double float64;
  304. //////////////////
  305. // float_or_int_trait
  306. struct float_or_int_value
  307. {
  308. enum
  309. {
  310. GLM_ERROR,
  311. GLM_FLOAT,
  312. GLM_INT
  313. };
  314. };
  315. template <typename T>
  316. struct float_or_int_trait
  317. {
  318. enum{ID = float_or_int_value::GLM_ERROR};
  319. };
  320. template <>
  321. struct float_or_int_trait<int8>
  322. {
  323. enum{ID = float_or_int_value::GLM_INT};
  324. };
  325. template <>
  326. struct float_or_int_trait<int16>
  327. {
  328. enum{ID = float_or_int_value::GLM_INT};
  329. };
  330. template <>
  331. struct float_or_int_trait<int32>
  332. {
  333. enum{ID = float_or_int_value::GLM_INT};
  334. };
  335. template <>
  336. struct float_or_int_trait<int64>
  337. {
  338. enum{ID = float_or_int_value::GLM_INT};
  339. };
  340. template <>
  341. struct float_or_int_trait<uint8>
  342. {
  343. enum{ID = float_or_int_value::GLM_INT};
  344. };
  345. template <>
  346. struct float_or_int_trait<uint16>
  347. {
  348. enum{ID = float_or_int_value::GLM_INT};
  349. };
  350. template <>
  351. struct float_or_int_trait<uint32>
  352. {
  353. enum{ID = float_or_int_value::GLM_INT};
  354. };
  355. template <>
  356. struct float_or_int_trait<uint64>
  357. {
  358. enum{ID = float_or_int_value::GLM_INT};
  359. };
  360. template <>
  361. struct float_or_int_trait<float16>
  362. {
  363. enum{ID = float_or_int_value::GLM_FLOAT};
  364. };
  365. template <>
  366. struct float_or_int_trait<float32>
  367. {
  368. enum{ID = float_or_int_value::GLM_FLOAT};
  369. };
  370. template <>
  371. struct float_or_int_trait<float64>
  372. {
  373. enum{ID = float_or_int_value::GLM_FLOAT};
  374. };
  375. }//namespace detail
  376. }//namespace glm
  377. #if((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC2005))
  378. # define GLM_DEPRECATED __declspec(deprecated)
  379. # define GLM_ALIGN(x) __declspec(align(x))
  380. # define GLM_ALIGNED_STRUCT(x) __declspec(align(x)) struct
  381. # define GLM_RESTRICT __declspec(restrict)
  382. # define GLM_RESTRICT_VAR __restrict
  383. # define GLM_CONSTEXPR
  384. #elif(GLM_COMPILER & GLM_COMPILER_INTEL)
  385. # define GLM_DEPRECATED
  386. # define GLM_ALIGN(x) __declspec(align(x))
  387. # define GLM_ALIGNED_STRUCT(x) __declspec(align(x)) struct
  388. # define GLM_RESTRICT
  389. # define GLM_RESTRICT_VAR __restrict
  390. # define GLM_CONSTEXPR
  391. #elif(((GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_LLVM_GCC)) && (GLM_COMPILER >= GLM_COMPILER_GCC31)) || (GLM_COMPILER & GLM_COMPILER_CLANG))
  392. # define GLM_DEPRECATED __attribute__((__deprecated__))
  393. # define GLM_ALIGN(x) __attribute__((aligned(x)))
  394. # define GLM_ALIGNED_STRUCT(x) struct __attribute__((aligned(x)))
  395. # if(GLM_COMPILER >= GLM_COMPILER_GCC33)
  396. # define GLM_RESTRICT __restrict__
  397. # define GLM_RESTRICT_VAR __restrict__
  398. # else
  399. # define GLM_RESTRICT
  400. # define GLM_RESTRICT_VAR
  401. # endif
  402. # define GLM_RESTRICT __restrict__
  403. # define GLM_RESTRICT_VAR __restrict__
  404. # if((GLM_COMPILER >= GLM_COMPILER_GCC47) && ((GLM_LANG & GLM_LANG_CXX0X) == GLM_LANG_CXX0X))
  405. # define GLM_CONSTEXPR constexpr
  406. # else
  407. # define GLM_CONSTEXPR
  408. # endif
  409. #else
  410. # define GLM_DEPRECATED
  411. # define GLM_ALIGN
  412. # define GLM_ALIGNED_STRUCT(x)
  413. # define GLM_RESTRICT
  414. # define GLM_RESTRICT_VAR
  415. # define GLM_CONSTEXPR
  416. #endif//GLM_COMPILER
  417. #endif//glm_core_detail