aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/irrlicht-1.8.1/source/Irrlicht/CTRStencilShadow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/irrlicht-1.8.1/source/Irrlicht/CTRStencilShadow.cpp')
-rw-r--r--src/others/irrlicht-1.8.1/source/Irrlicht/CTRStencilShadow.cpp930
1 files changed, 930 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/source/Irrlicht/CTRStencilShadow.cpp b/src/others/irrlicht-1.8.1/source/Irrlicht/CTRStencilShadow.cpp
new file mode 100644
index 0000000..be974b6
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/source/Irrlicht/CTRStencilShadow.cpp
@@ -0,0 +1,930 @@
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 USE_SBUFFER
13#undef IPOL_Z
14#undef CMP_Z
15#undef WRITE_Z
16
17#undef IPOL_W
18#undef CMP_W
19#undef WRITE_W
20
21#undef SUBTEXEL
22#undef INVERSE_W
23
24#undef IPOL_C0
25#undef IPOL_T0
26#undef IPOL_T1
27#undef IPOL_T2
28#undef IPOL_L0
29
30// define render case
31#define SUBTEXEL
32//#define INVERSE_W
33
34#define USE_ZBUFFER
35#define USE_SBUFFER
36#define IPOL_W
37#define CMP_W
38//#define WRITE_W
39
40
41// apply global override
42#ifndef SOFTWARE_DRIVER_2_PERSPECTIVE_CORRECT
43 #undef INVERSE_W
44#endif
45
46#ifndef SOFTWARE_DRIVER_2_SUBTEXEL
47 #undef SUBTEXEL
48#endif
49
50#ifndef SOFTWARE_DRIVER_2_USE_VERTEX_COLOR
51 #undef IPOL_C0
52#endif
53
54#if !defined ( SOFTWARE_DRIVER_2_USE_WBUFFER ) && defined ( USE_ZBUFFER )
55 #ifndef SOFTWARE_DRIVER_2_PERSPECTIVE_CORRECT
56 #undef IPOL_W
57 #endif
58 #define IPOL_Z
59
60 #ifdef CMP_W
61 #undef CMP_W
62 #define CMP_Z
63 #endif
64
65 #ifdef WRITE_W
66 #undef WRITE_W
67 #define WRITE_Z
68 #endif
69
70#endif
71
72
73namespace irr
74{
75
76namespace video
77{
78
79class CTRStencilShadow : public IBurningShader
80{
81public:
82
83 //! constructor
84 CTRStencilShadow(CBurningVideoDriver* driver);
85
86 //! draws an indexed triangle list
87 virtual void drawTriangle ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c );
88 virtual void setParam ( u32 index, f32 value);
89
90private:
91 // fragment shader
92 typedef void (CTRStencilShadow::*tFragmentShader) ();
93 void fragment_zfail_decr ();
94 void fragment_zfail_incr ();
95
96 tFragmentShader fragmentShader;
97
98 sScanConvertData scan;
99 sScanLineData line;
100
101};
102
103//! constructor
104CTRStencilShadow::CTRStencilShadow(CBurningVideoDriver* driver)
105: IBurningShader(driver)
106{
107 #ifdef _DEBUG
108 setDebugName("CTRStencilShadow");
109 #endif
110}
111
112
113/*!
114*/
115void CTRStencilShadow::setParam ( u32 index, f32 value)
116{
117 u32 val = (u32) value;
118
119 // glStencilOp (fail,zfail,zpass
120 if ( index == 1 && val == 1 )
121 {
122 fragmentShader = &CTRStencilShadow::fragment_zfail_incr;
123 }
124 else
125 if ( index == 1 && val == 2 )
126 {
127 fragmentShader = &CTRStencilShadow::fragment_zfail_decr;
128 }
129}
130
131/*!
132*/
133void CTRStencilShadow::fragment_zfail_decr ()
134{
135 if (!Stencil)
136 return;
137 //tVideoSample *dst;
138
139#ifdef USE_ZBUFFER
140 fp24 *z;
141#endif
142
143#ifdef USE_SBUFFER
144 u32 *stencil;
145#endif
146
147 s32 xStart;
148 s32 xEnd;
149 s32 dx;
150
151#ifdef SUBTEXEL
152 f32 subPixel;
153#endif
154
155#ifdef IPOL_Z
156 f32 slopeZ;
157#endif
158#ifdef IPOL_W
159 fp24 slopeW;
160#endif
161#ifdef IPOL_C0
162 sVec4 slopeC[MATERIAL_MAX_COLORS];
163#endif
164#ifdef IPOL_T0
165 sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES];
166#endif
167#ifdef IPOL_L0
168 sVec3 slopeL[BURNING_MATERIAL_MAX_TANGENT];
169#endif
170
171 // apply top-left fill-convention, left
172 xStart = core::ceil32( line.x[0] );
173 xEnd = core::ceil32( line.x[1] ) - 1;
174
175 dx = xEnd - xStart;
176
177 if ( dx < 0 )
178 return;
179
180 // slopes
181 const f32 invDeltaX = core::reciprocal_approxim ( line.x[1] - line.x[0] );
182
183#ifdef IPOL_Z
184 slopeZ = (line.z[1] - line.z[0]) * invDeltaX;
185#endif
186#ifdef IPOL_W
187 slopeW = (line.w[1] - line.w[0]) * invDeltaX;
188#endif
189#ifdef IPOL_C0
190 slopeC[0] = (line.c[0][1] - line.c[0][0]) * invDeltaX;
191#endif
192#ifdef IPOL_T0
193 slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX;
194#endif
195#ifdef IPOL_T1
196 slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX;
197#endif
198#ifdef IPOL_T2
199 slopeT[2] = (line.t[2][1] - line.t[2][0]) * invDeltaX;
200#endif
201#ifdef IPOL_L0
202 slopeL[0] = (line.l[0][1] - line.l[0][0]) * invDeltaX;
203#endif
204
205#ifdef SUBTEXEL
206 subPixel = ( (f32) xStart ) - line.x[0];
207#ifdef IPOL_Z
208 line.z[0] += slopeZ * subPixel;
209#endif
210#ifdef IPOL_W
211 line.w[0] += slopeW * subPixel;
212#endif
213#ifdef IPOL_C0
214 line.c[0][0] += slopeC[0] * subPixel;
215#endif
216#ifdef IPOL_T0
217 line.t[0][0] += slopeT[0] * subPixel;
218#endif
219#ifdef IPOL_T1
220 line.t[1][0] += slopeT[1] * subPixel;
221#endif
222#ifdef IPOL_T2
223 line.t[2][0] += slopeT[2] * subPixel;
224#endif
225#ifdef IPOL_L0
226 line.l[0][0] += slopeL[0] * subPixel;
227#endif
228#endif
229
230 //dst = (tVideoSample*)RenderTarget->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;
231
232#ifdef USE_ZBUFFER
233 z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;
234#endif
235
236#ifdef USE_SBUFFER
237 stencil = (u32*) Stencil->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;
238#endif
239
240
241#ifdef INVERSE_W
242 f32 inversew;
243#endif
244
245
246#ifdef IPOL_C0
247 tFixPoint r3, g3, b3;
248#endif
249
250 for ( s32 i = 0; i <= dx; i++ )
251 {
252#ifdef CMP_Z
253 if ( line.z[0] < z[i] )
254#endif
255#ifdef CMP_W
256 if ( line.w[0] < z[i] )
257#endif
258 {
259 // zfail
260 stencil[i] -= 1;
261 }
262
263#ifdef IPOL_Z
264 line.z[0] += slopeZ;
265#endif
266#ifdef IPOL_W
267 line.w[0] += slopeW;
268#endif
269#ifdef IPOL_C0
270 line.c[0][0] += slopeC[0];
271#endif
272#ifdef IPOL_T0
273 line.t[0][0] += slopeT[0];
274#endif
275#ifdef IPOL_T1
276 line.t[1][0] += slopeT[1];
277#endif
278#ifdef IPOL_T2
279 line.t[2][0] += slopeT[2];
280#endif
281#ifdef IPOL_L0
282 line.l[0][0] += slopeL[0];
283#endif
284 }
285}
286
287/*!
288*/
289void CTRStencilShadow::fragment_zfail_incr()
290{
291 if (!Stencil)
292 return;
293 //tVideoSample *dst;
294
295#ifdef USE_ZBUFFER
296 fp24 *z;
297#endif
298
299#ifdef USE_SBUFFER
300 u32 *stencil;
301#endif
302
303 s32 xStart;
304 s32 xEnd;
305 s32 dx;
306
307
308#ifdef SUBTEXEL
309 f32 subPixel;
310#endif
311
312#ifdef IPOL_Z
313 f32 slopeZ;
314#endif
315#ifdef IPOL_W
316 fp24 slopeW;
317#endif
318#ifdef IPOL_C0
319 sVec4 slopeC[MATERIAL_MAX_COLORS];
320#endif
321#ifdef IPOL_T0
322 sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES];
323#endif
324#ifdef IPOL_L0
325 sVec3 slopeL[BURNING_MATERIAL_MAX_TANGENT];
326#endif
327
328 // apply top-left fill-convention, left
329 xStart = core::ceil32( line.x[0] );
330 xEnd = core::ceil32( line.x[1] ) - 1;
331
332 dx = xEnd - xStart;
333
334 if ( dx < 0 )
335 return;
336
337 // slopes
338 const f32 invDeltaX = core::reciprocal_approxim ( line.x[1] - line.x[0] );
339
340#ifdef IPOL_Z
341 slopeZ = (line.z[1] - line.z[0]) * invDeltaX;
342#endif
343#ifdef IPOL_W
344 slopeW = (line.w[1] - line.w[0]) * invDeltaX;
345#endif
346#ifdef IPOL_C0
347 slopeC[0] = (line.c[0][1] - line.c[0][0]) * invDeltaX;
348#endif
349#ifdef IPOL_T0
350 slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX;
351#endif
352#ifdef IPOL_T1
353 slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX;
354#endif
355#ifdef IPOL_T2
356 slopeT[2] = (line.t[2][1] - line.t[2][0]) * invDeltaX;
357#endif
358#ifdef IPOL_L0
359 slopeL[0] = (line.l[0][1] - line.l[0][0]) * invDeltaX;
360#endif
361
362#ifdef SUBTEXEL
363 subPixel = ( (f32) xStart ) - line.x[0];
364#ifdef IPOL_Z
365 line.z[0] += slopeZ * subPixel;
366#endif
367#ifdef IPOL_W
368 line.w[0] += slopeW * subPixel;
369#endif
370#ifdef IPOL_C0
371 line.c[0][0] += slopeC[0] * subPixel;
372#endif
373#ifdef IPOL_T0
374 line.t[0][0] += slopeT[0] * subPixel;
375#endif
376#ifdef IPOL_T1
377 line.t[1][0] += slopeT[1] * subPixel;
378#endif
379#ifdef IPOL_T2
380 line.t[2][0] += slopeT[2] * subPixel;
381#endif
382#ifdef IPOL_L0
383 line.l[0][0] += slopeL[0] * subPixel;
384#endif
385#endif
386
387 //dst = (tVideoSample*)RenderTarget->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;
388
389#ifdef USE_ZBUFFER
390 z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;
391#endif
392
393#ifdef USE_SBUFFER
394 stencil = (u32*) Stencil->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;
395#endif
396
397#ifdef INVERSE_W
398 f32 inversew;
399#endif
400
401#ifdef IPOL_C0
402 tFixPoint r3, g3, b3;
403#endif
404
405 for ( s32 i = 0; i <= dx; i++ )
406 {
407#ifdef CMP_Z
408 if ( line.z[0] < z[i] )
409#endif
410#ifdef CMP_W
411 if ( line.w[0] < z[i] )
412#endif
413 {
414 // zfail
415 stencil[i] += 1;
416 }
417
418#ifdef IPOL_Z
419 line.z[0] += slopeZ;
420#endif
421#ifdef IPOL_W
422 line.w[0] += slopeW;
423#endif
424#ifdef IPOL_C0
425 line.c[0][0] += slopeC[0];
426#endif
427#ifdef IPOL_T0
428 line.t[0][0] += slopeT[0];
429#endif
430#ifdef IPOL_T1
431 line.t[1][0] += slopeT[1];
432#endif
433#ifdef IPOL_T2
434 line.t[2][0] += slopeT[2];
435#endif
436#ifdef IPOL_L0
437 line.l[0][0] += slopeL[0];
438#endif
439 }
440}
441
442void CTRStencilShadow::drawTriangle ( const s4DVertex *a,const s4DVertex *b,const s4DVertex *c )
443{
444 // sort on height, y
445 if ( F32_A_GREATER_B ( a->Pos.y , b->Pos.y ) ) swapVertexPointer(&a, &b);
446 if ( F32_A_GREATER_B ( b->Pos.y , c->Pos.y ) ) swapVertexPointer(&b, &c);
447 if ( F32_A_GREATER_B ( a->Pos.y , b->Pos.y ) ) swapVertexPointer(&a, &b);
448
449 const f32 ca = c->Pos.y - a->Pos.y;
450 const f32 ba = b->Pos.y - a->Pos.y;
451 const f32 cb = c->Pos.y - b->Pos.y;
452 // calculate delta y of the edges
453 scan.invDeltaY[0] = core::reciprocal( ca );
454 scan.invDeltaY[1] = core::reciprocal( ba );
455 scan.invDeltaY[2] = core::reciprocal( cb );
456
457 if ( F32_LOWER_EQUAL_0 ( scan.invDeltaY[0] ) )
458 return;
459
460 // find if the major edge is left or right aligned
461 f32 temp[4];
462
463 temp[0] = a->Pos.x - c->Pos.x;
464 temp[1] = -ca;
465 temp[2] = b->Pos.x - a->Pos.x;
466 temp[3] = ba;
467
468 scan.left = ( temp[0] * temp[3] - temp[1] * temp[2] ) > 0.f ? 0 : 1;
469 scan.right = 1 - scan.left;
470
471 // calculate slopes for the major edge
472 scan.slopeX[0] = (c->Pos.x - a->Pos.x) * scan.invDeltaY[0];
473 scan.x[0] = a->Pos.x;
474
475#ifdef IPOL_Z
476 scan.slopeZ[0] = (c->Pos.z - a->Pos.z) * scan.invDeltaY[0];
477 scan.z[0] = a->Pos.z;
478#endif
479
480#ifdef IPOL_W
481 scan.slopeW[0] = (c->Pos.w - a->Pos.w) * scan.invDeltaY[0];
482 scan.w[0] = a->Pos.w;
483#endif
484
485#ifdef IPOL_C0
486 scan.slopeC[0][0] = (c->Color[0] - a->Color[0]) * scan.invDeltaY[0];
487 scan.c[0][0] = a->Color[0];
488#endif
489
490#ifdef IPOL_T0
491 scan.slopeT[0][0] = (c->Tex[0] - a->Tex[0]) * scan.invDeltaY[0];
492 scan.t[0][0] = a->Tex[0];
493#endif
494
495#ifdef IPOL_T1
496 scan.slopeT[1][0] = (c->Tex[1] - a->Tex[1]) * scan.invDeltaY[0];
497 scan.t[1][0] = a->Tex[1];
498#endif
499
500#ifdef IPOL_T2
501 scan.slopeT[2][0] = (c->Tex[2] - a->Tex[2]) * scan.invDeltaY[0];
502 scan.t[2][0] = a->Tex[2];
503#endif
504
505#ifdef IPOL_L0
506 scan.slopeL[0][0] = (c->LightTangent[0] - a->LightTangent[0]) * scan.invDeltaY[0];
507 scan.l[0][0] = a->LightTangent[0];
508#endif
509
510 // top left fill convention y run
511 s32 yStart;
512 s32 yEnd;
513
514#ifdef SUBTEXEL
515 f32 subPixel;
516#endif
517
518 // rasterize upper sub-triangle
519 //if ( (f32) 0.0 != scan.invDeltaY[1] )
520 if ( F32_GREATER_0 ( scan.invDeltaY[1] ) )
521 {
522 // calculate slopes for top edge
523 scan.slopeX[1] = (b->Pos.x - a->Pos.x) * scan.invDeltaY[1];
524 scan.x[1] = a->Pos.x;
525
526#ifdef IPOL_Z
527 scan.slopeZ[1] = (b->Pos.z - a->Pos.z) * scan.invDeltaY[1];
528 scan.z[1] = a->Pos.z;
529#endif
530
531#ifdef IPOL_W
532 scan.slopeW[1] = (b->Pos.w - a->Pos.w) * scan.invDeltaY[1];
533 scan.w[1] = a->Pos.w;
534#endif
535
536#ifdef IPOL_C0
537 scan.slopeC[0][1] = (b->Color[0] - a->Color[0]) * scan.invDeltaY[1];
538 scan.c[0][1] = a->Color[0];
539#endif
540
541#ifdef IPOL_T0
542 scan.slopeT[0][1] = (b->Tex[0] - a->Tex[0]) * scan.invDeltaY[1];
543 scan.t[0][1] = a->Tex[0];
544#endif
545
546#ifdef IPOL_T1
547 scan.slopeT[1][1] = (b->Tex[1] - a->Tex[1]) * scan.invDeltaY[1];
548 scan.t[1][1] = a->Tex[1];
549#endif
550
551#ifdef IPOL_T2
552 scan.slopeT[2][1] = (b->Tex[2] - a->Tex[2]) * scan.invDeltaY[1];
553 scan.t[2][1] = a->Tex[2];
554#endif
555
556#ifdef IPOL_L0
557 scan.slopeL[0][1] = (b->LightTangent[0] - a->LightTangent[0]) * scan.invDeltaY[1];
558 scan.l[0][1] = a->LightTangent[0];
559#endif
560
561 // apply top-left fill convention, top part
562 yStart = core::ceil32( a->Pos.y );
563 yEnd = core::ceil32( b->Pos.y ) - 1;
564
565#ifdef SUBTEXEL
566 subPixel = ( (f32) yStart ) - a->Pos.y;
567
568 // correct to pixel center
569 scan.x[0] += scan.slopeX[0] * subPixel;
570 scan.x[1] += scan.slopeX[1] * subPixel;
571
572#ifdef IPOL_Z
573 scan.z[0] += scan.slopeZ[0] * subPixel;
574 scan.z[1] += scan.slopeZ[1] * subPixel;
575#endif
576
577#ifdef IPOL_W
578 scan.w[0] += scan.slopeW[0] * subPixel;
579 scan.w[1] += scan.slopeW[1] * subPixel;
580#endif
581
582#ifdef IPOL_C0
583 scan.c[0][0] += scan.slopeC[0][0] * subPixel;
584 scan.c[0][1] += scan.slopeC[0][1] * subPixel;
585#endif
586
587#ifdef IPOL_T0
588 scan.t[0][0] += scan.slopeT[0][0] * subPixel;
589 scan.t[0][1] += scan.slopeT[0][1] * subPixel;
590#endif
591
592#ifdef IPOL_T1
593 scan.t[1][0] += scan.slopeT[1][0] * subPixel;
594 scan.t[1][1] += scan.slopeT[1][1] * subPixel;
595#endif
596
597#ifdef IPOL_T2
598 scan.t[2][0] += scan.slopeT[2][0] * subPixel;
599 scan.t[2][1] += scan.slopeT[2][1] * subPixel;
600#endif
601
602#ifdef IPOL_L0
603 scan.l[0][0] += scan.slopeL[0][0] * subPixel;
604 scan.l[0][1] += scan.slopeL[0][1] * subPixel;
605#endif
606
607#endif
608
609 // rasterize the edge scanlines
610 for( line.y = yStart; line.y <= yEnd; ++line.y)
611 {
612 line.x[scan.left] = scan.x[0];
613 line.x[scan.right] = scan.x[1];
614
615#ifdef IPOL_Z
616 line.z[scan.left] = scan.z[0];
617 line.z[scan.right] = scan.z[1];
618#endif
619
620#ifdef IPOL_W
621 line.w[scan.left] = scan.w[0];
622 line.w[scan.right] = scan.w[1];
623#endif
624
625#ifdef IPOL_C0
626 line.c[0][scan.left] = scan.c[0][0];
627 line.c[0][scan.right] = scan.c[0][1];
628#endif
629
630#ifdef IPOL_T0
631 line.t[0][scan.left] = scan.t[0][0];
632 line.t[0][scan.right] = scan.t[0][1];
633#endif
634
635#ifdef IPOL_T1
636 line.t[1][scan.left] = scan.t[1][0];
637 line.t[1][scan.right] = scan.t[1][1];
638#endif
639
640#ifdef IPOL_T2
641 line.t[2][scan.left] = scan.t[2][0];
642 line.t[2][scan.right] = scan.t[2][1];
643#endif
644
645#ifdef IPOL_L0
646 line.l[0][scan.left] = scan.l[0][0];
647 line.l[0][scan.right] = scan.l[0][1];
648#endif
649
650 // render a scanline
651 (this->*fragmentShader) ();
652
653 scan.x[0] += scan.slopeX[0];
654 scan.x[1] += scan.slopeX[1];
655
656#ifdef IPOL_Z
657 scan.z[0] += scan.slopeZ[0];
658 scan.z[1] += scan.slopeZ[1];
659#endif
660
661#ifdef IPOL_W
662 scan.w[0] += scan.slopeW[0];
663 scan.w[1] += scan.slopeW[1];
664#endif
665
666#ifdef IPOL_C0
667 scan.c[0][0] += scan.slopeC[0][0];
668 scan.c[0][1] += scan.slopeC[0][1];
669#endif
670
671#ifdef IPOL_T0
672 scan.t[0][0] += scan.slopeT[0][0];
673 scan.t[0][1] += scan.slopeT[0][1];
674#endif
675
676#ifdef IPOL_T1
677 scan.t[1][0] += scan.slopeT[1][0];
678 scan.t[1][1] += scan.slopeT[1][1];
679#endif
680
681#ifdef IPOL_T2
682 scan.t[2][0] += scan.slopeT[2][0];
683 scan.t[2][1] += scan.slopeT[2][1];
684#endif
685
686#ifdef IPOL_L0
687 scan.l[0][0] += scan.slopeL[0][0];
688 scan.l[0][1] += scan.slopeL[0][1];
689#endif
690
691 }
692 }
693
694 // rasterize lower sub-triangle
695 //if ( (f32) 0.0 != scan.invDeltaY[2] )
696 if ( F32_GREATER_0 ( scan.invDeltaY[2] ) )
697 {
698 // advance to middle point
699 //if( (f32) 0.0 != scan.invDeltaY[1] )
700 if ( F32_GREATER_0 ( scan.invDeltaY[1] ) )
701 {
702 temp[0] = b->Pos.y - a->Pos.y; // dy
703
704 scan.x[0] = a->Pos.x + scan.slopeX[0] * temp[0];
705#ifdef IPOL_Z
706 scan.z[0] = a->Pos.z + scan.slopeZ[0] * temp[0];
707#endif
708#ifdef IPOL_W
709 scan.w[0] = a->Pos.w + scan.slopeW[0] * temp[0];
710#endif
711#ifdef IPOL_C0
712 scan.c[0][0] = a->Color[0] + scan.slopeC[0][0] * temp[0];
713#endif
714#ifdef IPOL_T0
715 scan.t[0][0] = a->Tex[0] + scan.slopeT[0][0] * temp[0];
716#endif
717#ifdef IPOL_T1
718 scan.t[1][0] = a->Tex[1] + scan.slopeT[1][0] * temp[0];
719#endif
720#ifdef IPOL_T2
721 scan.t[2][0] = a->Tex[2] + scan.slopeT[2][0] * temp[0];
722#endif
723#ifdef IPOL_L0
724 scan.l[0][0] = a->LightTangent[0] + scan.slopeL[0][0] * temp[0];
725#endif
726
727 }
728
729 // calculate slopes for bottom edge
730 scan.slopeX[1] = (c->Pos.x - b->Pos.x) * scan.invDeltaY[2];
731 scan.x[1] = b->Pos.x;
732
733#ifdef IPOL_Z
734 scan.slopeZ[1] = (c->Pos.z - b->Pos.z) * scan.invDeltaY[2];
735 scan.z[1] = b->Pos.z;
736#endif
737
738#ifdef IPOL_W
739 scan.slopeW[1] = (c->Pos.w - b->Pos.w) * scan.invDeltaY[2];
740 scan.w[1] = b->Pos.w;
741#endif
742
743#ifdef IPOL_C0
744 scan.slopeC[0][1] = (c->Color[0] - b->Color[0]) * scan.invDeltaY[2];
745 scan.c[0][1] = b->Color[0];
746#endif
747
748#ifdef IPOL_T0
749 scan.slopeT[0][1] = (c->Tex[0] - b->Tex[0]) * scan.invDeltaY[2];
750 scan.t[0][1] = b->Tex[0];
751#endif
752
753#ifdef IPOL_T1
754 scan.slopeT[1][1] = (c->Tex[1] - b->Tex[1]) * scan.invDeltaY[2];
755 scan.t[1][1] = b->Tex[1];
756#endif
757
758#ifdef IPOL_T2
759 scan.slopeT[2][1] = (c->Tex[2] - b->Tex[2]) * scan.invDeltaY[2];
760 scan.t[2][1] = b->Tex[2];
761#endif
762
763#ifdef IPOL_L0
764 scan.slopeL[0][1] = (c->LightTangent[0] - b->LightTangent[0]) * scan.invDeltaY[2];
765 scan.l[0][1] = b->LightTangent[0];
766#endif
767
768 // apply top-left fill convention, top part
769 yStart = core::ceil32( b->Pos.y );
770 yEnd = core::ceil32( c->Pos.y ) - 1;
771
772#ifdef SUBTEXEL
773
774 subPixel = ( (f32) yStart ) - b->Pos.y;
775
776 // correct to pixel center
777 scan.x[0] += scan.slopeX[0] * subPixel;
778 scan.x[1] += scan.slopeX[1] * subPixel;
779
780#ifdef IPOL_Z
781 scan.z[0] += scan.slopeZ[0] * subPixel;
782 scan.z[1] += scan.slopeZ[1] * subPixel;
783#endif
784
785#ifdef IPOL_W
786 scan.w[0] += scan.slopeW[0] * subPixel;
787 scan.w[1] += scan.slopeW[1] * subPixel;
788#endif
789
790#ifdef IPOL_C0
791 scan.c[0][0] += scan.slopeC[0][0] * subPixel;
792 scan.c[0][1] += scan.slopeC[0][1] * subPixel;
793#endif
794
795#ifdef IPOL_T0
796 scan.t[0][0] += scan.slopeT[0][0] * subPixel;
797 scan.t[0][1] += scan.slopeT[0][1] * subPixel;
798#endif
799
800#ifdef IPOL_T1
801 scan.t[1][0] += scan.slopeT[1][0] * subPixel;
802 scan.t[1][1] += scan.slopeT[1][1] * subPixel;
803#endif
804
805#ifdef IPOL_T2
806 scan.t[2][0] += scan.slopeT[2][0] * subPixel;
807 scan.t[2][1] += scan.slopeT[2][1] * subPixel;
808#endif
809
810#ifdef IPOL_L0
811 scan.l[0][0] += scan.slopeL[0][0] * subPixel;
812 scan.l[0][1] += scan.slopeL[0][1] * subPixel;
813#endif
814
815#endif
816
817 // rasterize the edge scanlines
818 for( line.y = yStart; line.y <= yEnd; ++line.y)
819 {
820 line.x[scan.left] = scan.x[0];
821 line.x[scan.right] = scan.x[1];
822
823#ifdef IPOL_Z
824 line.z[scan.left] = scan.z[0];
825 line.z[scan.right] = scan.z[1];
826#endif
827
828#ifdef IPOL_W
829 line.w[scan.left] = scan.w[0];
830 line.w[scan.right] = scan.w[1];
831#endif
832
833#ifdef IPOL_C0
834 line.c[0][scan.left] = scan.c[0][0];
835 line.c[0][scan.right] = scan.c[0][1];
836#endif
837
838#ifdef IPOL_T0
839 line.t[0][scan.left] = scan.t[0][0];
840 line.t[0][scan.right] = scan.t[0][1];
841#endif
842
843#ifdef IPOL_T1
844 line.t[1][scan.left] = scan.t[1][0];
845 line.t[1][scan.right] = scan.t[1][1];
846#endif
847
848#ifdef IPOL_T2
849 line.t[2][scan.left] = scan.t[2][0];
850 line.t[2][scan.right] = scan.t[2][1];
851#endif
852
853#ifdef IPOL_L0
854 line.l[0][scan.left] = scan.l[0][0];
855 line.l[0][scan.right] = scan.l[0][1];
856#endif
857
858 // render a scanline
859 (this->*fragmentShader) ();
860
861 scan.x[0] += scan.slopeX[0];
862 scan.x[1] += scan.slopeX[1];
863
864#ifdef IPOL_Z
865 scan.z[0] += scan.slopeZ[0];
866 scan.z[1] += scan.slopeZ[1];
867#endif
868
869#ifdef IPOL_W
870 scan.w[0] += scan.slopeW[0];
871 scan.w[1] += scan.slopeW[1];
872#endif
873
874#ifdef IPOL_C0
875 scan.c[0][0] += scan.slopeC[0][0];
876 scan.c[0][1] += scan.slopeC[0][1];
877#endif
878
879#ifdef IPOL_T0
880 scan.t[0][0] += scan.slopeT[0][0];
881 scan.t[0][1] += scan.slopeT[0][1];
882#endif
883
884#ifdef IPOL_T1
885 scan.t[1][0] += scan.slopeT[1][0];
886 scan.t[1][1] += scan.slopeT[1][1];
887#endif
888#ifdef IPOL_T2
889 scan.t[2][0] += scan.slopeT[2][0];
890 scan.t[2][1] += scan.slopeT[2][1];
891#endif
892
893#ifdef IPOL_L0
894 scan.l[0][0] += scan.slopeL[0][0];
895 scan.l[0][1] += scan.slopeL[0][1];
896#endif
897
898 }
899 }
900
901}
902
903
904} // end namespace video
905} // end namespace irr
906
907#endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_
908
909namespace irr
910{
911namespace video
912{
913
914
915//! creates a triangle renderer
916IBurningShader* createTRStencilShadow(CBurningVideoDriver* driver)
917{
918 #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
919 return new CTRStencilShadow(driver);
920 #else
921 return 0;
922 #endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_
923}
924
925
926} // end namespace video
927} // end namespace irr
928
929
930