aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CTRGouraud2.cpp
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-13 18:54:10 +1000
committerDavid Walter Seikel2013-01-13 18:54:10 +1000
commit959831f4ef5a3e797f576c3de08cd65032c997ad (patch)
treee7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/CTRGouraud2.cpp
parentAdd info about changes to Irrlicht. (diff)
downloadSledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CTRGouraud2.cpp')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CTRGouraud2.cpp1290
1 files changed, 645 insertions, 645 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CTRGouraud2.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CTRGouraud2.cpp
index 48ed4d1..5d0b69f 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CTRGouraud2.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CTRGouraud2.cpp
@@ -1,645 +1,645 @@
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 71
72namespace irr 72namespace irr
73{ 73{
74 74
75namespace video 75namespace video
76{ 76{
77 77
78class CTRGouraud2 : public IBurningShader 78class CTRGouraud2 : public IBurningShader
79{ 79{
80public: 80public:
81 81
82 //! constructor 82 //! constructor
83 CTRGouraud2(CBurningVideoDriver* driver); 83 CTRGouraud2(CBurningVideoDriver* driver);
84 84
85 //! draws an indexed triangle list 85 //! draws an indexed triangle list
86 virtual void drawTriangle ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c ); 86 virtual void drawTriangle ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c );
87 87
88 88
89private: 89private:
90 void scanline_bilinear (); 90 void scanline_bilinear ();
91 sScanConvertData scan; 91 sScanConvertData scan;
92 sScanLineData line; 92 sScanLineData line;
93 93
94}; 94};
95 95
96//! constructor 96//! constructor
97CTRGouraud2::CTRGouraud2(CBurningVideoDriver* driver) 97CTRGouraud2::CTRGouraud2(CBurningVideoDriver* driver)
98: IBurningShader(driver) 98: IBurningShader(driver)
99{ 99{
100 #ifdef _DEBUG 100 #ifdef _DEBUG
101 setDebugName("CTRGouraud2"); 101 setDebugName("CTRGouraud2");
102 #endif 102 #endif
103} 103}
104 104
105 105
106 106
107/*! 107/*!
108*/ 108*/
109void CTRGouraud2::scanline_bilinear () 109void CTRGouraud2::scanline_bilinear ()
110{ 110{
111 tVideoSample *dst; 111 tVideoSample *dst;
112 112
113#ifdef USE_ZBUFFER 113#ifdef USE_ZBUFFER
114 fp24 *z; 114 fp24 *z;
115#endif 115#endif
116 116
117 s32 xStart; 117 s32 xStart;
118 s32 xEnd; 118 s32 xEnd;
119 s32 dx; 119 s32 dx;
120 120
121#ifdef SUBTEXEL 121#ifdef SUBTEXEL
122 f32 subPixel; 122 f32 subPixel;
123#endif 123#endif
124 124
125#ifdef IPOL_Z 125#ifdef IPOL_Z
126 f32 slopeZ; 126 f32 slopeZ;
127#endif 127#endif
128#ifdef IPOL_W 128#ifdef IPOL_W
129 fp24 slopeW; 129 fp24 slopeW;
130#endif 130#endif
131#ifdef IPOL_C0 131#ifdef IPOL_C0
132 sVec4 slopeC; 132 sVec4 slopeC;
133#endif 133#endif
134#ifdef IPOL_T0 134#ifdef IPOL_T0
135 sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES]; 135 sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES];
136#endif 136#endif
137 137
138 // apply top-left fill-convention, left 138 // apply top-left fill-convention, left
139 xStart = core::ceil32( line.x[0] ); 139 xStart = core::ceil32( line.x[0] );
140 xEnd = core::ceil32( line.x[1] ) - 1; 140 xEnd = core::ceil32( line.x[1] ) - 1;
141 141
142 dx = xEnd - xStart; 142 dx = xEnd - xStart;
143 143
144 if ( dx < 0 ) 144 if ( dx < 0 )
145 return; 145 return;
146 146
147 // slopes 147 // slopes
148 const f32 invDeltaX = core::reciprocal_approxim ( line.x[1] - line.x[0] ); 148 const f32 invDeltaX = core::reciprocal_approxim ( line.x[1] - line.x[0] );
149 149
150#ifdef IPOL_Z 150#ifdef IPOL_Z
151 slopeZ = (line.z[1] - line.z[0]) * invDeltaX; 151 slopeZ = (line.z[1] - line.z[0]) * invDeltaX;
152#endif 152#endif
153#ifdef IPOL_W 153#ifdef IPOL_W
154 slopeW = (line.w[1] - line.w[0]) * invDeltaX; 154 slopeW = (line.w[1] - line.w[0]) * invDeltaX;
155#endif 155#endif
156#ifdef IPOL_C0 156#ifdef IPOL_C0
157 slopeC = (line.c[0][1] - line.c[0][0]) * invDeltaX; 157 slopeC = (line.c[0][1] - line.c[0][0]) * invDeltaX;
158#endif 158#endif
159#ifdef IPOL_T0 159#ifdef IPOL_T0
160 slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX; 160 slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX;
161#endif 161#endif
162#ifdef IPOL_T1 162#ifdef IPOL_T1
163 slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX; 163 slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX;
164#endif 164#endif
165 165
166#ifdef SUBTEXEL 166#ifdef SUBTEXEL
167 subPixel = ( (f32) xStart ) - line.x[0]; 167 subPixel = ( (f32) xStart ) - line.x[0];
168#ifdef IPOL_Z 168#ifdef IPOL_Z
169 line.z[0] += slopeZ * subPixel; 169 line.z[0] += slopeZ * subPixel;
170#endif 170#endif
171#ifdef IPOL_W 171#ifdef IPOL_W
172 line.w[0] += slopeW * subPixel; 172 line.w[0] += slopeW * subPixel;
173#endif 173#endif
174#ifdef IPOL_C0 174#ifdef IPOL_C0
175 line.c[0][0] += slopeC * subPixel; 175 line.c[0][0] += slopeC * subPixel;
176#endif 176#endif
177#ifdef IPOL_T0 177#ifdef IPOL_T0
178 line.t[0][0] += slopeT[0] * subPixel; 178 line.t[0][0] += slopeT[0] * subPixel;
179#endif 179#endif
180#ifdef IPOL_T1 180#ifdef IPOL_T1
181 line.t[1][0] += slopeT[1] * subPixel; 181 line.t[1][0] += slopeT[1] * subPixel;
182#endif 182#endif
183#endif 183#endif
184 184
185 dst = (tVideoSample*)RenderTarget->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart; 185 dst = (tVideoSample*)RenderTarget->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;
186 186
187#ifdef USE_ZBUFFER 187#ifdef USE_ZBUFFER
188 z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart; 188 z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;
189#endif 189#endif
190 190
191 191
192 192
193#ifdef IPOL_C0 193#ifdef IPOL_C0
194 tFixPoint r0, g0, b0; 194 tFixPoint r0, g0, b0;
195 195
196#ifdef INVERSE_W 196#ifdef INVERSE_W
197 f32 inversew; 197 f32 inversew;
198#endif 198#endif
199 199
200#endif 200#endif
201 201
202 for ( s32 i = 0; i <= dx; ++i ) 202 for ( s32 i = 0; i <= dx; ++i )
203 { 203 {
204#ifdef CMP_Z 204#ifdef CMP_Z
205 if ( line.z[0] < z[i] ) 205 if ( line.z[0] < z[i] )
206#endif 206#endif
207#ifdef CMP_W 207#ifdef CMP_W
208 if ( line.w[0] >= z[i] ) 208 if ( line.w[0] >= z[i] )
209#endif 209#endif
210 210
211 { 211 {
212#ifdef IPOL_C0 212#ifdef IPOL_C0
213#ifdef INVERSE_W 213#ifdef INVERSE_W
214 inversew = core::reciprocal ( line.w[0] ); 214 inversew = core::reciprocal ( line.w[0] );
215 215
216 getSample_color ( r0, g0, b0, line.c[0][0] * inversew ); 216 getSample_color ( r0, g0, b0, line.c[0][0] * inversew );
217#else 217#else
218 getSample_color ( r0, g0, b0, line.c[0][0] ); 218 getSample_color ( r0, g0, b0, line.c[0][0] );
219#endif 219#endif
220 220
221 dst[i] = fix_to_color ( r0, g0, b0 ); 221 dst[i] = fix_to_color ( r0, g0, b0 );
222#else 222#else
223 dst[i] = COLOR_BRIGHT_WHITE; 223 dst[i] = COLOR_BRIGHT_WHITE;
224#endif 224#endif
225 225
226#ifdef WRITE_Z 226#ifdef WRITE_Z
227 z[i] = line.z[0]; 227 z[i] = line.z[0];
228#endif 228#endif
229#ifdef WRITE_W 229#ifdef WRITE_W
230 z[i] = line.w[0]; 230 z[i] = line.w[0];
231#endif 231#endif
232 232
233 } 233 }
234 234
235#ifdef IPOL_Z 235#ifdef IPOL_Z
236 line.z[0] += slopeZ; 236 line.z[0] += slopeZ;
237#endif 237#endif
238#ifdef IPOL_W 238#ifdef IPOL_W
239 line.w[0] += slopeW; 239 line.w[0] += slopeW;
240#endif 240#endif
241#ifdef IPOL_C0 241#ifdef IPOL_C0
242 line.c[0][0] += slopeC; 242 line.c[0][0] += slopeC;
243#endif 243#endif
244#ifdef IPOL_T0 244#ifdef IPOL_T0
245 line.t[0][0] += slopeT[0]; 245 line.t[0][0] += slopeT[0];
246#endif 246#endif
247#ifdef IPOL_T1 247#ifdef IPOL_T1
248 line.t[1][0] += slopeT[1]; 248 line.t[1][0] += slopeT[1];
249#endif 249#endif
250 } 250 }
251 251
252} 252}
253 253
254void CTRGouraud2::drawTriangle ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c ) 254void CTRGouraud2::drawTriangle ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c )
255{ 255{
256 // sort on height, y 256 // sort on height, y
257 if ( a->Pos.y > b->Pos.y ) swapVertexPointer(&a, &b); 257 if ( a->Pos.y > b->Pos.y ) swapVertexPointer(&a, &b);
258 if ( a->Pos.y > c->Pos.y ) swapVertexPointer(&a, &c); 258 if ( a->Pos.y > c->Pos.y ) swapVertexPointer(&a, &c);
259 if ( b->Pos.y > c->Pos.y ) swapVertexPointer(&b, &c); 259 if ( b->Pos.y > c->Pos.y ) swapVertexPointer(&b, &c);
260 260
261 const f32 ca = c->Pos.y - a->Pos.y; 261 const f32 ca = c->Pos.y - a->Pos.y;
262 const f32 ba = b->Pos.y - a->Pos.y; 262 const f32 ba = b->Pos.y - a->Pos.y;
263 const f32 cb = c->Pos.y - b->Pos.y; 263 const f32 cb = c->Pos.y - b->Pos.y;
264 // calculate delta y of the edges 264 // calculate delta y of the edges
265 scan.invDeltaY[0] = core::reciprocal( ca ); 265 scan.invDeltaY[0] = core::reciprocal( ca );
266 scan.invDeltaY[1] = core::reciprocal( ba ); 266 scan.invDeltaY[1] = core::reciprocal( ba );
267 scan.invDeltaY[2] = core::reciprocal( cb ); 267 scan.invDeltaY[2] = core::reciprocal( cb );
268 268
269 if ( F32_LOWER_EQUAL_0 ( scan.invDeltaY[0] ) ) 269 if ( F32_LOWER_EQUAL_0 ( scan.invDeltaY[0] ) )
270 return; 270 return;
271 271
272 // find if the major edge is left or right aligned 272 // find if the major edge is left or right aligned
273 f32 temp[4]; 273 f32 temp[4];
274 274
275 temp[0] = a->Pos.x - c->Pos.x; 275 temp[0] = a->Pos.x - c->Pos.x;
276 temp[1] = -ca; 276 temp[1] = -ca;
277 temp[2] = b->Pos.x - a->Pos.x; 277 temp[2] = b->Pos.x - a->Pos.x;
278 temp[3] = ba; 278 temp[3] = ba;
279 279
280 scan.left = ( temp[0] * temp[3] - temp[1] * temp[2] ) > 0.f ? 0 : 1; 280 scan.left = ( temp[0] * temp[3] - temp[1] * temp[2] ) > 0.f ? 0 : 1;
281 scan.right = 1 - scan.left; 281 scan.right = 1 - scan.left;
282 282
283 // calculate slopes for the major edge 283 // calculate slopes for the major edge
284 scan.slopeX[0] = (c->Pos.x - a->Pos.x) * scan.invDeltaY[0]; 284 scan.slopeX[0] = (c->Pos.x - a->Pos.x) * scan.invDeltaY[0];
285 scan.x[0] = a->Pos.x; 285 scan.x[0] = a->Pos.x;
286 286
287#ifdef IPOL_Z 287#ifdef IPOL_Z
288 scan.slopeZ[0] = (c->Pos.z - a->Pos.z) * scan.invDeltaY[0]; 288 scan.slopeZ[0] = (c->Pos.z - a->Pos.z) * scan.invDeltaY[0];
289 scan.z[0] = a->Pos.z; 289 scan.z[0] = a->Pos.z;
290#endif 290#endif
291 291
292#ifdef IPOL_W 292#ifdef IPOL_W
293 scan.slopeW[0] = (c->Pos.w - a->Pos.w) * scan.invDeltaY[0]; 293 scan.slopeW[0] = (c->Pos.w - a->Pos.w) * scan.invDeltaY[0];
294 scan.w[0] = a->Pos.w; 294 scan.w[0] = a->Pos.w;
295#endif 295#endif
296 296
297#ifdef IPOL_C0 297#ifdef IPOL_C0
298 scan.slopeC[0][0] = (c->Color[0] - a->Color[0]) * scan.invDeltaY[0]; 298 scan.slopeC[0][0] = (c->Color[0] - a->Color[0]) * scan.invDeltaY[0];
299 scan.c[0][0] = a->Color[0]; 299 scan.c[0][0] = a->Color[0];
300#endif 300#endif
301 301
302#ifdef IPOL_T0 302#ifdef IPOL_T0
303 scan.slopeT[0][0] = (c->Tex[0] - a->Tex[0]) * scan.invDeltaY[0]; 303 scan.slopeT[0][0] = (c->Tex[0] - a->Tex[0]) * scan.invDeltaY[0];
304 scan.t[0][0] = a->Tex[0]; 304 scan.t[0][0] = a->Tex[0];
305#endif 305#endif
306 306
307#ifdef IPOL_T1 307#ifdef IPOL_T1
308 scan.slopeT[1][0] = (c->Tex[1] - a->Tex[1]) * scan.invDeltaY[0]; 308 scan.slopeT[1][0] = (c->Tex[1] - a->Tex[1]) * scan.invDeltaY[0];
309 scan.t[1][0] = a->Tex[1]; 309 scan.t[1][0] = a->Tex[1];
310#endif 310#endif
311 311
312 // top left fill convention y run 312 // top left fill convention y run
313 s32 yStart; 313 s32 yStart;
314 s32 yEnd; 314 s32 yEnd;
315 315
316#ifdef SUBTEXEL 316#ifdef SUBTEXEL
317 f32 subPixel; 317 f32 subPixel;
318#endif 318#endif
319 319
320 320
321 // rasterize upper sub-triangle 321 // rasterize upper sub-triangle
322 if ( (f32) 0.0 != scan.invDeltaY[1] ) 322 if ( (f32) 0.0 != scan.invDeltaY[1] )
323 { 323 {
324 // calculate slopes for top edge 324 // calculate slopes for top edge
325 scan.slopeX[1] = (b->Pos.x - a->Pos.x) * scan.invDeltaY[1]; 325 scan.slopeX[1] = (b->Pos.x - a->Pos.x) * scan.invDeltaY[1];
326 scan.x[1] = a->Pos.x; 326 scan.x[1] = a->Pos.x;
327 327
328#ifdef IPOL_Z 328#ifdef IPOL_Z
329 scan.slopeZ[1] = (b->Pos.z - a->Pos.z) * scan.invDeltaY[1]; 329 scan.slopeZ[1] = (b->Pos.z - a->Pos.z) * scan.invDeltaY[1];
330 scan.z[1] = a->Pos.z; 330 scan.z[1] = a->Pos.z;
331#endif 331#endif
332 332
333#ifdef IPOL_W 333#ifdef IPOL_W
334 scan.slopeW[1] = (b->Pos.w - a->Pos.w) * scan.invDeltaY[1]; 334 scan.slopeW[1] = (b->Pos.w - a->Pos.w) * scan.invDeltaY[1];
335 scan.w[1] = a->Pos.w; 335 scan.w[1] = a->Pos.w;
336#endif 336#endif
337 337
338#ifdef IPOL_C0 338#ifdef IPOL_C0
339 scan.slopeC[0][1] = (b->Color[0] - a->Color[0]) * scan.invDeltaY[1]; 339 scan.slopeC[0][1] = (b->Color[0] - a->Color[0]) * scan.invDeltaY[1];
340 scan.c[0][1] = a->Color[0]; 340 scan.c[0][1] = a->Color[0];
341#endif 341#endif
342 342
343#ifdef IPOL_T0 343#ifdef IPOL_T0
344 scan.slopeT[0][1] = (b->Tex[0] - a->Tex[0]) * scan.invDeltaY[1]; 344 scan.slopeT[0][1] = (b->Tex[0] - a->Tex[0]) * scan.invDeltaY[1];
345 scan.t[0][1] = a->Tex[0]; 345 scan.t[0][1] = a->Tex[0];
346#endif 346#endif
347 347
348#ifdef IPOL_T1 348#ifdef IPOL_T1
349 scan.slopeT[1][1] = (b->Tex[1] - a->Tex[1]) * scan.invDeltaY[1]; 349 scan.slopeT[1][1] = (b->Tex[1] - a->Tex[1]) * scan.invDeltaY[1];
350 scan.t[1][1] = a->Tex[1]; 350 scan.t[1][1] = a->Tex[1];
351#endif 351#endif
352 352
353 // apply top-left fill convention, top part 353 // apply top-left fill convention, top part
354 yStart = core::ceil32( a->Pos.y ); 354 yStart = core::ceil32( a->Pos.y );
355 yEnd = core::ceil32( b->Pos.y ) - 1; 355 yEnd = core::ceil32( b->Pos.y ) - 1;
356 356
357#ifdef SUBTEXEL 357#ifdef SUBTEXEL
358 subPixel = ( (f32) yStart ) - a->Pos.y; 358 subPixel = ( (f32) yStart ) - a->Pos.y;
359 359
360 // correct to pixel center 360 // correct to pixel center
361 scan.x[0] += scan.slopeX[0] * subPixel; 361 scan.x[0] += scan.slopeX[0] * subPixel;
362 scan.x[1] += scan.slopeX[1] * subPixel; 362 scan.x[1] += scan.slopeX[1] * subPixel;
363 363
364#ifdef IPOL_Z 364#ifdef IPOL_Z
365 scan.z[0] += scan.slopeZ[0] * subPixel; 365 scan.z[0] += scan.slopeZ[0] * subPixel;
366 scan.z[1] += scan.slopeZ[1] * subPixel; 366 scan.z[1] += scan.slopeZ[1] * subPixel;
367#endif 367#endif
368 368
369#ifdef IPOL_W 369#ifdef IPOL_W
370 scan.w[0] += scan.slopeW[0] * subPixel; 370 scan.w[0] += scan.slopeW[0] * subPixel;
371 scan.w[1] += scan.slopeW[1] * subPixel; 371 scan.w[1] += scan.slopeW[1] * subPixel;
372#endif 372#endif
373 373
374#ifdef IPOL_C0 374#ifdef IPOL_C0
375 scan.c[0][0] += scan.slopeC[0][0] * subPixel; 375 scan.c[0][0] += scan.slopeC[0][0] * subPixel;
376 scan.c[0][1] += scan.slopeC[0][1] * subPixel; 376 scan.c[0][1] += scan.slopeC[0][1] * subPixel;
377#endif 377#endif
378 378
379#ifdef IPOL_T0 379#ifdef IPOL_T0
380 scan.t[0][0] += scan.slopeT[0][0] * subPixel; 380 scan.t[0][0] += scan.slopeT[0][0] * subPixel;
381 scan.t[0][1] += scan.slopeT[0][1] * subPixel; 381 scan.t[0][1] += scan.slopeT[0][1] * subPixel;
382#endif 382#endif
383 383
384#ifdef IPOL_T1 384#ifdef IPOL_T1
385 scan.t[1][0] += scan.slopeT[1][0] * subPixel; 385 scan.t[1][0] += scan.slopeT[1][0] * subPixel;
386 scan.t[1][1] += scan.slopeT[1][1] * subPixel; 386 scan.t[1][1] += scan.slopeT[1][1] * subPixel;
387#endif 387#endif
388 388
389#endif 389#endif
390 390
391 // rasterize the edge scanlines 391 // rasterize the edge scanlines
392 for( line.y = yStart; line.y <= yEnd; ++line.y) 392 for( line.y = yStart; line.y <= yEnd; ++line.y)
393 { 393 {
394 line.x[scan.left] = scan.x[0]; 394 line.x[scan.left] = scan.x[0];
395 line.x[scan.right] = scan.x[1]; 395 line.x[scan.right] = scan.x[1];
396 396
397#ifdef IPOL_Z 397#ifdef IPOL_Z
398 line.z[scan.left] = scan.z[0]; 398 line.z[scan.left] = scan.z[0];
399 line.z[scan.right] = scan.z[1]; 399 line.z[scan.right] = scan.z[1];
400#endif 400#endif
401 401
402#ifdef IPOL_W 402#ifdef IPOL_W
403 line.w[scan.left] = scan.w[0]; 403 line.w[scan.left] = scan.w[0];
404 line.w[scan.right] = scan.w[1]; 404 line.w[scan.right] = scan.w[1];
405#endif 405#endif
406 406
407#ifdef IPOL_C0 407#ifdef IPOL_C0
408 line.c[0][scan.left] = scan.c[0][0]; 408 line.c[0][scan.left] = scan.c[0][0];
409 line.c[0][scan.right] = scan.c[0][1]; 409 line.c[0][scan.right] = scan.c[0][1];
410#endif 410#endif
411 411
412#ifdef IPOL_T0 412#ifdef IPOL_T0
413 line.t[0][scan.left] = scan.t[0][0]; 413 line.t[0][scan.left] = scan.t[0][0];
414 line.t[0][scan.right] = scan.t[0][1]; 414 line.t[0][scan.right] = scan.t[0][1];
415#endif 415#endif
416 416
417#ifdef IPOL_T1 417#ifdef IPOL_T1
418 line.t[1][scan.left] = scan.t[1][0]; 418 line.t[1][scan.left] = scan.t[1][0];
419 line.t[1][scan.right] = scan.t[1][1]; 419 line.t[1][scan.right] = scan.t[1][1];
420#endif 420#endif
421 421
422 // render a scanline 422 // render a scanline
423 scanline_bilinear (); 423 scanline_bilinear ();
424 424
425 scan.x[0] += scan.slopeX[0]; 425 scan.x[0] += scan.slopeX[0];
426 scan.x[1] += scan.slopeX[1]; 426 scan.x[1] += scan.slopeX[1];
427 427
428#ifdef IPOL_Z 428#ifdef IPOL_Z
429 scan.z[0] += scan.slopeZ[0]; 429 scan.z[0] += scan.slopeZ[0];
430 scan.z[1] += scan.slopeZ[1]; 430 scan.z[1] += scan.slopeZ[1];
431#endif 431#endif
432 432
433#ifdef IPOL_W 433#ifdef IPOL_W
434 scan.w[0] += scan.slopeW[0]; 434 scan.w[0] += scan.slopeW[0];
435 scan.w[1] += scan.slopeW[1]; 435 scan.w[1] += scan.slopeW[1];
436#endif 436#endif
437 437
438#ifdef IPOL_C0 438#ifdef IPOL_C0
439 scan.c[0][0] += scan.slopeC[0][0]; 439 scan.c[0][0] += scan.slopeC[0][0];
440 scan.c[0][1] += scan.slopeC[0][1]; 440 scan.c[0][1] += scan.slopeC[0][1];
441#endif 441#endif
442 442
443#ifdef IPOL_T0 443#ifdef IPOL_T0
444 scan.t[0][0] += scan.slopeT[0][0]; 444 scan.t[0][0] += scan.slopeT[0][0];
445 scan.t[0][1] += scan.slopeT[0][1]; 445 scan.t[0][1] += scan.slopeT[0][1];
446#endif 446#endif
447 447
448#ifdef IPOL_T1 448#ifdef IPOL_T1
449 scan.t[1][0] += scan.slopeT[1][0]; 449 scan.t[1][0] += scan.slopeT[1][0];
450 scan.t[1][1] += scan.slopeT[1][1]; 450 scan.t[1][1] += scan.slopeT[1][1];
451#endif 451#endif
452 452
453 } 453 }
454 } 454 }
455 455
456 // rasterize lower sub-triangle 456 // rasterize lower sub-triangle
457 if ( (f32) 0.0 != scan.invDeltaY[2] ) 457 if ( (f32) 0.0 != scan.invDeltaY[2] )
458 { 458 {
459 // advance to middle point 459 // advance to middle point
460 if( (f32) 0.0 != scan.invDeltaY[1] ) 460 if( (f32) 0.0 != scan.invDeltaY[1] )
461 { 461 {
462 temp[0] = b->Pos.y - a->Pos.y; // dy 462 temp[0] = b->Pos.y - a->Pos.y; // dy
463 463
464 scan.x[0] = a->Pos.x + scan.slopeX[0] * temp[0]; 464 scan.x[0] = a->Pos.x + scan.slopeX[0] * temp[0];
465#ifdef IPOL_Z 465#ifdef IPOL_Z
466 scan.z[0] = a->Pos.z + scan.slopeZ[0] * temp[0]; 466 scan.z[0] = a->Pos.z + scan.slopeZ[0] * temp[0];
467#endif 467#endif
468#ifdef IPOL_W 468#ifdef IPOL_W
469 scan.w[0] = a->Pos.w + scan.slopeW[0] * temp[0]; 469 scan.w[0] = a->Pos.w + scan.slopeW[0] * temp[0];
470#endif 470#endif
471#ifdef IPOL_C0 471#ifdef IPOL_C0
472 scan.c[0][0] = a->Color[0] + scan.slopeC[0][0] * temp[0]; 472 scan.c[0][0] = a->Color[0] + scan.slopeC[0][0] * temp[0];
473#endif 473#endif
474#ifdef IPOL_T0 474#ifdef IPOL_T0
475 scan.t[0][0] = a->Tex[0] + scan.slopeT[0][0] * temp[0]; 475 scan.t[0][0] = a->Tex[0] + scan.slopeT[0][0] * temp[0];
476#endif 476#endif
477#ifdef IPOL_T1 477#ifdef IPOL_T1
478 scan.t[1][0] = a->Tex[1] + scan.slopeT[1][0] * temp[0]; 478 scan.t[1][0] = a->Tex[1] + scan.slopeT[1][0] * temp[0];
479#endif 479#endif
480 480
481 } 481 }
482 482
483 // calculate slopes for bottom edge 483 // calculate slopes for bottom edge
484 scan.slopeX[1] = (c->Pos.x - b->Pos.x) * scan.invDeltaY[2]; 484 scan.slopeX[1] = (c->Pos.x - b->Pos.x) * scan.invDeltaY[2];
485 scan.x[1] = b->Pos.x; 485 scan.x[1] = b->Pos.x;
486 486
487#ifdef IPOL_Z 487#ifdef IPOL_Z
488 scan.slopeZ[1] = (c->Pos.z - b->Pos.z) * scan.invDeltaY[2]; 488 scan.slopeZ[1] = (c->Pos.z - b->Pos.z) * scan.invDeltaY[2];
489 scan.z[1] = b->Pos.z; 489 scan.z[1] = b->Pos.z;
490#endif 490#endif
491 491
492#ifdef IPOL_W 492#ifdef IPOL_W
493 scan.slopeW[1] = (c->Pos.w - b->Pos.w) * scan.invDeltaY[2]; 493 scan.slopeW[1] = (c->Pos.w - b->Pos.w) * scan.invDeltaY[2];
494 scan.w[1] = b->Pos.w; 494 scan.w[1] = b->Pos.w;
495#endif 495#endif
496 496
497#ifdef IPOL_C0 497#ifdef IPOL_C0
498 scan.slopeC[0][1] = (c->Color[0] - b->Color[0]) * scan.invDeltaY[2]; 498 scan.slopeC[0][1] = (c->Color[0] - b->Color[0]) * scan.invDeltaY[2];
499 scan.c[0][1] = b->Color[0]; 499 scan.c[0][1] = b->Color[0];
500#endif 500#endif
501 501
502#ifdef IPOL_T0 502#ifdef IPOL_T0
503 scan.slopeT[0][1] = (c->Tex[0] - b->Tex[0]) * scan.invDeltaY[2]; 503 scan.slopeT[0][1] = (c->Tex[0] - b->Tex[0]) * scan.invDeltaY[2];
504 scan.t[0][1] = b->Tex[0]; 504 scan.t[0][1] = b->Tex[0];
505#endif 505#endif
506 506
507#ifdef IPOL_T1 507#ifdef IPOL_T1
508 scan.slopeT[1][1] = (c->Tex[1] - b->Tex[1]) * scan.invDeltaY[2]; 508 scan.slopeT[1][1] = (c->Tex[1] - b->Tex[1]) * scan.invDeltaY[2];
509 scan.t[1][1] = b->Tex[1]; 509 scan.t[1][1] = b->Tex[1];
510#endif 510#endif
511 511
512 // apply top-left fill convention, top part 512 // apply top-left fill convention, top part
513 yStart = core::ceil32( b->Pos.y ); 513 yStart = core::ceil32( b->Pos.y );
514 yEnd = core::ceil32( c->Pos.y ) - 1; 514 yEnd = core::ceil32( c->Pos.y ) - 1;
515 515
516#ifdef SUBTEXEL 516#ifdef SUBTEXEL
517 517
518 subPixel = ( (f32) yStart ) - b->Pos.y; 518 subPixel = ( (f32) yStart ) - b->Pos.y;
519 519
520 // correct to pixel center 520 // correct to pixel center
521 scan.x[0] += scan.slopeX[0] * subPixel; 521 scan.x[0] += scan.slopeX[0] * subPixel;
522 scan.x[1] += scan.slopeX[1] * subPixel; 522 scan.x[1] += scan.slopeX[1] * subPixel;
523 523
524#ifdef IPOL_Z 524#ifdef IPOL_Z
525 scan.z[0] += scan.slopeZ[0] * subPixel; 525 scan.z[0] += scan.slopeZ[0] * subPixel;
526 scan.z[1] += scan.slopeZ[1] * subPixel; 526 scan.z[1] += scan.slopeZ[1] * subPixel;
527#endif 527#endif
528 528
529#ifdef IPOL_W 529#ifdef IPOL_W
530 scan.w[0] += scan.slopeW[0] * subPixel; 530 scan.w[0] += scan.slopeW[0] * subPixel;
531 scan.w[1] += scan.slopeW[1] * subPixel; 531 scan.w[1] += scan.slopeW[1] * subPixel;
532#endif 532#endif
533 533
534#ifdef IPOL_C0 534#ifdef IPOL_C0
535 scan.c[0][0] += scan.slopeC[0][0] * subPixel; 535 scan.c[0][0] += scan.slopeC[0][0] * subPixel;
536 scan.c[0][1] += scan.slopeC[0][1] * subPixel; 536 scan.c[0][1] += scan.slopeC[0][1] * subPixel;
537#endif 537#endif
538 538
539#ifdef IPOL_T0 539#ifdef IPOL_T0
540 scan.t[0][0] += scan.slopeT[0][0] * subPixel; 540 scan.t[0][0] += scan.slopeT[0][0] * subPixel;
541 scan.t[0][1] += scan.slopeT[0][1] * subPixel; 541 scan.t[0][1] += scan.slopeT[0][1] * subPixel;
542#endif 542#endif
543 543
544#ifdef IPOL_T1 544#ifdef IPOL_T1
545 scan.t[1][0] += scan.slopeT[1][0] * subPixel; 545 scan.t[1][0] += scan.slopeT[1][0] * subPixel;
546 scan.t[1][1] += scan.slopeT[1][1] * subPixel; 546 scan.t[1][1] += scan.slopeT[1][1] * subPixel;
547#endif 547#endif
548 548
549#endif 549#endif
550 550
551 // rasterize the edge scanlines 551 // rasterize the edge scanlines
552 for( line.y = yStart; line.y <= yEnd; ++line.y) 552 for( line.y = yStart; line.y <= yEnd; ++line.y)
553 { 553 {
554 line.x[scan.left] = scan.x[0]; 554 line.x[scan.left] = scan.x[0];
555 line.x[scan.right] = scan.x[1]; 555 line.x[scan.right] = scan.x[1];
556 556
557#ifdef IPOL_Z 557#ifdef IPOL_Z
558 line.z[scan.left] = scan.z[0]; 558 line.z[scan.left] = scan.z[0];
559 line.z[scan.right] = scan.z[1]; 559 line.z[scan.right] = scan.z[1];
560#endif 560#endif
561 561
562#ifdef IPOL_W 562#ifdef IPOL_W
563 line.w[scan.left] = scan.w[0]; 563 line.w[scan.left] = scan.w[0];
564 line.w[scan.right] = scan.w[1]; 564 line.w[scan.right] = scan.w[1];
565#endif 565#endif
566 566
567#ifdef IPOL_C0 567#ifdef IPOL_C0
568 line.c[0][scan.left] = scan.c[0][0]; 568 line.c[0][scan.left] = scan.c[0][0];
569 line.c[0][scan.right] = scan.c[0][1]; 569 line.c[0][scan.right] = scan.c[0][1];
570#endif 570#endif
571 571
572#ifdef IPOL_T0 572#ifdef IPOL_T0
573 line.t[0][scan.left] = scan.t[0][0]; 573 line.t[0][scan.left] = scan.t[0][0];
574 line.t[0][scan.right] = scan.t[0][1]; 574 line.t[0][scan.right] = scan.t[0][1];
575#endif 575#endif
576 576
577#ifdef IPOL_T1 577#ifdef IPOL_T1
578 line.t[1][scan.left] = scan.t[1][0]; 578 line.t[1][scan.left] = scan.t[1][0];
579 line.t[1][scan.right] = scan.t[1][1]; 579 line.t[1][scan.right] = scan.t[1][1];
580#endif 580#endif
581 581
582 // render a scanline 582 // render a scanline
583 scanline_bilinear (); 583 scanline_bilinear ();
584 584
585 scan.x[0] += scan.slopeX[0]; 585 scan.x[0] += scan.slopeX[0];
586 scan.x[1] += scan.slopeX[1]; 586 scan.x[1] += scan.slopeX[1];
587 587
588#ifdef IPOL_Z 588#ifdef IPOL_Z
589 scan.z[0] += scan.slopeZ[0]; 589 scan.z[0] += scan.slopeZ[0];
590 scan.z[1] += scan.slopeZ[1]; 590 scan.z[1] += scan.slopeZ[1];
591#endif 591#endif
592 592
593#ifdef IPOL_W 593#ifdef IPOL_W
594 scan.w[0] += scan.slopeW[0]; 594 scan.w[0] += scan.slopeW[0];
595 scan.w[1] += scan.slopeW[1]; 595 scan.w[1] += scan.slopeW[1];
596#endif 596#endif
597 597
598#ifdef IPOL_C0 598#ifdef IPOL_C0
599 scan.c[0][0] += scan.slopeC[0][0]; 599 scan.c[0][0] += scan.slopeC[0][0];
600 scan.c[0][1] += scan.slopeC[0][1]; 600 scan.c[0][1] += scan.slopeC[0][1];
601#endif 601#endif
602 602
603#ifdef IPOL_T0 603#ifdef IPOL_T0
604 scan.t[0][0] += scan.slopeT[0][0]; 604 scan.t[0][0] += scan.slopeT[0][0];
605 scan.t[0][1] += scan.slopeT[0][1]; 605 scan.t[0][1] += scan.slopeT[0][1];
606#endif 606#endif
607 607
608#ifdef IPOL_T1 608#ifdef IPOL_T1
609 scan.t[1][0] += scan.slopeT[1][0]; 609 scan.t[1][0] += scan.slopeT[1][0];
610 scan.t[1][1] += scan.slopeT[1][1]; 610 scan.t[1][1] += scan.slopeT[1][1];
611#endif 611#endif
612 612
613 } 613 }
614 } 614 }
615 615
616 616
617} 617}
618 618
619 619
620} // end namespace video 620} // end namespace video
621} // end namespace irr 621} // end namespace irr
622 622
623#endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_ 623#endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_
624 624
625namespace irr 625namespace irr
626{ 626{
627namespace video 627namespace video
628{ 628{
629 629
630//! creates a flat triangle renderer 630//! creates a flat triangle renderer
631IBurningShader* createTriangleRendererGouraud2(CBurningVideoDriver* driver) 631IBurningShader* createTriangleRendererGouraud2(CBurningVideoDriver* driver)
632{ 632{
633 #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_ 633 #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
634 return new CTRGouraud2(driver); 634 return new CTRGouraud2(driver);
635 #else 635 #else
636 return 0; 636 return 0;
637 #endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_ 637 #endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_
638} 638}
639 639
640 640
641} // end namespace video 641} // end namespace video
642} // end namespace irr 642} // end namespace irr
643 643
644 644
645 645