diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CTRTextureLightMap2_M4.cpp | 2308 |
1 files changed, 1154 insertions, 1154 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CTRTextureLightMap2_M4.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CTRTextureLightMap2_M4.cpp index 989a915..71c1770 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/CTRTextureLightMap2_M4.cpp +++ b/libraries/irrlicht-1.8/source/Irrlicht/CTRTextureLightMap2_M4.cpp | |||
@@ -1,1154 +1,1154 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt / Thomas Alten | 1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt / Thomas Alten |
2 | // This file is part of the "Irrlicht Engine". | 2 | // This file is part of the "Irrlicht Engine". |
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h |
4 | 4 | ||
5 | #include "IrrCompileConfig.h" | 5 | #include "IrrCompileConfig.h" |
6 | #include "IBurningShader.h" | 6 | #include "IBurningShader.h" |
7 | 7 | ||
8 | #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_ | 8 | #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_ |
9 | 9 | ||
10 | // compile flag for this file | 10 | // compile flag for this file |
11 | #undef USE_ZBUFFER | 11 | #undef USE_ZBUFFER |
12 | #undef IPOL_Z | 12 | #undef IPOL_Z |
13 | #undef CMP_Z | 13 | #undef CMP_Z |
14 | #undef WRITE_Z | 14 | #undef WRITE_Z |
15 | 15 | ||
16 | #undef IPOL_W | 16 | #undef IPOL_W |
17 | #undef CMP_W | 17 | #undef CMP_W |
18 | #undef WRITE_W | 18 | #undef WRITE_W |
19 | 19 | ||
20 | #undef SUBTEXEL | 20 | #undef SUBTEXEL |
21 | #undef INVERSE_W | 21 | #undef INVERSE_W |
22 | 22 | ||
23 | #undef IPOL_C0 | 23 | #undef IPOL_C0 |
24 | #undef IPOL_T0 | 24 | #undef IPOL_T0 |
25 | #undef IPOL_T1 | 25 | #undef IPOL_T1 |
26 | 26 | ||
27 | // define render case | 27 | // define render case |
28 | #define SUBTEXEL | 28 | #define SUBTEXEL |
29 | #define INVERSE_W | 29 | #define INVERSE_W |
30 | 30 | ||
31 | #define USE_ZBUFFER | 31 | #define USE_ZBUFFER |
32 | #define IPOL_W | 32 | #define IPOL_W |
33 | #define CMP_W | 33 | #define CMP_W |
34 | #define WRITE_W | 34 | #define WRITE_W |
35 | 35 | ||
36 | //#define IPOL_C0 | 36 | //#define IPOL_C0 |
37 | #define IPOL_T0 | 37 | #define IPOL_T0 |
38 | #define IPOL_T1 | 38 | #define IPOL_T1 |
39 | 39 | ||
40 | // apply global override | 40 | // apply global override |
41 | #ifndef SOFTWARE_DRIVER_2_PERSPECTIVE_CORRECT | 41 | #ifndef SOFTWARE_DRIVER_2_PERSPECTIVE_CORRECT |
42 | #undef INVERSE_W | 42 | #undef INVERSE_W |
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | #ifndef SOFTWARE_DRIVER_2_SUBTEXEL | 45 | #ifndef SOFTWARE_DRIVER_2_SUBTEXEL |
46 | #undef SUBTEXEL | 46 | #undef SUBTEXEL |
47 | #endif | 47 | #endif |
48 | 48 | ||
49 | #ifndef SOFTWARE_DRIVER_2_USE_VERTEX_COLOR | 49 | #ifndef SOFTWARE_DRIVER_2_USE_VERTEX_COLOR |
50 | #undef IPOL_C0 | 50 | #undef IPOL_C0 |
51 | #endif | 51 | #endif |
52 | 52 | ||
53 | #if !defined ( SOFTWARE_DRIVER_2_USE_WBUFFER ) && defined ( USE_ZBUFFER ) | 53 | #if !defined ( SOFTWARE_DRIVER_2_USE_WBUFFER ) && defined ( USE_ZBUFFER ) |
54 | #ifndef SOFTWARE_DRIVER_2_PERSPECTIVE_CORRECT | 54 | #ifndef SOFTWARE_DRIVER_2_PERSPECTIVE_CORRECT |
55 | #undef IPOL_W | 55 | #undef IPOL_W |
56 | #endif | 56 | #endif |
57 | #define IPOL_Z | 57 | #define IPOL_Z |
58 | 58 | ||
59 | #ifdef CMP_W | 59 | #ifdef CMP_W |
60 | #undef CMP_W | 60 | #undef CMP_W |
61 | #define CMP_Z | 61 | #define CMP_Z |
62 | #endif | 62 | #endif |
63 | 63 | ||
64 | #ifdef WRITE_W | 64 | #ifdef WRITE_W |
65 | #undef WRITE_W | 65 | #undef WRITE_W |
66 | #define WRITE_Z | 66 | #define WRITE_Z |
67 | #endif | 67 | #endif |
68 | 68 | ||
69 | #endif | 69 | #endif |
70 | 70 | ||
71 | namespace irr | 71 | namespace irr |
72 | { | 72 | { |
73 | 73 | ||
74 | namespace video | 74 | namespace video |
75 | { | 75 | { |
76 | 76 | ||
77 | class CTRTextureLightMap2_M4 : public IBurningShader | 77 | class CTRTextureLightMap2_M4 : public IBurningShader |
78 | { | 78 | { |
79 | public: | 79 | public: |
80 | 80 | ||
81 | //! constructor | 81 | //! constructor |
82 | CTRTextureLightMap2_M4(CBurningVideoDriver* driver); | 82 | CTRTextureLightMap2_M4(CBurningVideoDriver* driver); |
83 | 83 | ||
84 | //! draws an indexed triangle list | 84 | //! draws an indexed triangle list |
85 | virtual void drawTriangle ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c ); | 85 | virtual void drawTriangle ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c ); |
86 | 86 | ||
87 | 87 | ||
88 | private: | 88 | private: |
89 | 89 | ||
90 | void drawTriangle_Min ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c ); | 90 | void drawTriangle_Min ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c ); |
91 | void drawTriangle_Mag ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c ); | 91 | void drawTriangle_Mag ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c ); |
92 | 92 | ||
93 | void scanline_bilinear (); | 93 | void scanline_bilinear (); |
94 | void scanline_bilinear2_mag (); | 94 | void scanline_bilinear2_mag (); |
95 | void scanline_bilinear2_min (); | 95 | void scanline_bilinear2_min (); |
96 | 96 | ||
97 | sScanLineData line; | 97 | sScanLineData line; |
98 | 98 | ||
99 | }; | 99 | }; |
100 | 100 | ||
101 | //! constructor | 101 | //! constructor |
102 | CTRTextureLightMap2_M4::CTRTextureLightMap2_M4(CBurningVideoDriver* driver) | 102 | CTRTextureLightMap2_M4::CTRTextureLightMap2_M4(CBurningVideoDriver* driver) |
103 | : IBurningShader(driver) | 103 | : IBurningShader(driver) |
104 | { | 104 | { |
105 | #ifdef _DEBUG | 105 | #ifdef _DEBUG |
106 | setDebugName("CTRTextureLightMap2_M4"); | 106 | setDebugName("CTRTextureLightMap2_M4"); |
107 | #endif | 107 | #endif |
108 | } | 108 | } |
109 | 109 | ||
110 | /*! | 110 | /*! |
111 | */ | 111 | */ |
112 | REALINLINE void CTRTextureLightMap2_M4::scanline_bilinear2_mag () | 112 | REALINLINE void CTRTextureLightMap2_M4::scanline_bilinear2_mag () |
113 | { | 113 | { |
114 | tVideoSample *dst; | 114 | tVideoSample *dst; |
115 | fp24 *z; | 115 | fp24 *z; |
116 | 116 | ||
117 | // apply top-left fill-convention, left | 117 | // apply top-left fill-convention, left |
118 | const s32 xStart = irr::core::ceil32( line.x[0] ); | 118 | const s32 xStart = irr::core::ceil32( line.x[0] ); |
119 | const s32 xEnd = irr::core::ceil32( line.x[1] ) - 1; | 119 | const s32 xEnd = irr::core::ceil32( line.x[1] ) - 1; |
120 | s32 dx; | 120 | s32 dx; |
121 | s32 i; | 121 | s32 i; |
122 | 122 | ||
123 | 123 | ||
124 | dx = xEnd - xStart; | 124 | dx = xEnd - xStart; |
125 | if ( dx < 0 ) | 125 | if ( dx < 0 ) |
126 | return; | 126 | return; |
127 | 127 | ||
128 | // slopes | 128 | // slopes |
129 | const f32 invDeltaX = core::reciprocal_approxim ( line.x[1] - line.x[0] ); | 129 | const f32 invDeltaX = core::reciprocal_approxim ( line.x[1] - line.x[0] ); |
130 | 130 | ||
131 | // search z-buffer for first not occulled pixel | 131 | // search z-buffer for first not occulled pixel |
132 | i = ( line.y * RenderTarget->getDimension().Width ) + xStart; | 132 | i = ( line.y * RenderTarget->getDimension().Width ) + xStart; |
133 | z = (fp24*) DepthBuffer->lock() + i; | 133 | z = (fp24*) DepthBuffer->lock() + i; |
134 | dst = (tVideoSample*)RenderTarget->lock() + i; | 134 | dst = (tVideoSample*)RenderTarget->lock() + i; |
135 | 135 | ||
136 | // subTexel | 136 | // subTexel |
137 | const f32 subPixel = ( (f32) xStart ) - line.x[0]; | 137 | const f32 subPixel = ( (f32) xStart ) - line.x[0]; |
138 | 138 | ||
139 | #ifdef IPOL_W | 139 | #ifdef IPOL_W |
140 | const fp24 b = (line.w[1] - line.w[0]) * invDeltaX; | 140 | const fp24 b = (line.w[1] - line.w[0]) * invDeltaX; |
141 | fp24 a = line.w[0] + ( b * subPixel ); | 141 | fp24 a = line.w[0] + ( b * subPixel ); |
142 | 142 | ||
143 | i = 0; | 143 | i = 0; |
144 | 144 | ||
145 | while ( a < z[i] ) | 145 | while ( a < z[i] ) |
146 | { | 146 | { |
147 | a += b; | 147 | a += b; |
148 | 148 | ||
149 | i += 1; | 149 | i += 1; |
150 | if ( i > dx ) | 150 | if ( i > dx ) |
151 | return; | 151 | return; |
152 | 152 | ||
153 | } | 153 | } |
154 | 154 | ||
155 | // lazy setup rest of scanline | 155 | // lazy setup rest of scanline |
156 | 156 | ||
157 | line.w[0] = a; | 157 | line.w[0] = a; |
158 | line.w[1] = b; | 158 | line.w[1] = b; |
159 | #else | 159 | #else |
160 | const f32 b = (line.z[1] - line.z[0]) * invDeltaX; | 160 | const f32 b = (line.z[1] - line.z[0]) * invDeltaX; |
161 | f32 a = line.z[0] + ( b * subPixel ); | 161 | f32 a = line.z[0] + ( b * subPixel ); |
162 | 162 | ||
163 | i = 0; | 163 | i = 0; |
164 | 164 | ||
165 | while ( a > z[i] ) | 165 | while ( a > z[i] ) |
166 | { | 166 | { |
167 | a += b; | 167 | a += b; |
168 | 168 | ||
169 | i += 1; | 169 | i += 1; |
170 | if ( i > dx ) | 170 | if ( i > dx ) |
171 | return; | 171 | return; |
172 | 172 | ||
173 | } | 173 | } |
174 | 174 | ||
175 | // lazy setup rest of scanline | 175 | // lazy setup rest of scanline |
176 | 176 | ||
177 | line.z[0] = a; | 177 | line.z[0] = a; |
178 | line.z[1] = b; | 178 | line.z[1] = b; |
179 | #endif | 179 | #endif |
180 | 180 | ||
181 | a = (f32) i + subPixel; | 181 | a = (f32) i + subPixel; |
182 | 182 | ||
183 | line.t[0][1] = (line.t[0][1] - line.t[0][0]) * invDeltaX; | 183 | line.t[0][1] = (line.t[0][1] - line.t[0][0]) * invDeltaX; |
184 | line.t[1][1] = (line.t[1][1] - line.t[1][0]) * invDeltaX; | 184 | line.t[1][1] = (line.t[1][1] - line.t[1][0]) * invDeltaX; |
185 | 185 | ||
186 | line.t[0][0] += line.t[0][1] * a; | 186 | line.t[0][0] += line.t[0][1] * a; |
187 | line.t[1][0] += line.t[1][1] * a; | 187 | line.t[1][0] += line.t[1][1] * a; |
188 | 188 | ||
189 | 189 | ||
190 | #ifdef BURNINGVIDEO_RENDERER_FAST | 190 | #ifdef BURNINGVIDEO_RENDERER_FAST |
191 | u32 dIndex = ( line.y & 3 ) << 2; | 191 | u32 dIndex = ( line.y & 3 ) << 2; |
192 | 192 | ||
193 | tFixPoint r0, g0, b0; | 193 | tFixPoint r0, g0, b0; |
194 | tFixPoint r1, g1, b1; | 194 | tFixPoint r1, g1, b1; |
195 | 195 | ||
196 | #else | 196 | #else |
197 | // | 197 | // |
198 | tFixPoint r0, g0, b0; | 198 | tFixPoint r0, g0, b0; |
199 | tFixPoint r1, g1, b1; | 199 | tFixPoint r1, g1, b1; |
200 | #endif | 200 | #endif |
201 | 201 | ||
202 | 202 | ||
203 | for ( ;i <= dx; i++ ) | 203 | for ( ;i <= dx; i++ ) |
204 | { | 204 | { |
205 | #ifdef IPOL_W | 205 | #ifdef IPOL_W |
206 | if ( line.w[0] >= z[i] ) | 206 | if ( line.w[0] >= z[i] ) |
207 | { | 207 | { |
208 | z[i] = line.w[0]; | 208 | z[i] = line.w[0]; |
209 | #else | 209 | #else |
210 | if ( line.z[0] < z[i] ) | 210 | if ( line.z[0] < z[i] ) |
211 | { | 211 | { |
212 | z[i] = line.z[0]; | 212 | z[i] = line.z[0]; |
213 | #endif | 213 | #endif |
214 | 214 | ||
215 | #ifdef SOFTWARE_DRIVER_2_PERSPECTIVE_CORRECT | 215 | #ifdef SOFTWARE_DRIVER_2_PERSPECTIVE_CORRECT |
216 | f32 inversew = fix_inverse32 ( line.w[0] ); | 216 | f32 inversew = fix_inverse32 ( line.w[0] ); |
217 | #else | 217 | #else |
218 | f32 inversew = FIX_POINT_F32_MUL; | 218 | f32 inversew = FIX_POINT_F32_MUL; |
219 | #endif | 219 | #endif |
220 | 220 | ||
221 | 221 | ||
222 | 222 | ||
223 | #ifdef BURNINGVIDEO_RENDERER_FAST | 223 | #ifdef BURNINGVIDEO_RENDERER_FAST |
224 | 224 | ||
225 | const tFixPointu d = dithermask [ dIndex | ( i ) & 3 ]; | 225 | const tFixPointu d = dithermask [ dIndex | ( i ) & 3 ]; |
226 | 226 | ||
227 | getSample_texture ( r0, g0, b0, &IT[0], d + tofix ( line.t[0][0].x,inversew), d + tofix ( line.t[0][0].y,inversew) ); | 227 | getSample_texture ( r0, g0, b0, &IT[0], d + tofix ( line.t[0][0].x,inversew), d + tofix ( line.t[0][0].y,inversew) ); |
228 | getSample_texture ( r1, g1, b1, &IT[1], d + tofix ( line.t[1][0].x,inversew), d + tofix ( line.t[1][0].y,inversew) ); | 228 | getSample_texture ( r1, g1, b1, &IT[1], d + tofix ( line.t[1][0].x,inversew), d + tofix ( line.t[1][0].y,inversew) ); |
229 | #else | 229 | #else |
230 | getSample_texture ( r0, g0, b0, &IT[0], tofix ( line.t[0][0].x,inversew), tofix ( line.t[0][0].y,inversew) ); | 230 | getSample_texture ( r0, g0, b0, &IT[0], tofix ( line.t[0][0].x,inversew), tofix ( line.t[0][0].y,inversew) ); |
231 | getSample_texture ( r1, g1, b1, &IT[1], tofix ( line.t[1][0].x,inversew), tofix ( line.t[1][0].y,inversew) ); | 231 | getSample_texture ( r1, g1, b1, &IT[1], tofix ( line.t[1][0].x,inversew), tofix ( line.t[1][0].y,inversew) ); |
232 | 232 | ||
233 | #endif | 233 | #endif |
234 | 234 | ||
235 | dst[i] = fix_to_color ( clampfix_maxcolor ( imulFix_tex4 ( r0, r1 ) ), | 235 | dst[i] = fix_to_color ( clampfix_maxcolor ( imulFix_tex4 ( r0, r1 ) ), |
236 | clampfix_maxcolor ( imulFix_tex4 ( g0, g1 ) ), | 236 | clampfix_maxcolor ( imulFix_tex4 ( g0, g1 ) ), |
237 | clampfix_maxcolor ( imulFix_tex4 ( b0, b1 ) ) | 237 | clampfix_maxcolor ( imulFix_tex4 ( b0, b1 ) ) |
238 | ); | 238 | ); |
239 | } | 239 | } |
240 | 240 | ||
241 | #ifdef IPOL_W | 241 | #ifdef IPOL_W |
242 | line.w[0] += line.w[1]; | 242 | line.w[0] += line.w[1]; |
243 | #else | 243 | #else |
244 | line.z[0] += line.z[1]; | 244 | line.z[0] += line.z[1]; |
245 | #endif | 245 | #endif |
246 | line.t[0][0] += line.t[0][1]; | 246 | line.t[0][0] += line.t[0][1]; |
247 | line.t[1][0] += line.t[1][1]; | 247 | line.t[1][0] += line.t[1][1]; |
248 | } | 248 | } |
249 | 249 | ||
250 | } | 250 | } |
251 | 251 | ||
252 | /*! | 252 | /*! |
253 | */ | 253 | */ |
254 | REALINLINE void CTRTextureLightMap2_M4::scanline_bilinear2_min () | 254 | REALINLINE void CTRTextureLightMap2_M4::scanline_bilinear2_min () |
255 | { | 255 | { |
256 | tVideoSample *dst; | 256 | tVideoSample *dst; |
257 | fp24 *z; | 257 | fp24 *z; |
258 | 258 | ||
259 | s32 xStart; | 259 | s32 xStart; |
260 | s32 xEnd; | 260 | s32 xEnd; |
261 | s32 dx; | 261 | s32 dx; |
262 | s32 i; | 262 | s32 i; |
263 | 263 | ||
264 | 264 | ||
265 | // apply top-left fill-convention, left | 265 | // apply top-left fill-convention, left |
266 | xStart = core::ceil32( line.x[0] ); | 266 | xStart = core::ceil32( line.x[0] ); |
267 | xEnd = core::ceil32( line.x[1] ) - 1; | 267 | xEnd = core::ceil32( line.x[1] ) - 1; |
268 | 268 | ||
269 | dx = xEnd - xStart; | 269 | dx = xEnd - xStart; |
270 | if ( dx < 0 ) | 270 | if ( dx < 0 ) |
271 | return; | 271 | return; |
272 | 272 | ||
273 | // slopes | 273 | // slopes |
274 | const f32 invDeltaX = core::reciprocal_approxim ( line.x[1] - line.x[0] ); | 274 | const f32 invDeltaX = core::reciprocal_approxim ( line.x[1] - line.x[0] ); |
275 | 275 | ||
276 | // search z-buffer for first not occulled pixel | 276 | // search z-buffer for first not occulled pixel |
277 | z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart; | 277 | z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart; |
278 | 278 | ||
279 | // subTexel | 279 | // subTexel |
280 | const f32 subPixel = ( (f32) xStart ) - line.x[0]; | 280 | const f32 subPixel = ( (f32) xStart ) - line.x[0]; |
281 | 281 | ||
282 | #ifdef IPOL_W | 282 | #ifdef IPOL_W |
283 | const f32 b = (line.w[1] - line.w[0]) * invDeltaX; | 283 | const f32 b = (line.w[1] - line.w[0]) * invDeltaX; |
284 | f32 a = line.w[0] + ( b * subPixel ); | 284 | f32 a = line.w[0] + ( b * subPixel ); |
285 | 285 | ||
286 | i = 0; | 286 | i = 0; |
287 | 287 | ||
288 | while ( a <= z[i] ) | 288 | while ( a <= z[i] ) |
289 | { | 289 | { |
290 | a += b; | 290 | a += b; |
291 | 291 | ||
292 | i += 1; | 292 | i += 1; |
293 | if ( i > dx ) | 293 | if ( i > dx ) |
294 | return; | 294 | return; |
295 | 295 | ||
296 | } | 296 | } |
297 | 297 | ||
298 | // lazy setup rest of scanline | 298 | // lazy setup rest of scanline |
299 | 299 | ||
300 | line.w[0] = a; | 300 | line.w[0] = a; |
301 | line.w[1] = b; | 301 | line.w[1] = b; |
302 | #else | 302 | #else |
303 | const f32 b = (line.z[1] - line.z[0]) * invDeltaX; | 303 | const f32 b = (line.z[1] - line.z[0]) * invDeltaX; |
304 | f32 a = line.z[0] + ( b * subPixel ); | 304 | f32 a = line.z[0] + ( b * subPixel ); |
305 | 305 | ||
306 | i = 0; | 306 | i = 0; |
307 | 307 | ||
308 | while ( a > z[i] ) | 308 | while ( a > z[i] ) |
309 | { | 309 | { |
310 | a += b; | 310 | a += b; |
311 | 311 | ||
312 | i += 1; | 312 | i += 1; |
313 | if ( i > dx ) | 313 | if ( i > dx ) |
314 | return; | 314 | return; |
315 | 315 | ||
316 | } | 316 | } |
317 | 317 | ||
318 | // lazy setup rest of scanline | 318 | // lazy setup rest of scanline |
319 | 319 | ||
320 | line.z[0] = a; | 320 | line.z[0] = a; |
321 | line.z[1] = b; | 321 | line.z[1] = b; |
322 | #endif | 322 | #endif |
323 | dst = (tVideoSample*)RenderTarget->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart; | 323 | dst = (tVideoSample*)RenderTarget->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart; |
324 | 324 | ||
325 | a = (f32) i + subPixel; | 325 | a = (f32) i + subPixel; |
326 | 326 | ||
327 | line.t[0][1] = (line.t[0][1] - line.t[0][0]) * invDeltaX; | 327 | line.t[0][1] = (line.t[0][1] - line.t[0][0]) * invDeltaX; |
328 | line.t[1][1] = (line.t[1][1] - line.t[1][0]) * invDeltaX; | 328 | line.t[1][1] = (line.t[1][1] - line.t[1][0]) * invDeltaX; |
329 | 329 | ||
330 | line.t[0][0] += line.t[0][1] * a; | 330 | line.t[0][0] += line.t[0][1] * a; |
331 | line.t[1][0] += line.t[1][1] * a; | 331 | line.t[1][0] += line.t[1][1] * a; |
332 | 332 | ||
333 | 333 | ||
334 | tFixPoint r0, g0, b0; | 334 | tFixPoint r0, g0, b0; |
335 | tFixPoint r1, g1, b1; | 335 | tFixPoint r1, g1, b1; |
336 | 336 | ||
337 | 337 | ||
338 | for ( ;i <= dx; i++ ) | 338 | for ( ;i <= dx; i++ ) |
339 | { | 339 | { |
340 | #ifdef IPOL_W | 340 | #ifdef IPOL_W |
341 | if ( line.w[0] >= z[i] ) | 341 | if ( line.w[0] >= z[i] ) |
342 | { | 342 | { |
343 | z[i] = line.w[0]; | 343 | z[i] = line.w[0]; |
344 | #else | 344 | #else |
345 | if ( line.z[0] < z[i] ) | 345 | if ( line.z[0] < z[i] ) |
346 | { | 346 | { |
347 | z[i] = line.z[0]; | 347 | z[i] = line.z[0]; |
348 | #endif | 348 | #endif |
349 | 349 | ||
350 | #ifdef SOFTWARE_DRIVER_2_PERSPECTIVE_CORRECT | 350 | #ifdef SOFTWARE_DRIVER_2_PERSPECTIVE_CORRECT |
351 | f32 inversew = fix_inverse32 ( line.w[0] ); | 351 | f32 inversew = fix_inverse32 ( line.w[0] ); |
352 | #else | 352 | #else |
353 | f32 inversew = FIX_POINT_F32_MUL; | 353 | f32 inversew = FIX_POINT_F32_MUL; |
354 | #endif | 354 | #endif |
355 | 355 | ||
356 | 356 | ||
357 | getTexel_fix ( r0, g0, b0, &IT[0], tofix ( line.t[0][0].x,inversew), tofix ( line.t[0][0].y,inversew) ); | 357 | getTexel_fix ( r0, g0, b0, &IT[0], tofix ( line.t[0][0].x,inversew), tofix ( line.t[0][0].y,inversew) ); |
358 | getTexel_fix ( r1, g1, b1, &IT[1], tofix ( line.t[1][0].x,inversew), tofix ( line.t[1][0].y,inversew) ); | 358 | getTexel_fix ( r1, g1, b1, &IT[1], tofix ( line.t[1][0].x,inversew), tofix ( line.t[1][0].y,inversew) ); |
359 | 359 | ||
360 | dst[i] = fix_to_color ( clampfix_maxcolor ( imulFix_tex4 ( r0, r1 ) ), | 360 | dst[i] = fix_to_color ( clampfix_maxcolor ( imulFix_tex4 ( r0, r1 ) ), |
361 | clampfix_maxcolor ( imulFix_tex4 ( g0, g1 ) ), | 361 | clampfix_maxcolor ( imulFix_tex4 ( g0, g1 ) ), |
362 | clampfix_maxcolor ( imulFix_tex4 ( b0, b1 ) ) | 362 | clampfix_maxcolor ( imulFix_tex4 ( b0, b1 ) ) |
363 | ); | 363 | ); |
364 | } | 364 | } |
365 | 365 | ||
366 | #ifdef IPOL_W | 366 | #ifdef IPOL_W |
367 | line.w[0] += line.w[1]; | 367 | line.w[0] += line.w[1]; |
368 | #else | 368 | #else |
369 | line.z[0] += line.z[1]; | 369 | line.z[0] += line.z[1]; |
370 | #endif | 370 | #endif |
371 | line.t[0][0] += line.t[0][1]; | 371 | line.t[0][0] += line.t[0][1]; |
372 | line.t[1][0] += line.t[1][1]; | 372 | line.t[1][0] += line.t[1][1]; |
373 | } | 373 | } |
374 | 374 | ||
375 | } | 375 | } |
376 | 376 | ||
377 | //#ifdef BURNINGVIDEO_RENDERER_FAST | 377 | //#ifdef BURNINGVIDEO_RENDERER_FAST |
378 | #if 1 | 378 | #if 1 |
379 | 379 | ||
380 | void CTRTextureLightMap2_M4::drawTriangle ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c ) | 380 | void CTRTextureLightMap2_M4::drawTriangle ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c ) |
381 | { | 381 | { |
382 | if ( IT[0].lodLevel <= 2 ) | 382 | if ( IT[0].lodLevel <= 2 ) |
383 | drawTriangle_Mag ( a, b, c ); | 383 | drawTriangle_Mag ( a, b, c ); |
384 | else | 384 | else |
385 | drawTriangle_Min ( a, b, c ); | 385 | drawTriangle_Min ( a, b, c ); |
386 | } | 386 | } |
387 | 387 | ||
388 | void CTRTextureLightMap2_M4::drawTriangle_Min ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c ) | 388 | void CTRTextureLightMap2_M4::drawTriangle_Min ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c ) |
389 | { | 389 | { |
390 | sScanConvertData scan; | 390 | sScanConvertData scan; |
391 | 391 | ||
392 | // sort on height, y | 392 | // sort on height, y |
393 | if ( F32_A_GREATER_B ( a->Pos.y , b->Pos.y ) ) swapVertexPointer(&a, &b); | 393 | if ( F32_A_GREATER_B ( a->Pos.y , b->Pos.y ) ) swapVertexPointer(&a, &b); |
394 | if ( F32_A_GREATER_B ( b->Pos.y , c->Pos.y ) ) swapVertexPointer(&b, &c); | 394 | if ( F32_A_GREATER_B ( b->Pos.y , c->Pos.y ) ) swapVertexPointer(&b, &c); |
395 | if ( F32_A_GREATER_B ( a->Pos.y , b->Pos.y ) ) swapVertexPointer(&a, &b); | 395 | if ( F32_A_GREATER_B ( a->Pos.y , b->Pos.y ) ) swapVertexPointer(&a, &b); |
396 | 396 | ||
397 | const f32 ca = c->Pos.y - a->Pos.y; | 397 | const f32 ca = c->Pos.y - a->Pos.y; |
398 | const f32 ba = b->Pos.y - a->Pos.y; | 398 | const f32 ba = b->Pos.y - a->Pos.y; |
399 | const f32 cb = c->Pos.y - b->Pos.y; | 399 | const f32 cb = c->Pos.y - b->Pos.y; |
400 | // calculate delta y of the edges | 400 | // calculate delta y of the edges |
401 | scan.invDeltaY[0] = core::reciprocal( ca ); | 401 | scan.invDeltaY[0] = core::reciprocal( ca ); |
402 | scan.invDeltaY[1] = core::reciprocal( ba ); | 402 | scan.invDeltaY[1] = core::reciprocal( ba ); |
403 | scan.invDeltaY[2] = core::reciprocal( cb ); | 403 | scan.invDeltaY[2] = core::reciprocal( cb ); |
404 | 404 | ||
405 | if ( F32_LOWER_EQUAL_0 ( scan.invDeltaY[0] ) ) | 405 | if ( F32_LOWER_EQUAL_0 ( scan.invDeltaY[0] ) ) |
406 | return; | 406 | return; |
407 | 407 | ||
408 | // find if the major edge is left or right aligned | 408 | // find if the major edge is left or right aligned |
409 | f32 temp[4]; | 409 | f32 temp[4]; |
410 | 410 | ||
411 | temp[0] = a->Pos.x - c->Pos.x; | 411 | temp[0] = a->Pos.x - c->Pos.x; |
412 | temp[1] = -ca; | 412 | temp[1] = -ca; |
413 | temp[2] = b->Pos.x - a->Pos.x; | 413 | temp[2] = b->Pos.x - a->Pos.x; |
414 | temp[3] = ba; | 414 | temp[3] = ba; |
415 | 415 | ||
416 | scan.left = ( temp[0] * temp[3] - temp[1] * temp[2] ) > 0.f ? 0 : 1; | 416 | scan.left = ( temp[0] * temp[3] - temp[1] * temp[2] ) > 0.f ? 0 : 1; |
417 | scan.right = 1 - scan.left; | 417 | scan.right = 1 - scan.left; |
418 | 418 | ||
419 | // calculate slopes for the major edge | 419 | // calculate slopes for the major edge |
420 | scan.slopeX[0] = (c->Pos.x - a->Pos.x) * scan.invDeltaY[0]; | 420 | scan.slopeX[0] = (c->Pos.x - a->Pos.x) * scan.invDeltaY[0]; |
421 | scan.x[0] = a->Pos.x; | 421 | scan.x[0] = a->Pos.x; |
422 | 422 | ||
423 | #ifdef IPOL_Z | 423 | #ifdef IPOL_Z |
424 | scan.slopeZ[0] = (c->Pos.z - a->Pos.z) * scan.invDeltaY[0]; | 424 | scan.slopeZ[0] = (c->Pos.z - a->Pos.z) * scan.invDeltaY[0]; |
425 | scan.z[0] = a->Pos.z; | 425 | scan.z[0] = a->Pos.z; |
426 | #endif | 426 | #endif |
427 | 427 | ||
428 | #ifdef IPOL_W | 428 | #ifdef IPOL_W |
429 | scan.slopeW[0] = (c->Pos.w - a->Pos.w) * scan.invDeltaY[0]; | 429 | scan.slopeW[0] = (c->Pos.w - a->Pos.w) * scan.invDeltaY[0]; |
430 | scan.w[0] = a->Pos.w; | 430 | scan.w[0] = a->Pos.w; |
431 | #endif | 431 | #endif |
432 | 432 | ||
433 | #ifdef IPOL_C0 | 433 | #ifdef IPOL_C0 |
434 | scan.slopeC[0] = (c->Color[0] - a->Color[0]) * scan.invDeltaY[0]; | 434 | scan.slopeC[0] = (c->Color[0] - a->Color[0]) * scan.invDeltaY[0]; |
435 | scan.c[0] = a->Color[0]; | 435 | scan.c[0] = a->Color[0]; |
436 | #endif | 436 | #endif |
437 | 437 | ||
438 | #ifdef IPOL_T0 | 438 | #ifdef IPOL_T0 |
439 | scan.slopeT[0][0] = (c->Tex[0] - a->Tex[0]) * scan.invDeltaY[0]; | 439 | scan.slopeT[0][0] = (c->Tex[0] - a->Tex[0]) * scan.invDeltaY[0]; |
440 | scan.t[0][0] = a->Tex[0]; | 440 | scan.t[0][0] = a->Tex[0]; |
441 | #endif | 441 | #endif |
442 | 442 | ||
443 | #ifdef IPOL_T1 | 443 | #ifdef IPOL_T1 |
444 | scan.slopeT[1][0] = (c->Tex[1] - a->Tex[1]) * scan.invDeltaY[0]; | 444 | scan.slopeT[1][0] = (c->Tex[1] - a->Tex[1]) * scan.invDeltaY[0]; |
445 | scan.t[1][0] = a->Tex[1]; | 445 | scan.t[1][0] = a->Tex[1]; |
446 | #endif | 446 | #endif |
447 | 447 | ||
448 | // top left fill convention y run | 448 | // top left fill convention y run |
449 | s32 yStart; | 449 | s32 yStart; |
450 | s32 yEnd; | 450 | s32 yEnd; |
451 | 451 | ||
452 | #ifdef SUBTEXEL | 452 | #ifdef SUBTEXEL |
453 | f32 subPixel; | 453 | f32 subPixel; |
454 | #endif | 454 | #endif |
455 | 455 | ||
456 | // rasterize upper sub-triangle | 456 | // rasterize upper sub-triangle |
457 | if ( F32_GREATER_0 ( scan.invDeltaY[1] ) ) | 457 | if ( F32_GREATER_0 ( scan.invDeltaY[1] ) ) |
458 | { | 458 | { |
459 | // calculate slopes for top edge | 459 | // calculate slopes for top edge |
460 | scan.slopeX[1] = (b->Pos.x - a->Pos.x) * scan.invDeltaY[1]; | 460 | scan.slopeX[1] = (b->Pos.x - a->Pos.x) * scan.invDeltaY[1]; |
461 | scan.x[1] = a->Pos.x; | 461 | scan.x[1] = a->Pos.x; |
462 | 462 | ||
463 | #ifdef IPOL_Z | 463 | #ifdef IPOL_Z |
464 | scan.slopeZ[1] = (b->Pos.z - a->Pos.z) * scan.invDeltaY[1]; | 464 | scan.slopeZ[1] = (b->Pos.z - a->Pos.z) * scan.invDeltaY[1]; |
465 | scan.z[1] = a->Pos.z; | 465 | scan.z[1] = a->Pos.z; |
466 | #endif | 466 | #endif |
467 | 467 | ||
468 | #ifdef IPOL_W | 468 | #ifdef IPOL_W |
469 | scan.slopeW[1] = (b->Pos.w - a->Pos.w) * scan.invDeltaY[1]; | 469 | scan.slopeW[1] = (b->Pos.w - a->Pos.w) * scan.invDeltaY[1]; |
470 | scan.w[1] = a->Pos.w; | 470 | scan.w[1] = a->Pos.w; |
471 | #endif | 471 | #endif |
472 | 472 | ||
473 | #ifdef IPOL_C0 | 473 | #ifdef IPOL_C0 |
474 | scan.slopeC[1] = (b->Color[0] - a->Color[0]) * scan.invDeltaY[1]; | 474 | scan.slopeC[1] = (b->Color[0] - a->Color[0]) * scan.invDeltaY[1]; |
475 | scan.c[1] = a->Color[0]; | 475 | scan.c[1] = a->Color[0]; |
476 | #endif | 476 | #endif |
477 | 477 | ||
478 | #ifdef IPOL_T0 | 478 | #ifdef IPOL_T0 |
479 | scan.slopeT[0][1] = (b->Tex[0] - a->Tex[0]) * scan.invDeltaY[1]; | 479 | scan.slopeT[0][1] = (b->Tex[0] - a->Tex[0]) * scan.invDeltaY[1]; |
480 | scan.t[0][1] = a->Tex[0]; | 480 | scan.t[0][1] = a->Tex[0]; |
481 | #endif | 481 | #endif |
482 | 482 | ||
483 | #ifdef IPOL_T1 | 483 | #ifdef IPOL_T1 |
484 | scan.slopeT[1][1] = (b->Tex[1] - a->Tex[1]) * scan.invDeltaY[1]; | 484 | scan.slopeT[1][1] = (b->Tex[1] - a->Tex[1]) * scan.invDeltaY[1]; |
485 | scan.t[1][1] = a->Tex[1]; | 485 | scan.t[1][1] = a->Tex[1]; |
486 | #endif | 486 | #endif |
487 | 487 | ||
488 | // apply top-left fill convention, top part | 488 | // apply top-left fill convention, top part |
489 | yStart = core::ceil32( a->Pos.y ); | 489 | yStart = core::ceil32( a->Pos.y ); |
490 | yEnd = core::ceil32( b->Pos.y ) - 1; | 490 | yEnd = core::ceil32( b->Pos.y ) - 1; |
491 | 491 | ||
492 | #ifdef SUBTEXEL | 492 | #ifdef SUBTEXEL |
493 | subPixel = ( (f32) yStart ) - a->Pos.y; | 493 | subPixel = ( (f32) yStart ) - a->Pos.y; |
494 | 494 | ||
495 | // correct to pixel center | 495 | // correct to pixel center |
496 | scan.x[0] += scan.slopeX[0] * subPixel; | 496 | scan.x[0] += scan.slopeX[0] * subPixel; |
497 | scan.x[1] += scan.slopeX[1] * subPixel; | 497 | scan.x[1] += scan.slopeX[1] * subPixel; |
498 | 498 | ||
499 | #ifdef IPOL_Z | 499 | #ifdef IPOL_Z |
500 | scan.z[0] += scan.slopeZ[0] * subPixel; | 500 | scan.z[0] += scan.slopeZ[0] * subPixel; |
501 | scan.z[1] += scan.slopeZ[1] * subPixel; | 501 | scan.z[1] += scan.slopeZ[1] * subPixel; |
502 | #endif | 502 | #endif |
503 | 503 | ||
504 | #ifdef IPOL_W | 504 | #ifdef IPOL_W |
505 | scan.w[0] += scan.slopeW[0] * subPixel; | 505 | scan.w[0] += scan.slopeW[0] * subPixel; |
506 | scan.w[1] += scan.slopeW[1] * subPixel; | 506 | scan.w[1] += scan.slopeW[1] * subPixel; |
507 | #endif | 507 | #endif |
508 | 508 | ||
509 | #ifdef IPOL_C0 | 509 | #ifdef IPOL_C0 |
510 | scan.c[0] += scan.slopeC[0] * subPixel; | 510 | scan.c[0] += scan.slopeC[0] * subPixel; |
511 | scan.c[1] += scan.slopeC[1] * subPixel; | 511 | scan.c[1] += scan.slopeC[1] * subPixel; |
512 | #endif | 512 | #endif |
513 | 513 | ||
514 | #ifdef IPOL_T0 | 514 | #ifdef IPOL_T0 |
515 | scan.t[0][0] += scan.slopeT[0][0] * subPixel; | 515 | scan.t[0][0] += scan.slopeT[0][0] * subPixel; |
516 | scan.t[0][1] += scan.slopeT[0][1] * subPixel; | 516 | scan.t[0][1] += scan.slopeT[0][1] * subPixel; |
517 | #endif | 517 | #endif |
518 | 518 | ||
519 | #ifdef IPOL_T1 | 519 | #ifdef IPOL_T1 |
520 | scan.t[1][0] += scan.slopeT[1][0] * subPixel; | 520 | scan.t[1][0] += scan.slopeT[1][0] * subPixel; |
521 | scan.t[1][1] += scan.slopeT[1][1] * subPixel; | 521 | scan.t[1][1] += scan.slopeT[1][1] * subPixel; |
522 | #endif | 522 | #endif |
523 | 523 | ||
524 | #endif | 524 | #endif |
525 | 525 | ||
526 | // rasterize the edge scanlines | 526 | // rasterize the edge scanlines |
527 | for( line.y = yStart; line.y <= yEnd; ++line.y) | 527 | for( line.y = yStart; line.y <= yEnd; ++line.y) |
528 | { | 528 | { |
529 | line.x[scan.left] = scan.x[0]; | 529 | line.x[scan.left] = scan.x[0]; |
530 | line.x[scan.right] = scan.x[1]; | 530 | line.x[scan.right] = scan.x[1]; |
531 | 531 | ||
532 | #ifdef IPOL_Z | 532 | #ifdef IPOL_Z |
533 | line.z[scan.left] = scan.z[0]; | 533 | line.z[scan.left] = scan.z[0]; |
534 | line.z[scan.right] = scan.z[1]; | 534 | line.z[scan.right] = scan.z[1]; |
535 | #endif | 535 | #endif |
536 | 536 | ||
537 | #ifdef IPOL_W | 537 | #ifdef IPOL_W |
538 | line.w[scan.left] = scan.w[0]; | 538 | line.w[scan.left] = scan.w[0]; |
539 | line.w[scan.right] = scan.w[1]; | 539 | line.w[scan.right] = scan.w[1]; |
540 | #endif | 540 | #endif |
541 | 541 | ||
542 | #ifdef IPOL_C0 | 542 | #ifdef IPOL_C0 |
543 | line.c[scan.left] = scan.c[0]; | 543 | line.c[scan.left] = scan.c[0]; |
544 | line.c[scan.right] = scan.c[1]; | 544 | line.c[scan.right] = scan.c[1]; |
545 | #endif | 545 | #endif |
546 | 546 | ||
547 | #ifdef IPOL_T0 | 547 | #ifdef IPOL_T0 |
548 | line.t[0][scan.left] = scan.t[0][0]; | 548 | line.t[0][scan.left] = scan.t[0][0]; |
549 | line.t[0][scan.right] = scan.t[0][1]; | 549 | line.t[0][scan.right] = scan.t[0][1]; |
550 | #endif | 550 | #endif |
551 | 551 | ||
552 | #ifdef IPOL_T1 | 552 | #ifdef IPOL_T1 |
553 | line.t[1][scan.left] = scan.t[1][0]; | 553 | line.t[1][scan.left] = scan.t[1][0]; |
554 | line.t[1][scan.right] = scan.t[1][1]; | 554 | line.t[1][scan.right] = scan.t[1][1]; |
555 | #endif | 555 | #endif |
556 | 556 | ||
557 | // render a scanline | 557 | // render a scanline |
558 | scanline_bilinear2_min (); | 558 | scanline_bilinear2_min (); |
559 | 559 | ||
560 | scan.x[0] += scan.slopeX[0]; | 560 | scan.x[0] += scan.slopeX[0]; |
561 | scan.x[1] += scan.slopeX[1]; | 561 | scan.x[1] += scan.slopeX[1]; |
562 | 562 | ||
563 | #ifdef IPOL_Z | 563 | #ifdef IPOL_Z |
564 | scan.z[0] += scan.slopeZ[0]; | 564 | scan.z[0] += scan.slopeZ[0]; |
565 | scan.z[1] += scan.slopeZ[1]; | 565 | scan.z[1] += scan.slopeZ[1]; |
566 | #endif | 566 | #endif |
567 | 567 | ||
568 | #ifdef IPOL_W | 568 | #ifdef IPOL_W |
569 | scan.w[0] += scan.slopeW[0]; | 569 | scan.w[0] += scan.slopeW[0]; |
570 | scan.w[1] += scan.slopeW[1]; | 570 | scan.w[1] += scan.slopeW[1]; |
571 | #endif | 571 | #endif |
572 | 572 | ||
573 | #ifdef IPOL_C0 | 573 | #ifdef IPOL_C0 |
574 | scan.c[0] += scan.slopeC[0]; | 574 | scan.c[0] += scan.slopeC[0]; |
575 | scan.c[1] += scan.slopeC[1]; | 575 | scan.c[1] += scan.slopeC[1]; |
576 | #endif | 576 | #endif |
577 | 577 | ||
578 | #ifdef IPOL_T0 | 578 | #ifdef IPOL_T0 |
579 | scan.t[0][0] += scan.slopeT[0][0]; | 579 | scan.t[0][0] += scan.slopeT[0][0]; |
580 | scan.t[0][1] += scan.slopeT[0][1]; | 580 | scan.t[0][1] += scan.slopeT[0][1]; |
581 | #endif | 581 | #endif |
582 | 582 | ||
583 | #ifdef IPOL_T1 | 583 | #ifdef IPOL_T1 |
584 | scan.t[1][0] += scan.slopeT[1][0]; | 584 | scan.t[1][0] += scan.slopeT[1][0]; |
585 | scan.t[1][1] += scan.slopeT[1][1]; | 585 | scan.t[1][1] += scan.slopeT[1][1]; |
586 | #endif | 586 | #endif |
587 | 587 | ||
588 | } | 588 | } |
589 | } | 589 | } |
590 | 590 | ||
591 | // rasterize lower sub-triangle | 591 | // rasterize lower sub-triangle |
592 | //if ( (f32) 0.0 != scan.invDeltaY[2] ) | 592 | //if ( (f32) 0.0 != scan.invDeltaY[2] ) |
593 | if ( F32_GREATER_0 ( scan.invDeltaY[2] ) ) | 593 | if ( F32_GREATER_0 ( scan.invDeltaY[2] ) ) |
594 | { | 594 | { |
595 | // advance to middle point | 595 | // advance to middle point |
596 | if ( F32_GREATER_0 ( scan.invDeltaY[1] ) ) | 596 | if ( F32_GREATER_0 ( scan.invDeltaY[1] ) ) |
597 | { | 597 | { |
598 | temp[0] = b->Pos.y - a->Pos.y; // dy | 598 | temp[0] = b->Pos.y - a->Pos.y; // dy |
599 | 599 | ||
600 | scan.x[0] = a->Pos.x + scan.slopeX[0] * temp[0]; | 600 | scan.x[0] = a->Pos.x + scan.slopeX[0] * temp[0]; |
601 | #ifdef IPOL_Z | 601 | #ifdef IPOL_Z |
602 | scan.z[0] = a->Pos.z + scan.slopeZ[0] * temp[0]; | 602 | scan.z[0] = a->Pos.z + scan.slopeZ[0] * temp[0]; |
603 | #endif | 603 | #endif |
604 | #ifdef IPOL_W | 604 | #ifdef IPOL_W |
605 | scan.w[0] = a->Pos.w + scan.slopeW[0] * temp[0]; | 605 | scan.w[0] = a->Pos.w + scan.slopeW[0] * temp[0]; |
606 | #endif | 606 | #endif |
607 | #ifdef IPOL_C0 | 607 | #ifdef IPOL_C0 |
608 | scan.c[0] = a->Color[0] + scan.slopeC[0] * temp[0]; | 608 | scan.c[0] = a->Color[0] + scan.slopeC[0] * temp[0]; |
609 | #endif | 609 | #endif |
610 | #ifdef IPOL_T0 | 610 | #ifdef IPOL_T0 |
611 | scan.t[0][0] = a->Tex[0] + scan.slopeT[0][0] * temp[0]; | 611 | scan.t[0][0] = a->Tex[0] + scan.slopeT[0][0] * temp[0]; |
612 | #endif | 612 | #endif |
613 | #ifdef IPOL_T1 | 613 | #ifdef IPOL_T1 |
614 | scan.t[1][0] = a->Tex[1] + scan.slopeT[1][0] * temp[0]; | 614 | scan.t[1][0] = a->Tex[1] + scan.slopeT[1][0] * temp[0]; |
615 | #endif | 615 | #endif |
616 | 616 | ||
617 | } | 617 | } |
618 | 618 | ||
619 | // calculate slopes for bottom edge | 619 | // calculate slopes for bottom edge |
620 | scan.slopeX[1] = (c->Pos.x - b->Pos.x) * scan.invDeltaY[2]; | 620 | scan.slopeX[1] = (c->Pos.x - b->Pos.x) * scan.invDeltaY[2]; |
621 | scan.x[1] = b->Pos.x; | 621 | scan.x[1] = b->Pos.x; |
622 | 622 | ||
623 | #ifdef IPOL_Z | 623 | #ifdef IPOL_Z |
624 | scan.slopeZ[1] = (c->Pos.z - b->Pos.z) * scan.invDeltaY[2]; | 624 | scan.slopeZ[1] = (c->Pos.z - b->Pos.z) * scan.invDeltaY[2]; |
625 | scan.z[1] = b->Pos.z; | 625 | scan.z[1] = b->Pos.z; |
626 | #endif | 626 | #endif |
627 | 627 | ||
628 | #ifdef IPOL_W | 628 | #ifdef IPOL_W |
629 | scan.slopeW[1] = (c->Pos.w - b->Pos.w) * scan.invDeltaY[2]; | 629 | scan.slopeW[1] = (c->Pos.w - b->Pos.w) * scan.invDeltaY[2]; |
630 | scan.w[1] = b->Pos.w; | 630 | scan.w[1] = b->Pos.w; |
631 | #endif | 631 | #endif |
632 | 632 | ||
633 | #ifdef IPOL_C0 | 633 | #ifdef IPOL_C0 |
634 | scan.slopeC[1] = (c->Color[0] - b->Color[0]) * scan.invDeltaY[2]; | 634 | scan.slopeC[1] = (c->Color[0] - b->Color[0]) * scan.invDeltaY[2]; |
635 | scan.c[1] = b->Color[0]; | 635 | scan.c[1] = b->Color[0]; |
636 | #endif | 636 | #endif |
637 | 637 | ||
638 | #ifdef IPOL_T0 | 638 | #ifdef IPOL_T0 |
639 | scan.slopeT[0][1] = (c->Tex[0] - b->Tex[0]) * scan.invDeltaY[2]; | 639 | scan.slopeT[0][1] = (c->Tex[0] - b->Tex[0]) * scan.invDeltaY[2]; |
640 | scan.t[0][1] = b->Tex[0]; | 640 | scan.t[0][1] = b->Tex[0]; |
641 | #endif | 641 | #endif |
642 | 642 | ||
643 | #ifdef IPOL_T1 | 643 | #ifdef IPOL_T1 |
644 | scan.slopeT[1][1] = (c->Tex[1] - b->Tex[1]) * scan.invDeltaY[2]; | 644 | scan.slopeT[1][1] = (c->Tex[1] - b->Tex[1]) * scan.invDeltaY[2]; |
645 | scan.t[1][1] = b->Tex[1]; | 645 | scan.t[1][1] = b->Tex[1]; |
646 | #endif | 646 | #endif |
647 | 647 | ||
648 | // apply top-left fill convention, top part | 648 | // apply top-left fill convention, top part |
649 | yStart = core::ceil32( b->Pos.y ); | 649 | yStart = core::ceil32( b->Pos.y ); |
650 | yEnd = core::ceil32( c->Pos.y ) - 1; | 650 | yEnd = core::ceil32( c->Pos.y ) - 1; |
651 | 651 | ||
652 | #ifdef SUBTEXEL | 652 | #ifdef SUBTEXEL |
653 | 653 | ||
654 | subPixel = ( (f32) yStart ) - b->Pos.y; | 654 | subPixel = ( (f32) yStart ) - b->Pos.y; |
655 | 655 | ||
656 | // correct to pixel center | 656 | // correct to pixel center |
657 | scan.x[0] += scan.slopeX[0] * subPixel; | 657 | scan.x[0] += scan.slopeX[0] * subPixel; |
658 | scan.x[1] += scan.slopeX[1] * subPixel; | 658 | scan.x[1] += scan.slopeX[1] * subPixel; |
659 | 659 | ||
660 | #ifdef IPOL_Z | 660 | #ifdef IPOL_Z |
661 | scan.z[0] += scan.slopeZ[0] * subPixel; | 661 | scan.z[0] += scan.slopeZ[0] * subPixel; |
662 | scan.z[1] += scan.slopeZ[1] * subPixel; | 662 | scan.z[1] += scan.slopeZ[1] * subPixel; |
663 | #endif | 663 | #endif |
664 | 664 | ||
665 | #ifdef IPOL_W | 665 | #ifdef IPOL_W |
666 | scan.w[0] += scan.slopeW[0] * subPixel; | 666 | scan.w[0] += scan.slopeW[0] * subPixel; |
667 | scan.w[1] += scan.slopeW[1] * subPixel; | 667 | scan.w[1] += scan.slopeW[1] * subPixel; |
668 | #endif | 668 | #endif |
669 | 669 | ||
670 | #ifdef IPOL_C0 | 670 | #ifdef IPOL_C0 |
671 | scan.c[0] += scan.slopeC[0] * subPixel; | 671 | scan.c[0] += scan.slopeC[0] * subPixel; |
672 | scan.c[1] += scan.slopeC[1] * subPixel; | 672 | scan.c[1] += scan.slopeC[1] * subPixel; |
673 | #endif | 673 | #endif |
674 | 674 | ||
675 | #ifdef IPOL_T0 | 675 | #ifdef IPOL_T0 |
676 | scan.t[0][0] += scan.slopeT[0][0] * subPixel; | 676 | scan.t[0][0] += scan.slopeT[0][0] * subPixel; |
677 | scan.t[0][1] += scan.slopeT[0][1] * subPixel; | 677 | scan.t[0][1] += scan.slopeT[0][1] * subPixel; |
678 | #endif | 678 | #endif |
679 | 679 | ||
680 | #ifdef IPOL_T1 | 680 | #ifdef IPOL_T1 |
681 | scan.t[1][0] += scan.slopeT[1][0] * subPixel; | 681 | scan.t[1][0] += scan.slopeT[1][0] * subPixel; |
682 | scan.t[1][1] += scan.slopeT[1][1] * subPixel; | 682 | scan.t[1][1] += scan.slopeT[1][1] * subPixel; |
683 | #endif | 683 | #endif |
684 | 684 | ||
685 | #endif | 685 | #endif |
686 | 686 | ||
687 | // rasterize the edge scanlines | 687 | // rasterize the edge scanlines |
688 | for( line.y = yStart; line.y <= yEnd; ++line.y) | 688 | for( line.y = yStart; line.y <= yEnd; ++line.y) |
689 | { | 689 | { |
690 | line.x[scan.left] = scan.x[0]; | 690 | line.x[scan.left] = scan.x[0]; |
691 | line.x[scan.right] = scan.x[1]; | 691 | line.x[scan.right] = scan.x[1]; |
692 | 692 | ||
693 | #ifdef IPOL_Z | 693 | #ifdef IPOL_Z |
694 | line.z[scan.left] = scan.z[0]; | 694 | line.z[scan.left] = scan.z[0]; |
695 | line.z[scan.right] = scan.z[1]; | 695 | line.z[scan.right] = scan.z[1]; |
696 | #endif | 696 | #endif |
697 | 697 | ||
698 | #ifdef IPOL_W | 698 | #ifdef IPOL_W |
699 | line.w[scan.left] = scan.w[0]; | 699 | line.w[scan.left] = scan.w[0]; |
700 | line.w[scan.right] = scan.w[1]; | 700 | line.w[scan.right] = scan.w[1]; |
701 | #endif | 701 | #endif |
702 | 702 | ||
703 | #ifdef IPOL_C0 | 703 | #ifdef IPOL_C0 |
704 | line.c[scan.left] = scan.c[0]; | 704 | line.c[scan.left] = scan.c[0]; |
705 | line.c[scan.right] = scan.c[1]; | 705 | line.c[scan.right] = scan.c[1]; |
706 | #endif | 706 | #endif |
707 | 707 | ||
708 | #ifdef IPOL_T0 | 708 | #ifdef IPOL_T0 |
709 | line.t[0][scan.left] = scan.t[0][0]; | 709 | line.t[0][scan.left] = scan.t[0][0]; |
710 | line.t[0][scan.right] = scan.t[0][1]; | 710 | line.t[0][scan.right] = scan.t[0][1]; |
711 | #endif | 711 | #endif |
712 | 712 | ||
713 | #ifdef IPOL_T1 | 713 | #ifdef IPOL_T1 |
714 | line.t[1][scan.left] = scan.t[1][0]; | 714 | line.t[1][scan.left] = scan.t[1][0]; |
715 | line.t[1][scan.right] = scan.t[1][1]; | 715 | line.t[1][scan.right] = scan.t[1][1]; |
716 | #endif | 716 | #endif |
717 | 717 | ||
718 | // render a scanline | 718 | // render a scanline |
719 | scanline_bilinear2_min (); | 719 | scanline_bilinear2_min (); |
720 | 720 | ||
721 | scan.x[0] += scan.slopeX[0]; | 721 | scan.x[0] += scan.slopeX[0]; |
722 | scan.x[1] += scan.slopeX[1]; | 722 | scan.x[1] += scan.slopeX[1]; |
723 | 723 | ||
724 | #ifdef IPOL_Z | 724 | #ifdef IPOL_Z |
725 | scan.z[0] += scan.slopeZ[0]; | 725 | scan.z[0] += scan.slopeZ[0]; |
726 | scan.z[1] += scan.slopeZ[1]; | 726 | scan.z[1] += scan.slopeZ[1]; |
727 | #endif | 727 | #endif |
728 | 728 | ||
729 | #ifdef IPOL_W | 729 | #ifdef IPOL_W |
730 | scan.w[0] += scan.slopeW[0]; | 730 | scan.w[0] += scan.slopeW[0]; |
731 | scan.w[1] += scan.slopeW[1]; | 731 | scan.w[1] += scan.slopeW[1]; |
732 | #endif | 732 | #endif |
733 | 733 | ||
734 | #ifdef IPOL_C0 | 734 | #ifdef IPOL_C0 |
735 | scan.c[0] += scan.slopeC[0]; | 735 | scan.c[0] += scan.slopeC[0]; |
736 | scan.c[1] += scan.slopeC[1]; | 736 | scan.c[1] += scan.slopeC[1]; |
737 | #endif | 737 | #endif |
738 | 738 | ||
739 | #ifdef IPOL_T0 | 739 | #ifdef IPOL_T0 |
740 | scan.t[0][0] += scan.slopeT[0][0]; | 740 | scan.t[0][0] += scan.slopeT[0][0]; |
741 | scan.t[0][1] += scan.slopeT[0][1]; | 741 | scan.t[0][1] += scan.slopeT[0][1]; |
742 | #endif | 742 | #endif |
743 | 743 | ||
744 | #ifdef IPOL_T1 | 744 | #ifdef IPOL_T1 |
745 | scan.t[1][0] += scan.slopeT[1][0]; | 745 | scan.t[1][0] += scan.slopeT[1][0]; |
746 | scan.t[1][1] += scan.slopeT[1][1]; | 746 | scan.t[1][1] += scan.slopeT[1][1]; |
747 | #endif | 747 | #endif |
748 | 748 | ||
749 | } | 749 | } |
750 | } | 750 | } |
751 | 751 | ||
752 | } | 752 | } |
753 | 753 | ||
754 | void CTRTextureLightMap2_M4::drawTriangle_Mag ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c ) | 754 | void CTRTextureLightMap2_M4::drawTriangle_Mag ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c ) |
755 | 755 | ||
756 | #else | 756 | #else |
757 | 757 | ||
758 | void CTRTextureLightMap2_M4::drawTriangle ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c ) | 758 | void CTRTextureLightMap2_M4::drawTriangle ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c ) |
759 | 759 | ||
760 | #endif | 760 | #endif |
761 | 761 | ||
762 | { | 762 | { |
763 | sScanConvertData scan; | 763 | sScanConvertData scan; |
764 | 764 | ||
765 | // sort on height, y | 765 | // sort on height, y |
766 | if ( F32_A_GREATER_B ( a->Pos.y , b->Pos.y ) ) swapVertexPointer(&a, &b); | 766 | if ( F32_A_GREATER_B ( a->Pos.y , b->Pos.y ) ) swapVertexPointer(&a, &b); |
767 | if ( F32_A_GREATER_B ( b->Pos.y , c->Pos.y ) ) swapVertexPointer(&b, &c); | 767 | if ( F32_A_GREATER_B ( b->Pos.y , c->Pos.y ) ) swapVertexPointer(&b, &c); |
768 | if ( F32_A_GREATER_B ( a->Pos.y , b->Pos.y ) ) swapVertexPointer(&a, &b); | 768 | if ( F32_A_GREATER_B ( a->Pos.y , b->Pos.y ) ) swapVertexPointer(&a, &b); |
769 | 769 | ||
770 | const f32 ca = c->Pos.y - a->Pos.y; | 770 | const f32 ca = c->Pos.y - a->Pos.y; |
771 | const f32 ba = b->Pos.y - a->Pos.y; | 771 | const f32 ba = b->Pos.y - a->Pos.y; |
772 | const f32 cb = c->Pos.y - b->Pos.y; | 772 | const f32 cb = c->Pos.y - b->Pos.y; |
773 | // calculate delta y of the edges | 773 | // calculate delta y of the edges |
774 | scan.invDeltaY[0] = core::reciprocal( ca ); | 774 | scan.invDeltaY[0] = core::reciprocal( ca ); |
775 | scan.invDeltaY[1] = core::reciprocal( ba ); | 775 | scan.invDeltaY[1] = core::reciprocal( ba ); |
776 | scan.invDeltaY[2] = core::reciprocal( cb ); | 776 | scan.invDeltaY[2] = core::reciprocal( cb ); |
777 | 777 | ||
778 | if ( F32_LOWER_EQUAL_0 ( scan.invDeltaY[0] ) ) | 778 | if ( F32_LOWER_EQUAL_0 ( scan.invDeltaY[0] ) ) |
779 | return; | 779 | return; |
780 | 780 | ||
781 | // find if the major edge is left or right aligned | 781 | // find if the major edge is left or right aligned |
782 | f32 temp[4]; | 782 | f32 temp[4]; |
783 | 783 | ||
784 | temp[0] = a->Pos.x - c->Pos.x; | 784 | temp[0] = a->Pos.x - c->Pos.x; |
785 | temp[1] = -ca; | 785 | temp[1] = -ca; |
786 | temp[2] = b->Pos.x - a->Pos.x; | 786 | temp[2] = b->Pos.x - a->Pos.x; |
787 | temp[3] = ba; | 787 | temp[3] = ba; |
788 | 788 | ||
789 | scan.left = ( temp[0] * temp[3] - temp[1] * temp[2] ) > 0.f ? 0 : 1; | 789 | scan.left = ( temp[0] * temp[3] - temp[1] * temp[2] ) > 0.f ? 0 : 1; |
790 | scan.right = 1 - scan.left; | 790 | scan.right = 1 - scan.left; |
791 | 791 | ||
792 | // calculate slopes for the major edge | 792 | // calculate slopes for the major edge |
793 | scan.slopeX[0] = (c->Pos.x - a->Pos.x) * scan.invDeltaY[0]; | 793 | scan.slopeX[0] = (c->Pos.x - a->Pos.x) * scan.invDeltaY[0]; |
794 | scan.x[0] = a->Pos.x; | 794 | scan.x[0] = a->Pos.x; |
795 | 795 | ||
796 | #ifdef IPOL_Z | 796 | #ifdef IPOL_Z |
797 | scan.slopeZ[0] = (c->Pos.z - a->Pos.z) * scan.invDeltaY[0]; | 797 | scan.slopeZ[0] = (c->Pos.z - a->Pos.z) * scan.invDeltaY[0]; |
798 | scan.z[0] = a->Pos.z; | 798 | scan.z[0] = a->Pos.z; |
799 | #endif | 799 | #endif |
800 | 800 | ||
801 | #ifdef IPOL_W | 801 | #ifdef IPOL_W |
802 | scan.slopeW[0] = (c->Pos.w - a->Pos.w) * scan.invDeltaY[0]; | 802 | scan.slopeW[0] = (c->Pos.w - a->Pos.w) * scan.invDeltaY[0]; |
803 | scan.w[0] = a->Pos.w; | 803 | scan.w[0] = a->Pos.w; |
804 | #endif | 804 | #endif |
805 | 805 | ||
806 | #ifdef IPOL_C0 | 806 | #ifdef IPOL_C0 |
807 | scan.slopeC[0] = (c->Color[0] - a->Color[0]) * scan.invDeltaY[0]; | 807 | scan.slopeC[0] = (c->Color[0] - a->Color[0]) * scan.invDeltaY[0]; |
808 | scan.c[0] = a->Color[0]; | 808 | scan.c[0] = a->Color[0]; |
809 | #endif | 809 | #endif |
810 | 810 | ||
811 | #ifdef IPOL_T0 | 811 | #ifdef IPOL_T0 |
812 | scan.slopeT[0][0] = (c->Tex[0] - a->Tex[0]) * scan.invDeltaY[0]; | 812 | scan.slopeT[0][0] = (c->Tex[0] - a->Tex[0]) * scan.invDeltaY[0]; |
813 | scan.t[0][0] = a->Tex[0]; | 813 | scan.t[0][0] = a->Tex[0]; |
814 | #endif | 814 | #endif |
815 | 815 | ||
816 | #ifdef IPOL_T1 | 816 | #ifdef IPOL_T1 |
817 | scan.slopeT[1][0] = (c->Tex[1] - a->Tex[1]) * scan.invDeltaY[0]; | 817 | scan.slopeT[1][0] = (c->Tex[1] - a->Tex[1]) * scan.invDeltaY[0]; |
818 | scan.t[1][0] = a->Tex[1]; | 818 | scan.t[1][0] = a->Tex[1]; |
819 | #endif | 819 | #endif |
820 | 820 | ||
821 | // top left fill convention y run | 821 | // top left fill convention y run |
822 | s32 yStart; | 822 | s32 yStart; |
823 | s32 yEnd; | 823 | s32 yEnd; |
824 | 824 | ||
825 | #ifdef SUBTEXEL | 825 | #ifdef SUBTEXEL |
826 | f32 subPixel; | 826 | f32 subPixel; |
827 | #endif | 827 | #endif |
828 | 828 | ||
829 | 829 | ||
830 | // rasterize upper sub-triangle | 830 | // rasterize upper sub-triangle |
831 | if ( F32_GREATER_0 ( scan.invDeltaY[1] ) ) | 831 | if ( F32_GREATER_0 ( scan.invDeltaY[1] ) ) |
832 | { | 832 | { |
833 | // calculate slopes for top edge | 833 | // calculate slopes for top edge |
834 | scan.slopeX[1] = (b->Pos.x - a->Pos.x) * scan.invDeltaY[1]; | 834 | scan.slopeX[1] = (b->Pos.x - a->Pos.x) * scan.invDeltaY[1]; |
835 | scan.x[1] = a->Pos.x; | 835 | scan.x[1] = a->Pos.x; |
836 | 836 | ||
837 | #ifdef IPOL_Z | 837 | #ifdef IPOL_Z |
838 | scan.slopeZ[1] = (b->Pos.z - a->Pos.z) * scan.invDeltaY[1]; | 838 | scan.slopeZ[1] = (b->Pos.z - a->Pos.z) * scan.invDeltaY[1]; |
839 | scan.z[1] = a->Pos.z; | 839 | scan.z[1] = a->Pos.z; |
840 | #endif | 840 | #endif |
841 | 841 | ||
842 | #ifdef IPOL_W | 842 | #ifdef IPOL_W |
843 | scan.slopeW[1] = (b->Pos.w - a->Pos.w) * scan.invDeltaY[1]; | 843 | scan.slopeW[1] = (b->Pos.w - a->Pos.w) * scan.invDeltaY[1]; |
844 | scan.w[1] = a->Pos.w; | 844 | scan.w[1] = a->Pos.w; |
845 | #endif | 845 | #endif |
846 | 846 | ||
847 | #ifdef IPOL_C0 | 847 | #ifdef IPOL_C0 |
848 | scan.slopeC[1] = (b->Color[0] - a->Color[0]) * scan.invDeltaY[1]; | 848 | scan.slopeC[1] = (b->Color[0] - a->Color[0]) * scan.invDeltaY[1]; |
849 | scan.c[1] = a->Color[0]; | 849 | scan.c[1] = a->Color[0]; |
850 | #endif | 850 | #endif |
851 | 851 | ||
852 | #ifdef IPOL_T0 | 852 | #ifdef IPOL_T0 |
853 | scan.slopeT[0][1] = (b->Tex[0] - a->Tex[0]) * scan.invDeltaY[1]; | 853 | scan.slopeT[0][1] = (b->Tex[0] - a->Tex[0]) * scan.invDeltaY[1]; |
854 | scan.t[0][1] = a->Tex[0]; | 854 | scan.t[0][1] = a->Tex[0]; |
855 | #endif | 855 | #endif |
856 | 856 | ||
857 | #ifdef IPOL_T1 | 857 | #ifdef IPOL_T1 |
858 | scan.slopeT[1][1] = (b->Tex[1] - a->Tex[1]) * scan.invDeltaY[1]; | 858 | scan.slopeT[1][1] = (b->Tex[1] - a->Tex[1]) * scan.invDeltaY[1]; |
859 | scan.t[1][1] = a->Tex[1]; | 859 | scan.t[1][1] = a->Tex[1]; |
860 | #endif | 860 | #endif |
861 | 861 | ||
862 | // apply top-left fill convention, top part | 862 | // apply top-left fill convention, top part |
863 | yStart = core::ceil32( a->Pos.y ); | 863 | yStart = core::ceil32( a->Pos.y ); |
864 | yEnd = core::ceil32( b->Pos.y ) - 1; | 864 | yEnd = core::ceil32( b->Pos.y ) - 1; |
865 | 865 | ||
866 | #ifdef SUBTEXEL | 866 | #ifdef SUBTEXEL |
867 | subPixel = ( (f32) yStart ) - a->Pos.y; | 867 | subPixel = ( (f32) yStart ) - a->Pos.y; |
868 | 868 | ||
869 | // correct to pixel center | 869 | // correct to pixel center |
870 | scan.x[0] += scan.slopeX[0] * subPixel; | 870 | scan.x[0] += scan.slopeX[0] * subPixel; |
871 | scan.x[1] += scan.slopeX[1] * subPixel; | 871 | scan.x[1] += scan.slopeX[1] * subPixel; |
872 | 872 | ||
873 | #ifdef IPOL_Z | 873 | #ifdef IPOL_Z |
874 | scan.z[0] += scan.slopeZ[0] * subPixel; | 874 | scan.z[0] += scan.slopeZ[0] * subPixel; |
875 | scan.z[1] += scan.slopeZ[1] * subPixel; | 875 | scan.z[1] += scan.slopeZ[1] * subPixel; |
876 | #endif | 876 | #endif |
877 | 877 | ||
878 | #ifdef IPOL_W | 878 | #ifdef IPOL_W |
879 | scan.w[0] += scan.slopeW[0] * subPixel; | 879 | scan.w[0] += scan.slopeW[0] * subPixel; |
880 | scan.w[1] += scan.slopeW[1] * subPixel; | 880 | scan.w[1] += scan.slopeW[1] * subPixel; |
881 | #endif | 881 | #endif |
882 | 882 | ||
883 | #ifdef IPOL_C0 | 883 | #ifdef IPOL_C0 |
884 | scan.c[0] += scan.slopeC[0] * subPixel; | 884 | scan.c[0] += scan.slopeC[0] * subPixel; |
885 | scan.c[1] += scan.slopeC[1] * subPixel; | 885 | scan.c[1] += scan.slopeC[1] * subPixel; |
886 | #endif | 886 | #endif |
887 | 887 | ||
888 | #ifdef IPOL_T0 | 888 | #ifdef IPOL_T0 |
889 | scan.t[0][0] += scan.slopeT[0][0] * subPixel; | 889 | scan.t[0][0] += scan.slopeT[0][0] * subPixel; |
890 | scan.t[0][1] += scan.slopeT[0][1] * subPixel; | 890 | scan.t[0][1] += scan.slopeT[0][1] * subPixel; |
891 | #endif | 891 | #endif |
892 | 892 | ||
893 | #ifdef IPOL_T1 | 893 | #ifdef IPOL_T1 |
894 | scan.t[1][0] += scan.slopeT[1][0] * subPixel; | 894 | scan.t[1][0] += scan.slopeT[1][0] * subPixel; |
895 | scan.t[1][1] += scan.slopeT[1][1] * subPixel; | 895 | scan.t[1][1] += scan.slopeT[1][1] * subPixel; |
896 | #endif | 896 | #endif |
897 | 897 | ||
898 | #endif | 898 | #endif |
899 | 899 | ||
900 | // rasterize the edge scanlines | 900 | // rasterize the edge scanlines |
901 | for( line.y = yStart; line.y <= yEnd; ++line.y) | 901 | for( line.y = yStart; line.y <= yEnd; ++line.y) |
902 | { | 902 | { |
903 | line.x[scan.left] = scan.x[0]; | 903 | line.x[scan.left] = scan.x[0]; |
904 | line.x[scan.right] = scan.x[1]; | 904 | line.x[scan.right] = scan.x[1]; |
905 | 905 | ||
906 | #ifdef IPOL_Z | 906 | #ifdef IPOL_Z |
907 | line.z[scan.left] = scan.z[0]; | 907 | line.z[scan.left] = scan.z[0]; |
908 | line.z[scan.right] = scan.z[1]; | 908 | line.z[scan.right] = scan.z[1]; |
909 | #endif | 909 | #endif |
910 | 910 | ||
911 | #ifdef IPOL_W | 911 | #ifdef IPOL_W |
912 | line.w[scan.left] = scan.w[0]; | 912 | line.w[scan.left] = scan.w[0]; |
913 | line.w[scan.right] = scan.w[1]; | 913 | line.w[scan.right] = scan.w[1]; |
914 | #endif | 914 | #endif |
915 | 915 | ||
916 | #ifdef IPOL_C0 | 916 | #ifdef IPOL_C0 |
917 | line.c[scan.left] = scan.c[0]; | 917 | line.c[scan.left] = scan.c[0]; |
918 | line.c[scan.right] = scan.c[1]; | 918 | line.c[scan.right] = scan.c[1]; |
919 | #endif | 919 | #endif |
920 | 920 | ||
921 | #ifdef IPOL_T0 | 921 | #ifdef IPOL_T0 |
922 | line.t[0][scan.left] = scan.t[0][0]; | 922 | line.t[0][scan.left] = scan.t[0][0]; |
923 | line.t[0][scan.right] = scan.t[0][1]; | 923 | line.t[0][scan.right] = scan.t[0][1]; |
924 | #endif | 924 | #endif |
925 | 925 | ||
926 | #ifdef IPOL_T1 | 926 | #ifdef IPOL_T1 |
927 | line.t[1][scan.left] = scan.t[1][0]; | 927 | line.t[1][scan.left] = scan.t[1][0]; |
928 | line.t[1][scan.right] = scan.t[1][1]; | 928 | line.t[1][scan.right] = scan.t[1][1]; |
929 | #endif | 929 | #endif |
930 | 930 | ||
931 | // render a scanline | 931 | // render a scanline |
932 | scanline_bilinear2_mag (); | 932 | scanline_bilinear2_mag (); |
933 | 933 | ||
934 | scan.x[0] += scan.slopeX[0]; | 934 | scan.x[0] += scan.slopeX[0]; |
935 | scan.x[1] += scan.slopeX[1]; | 935 | scan.x[1] += scan.slopeX[1]; |
936 | 936 | ||
937 | #ifdef IPOL_Z | 937 | #ifdef IPOL_Z |
938 | scan.z[0] += scan.slopeZ[0]; | 938 | scan.z[0] += scan.slopeZ[0]; |
939 | scan.z[1] += scan.slopeZ[1]; | 939 | scan.z[1] += scan.slopeZ[1]; |
940 | #endif | 940 | #endif |
941 | 941 | ||
942 | #ifdef IPOL_W | 942 | #ifdef IPOL_W |
943 | scan.w[0] += scan.slopeW[0]; | 943 | scan.w[0] += scan.slopeW[0]; |
944 | scan.w[1] += scan.slopeW[1]; | 944 | scan.w[1] += scan.slopeW[1]; |
945 | #endif | 945 | #endif |
946 | 946 | ||
947 | #ifdef IPOL_C0 | 947 | #ifdef IPOL_C0 |
948 | scan.c[0] += scan.slopeC[0]; | 948 | scan.c[0] += scan.slopeC[0]; |
949 | scan.c[1] += scan.slopeC[1]; | 949 | scan.c[1] += scan.slopeC[1]; |
950 | #endif | 950 | #endif |
951 | 951 | ||
952 | #ifdef IPOL_T0 | 952 | #ifdef IPOL_T0 |
953 | scan.t[0][0] += scan.slopeT[0][0]; | 953 | scan.t[0][0] += scan.slopeT[0][0]; |
954 | scan.t[0][1] += scan.slopeT[0][1]; | 954 | scan.t[0][1] += scan.slopeT[0][1]; |
955 | #endif | 955 | #endif |
956 | 956 | ||
957 | #ifdef IPOL_T1 | 957 | #ifdef IPOL_T1 |
958 | scan.t[1][0] += scan.slopeT[1][0]; | 958 | scan.t[1][0] += scan.slopeT[1][0]; |
959 | scan.t[1][1] += scan.slopeT[1][1]; | 959 | scan.t[1][1] += scan.slopeT[1][1]; |
960 | #endif | 960 | #endif |
961 | 961 | ||
962 | } | 962 | } |
963 | } | 963 | } |
964 | 964 | ||
965 | // rasterize lower sub-triangle | 965 | // rasterize lower sub-triangle |
966 | //if ( (f32) 0.0 != scan.invDeltaY[2] ) | 966 | //if ( (f32) 0.0 != scan.invDeltaY[2] ) |
967 | if ( F32_GREATER_0 ( scan.invDeltaY[2] ) ) | 967 | if ( F32_GREATER_0 ( scan.invDeltaY[2] ) ) |
968 | { | 968 | { |
969 | // advance to middle point | 969 | // advance to middle point |
970 | if ( F32_GREATER_0 ( scan.invDeltaY[1] ) ) | 970 | if ( F32_GREATER_0 ( scan.invDeltaY[1] ) ) |
971 | { | 971 | { |
972 | temp[0] = b->Pos.y - a->Pos.y; // dy | 972 | temp[0] = b->Pos.y - a->Pos.y; // dy |
973 | 973 | ||
974 | scan.x[0] = a->Pos.x + scan.slopeX[0] * temp[0]; | 974 | scan.x[0] = a->Pos.x + scan.slopeX[0] * temp[0]; |
975 | #ifdef IPOL_Z | 975 | #ifdef IPOL_Z |
976 | scan.z[0] = a->Pos.z + scan.slopeZ[0] * temp[0]; | 976 | scan.z[0] = a->Pos.z + scan.slopeZ[0] * temp[0]; |
977 | #endif | 977 | #endif |
978 | #ifdef IPOL_W | 978 | #ifdef IPOL_W |
979 | scan.w[0] = a->Pos.w + scan.slopeW[0] * temp[0]; | 979 | scan.w[0] = a->Pos.w + scan.slopeW[0] * temp[0]; |
980 | #endif | 980 | #endif |
981 | #ifdef IPOL_C0 | 981 | #ifdef IPOL_C0 |
982 | scan.c[0] = a->Color[0] + scan.slopeC[0] * temp[0]; | 982 | scan.c[0] = a->Color[0] + scan.slopeC[0] * temp[0]; |
983 | #endif | 983 | #endif |
984 | #ifdef IPOL_T0 | 984 | #ifdef IPOL_T0 |
985 | scan.t[0][0] = a->Tex[0] + scan.slopeT[0][0] * temp[0]; | 985 | scan.t[0][0] = a->Tex[0] + scan.slopeT[0][0] * temp[0]; |
986 | #endif | 986 | #endif |
987 | #ifdef IPOL_T1 | 987 | #ifdef IPOL_T1 |
988 | scan.t[1][0] = a->Tex[1] + scan.slopeT[1][0] * temp[0]; | 988 | scan.t[1][0] = a->Tex[1] + scan.slopeT[1][0] * temp[0]; |
989 | #endif | 989 | #endif |
990 | 990 | ||
991 | } | 991 | } |
992 | 992 | ||
993 | // calculate slopes for bottom edge | 993 | // calculate slopes for bottom edge |
994 | scan.slopeX[1] = (c->Pos.x - b->Pos.x) * scan.invDeltaY[2]; | 994 | scan.slopeX[1] = (c->Pos.x - b->Pos.x) * scan.invDeltaY[2]; |
995 | scan.x[1] = b->Pos.x; | 995 | scan.x[1] = b->Pos.x; |
996 | 996 | ||
997 | #ifdef IPOL_Z | 997 | #ifdef IPOL_Z |
998 | scan.slopeZ[1] = (c->Pos.z - b->Pos.z) * scan.invDeltaY[2]; | 998 | scan.slopeZ[1] = (c->Pos.z - b->Pos.z) * scan.invDeltaY[2]; |
999 | scan.z[1] = b->Pos.z; | 999 | scan.z[1] = b->Pos.z; |
1000 | #endif | 1000 | #endif |
1001 | 1001 | ||
1002 | #ifdef IPOL_W | 1002 | #ifdef IPOL_W |
1003 | scan.slopeW[1] = (c->Pos.w - b->Pos.w) * scan.invDeltaY[2]; | 1003 | scan.slopeW[1] = (c->Pos.w - b->Pos.w) * scan.invDeltaY[2]; |
1004 | scan.w[1] = b->Pos.w; | 1004 | scan.w[1] = b->Pos.w; |
1005 | #endif | 1005 | #endif |
1006 | 1006 | ||
1007 | #ifdef IPOL_C0 | 1007 | #ifdef IPOL_C0 |
1008 | scan.slopeC[1] = (c->Color[0] - b->Color[0]) * scan.invDeltaY[2]; | 1008 | scan.slopeC[1] = (c->Color[0] - b->Color[0]) * scan.invDeltaY[2]; |
1009 | scan.c[1] = b->Color[0]; | 1009 | scan.c[1] = b->Color[0]; |
1010 | #endif | 1010 | #endif |
1011 | 1011 | ||
1012 | #ifdef IPOL_T0 | 1012 | #ifdef IPOL_T0 |
1013 | scan.slopeT[0][1] = (c->Tex[0] - b->Tex[0]) * scan.invDeltaY[2]; | 1013 | scan.slopeT[0][1] = (c->Tex[0] - b->Tex[0]) * scan.invDeltaY[2]; |
1014 | scan.t[0][1] = b->Tex[0]; | 1014 | scan.t[0][1] = b->Tex[0]; |
1015 | #endif | 1015 | #endif |
1016 | 1016 | ||
1017 | #ifdef IPOL_T1 | 1017 | #ifdef IPOL_T1 |
1018 | scan.slopeT[1][1] = (c->Tex[1] - b->Tex[1]) * scan.invDeltaY[2]; | 1018 | scan.slopeT[1][1] = (c->Tex[1] - b->Tex[1]) * scan.invDeltaY[2]; |
1019 | scan.t[1][1] = b->Tex[1]; | 1019 | scan.t[1][1] = b->Tex[1]; |
1020 | #endif | 1020 | #endif |
1021 | 1021 | ||
1022 | // apply top-left fill convention, top part | 1022 | // apply top-left fill convention, top part |
1023 | yStart = core::ceil32( b->Pos.y ); | 1023 | yStart = core::ceil32( b->Pos.y ); |
1024 | yEnd = core::ceil32( c->Pos.y ) - 1; | 1024 | yEnd = core::ceil32( c->Pos.y ) - 1; |
1025 | 1025 | ||
1026 | #ifdef SUBTEXEL | 1026 | #ifdef SUBTEXEL |
1027 | 1027 | ||
1028 | subPixel = ( (f32) yStart ) - b->Pos.y; | 1028 | subPixel = ( (f32) yStart ) - b->Pos.y; |
1029 | 1029 | ||
1030 | // correct to pixel center | 1030 | // correct to pixel center |
1031 | scan.x[0] += scan.slopeX[0] * subPixel; | 1031 | scan.x[0] += scan.slopeX[0] * subPixel; |
1032 | scan.x[1] += scan.slopeX[1] * subPixel; | 1032 | scan.x[1] += scan.slopeX[1] * subPixel; |
1033 | 1033 | ||
1034 | #ifdef IPOL_Z | 1034 | #ifdef IPOL_Z |
1035 | scan.z[0] += scan.slopeZ[0] * subPixel; | 1035 | scan.z[0] += scan.slopeZ[0] * subPixel; |
1036 | scan.z[1] += scan.slopeZ[1] * subPixel; | 1036 | scan.z[1] += scan.slopeZ[1] * subPixel; |
1037 | #endif | 1037 | #endif |
1038 | 1038 | ||
1039 | #ifdef IPOL_W | 1039 | #ifdef IPOL_W |
1040 | scan.w[0] += scan.slopeW[0] * subPixel; | 1040 | scan.w[0] += scan.slopeW[0] * subPixel; |
1041 | scan.w[1] += scan.slopeW[1] * subPixel; | 1041 | scan.w[1] += scan.slopeW[1] * subPixel; |
1042 | #endif | 1042 | #endif |
1043 | 1043 | ||
1044 | #ifdef IPOL_C0 | 1044 | #ifdef IPOL_C0 |
1045 | scan.c[0] += scan.slopeC[0] * subPixel; | 1045 | scan.c[0] += scan.slopeC[0] * subPixel; |
1046 | scan.c[1] += scan.slopeC[1] * subPixel; | 1046 | scan.c[1] += scan.slopeC[1] * subPixel; |
1047 | #endif | 1047 | #endif |
1048 | 1048 | ||
1049 | #ifdef IPOL_T0 | 1049 | #ifdef IPOL_T0 |
1050 | scan.t[0][0] += scan.slopeT[0][0] * subPixel; | 1050 | scan.t[0][0] += scan.slopeT[0][0] * subPixel; |
1051 | scan.t[0][1] += scan.slopeT[0][1] * subPixel; | 1051 | scan.t[0][1] += scan.slopeT[0][1] * subPixel; |
1052 | #endif | 1052 | #endif |
1053 | 1053 | ||
1054 | #ifdef IPOL_T1 | 1054 | #ifdef IPOL_T1 |
1055 | scan.t[1][0] += scan.slopeT[1][0] * subPixel; | 1055 | scan.t[1][0] += scan.slopeT[1][0] * subPixel; |
1056 | scan.t[1][1] += scan.slopeT[1][1] * subPixel; | 1056 | scan.t[1][1] += scan.slopeT[1][1] * subPixel; |
1057 | #endif | 1057 | #endif |
1058 | 1058 | ||
1059 | #endif | 1059 | #endif |
1060 | 1060 | ||
1061 | // rasterize the edge scanlines | 1061 | // rasterize the edge scanlines |
1062 | for( line.y = yStart; line.y <= yEnd; ++line.y) | 1062 | for( line.y = yStart; line.y <= yEnd; ++line.y) |
1063 | { | 1063 | { |
1064 | line.x[scan.left] = scan.x[0]; | 1064 | line.x[scan.left] = scan.x[0]; |
1065 | line.x[scan.right] = scan.x[1]; | 1065 | line.x[scan.right] = scan.x[1]; |
1066 | 1066 | ||
1067 | #ifdef IPOL_Z | 1067 | #ifdef IPOL_Z |
1068 | line.z[scan.left] = scan.z[0]; | 1068 | line.z[scan.left] = scan.z[0]; |
1069 | line.z[scan.right] = scan.z[1]; | 1069 | line.z[scan.right] = scan.z[1]; |
1070 | #endif | 1070 | #endif |
1071 | 1071 | ||
1072 | #ifdef IPOL_W | 1072 | #ifdef IPOL_W |
1073 | line.w[scan.left] = scan.w[0]; | 1073 | line.w[scan.left] = scan.w[0]; |
1074 | line.w[scan.right] = scan.w[1]; | 1074 | line.w[scan.right] = scan.w[1]; |
1075 | #endif | 1075 | #endif |
1076 | 1076 | ||
1077 | #ifdef IPOL_C0 | 1077 | #ifdef IPOL_C0 |
1078 | line.c[scan.left] = scan.c[0]; | 1078 | line.c[scan.left] = scan.c[0]; |
1079 | line.c[scan.right] = scan.c[1]; | 1079 | line.c[scan.right] = scan.c[1]; |
1080 | #endif | 1080 | #endif |
1081 | 1081 | ||
1082 | #ifdef IPOL_T0 | 1082 | #ifdef IPOL_T0 |
1083 | line.t[0][scan.left] = scan.t[0][0]; | 1083 | line.t[0][scan.left] = scan.t[0][0]; |
1084 | line.t[0][scan.right] = scan.t[0][1]; | 1084 | line.t[0][scan.right] = scan.t[0][1]; |
1085 | #endif | 1085 | #endif |
1086 | 1086 | ||
1087 | #ifdef IPOL_T1 | 1087 | #ifdef IPOL_T1 |
1088 | line.t[1][scan.left] = scan.t[1][0]; | 1088 | line.t[1][scan.left] = scan.t[1][0]; |
1089 | line.t[1][scan.right] = scan.t[1][1]; | 1089 | line.t[1][scan.right] = scan.t[1][1]; |
1090 | #endif | 1090 | #endif |
1091 | 1091 | ||
1092 | // render a scanline | 1092 | // render a scanline |
1093 | scanline_bilinear2_mag (); | 1093 | scanline_bilinear2_mag (); |
1094 | 1094 | ||
1095 | scan.x[0] += scan.slopeX[0]; | 1095 | scan.x[0] += scan.slopeX[0]; |
1096 | scan.x[1] += scan.slopeX[1]; | 1096 | scan.x[1] += scan.slopeX[1]; |
1097 | 1097 | ||
1098 | #ifdef IPOL_Z | 1098 | #ifdef IPOL_Z |
1099 | scan.z[0] += scan.slopeZ[0]; | 1099 | scan.z[0] += scan.slopeZ[0]; |
1100 | scan.z[1] += scan.slopeZ[1]; | 1100 | scan.z[1] += scan.slopeZ[1]; |
1101 | #endif | 1101 | #endif |
1102 | 1102 | ||
1103 | #ifdef IPOL_W | 1103 | #ifdef IPOL_W |
1104 | scan.w[0] += scan.slopeW[0]; | 1104 | scan.w[0] += scan.slopeW[0]; |
1105 | scan.w[1] += scan.slopeW[1]; | 1105 | scan.w[1] += scan.slopeW[1]; |
1106 | #endif | 1106 | #endif |
1107 | 1107 | ||
1108 | #ifdef IPOL_C0 | 1108 | #ifdef IPOL_C0 |
1109 | scan.c[0] += scan.slopeC[0]; | 1109 | scan.c[0] += scan.slopeC[0]; |
1110 | scan.c[1] += scan.slopeC[1]; | 1110 | scan.c[1] += scan.slopeC[1]; |
1111 | #endif | 1111 | #endif |
1112 | 1112 | ||
1113 | #ifdef IPOL_T0 | 1113 | #ifdef IPOL_T0 |
1114 | scan.t[0][0] += scan.slopeT[0][0]; | 1114 | scan.t[0][0] += scan.slopeT[0][0]; |
1115 | scan.t[0][1] += scan.slopeT[0][1]; | 1115 | scan.t[0][1] += scan.slopeT[0][1]; |
1116 | #endif | 1116 | #endif |
1117 | 1117 | ||
1118 | #ifdef IPOL_T1 | 1118 | #ifdef IPOL_T1 |
1119 | scan.t[1][0] += scan.slopeT[1][0]; | 1119 | scan.t[1][0] += scan.slopeT[1][0]; |
1120 | scan.t[1][1] += scan.slopeT[1][1]; | 1120 | scan.t[1][1] += scan.slopeT[1][1]; |
1121 | #endif | 1121 | #endif |
1122 | 1122 | ||
1123 | } | 1123 | } |
1124 | } | 1124 | } |
1125 | 1125 | ||
1126 | } | 1126 | } |
1127 | 1127 | ||
1128 | } // end namespace video | 1128 | } // end namespace video |
1129 | } // end namespace irr | 1129 | } // end namespace irr |
1130 | 1130 | ||
1131 | #endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_ | 1131 | #endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_ |
1132 | 1132 | ||
1133 | namespace irr | 1133 | namespace irr |
1134 | { | 1134 | { |
1135 | namespace video | 1135 | namespace video |
1136 | { | 1136 | { |
1137 | 1137 | ||
1138 | 1138 | ||
1139 | //! creates a flat triangle renderer | 1139 | //! creates a flat triangle renderer |
1140 | IBurningShader* createTriangleRendererTextureLightMap2_M4(CBurningVideoDriver* driver) | 1140 | IBurningShader* createTriangleRendererTextureLightMap2_M4(CBurningVideoDriver* driver) |
1141 | { | 1141 | { |
1142 | #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_ | 1142 | #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_ |
1143 | return new CTRTextureLightMap2_M4(driver); | 1143 | return new CTRTextureLightMap2_M4(driver); |
1144 | #else | 1144 | #else |
1145 | return 0; | 1145 | return 0; |
1146 | #endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_ | 1146 | #endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_ |
1147 | } | 1147 | } |
1148 | 1148 | ||
1149 | 1149 | ||
1150 | } // end namespace video | 1150 | } // end namespace video |
1151 | } // end namespace irr | 1151 | } // end namespace irr |
1152 | 1152 | ||
1153 | 1153 | ||
1154 | 1154 | ||