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