]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CTRTextureBlend.cpp
Set includes and libs on object targets
[irrlicht.git] / source / Irrlicht / CTRTextureBlend.cpp
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt / Thomas Alten\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 \r
5 #include "IrrCompileConfig.h"\r
6 #include "IBurningShader.h"\r
7 \r
8 #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_\r
9 \r
10 // compile flag for this file\r
11 #undef USE_ZBUFFER\r
12 #undef IPOL_Z\r
13 #undef CMP_Z\r
14 #undef WRITE_Z\r
15 \r
16 #undef IPOL_W\r
17 #undef CMP_W\r
18 #undef WRITE_W\r
19 \r
20 #undef SUBTEXEL\r
21 #undef INVERSE_W\r
22 \r
23 #undef IPOL_C0\r
24 #undef IPOL_T0\r
25 #undef IPOL_T1\r
26 \r
27 // define render case\r
28 #define SUBTEXEL\r
29 #define INVERSE_W\r
30 \r
31 #define USE_ZBUFFER\r
32 #define IPOL_W\r
33 #define CMP_W\r
34 #define WRITE_W\r
35 \r
36 #define IPOL_C0\r
37 #define IPOL_T0\r
38 //#define IPOL_T1\r
39 \r
40 // apply global override\r
41 #ifndef SOFTWARE_DRIVER_2_PERSPECTIVE_CORRECT\r
42         #undef INVERSE_W\r
43 #endif\r
44 \r
45 #ifndef SOFTWARE_DRIVER_2_SUBTEXEL\r
46         #undef SUBTEXEL\r
47 #endif\r
48 \r
49 #if BURNING_MATERIAL_MAX_COLORS < 1\r
50         #undef IPOL_C0\r
51 #endif\r
52 \r
53 #if !defined ( SOFTWARE_DRIVER_2_USE_WBUFFER ) && defined ( USE_ZBUFFER )\r
54         #ifndef SOFTWARE_DRIVER_2_PERSPECTIVE_CORRECT\r
55                 #undef IPOL_W\r
56         #endif\r
57         #define IPOL_Z\r
58 \r
59         #ifdef CMP_W\r
60                 #undef CMP_W\r
61                 #define CMP_Z\r
62         #endif\r
63 \r
64         #ifdef WRITE_W\r
65                 #undef WRITE_W\r
66                 #define WRITE_Z\r
67         #endif\r
68 \r
69 #endif\r
70 \r
71 \r
72 \r
73 namespace irr\r
74 {\r
75 \r
76 namespace video\r
77 {\r
78 \r
79         class CTRTextureBlend : public IBurningShader\r
80         {\r
81         public:\r
82 \r
83                 //! constructor\r
84                 CTRTextureBlend(CBurningVideoDriver* driver);\r
85 \r
86                 //! draws an indexed triangle list\r
87                 virtual void drawTriangle(const s4DVertex* burning_restrict a, const s4DVertex* burning_restrict b, const s4DVertex* burning_restrict c) _IRR_OVERRIDE_;\r
88                 virtual void OnSetMaterial(const SBurningShaderMaterial& material) _IRR_OVERRIDE_;\r
89 \r
90 private:\r
91         // fragment shader\r
92         typedef void (CTRTextureBlend::*tFragmentShader) ();\r
93         void fragment_dst_color_zero ();\r
94         void fragment_dst_color_one ();\r
95         void fragment_dst_color_src_alpha ();\r
96         void fragment_dst_color_one_minus_dst_alpha ();\r
97         void fragment_zero_one_minus_scr_color ();\r
98         void fragment_src_color_src_alpha ();\r
99         void fragment_one_one_minus_src_alpha ();\r
100         void fragment_one_minus_dst_alpha_one();\r
101         void fragment_src_alpha_one();\r
102         void fragment_src_alpha_one_minus_src_alpha();\r
103 \r
104         tFragmentShader fragmentShader;\r
105 \r
106         E_COMPARISON_FUNC depth_func;\r
107 };\r
108 \r
109 //! constructor\r
110 CTRTextureBlend::CTRTextureBlend(CBurningVideoDriver* driver)\r
111 : IBurningShader(driver)\r
112 {\r
113         #ifdef _DEBUG\r
114         setDebugName("CTRTextureBlend");\r
115         #endif\r
116 \r
117         depth_func = ECFN_LESSEQUAL;\r
118         fragmentShader = &CTRTextureBlend::fragment_dst_color_zero;\r
119 }\r
120 \r
121 /*!\r
122 */\r
123 void CTRTextureBlend::OnSetMaterial(const SBurningShaderMaterial& material)\r
124 {\r
125         int showname = 0;\r
126 \r
127         depth_func = (E_COMPARISON_FUNC)material.org.ZBuffer;\r
128         AlphaRef = 0; // tofix(material.org.MaterialTypeParam, FIXPOINT_COLOR_MAX);\r
129 \r
130         E_BLEND_FACTOR srcFact,dstFact;\r
131         E_MODULATE_FUNC modulate;\r
132         u32 alphaSrc;\r
133         unpack_textureBlendFunc ( srcFact, dstFact, modulate, alphaSrc, material.org.MaterialTypeParam);\r
134 \r
135         fragmentShader = 0;\r
136 \r
137         if ( srcFact == EBF_DST_COLOR && dstFact == EBF_ZERO )\r
138         {\r
139                 fragmentShader = &CTRTextureBlend::fragment_dst_color_zero;\r
140         }\r
141         else if ( srcFact == EBF_DST_COLOR && dstFact == EBF_ONE )\r
142         {\r
143                 fragmentShader = &CTRTextureBlend::fragment_dst_color_one;\r
144         }\r
145         else if ( srcFact == EBF_DST_COLOR && dstFact == EBF_SRC_ALPHA)\r
146         {\r
147                 fragmentShader = &CTRTextureBlend::fragment_dst_color_src_alpha;\r
148         }\r
149         else if ( srcFact == EBF_DST_COLOR && dstFact == EBF_ONE_MINUS_DST_ALPHA)\r
150         {\r
151                 fragmentShader = &CTRTextureBlend::fragment_dst_color_one_minus_dst_alpha;\r
152         }\r
153         else if ( srcFact == EBF_ZERO && dstFact == EBF_ONE_MINUS_SRC_COLOR )\r
154         {\r
155                 fragmentShader = &CTRTextureBlend::fragment_zero_one_minus_scr_color;\r
156         }\r
157         else if ( srcFact == EBF_ONE && dstFact == EBF_ONE_MINUS_SRC_ALPHA)\r
158         {\r
159                 fragmentShader = &CTRTextureBlend::fragment_one_one_minus_src_alpha;\r
160         }\r
161         else if ( srcFact == EBF_ONE_MINUS_DST_ALPHA && dstFact == EBF_ONE )\r
162         {\r
163                 fragmentShader = &CTRTextureBlend::fragment_one_minus_dst_alpha_one;\r
164         }\r
165         else if ( srcFact == EBF_SRC_ALPHA && dstFact == EBF_ONE )\r
166         {\r
167                 fragmentShader = &CTRTextureBlend::fragment_src_alpha_one;\r
168         }\r
169         else if (srcFact == EBF_SRC_ALPHA && dstFact == EBF_ONE_MINUS_SRC_ALPHA)\r
170         {\r
171                 fragmentShader = &CTRTextureBlend::fragment_src_alpha_one_minus_src_alpha;\r
172         }\r
173         else if ( srcFact == EBF_SRC_COLOR && dstFact == EBF_SRC_ALPHA )\r
174         {\r
175                 fragmentShader = &CTRTextureBlend::fragment_src_color_src_alpha;\r
176         }\r
177         else\r
178         {\r
179                 showname = 1;\r
180                 fragmentShader = &CTRTextureBlend::fragment_dst_color_zero;\r
181         }\r
182 \r
183         static const c8 *n[] =\r
184         {\r
185                 "gl_zero",\r
186                 "gl_one",\r
187                 "gl_dst_color",\r
188                 "gl_one_minus_dst_color",\r
189                 "gl_src_color",\r
190                 "gl_one_minus_src_color",\r
191                 "gl_src_alpha",\r
192                 "gl_one_minus_src_alpha",\r
193                 "gl_dst_alpha",\r
194                 "gl_one_minus_dst_alpha",\r
195                 "gl_src_alpha_saturate"\r
196         };\r
197 \r
198         static E_BLEND_FACTOR lsrcFact = EBF_ZERO;\r
199         static E_BLEND_FACTOR ldstFact = EBF_ZERO;\r
200 \r
201         if ( showname && ( lsrcFact != srcFact || ldstFact != dstFact ) )\r
202         {\r
203                 char buf[128];\r
204                 snprintf_irr ( buf, 128, "missing shader: %s %s",n[srcFact], n[dstFact] );\r
205                 os::Printer::log( buf, ELL_WARNING);\r
206 \r
207                 lsrcFact = srcFact;\r
208                 ldstFact = dstFact;\r
209         }\r
210 \r
211 }\r
212 \r
213 \r
214 /*!\r
215 */\r
216 void CTRTextureBlend::fragment_dst_color_src_alpha ()\r
217 {\r
218         tVideoSample *dst;\r
219 \r
220 #ifdef USE_ZBUFFER\r
221         fp24 *z;\r
222 #endif\r
223 \r
224         s32 xStart;\r
225         s32 xEnd;\r
226         s32 dx;\r
227 \r
228 \r
229 #ifdef SUBTEXEL\r
230         f32 subPixel;\r
231 #endif\r
232 \r
233 #ifdef IPOL_Z\r
234         f32 slopeZ;\r
235 #endif\r
236 #ifdef IPOL_W\r
237         fp24 slopeW;\r
238 #endif\r
239 #ifdef IPOL_C0\r
240         sVec4 slopeC[BURNING_MATERIAL_MAX_COLORS];\r
241 #endif\r
242 #ifdef IPOL_T0\r
243         sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES];\r
244 #endif\r
245 \r
246         // apply top-left fill-convention, left\r
247         xStart = fill_convention_left( line.x[0] );\r
248         xEnd = fill_convention_right( line.x[1] );\r
249 \r
250         dx = xEnd - xStart;\r
251 \r
252         if ( dx < 0 )\r
253                 return;\r
254 \r
255         // slopes\r
256         const f32 invDeltaX = fill_step_x( line.x[1] - line.x[0] );\r
257 \r
258 #ifdef IPOL_Z\r
259         slopeZ = (line.z[1] - line.z[0]) * invDeltaX;\r
260 #endif\r
261 #ifdef IPOL_W\r
262         slopeW = (line.w[1] - line.w[0]) * invDeltaX;\r
263 #endif\r
264 #ifdef IPOL_C0\r
265         slopeC[0] = (line.c[0][1] - line.c[0][0]) * invDeltaX;\r
266 #endif\r
267 #ifdef IPOL_T0\r
268         slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX;\r
269 #endif\r
270 #ifdef IPOL_T1\r
271         slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX;\r
272 #endif\r
273 \r
274 #ifdef SUBTEXEL\r
275         subPixel = ( (f32) xStart ) - line.x[0];\r
276 #ifdef IPOL_Z\r
277         line.z[0] += slopeZ * subPixel;\r
278 #endif\r
279 #ifdef IPOL_W\r
280         line.w[0] += slopeW * subPixel;\r
281 #endif\r
282 #ifdef IPOL_C0\r
283         line.c[0][0] += slopeC[0] * subPixel;\r
284 #endif\r
285 #ifdef IPOL_T0\r
286         line.t[0][0] += slopeT[0] * subPixel;\r
287 #endif\r
288 #ifdef IPOL_T1\r
289         line.t[1][0] += slopeT[1] * subPixel;\r
290 #endif\r
291 #endif\r
292 \r
293         SOFTWARE_DRIVER_2_CLIPCHECK;\r
294         dst = (tVideoSample*)RenderTarget->getData() + ( line.y * RenderTarget->getDimension().Width ) + xStart;\r
295 \r
296 #ifdef USE_ZBUFFER\r
297         z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;\r
298 #endif\r
299 \r
300 \r
301         f32 iw =        FIX_POINT_F32_MUL;\r
302 \r
303         tFixPoint a0, r0, g0, b0;\r
304         tFixPoint     r1, g1, b1;\r
305 \r
306         s32 i;\r
307 \r
308         switch (depth_func)\r
309         {\r
310         default:\r
311         case ECFN_LESSEQUAL:\r
312         for ( i = 0; i <= dx; i += SOFTWARE_DRIVER_2_STEP_X)\r
313         {\r
314 #ifdef CMP_W\r
315                 if ( line.w[0] >= z[i] )\r
316 #endif\r
317 \r
318                 {\r
319 \r
320 #ifdef WRITE_W\r
321                         z[i] = line.w[0];\r
322 #endif\r
323 \r
324 #ifdef INVERSE_W\r
325                 iw = fix_inverse32 ( line.w[0] );\r
326 #endif\r
327 \r
328                 getSample_texture ( a0,r0,g0,b0,\r
329                                                         &IT[0],\r
330                                                         tofix(line.t[0][0].x, iw),\r
331                                                         tofix(line.t[0][0].y, iw)\r
332                                                 );\r
333 \r
334                 color_to_fix ( r1, g1, b1, dst[i] );\r
335 \r
336                 dst[i] = fix_to_sample( clampfix_maxcolor ( imulFix_tex2 ( r0, r1 ) ),\r
337                                                                 clampfix_maxcolor ( imulFix_tex2 ( g0, g1 ) ),\r
338                                                                 clampfix_maxcolor ( imulFix_tex2 ( b0, b1 ) )\r
339                                                         );\r
340                 }\r
341 \r
342 #ifdef IPOL_W\r
343                 line.w[0] += slopeW;\r
344 #endif\r
345 #ifdef IPOL_T0\r
346                 line.t[0][0] += slopeT[0];\r
347 #endif\r
348 #ifdef IPOL_C0\r
349                 line.c[0][0] += slopeC[0];\r
350 #endif\r
351         }\r
352         break;\r
353 \r
354         case 2:\r
355         for ( i = 0; i <= dx; i += SOFTWARE_DRIVER_2_STEP_X)\r
356         {\r
357 #ifdef CMP_W\r
358                 if ( line.w[0] == z[i] )\r
359 #endif\r
360 \r
361                 {\r
362 \r
363 #ifdef WRITE_W\r
364                         z[i] = line.w[0];\r
365 #endif\r
366 \r
367 #ifdef INVERSE_W\r
368                 iw = fix_inverse32 ( line.w[0] );\r
369 #endif\r
370 \r
371                 getSample_texture ( a0,r0,g0,b0,\r
372                                                         &IT[0],\r
373                                                         tofix ( line.t[0][0].x,iw),\r
374                                                         tofix ( line.t[0][0].y,iw)\r
375                                                 );\r
376 \r
377                 color_to_fix ( r1, g1, b1, dst[i] );\r
378 \r
379                 dst[i] = fix_to_sample( clampfix_maxcolor ( imulFix_tex2 ( r0, r1 ) ),\r
380                                                                 clampfix_maxcolor ( imulFix_tex2 ( g0, g1 ) ),\r
381                                                                 clampfix_maxcolor ( imulFix_tex2 ( b0, b1 ) )\r
382                                                         );\r
383 \r
384                 }\r
385 \r
386 #ifdef IPOL_W\r
387                 line.w[0] += slopeW;\r
388 #endif\r
389 #ifdef IPOL_T0\r
390                 line.t[0][0] += slopeT[0];\r
391 #endif\r
392 #ifdef IPOL_C0\r
393                 line.c[0][0] += slopeC[0];\r
394 #endif\r
395         }break;\r
396         } // zcompare\r
397 \r
398 }\r
399 \r
400 /*!\r
401 */\r
402 void CTRTextureBlend::fragment_src_color_src_alpha ()\r
403 {\r
404         tVideoSample *dst;\r
405 \r
406 #ifdef USE_ZBUFFER\r
407         fp24 *z;\r
408 #endif\r
409 \r
410         s32 xStart;\r
411         s32 xEnd;\r
412         s32 dx;\r
413 \r
414 \r
415 #ifdef SUBTEXEL\r
416         f32 subPixel;\r
417 #endif\r
418 \r
419 #ifdef IPOL_Z\r
420         f32 slopeZ;\r
421 #endif\r
422 #ifdef IPOL_W\r
423         fp24 slopeW;\r
424 #endif\r
425 #ifdef IPOL_C0\r
426         sVec4 slopeC[BURNING_MATERIAL_MAX_COLORS];\r
427 #endif\r
428 #ifdef IPOL_T0\r
429         sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES];\r
430 #endif\r
431 \r
432         // apply top-left fill-convention, left\r
433         xStart = fill_convention_left( line.x[0] );\r
434         xEnd = fill_convention_right( line.x[1] );\r
435 \r
436         dx = xEnd - xStart;\r
437         if ( dx < 0 )\r
438                 return;\r
439 \r
440         // slopes\r
441         const f32 invDeltaX = fill_step_x( line.x[1] - line.x[0] );\r
442 \r
443 #ifdef IPOL_Z\r
444         slopeZ = (line.z[1] - line.z[0]) * invDeltaX;\r
445 #endif\r
446 #ifdef IPOL_W\r
447         slopeW = (line.w[1] - line.w[0]) * invDeltaX;\r
448 #endif\r
449 #ifdef IPOL_C0\r
450         slopeC[0] = (line.c[0][1] - line.c[0][0]) * invDeltaX;\r
451 #endif\r
452 #ifdef IPOL_T0\r
453         slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX;\r
454 #endif\r
455 #ifdef IPOL_T1\r
456         slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX;\r
457 #endif\r
458 \r
459 #ifdef SUBTEXEL\r
460         subPixel = ( (f32) xStart ) - line.x[0];\r
461 #ifdef IPOL_Z\r
462         line.z[0] += slopeZ * subPixel;\r
463 #endif\r
464 #ifdef IPOL_W\r
465         line.w[0] += slopeW * subPixel;\r
466 #endif\r
467 #ifdef IPOL_C0\r
468         line.c[0][0] += slopeC[0] * subPixel;\r
469 #endif\r
470 #ifdef IPOL_T0\r
471         line.t[0][0] += slopeT[0] * subPixel;\r
472 #endif\r
473 #ifdef IPOL_T1\r
474         line.t[1][0] += slopeT[1] * subPixel;\r
475 #endif\r
476 #endif\r
477 \r
478         SOFTWARE_DRIVER_2_CLIPCHECK;\r
479         dst = (tVideoSample*)RenderTarget->getData() + ( line.y * RenderTarget->getDimension().Width ) + xStart;\r
480 \r
481 #ifdef USE_ZBUFFER\r
482         z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;\r
483 #endif\r
484 \r
485 \r
486         f32 iw =        FIX_POINT_F32_MUL;\r
487 \r
488         tFixPoint a0, r0, g0, b0;\r
489         tFixPoint     r1, g1, b1;\r
490 \r
491 #ifdef IPOL_C0\r
492         tFixPoint a2,r2, g2, b2;\r
493 #endif\r
494 \r
495         s32 i;\r
496 \r
497         switch (depth_func)\r
498         {\r
499         default:\r
500         case ECFN_LESSEQUAL:\r
501         for ( i = 0; i <= dx; i += SOFTWARE_DRIVER_2_STEP_X)\r
502         {\r
503 #ifdef CMP_W\r
504                 if ( line.w[0] >= z[i] )\r
505 #endif\r
506 \r
507                 {\r
508                         //solves example 08. todo: depth_write. \r
509 #ifdef WRITE_W\r
510                 //z[i] = line.w[0];\r
511 #endif\r
512 \r
513 #ifdef INVERSE_W\r
514                 iw = fix_inverse32 ( line.w[0] );\r
515 #endif\r
516 \r
517                 getSample_texture ( a0, r0, g0, b0, &IT[0],     tofix ( line.t[0][0].x,iw),     tofix ( line.t[0][0].y,iw) );\r
518 \r
519 #ifdef IPOL_C0\r
520                 vec4_to_fix(a2,r2, g2, b2, line.c[0][0], iw);\r
521                 //a0 = imulFix(a0, a2); why is vertex color enabled and not vertex_alpha?\r
522                 r0 = imulFix_simple(r0, r2);\r
523                 g0 = imulFix_simple(g0, g2);\r
524                 b0 = imulFix_simple(b0, b2);\r
525 #endif\r
526 \r
527                 color_to_fix ( r1, g1, b1, dst[i] );\r
528                 dst[i] = fix_to_sample( clampfix_maxcolor ( imulFix_tex1( r0, r0 ) + imulFix_tex1( r1, a0 ) ),\r
529                                                                 clampfix_maxcolor ( imulFix_tex1( g0, g0 ) + imulFix_tex1( g1, a0 ) ),\r
530                                                                 clampfix_maxcolor ( imulFix_tex1( b0, b0 ) + imulFix_tex1( b1, a0 ) )\r
531                                                         );\r
532 \r
533                 }\r
534 \r
535 #ifdef IPOL_W\r
536                 line.w[0] += slopeW;\r
537 #endif\r
538 #ifdef IPOL_T0\r
539                 line.t[0][0] += slopeT[0];\r
540 #endif\r
541 #ifdef IPOL_C0\r
542                 line.c[0][0] += slopeC[0];\r
543 #endif\r
544         }\r
545         break;\r
546 \r
547         case 2:\r
548         for ( i = 0; i <= dx; i += SOFTWARE_DRIVER_2_STEP_X)\r
549         {\r
550 #ifdef CMP_W\r
551                 if ( line.w[0] == z[i] )\r
552 #endif\r
553 \r
554                 {\r
555 \r
556 #ifdef WRITE_W\r
557                         z[i] = line.w[0];\r
558 #endif\r
559 \r
560 #ifdef INVERSE_W\r
561                 iw = fix_inverse32 ( line.w[0] );\r
562 #endif\r
563 \r
564                 getSample_texture ( a0,r0,g0,b0,\r
565                                                         &IT[0],\r
566                                                         tofix ( line.t[0][0].x,iw),\r
567                                                         tofix ( line.t[0][0].y,iw)\r
568                                                 );\r
569 \r
570                 color_to_fix ( r1, g1, b1, dst[i] );\r
571 \r
572                 dst[i] = fix_to_sample( clampfix_maxcolor ( imulFix_tex2 ( r0, r1 ) ),\r
573                                                                 clampfix_maxcolor ( imulFix_tex2 ( g0, g1 ) ),\r
574                                                                 clampfix_maxcolor ( imulFix_tex2 ( b0, b1 ) )\r
575                                                         );\r
576 \r
577                 }\r
578 \r
579 #ifdef IPOL_W\r
580                 line.w[0] += slopeW;\r
581 #endif\r
582 #ifdef IPOL_T0\r
583                 line.t[0][0] += slopeT[0];\r
584 #endif\r
585 #ifdef IPOL_C0\r
586                 line.c[0][0] += slopeC[0];\r
587 #endif\r
588         }break;\r
589         \r
590         } // zcompare\r
591 \r
592 }\r
593 \r
594 /*!\r
595 */\r
596 void CTRTextureBlend::fragment_one_one_minus_src_alpha()\r
597 {\r
598         tVideoSample *dst;\r
599 \r
600 #ifdef USE_ZBUFFER\r
601         fp24 *z;\r
602 #endif\r
603 \r
604         s32 xStart;\r
605         s32 xEnd;\r
606         s32 dx;\r
607 \r
608 \r
609 #ifdef SUBTEXEL\r
610         f32 subPixel;\r
611 #endif\r
612 \r
613 #ifdef IPOL_Z\r
614         f32 slopeZ;\r
615 #endif\r
616 #ifdef IPOL_W\r
617         fp24 slopeW;\r
618 #endif\r
619 #ifdef IPOL_C0\r
620         sVec4 slopeC[BURNING_MATERIAL_MAX_COLORS];\r
621 #endif\r
622 #ifdef IPOL_T0\r
623         sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES];\r
624 #endif\r
625 \r
626         // apply top-left fill-convention, left\r
627         xStart = fill_convention_left( line.x[0] );\r
628         xEnd = fill_convention_right( line.x[1] );\r
629 \r
630         dx = xEnd - xStart;\r
631 \r
632         if ( dx < 0 )\r
633                 return;\r
634 \r
635         // slopes\r
636         const f32 invDeltaX = fill_step_x( line.x[1] - line.x[0] );\r
637 \r
638 #ifdef IPOL_Z\r
639         slopeZ = (line.z[1] - line.z[0]) * invDeltaX;\r
640 #endif\r
641 #ifdef IPOL_W\r
642         slopeW = (line.w[1] - line.w[0]) * invDeltaX;\r
643 #endif\r
644 #ifdef IPOL_C0\r
645         slopeC[0] = (line.c[0][1] - line.c[0][0]) * invDeltaX;\r
646 #endif\r
647 #ifdef IPOL_T0\r
648         slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX;\r
649 #endif\r
650 #ifdef IPOL_T1\r
651         slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX;\r
652 #endif\r
653 \r
654 #ifdef SUBTEXEL\r
655         subPixel = ( (f32) xStart ) - line.x[0];\r
656 #ifdef IPOL_Z\r
657         line.z[0] += slopeZ * subPixel;\r
658 #endif\r
659 #ifdef IPOL_W\r
660         line.w[0] += slopeW * subPixel;\r
661 #endif\r
662 #ifdef IPOL_C0\r
663         line.c[0][0] += slopeC[0] * subPixel;\r
664 #endif\r
665 #ifdef IPOL_T0\r
666         line.t[0][0] += slopeT[0] * subPixel;\r
667 #endif\r
668 #ifdef IPOL_T1\r
669         line.t[1][0] += slopeT[1] * subPixel;\r
670 #endif\r
671 #endif\r
672 \r
673         SOFTWARE_DRIVER_2_CLIPCHECK;\r
674         dst = (tVideoSample*)RenderTarget->getData() + ( line.y * RenderTarget->getDimension().Width ) + xStart;\r
675 \r
676 #ifdef USE_ZBUFFER\r
677         z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;\r
678 #endif\r
679 \r
680 \r
681         f32 iw = FIX_POINT_F32_MUL;\r
682 \r
683         tFixPoint a0,r0, g0, b0;\r
684         tFixPoint        r1, g1, b1;\r
685 #ifdef IPOL_C0\r
686         tFixPoint        r2, g2, b2;\r
687 #endif\r
688         s32 i;\r
689 \r
690         switch (depth_func)\r
691         {\r
692         default:\r
693         case ECFN_LESSEQUAL:\r
694         for ( i = 0; i <= dx; i += SOFTWARE_DRIVER_2_STEP_X)\r
695         {\r
696 #ifdef CMP_W\r
697                 if ( line.w[0] >= z[i] )\r
698 #endif\r
699 \r
700                 {\r
701 \r
702 #ifdef WRITE_W\r
703                         z[i] = line.w[0];\r
704 #endif\r
705 \r
706 #ifdef INVERSE_W\r
707                 iw = fix_inverse32 ( line.w[0] );\r
708 #endif\r
709 \r
710                 getSample_texture ( a0, r0, g0, b0, IT + 0, tofix ( line.t[0][0].x,iw),tofix ( line.t[0][0].y,iw) );\r
711                 a0 = FIX_POINT_ONE - a0;\r
712 \r
713                 color_to_fix1 ( r1, g1, b1, dst[i] );\r
714 #ifdef IPOL_C0\r
715                 vec4_to_fix( r2, g2, b2, line.c[0][0],iw );\r
716 \r
717                 dst[i] = fix_to_sample( imulFix ( r0 + imulFix_simple( r1, a0 ), r2 ),\r
718                                                                 imulFix ( g0 + imulFix_simple( g1, a0 ), g2 ),\r
719                                                                 imulFix ( b0 + imulFix_simple( b1, a0 ), b2 )\r
720                                                         );\r
721 #else\r
722                 dst[i] = fix_to_sample( r0 + imulFix_simple( r1, a0 ),\r
723                                                                 g0 + imulFix_simple( g1, a0 ),\r
724                                                                 b0 + imulFix_simple( b1, a0 )\r
725                                                         );\r
726 \r
727 #endif\r
728 \r
729                 }\r
730 \r
731 #ifdef IPOL_W\r
732                 line.w[0] += slopeW;\r
733 #endif\r
734 #ifdef IPOL_T0\r
735                 line.t[0][0] += slopeT[0];\r
736 #endif\r
737 #ifdef IPOL_C0\r
738                 line.c[0][0] += slopeC[0];\r
739 #endif\r
740         }\r
741         break;\r
742 \r
743         case 2:\r
744         for ( i = 0; i <= dx; i += SOFTWARE_DRIVER_2_STEP_X)\r
745         {\r
746 #ifdef CMP_W\r
747                 if ( line.w[0] == z[i] )\r
748 #endif\r
749 \r
750                 {\r
751 \r
752 #ifdef WRITE_W\r
753                         z[i] = line.w[0];\r
754 #endif\r
755 \r
756 #ifdef INVERSE_W\r
757                 iw = fix_inverse32 ( line.w[0] );\r
758 #endif\r
759                 getSample_texture ( a0, r0, g0, b0, IT + 0, tofix ( line.t[0][0].x,iw),tofix ( line.t[0][0].y,iw) );\r
760                 a0 = FIX_POINT_ONE - a0;\r
761 \r
762                 color_to_fix1 ( r1, g1, b1, dst[i] );\r
763 #ifdef IPOL_C0\r
764                 vec4_to_fix( r2, g2, b2, line.c[0][0],iw );\r
765 \r
766                 dst[i] = fix_to_sample( imulFix ( r0 + imulFix_simple( r1, a0 ), r2 ),\r
767                                                                 imulFix ( g0 + imulFix_simple( g1, a0 ), g2 ),\r
768                                                                 imulFix ( b0 + imulFix_simple( b1, a0 ), b2 )\r
769                                                         );\r
770 #else\r
771                 dst[i] = fix_to_sample( r0 + imulFix_simple( r1, a0 ),\r
772                                                                 g0 + imulFix_simple( g1, a0 ),\r
773                                                                 b0 + imulFix_simple( b1, a0 )\r
774                                                         );\r
775 \r
776 #endif\r
777 \r
778                 }\r
779 \r
780 #ifdef IPOL_W\r
781                 line.w[0] += slopeW;\r
782 #endif\r
783 #ifdef IPOL_T0\r
784                 line.t[0][0] += slopeT[0];\r
785 #endif\r
786 #ifdef IPOL_C0\r
787                 line.c[0][0] += slopeC[0];\r
788 #endif\r
789         }break;\r
790 \r
791         } // zcompare\r
792 \r
793 }\r
794 \r
795 /*!\r
796 */\r
797 void CTRTextureBlend::fragment_one_minus_dst_alpha_one ()\r
798 {\r
799         tVideoSample *dst;\r
800 \r
801 #ifdef USE_ZBUFFER\r
802         fp24 *z;\r
803 #endif\r
804 \r
805         s32 xStart;\r
806         s32 xEnd;\r
807         s32 dx;\r
808 \r
809 \r
810 #ifdef SUBTEXEL\r
811         f32 subPixel;\r
812 #endif\r
813 \r
814 #ifdef IPOL_Z\r
815         f32 slopeZ;\r
816 #endif\r
817 #ifdef IPOL_W\r
818         fp24 slopeW;\r
819 #endif\r
820 #ifdef IPOL_C0\r
821         sVec4 slopeC[BURNING_MATERIAL_MAX_COLORS];\r
822 #endif\r
823 #ifdef IPOL_T0\r
824         sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES];\r
825 #endif\r
826 \r
827         // apply top-left fill-convention, left\r
828         xStart = fill_convention_left( line.x[0] );\r
829         xEnd = fill_convention_right( line.x[1] );\r
830 \r
831         dx = xEnd - xStart;\r
832 \r
833         if ( dx < 0 )\r
834                 return;\r
835 \r
836         // slopes\r
837         const f32 invDeltaX = fill_step_x( line.x[1] - line.x[0] );\r
838 \r
839 #ifdef IPOL_Z\r
840         slopeZ = (line.z[1] - line.z[0]) * invDeltaX;\r
841 #endif\r
842 #ifdef IPOL_W\r
843         slopeW = (line.w[1] - line.w[0]) * invDeltaX;\r
844 #endif\r
845 #ifdef IPOL_C0\r
846         slopeC[0] = (line.c[0][1] - line.c[0][0]) * invDeltaX;\r
847 #endif\r
848 #ifdef IPOL_T0\r
849         slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX;\r
850 #endif\r
851 #ifdef IPOL_T1\r
852         slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX;\r
853 #endif\r
854 \r
855 #ifdef SUBTEXEL\r
856         subPixel = ( (f32) xStart ) - line.x[0];\r
857 #ifdef IPOL_Z\r
858         line.z[0] += slopeZ * subPixel;\r
859 #endif\r
860 #ifdef IPOL_W\r
861         line.w[0] += slopeW * subPixel;\r
862 #endif\r
863 #ifdef IPOL_C0\r
864         line.c[0][0] += slopeC[0] * subPixel;\r
865 #endif\r
866 #ifdef IPOL_T0\r
867         line.t[0][0] += slopeT[0] * subPixel;\r
868 #endif\r
869 #ifdef IPOL_T1\r
870         line.t[1][0] += slopeT[1] * subPixel;\r
871 #endif\r
872 #endif\r
873 \r
874         SOFTWARE_DRIVER_2_CLIPCHECK;\r
875         dst = (tVideoSample*)RenderTarget->getData() + ( line.y * RenderTarget->getDimension().Width ) + xStart;\r
876 \r
877 #ifdef USE_ZBUFFER\r
878         z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;\r
879 #endif\r
880 \r
881 \r
882         f32 iw = FIX_POINT_F32_MUL;\r
883 \r
884         tFixPoint r0, g0, b0;\r
885         tFixPoint a1, r1, g1, b1;\r
886 #ifdef IPOL_C0\r
887         tFixPoint r2, g2, b2;\r
888 #endif\r
889         s32 i;\r
890 \r
891         switch (depth_func)\r
892         {\r
893         default:\r
894         case ECFN_LESSEQUAL:\r
895         for ( i = 0; i <= dx; i += SOFTWARE_DRIVER_2_STEP_X)\r
896         {\r
897 #ifdef CMP_W\r
898                 if ( line.w[0] >= z[i] )\r
899 #endif\r
900 \r
901                 {\r
902 \r
903 #ifdef WRITE_W\r
904                         z[i] = line.w[0];\r
905 #endif\r
906 \r
907 #ifdef INVERSE_W\r
908                 iw = fix_inverse32 ( line.w[0] );\r
909 #endif\r
910 \r
911                 getSample_texture ( r0, g0, b0, IT + 0, tofix ( line.t[0][0].x,iw),tofix ( line.t[0][0].y,iw) );\r
912                 color_to_fix1 ( a1, r1, g1, b1, dst[i] );\r
913 #ifdef IPOL_C0\r
914                 vec4_to_fix( r2, g2, b2, line.c[0][0],iw );\r
915 \r
916                 a1 = FIX_POINT_ONE - a1;\r
917                 dst[i] = fix_to_sample( imulFix (imulFix_simple( r0, a1 ) + r1, r2 ),\r
918                                                                 imulFix (imulFix_simple( g0, a1 ) + g1, g2 ),\r
919                                                                 imulFix (imulFix_simple( b0, a1 ) + b1, b2 )\r
920                                                         );\r
921 #else\r
922                 dst[i] = fix_to_sample(imulFix_simple( r0, a1) + r0,\r
923                         imulFix_simple( g0, a1) + g0,\r
924                         imulFix_simple( b0, a1) + b0\r
925                                                         );\r
926 \r
927 #endif\r
928 \r
929                 }\r
930 \r
931 #ifdef IPOL_W\r
932                 line.w[0] += slopeW;\r
933 #endif\r
934 #ifdef IPOL_T0\r
935                 line.t[0][0] += slopeT[0];\r
936 #endif\r
937 #ifdef IPOL_C0\r
938                 line.c[0][0] += slopeC[0];\r
939 #endif\r
940         }\r
941         break;\r
942 \r
943         case 2:\r
944         for ( i = 0; i <= dx; i += SOFTWARE_DRIVER_2_STEP_X)\r
945         {\r
946 #ifdef CMP_W\r
947                 if ( line.w[0] == z[i] )\r
948 #endif\r
949 \r
950                 {\r
951 \r
952 #ifdef WRITE_W\r
953                         z[i] = line.w[0];\r
954 #endif\r
955 \r
956 #ifdef INVERSE_W\r
957                 iw = fix_inverse32 ( line.w[0] );\r
958 #endif\r
959                 getSample_texture ( r0, g0, b0, IT + 0, tofix ( line.t[0][0].x,iw),tofix ( line.t[0][0].y,iw) );\r
960                 color_to_fix1 ( a1, r1, g1, b1, dst[i] );\r
961 \r
962 #ifdef IPOL_C0\r
963                 vec4_to_fix( r2, g2, b2, line.c[0][0],iw );\r
964 \r
965                 a1 = FIX_POINT_ONE - a1;\r
966                 dst[i] = fix_to_sample( imulFix (imulFix_simple( r0, a1 ) + r1, r2 ),\r
967                                                                 imulFix (imulFix_simple( g0, a1 ) + g1, g2 ),\r
968                                                                 imulFix (imulFix_simple( b0, a1 ) + b1, b2 )\r
969                                                         );\r
970 #else\r
971                 dst[i] = fix_to_sample(imulFix_simple( r0, a1) + r0,\r
972                         imulFix_simple( g0, a1) + g0,\r
973                         imulFix_simple( b0, a1) + b0\r
974                                                         );\r
975 \r
976 #endif\r
977 \r
978                 }\r
979 \r
980 #ifdef IPOL_W\r
981                 line.w[0] += slopeW;\r
982 #endif\r
983 #ifdef IPOL_T0\r
984                 line.t[0][0] += slopeT[0];\r
985 #endif\r
986 #ifdef IPOL_C0\r
987                 line.c[0][0] += slopeC[0];\r
988 #endif\r
989         }break;\r
990 \r
991         } // zcompare\r
992 \r
993 }\r
994 \r
995 /*!\r
996 */\r
997 void CTRTextureBlend::fragment_src_alpha_one ()\r
998 {\r
999         tVideoSample *dst;\r
1000 \r
1001 #ifdef USE_ZBUFFER\r
1002         fp24 *z;\r
1003 #endif\r
1004 \r
1005         s32 xStart;\r
1006         s32 xEnd;\r
1007         s32 dx;\r
1008 \r
1009 \r
1010 #ifdef SUBTEXEL\r
1011         f32 subPixel;\r
1012 #endif\r
1013 \r
1014 #ifdef IPOL_Z\r
1015         f32 slopeZ;\r
1016 #endif\r
1017 #ifdef IPOL_W\r
1018         fp24 slopeW;\r
1019 #endif\r
1020 #ifdef IPOL_C0\r
1021         sVec4 slopeC[BURNING_MATERIAL_MAX_COLORS];\r
1022 #endif\r
1023 #ifdef IPOL_T0\r
1024         sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES];\r
1025 #endif\r
1026 \r
1027         // apply top-left fill-convention, left\r
1028         xStart = fill_convention_left( line.x[0] );\r
1029         xEnd = fill_convention_right( line.x[1] );\r
1030 \r
1031         dx = xEnd - xStart;\r
1032 \r
1033         if ( dx < 0 )\r
1034                 return;\r
1035 \r
1036         // slopes\r
1037         const f32 invDeltaX = fill_step_x( line.x[1] - line.x[0] );\r
1038 \r
1039 #ifdef IPOL_Z\r
1040         slopeZ = (line.z[1] - line.z[0]) * invDeltaX;\r
1041 #endif\r
1042 #ifdef IPOL_W\r
1043         slopeW = (line.w[1] - line.w[0]) * invDeltaX;\r
1044 #endif\r
1045 #ifdef IPOL_C0\r
1046         slopeC[0] = (line.c[0][1] - line.c[0][0]) * invDeltaX;\r
1047 #endif\r
1048 #ifdef IPOL_T0\r
1049         slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX;\r
1050 #endif\r
1051 #ifdef IPOL_T1\r
1052         slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX;\r
1053 #endif\r
1054 \r
1055 #ifdef SUBTEXEL\r
1056         subPixel = ( (f32) xStart ) - line.x[0];\r
1057 #ifdef IPOL_Z\r
1058         line.z[0] += slopeZ * subPixel;\r
1059 #endif\r
1060 #ifdef IPOL_W\r
1061         line.w[0] += slopeW * subPixel;\r
1062 #endif\r
1063 #ifdef IPOL_C0\r
1064         line.c[0][0] += slopeC[0] * subPixel;\r
1065 #endif\r
1066 #ifdef IPOL_T0\r
1067         line.t[0][0] += slopeT[0] * subPixel;\r
1068 #endif\r
1069 #ifdef IPOL_T1\r
1070         line.t[1][0] += slopeT[1] * subPixel;\r
1071 #endif\r
1072 #endif\r
1073 \r
1074         SOFTWARE_DRIVER_2_CLIPCHECK;\r
1075         dst = (tVideoSample*)RenderTarget->getData() + ( line.y * RenderTarget->getDimension().Width ) + xStart;\r
1076 \r
1077 #ifdef USE_ZBUFFER\r
1078         z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;\r
1079 #endif\r
1080 \r
1081 \r
1082         f32 iw = FIX_POINT_F32_MUL;\r
1083 \r
1084         tFixPoint a0, r0, g0, b0;\r
1085         tFixPoint r1, g1, b1;\r
1086 #ifdef IPOL_C0\r
1087         tFixPoint r2, g2, b2;\r
1088 #endif\r
1089         s32 i;\r
1090 \r
1091         switch (depth_func)\r
1092         {\r
1093         default:\r
1094         case ECFN_LESSEQUAL:\r
1095         for ( i = 0; i <= dx; i += SOFTWARE_DRIVER_2_STEP_X)\r
1096         {\r
1097 #ifdef CMP_W\r
1098                 if ( line.w[0] >= z[i] )\r
1099 #endif\r
1100 \r
1101                 {\r
1102 \r
1103 \r
1104 #ifdef INVERSE_W\r
1105                 iw = fix_inverse32 ( line.w[0] );\r
1106 #endif\r
1107 \r
1108                 getSample_texture ( a0, r0, g0, b0, IT + 0, tofix ( line.t[0][0].x,iw),tofix ( line.t[0][0].y,iw) );\r
1109                 if ( a0 > 0 )\r
1110                 {\r
1111                         fix_color_norm(a0);\r
1112 \r
1113                 color_to_fix ( r1, g1, b1, dst[i] );\r
1114 \r
1115 #ifdef IPOL_C0\r
1116                 vec4_to_fix( r2, g2, b2, line.c[0][0],iw );\r
1117 \r
1118                 dst[i] = fix4_to_sample( a0,\r
1119                                                                  clampfix_maxcolor (imulFix_simple(r0,a0) + r1),\r
1120                                                                  clampfix_maxcolor (imulFix_simple(g0,a0) + g1),\r
1121                                                                  clampfix_maxcolor (imulFix_simple(b0,a0) + b1)\r
1122                                                                 );\r
1123 \r
1124 /*\r
1125                 fix_color_norm(a0);\r
1126                 dst[i] = fix4_to_sample ( a0,\r
1127                                                                 imulFix ( imulFix_simple ( r0, a0 ) + r1, r2 ),\r
1128                                                                 imulFix ( imulFix_simple ( g0, a0 ) + g1, g2 ),\r
1129                                                                 imulFix ( imulFix_simple ( b0, a0 ) + b1, b2 )\r
1130                                                         );\r
1131 */\r
1132 #else\r
1133                 dst[i] = fix4_to_sample( a0,\r
1134                                                                  clampfix_maxcolor (imulFix_simple(r0,a0 ) + r1 ),\r
1135                                                                  clampfix_maxcolor (imulFix_simple(g0,a0 ) + g1 ),\r
1136                                                                  clampfix_maxcolor (imulFix_simple(b0,a0 ) + b1 )\r
1137                                                                 );\r
1138 \r
1139 #endif\r
1140 \r
1141 #ifdef WRITE_W\r
1142                         //z[i] = line.w[0];\r
1143 #endif\r
1144                 }\r
1145 \r
1146                 }\r
1147 \r
1148 #ifdef IPOL_W\r
1149                 line.w[0] += slopeW;\r
1150 #endif\r
1151 #ifdef IPOL_T0\r
1152                 line.t[0][0] += slopeT[0];\r
1153 #endif\r
1154 #ifdef IPOL_C0\r
1155                 line.c[0][0] += slopeC[0];\r
1156 #endif\r
1157         }\r
1158         break;\r
1159 \r
1160         case 2:\r
1161         for ( i = 0; i <= dx; i += SOFTWARE_DRIVER_2_STEP_X)\r
1162         {\r
1163 #ifdef CMP_W\r
1164                 if ( line.w[0] == z[i] )\r
1165 #endif\r
1166                 {\r
1167 \r
1168 #ifdef INVERSE_W\r
1169                 iw = fix_inverse32 ( line.w[0] );\r
1170 #endif\r
1171 \r
1172                 getSample_texture ( a0, r0, g0, b0, IT + 0, tofix ( line.t[0][0].x,iw),tofix ( line.t[0][0].y,iw) );\r
1173                 if ( a0 > 0 )\r
1174                 {\r
1175                         fix_color_norm(a0);\r
1176 \r
1177                 color_to_fix ( r1, g1, b1, dst[i] );\r
1178 \r
1179 #ifdef IPOL_C0\r
1180                 vec4_to_fix( r2, g2, b2, line.c[0][0],iw );\r
1181 \r
1182                 dst[i] = fix4_to_sample( a0,\r
1183                                                                  clampfix_maxcolor ( imulFix (imulFix_simple(r0,a0 ) + r1, r2 ) ),\r
1184                                                                  clampfix_maxcolor ( imulFix (imulFix_simple(g0,a0 ) + g1, g2 ) ),\r
1185                                                                  clampfix_maxcolor ( imulFix (imulFix_simple(b0,a0 ) + b1, b2 ) )\r
1186                                                                 );\r
1187 \r
1188 /*\r
1189                 fix_color_norm(a0);\r
1190                 dst[i] = fix4_to_sample ( a0,\r
1191                                                                 imulFix ( imulFix_simple ( r0, a0 ) + r1, r2 ),\r
1192                                                                 imulFix ( imulFix_simple ( g0, a0 ) + g1, g2 ),\r
1193                                                                 imulFix ( imulFix_simple ( b0, a0 ) + b1, b2 )\r
1194                                                         );\r
1195 */\r
1196 #else\r
1197                 dst[i] = fix4_to_sample( a0,\r
1198                                                                  clampfix_maxcolor (imulFix_simple(r0,a0 ) + r1 ),\r
1199                                                                  clampfix_maxcolor (imulFix_simple(g0,a0 ) + g1 ),\r
1200                                                                  clampfix_maxcolor (imulFix_simple(b0,a0 ) + b1 )\r
1201                                                                 );\r
1202 \r
1203 #endif\r
1204 \r
1205 #ifdef WRITE_W\r
1206                         z[i] = line.w[0];\r
1207 #endif\r
1208                 }\r
1209                 }\r
1210 #ifdef IPOL_W\r
1211                 line.w[0] += slopeW;\r
1212 #endif\r
1213 #ifdef IPOL_T0\r
1214                 line.t[0][0] += slopeT[0];\r
1215 #endif\r
1216 #ifdef IPOL_C0\r
1217                 line.c[0][0] += slopeC[0];\r
1218 #endif\r
1219         }break;\r
1220 \r
1221         } // zcompare\r
1222 \r
1223 }\r
1224 \r
1225 \r
1226 /*!\r
1227 */\r
1228 void CTRTextureBlend::fragment_src_alpha_one_minus_src_alpha()\r
1229 {\r
1230         tVideoSample *dst;\r
1231 \r
1232 #ifdef USE_ZBUFFER\r
1233         fp24 *z;\r
1234 #endif\r
1235 \r
1236         s32 xStart;\r
1237         s32 xEnd;\r
1238         s32 dx;\r
1239 \r
1240 \r
1241 #ifdef SUBTEXEL\r
1242         f32 subPixel;\r
1243 #endif\r
1244 \r
1245 #ifdef IPOL_Z\r
1246         f32 slopeZ;\r
1247 #endif\r
1248 #ifdef IPOL_W\r
1249         fp24 slopeW;\r
1250 #endif\r
1251 #ifdef IPOL_C0\r
1252         sVec4 slopeC[BURNING_MATERIAL_MAX_COLORS];\r
1253 #endif\r
1254 #ifdef IPOL_T0\r
1255         sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES];\r
1256 #endif\r
1257 \r
1258         // apply top-left fill-convention, left\r
1259         xStart = fill_convention_left(line.x[0]);\r
1260         xEnd = fill_convention_right(line.x[1]);\r
1261 \r
1262         dx = xEnd - xStart;\r
1263         if (dx < 0)\r
1264                 return;\r
1265 \r
1266         // slopes\r
1267         const f32 invDeltaX = fill_step_x(line.x[1] - line.x[0]);\r
1268 \r
1269 #ifdef IPOL_Z\r
1270         slopeZ = (line.z[1] - line.z[0]) * invDeltaX;\r
1271 #endif\r
1272 #ifdef IPOL_W\r
1273         slopeW = (line.w[1] - line.w[0]) * invDeltaX;\r
1274 #endif\r
1275 #ifdef IPOL_C0\r
1276         slopeC[0] = (line.c[0][1] - line.c[0][0]) * invDeltaX;\r
1277 #endif\r
1278 #ifdef IPOL_T0\r
1279         slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX;\r
1280 #endif\r
1281 #ifdef IPOL_T1\r
1282         slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX;\r
1283 #endif\r
1284 \r
1285 #ifdef SUBTEXEL\r
1286         subPixel = ((f32)xStart) - line.x[0];\r
1287 #ifdef IPOL_Z\r
1288         line.z[0] += slopeZ * subPixel;\r
1289 #endif\r
1290 #ifdef IPOL_W\r
1291         line.w[0] += slopeW * subPixel;\r
1292 #endif\r
1293 #ifdef IPOL_C0\r
1294         line.c[0][0] += slopeC[0] * subPixel;\r
1295 #endif\r
1296 #ifdef IPOL_T0\r
1297         line.t[0][0] += slopeT[0] * subPixel;\r
1298 #endif\r
1299 #ifdef IPOL_T1\r
1300         line.t[1][0] += slopeT[1] * subPixel;\r
1301 #endif\r
1302 #endif\r
1303 \r
1304         SOFTWARE_DRIVER_2_CLIPCHECK;\r
1305         dst = (tVideoSample*)RenderTarget->getData() + (line.y * RenderTarget->getDimension().Width) + xStart;\r
1306 \r
1307 #ifdef USE_ZBUFFER\r
1308         z = (fp24*)DepthBuffer->lock() + (line.y * RenderTarget->getDimension().Width) + xStart;\r
1309 #endif\r
1310 \r
1311 \r
1312         f32 iw = FIX_POINT_F32_MUL;\r
1313 \r
1314         tFixPoint a0, r0, g0, b0;\r
1315         tFixPoint     r1, g1, b1;\r
1316         tFixPoint a2, r2, g2, b2;\r
1317 \r
1318         s32 i;\r
1319 \r
1320         switch (depth_func)\r
1321         {\r
1322         default:\r
1323         case ECFN_LESSEQUAL:\r
1324                 for (i = 0; i <= dx; i += SOFTWARE_DRIVER_2_STEP_X)\r
1325                 {\r
1326 #ifdef CMP_W\r
1327                         if (line.w[0] >= z[i])\r
1328 #endif\r
1329 \r
1330                         {\r
1331 #ifdef WRITE_W\r
1332                 //z[i] = line.w[0];\r
1333 #endif\r
1334 \r
1335 #ifdef INVERSE_W\r
1336                                 iw = fix_inverse32(line.w[0]);\r
1337 #endif\r
1338 \r
1339                                 getSample_texture(a0, r0, g0, b0, &IT[0], tofix(line.t[0][0].x, iw), tofix(line.t[0][0].y, iw));\r
1340                                 if (a0 > AlphaRef)\r
1341                                 {\r
1342 #ifdef IPOL_C0\r
1343                                         vec4_to_fix(a2, r2, g2, b2, line.c[0][0], iw);\r
1344                                         //a0 = imulFix(a0, a2); why is vertex color enabled and not vertex_alpha?\r
1345                                         r0 = imulFix_simple(r0, r2);\r
1346                                         g0 = imulFix_simple(g0, g2);\r
1347                                         b0 = imulFix_simple(b0, b2);\r
1348 #endif\r
1349 \r
1350                                         color_to_fix(r1, g1, b1, dst[i]);\r
1351 \r
1352                                         fix_color_norm(a0);\r
1353 \r
1354                                         r2 = r1 + imulFix(a0, r0 - r1);\r
1355                                         g2 = g1 + imulFix(a0, g0 - g1);\r
1356                                         b2 = b1 + imulFix(a0, b0 - b1);\r
1357                                         dst[i] = fix4_to_sample(a0, r2, g2, b2);\r
1358                                 }\r
1359 \r
1360                         }\r
1361 \r
1362 #ifdef IPOL_W\r
1363                         line.w[0] += slopeW;\r
1364 #endif\r
1365 #ifdef IPOL_T0\r
1366                         line.t[0][0] += slopeT[0];\r
1367 #endif\r
1368 #ifdef IPOL_C0\r
1369                         line.c[0][0] += slopeC[0];\r
1370 #endif\r
1371                 }\r
1372                 break;\r
1373 \r
1374         } // zcompare\r
1375 \r
1376 }\r
1377 \r
1378 \r
1379 /*!\r
1380 */\r
1381 void CTRTextureBlend::fragment_dst_color_one_minus_dst_alpha ()\r
1382 {\r
1383         tVideoSample *dst;\r
1384 \r
1385 #ifdef USE_ZBUFFER\r
1386         fp24 *z;\r
1387 #endif\r
1388 \r
1389         s32 xStart;\r
1390         s32 xEnd;\r
1391         s32 dx;\r
1392 \r
1393 \r
1394 #ifdef SUBTEXEL\r
1395         f32 subPixel;\r
1396 #endif\r
1397 \r
1398 #ifdef IPOL_Z\r
1399         f32 slopeZ;\r
1400 #endif\r
1401 #ifdef IPOL_W\r
1402         fp24 slopeW;\r
1403 #endif\r
1404 #ifdef IPOL_C0\r
1405         sVec4 slopeC[BURNING_MATERIAL_MAX_COLORS];\r
1406 #endif\r
1407 #ifdef IPOL_T0\r
1408         sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES];\r
1409 #endif\r
1410 \r
1411         // apply top-left fill-convention, left\r
1412         xStart = fill_convention_left( line.x[0] );\r
1413         xEnd = fill_convention_right( line.x[1] );\r
1414 \r
1415         dx = xEnd - xStart;\r
1416 \r
1417         if ( dx < 0 )\r
1418                 return;\r
1419 \r
1420         // slopes\r
1421         const f32 invDeltaX = fill_step_x( line.x[1] - line.x[0] );\r
1422 \r
1423 #ifdef IPOL_Z\r
1424         slopeZ = (line.z[1] - line.z[0]) * invDeltaX;\r
1425 #endif\r
1426 #ifdef IPOL_W\r
1427         slopeW = (line.w[1] - line.w[0]) * invDeltaX;\r
1428 #endif\r
1429 #ifdef IPOL_C0\r
1430         slopeC[0] = (line.c[0][1] - line.c[0][0]) * invDeltaX;\r
1431 #endif\r
1432 #ifdef IPOL_T0\r
1433         slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX;\r
1434 #endif\r
1435 #ifdef IPOL_T1\r
1436         slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX;\r
1437 #endif\r
1438 \r
1439 #ifdef SUBTEXEL\r
1440         subPixel = ( (f32) xStart ) - line.x[0];\r
1441 #ifdef IPOL_Z\r
1442         line.z[0] += slopeZ * subPixel;\r
1443 #endif\r
1444 #ifdef IPOL_W\r
1445         line.w[0] += slopeW * subPixel;\r
1446 #endif\r
1447 #ifdef IPOL_C0\r
1448         line.c[0][0] += slopeC[0] * subPixel;\r
1449 #endif\r
1450 #ifdef IPOL_T0\r
1451         line.t[0][0] += slopeT[0] * subPixel;\r
1452 #endif\r
1453 #ifdef IPOL_T1\r
1454         line.t[1][0] += slopeT[1] * subPixel;\r
1455 #endif\r
1456 #endif\r
1457 \r
1458         SOFTWARE_DRIVER_2_CLIPCHECK;\r
1459         dst = (tVideoSample*)RenderTarget->getData() + ( line.y * RenderTarget->getDimension().Width ) + xStart;\r
1460 \r
1461 #ifdef USE_ZBUFFER\r
1462         z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;\r
1463 #endif\r
1464 \r
1465 \r
1466         f32 iw = FIX_POINT_F32_MUL;\r
1467 \r
1468         tFixPoint r0, g0, b0;\r
1469         tFixPoint a1, r1, g1, b1;\r
1470 #ifdef IPOL_C0\r
1471         tFixPoint r2, g2, b2;\r
1472 #endif\r
1473         s32 i;\r
1474 \r
1475         switch (depth_func)\r
1476         {\r
1477         default:\r
1478         case ECFN_LESSEQUAL:\r
1479         for ( i = 0; i <= dx; i += SOFTWARE_DRIVER_2_STEP_X)\r
1480         {\r
1481 #ifdef CMP_W\r
1482                 if ( line.w[0] >= z[i] )\r
1483 #endif\r
1484 \r
1485                 {\r
1486 \r
1487 #ifdef WRITE_W\r
1488                         z[i] = line.w[0];\r
1489 #endif\r
1490 \r
1491 #ifdef INVERSE_W\r
1492                 iw = fix_inverse32 ( line.w[0] );\r
1493 #endif\r
1494 \r
1495                 getSample_texture ( r0, g0, b0, IT + 0, tofix ( line.t[0][0].x,iw),tofix ( line.t[0][0].y,iw) );\r
1496                 color_to_fix1 ( a1, r1, g1, b1, dst[i] );\r
1497 #ifdef IPOL_C0\r
1498                 vec4_to_fix( r2, g2, b2, line.c[0][0],iw );\r
1499 \r
1500                 a1 = FIX_POINT_ONE - a1;\r
1501                 dst[i] = fix_to_sample( imulFix ( imulFix ( r1, r0 + a1 ), r2 ),\r
1502                                                                 imulFix ( imulFix ( g1, g0 + a1 ), g2 ),\r
1503                                                                 imulFix ( imulFix ( b1, b0 + a1 ), b2 )\r
1504                                                         );\r
1505 #else\r
1506                 dst[i] = fix_to_sample( imulFix ( r1, r0 + a1 ),\r
1507                                                                 imulFix ( g1, g0 + a1 ),\r
1508                                                                 imulFix ( b1, b0 + a1 )\r
1509                                                         );\r
1510 \r
1511 #endif\r
1512 \r
1513                 }\r
1514 \r
1515 #ifdef IPOL_W\r
1516                 line.w[0] += slopeW;\r
1517 #endif\r
1518 #ifdef IPOL_T0\r
1519                 line.t[0][0] += slopeT[0];\r
1520 #endif\r
1521 #ifdef IPOL_C0\r
1522                 line.c[0][0] += slopeC[0];\r
1523 #endif\r
1524         }\r
1525         break;\r
1526 \r
1527         case 2:\r
1528         for ( i = 0; i <= dx; i += SOFTWARE_DRIVER_2_STEP_X)\r
1529         {\r
1530 #ifdef CMP_W\r
1531                 if ( line.w[0] == z[i] )\r
1532 #endif\r
1533 \r
1534                 {\r
1535 \r
1536 #ifdef WRITE_W\r
1537                         z[i] = line.w[0];\r
1538 #endif\r
1539 \r
1540 #ifdef INVERSE_W\r
1541                 iw = fix_inverse32 ( line.w[0] );\r
1542 #endif\r
1543                 getSample_texture ( r0, g0, b0, IT + 0, tofix ( line.t[0][0].x,iw),tofix ( line.t[0][0].y,iw) );\r
1544                 color_to_fix1 ( a1, r1, g1, b1, dst[i] );\r
1545 \r
1546 #ifdef IPOL_C0\r
1547                 vec4_to_fix( r2, g2, b2, line.c[0][0],iw );\r
1548 \r
1549                 a1 = FIX_POINT_ONE - a1;\r
1550                 dst[i] = fix_to_sample( imulFix ( imulFix ( r1, r0 + a1 ), r2 ),\r
1551                                                                 imulFix ( imulFix ( g1, g0 + a1 ), g2 ),\r
1552                                                                 imulFix ( imulFix ( b1, b0 + a1 ), b2 )\r
1553                                                         );\r
1554 #else\r
1555                 dst[i] = fix_to_sample( imulFix ( r1, r0 + a1 ),\r
1556                                                                 imulFix ( g1, g0 + a1 ),\r
1557                                                                 imulFix ( b1, b0 + a1 )\r
1558                                                         );\r
1559 \r
1560 #endif\r
1561 \r
1562                 }\r
1563 \r
1564 #ifdef IPOL_W\r
1565                 line.w[0] += slopeW;\r
1566 #endif\r
1567 #ifdef IPOL_T0\r
1568                 line.t[0][0] += slopeT[0];\r
1569 #endif\r
1570 #ifdef IPOL_C0\r
1571                 line.c[0][0] += slopeC[0];\r
1572 #endif\r
1573         }break;\r
1574         } // zcompare\r
1575 \r
1576 }\r
1577 \r
1578 /*!\r
1579 */\r
1580 void CTRTextureBlend::fragment_dst_color_zero ()\r
1581 {\r
1582         tVideoSample *dst;\r
1583 \r
1584 #ifdef USE_ZBUFFER\r
1585         fp24 *z;\r
1586 #endif\r
1587 \r
1588         s32 xStart;\r
1589         s32 xEnd;\r
1590         s32 dx;\r
1591 \r
1592 \r
1593 #ifdef SUBTEXEL\r
1594         f32 subPixel;\r
1595 #endif\r
1596 \r
1597 #ifdef IPOL_Z\r
1598         f32 slopeZ;\r
1599 #endif\r
1600 #ifdef IPOL_W\r
1601         fp24 slopeW;\r
1602 #endif\r
1603 #ifdef IPOL_C0\r
1604         sVec4 slopeC[BURNING_MATERIAL_MAX_COLORS];\r
1605 #endif\r
1606 #ifdef IPOL_T0\r
1607         sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES];\r
1608 #endif\r
1609 \r
1610         // apply top-left fill-convention, left\r
1611         xStart = fill_convention_left( line.x[0] );\r
1612         xEnd = fill_convention_right( line.x[1] );\r
1613 \r
1614         dx = xEnd - xStart;\r
1615 \r
1616         if ( dx < 0 )\r
1617                 return;\r
1618 \r
1619         // slopes\r
1620         const f32 invDeltaX = fill_step_x( line.x[1] - line.x[0] );\r
1621 \r
1622 #ifdef IPOL_Z\r
1623         slopeZ = (line.z[1] - line.z[0]) * invDeltaX;\r
1624 #endif\r
1625 #ifdef IPOL_W\r
1626         slopeW = (line.w[1] - line.w[0]) * invDeltaX;\r
1627 #endif\r
1628 #ifdef IPOL_C0\r
1629         slopeC[0] = (line.c[0][1] - line.c[0][0]) * invDeltaX;\r
1630 #endif\r
1631 #ifdef IPOL_T0\r
1632         slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX;\r
1633 #endif\r
1634 #ifdef IPOL_T1\r
1635         slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX;\r
1636 #endif\r
1637 \r
1638 #ifdef SUBTEXEL\r
1639         subPixel = ( (f32) xStart ) - line.x[0];\r
1640 #ifdef IPOL_Z\r
1641         line.z[0] += slopeZ * subPixel;\r
1642 #endif\r
1643 #ifdef IPOL_W\r
1644         line.w[0] += slopeW * subPixel;\r
1645 #endif\r
1646 #ifdef IPOL_C0\r
1647         line.c[0][0] += slopeC[0] * subPixel;\r
1648 #endif\r
1649 #ifdef IPOL_T0\r
1650         line.t[0][0] += slopeT[0] * subPixel;\r
1651 #endif\r
1652 #ifdef IPOL_T1\r
1653         line.t[1][0] += slopeT[1] * subPixel;\r
1654 #endif\r
1655 #endif\r
1656 \r
1657         SOFTWARE_DRIVER_2_CLIPCHECK;\r
1658         dst = (tVideoSample*)RenderTarget->getData() + ( line.y * RenderTarget->getDimension().Width ) + xStart;\r
1659 \r
1660 #ifdef USE_ZBUFFER\r
1661         z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;\r
1662 #endif\r
1663 \r
1664 \r
1665         f32 iw = FIX_POINT_F32_MUL;\r
1666 \r
1667         tFixPoint r0, g0, b0;\r
1668         tFixPoint r1, g1, b1;\r
1669 #ifdef IPOL_C0\r
1670         tFixPoint r2, g2, b2;\r
1671 #endif\r
1672         s32 i;\r
1673 \r
1674         switch (depth_func)\r
1675         {\r
1676         default:\r
1677         case ECFN_LESSEQUAL:\r
1678         for ( i = 0; i <= dx; i += SOFTWARE_DRIVER_2_STEP_X)\r
1679         {\r
1680 #ifdef CMP_W\r
1681                 if ( line.w[0] >= z[i] )\r
1682 #endif\r
1683 \r
1684                 {\r
1685 \r
1686 #ifdef WRITE_W\r
1687                         z[i] = line.w[0];\r
1688 #endif\r
1689 \r
1690 #ifdef INVERSE_W\r
1691                 iw = fix_inverse32 ( line.w[0] );\r
1692 #endif\r
1693 \r
1694                 getSample_texture ( r0, g0, b0, IT + 0, tofix ( line.t[0][0].x,iw),tofix ( line.t[0][0].y,iw) );\r
1695                 color_to_fix1 ( r1, g1, b1, dst[i] );\r
1696 \r
1697 #ifdef IPOL_C0\r
1698                 vec4_to_fix( r2, g2, b2, line.c[0][0],iw );\r
1699 \r
1700                 dst[i] = fix_to_sample( imulFix (imulFix_simple( r0, r1 ), r2 ),\r
1701                                                                 imulFix (imulFix_simple( g0, g1 ), g2 ),\r
1702                                                                 imulFix (imulFix_simple( b0, b1 ), b2 ) );\r
1703 #else\r
1704                 dst[i] = fix_to_sample(imulFix_simple( r0, r1 ),\r
1705                         imulFix_simple( g0, g1 ),\r
1706                         imulFix_simple( b0, b1 )\r
1707                                                         );\r
1708 \r
1709 #endif\r
1710 \r
1711                 }\r
1712 \r
1713 #ifdef IPOL_W\r
1714                 line.w[0] += slopeW;\r
1715 #endif\r
1716 #ifdef IPOL_T0\r
1717                 line.t[0][0] += slopeT[0];\r
1718 #endif\r
1719 #ifdef IPOL_C0\r
1720                 line.c[0][0] += slopeC[0];\r
1721 #endif\r
1722         }\r
1723         break;\r
1724 \r
1725         case 2:\r
1726         for ( i = 0; i <= dx; i += SOFTWARE_DRIVER_2_STEP_X)\r
1727         {\r
1728 #ifdef CMP_W\r
1729                 if ( line.w[0] == z[i] )\r
1730 #endif\r
1731 \r
1732                 {\r
1733 \r
1734 #ifdef WRITE_W\r
1735                         z[i] = line.w[0];\r
1736 #endif\r
1737 \r
1738 #ifdef INVERSE_W\r
1739                 iw = fix_inverse32 ( line.w[0] );\r
1740 #endif\r
1741                 getSample_texture ( r0, g0, b0, IT + 0, tofix ( line.t[0][0].x,iw),tofix ( line.t[0][0].y,iw) );\r
1742                 color_to_fix1 ( r1, g1, b1, dst[i] );\r
1743 \r
1744 #ifdef IPOL_C0\r
1745                 vec4_to_fix( r2, g2, b2, line.c[0][0],iw );\r
1746 \r
1747                 dst[i] = fix_to_sample( imulFix (imulFix_simple( r0, r1 ), r2 ),\r
1748                                                                 imulFix (imulFix_simple( g0, g1 ), g2 ),\r
1749                                                                 imulFix (imulFix_simple( b0, b1 ), b2 )\r
1750                                                         );\r
1751 #else\r
1752                 dst[i] = fix_to_sample(imulFix_simple( r0, r1 ),\r
1753                         imulFix_simple( g0, g1 ),\r
1754                         imulFix_simple( b0, b1 )\r
1755                                                         );\r
1756 \r
1757 #endif\r
1758 \r
1759                 }\r
1760 \r
1761 #ifdef IPOL_W\r
1762                 line.w[0] += slopeW;\r
1763 #endif\r
1764 #ifdef IPOL_T0\r
1765                 line.t[0][0] += slopeT[0];\r
1766 #endif\r
1767 #ifdef IPOL_C0\r
1768                 line.c[0][0] += slopeC[0];\r
1769 #endif\r
1770         }break;\r
1771         } // zcompare\r
1772 \r
1773 }\r
1774 \r
1775 /*!\r
1776 */\r
1777 void CTRTextureBlend::fragment_dst_color_one ()\r
1778 {\r
1779         tVideoSample *dst;\r
1780 \r
1781 #ifdef USE_ZBUFFER\r
1782         fp24 *z;\r
1783 #endif\r
1784 \r
1785         s32 xStart;\r
1786         s32 xEnd;\r
1787         s32 dx;\r
1788 \r
1789 \r
1790 #ifdef SUBTEXEL\r
1791         f32 subPixel;\r
1792 #endif\r
1793 \r
1794 #ifdef IPOL_Z\r
1795         f32 slopeZ;\r
1796 #endif\r
1797 #ifdef IPOL_W\r
1798         fp24 slopeW;\r
1799 #endif\r
1800 #ifdef IPOL_C0\r
1801         sVec4 slopeC[BURNING_MATERIAL_MAX_COLORS];\r
1802 #endif\r
1803 #ifdef IPOL_T0\r
1804         sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES];\r
1805 #endif\r
1806 \r
1807         // apply top-left fill-convention, left\r
1808         xStart = fill_convention_left( line.x[0] );\r
1809         xEnd = fill_convention_right( line.x[1] );\r
1810 \r
1811         dx = xEnd - xStart;\r
1812 \r
1813         if ( dx < 0 )\r
1814                 return;\r
1815 \r
1816         // slopes\r
1817         const f32 invDeltaX = fill_step_x( line.x[1] - line.x[0] );\r
1818 \r
1819 #ifdef IPOL_Z\r
1820         slopeZ = (line.z[1] - line.z[0]) * invDeltaX;\r
1821 #endif\r
1822 #ifdef IPOL_W\r
1823         slopeW = (line.w[1] - line.w[0]) * invDeltaX;\r
1824 #endif\r
1825 #ifdef IPOL_C0\r
1826         slopeC[0] = (line.c[0][1] - line.c[0][0]) * invDeltaX;\r
1827 #endif\r
1828 #ifdef IPOL_T0\r
1829         slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX;\r
1830 #endif\r
1831 #ifdef IPOL_T1\r
1832         slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX;\r
1833 #endif\r
1834 \r
1835 #ifdef SUBTEXEL\r
1836         subPixel = ( (f32) xStart ) - line.x[0];\r
1837 #ifdef IPOL_Z\r
1838         line.z[0] += slopeZ * subPixel;\r
1839 #endif\r
1840 #ifdef IPOL_W\r
1841         line.w[0] += slopeW * subPixel;\r
1842 #endif\r
1843 #ifdef IPOL_C0\r
1844         line.c[0][0] += slopeC[0] * subPixel;\r
1845 #endif\r
1846 #ifdef IPOL_T0\r
1847         line.t[0][0] += slopeT[0] * subPixel;\r
1848 #endif\r
1849 #ifdef IPOL_T1\r
1850         line.t[1][0] += slopeT[1] * subPixel;\r
1851 #endif\r
1852 #endif\r
1853 \r
1854         SOFTWARE_DRIVER_2_CLIPCHECK;\r
1855         dst = (tVideoSample*)RenderTarget->getData() + ( line.y * RenderTarget->getDimension().Width ) + xStart;\r
1856 \r
1857 #ifdef USE_ZBUFFER\r
1858         z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;\r
1859 #endif\r
1860 \r
1861 \r
1862         f32 iw = FIX_POINT_F32_MUL;\r
1863 \r
1864         tFixPoint r0, g0, b0;\r
1865         tFixPoint r1, g1, b1;\r
1866 #ifdef IPOL_C0\r
1867         tFixPoint r2, g2, b2;\r
1868 #endif\r
1869         s32 i;\r
1870 \r
1871         switch (depth_func)\r
1872         {\r
1873         default:\r
1874         case ECFN_LESSEQUAL:\r
1875         for ( i = 0; i <= dx; i += SOFTWARE_DRIVER_2_STEP_X)\r
1876         {\r
1877 #ifdef CMP_W\r
1878                 if ( line.w[0] >= z[i] )\r
1879 #endif\r
1880 \r
1881                 {\r
1882 \r
1883 #ifdef WRITE_W\r
1884                         z[i] = line.w[0];\r
1885 #endif\r
1886 \r
1887 #ifdef INVERSE_W\r
1888                 iw = fix_inverse32 ( line.w[0] );\r
1889 #endif\r
1890 \r
1891                 getSample_texture ( r0, g0, b0, IT + 0, tofix ( line.t[0][0].x,iw),tofix ( line.t[0][0].y,iw) );\r
1892                 color_to_fix ( r1, g1, b1, dst[i] );\r
1893 #ifdef IPOL_C0\r
1894                 vec4_to_fix( r2, g2, b2, line.c[0][0],iw );\r
1895 \r
1896                 dst[i] = fix_to_sample( clampfix_maxcolor ( imulFix_tex1 ( r0, r1 ) + r1 ),\r
1897                                                                 clampfix_maxcolor ( imulFix_tex1 ( g0, g1 ) + g1 ),\r
1898                                                                 clampfix_maxcolor ( imulFix_tex1 ( b0, b1 ) + b1 )\r
1899                                                         );\r
1900 \r
1901 #else\r
1902                 dst[i] = fix_to_sample( clampfix_maxcolor ( imulFix_tex1 ( r0, r1 ) + r1 ),\r
1903                                                                 clampfix_maxcolor ( imulFix_tex1 ( g0, g1 ) + g1 ),\r
1904                                                                 clampfix_maxcolor ( imulFix_tex1 ( b0, b1 ) + b1 )\r
1905                                                         );\r
1906 \r
1907 #endif\r
1908 \r
1909                 }\r
1910 \r
1911 #ifdef IPOL_W\r
1912                 line.w[0] += slopeW;\r
1913 #endif\r
1914 #ifdef IPOL_T0\r
1915                 line.t[0][0] += slopeT[0];\r
1916 #endif\r
1917 #ifdef IPOL_C0\r
1918                 line.c[0][0] += slopeC[0];\r
1919 #endif\r
1920         }\r
1921         break;\r
1922 \r
1923         case 2:\r
1924         for ( i = 0; i <= dx; i += SOFTWARE_DRIVER_2_STEP_X)\r
1925         {\r
1926 #ifdef CMP_W\r
1927                 if ( line.w[0] == z[i] )\r
1928 #endif\r
1929 \r
1930                 {\r
1931 \r
1932 #ifdef WRITE_W\r
1933                         z[i] = line.w[0];\r
1934 #endif\r
1935 \r
1936 #ifdef INVERSE_W\r
1937                 iw = fix_inverse32 ( line.w[0] );\r
1938 #endif\r
1939                 getSample_texture ( r0, g0, b0, IT + 0, tofix ( line.t[0][0].x,iw),tofix ( line.t[0][0].y,iw) );\r
1940                 color_to_fix ( r1, g1, b1, dst[i] );\r
1941 \r
1942 #ifdef IPOL_C0\r
1943                 vec4_to_fix( r2, g2, b2, line.c[0][0],iw );\r
1944 \r
1945                 dst[i] = fix_to_sample( clampfix_maxcolor ( imulFix_tex1 ( r0, r1 ) + r1 ),\r
1946                                                                 clampfix_maxcolor ( imulFix_tex1 ( g0, g1 ) + g1 ),\r
1947                                                                 clampfix_maxcolor ( imulFix_tex1 ( b0, b1 ) + b1 )\r
1948                                                         );\r
1949 \r
1950 #else\r
1951                 dst[i] = fix_to_sample( clampfix_maxcolor ( imulFix_tex1 ( r0, r1 ) + r1 ),\r
1952                                                                 clampfix_maxcolor ( imulFix_tex1 ( g0, g1 ) + g1 ),\r
1953                                                                 clampfix_maxcolor ( imulFix_tex1 ( b0, b1 ) + b1 )\r
1954                                                         );\r
1955 \r
1956 #endif\r
1957 \r
1958 \r
1959                 }\r
1960 \r
1961 #ifdef IPOL_W\r
1962                 line.w[0] += slopeW;\r
1963 #endif\r
1964 #ifdef IPOL_T0\r
1965                 line.t[0][0] += slopeT[0];\r
1966 #endif\r
1967 #ifdef IPOL_C0\r
1968                 line.c[0][0] += slopeC[0];\r
1969 #endif\r
1970         }break;\r
1971         } // zcompare\r
1972 \r
1973 }\r
1974 \r
1975 /*!\r
1976 */\r
1977 void CTRTextureBlend::fragment_zero_one_minus_scr_color ()\r
1978 {\r
1979         tVideoSample *dst;\r
1980 \r
1981 #ifdef USE_ZBUFFER\r
1982         fp24 *z;\r
1983 #endif\r
1984 \r
1985         s32 xStart;\r
1986         s32 xEnd;\r
1987         s32 dx;\r
1988 \r
1989 \r
1990 #ifdef SUBTEXEL\r
1991         f32 subPixel;\r
1992 #endif\r
1993 \r
1994 #ifdef IPOL_Z\r
1995         f32 slopeZ;\r
1996 #endif\r
1997 #ifdef IPOL_W\r
1998         fp24 slopeW;\r
1999 #endif\r
2000 #ifdef IPOL_C0\r
2001         sVec4 slopeC[BURNING_MATERIAL_MAX_COLORS];\r
2002 #endif\r
2003 #ifdef IPOL_T0\r
2004         sVec2 slopeT[BURNING_MATERIAL_MAX_TEXTURES];\r
2005 #endif\r
2006 \r
2007         // apply top-left fill-convention, left\r
2008         xStart = fill_convention_left( line.x[0] );\r
2009         xEnd = fill_convention_right( line.x[1] );\r
2010 \r
2011         dx = xEnd - xStart;\r
2012 \r
2013         if ( dx < 0 )\r
2014                 return;\r
2015 \r
2016         // slopes\r
2017         const f32 invDeltaX = fill_step_x( line.x[1] - line.x[0] );\r
2018 \r
2019 #ifdef IPOL_Z\r
2020         slopeZ = (line.z[1] - line.z[0]) * invDeltaX;\r
2021 #endif\r
2022 #ifdef IPOL_W\r
2023         slopeW = (line.w[1] - line.w[0]) * invDeltaX;\r
2024 #endif\r
2025 #ifdef IPOL_C0\r
2026         slopeC[0] = (line.c[0][1] - line.c[0][0]) * invDeltaX;\r
2027 #endif\r
2028 #ifdef IPOL_T0\r
2029         slopeT[0] = (line.t[0][1] - line.t[0][0]) * invDeltaX;\r
2030 #endif\r
2031 #ifdef IPOL_T1\r
2032         slopeT[1] = (line.t[1][1] - line.t[1][0]) * invDeltaX;\r
2033 #endif\r
2034 \r
2035 #ifdef SUBTEXEL\r
2036         subPixel = ( (f32) xStart ) - line.x[0];\r
2037 #ifdef IPOL_Z\r
2038         line.z[0] += slopeZ * subPixel;\r
2039 #endif\r
2040 #ifdef IPOL_W\r
2041         line.w[0] += slopeW * subPixel;\r
2042 #endif\r
2043 #ifdef IPOL_C0\r
2044         line.c[0][0] += slopeC[0] * subPixel;\r
2045 #endif\r
2046 #ifdef IPOL_T0\r
2047         line.t[0][0] += slopeT[0] * subPixel;\r
2048 #endif\r
2049 #ifdef IPOL_T1\r
2050         line.t[1][0] += slopeT[1] * subPixel;\r
2051 #endif\r
2052 #endif\r
2053 \r
2054         SOFTWARE_DRIVER_2_CLIPCHECK;\r
2055         dst = (tVideoSample*)RenderTarget->getData() + ( line.y * RenderTarget->getDimension().Width ) + xStart;\r
2056 \r
2057 #ifdef USE_ZBUFFER\r
2058         z = (fp24*) DepthBuffer->lock() + ( line.y * RenderTarget->getDimension().Width ) + xStart;\r
2059 #endif\r
2060 \r
2061 \r
2062         f32 iw = FIX_POINT_F32_MUL;\r
2063 \r
2064         tFixPoint r0, g0, b0;\r
2065         tFixPoint r1, g1, b1;\r
2066 #ifdef IPOL_C0\r
2067         tFixPoint r2, g2, b2;\r
2068 #endif\r
2069         s32 i;\r
2070 \r
2071         switch (depth_func)\r
2072         {\r
2073         default:\r
2074         case ECFN_LESSEQUAL:\r
2075         for ( i = 0; i <= dx; i += SOFTWARE_DRIVER_2_STEP_X)\r
2076         {\r
2077 #ifdef CMP_W\r
2078                 if ( line.w[0] >= z[i] )\r
2079 #endif\r
2080 \r
2081                 {\r
2082 \r
2083 #ifdef WRITE_W\r
2084                         z[i] = line.w[0];\r
2085 #endif\r
2086 \r
2087 #ifdef INVERSE_W\r
2088                 iw = fix_inverse32 ( line.w[0] );\r
2089 #endif\r
2090 \r
2091                 getSample_texture ( r0, g0, b0, IT + 0, tofix ( line.t[0][0].x,iw),tofix ( line.t[0][0].y,iw) );\r
2092                 color_to_fix1 ( r1, g1, b1, dst[i] );\r
2093 #ifdef IPOL_C0\r
2094                 vec4_to_fix( r2, g2, b2, line.c[0][0],iw );\r
2095 \r
2096                 dst[i] = fix_to_sample(imulFix( FIX_POINT_ONE - r0, r1 ),\r
2097                         imulFix( FIX_POINT_ONE - g0, g1 ),\r
2098                         imulFix( FIX_POINT_ONE - b0, b1 )\r
2099                                                         );\r
2100 \r
2101 #else\r
2102                 dst[i] = fix_to_sample(imulFix( FIX_POINT_ONE - r0, r1 ),\r
2103                         imulFix( FIX_POINT_ONE - g0, g1 ),\r
2104                         imulFix( FIX_POINT_ONE - b0, b1 )\r
2105                                                         );\r
2106 \r
2107 #endif\r
2108 \r
2109                 }\r
2110 \r
2111 #ifdef IPOL_W\r
2112                 line.w[0] += slopeW;\r
2113 #endif\r
2114 #ifdef IPOL_T0\r
2115                 line.t[0][0] += slopeT[0];\r
2116 #endif\r
2117 #ifdef IPOL_C0\r
2118                 line.c[0][0] += slopeC[0];\r
2119 #endif\r
2120         }\r
2121         break;\r
2122 \r
2123         case 2:\r
2124         for ( i = 0; i <= dx; i += SOFTWARE_DRIVER_2_STEP_X)\r
2125         {\r
2126 #ifdef CMP_W\r
2127                 if ( line.w[0] == z[i] )\r
2128 #endif\r
2129 \r
2130                 {\r
2131 \r
2132 #ifdef WRITE_W\r
2133                         z[i] = line.w[0];\r
2134 #endif\r
2135 \r
2136 #ifdef INVERSE_W\r
2137                 iw = fix_inverse32 ( line.w[0] );\r
2138 #endif\r
2139                 getSample_texture ( r0, g0, b0, IT + 0, tofix ( line.t[0][0].x,iw),tofix ( line.t[0][0].y,iw) );\r
2140                 color_to_fix1 ( r1, g1, b1, dst[i] );\r
2141 #ifdef IPOL_C0\r
2142                 vec4_to_fix( r2, g2, b2, line.c[0][0],iw );\r
2143 \r
2144                 dst[i] = fix_to_sample(imulFix( FIX_POINT_ONE - r0, r1 ),\r
2145                         imulFix( FIX_POINT_ONE - g0, g1 ),\r
2146                         imulFix( FIX_POINT_ONE - b0, b1 )\r
2147                                                         );\r
2148 \r
2149 #else\r
2150                 dst[i] = fix_to_sample(imulFix( FIX_POINT_ONE - r0, r1 ),\r
2151                         imulFix( FIX_POINT_ONE - g0, g1 ),\r
2152                         imulFix( FIX_POINT_ONE - b0, b1 )\r
2153                                                         );\r
2154 \r
2155 #endif\r
2156 \r
2157                 }\r
2158 \r
2159 #ifdef IPOL_W\r
2160                 line.w[0] += slopeW;\r
2161 #endif\r
2162 #ifdef IPOL_T0\r
2163                 line.t[0][0] += slopeT[0];\r
2164 #endif\r
2165 #ifdef IPOL_C0\r
2166                 line.c[0][0] += slopeC[0];\r
2167 #endif\r
2168         }break;\r
2169         } // zcompare\r
2170 \r
2171 }\r
2172 \r
2173 \r
2174 \r
2175 void CTRTextureBlend::drawTriangle(const s4DVertex* burning_restrict a, const s4DVertex* burning_restrict b, const s4DVertex* burning_restrict c)\r
2176 {\r
2177         if ( 0 == fragmentShader )\r
2178                 return;\r
2179 \r
2180         // sort on height, y\r
2181         if ( F32_A_GREATER_B ( a->Pos.y , b->Pos.y ) ) swapVertexPointer(&a, &b);\r
2182         if ( F32_A_GREATER_B ( b->Pos.y , c->Pos.y ) ) swapVertexPointer(&b, &c);\r
2183         if ( F32_A_GREATER_B ( a->Pos.y , b->Pos.y ) ) swapVertexPointer(&a, &b);\r
2184 \r
2185         const f32 ca = c->Pos.y - a->Pos.y;\r
2186         const f32 ba = b->Pos.y - a->Pos.y;\r
2187         const f32 cb = c->Pos.y - b->Pos.y;\r
2188         // calculate delta y of the edges\r
2189         scan.invDeltaY[0] = fill_step_y( ca );\r
2190         scan.invDeltaY[1] = fill_step_y( ba );\r
2191         scan.invDeltaY[2] = fill_step_y( cb );\r
2192 \r
2193         if ( F32_LOWER_EQUAL_0 ( scan.invDeltaY[0] ) )\r
2194                 return;\r
2195 \r
2196         // find if the major edge is left or right aligned\r
2197         f32 temp[4];\r
2198 \r
2199         temp[0] = a->Pos.x - c->Pos.x;\r
2200         temp[1] = -ca;\r
2201         temp[2] = b->Pos.x - a->Pos.x;\r
2202         temp[3] = ba;\r
2203 \r
2204         scan.left = ( temp[0] * temp[3] - temp[1] * temp[2] ) > 0.f ? 0 : 1;\r
2205         scan.right = 1 - scan.left;\r
2206 \r
2207         // calculate slopes for the major edge\r
2208         scan.slopeX[0] = (c->Pos.x - a->Pos.x) * scan.invDeltaY[0];\r
2209         scan.x[0] = a->Pos.x;\r
2210 \r
2211 #ifdef IPOL_Z\r
2212         scan.slopeZ[0] = (c->Pos.z - a->Pos.z) * scan.invDeltaY[0];\r
2213         scan.z[0] = a->Pos.z;\r
2214 #endif\r
2215 \r
2216 #ifdef IPOL_W\r
2217         scan.slopeW[0] = (c->Pos.w - a->Pos.w) * scan.invDeltaY[0];\r
2218         scan.w[0] = a->Pos.w;\r
2219 #endif\r
2220 \r
2221 #ifdef IPOL_C0\r
2222         scan.slopeC[0][0] = (c->Color[0] - a->Color[0]) * scan.invDeltaY[0];\r
2223         scan.c[0][0] = a->Color[0];\r
2224 #endif\r
2225 \r
2226 #ifdef IPOL_T0\r
2227         scan.slopeT[0][0] = (c->Tex[0] - a->Tex[0]) * scan.invDeltaY[0];\r
2228         scan.t[0][0] = a->Tex[0];\r
2229 #endif\r
2230 \r
2231 #ifdef IPOL_T1\r
2232         scan.slopeT[1][0] = (c->Tex[1] - a->Tex[1]) * scan.invDeltaY[0];\r
2233         scan.t[1][0] = a->Tex[1];\r
2234 #endif\r
2235 \r
2236         // top left fill convention y run\r
2237         s32 yStart;\r
2238         s32 yEnd;\r
2239 \r
2240 #ifdef SUBTEXEL\r
2241         f32 subPixel;\r
2242 #endif\r
2243 \r
2244         // rasterize upper sub-triangle\r
2245         if ( (f32) 0.0 != scan.invDeltaY[1]  )\r
2246         {\r
2247                 // calculate slopes for top edge\r
2248                 scan.slopeX[1] = (b->Pos.x - a->Pos.x) * scan.invDeltaY[1];\r
2249                 scan.x[1] = a->Pos.x;\r
2250 \r
2251 #ifdef IPOL_Z\r
2252                 scan.slopeZ[1] = (b->Pos.z - a->Pos.z) * scan.invDeltaY[1];\r
2253                 scan.z[1] = a->Pos.z;\r
2254 #endif\r
2255 \r
2256 #ifdef IPOL_W\r
2257                 scan.slopeW[1] = (b->Pos.w - a->Pos.w) * scan.invDeltaY[1];\r
2258                 scan.w[1] = a->Pos.w;\r
2259 #endif\r
2260 \r
2261 #ifdef IPOL_C0\r
2262                 scan.slopeC[0][1] = (b->Color[0] - a->Color[0]) * scan.invDeltaY[1];\r
2263                 scan.c[0][1] = a->Color[0];\r
2264 #endif\r
2265 \r
2266 #ifdef IPOL_T0\r
2267                 scan.slopeT[0][1] = (b->Tex[0] - a->Tex[0]) * scan.invDeltaY[1];\r
2268                 scan.t[0][1] = a->Tex[0];\r
2269 #endif\r
2270 \r
2271 #ifdef IPOL_T1\r
2272                 scan.slopeT[1][1] = (b->Tex[1] - a->Tex[1]) * scan.invDeltaY[1];\r
2273                 scan.t[1][1] = a->Tex[1];\r
2274 #endif\r
2275 \r
2276                 // apply top-left fill convention, top part\r
2277                 yStart = fill_convention_left( a->Pos.y );\r
2278                 yEnd = fill_convention_right( b->Pos.y );\r
2279 \r
2280 #ifdef SUBTEXEL\r
2281                 subPixel = ( (f32) yStart ) - a->Pos.y;\r
2282 \r
2283                 // correct to pixel center\r
2284                 scan.x[0] += scan.slopeX[0] * subPixel;\r
2285                 scan.x[1] += scan.slopeX[1] * subPixel;\r
2286 \r
2287 #ifdef IPOL_Z\r
2288                 scan.z[0] += scan.slopeZ[0] * subPixel;\r
2289                 scan.z[1] += scan.slopeZ[1] * subPixel;\r
2290 #endif\r
2291 \r
2292 #ifdef IPOL_W\r
2293                 scan.w[0] += scan.slopeW[0] * subPixel;\r
2294                 scan.w[1] += scan.slopeW[1] * subPixel;\r
2295 #endif\r
2296 \r
2297 #ifdef IPOL_C0\r
2298                 scan.c[0][0] += scan.slopeC[0][0] * subPixel;\r
2299                 scan.c[0][1] += scan.slopeC[0][1] * subPixel;\r
2300 #endif\r
2301 \r
2302 #ifdef IPOL_T0\r
2303                 scan.t[0][0] += scan.slopeT[0][0] * subPixel;\r
2304                 scan.t[0][1] += scan.slopeT[0][1] * subPixel;\r
2305 #endif\r
2306 \r
2307 #ifdef IPOL_T1\r
2308                 scan.t[1][0] += scan.slopeT[1][0] * subPixel;\r
2309                 scan.t[1][1] += scan.slopeT[1][1] * subPixel;\r
2310 #endif\r
2311 \r
2312 #endif\r
2313 \r
2314                 // rasterize the edge scanlines\r
2315                 for( line.y = yStart; line.y <= yEnd; line.y += SOFTWARE_DRIVER_2_STEP_Y)\r
2316                 {\r
2317                         line.x[scan.left] = scan.x[0];\r
2318                         line.x[scan.right] = scan.x[1];\r
2319 \r
2320 #ifdef IPOL_Z\r
2321                         line.z[scan.left] = scan.z[0];\r
2322                         line.z[scan.right] = scan.z[1];\r
2323 #endif\r
2324 \r
2325 #ifdef IPOL_W\r
2326                         line.w[scan.left] = scan.w[0];\r
2327                         line.w[scan.right] = scan.w[1];\r
2328 #endif\r
2329 \r
2330 #ifdef IPOL_C0\r
2331                         line.c[0][scan.left] = scan.c[0][0];\r
2332                         line.c[0][scan.right] = scan.c[0][1];\r
2333 #endif\r
2334 \r
2335 #ifdef IPOL_T0\r
2336                         line.t[0][scan.left] = scan.t[0][0];\r
2337                         line.t[0][scan.right] = scan.t[0][1];\r
2338 #endif\r
2339 \r
2340 #ifdef IPOL_T1\r
2341                         line.t[1][scan.left] = scan.t[1][0];\r
2342                         line.t[1][scan.right] = scan.t[1][1];\r
2343 #endif\r
2344 \r
2345                         // render a scanline\r
2346                         interlace_scanline (this->*fragmentShader) ();\r
2347 \r
2348                         scan.x[0] += scan.slopeX[0];\r
2349                         scan.x[1] += scan.slopeX[1];\r
2350 \r
2351 #ifdef IPOL_Z\r
2352                         scan.z[0] += scan.slopeZ[0];\r
2353                         scan.z[1] += scan.slopeZ[1];\r
2354 #endif\r
2355 \r
2356 #ifdef IPOL_W\r
2357                         scan.w[0] += scan.slopeW[0];\r
2358                         scan.w[1] += scan.slopeW[1];\r
2359 #endif\r
2360 \r
2361 #ifdef IPOL_C0\r
2362                         scan.c[0][0] += scan.slopeC[0][0];\r
2363                         scan.c[0][1] += scan.slopeC[0][1];\r
2364 #endif\r
2365 \r
2366 #ifdef IPOL_T0\r
2367                         scan.t[0][0] += scan.slopeT[0][0];\r
2368                         scan.t[0][1] += scan.slopeT[0][1];\r
2369 #endif\r
2370 \r
2371 #ifdef IPOL_T1\r
2372                         scan.t[1][0] += scan.slopeT[1][0];\r
2373                         scan.t[1][1] += scan.slopeT[1][1];\r
2374 #endif\r
2375 \r
2376                 }\r
2377         }\r
2378 \r
2379         // rasterize lower sub-triangle\r
2380         if ( (f32) 0.0 != scan.invDeltaY[2] )\r
2381         {\r
2382                 // advance to middle point\r
2383                 if( (f32) 0.0 != scan.invDeltaY[1] )\r
2384                 {\r
2385                         temp[0] = b->Pos.y - a->Pos.y;  // dy\r
2386 \r
2387                         scan.x[0] = a->Pos.x + scan.slopeX[0] * temp[0];\r
2388 #ifdef IPOL_Z\r
2389                         scan.z[0] = a->Pos.z + scan.slopeZ[0] * temp[0];\r
2390 #endif\r
2391 #ifdef IPOL_W\r
2392                         scan.w[0] = a->Pos.w + scan.slopeW[0] * temp[0];\r
2393 #endif\r
2394 #ifdef IPOL_C0\r
2395                         scan.c[0][0] = a->Color[0] + scan.slopeC[0][0] * temp[0];\r
2396 #endif\r
2397 #ifdef IPOL_T0\r
2398                         scan.t[0][0] = a->Tex[0] + scan.slopeT[0][0] * temp[0];\r
2399 #endif\r
2400 #ifdef IPOL_T1\r
2401                         scan.t[1][0] = a->Tex[1] + scan.slopeT[1][0] * temp[0];\r
2402 #endif\r
2403 \r
2404                 }\r
2405 \r
2406                 // calculate slopes for bottom edge\r
2407                 scan.slopeX[1] = (c->Pos.x - b->Pos.x) * scan.invDeltaY[2];\r
2408                 scan.x[1] = b->Pos.x;\r
2409 \r
2410 #ifdef IPOL_Z\r
2411                 scan.slopeZ[1] = (c->Pos.z - b->Pos.z) * scan.invDeltaY[2];\r
2412                 scan.z[1] = b->Pos.z;\r
2413 #endif\r
2414 \r
2415 #ifdef IPOL_W\r
2416                 scan.slopeW[1] = (c->Pos.w - b->Pos.w) * scan.invDeltaY[2];\r
2417                 scan.w[1] = b->Pos.w;\r
2418 #endif\r
2419 \r
2420 #ifdef IPOL_C0\r
2421                 scan.slopeC[0][1] = (c->Color[0] - b->Color[0]) * scan.invDeltaY[2];\r
2422                 scan.c[0][1] = b->Color[0];\r
2423 #endif\r
2424 \r
2425 #ifdef IPOL_T0\r
2426                 scan.slopeT[0][1] = (c->Tex[0] - b->Tex[0]) * scan.invDeltaY[2];\r
2427                 scan.t[0][1] = b->Tex[0];\r
2428 #endif\r
2429 \r
2430 #ifdef IPOL_T1\r
2431                 scan.slopeT[1][1] = (c->Tex[1] - b->Tex[1]) * scan.invDeltaY[2];\r
2432                 scan.t[1][1] = b->Tex[1];\r
2433 #endif\r
2434 \r
2435                 // apply top-left fill convention, top part\r
2436                 yStart = fill_convention_left( b->Pos.y );\r
2437                 yEnd = fill_convention_right( c->Pos.y );\r
2438 \r
2439 #ifdef SUBTEXEL\r
2440                 subPixel = ( (f32) yStart ) - b->Pos.y;\r
2441 \r
2442                 // correct to pixel center\r
2443                 scan.x[0] += scan.slopeX[0] * subPixel;\r
2444                 scan.x[1] += scan.slopeX[1] * subPixel;\r
2445 \r
2446 #ifdef IPOL_Z\r
2447                 scan.z[0] += scan.slopeZ[0] * subPixel;\r
2448                 scan.z[1] += scan.slopeZ[1] * subPixel;\r
2449 #endif\r
2450 \r
2451 #ifdef IPOL_W\r
2452                 scan.w[0] += scan.slopeW[0] * subPixel;\r
2453                 scan.w[1] += scan.slopeW[1] * subPixel;\r
2454 #endif\r
2455 \r
2456 #ifdef IPOL_C0\r
2457                 scan.c[0][0] += scan.slopeC[0][0] * subPixel;\r
2458                 scan.c[0][1] += scan.slopeC[0][1] * subPixel;\r
2459 #endif\r
2460 \r
2461 #ifdef IPOL_T0\r
2462                 scan.t[0][0] += scan.slopeT[0][0] * subPixel;\r
2463                 scan.t[0][1] += scan.slopeT[0][1] * subPixel;\r
2464 #endif\r
2465 \r
2466 #ifdef IPOL_T1\r
2467                 scan.t[1][0] += scan.slopeT[1][0] * subPixel;\r
2468                 scan.t[1][1] += scan.slopeT[1][1] * subPixel;\r
2469 #endif\r
2470 \r
2471 #endif\r
2472 \r
2473                 // rasterize the edge scanlines\r
2474                 for( line.y = yStart; line.y <= yEnd; line.y += SOFTWARE_DRIVER_2_STEP_Y)\r
2475                 {\r
2476                         line.x[scan.left] = scan.x[0];\r
2477                         line.x[scan.right] = scan.x[1];\r
2478 \r
2479 #ifdef IPOL_Z\r
2480                         line.z[scan.left] = scan.z[0];\r
2481                         line.z[scan.right] = scan.z[1];\r
2482 #endif\r
2483 \r
2484 #ifdef IPOL_W\r
2485                         line.w[scan.left] = scan.w[0];\r
2486                         line.w[scan.right] = scan.w[1];\r
2487 #endif\r
2488 \r
2489 #ifdef IPOL_C0\r
2490                         line.c[0][scan.left] = scan.c[0][0];\r
2491                         line.c[0][scan.right] = scan.c[0][1];\r
2492 #endif\r
2493 \r
2494 #ifdef IPOL_T0\r
2495                         line.t[0][scan.left] = scan.t[0][0];\r
2496                         line.t[0][scan.right] = scan.t[0][1];\r
2497 #endif\r
2498 \r
2499 #ifdef IPOL_T1\r
2500                         line.t[1][scan.left] = scan.t[1][0];\r
2501                         line.t[1][scan.right] = scan.t[1][1];\r
2502 #endif\r
2503 \r
2504                         // render a scanline\r
2505                         interlace_scanline (this->*fragmentShader) ();\r
2506 \r
2507                         scan.x[0] += scan.slopeX[0];\r
2508                         scan.x[1] += scan.slopeX[1];\r
2509 \r
2510 #ifdef IPOL_Z\r
2511                         scan.z[0] += scan.slopeZ[0];\r
2512                         scan.z[1] += scan.slopeZ[1];\r
2513 #endif\r
2514 \r
2515 #ifdef IPOL_W\r
2516                         scan.w[0] += scan.slopeW[0];\r
2517                         scan.w[1] += scan.slopeW[1];\r
2518 #endif\r
2519 \r
2520 #ifdef IPOL_C0\r
2521                         scan.c[0][0] += scan.slopeC[0][0];\r
2522                         scan.c[0][1] += scan.slopeC[0][1];\r
2523 #endif\r
2524 \r
2525 #ifdef IPOL_T0\r
2526                         scan.t[0][0] += scan.slopeT[0][0];\r
2527                         scan.t[0][1] += scan.slopeT[0][1];\r
2528 #endif\r
2529 \r
2530 #ifdef IPOL_T1\r
2531                         scan.t[1][0] += scan.slopeT[1][0];\r
2532                         scan.t[1][1] += scan.slopeT[1][1];\r
2533 #endif\r
2534 \r
2535                 }\r
2536         }\r
2537 \r
2538 }\r
2539 \r
2540 \r
2541 \r
2542 } // end namespace video\r
2543 } // end namespace irr\r
2544 \r
2545 #endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_\r
2546 \r
2547 namespace irr\r
2548 {\r
2549 namespace video\r
2550 {\r
2551 \r
2552 //! creates a flat triangle renderer\r
2553 IBurningShader* createTRTextureBlend(CBurningVideoDriver* driver)\r
2554 {\r
2555         // EMT_ONETEXTURE_BLEND\r
2556         #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_\r
2557         return new CTRTextureBlend(driver);\r
2558         #else\r
2559         return 0;\r
2560         #endif // _IRR_COMPILE_WITH_BURNINGSVIDEO_\r
2561 }\r
2562 \r
2563 \r
2564 } // end namespace video\r
2565 } // end namespace irr\r
2566 \r
2567 \r