core_cpp_constexpr.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. #include <glm/glm.hpp>
  2. #include <glm/ext.hpp>
  3. #if GLM_HAS_CONSTEXPR
  4. #include <glm/gtc/constants.hpp>
  5. #include <glm/gtc/quaternion.hpp>
  6. #include <glm/ext/vector_relational.hpp>
  7. #include <glm/ext/vector_int1.hpp>
  8. #include <glm/ext/vector_bool1.hpp>
  9. #include <glm/ext/vector_bool4.hpp>
  10. #include <glm/ext/vector_float1.hpp>
  11. #include <glm/vector_relational.hpp>
  12. static int test_vec1()
  13. {
  14. int Error = 0;
  15. {
  16. constexpr glm::bvec1 B(true);
  17. constexpr bool A = glm::all(B);
  18. static_assert(A, "GLM: Failed constexpr");
  19. constexpr glm::bvec1 D(true);
  20. constexpr bool C = glm::any(D);
  21. static_assert(C, "GLM: Failed constexpr");
  22. }
  23. {
  24. constexpr glm::bvec2 C(true);
  25. constexpr glm::bvec2 B(true);
  26. static_assert(glm::any(glm::equal(C, B)), "GLM: Failed constexpr");
  27. }
  28. {
  29. constexpr glm::ivec1 O(glm::ivec1(1));
  30. static_assert(glm::ivec1(1) == O, "GLM: Failed constexpr");
  31. constexpr glm::ivec1 P(1);
  32. static_assert(glm::ivec1(1) == P, "GLM: Failed constexpr");
  33. }
  34. {
  35. constexpr glm::ivec1 L(glm::ivec2(1, 2));
  36. static_assert(glm::ivec1(1) == L, "GLM: Failed constexpr");
  37. constexpr glm::ivec1 M(glm::ivec3(1, 2, 3));
  38. static_assert(glm::ivec1(1) == M, "GLM: Failed constexpr");
  39. constexpr glm::ivec1 N(glm::ivec4(1, 2, 3, 4));
  40. static_assert(glm::ivec1(1) == N, "GLM: Failed constexpr");
  41. }
  42. {
  43. constexpr glm::ivec1 A(1);
  44. static_assert(A[0] == 1, "GLM: Failed constexpr");
  45. static_assert(glm::vec1(1.0f).x > 0.0f, "GLM: Failed constexpr");
  46. static_assert(glm::vec1::length() == 1, "GLM: Failed constexpr");
  47. }
  48. {
  49. constexpr glm::bvec1 A1(true);
  50. constexpr glm::bvec1 A2(true);
  51. constexpr glm::bvec1 B1(false);
  52. constexpr glm::bvec1 B2(false);
  53. static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr");
  54. static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr");
  55. }
  56. {
  57. constexpr glm::ivec1 A(1);
  58. constexpr glm::ivec1 B = A + 1;
  59. constexpr glm::ivec1 C(3);
  60. static_assert(A + B == C, "GLM: Failed constexpr");
  61. constexpr glm::ivec1 D = +A;
  62. static_assert(D == A, "GLM: Failed constexpr");
  63. }
  64. {
  65. constexpr glm::ivec1 A(3);
  66. constexpr glm::ivec1 B = A - 1;
  67. constexpr glm::ivec1 C(1);
  68. static_assert(A - B == C, "GLM: Failed constexpr");
  69. constexpr glm::ivec1 D = -A;
  70. static_assert(-D == A, "GLM: Failed constexpr");
  71. }
  72. {
  73. constexpr glm::ivec1 A(3);
  74. constexpr glm::ivec1 B = A * 1;
  75. static_assert(A == B, "GLM: Failed constexpr");
  76. constexpr glm::ivec1 C(1);
  77. static_assert(B * C == A, "GLM: Failed constexpr");
  78. }
  79. {
  80. constexpr glm::ivec1 A(3);
  81. constexpr glm::ivec1 B = A / 1;
  82. static_assert(A == B, "GLM: Failed constexpr");
  83. constexpr glm::ivec1 C(1);
  84. static_assert(B / C == A, "GLM: Failed constexpr");
  85. }
  86. {
  87. constexpr glm::ivec1 A(3);
  88. constexpr glm::ivec1 B = A % 2;
  89. constexpr glm::ivec1 C(1);
  90. static_assert(B == C, "GLM: Failed constexpr");
  91. constexpr glm::ivec1 D(2);
  92. static_assert(A % D == C, "GLM: Failed constexpr");
  93. }
  94. {
  95. constexpr glm::ivec1 A(1);
  96. constexpr glm::ivec1 B = A & 1;
  97. static_assert(A == B, "GLM: Failed constexpr");
  98. constexpr glm::ivec1 C(1);
  99. static_assert(A == (A & C), "GLM: Failed constexpr");
  100. }
  101. {
  102. constexpr glm::ivec1 A(1);
  103. constexpr glm::ivec1 B = A | 1;
  104. static_assert(A == B, "GLM: Failed constexpr");
  105. constexpr glm::ivec1 C(1);
  106. static_assert(A == (A | C), "GLM: Failed constexpr");
  107. }
  108. {
  109. constexpr glm::ivec1 A(1);
  110. constexpr glm::ivec1 B = A ^ 0;
  111. static_assert(A == B, "GLM: Failed constexpr");
  112. constexpr glm::ivec1 C(0);
  113. static_assert(A == (A ^ C), "GLM: Failed constexpr");
  114. }
  115. {
  116. constexpr glm::ivec1 A(1);
  117. constexpr glm::ivec1 B = A << 1;
  118. static_assert(B == glm::ivec1(2), "GLM: Failed constexpr");
  119. constexpr glm::ivec1 C(1);
  120. static_assert(B == (A << C), "GLM: Failed constexpr");
  121. }
  122. {
  123. constexpr glm::ivec1 A(2);
  124. constexpr glm::ivec1 B = A >> 1;
  125. static_assert(B == glm::ivec1(1), "GLM: Failed constexpr");
  126. constexpr glm::ivec1 C(1);
  127. static_assert(B == A >> C, "GLM: Failed constexpr");
  128. }
  129. {
  130. constexpr glm::ivec1 A(~0);
  131. constexpr glm::ivec1 B = ~A;
  132. static_assert(A == ~B, "GLM: Failed constexpr");
  133. }
  134. return Error;
  135. }
  136. static int test_vec2()
  137. {
  138. int Error = 0;
  139. {
  140. constexpr glm::bvec2 B(true);
  141. constexpr bool A = glm::all(B);
  142. static_assert(A, "GLM: Failed constexpr");
  143. constexpr glm::bvec2 D(true, false);
  144. constexpr bool C = glm::any(D);
  145. static_assert(C, "GLM: Failed constexpr");
  146. }
  147. {
  148. constexpr glm::bvec2 C(true);
  149. constexpr glm::bvec2 B(true, false);
  150. static_assert(glm::any(glm::equal(C, B)), "GLM: Failed constexpr");
  151. }
  152. {
  153. constexpr glm::ivec2 O(glm::ivec1(1));
  154. static_assert(glm::ivec2(1) == O, "GLM: Failed constexpr");
  155. constexpr glm::ivec2 A(1);
  156. static_assert(glm::ivec2(1) == A, "GLM: Failed constexpr");
  157. }
  158. {
  159. constexpr glm::ivec2 F(glm::ivec1(1), glm::ivec1(2));
  160. static_assert(glm::ivec2(1, 2) == F, "GLM: Failed constexpr");
  161. constexpr glm::ivec2 G(1, glm::ivec1(2));
  162. static_assert(glm::ivec2(1, 2) == G, "GLM: Failed constexpr");
  163. constexpr glm::ivec2 H(glm::ivec1(1), 2);
  164. static_assert(glm::ivec2(1, 2) == H, "GLM: Failed constexpr");
  165. constexpr glm::ivec2 I(1, 2);
  166. static_assert(glm::ivec2(1, 2) == I, "GLM: Failed constexpr");
  167. }
  168. {
  169. constexpr glm::ivec2 L(glm::ivec2(1, 2));
  170. static_assert(glm::ivec2(1, 2) == L, "GLM: Failed constexpr");
  171. constexpr glm::ivec2 M(glm::ivec3(1, 2, 3));
  172. static_assert(glm::ivec2(1, 2) == M, "GLM: Failed constexpr");
  173. constexpr glm::ivec2 N(glm::ivec4(1, 2, 3, 4));
  174. static_assert(glm::ivec2(1, 2) == N, "GLM: Failed constexpr");
  175. }
  176. {
  177. constexpr glm::ivec2 A(1);
  178. static_assert(A[0] == 1, "GLM: Failed constexpr");
  179. static_assert(glm::vec2(1.0f).x > 0.0f, "GLM: Failed constexpr");
  180. static_assert(glm::vec2(1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr");
  181. static_assert(glm::vec2(1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr");
  182. static_assert(glm::vec2::length() == 2, "GLM: Failed constexpr");
  183. }
  184. {
  185. constexpr glm::bvec2 A1(true);
  186. constexpr glm::bvec2 A2(true);
  187. constexpr glm::bvec2 B1(false);
  188. constexpr glm::bvec2 B2(false);
  189. static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr");
  190. static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr");
  191. }
  192. {
  193. constexpr glm::ivec2 A(1);
  194. constexpr glm::ivec2 B = A + 1;
  195. constexpr glm::ivec2 C(3);
  196. static_assert(A + B == C, "GLM: Failed constexpr");
  197. constexpr glm::ivec2 D = +A;
  198. static_assert(D == A, "GLM: Failed constexpr");
  199. }
  200. {
  201. constexpr glm::ivec2 A(3);
  202. constexpr glm::ivec2 B = A - 1;
  203. constexpr glm::ivec2 C(1);
  204. static_assert(A - B == C, "GLM: Failed constexpr");
  205. constexpr glm::ivec2 D = -A;
  206. static_assert(-D == A, "GLM: Failed constexpr");
  207. }
  208. {
  209. constexpr glm::ivec2 A(3);
  210. constexpr glm::ivec2 B = A * 1;
  211. static_assert(A == B, "GLM: Failed constexpr");
  212. constexpr glm::ivec2 C(1);
  213. static_assert(B * C == A, "GLM: Failed constexpr");
  214. }
  215. {
  216. constexpr glm::ivec2 A(3);
  217. constexpr glm::ivec2 B = A / 1;
  218. static_assert(A == B, "GLM: Failed constexpr");
  219. constexpr glm::ivec2 C(1);
  220. static_assert(B / C == A, "GLM: Failed constexpr");
  221. }
  222. {
  223. constexpr glm::ivec2 A(3);
  224. constexpr glm::ivec2 B = A % 2;
  225. constexpr glm::ivec2 C(1);
  226. static_assert(B == C, "GLM: Failed constexpr");
  227. constexpr glm::ivec1 D(2);
  228. static_assert(A % D == C, "GLM: Failed constexpr");
  229. }
  230. {
  231. constexpr glm::ivec2 A(1);
  232. constexpr glm::ivec2 B = A & 1;
  233. static_assert(A == B, "GLM: Failed constexpr");
  234. constexpr glm::ivec1 C(1);
  235. static_assert(A == (A & C), "GLM: Failed constexpr");
  236. }
  237. {
  238. constexpr glm::ivec2 A(1);
  239. constexpr glm::ivec2 B = A | 1;
  240. static_assert(A == B, "GLM: Failed constexpr");
  241. constexpr glm::ivec1 C(1);
  242. static_assert(A == (A | C), "GLM: Failed constexpr");
  243. }
  244. {
  245. constexpr glm::ivec2 A(1);
  246. constexpr glm::ivec2 B = A ^ 0;
  247. static_assert(A == B, "GLM: Failed constexpr");
  248. constexpr glm::ivec1 C(0);
  249. static_assert(A == (A ^ C), "GLM: Failed constexpr");
  250. }
  251. {
  252. constexpr glm::ivec2 A(1);
  253. constexpr glm::ivec2 B = A << 1;
  254. static_assert(B == glm::ivec2(2), "GLM: Failed constexpr");
  255. constexpr glm::ivec1 C(1);
  256. static_assert(B == (A << C), "GLM: Failed constexpr");
  257. }
  258. {
  259. constexpr glm::ivec2 A(2);
  260. constexpr glm::ivec2 B = A >> 1;
  261. static_assert(B == glm::ivec2(1), "GLM: Failed constexpr");
  262. constexpr glm::ivec1 C(1);
  263. static_assert(B == A >> C, "GLM: Failed constexpr");
  264. }
  265. {
  266. constexpr glm::ivec2 A(~0);
  267. constexpr glm::ivec2 B = ~A;
  268. static_assert(A == ~B, "GLM: Failed constexpr");
  269. }
  270. return Error;
  271. }
  272. static int test_vec3()
  273. {
  274. int Error = 0;
  275. {
  276. constexpr glm::bvec3 B(true);
  277. constexpr bool A = glm::all(B);
  278. static_assert(A, "GLM: Failed constexpr");
  279. constexpr glm::bvec3 D(true, false, true);
  280. constexpr bool C = glm::any(D);
  281. static_assert(C, "GLM: Failed constexpr");
  282. }
  283. {
  284. constexpr glm::bvec3 C(true);
  285. constexpr glm::bvec3 B(true, false, true);
  286. static_assert(glm::any(glm::equal(C, B)), "GLM: Failed constexpr");
  287. }
  288. {
  289. constexpr glm::ivec3 O(glm::ivec1(1));
  290. static_assert(glm::ivec3(1) == O, "GLM: Failed constexpr");
  291. constexpr glm::ivec3 A(1);
  292. static_assert(glm::ivec3(1) == A, "GLM: Failed constexpr");
  293. }
  294. {
  295. constexpr glm::ivec3 B(glm::ivec2(1, 2), 3);
  296. static_assert(glm::ivec3(1, 2, 3) == B, "GLM: Failed constexpr");
  297. constexpr glm::ivec3 C(1, glm::ivec2(2, 3));
  298. static_assert(glm::ivec3(1, 2, 3) == C, "GLM: Failed constexpr");
  299. constexpr glm::ivec3 D(glm::ivec1(1), glm::ivec2(2, 3));
  300. static_assert(glm::ivec3(1, 2, 3) == D, "GLM: Failed constexpr");
  301. constexpr glm::ivec3 E(glm::ivec2(1, 2), glm::ivec1(3));
  302. static_assert(glm::ivec3(1, 2, 3) == E, "GLM: Failed constexpr");
  303. }
  304. {
  305. constexpr glm::ivec3 F(glm::ivec1(1), glm::ivec1(2), glm::ivec1(3));
  306. static_assert(glm::ivec3(1, 2, 3) == F, "GLM: Failed constexpr");
  307. constexpr glm::ivec3 G(1, glm::ivec1(2), glm::ivec1(3));
  308. static_assert(glm::ivec3(1, 2, 3) == G, "GLM: Failed constexpr");
  309. constexpr glm::ivec3 H(glm::ivec1(1), 2, glm::ivec1(3));
  310. static_assert(glm::ivec3(1, 2, 3) == H, "GLM: Failed constexpr");
  311. constexpr glm::ivec3 I(1, 2, glm::ivec1(3));
  312. static_assert(glm::ivec3(1, 2, 3) == I, "GLM: Failed constexpr");
  313. constexpr glm::ivec3 J(glm::ivec1(1), glm::ivec1(2), 3);
  314. static_assert(glm::ivec3(1, 2, 3) == J, "GLM: Failed constexpr");
  315. constexpr glm::ivec3 K(1, glm::ivec1(2), 3);
  316. static_assert(glm::ivec3(1, 2, 3) == K, "GLM: Failed constexpr");
  317. constexpr glm::ivec3 L(glm::ivec1(1), 2, 3);
  318. static_assert(glm::ivec3(1, 2, 3) == L, "GLM: Failed constexpr");
  319. constexpr glm::ivec3 M(1, 2, 3);
  320. static_assert(glm::ivec3(1, 2, 3) == M, "GLM: Failed constexpr");
  321. }
  322. {
  323. constexpr glm::ivec3 N(glm::ivec4(1, 2, 3, 4));
  324. static_assert(glm::ivec3(1, 2, 3) == N, "GLM: Failed constexpr");
  325. }
  326. {
  327. constexpr glm::ivec3 const A(1);
  328. static_assert(A[0] == 1, "GLM: Failed constexpr");
  329. static_assert(glm::vec3(1.0f).x > 0.0f, "GLM: Failed constexpr");
  330. static_assert(glm::vec3(1.0f, -1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr");
  331. static_assert(glm::vec3(1.0f, -1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr");
  332. static_assert(glm::vec3::length() == 3, "GLM: Failed constexpr");
  333. }
  334. {
  335. constexpr glm::bvec3 A1(true);
  336. constexpr glm::bvec3 A2(true);
  337. constexpr glm::bvec3 B1(false);
  338. constexpr glm::bvec3 B2(false);
  339. static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr");
  340. static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr");
  341. }
  342. {
  343. constexpr glm::ivec3 A(1);
  344. constexpr glm::ivec3 B = A + 1;
  345. constexpr glm::ivec3 C(3);
  346. static_assert(A + B == C, "GLM: Failed constexpr");
  347. constexpr glm::ivec3 D = +A;
  348. static_assert(D == A, "GLM: Failed constexpr");
  349. }
  350. {
  351. constexpr glm::ivec3 A(3);
  352. constexpr glm::ivec3 B = A - 1;
  353. constexpr glm::ivec3 C(1);
  354. static_assert(A - B == C, "GLM: Failed constexpr");
  355. constexpr glm::ivec3 D = -A;
  356. static_assert(-D == A, "GLM: Failed constexpr");
  357. }
  358. {
  359. constexpr glm::ivec3 A(3);
  360. constexpr glm::ivec3 B = A * 1;
  361. static_assert(A == B, "GLM: Failed constexpr");
  362. constexpr glm::ivec3 C(1);
  363. static_assert(B * C == A, "GLM: Failed constexpr");
  364. }
  365. {
  366. constexpr glm::ivec3 A(3);
  367. constexpr glm::ivec3 B = A / 1;
  368. static_assert(A == B, "GLM: Failed constexpr");
  369. constexpr glm::ivec3 C(1);
  370. static_assert(B / C == A, "GLM: Failed constexpr");
  371. }
  372. {
  373. constexpr glm::ivec3 A(3);
  374. constexpr glm::ivec3 B = A % 2;
  375. constexpr glm::ivec3 C(1);
  376. static_assert(B == C, "GLM: Failed constexpr");
  377. constexpr glm::ivec1 D(2);
  378. static_assert(A % D == C, "GLM: Failed constexpr");
  379. }
  380. {
  381. constexpr glm::ivec3 A(1);
  382. constexpr glm::ivec3 B = A & 1;
  383. static_assert(A == B, "GLM: Failed constexpr");
  384. constexpr glm::ivec1 C(1);
  385. static_assert(A == (A & C), "GLM: Failed constexpr");
  386. }
  387. {
  388. constexpr glm::ivec3 A(1);
  389. constexpr glm::ivec3 B = A | 1;
  390. static_assert(A == B, "GLM: Failed constexpr");
  391. constexpr glm::ivec1 C(1);
  392. static_assert(A == (A | C), "GLM: Failed constexpr");
  393. }
  394. {
  395. constexpr glm::ivec3 A(1);
  396. constexpr glm::ivec3 B = A ^ 0;
  397. static_assert(A == B, "GLM: Failed constexpr");
  398. constexpr glm::ivec1 C(0);
  399. static_assert(A == (A ^ C), "GLM: Failed constexpr");
  400. }
  401. {
  402. constexpr glm::ivec3 A(1);
  403. constexpr glm::ivec3 B = A << 1;
  404. static_assert(B == glm::ivec3(2), "GLM: Failed constexpr");
  405. constexpr glm::ivec1 C(1);
  406. static_assert(B == (A << C), "GLM: Failed constexpr");
  407. }
  408. {
  409. constexpr glm::ivec3 A(2);
  410. constexpr glm::ivec3 B = A >> 1;
  411. static_assert(B == glm::ivec3(1), "GLM: Failed constexpr");
  412. constexpr glm::ivec1 C(1);
  413. static_assert(B == A >> C, "GLM: Failed constexpr");
  414. }
  415. {
  416. constexpr glm::ivec3 A(~0);
  417. constexpr glm::ivec3 B = ~A;
  418. static_assert(A == ~B, "GLM: Failed constexpr");
  419. }
  420. return Error;
  421. }
  422. static int test_vec4()
  423. {
  424. int Error = 0;
  425. {
  426. constexpr glm::bvec4 B(true);
  427. constexpr bool A = glm::all(B);
  428. static_assert(A, "GLM: Failed constexpr");
  429. constexpr glm::bvec4 D(true, false, true, false);
  430. constexpr bool C = glm::any(D);
  431. static_assert(C, "GLM: Failed constexpr");
  432. }
  433. {
  434. constexpr glm::bvec4 C(true);
  435. constexpr glm::bvec4 B(true, false, true, false);
  436. static_assert(glm::any(glm::equal(C, B)), "GLM: Failed constexpr");
  437. }
  438. {
  439. constexpr glm::ivec4 O(glm::ivec4(1));
  440. static_assert(glm::ivec4(1) == O, "GLM: Failed constexpr");
  441. constexpr glm::ivec4 A(1);
  442. static_assert(glm::ivec4(1) == A, "GLM: Failed constexpr");
  443. constexpr glm::ivec4 N(glm::ivec4(1, 2, 3, 4));
  444. static_assert(glm::ivec4(1, 2, 3, 4) == N, "GLM: Failed constexpr");
  445. }
  446. {
  447. constexpr glm::ivec4 A(glm::ivec3(1, 2, 3), 4);
  448. static_assert(glm::ivec4(1, 2, 3, 4) == A, "GLM: Failed constexpr");
  449. constexpr glm::ivec4 B(glm::ivec2(1, 2), glm::ivec2(3, 4));
  450. static_assert(glm::ivec4(1, 2, 3, 4) == B, "GLM: Failed constexpr");
  451. constexpr glm::ivec4 C(1, glm::ivec3(2, 3, 4));
  452. static_assert(glm::ivec4(1, 2, 3, 4) == C, "GLM: Failed constexpr");
  453. constexpr glm::ivec4 D(glm::ivec1(1), glm::ivec2(2, 3), glm::ivec1(4));
  454. static_assert(glm::ivec4(1, 2, 3, 4) == D, "GLM: Failed constexpr");
  455. constexpr glm::ivec4 E(glm::ivec2(1, 2), glm::ivec1(3), glm::ivec1(4));
  456. static_assert(glm::ivec4(1, 2, 3, 4) == E, "GLM: Failed constexpr");
  457. constexpr glm::ivec4 F(glm::ivec1(1), glm::ivec1(2), glm::ivec2(3, 4));
  458. static_assert(glm::ivec4(1, 2, 3, 4) == F, "GLM: Failed constexpr");
  459. }
  460. {
  461. constexpr glm::ivec4 A(1);
  462. static_assert(A[0] == 1, "GLM: Failed constexpr");
  463. static_assert(glm::ivec4(1).x > 0, "GLM: Failed constexpr");
  464. static_assert(glm::ivec4(1.0f, -1.0f, -1.0f, 1.0f).x > 0, "GLM: Failed constexpr");
  465. static_assert(glm::ivec4(1.0f, -1.0f, -1.0f, 1.0f).y < 0, "GLM: Failed constexpr");
  466. static_assert(glm::ivec4::length() == 4, "GLM: Failed constexpr");
  467. }
  468. {
  469. constexpr glm::bvec4 A1(true);
  470. constexpr glm::bvec4 A2(true);
  471. constexpr glm::bvec4 B1(false);
  472. constexpr glm::bvec4 B2(false);
  473. static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr");
  474. static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr");
  475. }
  476. {
  477. constexpr glm::ivec4 A(1);
  478. constexpr glm::ivec4 B = A + 1;
  479. constexpr glm::ivec4 C(3);
  480. static_assert(A + B == C, "GLM: Failed constexpr");
  481. constexpr glm::ivec4 D = +A;
  482. static_assert(D == A, "GLM: Failed constexpr");
  483. }
  484. {
  485. constexpr glm::ivec4 A(3);
  486. constexpr glm::ivec4 B = A - 1;
  487. constexpr glm::ivec4 C(1);
  488. static_assert(A - B == C, "GLM: Failed constexpr");
  489. constexpr glm::ivec4 D = -A;
  490. static_assert(-D == A, "GLM: Failed constexpr");
  491. }
  492. {
  493. constexpr glm::ivec4 A(3);
  494. constexpr glm::ivec4 B = A * 1;
  495. static_assert(A == B, "GLM: Failed constexpr");
  496. constexpr glm::ivec4 C(1);
  497. static_assert(B * C == A, "GLM: Failed constexpr");
  498. }
  499. {
  500. constexpr glm::ivec4 A(3);
  501. constexpr glm::ivec4 B = A / 1;
  502. static_assert(A == B, "GLM: Failed constexpr");
  503. constexpr glm::ivec4 C(1);
  504. static_assert(B / C == A, "GLM: Failed constexpr");
  505. }
  506. {
  507. constexpr glm::ivec4 A(3);
  508. constexpr glm::ivec4 B = A % 2;
  509. constexpr glm::ivec4 C(1);
  510. static_assert(B == C, "GLM: Failed constexpr");
  511. constexpr glm::ivec1 D(2);
  512. static_assert(A % D == C, "GLM: Failed constexpr");
  513. }
  514. {
  515. constexpr glm::ivec4 A(1);
  516. constexpr glm::ivec4 B = A & 1;
  517. static_assert(A == B, "GLM: Failed constexpr");
  518. constexpr glm::ivec1 C(1);
  519. static_assert(A == (A & C), "GLM: Failed constexpr");
  520. }
  521. {
  522. constexpr glm::ivec4 A(1);
  523. constexpr glm::ivec4 B = A | 1;
  524. static_assert(A == B, "GLM: Failed constexpr");
  525. constexpr glm::ivec1 C(1);
  526. static_assert(A == (A | C), "GLM: Failed constexpr");
  527. }
  528. {
  529. constexpr glm::ivec4 A(1);
  530. constexpr glm::ivec4 B = A ^ 0;
  531. static_assert(A == B, "GLM: Failed constexpr");
  532. constexpr glm::ivec1 C(0);
  533. static_assert(A == (A ^ C), "GLM: Failed constexpr");
  534. }
  535. {
  536. constexpr glm::ivec4 A(1);
  537. constexpr glm::ivec4 B = A << 1;
  538. static_assert(B == glm::ivec4(2), "GLM: Failed constexpr");
  539. constexpr glm::ivec1 C(1);
  540. static_assert(B == (A << C), "GLM: Failed constexpr");
  541. }
  542. {
  543. constexpr glm::ivec4 A(2);
  544. constexpr glm::ivec4 B = A >> 1;
  545. static_assert(B == glm::ivec4(1), "GLM: Failed constexpr");
  546. constexpr glm::ivec1 C(1);
  547. static_assert(B == A >> C, "GLM: Failed constexpr");
  548. }
  549. {
  550. constexpr glm::ivec4 A(~0);
  551. constexpr glm::ivec4 B = ~A;
  552. static_assert(A == ~B, "GLM: Failed constexpr");
  553. }
  554. return Error;
  555. }
  556. static int test_quat()
  557. {
  558. int Error = 0;
  559. {
  560. static_assert(glm::quat::length() == 4, "GLM: Failed constexpr");
  561. static_assert(glm::quat(1.0f, glm::vec3(0.0f)).w > 0.0f, "GLM: Failed constexpr");
  562. static_assert(glm::quat(1.0f, 0.0f, 0.0f, 0.0f).w > 0.0f, "GLM: Failed constexpr");
  563. glm::quat constexpr Q = glm::identity<glm::quat>();
  564. static_assert(Q.x - glm::quat(1.0f, glm::vec3(0.0f)).x <= glm::epsilon<float>(), "GLM: Failed constexpr");
  565. }
  566. return Error;
  567. }
  568. static int test_mat2x2()
  569. {
  570. int Error = 0;
  571. static_assert(glm::mat2x2::length() == 2, "GLM: Failed constexpr");
  572. return Error;
  573. }
  574. static int test_mat3x3()
  575. {
  576. int Error = 0;
  577. static_assert(glm::mat3x3::length() == 3, "GLM: Failed constexpr");
  578. constexpr glm::mat3x3 const Z(1.0f);
  579. Error += glm::all(glm::equal(Z, glm::mat3x3(1.0f), glm::epsilon<float>())) ? 0 : 1;
  580. return Error;
  581. }
  582. static int test_mat3x4()
  583. {
  584. int Error = 0;
  585. static_assert(glm::mat3x4::length() == 3, "GLM: Failed constexpr");
  586. constexpr glm::mat3x4 const Z(1.0f);
  587. Error += glm::all(glm::equal(Z, glm::mat3x4(1.0f), glm::epsilon<float>())) ? 0 : 1;
  588. return Error;
  589. }
  590. static int test_mat4x2()
  591. {
  592. int Error = 0;
  593. static_assert(glm::mat4x2::length() == 4, "GLM: Failed constexpr");
  594. constexpr glm::mat4x2 const Z(1.0f);
  595. Error += glm::all(glm::equal(Z, glm::mat4x2(1.0f), glm::epsilon<float>())) ? 0 : 1;
  596. return Error;
  597. }
  598. static int test_mat4x3()
  599. {
  600. int Error = 0;
  601. static_assert(glm::mat4x3::length() == 4, "GLM: Failed constexpr");
  602. constexpr glm::mat4x3 const Z(1.0f);
  603. Error += glm::all(glm::equal(Z, glm::mat4x3(1.0f), glm::epsilon<float>())) ? 0 : 1;
  604. return Error;
  605. }
  606. static int test_mat4x4()
  607. {
  608. int Error = 0;
  609. static_assert(glm::mat4::length() == 4, "GLM: Failed constexpr");
  610. constexpr glm::mat4 A(1.f);
  611. constexpr glm::mat4 B(1.f);
  612. constexpr glm::bvec4 C = glm::equal(A, B, 0.01f);
  613. static_assert(glm::all(C), "GLM: Failed constexpr");
  614. constexpr glm::mat4 const Z(1.0f);
  615. Error += glm::all(glm::equal(Z, glm::mat4(1.0f), glm::epsilon<float>())) ? 0 : 1;
  616. return Error;
  617. }
  618. static int test_common()
  619. {
  620. static_assert(glm::abs(1.0f) > 0.0f, "GLM: Failed constexpr");
  621. constexpr glm::vec1 const A = glm::abs(glm::vec1(1.0f));
  622. constexpr glm::vec2 const B = glm::abs(glm::vec2(1.0f));
  623. constexpr glm::vec3 const C = glm::abs(glm::vec3(1.0f));
  624. constexpr glm::vec4 const D = glm::abs(glm::vec4(1.0f));
  625. static_assert(glm::all(glm::equal(A, glm::vec1(1.0f), glm::epsilon<float>())), "GLM: Failed constexpr");
  626. static_assert(glm::all(glm::equal(B, glm::vec2(1.0f), glm::epsilon<float>())), "GLM: Failed constexpr");
  627. static_assert(glm::all(glm::equal(C, glm::vec3(1.0f), glm::epsilon<float>())), "GLM: Failed constexpr");
  628. static_assert(glm::all(glm::equal(D, glm::vec4(1.0f), glm::epsilon<float>())), "GLM: Failed constexpr");
  629. return 0;
  630. }
  631. int main()
  632. {
  633. int Error = 0;
  634. Error += test_vec1();
  635. Error += test_vec2();
  636. Error += test_vec3();
  637. Error += test_vec4();
  638. Error += test_quat();
  639. Error += test_mat2x2();
  640. Error += test_mat3x3();
  641. Error += test_mat3x4();
  642. Error += test_mat4x2();
  643. Error += test_mat4x3();
  644. Error += test_mat4x4();
  645. Error += test_common();
  646. return Error;
  647. }
  648. #else
  649. int main()
  650. {
  651. return 0;
  652. }
  653. #endif