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