func_common.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2010 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2008-08-31
  5. // Updated : 2008-08-31
  6. // Licence : This source is under MIT License
  7. // File : test/core/func_common.cpp
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. #include "../precompiled.hpp"
  10. #include <glm/core/func_common.hpp>
  11. namespace glm{
  12. namespace test{
  13. static const float epsilon = 0.00001f;
  14. bool test_abs_type1()
  15. {
  16. float absolute1 = glm::abs(( 76.f));
  17. float absolute2 = glm::abs((-76.f));
  18. if(absolute1 != (76.f) ||
  19. absolute2 != (76.f))
  20. return false;
  21. return true;
  22. }
  23. bool test_abs_type2()
  24. {
  25. glm::vec2 absolute1 = glm::abs(glm::vec2( 76.f, 76.f));
  26. glm::vec2 absolute2 = glm::abs(glm::vec2(-76.f,-76.f));
  27. if(absolute1.x != 76.f || absolute1.y != 76.f ||
  28. absolute2.x != 76.f || absolute2.y != 76.f)
  29. return false;
  30. return true;
  31. }
  32. bool test_abs_type3()
  33. {
  34. glm::vec3 absolute1 = glm::abs(glm::vec3( 76.f, 76.f, 76.f));
  35. glm::vec3 absolute2 = glm::abs(glm::vec3(-76.f,-76.f,-76.f));
  36. if(absolute1.x != 76.f || absolute1.y != 76.f || absolute1.z != 76.f ||
  37. absolute2.x != 76.f || absolute2.y != 76.f || absolute2.z != 76.f)
  38. return false;
  39. return true;
  40. }
  41. bool test_abs_type4()
  42. {
  43. glm::vec4 absolute1 = glm::abs(glm::vec4( 76.f, 76.f, 76.f, 76.f));
  44. glm::vec4 absolute2 = glm::abs(glm::vec4(-76.f,-76.f,-76.f,-76.f));
  45. if(absolute1.x != 76.f || absolute1.y != 76.f || absolute1.z != 76.f || absolute1.w != 76.f ||
  46. absolute2.x != 76.f || absolute2.y != 76.f || absolute2.z != 76.f || absolute2.w != 76.f)
  47. return false;
  48. return true;
  49. }
  50. bool test_sign_type1()
  51. {
  52. float vec_sign1 = sign( 76.f);
  53. float vec_sign2 = sign( 0.f);
  54. float vec_sign3 = sign(-76.f);
  55. if(vec_sign1 != 1.0f ||
  56. vec_sign2 != 0.0f ||
  57. vec_sign3 != -1.0f)
  58. return false;
  59. return true;
  60. }
  61. bool test_sign_type2()
  62. {
  63. vec2 vec_sign1 = sign(vec2( 76.f, 76.f));
  64. vec2 vec_sign2 = sign(vec2( 0.f, 0.f));
  65. vec2 vec_sign3 = sign(vec2(-76.f,-76.f));
  66. if(vec_sign1.x != 1.0f ||
  67. vec_sign1.y != 1.0f)
  68. return false;
  69. if(vec_sign2.x != 0.0f ||
  70. vec_sign2.y != 0.0f)
  71. return false;
  72. if(vec_sign3.x != -1.0f ||
  73. vec_sign3.y != -1.0f)
  74. return false;
  75. return true;
  76. }
  77. bool test_sign_type3()
  78. {
  79. vec3 vec_sign1 = sign(vec3( 76.f, 76.f, 76.f));
  80. vec3 vec_sign2 = sign(vec3( 0.f, 0.f, 0.f));
  81. vec3 vec_sign3 = sign(vec3(-76.f,-76.f,-76.f));
  82. if(vec_sign1.x != 1.0f ||
  83. vec_sign1.y != 1.0f ||
  84. vec_sign1.z != 1.0f)
  85. return false;
  86. if(vec_sign2.x != 0.0f ||
  87. vec_sign2.y != 0.0f ||
  88. vec_sign2.z != 0.0f)
  89. return false;
  90. if(vec_sign3.x != -1.0f ||
  91. vec_sign3.y != -1.0f ||
  92. vec_sign3.z != -1.0f)
  93. return false;
  94. return true;
  95. }
  96. bool test_sign_type4()
  97. {
  98. vec4 vec_sign1 = sign(vec4( 76.f, 76.f, 76.f, 76.f));
  99. vec4 vec_sign2 = sign(vec4( 0.f, 0.f, 0.f, 0.f));
  100. vec4 vec_sign3 = sign(vec4(-76.f,-76.f,-76.f,-76.f));
  101. if(vec_sign1.x != 1.0f ||
  102. vec_sign1.y != 1.0f ||
  103. vec_sign1.z != 1.0f ||
  104. vec_sign1.w != 1.0f)
  105. return false;
  106. if(vec_sign2.x != 0.0f ||
  107. vec_sign2.y != 0.0f ||
  108. vec_sign2.z != 0.0f ||
  109. vec_sign2.w != 0.0f)
  110. return false;
  111. if(vec_sign3.x != -1.0f ||
  112. vec_sign3.y != -1.0f ||
  113. vec_sign3.z != -1.0f ||
  114. vec_sign3.w != -1.0f)
  115. return false;
  116. return true;
  117. }
  118. bool test_floor_type1()
  119. {
  120. float val_floor = glm::floor(float(0.5f));
  121. if(val_floor != 0)
  122. return false;
  123. return true;
  124. }
  125. bool test_floor_type2()
  126. {
  127. glm::vec2 vec_floor = glm::floor(glm::vec2(0.5f, 0.5f));
  128. if(vec_floor.x != 0 ||
  129. vec_floor.y != 0)
  130. return false;
  131. return true;
  132. }
  133. bool test_floor_type3()
  134. {
  135. glm::vec3 vec_floor = glm::floor(glm::vec3(0.5f, 0.5f, 0.5f));
  136. if(vec_floor.x != 0 ||
  137. vec_floor.y != 0 ||
  138. vec_floor.z != 0)
  139. return false;
  140. return true;
  141. }
  142. bool test_floor_type4()
  143. {
  144. glm::vec4 vec_floor = glm::floor(glm::vec4(0.5f, 0.5f, 0.5f, 0.5f));
  145. if(vec_floor.x != 0 ||
  146. vec_floor.y != 0 ||
  147. vec_floor.z != 0 ||
  148. vec_floor.w != 0)
  149. return false;
  150. return true;
  151. }
  152. bool test_trunc_type1()
  153. {
  154. return true;
  155. }
  156. bool test_trunc_type2()
  157. {
  158. return true;
  159. }
  160. bool test_trunc_type3()
  161. {
  162. return true;
  163. }
  164. bool test_trunc_type4()
  165. {
  166. return true;
  167. }
  168. bool test_round_type1()
  169. {
  170. return true;
  171. }
  172. bool test_round_type2()
  173. {
  174. return true;
  175. }
  176. bool test_round_type3()
  177. {
  178. return true;
  179. }
  180. bool test_round_type4()
  181. {
  182. return true;
  183. }
  184. bool test_roundEven_type1()
  185. {
  186. float a = glm::roundEven(3.5f);
  187. float b = glm::roundEven(4.5f);
  188. float c = glm::roundEven(5.5f);
  189. float d = glm::roundEven(3.4f);
  190. float e = glm::roundEven(4.4f);
  191. float f = glm::roundEven(5.4f);
  192. float g = glm::roundEven(3.6f);
  193. float h = glm::roundEven(4.6f);
  194. float i = glm::roundEven(5.6f);
  195. float end = 0.0f;
  196. return true;
  197. }
  198. bool test_roundEven_type2()
  199. {
  200. return true;
  201. }
  202. bool test_roundEven_type3()
  203. {
  204. return true;
  205. }
  206. bool test_roundEven_type4()
  207. {
  208. return true;
  209. }
  210. bool test_ceil_1()
  211. {
  212. float val_ceil = glm::ceil(float(0.5f));
  213. if(val_ceil != 1)
  214. return false;
  215. return true;
  216. }
  217. bool test_ceil_2()
  218. {
  219. glm::vec2 vec_ceil = glm::ceil(glm::vec2(0.5f, 0.5f));
  220. if(vec_ceil.x != 1 ||
  221. vec_ceil.y != 1)
  222. return false;
  223. return true;
  224. }
  225. bool test_ceil_3()
  226. {
  227. glm::vec3 vec_ceil = glm::ceil(glm::vec3(0.5f, 0.5f, 0.5f));
  228. if(vec_ceil.x != 1 ||
  229. vec_ceil.y != 1 ||
  230. vec_ceil.z != 1)
  231. return false;
  232. return true;
  233. }
  234. bool test_ceil_4()
  235. {
  236. glm::vec4 vec_ceil = glm::ceil(glm::vec4(0.5f, 0.5f, 0.5f, 0.5f));
  237. if(vec_ceil.x != 1 ||
  238. vec_ceil.y != 1 ||
  239. vec_ceil.z != 1 ||
  240. vec_ceil.w != 1)
  241. return false;
  242. return true;
  243. }
  244. bool test_fract_1()
  245. {
  246. float val_fract = fract(float(0.5f));
  247. if(val_fract != 0.5f)
  248. return false;
  249. return true;
  250. }
  251. bool test_fract_2()
  252. {
  253. vec2 vec_fract = fract(vec2(0.5f, 0.5f));
  254. if(vec_fract.x != 0.5f ||
  255. vec_fract.y != 0.5f)
  256. return false;
  257. return true;
  258. }
  259. bool test_fract_3()
  260. {
  261. vec3 vec_fract = fract(vec3(0.5f, 0.5f, 0.5f));
  262. if(vec_fract.x != 0.5f ||
  263. vec_fract.y != 0.5f ||
  264. vec_fract.z != 0.5f)
  265. return false;
  266. return true;
  267. }
  268. bool test_fract_4()
  269. {
  270. vec4 vec_fract = fract(vec4(0.5f, 0.5f, 0.5f, 0.5f));
  271. if(vec_fract.x != 0.5f ||
  272. vec_fract.y != 0.5f ||
  273. vec_fract.z != 0.5f ||
  274. vec_fract.w != 0.5f)
  275. return false;
  276. return true;
  277. }
  278. bool test_mod_1()
  279. {
  280. float val_mod = glm::mod(float(4.0f), float(2.0f));
  281. if(val_mod != 0.0f)
  282. return false;
  283. return true;
  284. }
  285. bool test_mod_2()
  286. {
  287. glm::vec2 vec_mod1 = glm::mod(glm::vec2(4.0f, 4.0f), glm::vec2(2.0f, 2.0f));
  288. glm::vec2 vec_mod2 = glm::mod(glm::vec2(4.0f, 4.0f), float(2.0f));
  289. if(vec_mod1.x != 0.0f ||
  290. vec_mod1.y != 0.0f)
  291. return false;
  292. if(vec_mod2.x != 0.0f ||
  293. vec_mod2.y != 0.0f)
  294. return false;
  295. return true;
  296. }
  297. bool test_mod_3()
  298. {
  299. glm::vec3 vec_mod1 = glm::mod(glm::vec3(4.0f, 4.0f, 4.0f), glm::vec3(2.0f, 2.0f, 2.0f));
  300. glm::vec3 vec_mod2 = glm::mod(glm::vec3(4.0f, 4.0f, 4.0f), float(2.0f));
  301. if(vec_mod1.x != 0.0f ||
  302. vec_mod1.y != 0.0f ||
  303. vec_mod1.z != 0.0f)
  304. return false;
  305. if(vec_mod2.x != 0.0f ||
  306. vec_mod2.y != 0.0f ||
  307. vec_mod2.z != 0.0f)
  308. return false;
  309. return true;
  310. }
  311. bool test_mod_4()
  312. {
  313. glm::vec4 vec_mod1 = glm::mod(glm::vec4(4.0f, 4.0f, 4.0f, 4.0f), glm::vec4(2.0f, 2.0f, 2.0f, 2.0f));
  314. glm::vec4 vec_mod2 = glm::mod(glm::vec4(4.0f, 4.0f, 4.0f, 4.0f), float(2.0f));
  315. if(vec_mod1.x != 0.0f ||
  316. vec_mod1.y != 0.0f ||
  317. vec_mod1.z != 0.0f ||
  318. vec_mod1.w != 0.0f)
  319. return false;
  320. if(vec_mod2.x != 0.0f ||
  321. vec_mod2.y != 0.0f ||
  322. vec_mod2.z != 0.0f ||
  323. vec_mod2.w != 0.0f)
  324. return false;
  325. return true;
  326. }
  327. bool test_modf()
  328. {
  329. return true;
  330. }
  331. bool test_min_1()
  332. {
  333. float val_min = glm::min(float(0.0f), float(1.0f));
  334. if(val_min > 0.0f)
  335. return false;
  336. return true;
  337. }
  338. bool test_min_2()
  339. {
  340. glm::vec2 val_min1 = glm::min(glm::vec2(0.0f, 0.0f), glm::vec2(1.0f, 1.0f));
  341. glm::vec2 val_min2 = glm::min(glm::vec2(0.0f, 0.0f), float(1.0f));
  342. if(val_min1.x > 0.0f ||
  343. val_min1.y > 0.0f)
  344. return false;
  345. if(val_min2.x > 0.0f ||
  346. val_min2.y > 0.0f)
  347. return false;
  348. return true;
  349. }
  350. bool test_min_3()
  351. {
  352. glm::vec3 val_min1 = glm::min(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
  353. glm::vec3 val_min2 = glm::min(glm::vec3(0.0f, 0.0f, 0.0f), float(1.0f));
  354. if(val_min1.x > 0.0f ||
  355. val_min1.y > 0.0f ||
  356. val_min1.z > 0.0f)
  357. return false;
  358. if(val_min2.x > 0.0f ||
  359. val_min2.y > 0.0f ||
  360. val_min2.z > 0.0f)
  361. return false;
  362. return true;
  363. }
  364. bool test_min_4()
  365. {
  366. glm::vec4 val_min1 = glm::min(glm::vec4(0.0f, 0.0f, 0.0f, 0.0f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));
  367. glm::vec4 val_min2 = glm::min(glm::vec4(0.0f, 0.0f, 0.0f, 0.0f), float(1.0f));
  368. if(val_min1.x > 0.0f ||
  369. val_min1.y > 0.0f ||
  370. val_min1.z > 0.0f ||
  371. val_min1.w > 0.0f)
  372. return false;
  373. if(val_min2.x > 0.0f ||
  374. val_min2.y > 0.0f ||
  375. val_min2.z > 0.0f ||
  376. val_min2.w > 0.0f)
  377. return false;
  378. return true;
  379. }
  380. bool test_max_1()
  381. {
  382. float val_max = glm::max(float(0.0f), float(1.0f));
  383. if(val_max < 1.0f)
  384. return false;
  385. return true;
  386. }
  387. bool test_max_2()
  388. {
  389. glm::vec2 val_max1 = glm::max(glm::vec2(0.0f, 0.0f), glm::vec2(1.0f, 1.0f));
  390. glm::vec2 val_max2 = glm::max(glm::vec2(0.0f, 0.0f), float(1.0f));
  391. if(val_max1.x < 1.0f ||
  392. val_max1.y < 1.0f)
  393. return false;
  394. if(val_max2.x < 1.0f ||
  395. val_max2.y < 1.0f)
  396. return false;
  397. return true;
  398. }
  399. bool test_max_3()
  400. {
  401. glm::vec3 val_max1 = glm::max(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
  402. glm::vec3 val_max2 = glm::max(glm::vec3(0.0f, 0.0f, 0.0f), float(1.0f));
  403. if(val_max1.x < 1.0f ||
  404. val_max1.y < 1.0f ||
  405. val_max1.z < 1.0f)
  406. return false;
  407. if(val_max2.x < 1.0f ||
  408. val_max2.y < 1.0f ||
  409. val_max2.z < 1.0f)
  410. return false;
  411. return true;
  412. }
  413. bool test_max_4()
  414. {
  415. glm::vec4 val_max1 = glm::max(glm::vec4(0.0f, 0.0f, 0.0f, 0.0f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));
  416. glm::vec4 val_max2 = glm::max(glm::vec4(0.0f, 0.0f, 0.0f, 0.0f), float(1.0f));
  417. if(val_max1.x < 1.0f ||
  418. val_max1.y < 1.0f ||
  419. val_max1.z < 1.0f ||
  420. val_max1.w < 1.0f)
  421. return false;
  422. if(val_max2.x < 1.0f ||
  423. val_max2.y < 1.0f ||
  424. val_max2.z < 1.0f ||
  425. val_max2.w < 1.0f)
  426. return false;
  427. return true;
  428. }
  429. bool test_clamp_1()
  430. {
  431. float clamp1 = glm::clamp(float( 4.0f), float(0.0f), float(1.0f));
  432. float clamp2 = glm::clamp(float(-4.0f), float(0.0f), float(1.0f));
  433. if(clamp1 != 1.0f ||
  434. clamp2 != 0.0f)
  435. return false;
  436. return true;
  437. }
  438. bool test_clamp_2()
  439. {
  440. glm::vec2 clamp1 = glm::clamp(
  441. glm::vec2( 4.0f, 4.0f),
  442. glm::vec2( 0.0f, 0.0f),
  443. glm::vec2( 1.0f, 1.0f));
  444. glm::vec2 clamp2 = glm::clamp(
  445. glm::vec2(-4.0f,-4.0f),
  446. glm::vec2( 0.0f, 0.0f),
  447. glm::vec2( 1.0f, 1.0f));
  448. glm::vec2 clamp3 = glm::clamp(
  449. glm::vec2( 4.0f, 4.0f),
  450. float(0.0f), float(1.0f));
  451. glm::vec2 clamp4 = glm::clamp(
  452. glm::vec2(-4.0f,-4.0f),
  453. float(0.0f), float(1.0f));
  454. if(clamp1.x != 1.0f ||
  455. clamp1.y != 1.0f)
  456. return false;
  457. if(clamp2.x != 0.0f ||
  458. clamp2.y != 0.0f)
  459. return false;
  460. if(clamp3.x != 1.0f ||
  461. clamp3.y != 1.0f)
  462. return false;
  463. if(clamp4.x != 0.0f ||
  464. clamp4.y != 0.0f)
  465. return false;
  466. return true;
  467. }
  468. bool test_clamp_3()
  469. {
  470. glm::vec3 clamp1 = glm::clamp(
  471. glm::vec3( 4.0f, 4.0f, 4.0f),
  472. glm::vec3( 0.0f, 0.0f, 0.0f),
  473. glm::vec3( 1.0f, 1.0f, 1.0f));
  474. glm::vec3 clamp2 = glm::clamp(
  475. glm::vec3(-4.0f,-4.0f,-4.0f),
  476. glm::vec3( 0.0f, 0.0f, 0.0f),
  477. glm::vec3( 1.0f, 1.0f, 1.0f));
  478. glm::vec3 clamp3 = glm::clamp(
  479. glm::vec3( 4.0f, 4.0f, 4.0f),
  480. float(0.0f), float(1.0f));
  481. glm::vec3 clamp4 = glm::clamp(
  482. glm::vec3(-4.0f,-4.0f,-4.0f),
  483. float(0.0f), float(1.0f));
  484. if(clamp1.x != 1.0f ||
  485. clamp1.y != 1.0f ||
  486. clamp1.z != 1.0f)
  487. return false;
  488. if(clamp2.x != 0.0f ||
  489. clamp2.y != 0.0f ||
  490. clamp2.z != 0.0f)
  491. return false;
  492. if(clamp3.x != 1.0f ||
  493. clamp3.y != 1.0f ||
  494. clamp3.z != 1.0f)
  495. return false;
  496. if(clamp4.x != 0.0f ||
  497. clamp4.y != 0.0f ||
  498. clamp4.z != 0.0f)
  499. return false;
  500. return true;
  501. }
  502. bool test_clamp_4()
  503. {
  504. glm::vec4 clamp1 = glm::clamp(
  505. glm::vec4( 4.0f, 4.0f, 4.0f, 4.0f),
  506. glm::vec4( 0.0f, 0.0f, 0.0f, 0.0f),
  507. glm::vec4( 1.0f, 1.0f, 1.0f, 1.0f));
  508. glm::vec4 clamp2 = glm::clamp(
  509. glm::vec4(-4.0f,-4.0f,-4.0f,-4.0f),
  510. glm::vec4( 0.0f, 0.0f, 0.0f, 0.0f),
  511. glm::vec4( 1.0f, 1.0f, 1.0f, 1.0f));
  512. glm::vec4 clamp3 = glm::clamp(
  513. glm::vec4( 4.0f, 4.0f, 4.0f, 4.0f),
  514. float(0.0f), float(1.0f));
  515. glm::vec4 clamp4 = glm::clamp(
  516. glm::vec4(-4.0f,-4.0f,-4.0f,-4.0f),
  517. float(0.0f), float(1.0f));
  518. if(clamp1.x != 1.0f ||
  519. clamp1.y != 1.0f ||
  520. clamp1.z != 1.0f ||
  521. clamp1.w != 1.0f)
  522. return false;
  523. if(clamp2.x != 0.0f ||
  524. clamp2.y != 0.0f ||
  525. clamp2.z != 0.0f ||
  526. clamp2.w != 0.0f)
  527. return false;
  528. if(clamp3.x != 1.0f ||
  529. clamp3.y != 1.0f ||
  530. clamp3.z != 1.0f ||
  531. clamp3.w != 1.0f)
  532. return false;
  533. if(clamp4.x != 0.0f ||
  534. clamp4.y != 0.0f ||
  535. clamp4.z != 0.0f ||
  536. clamp4.w != 0.0f)
  537. return false;
  538. return true;
  539. }
  540. bool test_mix_1()
  541. {
  542. float val_mix = glm::mix(float(1.0f), float(1.0f), float(1.0f));
  543. if(val_mix != 1.0f)
  544. return false;
  545. return true;
  546. }
  547. bool test_mix_2()
  548. {
  549. glm::vec2 val_mix1 = glm::mix(glm::vec2(1.0f, 1.0f), glm::vec2(1.0f, 1.0f), glm::vec2(1.0f, 1.0f));
  550. glm::vec2 val_mix2 = glm::mix(glm::vec2(1.0f, 1.0f), glm::vec2(1.0f, 1.0f), float(1.0f));
  551. if(val_mix1.x != 1.0f || val_mix1.y != 1.0f ||
  552. val_mix2.x != 1.0f || val_mix2.y != 1.0f)
  553. return false;
  554. return true;
  555. }
  556. bool test_mix_3()
  557. {
  558. glm::vec3 val_mix1 = glm::mix(glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(1.0f, 1.0f, 1.0f));
  559. glm::vec3 val_mix2 = glm::mix(glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(1.0f, 1.0f, 1.0f), float(1.0f));
  560. if(val_mix1.x != 1.0f || val_mix1.y != 1.0f || val_mix1.z != 1.0f ||
  561. val_mix2.x != 1.0f || val_mix2.y != 1.0f || val_mix2.z != 1.0f)
  562. return false;
  563. return true;
  564. }
  565. bool test_mix_4()
  566. {
  567. glm::vec4 val_mix1 = glm::mix(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));
  568. glm::vec4 val_mix2 = glm::mix(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), float(1.0f));
  569. if(val_mix1.x != 1.0f || val_mix1.y != 1.0f || val_mix1.z != 1.0f || val_mix1.w != 1.0f ||
  570. val_mix2.x != 1.0f || val_mix2.y != 1.0f || val_mix2.z != 1.0f || val_mix2.w != 1.0f)
  571. return false;
  572. return true;
  573. }
  574. bool test_step_1()
  575. {
  576. float vec_step1 = step(1.f, 76.f);
  577. if(vec_step1 != 1.0f)
  578. return false;
  579. return true;
  580. }
  581. bool test_step_2()
  582. {
  583. vec2 vec_step1 = step(1.f, vec2(76.f, 1.f));
  584. vec2 vec_step2 = step(vec2(1.f, 1.f), vec2(76.f, 1.f));
  585. if(vec_step1.x != 1.0f || vec_step1.y != 0.0f ||
  586. vec_step2.x != 1.0f || vec_step2.y != 0.0f)
  587. return false;
  588. return true;
  589. }
  590. bool test_step_3()
  591. {
  592. vec3 vec_step1 = step(1.f, vec3(76.f, 1.f, 0.f));
  593. vec3 vec_step2 = step(vec3(1.f, 1.f, 1.f), vec3(76.f, 1.f, 0.f));
  594. if(vec_step1.x != 1.0f || vec_step1.y != 0.0f || vec_step1.z != 0.0f ||
  595. vec_step2.x != 1.0f || vec_step2.y != 0.0f || vec_step2.z != 0.0f)
  596. return false;
  597. return true;
  598. }
  599. bool test_step_4()
  600. {
  601. vec4 vec_step1 = step(1.f, vec4(76.f, 1.f, 0.f, 0.f));
  602. vec4 vec_step2 = step(vec4(1.f, 1.f, 1.f, 1.f), vec4(76.f, 1.f, 0.f, 0.f));
  603. if(vec_step1.x != 1.0f || vec_step1.y != 0.0f || vec_step1.z != 0.0f || vec_step1.w != 0.0f ||
  604. vec_step2.x != 1.0f || vec_step2.y != 0.0f || vec_step2.z != 0.0f || vec_step2.w != 0.0f)
  605. return false;
  606. return true;
  607. }
  608. bool test_smoothstep_1()
  609. {
  610. float vec_smoothstep1 = smoothstep(0.f, 100.f, 50.f);
  611. bool Result = (vec_smoothstep1 < 0.5f - epsilon || vec_smoothstep1 > 0.5f + epsilon);
  612. assert(!Result);
  613. float A = smoothstep(0.2f, 0.8f, 0.5f);
  614. float B = smoothstep(0.2f, 0.8f, 0.7f);
  615. float C = smoothstep(0.2f, 0.8f, 0.3f);
  616. float D = smoothstep(0.2f, 0.8f, 1.2f);
  617. float E = smoothstep(0.2f, 0.8f,-0.2f);
  618. if(Result)
  619. return false;
  620. return true;
  621. }
  622. bool test_smoothstep_2()
  623. {
  624. vec2 vec_smoothstep1 = smoothstep(0.f, 100.f, vec2(50.f, 100.f));
  625. vec2 vec_smoothstep2 = smoothstep(vec2(0.f, 0.f), vec2(100.f, 100.f), vec2(50.f, 100.f));
  626. if(vec_smoothstep1.x < 0.50f - epsilon || vec_smoothstep1.x > 0.50f + epsilon ||
  627. vec_smoothstep1.y < 1.00f - epsilon || vec_smoothstep1.y > 1.00f + epsilon)
  628. return false;
  629. if(vec_smoothstep2.x < 0.50f - epsilon || vec_smoothstep2.x > 0.50f + epsilon ||
  630. vec_smoothstep2.y < 1.00f - epsilon || vec_smoothstep2.y > 1.00f + epsilon)
  631. return false;
  632. return true;
  633. }
  634. bool test_smoothstep_3()
  635. {
  636. vec3 vec_smoothstep1 = smoothstep(0.f, 100.f, vec3(50.f, 100.f, 0.f));
  637. vec3 vec_smoothstep2 = smoothstep(vec3(0.f, 0.f, 0.f), vec3(100.f, 100.f, 100.f), vec3(50.f, 100.f, 0.f));
  638. if(vec_smoothstep1.x < 0.50f - epsilon || vec_smoothstep1.x > 0.50f + epsilon ||
  639. vec_smoothstep1.y < 1.00f - epsilon || vec_smoothstep1.y > 1.00f + epsilon ||
  640. vec_smoothstep1.z < 0.00f - epsilon || vec_smoothstep1.z > 0.00f + epsilon)
  641. return false;
  642. if(vec_smoothstep2.x < 0.50f - epsilon || vec_smoothstep2.x > 0.50f + epsilon ||
  643. vec_smoothstep2.y < 1.00f - epsilon || vec_smoothstep2.y > 1.00f + epsilon ||
  644. vec_smoothstep2.z < 0.00f - epsilon || vec_smoothstep2.z > 0.00f + epsilon)
  645. return false;
  646. return true;
  647. }
  648. bool test_smoothstep_4()
  649. {
  650. vec4 vec_smoothstep1 = smoothstep(0.f, 100.f, vec4(50.f, 100.f, 0.f, 0.f));
  651. vec4 vec_smoothstep2 = smoothstep(vec4(0.f, 0.f, 0.f, 0.f), vec4(100.f, 100.f, 100.f, 100.f), vec4(50.f, 100.f, 0.f, 0.f));
  652. if(vec_smoothstep1.x < 0.50f - epsilon || vec_smoothstep1.x > 0.50f + epsilon ||
  653. vec_smoothstep1.y < 1.00f - epsilon || vec_smoothstep1.y > 1.00f + epsilon ||
  654. vec_smoothstep1.z < 0.00f - epsilon || vec_smoothstep1.z > 0.00f + epsilon ||
  655. vec_smoothstep1.w < 0.00f - epsilon || vec_smoothstep1.w > 0.00f + epsilon)
  656. return false;
  657. if(vec_smoothstep2.x < 0.50f - epsilon || vec_smoothstep2.x > 0.50f + epsilon ||
  658. vec_smoothstep2.y < 1.00f - epsilon || vec_smoothstep2.y > 1.00f + epsilon ||
  659. vec_smoothstep2.z < 0.00f - epsilon || vec_smoothstep2.z > 0.00f + epsilon ||
  660. vec_smoothstep2.w < 0.00f - epsilon || vec_smoothstep2.w > 0.00f + epsilon)
  661. return false;
  662. return true;
  663. }
  664. bool test_isnan()
  665. {
  666. return true;
  667. }
  668. bool test_isinf()
  669. {
  670. return true;
  671. }
  672. void main_core_func_common()
  673. {
  674. assert(test_abs_type1());
  675. assert(test_abs_type2());
  676. assert(test_abs_type3());
  677. assert(test_abs_type4());
  678. assert(test_sign_type1());
  679. assert(test_sign_type2());
  680. assert(test_sign_type3());
  681. assert(test_sign_type4());
  682. assert(test_floor_type1());
  683. assert(test_floor_type2());
  684. assert(test_floor_type3());
  685. assert(test_floor_type4());
  686. assert(test_trunc_type1());
  687. assert(test_trunc_type2());
  688. assert(test_trunc_type3());
  689. assert(test_trunc_type4());
  690. assert(test_round_type1());
  691. assert(test_round_type2());
  692. assert(test_round_type3());
  693. assert(test_round_type4());
  694. assert(test_roundEven_type1());
  695. assert(test_roundEven_type2());
  696. assert(test_roundEven_type3());
  697. assert(test_roundEven_type4());
  698. assert(test_ceil_1());
  699. assert(test_ceil_2());
  700. assert(test_ceil_3());
  701. assert(test_ceil_4());
  702. assert(test_fract_1());
  703. assert(test_fract_2());
  704. assert(test_fract_3());
  705. assert(test_fract_4());
  706. assert(test_mod_1());
  707. assert(test_mod_2());
  708. assert(test_mod_3());
  709. assert(test_mod_4());
  710. assert(test_mod_1());
  711. assert(test_mod_2());
  712. assert(test_mod_3());
  713. assert(test_mod_4());
  714. assert(test_modf());
  715. assert(test_min_1());
  716. assert(test_min_2());
  717. assert(test_min_3());
  718. assert(test_min_4());
  719. assert(test_max_1());
  720. assert(test_max_2());
  721. assert(test_max_3());
  722. assert(test_max_4());
  723. assert(test_clamp_1());
  724. assert(test_clamp_2());
  725. assert(test_clamp_3());
  726. assert(test_clamp_4());
  727. assert(test_mix_1());
  728. assert(test_mix_2());
  729. assert(test_mix_3());
  730. assert(test_mix_4());
  731. assert(test_step_1());
  732. assert(test_step_2());
  733. assert(test_step_3());
  734. assert(test_step_4());
  735. assert(test_smoothstep_1());
  736. assert(test_smoothstep_2());
  737. assert(test_smoothstep_3());
  738. assert(test_smoothstep_4());
  739. assert(test_isnan());
  740. assert(test_isinf());
  741. }
  742. }//namespace test
  743. }//namespace glm