1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
28
29
30
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
86
87
88
89
90
91
92
93
94
95
96
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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
159
160
161
162
163
164
165
166
167
168
169
173
174
175
176
177
178
179
180
181
182
183
187
188
189
190
191
192
193
194
195
196
197
198
199
200
204
208
209
210
211
216
221
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
252
258
259
260
261
262
263
264
265
266
267
268
269
270
271
293
294
295
/* ... */
#ifndef TEXTUREMAPTYPES_HPP
#define TEXTUREMAPTYPES_HPP
#include <touchgfx/hal/Types.hpp>
namespace touchgfx
{
/* ... */
struct Gradients
{
/* ... */
Gradients(const Point3D* vertices);
float oneOverZ[3];
float UOverZ[3];
float VOverZ[3];
float dOneOverZdX;
float dOneOverZdY;
float dUOverZdX;
float dUOverZdY;
float dVOverZdX;
float dVOverZdY;
fixed16_16 dUdXModifier;
fixed16_16 dVdXModifier;
...};
/* ... */
struct Edge
{
/* ... */
Edge(const Gradients& gradients, const Point3D* vertices, int top, int bottom);
/* ... */
inline int step()
{
X += XStep;
Y++;
height--;
UOverZ += UOverZStep;
VOverZ += VOverZStep;
oneOverZ += oneOverZStep;
errorTerm += numerator;
if (errorTerm >= denominator)
{
X++;
errorTerm -= denominator;
oneOverZ += oneOverZStepExtra;
UOverZ += UOverZStepExtra;
VOverZ += VOverZStepExtra;
}if (errorTerm >= denominator) { ... }
return height;
}{ ... }
/* ... */
inline int step(int steps)
{
for (int i = 0; i < steps; i++)
{
step();
}for (int i = 0; i < steps; i++) { ... }
return height;
}{ ... }
int32_t X;
int32_t XStep;
int32_t numerator;
int32_t denominator;
int32_t errorTerm;
int Y;
int height;
float oneOverZ;
float oneOverZStep;
float oneOverZStepExtra;
float UOverZ;
float UOverZStep;
float UOverZStepExtra;
float VOverZ;
float VOverZStep;
float VOverZStepExtra;
...};
/* ... */
inline float fixed28_4ToFloat(fixed28_4 value)
{
return value / 16.0f;
}{ ... }
/* ... */
inline fixed28_4 floatToFixed28_4(float value)
{
return (fixed28_4)(value * 16);
}{ ... }
/* ... */
inline fixed16_16 floatToFixed16_16(float value)
{
return (fixed16_16)(value * 65536);
}{ ... }
/* ... */
inline fixed28_4 fixed28_4Mul(fixed28_4 a, fixed28_4 b)
{
if (a == 0 || b == 0)
{
return 0;
}if (a == 0 || b == 0) { ... }
if ((a * b) / b == a)
{
return (a * b) / 16;
}if ((a * b) / b == a) { ... }
int sign = 1;
if (b < 0)
{
sign = -sign;
b = -b;
}if (b < 0) { ... }
if (a < 0)
{
sign = -sign;
a = -a;
}if (a < 0) { ... }
if (a < b)
{
fixed28_4 tmp = a;
a = b;
b = tmp;
}if (a < b) { ... }
int32_t max_b = 0x7FFFFFFF / a;
int32_t num_max_b = b / max_b;
int32_t rem_b = b - max_b * num_max_b;
int32_t max_prod = a * max_b;
int32_t result = sign * (num_max_b * (max_prod / 16) + (num_max_b * (max_prod % 16) + rem_b * a) / 16);
return result;
}{ ... }
/* ... */
inline int32_t ceil28_4(fixed28_4 value)
{
int32_t returnValue;
int32_t numerator = value - 1 + 16;
if (numerator >= 0)
{
returnValue = numerator / 16;
}if (numerator >= 0) { ... }
else
{
returnValue = -((-numerator) / 16);
returnValue -= ((-numerator) % 16) ? 1 : 0;
}else { ... }
return returnValue;
}{ ... }
/* ... */
inline void floorDivMod(int32_t numerator, int32_t denominator, int32_t& floor, int32_t& mod)
{
assert(denominator > 0);
if (numerator >= 0)
{
floor = numerator / denominator;
mod = numerator % denominator;
}if (numerator >= 0) { ... }
else
{
floor = -((-numerator) / denominator);
mod = (-numerator) % denominator;
if (mod)
{
floor--;
mod = denominator - mod;
}if (mod) { ... }
}else { ... }
}{ ... }
}...
/* ... */
#endif