PageRenderTime 45ms CodeModel.GetById 1ms app.highlight 40ms RepoModel.GetById 1ms app.codeStats 1ms

/deps/glm-0.9.4.0/test/gtc/gtc_half_float.cpp

https://bitbucket.org/sturmh/dirtygraphics
C++ | 554 lines | 406 code | 114 blank | 34 comment | 65 complexity | 9adf73779721c62eaf2ac42a79f11a54 MD5 | raw file
  1///////////////////////////////////////////////////////////////////////////////////
  2/// OpenGL Mathematics (glm.g-truc.net)
  3///
  4/// Copyright (c) 2005 - 2012 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 test
 24/// @file test/gtc/half_float.cpp
 25/// @date 2011-05-32 / 2012-04-07
 26/// @author Christophe Riccio
 27///////////////////////////////////////////////////////////////////////////////////
 28
 29
 30#include <glm/glm.hpp>
 31#include <glm/gtc/half_float.hpp>
 32
 33int test_half_precision_scalar()
 34{
 35	int Error = 0;
 36
 37	Error += sizeof(glm::half) == 2 ? 0 : 1;
 38
 39	return Error;
 40}
 41
 42int test_half_precision_vec()
 43{
 44	int Error = 0;
 45
 46	Error += sizeof(glm::hvec2) == 4 ? 0 : 1;
 47	Error += sizeof(glm::hvec3) == 6 ? 0 : 1;
 48	Error += sizeof(glm::hvec4) == 8 ? 0 : 1;
 49    
 50    return Error;
 51}
 52
 53int test_half_precision_mat()
 54{
 55	int Error = 0;
 56
 57	Error += sizeof(glm::hmat2) == 8 ? 0 : 1;
 58	Error += sizeof(glm::hmat3) == 18 ? 0 : 1;
 59	Error += sizeof(glm::hmat4) == 32 ? 0 : 1;
 60
 61	Error += sizeof(glm::hmat2x2) == 8 ? 0 : 1;
 62	Error += sizeof(glm::hmat2x3) == 12 ? 0 : 1;
 63	Error += sizeof(glm::hmat2x4) == 16 ? 0 : 1;
 64	Error += sizeof(glm::hmat3x2) == 12 ? 0 : 1;
 65	Error += sizeof(glm::hmat3x3) == 18 ? 0 : 1;
 66	Error += sizeof(glm::hmat3x4) == 24 ? 0 : 1;
 67	Error += sizeof(glm::hmat4x2) == 16 ? 0 : 1;
 68	Error += sizeof(glm::hmat4x3) == 24 ? 0 : 1;
 69	Error += sizeof(glm::hmat4x4) == 32 ? 0 : 1;
 70
 71    return Error;
 72}
 73
 74int test_half_ctor_mat2x2()
 75{
 76	int Error = 0;
 77
 78	{
 79		glm::hvec2 A(1, 2);
 80		glm::hvec2 B(3, 4);
 81		glm::hmat2 C(A, B);//, 2.0f, 3.0f, 4.0f);
 82		glm::hmat2 D(1, 2, 3, 4);
 83
 84		Error += C[0] == D[0] ? 0 : 1;
 85		Error += C[1] == D[1] ? 0 : 1;
 86	}
 87
 88	{
 89		glm::hvec2 A(1, 2.0);
 90		glm::hvec2 B(3, 4.0);
 91		glm::hmat2 C(A, B);//, 2.0f, 3.0f, 4.0f);
 92		glm::hmat2 D(1, 2.0, 3u, 4.0f);
 93
 94		Error += C[0] == D[0] ? 0 : 1;
 95		Error += C[1] == D[1] ? 0 : 1;
 96	}
 97
 98	{
 99		glm::hmat2 A(1);
100		glm::mat2 B(1);
101		glm::hmat2 C(A);
102
103		Error += A == C ? 0 : 1;
104	}
105
106    return Error;
107}
108
109int test_half_ctor_mat2x3()
110{
111	int Error = 0;
112	
113	{
114		glm::hvec3 A(1, 2, 3);
115		glm::hvec3 B(4, 5, 6);
116		glm::hmat2x3 C(A, B);
117		glm::hmat2x3 D(1, 2, 3, 4, 5, 6);
118		
119		Error += C[0] == D[0] ? 0 : 1;
120		Error += C[1] == D[1] ? 0 : 1;
121	}
122	
123	{
124		glm::hvec3 A(1.0, 2.0f, 3u);
125		glm::hvec3 B(4, 5u, 6u);
126		glm::hmat2x3 C(A, B);
127		glm::hmat2x3 D(1, 2.0, 3u, 4.0f, 5.0, 6);
128		
129		Error += C[0] == D[0] ? 0 : 1;
130		Error += C[1] == D[1] ? 0 : 1;
131	}
132	
133	{
134		glm::hmat2x3 A(1);
135		glm::mat2x3 B(1);
136		glm::hmat2x3 C(A);
137		
138		Error += A == C ? 0 : 1;
139	}
140	
141    return Error;
142}
143
144int test_half_ctor_mat2x4()
145{
146	int Error = 0;
147	
148	{
149		glm::hvec4 A(1, 2, 3, 4);
150		glm::hvec4 B(5, 6, 7, 8);
151		glm::hmat2x4 C(A, B);
152		glm::hmat2x4 D(1, 2, 3, 4, 5, 6, 7, 8);
153		
154		Error += C[0] == D[0] ? 0 : 1;
155		Error += C[1] == D[1] ? 0 : 1;
156	}
157	
158	{
159		glm::hvec4 A(1.0, 2.0f, 3u, 4u);
160		glm::hvec4 B(5u, 6u, 7.0, 8.0);
161		glm::hmat2x4 C(A, B);
162		glm::hmat2x4 D(1, 2.0, 3u, 4.0f, 5.0, 6, 7.0f, 8.0f);
163		
164		Error += C[0] == D[0] ? 0 : 1;
165		Error += C[1] == D[1] ? 0 : 1;
166	}
167	
168	{
169		glm::hmat2x4 A(1);
170		glm::mat2x4 B(1);
171		glm::hmat2x4 C(A);
172		
173		Error += A == C ? 0 : 1;
174	}
175	
176    return Error;
177}
178
179int test_half_ctor_mat3x2()
180{
181	int Error = 0;
182	
183	{
184		glm::hvec2 A(1, 2);
185		glm::hvec2 B(3, 4);
186		glm::hvec2 C(5, 6);
187		glm::hmat3x2 M(A, B, C);
188		glm::hmat3x2 N(1, 2, 3, 4, 5, 6);
189		
190		Error += M == N ? 0 : 1;
191	}
192	
193	{
194		glm::hvec2 A(1, 2.0);
195		glm::hvec2 B(3, 4.0f);
196		glm::hvec2 C(5u, 6.0f);
197		glm::hmat3x2 M(A, B, C);
198		glm::hmat3x2 N(1, 2.0, 3u, 4.0f, 5, 6);
199		
200		Error += M == N ? 0 : 1;
201	}
202	
203	{
204		glm::hmat3x2 A(1);
205		glm::mat3x2 B(1);
206		glm::hmat3x2 C(A);
207		
208		Error += A == C ? 0 : 1;
209	}
210	
211    return Error;
212}
213
214int test_half_ctor_mat3x3()
215{
216	int Error = 0;
217	
218	{
219		glm::hvec3 A(1, 2, 3);
220		glm::hvec3 B(4, 5, 6);
221		glm::hvec3 C(7, 8, 9);
222		glm::hmat3x3 M(A, B, C);
223		glm::hmat3x3 N(1, 2, 3, 4, 5, 6, 7, 8, 9);
224		
225		Error += M == N ? 0 : 1;
226	}
227	
228	{
229		glm::hvec3 A(1, 2.0, 3.0f);
230		glm::hvec3 B(4, 5.0f, 6.0);
231		glm::hvec3 C(7u, 8.0f, 9);
232		glm::hmat3x3 M(A, B, C);
233		glm::hmat3x3 N(1, 2.0, 3u, 4.0f, 5, 6, 7.0f, 8.0, 9u);
234		
235		Error += M == N ? 0 : 1;
236	}
237	
238	{
239		glm::hmat3x3 A(1);
240		glm::mat3x3 B(1);
241		glm::hmat3x3 C(A);
242		
243		Error += A == C ? 0 : 1;
244	}
245	
246    return Error;
247}
248
249int test_half_ctor_mat3x4()
250{
251	int Error = 0;
252	
253	{
254		glm::hvec4 A(1, 2, 3, 4);
255		glm::hvec4 B(5, 6, 7, 8);
256		glm::hvec4 C(9, 10, 11, 12);
257		glm::hmat3x4 M(A, B, C);
258		glm::hmat3x4 N(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
259		
260		Error += M == N ? 0 : 1;
261	}
262	
263	{
264		glm::hvec4 A(1, 2.0, 3.0f, 4u);
265		glm::hvec4 B(5, 6.0f, 7.0, 8);
266		glm::hvec4 C(9u, 10.0f, 11, 12.f);
267		glm::hmat3x4 M(A, B, C);
268		glm::hmat3x4 N(1, 2.0, 3u, 4.0f, 5, 6, 7.0f, 8.0, 9u, 10, 11.f, 12.0);
269		
270		Error += M == N ? 0 : 1;
271	}
272	
273	{
274		glm::hmat3x4 A(1);
275		glm::mat3x4 B(1);
276		glm::hmat3x4 C(A);
277		
278		Error += A == C ? 0 : 1;
279	}
280	
281    return Error;
282}
283
284int test_half_ctor_mat4x2()
285{
286	int Error = 0;
287	
288	{
289		glm::hvec2 A(1, 2);
290		glm::hvec2 B(3, 4);
291		glm::hvec2 C(5, 6);
292		glm::hvec2 D(7, 8);
293		glm::hmat4x2 M(A, B, C, D);
294		glm::hmat4x2 N(1, 2, 3, 4, 5, 6, 7, 8);
295		
296		Error += M == N ? 0 : 1;
297	}
298	
299	{
300		glm::hvec2 A(1, 2.0);
301		glm::hvec2 B(3.0f, 4);
302		glm::hvec2 C(5.0, 6u);
303		glm::hvec2 D(7, 8u);
304		glm::hmat4x2 M(A, B, C, D);
305		glm::hmat4x2 N(1, 2.0, 3u, 4.0f, 5u, 6.0, 7, 8.0f);
306		
307		Error += M == N ? 0 : 1;
308	}
309	
310	{
311		glm::hmat4x2 A(1);
312		glm::mat4x2 B(1);
313		glm::hmat4x2 C(A);
314		
315		Error += A == C ? 0 : 1;
316	}
317	
318	return Error;
319}
320
321int test_half_ctor_mat4x3()
322{
323	int Error = 0;
324	
325	{
326		glm::hvec3 A(1, 2, 3);
327		glm::hvec3 B(4, 5, 6);
328		glm::hvec3 C(7, 8, 9);
329		glm::hvec3 D(10, 11, 12);
330		glm::hmat4x3 M(A, B, C, D);
331		glm::hmat4x3 N(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
332		
333		Error += M == N ? 0 : 1;
334	}
335	
336	{
337		glm::hvec3 A(1, 2.0, 3u);
338		glm::hvec3 B(4.0f, 5, 6u);
339		glm::hvec3 C(7.0, 8u, 9.f);
340		glm::hvec3 D(10, 11u, 12.0);
341		glm::hmat4x3 M(A, B, C, D);
342		glm::hmat4x3 N(1, 2.0, 3u, 4.0f, 5u, 6.0, 7, 8.0f, 9, 10u, 11.f, 12.0);
343		
344		Error += M == N ? 0 : 1;
345	}
346	
347	{
348		glm::hmat4x3 A(1);
349		glm::mat4x3 B(1);
350		glm::hmat4x3 C(A);
351		
352		Error += A == C ? 0 : 1;
353	}
354	
355	return Error;
356}
357
358int test_half_ctor_mat4x4()
359{
360	int Error = 0;
361	
362	{
363		glm::hvec4 A(1, 2, 3, 4);
364		glm::hvec4 B(5, 6, 7, 8);
365		glm::hvec4 C(9, 10, 11, 12);
366		glm::hvec4 D(13, 14, 15, 16);
367		glm::hmat4x4 M(A, B, C, D);
368		glm::hmat4x4 N(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
369		
370		Error += M == N ? 0 : 1;
371	}
372	
373	{
374		glm::hvec4 A(1, 2.0, 3u, 4);
375		glm::hvec4 B(5.0f, 6, 7u, 8.0);
376		glm::hvec4 C(9.0, 10u, 11.f, 12);
377		glm::hvec4 D(13, 14u, 15.0, 16u);
378		glm::hmat4x4 M(A, B, C, D);
379		glm::hmat4x4 N(1, 2.0, 3u, 4.0f, 5u, 6.0, 7, 8.0f, 9, 10u, 11.f, 12.0, 13, 14u, 15.0f, 16.0);
380		
381		Error += M == N ? 0 : 1;
382	}
383	
384	{
385		glm::hmat4x4 A(1);
386		glm::mat4x4 B(1);
387		glm::hmat4x4 C(A);
388		
389		Error += A == C ? 0 : 1;
390	}
391	
392	return Error;
393}
394
395int test_half_ctor_vec2()
396{
397	int Error = 0;
398	
399	{
400		glm::hvec2 A;
401		A.x = glm::half(1);
402		A.y = glm::half(2);
403		//glm::hvec2 A(1, 2);
404		glm::hvec2 B(A);
405		glm::vec2 C(1, 2);
406		glm::hvec2 D(C);
407		glm::dvec2 E(1, 2);
408		glm::hvec2 F(E);
409		glm::hvec2 G(1, 2.0);
410		glm::hvec2 H;
411		H = A;
412		
413		Error += A == B ? 0 : 1;
414		//Error += C == D ? 0 : 1; //Error
415		//Error += E == F ? 0 : 1; //Error
416		Error += A == G ? 0 : 1;
417		Error += A == H ? 0 : 1;
418	}
419	
420	{
421		glm::hvec2 A(1);
422		glm::vec2 B(1);
423		glm::hvec2 C(A);
424
425		Error += A == C ? 0 : 1;
426	}
427	
428	return Error;
429}
430
431int test_half_ctor_vec3()
432{
433	int Error = 0;
434	
435	{
436		glm::hvec3 A(1, 2, 3);
437		glm::hvec3 B(A);
438		glm::vec3 C(1, 2, 3);
439		glm::hvec3 D(C);
440		glm::dvec3 E(1, 2, 3);
441		glm::hvec3 F(E);
442		glm::hvec3 G(1, 2.0, 3);
443		glm::hvec3 H;
444		H = A;
445		
446		Error += A == B ? 0 : 1;
447		//Error += C == D ? 0 : 1;
448		//Error += E == F ? 0 : 1;
449		Error += A == G ? 0 : 1;
450		Error += A == H ? 0 : 1;
451	}
452	
453	{
454		glm::hvec3 A(1);
455		glm::vec3 B(1);
456		glm::hvec3 C(B);
457		
458		Error += A == C ? 0 : 1;
459	}
460	
461	return Error;
462}
463
464int test_half_ctor_vec4()
465{
466	int Error = 0;
467	
468	{
469		glm::hvec4 A(1, 2, 3, 4);
470		glm::hvec4 B(A);
471		glm::vec4 C(1, 2, 3, 4);
472		glm::hvec4 D(C);
473		glm::dvec4 E(1, 2, 3, 4);
474		glm::hvec4 F(E);
475		glm::hvec4 G(1, 2.0, 3, 4);
476		glm::hvec4 H;
477		H = A;
478		
479		Error += A == B ? 0 : 1;
480		//Error += C == D ? 0 : 1;
481		//Error += E == F ? 0 : 1;
482		Error += A == G ? 0 : 1;
483		Error += A == H ? 0 : 1;
484	}
485	
486	{
487		glm::hvec4 A(1);
488		glm::vec4 B(1);
489		glm::hvec4 C(B);
490		
491		Error += A == C ? 0 : 1;
492	}
493	
494	return Error;
495}
496
497int test_hvec2_size()
498{
499	int Error = 0;
500	
501	Error += sizeof(glm::hvec2) <= sizeof(glm::lowp_vec2) ? 0 : 1;
502	Error += 4 == sizeof(glm::hvec2) ? 0 : 1;
503	Error += glm::hvec2().length() == 2 ? 0 : 1;
504	
505	return Error;
506}
507
508int test_hvec3_size()
509{
510	int Error = 0;
511	
512	Error += sizeof(glm::hvec3) <= sizeof(glm::lowp_vec3) ? 0 : 1;
513	Error += 6 <= sizeof(glm::hvec3) ? 0 : 1;
514	Error += glm::hvec3().length() == 3 ? 0 : 1;
515		
516	return Error;
517}
518
519int test_hvec4_size()
520{
521	int Error = 0;
522	
523	Error += sizeof(glm::hvec4) <= sizeof(glm::lowp_vec4) ? 0 : 1;
524	Error += 8 <= sizeof(glm::hvec4) ? 0 : 1;
525	Error += glm::hvec4().length() == 4 ? 0 : 1;
526	
527	return Error;
528}
529
530int main()
531{
532	int Error = 0;
533
534	Error += test_hvec2_size();
535	Error += test_hvec3_size();
536	Error += test_hvec4_size();
537	Error += test_half_ctor_vec2();
538	Error += test_half_ctor_vec3();
539	Error += test_half_ctor_vec4();
540	Error += test_half_ctor_mat2x2();
541	Error += test_half_ctor_mat2x3();
542	Error += test_half_ctor_mat2x4();
543	Error += test_half_ctor_mat3x2();
544	Error += test_half_ctor_mat3x3();
545	Error += test_half_ctor_mat3x4();
546	Error += test_half_ctor_mat4x2();
547	Error += test_half_ctor_mat4x3();
548	Error += test_half_ctor_mat4x4();
549	Error += test_half_precision_scalar();
550	Error += test_half_precision_vec();
551	Error += test_half_precision_mat();
552
553	return Error;
554}