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