1 | // |
---|
2 | // Lol Engine |
---|
3 | // |
---|
4 | // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> |
---|
5 | // This program is free software; you can redistribute it and/or |
---|
6 | // modify it under the terms of the Do What The Fuck You Want To |
---|
7 | // Public License, Version 2, as published by Sam Hocevar. See |
---|
8 | // http://www.wtfpl.net/ for more details. |
---|
9 | // |
---|
10 | |
---|
11 | #pragma once |
---|
12 | |
---|
13 | #include <stdint.h> |
---|
14 | |
---|
15 | namespace lol |
---|
16 | { |
---|
17 | |
---|
18 | /* It’s nice to have single-word type names, so define this. */ |
---|
19 | typedef long double ldouble; |
---|
20 | |
---|
21 | /* The “real” type used for real numbers. It’s a specialisation of the |
---|
22 | * “Real” template class. */ |
---|
23 | template<int N> class Real; |
---|
24 | typedef Real<16> real; |
---|
25 | |
---|
26 | /* The “half” type used for 16-bit floating point numbers. */ |
---|
27 | class half; |
---|
28 | |
---|
29 | /* |
---|
30 | * Forward declaration of vec_t, mat_t, cmplx_t, quat_t |
---|
31 | */ |
---|
32 | |
---|
33 | /* HACK: if this is declared int const, Visual Studio becomes unable |
---|
34 | * to perform template argument deduction. */ |
---|
35 | #define FULL_SWIZZLE (0) |
---|
36 | |
---|
37 | template<typename T, int N, int SWIZZLE = FULL_SWIZZLE> struct vec_t; |
---|
38 | template<typename T, int COLS, int ROWS> struct mat_t; |
---|
39 | template<typename T> struct cmplx_t; |
---|
40 | template<typename T> struct quat_t; |
---|
41 | template<typename T> struct dualquat_t; |
---|
42 | |
---|
43 | /* |
---|
44 | * Generic GLSL-like type names |
---|
45 | */ |
---|
46 | |
---|
47 | #define _T(tleft, tright, suffix) \ |
---|
48 | typedef tleft half tright f16##suffix; \ |
---|
49 | typedef tleft float tright suffix; \ |
---|
50 | typedef tleft double tright d##suffix; \ |
---|
51 | typedef tleft ldouble tright f128##suffix; \ |
---|
52 | typedef tleft int8_t tright i8##suffix; \ |
---|
53 | typedef tleft uint8_t tright u8##suffix; \ |
---|
54 | typedef tleft int16_t tright i16##suffix; \ |
---|
55 | typedef tleft uint16_t tright u16##suffix; \ |
---|
56 | typedef tleft int32_t tright i##suffix; \ |
---|
57 | typedef tleft uint32_t tright u##suffix; \ |
---|
58 | typedef tleft int64_t tright i64##suffix; \ |
---|
59 | typedef tleft uint64_t tright u64##suffix; \ |
---|
60 | typedef tleft real tright r##suffix; |
---|
61 | |
---|
62 | /* Idiotic hack to put "," inside a macro argument */ |
---|
63 | #define _C , |
---|
64 | |
---|
65 | _T(vec_t<, _C 2>, vec2) |
---|
66 | _T(vec_t<, _C 3>, vec3) |
---|
67 | _T(vec_t<, _C 4>, vec4) |
---|
68 | _T(vec_t<, _C 5>, vec5) |
---|
69 | _T(vec_t<, _C 6>, vec6) |
---|
70 | _T(vec_t<, _C 7>, vec7) |
---|
71 | _T(vec_t<, _C 8>, vec8) |
---|
72 | _T(vec_t<, _C 9>, vec9) |
---|
73 | _T(vec_t<, _C 10>, vec10) |
---|
74 | _T(vec_t<, _C 11>, vec11) |
---|
75 | _T(vec_t<, _C 12>, vec12) |
---|
76 | |
---|
77 | _T(mat_t<, _C 2 _C 2>, mat2) |
---|
78 | _T(mat_t<, _C 3 _C 3>, mat3) |
---|
79 | _T(mat_t<, _C 4 _C 4>, mat4) |
---|
80 | |
---|
81 | _T(mat_t<, _C 2 _C 3>, mat2x3) |
---|
82 | _T(mat_t<, _C 2 _C 4>, mat2x4) |
---|
83 | _T(mat_t<, _C 3 _C 2>, mat3x2) |
---|
84 | _T(mat_t<, _C 3 _C 4>, mat3x4) |
---|
85 | _T(mat_t<, _C 4 _C 2>, mat4x2) |
---|
86 | _T(mat_t<, _C 4 _C 3>, mat4x3) |
---|
87 | |
---|
88 | _T(cmplx_t<, >, cmplx) |
---|
89 | _T(quat_t<, >, quat) |
---|
90 | _T(dualquat_t<, >, dualquat) |
---|
91 | |
---|
92 | #undef _C |
---|
93 | #undef _T |
---|
94 | |
---|
95 | /* |
---|
96 | * Practical useage typedefs |
---|
97 | */ |
---|
98 | typedef vec4 color; |
---|
99 | typedef vec2 spheric2; |
---|
100 | typedef vec3 spheric3; |
---|
101 | |
---|
102 | /* |
---|
103 | * HLSL/Cg-compliant type names |
---|
104 | */ |
---|
105 | |
---|
106 | typedef vec2 float2; |
---|
107 | typedef vec3 float3; |
---|
108 | typedef vec4 float4; |
---|
109 | typedef vec5 float5; |
---|
110 | typedef vec6 float6; |
---|
111 | typedef vec7 float7; |
---|
112 | typedef vec8 float8; |
---|
113 | typedef vec9 float9; |
---|
114 | typedef vec10 float10; |
---|
115 | typedef vec11 float11; |
---|
116 | typedef vec12 float12; |
---|
117 | typedef mat2 float2x2; |
---|
118 | typedef mat3 float3x3; |
---|
119 | typedef mat4 float4x4; |
---|
120 | typedef mat2x3 float2x3; |
---|
121 | typedef mat2x4 float2x4; |
---|
122 | typedef mat3x2 float3x2; |
---|
123 | typedef mat3x4 float3x4; |
---|
124 | typedef mat4x2 float4x2; |
---|
125 | typedef mat4x3 float4x3; |
---|
126 | |
---|
127 | typedef f16vec2 half2; |
---|
128 | typedef f16vec3 half3; |
---|
129 | typedef f16vec4 half4; |
---|
130 | typedef f16mat2 half2x2; |
---|
131 | typedef f16mat3 half3x3; |
---|
132 | typedef f16mat4 half4x4; |
---|
133 | typedef f16mat2x3 half2x3; |
---|
134 | typedef f16mat2x4 half2x4; |
---|
135 | typedef f16mat3x2 half3x2; |
---|
136 | typedef f16mat3x4 half3x4; |
---|
137 | typedef f16mat4x2 half4x2; |
---|
138 | typedef f16mat4x3 half4x3; |
---|
139 | |
---|
140 | typedef ivec2 int2; |
---|
141 | typedef ivec3 int3; |
---|
142 | typedef ivec4 int4; |
---|
143 | typedef ivec5 int5; |
---|
144 | typedef ivec6 int6; |
---|
145 | typedef ivec7 int7; |
---|
146 | typedef ivec8 int8; |
---|
147 | typedef ivec9 int9; |
---|
148 | typedef ivec10 int10; |
---|
149 | typedef ivec11 int11; |
---|
150 | typedef ivec12 int12; |
---|
151 | typedef imat2 int2x2; |
---|
152 | typedef imat3 int3x3; |
---|
153 | typedef imat4 int4x4; |
---|
154 | typedef imat2x3 int2x3; |
---|
155 | typedef imat2x4 int2x4; |
---|
156 | typedef imat3x2 int3x2; |
---|
157 | typedef imat3x4 int3x4; |
---|
158 | typedef imat4x2 int4x2; |
---|
159 | typedef imat4x3 int4x3; |
---|
160 | |
---|
161 | } /* namespace lol */ |
---|
162 | |
---|