-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtypes.h
983 lines (865 loc) · 23.5 KB
/
vtypes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
#ifndef vtypes_h
#define vtypes_h
#include <math.h>
#include <CL/cl.h>
#include <CL/cl_platform.h>
#include <iostream>
/* float2 functions */
/******************************************************************************/
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
using std::ostream;
// Use opencl types to guarantee being spatially identical.
typedef cl_float2 float2;
typedef cl_float3 float3;
typedef cl_float4 float4;
typedef cl_int2 int2;
typedef cl_int3 int3;
typedef cl_int4 int4;
typedef cl_uint2 uint2;
typedef cl_uint3 uint3;
typedef cl_uint4 uint4;
inline unsigned int min( unsigned int a, unsigned int b )
{
return a < b ? a : b;
}
inline unsigned int max( unsigned int a, unsigned int b )
{
return a > b ? a : b;
}
inline int min( int a, int b )
{
return a < b ? a : b;
}
inline int max( int a, int b )
{
return a > b ? a : b;
}
/* constructors */
inline float2 make_float2(const float a1, const float a2)
{
float2 f2 = {a1, a2};
return f2;
}
inline float2 make_float2(const float s)
{
return make_float2(s, s);
}
inline float2 make_float2(const int2& a)
{
return make_float2(float(a.x), float(a.y));
}
inline float2 make_float2(const uint2& a)
{
return make_float2(float(a.x), float(a.y));
}
/* negate */
inline float2 operator-(const float2& a)
{
return make_float2(-a.x, -a.y);
}
/* min */
inline float2 fminf(const float2& a, const float2& b)
{
return make_float2(fminf(a.x,b.x), fminf(a.y,b.y));
}
inline float2 fminf(const float2& a, const float2& b, const float2& c)
{
return fminf( fminf( a, b ), c );
}
inline float fminf(const float2& a)
{
return fminf(a.x, a.y);
}
/* max */
inline float2 fmaxf(const float2& a, const float2& b)
{
return make_float2(fmaxf(a.x,b.x), fmaxf(a.y,b.y));
}
inline float2 fmaxf(const float2& a, const float2& b, const float2& c)
{
return fmaxf( fmaxf( a, b ), c );
}
inline float fmaxf(const float2& a)
{
return fmaxf(a.x, a.y);
}
/* add */
inline float2 operator+(const float2& a, const float2& b)
{
return make_float2(a.x + b.x, a.y + b.y);
}
inline float2 operator+(const float2& a, const float b)
{
return make_float2(a.x + b, a.y + b);
}
inline float2 operator+(const float a, const float2& b)
{
return make_float2(a + b.x, a + b.y);
}
inline void operator+=(float2& a, const float2& b)
{
a.x += b.x; a.y += b.y;
}
/* subtract */
inline float2 operator-(const float2& a, const float2& b)
{
return make_float2(a.x - b.x, a.y - b.y);
}
inline float2 operator-(const float2& a, const float b)
{
return make_float2(a.x - b, a.y - b);
}
inline float2 operator-(const float a, const float2& b)
{
return make_float2(a - b.x, a - b.y);
}
inline void operator-=(float2& a, const float2& b)
{
a.x -= b.x; a.y -= b.y;
}
/* multiply */
inline float2 operator*(const float2& a, const float2& b)
{
return make_float2(a.x * b.x, a.y * b.y);
}
inline float2 operator*(const float2& a, const float s)
{
return make_float2(a.x * s, a.y * s);
}
inline float2 operator*(const float s, const float2& a)
{
return make_float2(a.x * s, a.y * s);
}
inline void operator*=(float2& a, const float2& s)
{
a.x *= s.x; a.y *= s.y;
}
inline void operator*=(float2& a, const float s)
{
a.x *= s; a.y *= s;
}
/* divide */
inline float2 operator/(const float2& a, const float2& b)
{
return make_float2(a.x / b.x, a.y / b.y);
}
inline float2 operator/(const float2& a, const float s)
{
float inv = 1.0f / s;
return a * inv;
}
inline float2 operator/(const float s, const float2& a)
{
return make_float2( s/a.x, s/a.y );
}
inline void operator/=(float2& a, const float s)
{
float inv = 1.0f / s;
a *= inv;
}
/* lerp */
inline float2 lerp(const float2& a, const float2& b, const float t)
{
return a + t*(b-a);
}
/* bilerp */
inline float2 bilerp(const float2& x00, const float2& x10, const float2& x01, const float2& x11,
const float u, const float v)
{
return lerp( lerp( x00, x10, u ), lerp( x01, x11, u ), v );
}
/* dot product */
inline float dot(const float2& a, const float2& b)
{
return a.x * b.x + a.y * b.y;
}
/* length */
inline float length(const float2& v)
{
return sqrtf(dot(v, v));
}
/* normalize */
inline float2 normalize(const float2& v)
{
float invLen = 1.0f / sqrtf(dot(v, v));
return v * invLen;
}
/* floor */
inline float2 floor(const float2& v)
{
return make_float2(::floorf(v.x), ::floorf(v.y));
}
/* reflect */
inline float2 reflect(const float2& i, const float2& n)
{
return i - 2.0f * n * dot(n,i);
}
/* faceforward */
/* Returns N if dot(i, nref) > 0; else -N; */
/* Typical usage is N = faceforward(N, -ray.dir, N); */
/* Note that this is opposite of what faceforward does in Cg and GLSL */
inline float2 faceforward(const float2& n, const float2& i, const float2& nref)
{
return n * copysignf( 1.0f, dot(i, nref) );
}
/* exp */
inline float2 expf(const float2& v)
{
return make_float2(::expf(v.x), ::expf(v.y));
}
// Stream out
inline ostream& operator<<( ostream& out, const float2& f )
{
out << "FLOAT2{" << f.x << "," << f.y << "}";
return out;
}
/* float4 functions */
/******************************************************************************/
/* constructors */
inline float4 make_float4(const float a1, const float a2, const float a3, const float a4)
{
float4 f4 = {a1, a2, a3, a4};
return f4;
}
inline float4 make_float4(const float s)
{
return make_float4(s, s, s, s);
}
inline float4 make_float4(const float3& a)
{
return make_float4(a.x, a.y, a.z, 0.0f);
}
inline float4 make_float4(const int4& a)
{
return make_float4(float(a.x), float(a.y), float(a.z), float(a.w));
}
inline float4 make_float4(const uint4& a)
{
return make_float4(float(a.x), float(a.y), float(a.z), float(a.w));
}
/* negate */
inline float4 operator-(const float4& a)
{
return make_float4(-a.x, -a.y, -a.z, -a.w);
}
/* min */
inline float4 fminf(const float4& a, const float4& b)
{
return make_float4(fminf(a.x,b.x), fminf(a.y,b.y), fminf(a.z,b.z), fminf(a.w,b.w));
}
inline float4 fminf(const float4& a, const float4& b, const float4& c)
{
return fminf( fminf( a, b ), c );
}
inline float fminf(const float4& a)
{
return fminf(fminf(a.x, a.y), fminf(a.z, a.w));
}
/* max */
inline float4 fmaxf(const float4& a, const float4& b)
{
return make_float4(fmaxf(a.x,b.x), fmaxf(a.y,b.y), fmaxf(a.z,b.z), fmaxf(a.w,b.w));
}
inline float4 fmaxf(const float4& a, const float4& b, const float4& c)
{
return fmaxf( fmaxf( a, b ), c );
}
inline float fmaxf(const float4& a)
{
return fmaxf(fmaxf(a.x, a.y), fmaxf(a.z, a.w));
}
/* add */
inline float4 operator+(const float4& a, const float4& b)
{
return make_float4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
}
inline float4 operator+(const float4& a, const float b)
{
return make_float4(a.x + b, a.y + b, a.z + b, a.w + b);
}
inline float4 operator+(const float a, const float4& b)
{
return make_float4(a + b.x, a + b.y, a + b.z, a + b.w);
}
inline void operator+=(float4& a, const float4& b)
{
a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w;
}
/* subtract */
inline float4 operator-(const float4& a, const float4& b)
{
return make_float4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
}
inline float4 operator-(const float4& a, const float b)
{
return make_float4(a.x - b, a.y - b, a.z - b, a.w - b);
}
inline float4 operator-(const float a, const float4& b)
{
return make_float4(a - b.x, a - b.y, a - b.z, a - b.w);
}
inline void operator-=(float4& a, const float4& b)
{
a.x -= b.x; a.y -= b.y; a.z -= b.z; a.w -= b.w;
}
/* multiply */
inline float4 operator*(const float4& a, const float4& s)
{
return make_float4(a.x * s.x, a.y * s.y, a.z * s.z, a.w * s.w);
}
inline float4 operator*(const float4& a, const float s)
{
return make_float4(a.x * s, a.y * s, a.z * s, a.w * s);
}
inline float4 operator*(const float s, const float4& a)
{
return make_float4(a.x * s, a.y * s, a.z * s, a.w * s);
}
inline void operator*=(float4& a, const float4& s)
{
a.x *= s.x; a.y *= s.y; a.z *= s.z; a.w *= s.w;
}
inline void operator*=(float4& a, const float s)
{
a.x *= s; a.y *= s; a.z *= s; a.w *= s;
}
/* divide */
inline float4 operator/(const float4& a, const float4& b)
{
return make_float4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
}
inline float4 operator/(const float4& a, const float s)
{
float inv = 1.0f / s;
return a * inv;
}
inline float4 operator/(const float s, const float4& a)
{
return make_float4( s/a.x, s/a.y, s/a.z, s/a.w );
}
inline void operator/=(float4& a, const float s)
{
float inv = 1.0f / s;
a *= inv;
}
/* dot product */
inline float dot(const float4& a, const float4& b)
{
return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
}
/* length */
inline float length(const float4& r)
{
return sqrtf(dot(r, r));
}
/* normalize */
inline float4 normalize(const float4& v)
{
float invLen = 1.0f / sqrtf(dot(v, v));
return v * invLen;
}
/* floor */
inline float4 floor(const float4& v)
{
return make_float4(::floorf(v.x), ::floorf(v.y), ::floorf(v.z), ::floorf(v.w));
}
/* reflect */
inline float4 reflect(const float4& i, const float4& n)
{
return i - 2.0f * n * dot(n,i);
}
/* faceforward */
/* Returns N if dot(i, nref) > 0; else -N; */
/* Typical usage is N = faceforward(N, -ray.dir, N); */
/* Note that this is opposite of what faceforward does in Cg and GLSL */
inline float4 faceforward(const float4& n, const float4& i, const float4& nref)
{
return n * copysignf( 1.0f, dot(i, nref) );
}
/* exp */
inline float4 expf(const float4& v)
{
return make_float4(::expf(v.x), ::expf(v.y), ::expf(v.z), ::expf(v.w));
}
/* float3 functions */
/******************************************************************************/
/* constructors */
inline float3 make_float3(const float a1, const float a2, const float a3)
{
float3 f3 = {a1, a2, a3};
return f3;
}
inline float3 make_float3(const float s)
{
return make_float3(s, s, s);
}
inline float3 make_float3(const float2& a)
{
return make_float3(a.x, a.y, 0.0f);
}
inline float3 make_float3(const int3& a)
{
return make_float3(float(a.x), float(a.y), float(a.z));
}
inline float3 make_float3(const uint3& a)
{
return make_float3(float(a.x), float(a.y), float(a.z));
}
/* min */
inline float3 fminf3(const float3& a, const float3& b)
{
return make_float3(fminf(a.x,b.x), fminf(a.y,b.y), fminf(a.z,b.z));
}
inline float fminf3(const float3& a)
{
return fminf(fminf(a.x, a.y), a.z);
}
/* max */
inline float3 fmaxf3(const float3& a, const float3& b)
{
return make_float3(fmaxf(a.x,b.x), fmaxf(a.y,b.y), fmaxf(a.z,b.z));
}
inline float fmaxf3(const float3& a)
{
return fmaxf(fmaxf(a.x, a.y), a.z);
}
/* dot product */
inline float dot3(const float3& a, const float3& b)
{
return a.x * b.x + a.y * b.y + a.z * b.z;
}
/* cross product */
inline float3 cross(const float3& a, const float3& b)
{
return make_float3(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x);
}
/* length */
inline float length3(const float3& v)
{
return sqrtf(dot(v, v));
}
/* normalize */
inline float3 normalize3(const float3& v)
{
float invLen = 1.0f / sqrtf(dot(v, v));
return v * invLen;
}
/* reflect */
inline float3 reflect3(const float3& i, const float3& n)
{
return i - 2.0f * n * dot(n,i);
}
/* faceforward */
/* Returns N if dot(i, nref) > 0; else -N; */
/* Typical usage is N = faceforward(N, -ray.dir, N); */
/* Note that this is opposite of what faceforward does in Cg and GLSL */
inline float3 faceforward3(const float3& n, const float3& i, const float3& nref)
{
return n * copysignf( 1.0f, dot(i, nref) );
}
// Stream out
inline ostream& operator<<( ostream& out, const float3& f )
{
out << "FLOAT3{" << f.x << "," << f.y << "," << f.z << "}";
return out;
}
/* int2 functions */
/******************************************************************************/
/* additional constructors */
inline int2 make_int2(const int a1, const int a2)
{
int2 i2 = {a1, a2};
return i2;
}
inline int2 make_int2(const int s)
{
return make_int2(s, s);
}
inline int2 make_int2(const float2& a)
{
return make_int2(int(a.x), int(a.y));
}
/* negate */
inline int2 operator-(const int2& a)
{
return make_int2(-a.x, -a.y);
}
/* min */
inline int2 min(const int2& a, const int2& b)
{
return make_int2(min(a.x,b.x), min(a.y,b.y));
}
/* max */
inline int2 max(const int2& a, const int2& b)
{
return make_int2(max(a.x,b.x), max(a.y,b.y));
}
/* add */
inline int2 operator+(const int2& a, const int2& b)
{
return make_int2(a.x + b.x, a.y + b.y);
}
inline void operator+=(int2& a, const int2& b)
{
a.x += b.x; a.y += b.y;
}
/* subtract */
inline int2 operator-(const int2& a, const int2& b)
{
return make_int2(a.x - b.x, a.y - b.y);
}
inline int2 operator-(const int2& a, const int b)
{
return make_int2(a.x - b, a.y - b);
}
inline void operator-=(int2& a, const int2& b)
{
a.x -= b.x; a.y -= b.y;
}
/* multiply */
inline int2 operator*(const int2& a, const int2& b)
{
return make_int2(a.x * b.x, a.y * b.y);
}
inline int2 operator*(const int2& a, const int s)
{
return make_int2(a.x * s, a.y * s);
}
inline int2 operator*(const int s, const int2& a)
{
return make_int2(a.x * s, a.y * s);
}
inline void operator*=(int2& a, const int s)
{
a.x *= s; a.y *= s;
}
/* equality */
inline bool operator==(const int2& a, const int2& b)
{
return a.x == b.x && a.y == b.y;
}
inline bool operator!=(const int2& a, const int2& b)
{
return a.x != b.x || a.y != b.y;
}
/* int3 functions */
/******************************************************************************/
/* constructors */
inline int3 make_int3(const int a1, const int a2, const int a3)
{
int3 i3 = {a1, a2, a3};
return i3;
}
inline int3 make_int3(const int s)
{
return make_int3(s, s, s);
}
inline int3 make_int3(const float3& a)
{
return make_int3(int(a.x), int(a.y), int(a.z));
}
/* int4 functions */
/******************************************************************************/
/* constructors */
inline int4 make_int4(const int a1, const int a2, const int a3, const int a4)
{
int4 i4 = {a1, a2, a3, a4};
return i4;
}
inline int4 make_int4(const int s)
{
return make_int4(s, s, s, s);
}
inline int4 make_int4(const float4& a)
{
return make_int4((int)a.x, (int)a.y, (int)a.z, (int)a.w);
}
/* negate */
inline int4 operator-(const int4& a)
{
return make_int4(-a.x, -a.y, -a.z, -a.w);
}
/* min */
inline int4 min(const int4& a, const int4& b)
{
return make_int4(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z), min(a.w,b.w));
}
/* max */
inline int4 max(const int4& a, const int4& b)
{
return make_int4(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z), max(a.w,b.w));
}
/* add */
inline int4 operator+(const int4& a, const int4& b)
{
return make_int4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
}
inline void operator+=(int4& a, const int4& b)
{
a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w;
}
/* subtract */
inline int4 operator-(const int4& a, const int4& b)
{
return make_int4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
}
inline void operator-=(int4& a, const int4& b)
{
a.x -= b.x; a.y -= b.y; a.z -= b.z; a.w -= b.w;
}
/* multiply */
inline int4 operator*(const int4& a, const int4& b)
{
return make_int4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
}
inline int4 operator*(const int4& a, const int s)
{
return make_int4(a.x * s, a.y * s, a.z * s, a.w * s);
}
inline int4 operator*(const int s, const int4& a)
{
return make_int4(a.x * s, a.y * s, a.z * s, a.w * s);
}
inline void operator*=(int4& a, const int s)
{
a.x *= s; a.y *= s; a.z *= s; a.w *= s;
}
/* divide */
inline int4 operator/(const int4& a, const int4& b)
{
return make_int4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
}
inline int4 operator/(const int4& a, const int s)
{
return make_int4(a.x / s, a.y / s, a.z / s, a.w / s);
}
inline int4 operator/(const int s, const int4& a)
{
return make_int4(s / a.x, s / a.y, s / a.z, s / a.w);
}
inline void operator/=(int4& a, const int s)
{
a.x /= s; a.y /= s; a.z /= s; a.w /= s;
}
/* equality */
inline bool operator==(const int4& a, const int4& b)
{
return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w;
}
inline bool operator!=(const int4& a, const int4& b)
{
return a.x != b.x || a.y != b.y || a.z != b.z || a.w != b.w;
}
/* uint2 functions */
/******************************************************************************/
/* constructors */
inline uint2 make_uint2(const unsigned int a1, const unsigned int a2)
{
uint2 ui2 = {a1, a2};
return ui2;
}
inline uint2 make_uint2(const unsigned int s)
{
return make_uint2(s, s);
}
inline uint2 make_uint2(const float2& a)
{
return make_uint2((unsigned int)a.x, (unsigned int)a.y);
}
/* min */
inline uint2 min(const uint2& a, const uint2& b)
{
return make_uint2(min(a.x,b.x), min(a.y,b.y));
}
/* max */
inline uint2 max(const uint2& a, const uint2& b)
{
return make_uint2(max(a.x,b.x), max(a.y,b.y));
}
/* add */
inline uint2 operator+(const uint2& a, const uint2& b)
{
return make_uint2(a.x + b.x, a.y + b.y);
}
inline void operator+=(uint2& a, const uint2& b)
{
a.x += b.x; a.y += b.y;
}
/* subtract */
inline uint2 operator-(const uint2& a, const uint2& b)
{
return make_uint2(a.x - b.x, a.y - b.y);
}
inline uint2 operator-(const uint2& a, const unsigned int b)
{
return make_uint2(a.x - b, a.y - b);
}
inline void operator-=(uint2& a, const uint2& b)
{
a.x -= b.x; a.y -= b.y;
}
/* multiply */
inline uint2 operator*(const uint2& a, const uint2& b)
{
return make_uint2(a.x * b.x, a.y * b.y);
}
inline uint2 operator*(const uint2& a, const unsigned int s)
{
return make_uint2(a.x * s, a.y * s);
}
inline uint2 operator*(const unsigned int s, const uint2& a)
{
return make_uint2(a.x * s, a.y * s);
}
inline void operator*=(uint2& a, const unsigned int s)
{
a.x *= s; a.y *= s;
}
/* equality */
inline bool operator==(const uint2& a, const uint2& b)
{
return a.x == b.x && a.y == b.y;
}
inline bool operator!=(const uint2& a, const uint2& b)
{
return a.x != b.x || a.y != b.y;
}
/* uint3 functions */
/******************************************************************************/
/* constructors */
inline uint3 make_uint3(const unsigned int a1, const unsigned int a2, const unsigned int a3)
{
uint3 ui3 = {a1, a2, a3};
return ui3;
}
inline uint3 make_uint3(const unsigned int s)
{
return make_uint3(s, s, s);
}
inline uint3 make_uint3(const float3& a)
{
return make_uint3((unsigned int)a.x, (unsigned int)a.y, (unsigned int)a.z);
}
/* uint4 functions */
/******************************************************************************/
/* constructors */
inline uint4 make_uint4(const unsigned int a1, const unsigned int a2, const unsigned int a3, const unsigned int a4)
{
uint4 ui4 = {a1, a2, a3, a4};
return ui4;
}
inline uint4 make_uint4(const unsigned int s)
{
return make_uint4(s, s, s, s);
}
inline uint4 make_uint4(const float4& a)
{
return make_uint4((unsigned int)a.x, (unsigned int)a.y, (unsigned int)a.z, (unsigned int)a.w);
}
/* min */
inline uint4 min(const uint4& a, const uint4& b)
{
return make_uint4(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z), min(a.w,b.w));
}
/* max */
inline uint4 max(const uint4& a, const uint4& b)
{
return make_uint4(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z), max(a.w,b.w));
}
/* add */
inline uint4 operator+(const uint4& a, const uint4& b)
{
return make_uint4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
}
inline void operator+=(uint4& a, const uint4& b)
{
a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w;
}
/* subtract */
inline uint4 operator-(const uint4& a, const uint4& b)
{
return make_uint4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
}
inline void operator-=(uint4& a, const uint4& b)
{
a.x -= b.x; a.y -= b.y; a.z -= b.z; a.w -= b.w;
}
/* multiply */
inline uint4 operator*(const uint4& a, const uint4& b)
{
return make_uint4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
}
inline uint4 operator*(const uint4& a, const unsigned int s)
{
return make_uint4(a.x * s, a.y * s, a.z * s, a.w * s);
}
inline uint4 operator*(const unsigned int s, const uint4& a)
{
return make_uint4(a.x * s, a.y * s, a.z * s, a.w * s);
}
inline void operator*=(uint4& a, const unsigned int s)
{
a.x *= s; a.y *= s; a.z *= s; a.w *= s;
}
/* divide */
inline uint4 operator/(const uint4& a, const uint4& b)
{
return make_uint4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
}
inline uint4 operator/(const uint4& a, const unsigned int s)
{
return make_uint4(a.x / s, a.y / s, a.z / s, a.w / s);
}
inline uint4 operator/(const unsigned int s, const uint4& a)
{
return make_uint4(s / a.x, s / a.y, s / a.z, s / a.w);
}
inline void operator/=(uint4& a, const unsigned int s)
{
a.x /= s; a.y /= s; a.z /= s; a.w /= s;
}
/* equality */
inline bool operator==(const uint4& a, const uint4& b)
{
return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w;
}
inline bool operator!=(const uint4& a, const uint4& b)
{
return a.x != b.x || a.y != b.y || a.z != b.z || a.w != b.w;
}
/******************************************************************************/
/* Narrowing */
inline int2 make_int2(const int4& v0) { return make_int2( v0.x, v0.y ); }
inline int3 make_int3(const int4& v0) { return make_int3( v0.x, v0.y, v0.z ); }
inline uint2 make_uint2(const uint4& v0) { return make_uint2( v0.x, v0.y ); }
inline uint3 make_uint3(const uint4& v0) { return make_uint3( v0.x, v0.y, v0.z ); }
inline float2 make_float2(const float4& v0) { return make_float2( v0.x, v0.y ); }
inline float3 make_float3(const float4& v0) { return make_float3( v0.x, v0.y, v0.z ); }
/* Assemble from smaller vectors */
inline int3 make_int3(const int v0, const int2& v1) { return make_int3( v0, v1.x, v1.y ); }
inline int3 make_int3(const int2& v0, const int v1) { return make_int3( v0.x, v0.y, v1 ); }
inline int4 make_int4(const int v0, const int v1, const int2& v2) { return make_int4( v0, v1, v2.x, v2.y ); }
inline int4 make_int4(const int v0, const int2& v1, const int v2) { return make_int4( v0, v1.x, v1.y, v2 ); }
inline int4 make_int4(const int2& v0, const int v1, const int v2) { return make_int4( v0.x, v0.y, v1, v2 ); }
inline int4 make_int4(const int v0, const int3& v1) { return make_int4( v0, v1.x, v1.y, v1.z ); }
inline int4 make_int4(const int3& v0, const int v1) { return make_int4( v0.x, v0.y, v0.z, v1 ); }
inline int4 make_int4(const int2& v0, const int2& v1) { return make_int4( v0.x, v0.y, v1.x, v1.y ); }
inline uint3 make_uint3(const unsigned int v0, const uint2& v1) { return make_uint3( v0, v1.x, v1.y ); }
inline uint3 make_uint3(const uint2& v0, const unsigned int v1) { return make_uint3( v0.x, v0.y, v1 ); }
inline uint4 make_uint4(const unsigned int v0, const unsigned int v1, const uint2& v2) { return make_uint4( v0, v1, v2.x, v2.y ); }
inline uint4 make_uint4(const unsigned int v0, const uint2& v1, const unsigned int v2) { return make_uint4( v0, v1.x, v1.y, v2 ); }
inline uint4 make_uint4(const uint2& v0, const unsigned int v1, const unsigned int v2) { return make_uint4( v0.x, v0.y, v1, v2 ); }
inline uint4 make_uint4(const unsigned int v0, const uint3& v1) { return make_uint4( v0, v1.x, v1.y, v1.z ); }
inline uint4 make_uint4(const uint3& v0, const unsigned int v1) { return make_uint4( v0.x, v0.y, v0.z, v1 ); }
inline uint4 make_uint4(const uint2& v0, const uint2& v1) { return make_uint4( v0.x, v0.y, v1.x, v1.y ); }
inline float3 make_float3(const float2& v0, const float v1) { return make_float3(v0.x, v0.y, v1); }
inline float3 make_float3(const float v0, const float2& v1) { return make_float3( v0, v1.x, v1.y ); }
inline float4 make_float4(const float v0, const float v1, const float2& v2) { return make_float4( v0, v1, v2.x, v2.y ); }
inline float4 make_float4(const float v0, const float2& v1, const float v2) { return make_float4( v0, v1.x, v1.y, v2 ); }
inline float4 make_float4(const float2& v0, const float v1, const float v2) { return make_float4( v0.x, v0.y, v1, v2 ); }
inline float4 make_float4(const float v0, const float3& v1) { return make_float4( v0, v1.x, v1.y, v1.z ); }
inline float4 make_float4(const float3& v0, const float v1) { return make_float4( v0.x, v0.y, v0.z, v1 ); }
inline float4 make_float4(const float2& v0, const float2& v1) { return make_float4( v0.x, v0.y, v1.x, v1.y ); }
#endif