Panda3D
|
00001 static void 00002 FNAME(white_untextured) (ZBuffer *zb, 00003 ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2) 00004 { 00005 #define INTERP_Z 00006 00007 #define EARLY_OUT() \ 00008 { \ 00009 } 00010 00011 #define DRAW_INIT() \ 00012 { \ 00013 } 00014 00015 #define PUT_PIXEL(_a) \ 00016 { \ 00017 zz=z >> ZB_POINT_Z_FRAC_BITS; \ 00018 if (ZCMP(pz[_a], zz)) { \ 00019 STORE_PIX(pp[_a], 0xffffffffUL, 0xffffUL, 0xffffUL, 0xffffUL, 0xffffUL); \ 00020 STORE_Z(pz[_a], zz); \ 00021 } \ 00022 z+=dzdx; \ 00023 } 00024 00025 #define PIXEL_COUNT pixel_count_white_untextured 00026 00027 #include "ztriangle.h" 00028 } 00029 00030 static void 00031 FNAME(flat_untextured) (ZBuffer *zb, 00032 ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2) 00033 { 00034 int color; 00035 int or0, og0, ob0, oa0; 00036 00037 #define INTERP_Z 00038 00039 #define EARLY_OUT() \ 00040 { \ 00041 } 00042 00043 #define DRAW_INIT() \ 00044 { \ 00045 if (!ACMP(zb, p2->a)) { \ 00046 return; \ 00047 } \ 00048 or0 = p2->r; \ 00049 og0 = p2->g; \ 00050 ob0 = p2->b; \ 00051 oa0 = p2->a; \ 00052 color=RGBA_TO_PIXEL(or0, og0, ob0, oa0); \ 00053 } 00054 00055 #define PUT_PIXEL(_a) \ 00056 { \ 00057 zz=z >> ZB_POINT_Z_FRAC_BITS; \ 00058 if (ZCMP(pz[_a], zz)) { \ 00059 STORE_PIX(pp[_a], color, or0, og0, ob0, oa0); \ 00060 STORE_Z(pz[_a], zz); \ 00061 } \ 00062 z+=dzdx; \ 00063 } 00064 00065 #define PIXEL_COUNT pixel_count_flat_untextured 00066 00067 #include "ztriangle.h" 00068 } 00069 00070 /* 00071 * Smooth filled triangle. 00072 * The code below is very tricky :) 00073 */ 00074 00075 static void 00076 FNAME(smooth_untextured) (ZBuffer *zb, 00077 ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2) 00078 { 00079 #define INTERP_Z 00080 #define INTERP_RGB 00081 00082 #define EARLY_OUT() \ 00083 { \ 00084 int c0, c1, c2; \ 00085 c0 = RGBA_TO_PIXEL(p0->r, p0->g, p0->b, p0->a); \ 00086 c1 = RGBA_TO_PIXEL(p1->r, p1->g, p1->b, p1->a); \ 00087 c2 = RGBA_TO_PIXEL(p2->r, p2->g, p2->b, p2->a); \ 00088 if (c0 == c1 && c0 == c2) { \ 00089 /* It's really a flat-shaded triangle. */ \ 00090 FNAME(flat_untextured)(zb, p0, p1, p2); \ 00091 return; \ 00092 } \ 00093 } 00094 00095 #define DRAW_INIT() \ 00096 { \ 00097 } 00098 00099 #define PUT_PIXEL(_a) \ 00100 { \ 00101 zz=z >> ZB_POINT_Z_FRAC_BITS; \ 00102 if (ZCMP(pz[_a], zz)) { \ 00103 if (ACMP(zb, oa1)) { \ 00104 STORE_PIX(pp[_a], RGBA_TO_PIXEL(or1, og1, ob1, oa1), or1, og1, ob1, oa1); \ 00105 STORE_Z(pz[_a], zz); \ 00106 } \ 00107 } \ 00108 z+=dzdx; \ 00109 og1+=dgdx; \ 00110 or1+=drdx; \ 00111 ob1+=dbdx; \ 00112 oa1+=dadx; \ 00113 } 00114 00115 #define PIXEL_COUNT pixel_count_smooth_untextured 00116 00117 #include "ztriangle.h" 00118 } 00119 00120 static void 00121 FNAME(white_textured) (ZBuffer *zb, 00122 ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2) 00123 { 00124 ZTextureDef *texture_def; 00125 00126 #define INTERP_Z 00127 #define INTERP_ST 00128 00129 #define EARLY_OUT() \ 00130 { \ 00131 } 00132 00133 #define DRAW_INIT() \ 00134 { \ 00135 texture_def = &zb->current_textures[0]; \ 00136 } 00137 00138 #define PUT_PIXEL(_a) \ 00139 { \ 00140 zz=z >> ZB_POINT_Z_FRAC_BITS; \ 00141 if (ZCMP(pz[_a], zz)) { \ 00142 tmp = ZB_LOOKUP_TEXTURE(texture_def, s, t, mipmap_level, mipmap_dx); \ 00143 if (ACMP(zb, PIXEL_A(tmp))) { \ 00144 STORE_PIX(pp[_a], tmp, PIXEL_R(tmp), PIXEL_G(tmp), PIXEL_B(tmp), PIXEL_A(tmp)); \ 00145 STORE_Z(pz[_a], zz); \ 00146 } \ 00147 } \ 00148 z+=dzdx; \ 00149 s+=dsdx; \ 00150 t+=dtdx; \ 00151 } 00152 00153 #define PIXEL_COUNT pixel_count_white_textured 00154 00155 #include "ztriangle.h" 00156 } 00157 00158 static void 00159 FNAME(flat_textured) (ZBuffer *zb, 00160 ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2) 00161 { 00162 ZTextureDef *texture_def; 00163 int or0, og0, ob0, oa0; 00164 00165 #define INTERP_Z 00166 #define INTERP_ST 00167 00168 #define EARLY_OUT() \ 00169 { \ 00170 } 00171 00172 #define DRAW_INIT() \ 00173 { \ 00174 if (p2->a == 0 && !ACMP(zb, p2->a)) { \ 00175 /* This alpha is zero, and we'll never get other than 0. */ \ 00176 return; \ 00177 } \ 00178 texture_def = &zb->current_textures[0]; \ 00179 or0 = p2->r; \ 00180 og0 = p2->g; \ 00181 ob0 = p2->b; \ 00182 oa0 = p2->a; \ 00183 } 00184 00185 #define PUT_PIXEL(_a) \ 00186 { \ 00187 zz=z >> ZB_POINT_Z_FRAC_BITS; \ 00188 if (ZCMP(pz[_a], zz)) { \ 00189 tmp = ZB_LOOKUP_TEXTURE(texture_def, s, t, mipmap_level, mipmap_dx); \ 00190 int a = PALPHA_MULT(oa0, PIXEL_A(tmp)); \ 00191 if (ACMP(zb, a)) { \ 00192 STORE_PIX(pp[_a], \ 00193 RGBA_TO_PIXEL(PCOMPONENT_MULT(or0, PIXEL_R(tmp)), \ 00194 PCOMPONENT_MULT(og0, PIXEL_G(tmp)), \ 00195 PCOMPONENT_MULT(ob0, PIXEL_B(tmp)), \ 00196 a), \ 00197 PCOMPONENT_MULT(or0, PIXEL_R(tmp)), \ 00198 PCOMPONENT_MULT(og0, PIXEL_G(tmp)), \ 00199 PCOMPONENT_MULT(ob0, PIXEL_B(tmp)), \ 00200 a); \ 00201 STORE_Z(pz[_a], zz); \ 00202 } \ 00203 } \ 00204 z+=dzdx; \ 00205 s+=dsdx; \ 00206 t+=dtdx; \ 00207 } 00208 00209 #define PIXEL_COUNT pixel_count_flat_textured 00210 00211 #include "ztriangle.h" 00212 } 00213 00214 static void 00215 FNAME(smooth_textured) (ZBuffer *zb, 00216 ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2) 00217 { 00218 ZTextureDef *texture_def; 00219 00220 #define INTERP_Z 00221 #define INTERP_ST 00222 #define INTERP_RGB 00223 00224 #define EARLY_OUT() \ 00225 { \ 00226 int c0, c1, c2; \ 00227 c0 = RGBA_TO_PIXEL(p0->r, p0->g, p0->b, p0->a); \ 00228 c1 = RGBA_TO_PIXEL(p1->r, p1->g, p1->b, p1->a); \ 00229 c2 = RGBA_TO_PIXEL(p2->r, p2->g, p2->b, p2->a); \ 00230 if (c0 == c1 && c0 == c2) { \ 00231 /* It's really a flat-shaded triangle. */ \ 00232 if (c0 == 0xffffffff) { \ 00233 /* Actually, it's a white triangle. */ \ 00234 FNAME(white_textured)(zb, p0, p1, p2); \ 00235 return; \ 00236 } \ 00237 FNAME(flat_textured)(zb, p0, p1, p2); \ 00238 return; \ 00239 } \ 00240 } 00241 00242 #define DRAW_INIT() \ 00243 { \ 00244 texture_def = &zb->current_textures[0]; \ 00245 } 00246 00247 #define PUT_PIXEL(_a) \ 00248 { \ 00249 zz=z >> ZB_POINT_Z_FRAC_BITS; \ 00250 if (ZCMP(pz[_a], zz)) { \ 00251 tmp = ZB_LOOKUP_TEXTURE(texture_def, s, t, mipmap_level, mipmap_dx); \ 00252 int a = PALPHA_MULT(oa1, PIXEL_A(tmp)); \ 00253 if (ACMP(zb, a)) { \ 00254 STORE_PIX(pp[_a], \ 00255 RGBA_TO_PIXEL(PCOMPONENT_MULT(or1, PIXEL_R(tmp)), \ 00256 PCOMPONENT_MULT(og1, PIXEL_G(tmp)), \ 00257 PCOMPONENT_MULT(ob1, PIXEL_B(tmp)), \ 00258 a), \ 00259 PCOMPONENT_MULT(or1, PIXEL_R(tmp)), \ 00260 PCOMPONENT_MULT(og1, PIXEL_G(tmp)), \ 00261 PCOMPONENT_MULT(ob1, PIXEL_B(tmp)), \ 00262 a); \ 00263 STORE_Z(pz[_a], zz); \ 00264 } \ 00265 } \ 00266 z+=dzdx; \ 00267 og1+=dgdx; \ 00268 or1+=drdx; \ 00269 ob1+=dbdx; \ 00270 oa1+=dadx; \ 00271 s+=dsdx; \ 00272 t+=dtdx; \ 00273 } 00274 00275 #define PIXEL_COUNT pixel_count_smooth_textured 00276 00277 #include "ztriangle.h" 00278 } 00279 00280 /* 00281 * Texture mapping with perspective correction. 00282 * We use the gradient method to make less divisions. 00283 * TODO: pipeline the division 00284 */ 00285 00286 static void 00287 FNAME(white_perspective) (ZBuffer *zb, 00288 ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2) 00289 { 00290 ZTextureDef *texture_def; 00291 PN_stdfloat fdzdx,fndzdx,ndszdx,ndtzdx; 00292 00293 #define INTERP_Z 00294 #define INTERP_STZ 00295 00296 #define NB_INTERP 8 00297 00298 #define EARLY_OUT() \ 00299 { \ 00300 } 00301 00302 #define DRAW_INIT() \ 00303 { \ 00304 texture_def = &zb->current_textures[0]; \ 00305 fdzdx=(PN_stdfloat)dzdx; \ 00306 fndzdx=NB_INTERP * fdzdx; \ 00307 ndszdx=NB_INTERP * dszdx; \ 00308 ndtzdx=NB_INTERP * dtzdx; \ 00309 } 00310 00311 00312 #define PUT_PIXEL(_a) \ 00313 { \ 00314 zz=z >> ZB_POINT_Z_FRAC_BITS; \ 00315 if (ZCMP(pz[_a], zz)) { \ 00316 tmp = ZB_LOOKUP_TEXTURE(texture_def, s, t, mipmap_level, mipmap_dx); \ 00317 if (ACMP(zb, PIXEL_A(tmp))) { \ 00318 STORE_PIX(pp[_a], tmp, PIXEL_R(tmp), PIXEL_G(tmp), PIXEL_B(tmp), PIXEL_A(tmp)); \ 00319 STORE_Z(pz[_a], zz); \ 00320 } \ 00321 } \ 00322 z+=dzdx; \ 00323 s+=dsdx; \ 00324 t+=dtdx; \ 00325 } 00326 00327 #define DRAW_LINE() \ 00328 { \ 00329 register ZPOINT *pz; \ 00330 register PIXEL *pp; \ 00331 register int s,t,z,zz; \ 00332 register int n,dsdx,dtdx; \ 00333 PN_stdfloat sz,tz,fz,zinv; \ 00334 n=(x2>>16)-x1; \ 00335 fz=(PN_stdfloat)z1; \ 00336 zinv=1.0f / fz; \ 00337 pp=(PIXEL *)((char *)pp1 + x1 * PSZB); \ 00338 pz=pz1+x1; \ 00339 z=z1; \ 00340 sz=sz1; \ 00341 tz=tz1; \ 00342 while (n>=(NB_INTERP-1)) { \ 00343 { \ 00344 PN_stdfloat ss,tt; \ 00345 ss=(sz * zinv); \ 00346 tt=(tz * zinv); \ 00347 s=(int) ss; \ 00348 t=(int) tt; \ 00349 dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \ 00350 dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \ 00351 CALC_MIPMAP_LEVEL(mipmap_level, mipmap_dx, dsdx, dtdx); \ 00352 fz+=fndzdx; \ 00353 zinv=1.0f / fz; \ 00354 } \ 00355 PUT_PIXEL(0); \ 00356 PUT_PIXEL(1); \ 00357 PUT_PIXEL(2); \ 00358 PUT_PIXEL(3); \ 00359 PUT_PIXEL(4); \ 00360 PUT_PIXEL(5); \ 00361 PUT_PIXEL(6); \ 00362 PUT_PIXEL(7); \ 00363 pz+=NB_INTERP; \ 00364 pp=(PIXEL *)((char *)pp + NB_INTERP * PSZB); \ 00365 n-=NB_INTERP; \ 00366 sz+=ndszdx; \ 00367 tz+=ndtzdx; \ 00368 } \ 00369 { \ 00370 PN_stdfloat ss,tt; \ 00371 ss=(sz * zinv); \ 00372 tt=(tz * zinv); \ 00373 s=(int) ss; \ 00374 t=(int) tt; \ 00375 dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \ 00376 dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \ 00377 CALC_MIPMAP_LEVEL(mipmap_level, mipmap_dx, dsdx, dtdx); \ 00378 } \ 00379 while (n>=0) { \ 00380 PUT_PIXEL(0); \ 00381 pz+=1; \ 00382 pp=(PIXEL *)((char *)pp + PSZB); \ 00383 n-=1; \ 00384 } \ 00385 } 00386 00387 #define PIXEL_COUNT pixel_count_white_perspective 00388 00389 #include "ztriangle.h" 00390 } 00391 00392 /* 00393 * Flat shaded triangle, with perspective-correct mapping. 00394 */ 00395 00396 static void 00397 FNAME(flat_perspective) (ZBuffer *zb, 00398 ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2) 00399 { 00400 ZTextureDef *texture_def; 00401 PN_stdfloat fdzdx,fndzdx,ndszdx,ndtzdx; 00402 int or0, og0, ob0, oa0; 00403 00404 #define INTERP_Z 00405 #define INTERP_STZ 00406 #define INTERP_RGB 00407 00408 #define EARLY_OUT() \ 00409 { \ 00410 } 00411 00412 #define DRAW_INIT() \ 00413 { \ 00414 if (p2->a == 0 && !ACMP(zb, p2->a)) { \ 00415 /* This alpha is zero, and we'll never get other than 0. */ \ 00416 return; \ 00417 } \ 00418 texture_def = &zb->current_textures[0]; \ 00419 fdzdx=(PN_stdfloat)dzdx; \ 00420 fndzdx=NB_INTERP * fdzdx; \ 00421 ndszdx=NB_INTERP * dszdx; \ 00422 ndtzdx=NB_INTERP * dtzdx; \ 00423 or0 = p2->r; \ 00424 og0 = p2->g; \ 00425 ob0 = p2->b; \ 00426 oa0 = p2->a; \ 00427 } 00428 00429 #define PUT_PIXEL(_a) \ 00430 { \ 00431 zz=z >> ZB_POINT_Z_FRAC_BITS; \ 00432 if (ZCMP(pz[_a], zz)) { \ 00433 tmp = ZB_LOOKUP_TEXTURE(texture_def, s, t, mipmap_level, mipmap_dx); \ 00434 int a = PALPHA_MULT(oa0, PIXEL_A(tmp)); \ 00435 if (ACMP(zb, a)) { \ 00436 STORE_PIX(pp[_a], \ 00437 RGBA_TO_PIXEL(PCOMPONENT_MULT(or0, PIXEL_R(tmp)), \ 00438 PCOMPONENT_MULT(og0, PIXEL_G(tmp)), \ 00439 PCOMPONENT_MULT(ob0, PIXEL_B(tmp)), \ 00440 a), \ 00441 PCOMPONENT_MULT(or0, PIXEL_R(tmp)), \ 00442 PCOMPONENT_MULT(og0, PIXEL_G(tmp)), \ 00443 PCOMPONENT_MULT(ob0, PIXEL_B(tmp)), \ 00444 a); \ 00445 STORE_Z(pz[_a], zz); \ 00446 } \ 00447 } \ 00448 z+=dzdx; \ 00449 s+=dsdx; \ 00450 t+=dtdx; \ 00451 } 00452 00453 #define DRAW_LINE() \ 00454 { \ 00455 register ZPOINT *pz; \ 00456 register PIXEL *pp; \ 00457 register int s,t,z,zz; \ 00458 register int n,dsdx,dtdx; \ 00459 register int or1,og1,ob1,oa1; \ 00460 PN_stdfloat sz,tz,fz,zinv; \ 00461 n=(x2>>16)-x1; \ 00462 fz=(PN_stdfloat)z1; \ 00463 zinv=1.0f / fz; \ 00464 pp=(PIXEL *)((char *)pp1 + x1 * PSZB); \ 00465 pz=pz1+x1; \ 00466 z=z1; \ 00467 sz=sz1; \ 00468 tz=tz1; \ 00469 or1 = r1; \ 00470 og1 = g1; \ 00471 ob1 = b1; \ 00472 oa1 = a1; \ 00473 while (n>=(NB_INTERP-1)) { \ 00474 { \ 00475 PN_stdfloat ss,tt; \ 00476 ss=(sz * zinv); \ 00477 tt=(tz * zinv); \ 00478 s=(int) ss; \ 00479 t=(int) tt; \ 00480 dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \ 00481 dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \ 00482 CALC_MIPMAP_LEVEL(mipmap_level, mipmap_dx, dsdx, dtdx); \ 00483 fz+=fndzdx; \ 00484 zinv=1.0f / fz; \ 00485 } \ 00486 PUT_PIXEL(0); \ 00487 PUT_PIXEL(1); \ 00488 PUT_PIXEL(2); \ 00489 PUT_PIXEL(3); \ 00490 PUT_PIXEL(4); \ 00491 PUT_PIXEL(5); \ 00492 PUT_PIXEL(6); \ 00493 PUT_PIXEL(7); \ 00494 pz+=NB_INTERP; \ 00495 pp=(PIXEL *)((char *)pp + NB_INTERP * PSZB); \ 00496 n-=NB_INTERP; \ 00497 sz+=ndszdx; \ 00498 tz+=ndtzdx; \ 00499 } \ 00500 { \ 00501 PN_stdfloat ss,tt; \ 00502 ss=(sz * zinv); \ 00503 tt=(tz * zinv); \ 00504 s=(int) ss; \ 00505 t=(int) tt; \ 00506 dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \ 00507 dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \ 00508 CALC_MIPMAP_LEVEL(mipmap_level, mipmap_dx, dsdx, dtdx); \ 00509 } \ 00510 while (n>=0) { \ 00511 PUT_PIXEL(0); \ 00512 pz+=1; \ 00513 pp=(PIXEL *)((char *)pp + PSZB); \ 00514 n-=1; \ 00515 } \ 00516 } 00517 00518 #define PIXEL_COUNT pixel_count_flat_perspective 00519 00520 #include "ztriangle.h" 00521 } 00522 00523 /* 00524 * Smooth filled triangle, with perspective-correct mapping. 00525 */ 00526 00527 static void 00528 FNAME(smooth_perspective) (ZBuffer *zb, 00529 ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2) 00530 { 00531 ZTextureDef *texture_def; 00532 PN_stdfloat fdzdx,fndzdx,ndszdx,ndtzdx; 00533 00534 #define INTERP_Z 00535 #define INTERP_STZ 00536 #define INTERP_RGB 00537 00538 #define EARLY_OUT() \ 00539 { \ 00540 int c0, c1, c2; \ 00541 c0 = RGBA_TO_PIXEL(p0->r, p0->g, p0->b, p0->a); \ 00542 c1 = RGBA_TO_PIXEL(p1->r, p1->g, p1->b, p1->a); \ 00543 c2 = RGBA_TO_PIXEL(p2->r, p2->g, p2->b, p2->a); \ 00544 if (c0 == c1 && c0 == c2) { \ 00545 /* It's really a flat-shaded triangle. */ \ 00546 if (c0 == 0xffffffff) { \ 00547 /* Actually, it's a white triangle. */ \ 00548 FNAME(white_perspective)(zb, p0, p1, p2); \ 00549 return; \ 00550 } \ 00551 FNAME(flat_perspective)(zb, p0, p1, p2); \ 00552 return; \ 00553 } \ 00554 } 00555 00556 #define DRAW_INIT() \ 00557 { \ 00558 texture_def = &zb->current_textures[0]; \ 00559 fdzdx=(PN_stdfloat)dzdx; \ 00560 fndzdx=NB_INTERP * fdzdx; \ 00561 ndszdx=NB_INTERP * dszdx; \ 00562 ndtzdx=NB_INTERP * dtzdx; \ 00563 } 00564 00565 #define PUT_PIXEL(_a) \ 00566 { \ 00567 zz=z >> ZB_POINT_Z_FRAC_BITS; \ 00568 if (ZCMP(pz[_a], zz)) { \ 00569 tmp = ZB_LOOKUP_TEXTURE(texture_def, s, t, mipmap_level, mipmap_dx); \ 00570 int a = PALPHA_MULT(oa1, PIXEL_A(tmp)); \ 00571 if (ACMP(zb, a)) { \ 00572 STORE_PIX(pp[_a], \ 00573 RGBA_TO_PIXEL(PCOMPONENT_MULT(or1, PIXEL_R(tmp)), \ 00574 PCOMPONENT_MULT(og1, PIXEL_G(tmp)), \ 00575 PCOMPONENT_MULT(ob1, PIXEL_B(tmp)), \ 00576 a), \ 00577 PCOMPONENT_MULT(or1, PIXEL_R(tmp)), \ 00578 PCOMPONENT_MULT(og1, PIXEL_G(tmp)), \ 00579 PCOMPONENT_MULT(ob1, PIXEL_B(tmp)), \ 00580 a); \ 00581 STORE_Z(pz[_a], zz); \ 00582 } \ 00583 } \ 00584 z+=dzdx; \ 00585 og1+=dgdx; \ 00586 or1+=drdx; \ 00587 ob1+=dbdx; \ 00588 oa1+=dadx; \ 00589 s+=dsdx; \ 00590 t+=dtdx; \ 00591 } 00592 00593 #define DRAW_LINE() \ 00594 { \ 00595 register ZPOINT *pz; \ 00596 register PIXEL *pp; \ 00597 register int s,t,z,zz; \ 00598 register int n,dsdx,dtdx; \ 00599 register int or1,og1,ob1,oa1; \ 00600 PN_stdfloat sz,tz,fz,zinv; \ 00601 n=(x2>>16)-x1; \ 00602 fz=(PN_stdfloat)z1; \ 00603 zinv=1.0f / fz; \ 00604 pp=(PIXEL *)((char *)pp1 + x1 * PSZB); \ 00605 pz=pz1+x1; \ 00606 z=z1; \ 00607 sz=sz1; \ 00608 tz=tz1; \ 00609 or1 = r1; \ 00610 og1 = g1; \ 00611 ob1 = b1; \ 00612 oa1 = a1; \ 00613 while (n>=(NB_INTERP-1)) { \ 00614 { \ 00615 PN_stdfloat ss,tt; \ 00616 ss=(sz * zinv); \ 00617 tt=(tz * zinv); \ 00618 s=(int) ss; \ 00619 t=(int) tt; \ 00620 dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \ 00621 dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \ 00622 CALC_MIPMAP_LEVEL(mipmap_level, mipmap_dx, dsdx, dtdx); \ 00623 fz+=fndzdx; \ 00624 zinv=1.0f / fz; \ 00625 } \ 00626 PUT_PIXEL(0); \ 00627 PUT_PIXEL(1); \ 00628 PUT_PIXEL(2); \ 00629 PUT_PIXEL(3); \ 00630 PUT_PIXEL(4); \ 00631 PUT_PIXEL(5); \ 00632 PUT_PIXEL(6); \ 00633 PUT_PIXEL(7); \ 00634 pz+=NB_INTERP; \ 00635 pp=(PIXEL *)((char *)pp + NB_INTERP * PSZB); \ 00636 n-=NB_INTERP; \ 00637 sz+=ndszdx; \ 00638 tz+=ndtzdx; \ 00639 } \ 00640 { \ 00641 PN_stdfloat ss,tt; \ 00642 ss=(sz * zinv); \ 00643 tt=(tz * zinv); \ 00644 s=(int) ss; \ 00645 t=(int) tt; \ 00646 dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \ 00647 dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \ 00648 CALC_MIPMAP_LEVEL(mipmap_level, mipmap_dx, dsdx, dtdx); \ 00649 } \ 00650 while (n>=0) { \ 00651 PUT_PIXEL(0); \ 00652 pz+=1; \ 00653 pp=(PIXEL *)((char *)pp + PSZB); \ 00654 n-=1; \ 00655 } \ 00656 } 00657 00658 #define PIXEL_COUNT pixel_count_smooth_perspective 00659 00660 #include "ztriangle.h" 00661 } 00662 00663 /* 00664 * Smooth filled triangle, with perspective-correct mapping, on two 00665 * stages of multitexture. 00666 */ 00667 00668 static void 00669 FNAME(smooth_multitex2) (ZBuffer *zb, 00670 ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2) 00671 { 00672 PN_stdfloat fdzdx,fndzdx,ndszdx,ndtzdx,ndszadx,ndtzadx; 00673 00674 #define INTERP_Z 00675 #define INTERP_STZ 00676 #define INTERP_STZA 00677 #define INTERP_RGB 00678 00679 #define EARLY_OUT() \ 00680 { \ 00681 } 00682 00683 #define DRAW_INIT() \ 00684 { \ 00685 fdzdx=(PN_stdfloat)dzdx; \ 00686 fndzdx=NB_INTERP * fdzdx; \ 00687 ndszdx=NB_INTERP * dszdx; \ 00688 ndtzdx=NB_INTERP * dtzdx; \ 00689 ndszadx=NB_INTERP * dszadx; \ 00690 ndtzadx=NB_INTERP * dtzadx; \ 00691 } 00692 00693 #define PUT_PIXEL(_a) \ 00694 { \ 00695 zz=z >> ZB_POINT_Z_FRAC_BITS; \ 00696 if (ZCMP(pz[_a], zz)) { \ 00697 tmp = ZB_LOOKUP_TEXTURE(&zb->current_textures[0], s, t, mipmap_level, mipmap_dx); \ 00698 int a = PALPHA_MULT(oa1, PIXEL_A(tmp)); \ 00699 if (ACMP(zb, a)) { \ 00700 int tmpa = ZB_LOOKUP_TEXTURE(&zb->current_textures[1], sa, ta, mipmap_levela, mipmap_dxa); \ 00701 STORE_PIX(pp[_a], \ 00702 RGBA_TO_PIXEL(PCOMPONENT_MULT3(or1, PIXEL_R(tmp), PIXEL_R(tmpa)), \ 00703 PCOMPONENT_MULT3(og1, PIXEL_G(tmp), PIXEL_G(tmpa)), \ 00704 PCOMPONENT_MULT3(ob1, PIXEL_B(tmp), PIXEL_B(tmpa)), \ 00705 a), \ 00706 PCOMPONENT_MULT3(or1, PIXEL_R(tmp), PIXEL_R(tmpa)), \ 00707 PCOMPONENT_MULT3(og1, PIXEL_G(tmp), PIXEL_G(tmpa)), \ 00708 PCOMPONENT_MULT3(ob1, PIXEL_B(tmp), PIXEL_B(tmpa)), \ 00709 a); \ 00710 STORE_Z(pz[_a], zz); \ 00711 } \ 00712 } \ 00713 z+=dzdx; \ 00714 og1+=dgdx; \ 00715 or1+=drdx; \ 00716 ob1+=dbdx; \ 00717 oa1+=dadx; \ 00718 s+=dsdx; \ 00719 t+=dtdx; \ 00720 sa+=dsadx; \ 00721 ta+=dtadx; \ 00722 } 00723 00724 #define DRAW_LINE() \ 00725 { \ 00726 register ZPOINT *pz; \ 00727 register PIXEL *pp; \ 00728 register int s,t,sa,ta,z,zz; \ 00729 register int n,dsdx,dtdx,dsadx,dtadx; \ 00730 register int or1,og1,ob1,oa1; \ 00731 PN_stdfloat sz,tz,sza,tza,fz,zinv; \ 00732 n=(x2>>16)-x1; \ 00733 fz=(PN_stdfloat)z1; \ 00734 zinv=1.0f / fz; \ 00735 pp=(PIXEL *)((char *)pp1 + x1 * PSZB); \ 00736 pz=pz1+x1; \ 00737 z=z1; \ 00738 sz=sz1; \ 00739 tz=tz1; \ 00740 sza=sza1; \ 00741 tza=tza1; \ 00742 or1 = r1; \ 00743 og1 = g1; \ 00744 ob1 = b1; \ 00745 oa1 = a1; \ 00746 while (n>=(NB_INTERP-1)) { \ 00747 { \ 00748 PN_stdfloat ss,tt; \ 00749 ss=(sz * zinv); \ 00750 tt=(tz * zinv); \ 00751 s=(int) ss; \ 00752 t=(int) tt; \ 00753 dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \ 00754 dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \ 00755 CALC_MIPMAP_LEVEL(mipmap_level, mipmap_dx, dsdx, dtdx); \ 00756 } \ 00757 { \ 00758 PN_stdfloat ssa,tta; \ 00759 ssa=(sza * zinv); \ 00760 tta=(tza * zinv); \ 00761 sa=(int) ssa; \ 00762 ta=(int) tta; \ 00763 dsadx= (int)( (dszadx - ssa*fdzdx)*zinv ); \ 00764 dtadx= (int)( (dtzadx - tta*fdzdx)*zinv ); \ 00765 CALC_MIPMAP_LEVEL(mipmap_levela, mipmap_dxa, dsadx, dtadx); \ 00766 } \ 00767 fz+=fndzdx; \ 00768 zinv=1.0f / fz; \ 00769 PUT_PIXEL(0); \ 00770 PUT_PIXEL(1); \ 00771 PUT_PIXEL(2); \ 00772 PUT_PIXEL(3); \ 00773 PUT_PIXEL(4); \ 00774 PUT_PIXEL(5); \ 00775 PUT_PIXEL(6); \ 00776 PUT_PIXEL(7); \ 00777 pz+=NB_INTERP; \ 00778 pp=(PIXEL *)((char *)pp + NB_INTERP * PSZB); \ 00779 n-=NB_INTERP; \ 00780 sz+=ndszdx; \ 00781 tz+=ndtzdx; \ 00782 sza+=ndszadx; \ 00783 tza+=ndtzadx; \ 00784 } \ 00785 { \ 00786 PN_stdfloat ss,tt; \ 00787 ss=(sz * zinv); \ 00788 tt=(tz * zinv); \ 00789 s=(int) ss; \ 00790 t=(int) tt; \ 00791 dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \ 00792 dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \ 00793 CALC_MIPMAP_LEVEL(mipmap_level, mipmap_dx, dsdx, dtdx); \ 00794 } \ 00795 { \ 00796 PN_stdfloat ssa,tta; \ 00797 ssa=(sza * zinv); \ 00798 tta=(tza * zinv); \ 00799 sa=(int) ssa; \ 00800 ta=(int) tta; \ 00801 dsadx= (int)( (dszadx - ssa*fdzdx)*zinv ); \ 00802 dtadx= (int)( (dtzadx - tta*fdzdx)*zinv ); \ 00803 CALC_MIPMAP_LEVEL(mipmap_levela, mipmap_dxa, dsadx, dtadx); \ 00804 } \ 00805 while (n>=0) { \ 00806 PUT_PIXEL(0); \ 00807 pz+=1; \ 00808 pp=(PIXEL *)((char *)pp + PSZB); \ 00809 n-=1; \ 00810 } \ 00811 } 00812 00813 #define PIXEL_COUNT pixel_count_smooth_multitex2 00814 00815 #include "ztriangle.h" 00816 } 00817 00818 /* 00819 * Smooth filled triangle, with perspective-correct mapping, on three 00820 * stages of multitexture. 00821 */ 00822 00823 static void 00824 FNAME(smooth_multitex3) (ZBuffer *zb, 00825 ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2) 00826 { 00827 PN_stdfloat fdzdx,fndzdx,ndszdx,ndtzdx,ndszadx,ndtzadx,ndszbdx,ndtzbdx; 00828 00829 #define INTERP_Z 00830 #define INTERP_STZ 00831 #define INTERP_STZA 00832 #define INTERP_STZB 00833 #define INTERP_RGB 00834 00835 #define EARLY_OUT() \ 00836 { \ 00837 } 00838 00839 #define DRAW_INIT() \ 00840 { \ 00841 fdzdx=(PN_stdfloat)dzdx; \ 00842 fndzdx=NB_INTERP * fdzdx; \ 00843 ndszdx=NB_INTERP * dszdx; \ 00844 ndtzdx=NB_INTERP * dtzdx; \ 00845 ndszadx=NB_INTERP * dszadx; \ 00846 ndtzadx=NB_INTERP * dtzadx; \ 00847 ndszbdx=NB_INTERP * dszbdx; \ 00848 ndtzbdx=NB_INTERP * dtzbdx; \ 00849 } 00850 00851 #define PUT_PIXEL(_a) \ 00852 { \ 00853 zz=z >> ZB_POINT_Z_FRAC_BITS; \ 00854 if (ZCMP(pz[_a], zz)) { \ 00855 tmp = ZB_LOOKUP_TEXTURE(&zb->current_textures[0], s, t, mipmap_level, mipmap_dx); \ 00856 int a = PALPHA_MULT(oa1, PIXEL_A(tmp)); \ 00857 if (ACMP(zb, a)) { \ 00858 int tmpa = ZB_LOOKUP_TEXTURE(&zb->current_textures[1], sa, ta, mipmap_levela, mipmap_dxa); \ 00859 int tmpb = ZB_LOOKUP_TEXTURE(&zb->current_textures[2], sb, tb, mipmap_levelb, mipmap_dxb); \ 00860 STORE_PIX(pp[_a], \ 00861 RGBA_TO_PIXEL(PCOMPONENT_MULT4(or1, PIXEL_R(tmp), PIXEL_R(tmpa), PIXEL_R(tmpb)), \ 00862 PCOMPONENT_MULT4(og1, PIXEL_G(tmp), PIXEL_G(tmpa), PIXEL_G(tmpb)), \ 00863 PCOMPONENT_MULT4(ob1, PIXEL_B(tmp), PIXEL_B(tmpa), PIXEL_B(tmpb)), \ 00864 a), \ 00865 PCOMPONENT_MULT4(or1, PIXEL_R(tmp), PIXEL_R(tmpa), PIXEL_R(tmpb)), \ 00866 PCOMPONENT_MULT4(og1, PIXEL_G(tmp), PIXEL_G(tmpa), PIXEL_G(tmpb)), \ 00867 PCOMPONENT_MULT4(ob1, PIXEL_B(tmp), PIXEL_B(tmpa), PIXEL_B(tmpb)), \ 00868 a); \ 00869 STORE_Z(pz[_a], zz); \ 00870 } \ 00871 } \ 00872 z+=dzdx; \ 00873 og1+=dgdx; \ 00874 or1+=drdx; \ 00875 ob1+=dbdx; \ 00876 oa1+=dadx; \ 00877 s+=dsdx; \ 00878 t+=dtdx; \ 00879 sa+=dsadx; \ 00880 ta+=dtadx; \ 00881 sb+=dsbdx; \ 00882 tb+=dtbdx; \ 00883 } 00884 00885 #define DRAW_LINE() \ 00886 { \ 00887 register ZPOINT *pz; \ 00888 register PIXEL *pp; \ 00889 register int s,t,sa,ta,sb,tb,z,zz; \ 00890 register int n,dsdx,dtdx,dsadx,dtadx,dsbdx,dtbdx; \ 00891 register int or1,og1,ob1,oa1; \ 00892 PN_stdfloat sz,tz,sza,tza,szb,tzb,fz,zinv; \ 00893 n=(x2>>16)-x1; \ 00894 fz=(PN_stdfloat)z1; \ 00895 zinv=1.0f / fz; \ 00896 pp=(PIXEL *)((char *)pp1 + x1 * PSZB); \ 00897 pz=pz1+x1; \ 00898 z=z1; \ 00899 sz=sz1; \ 00900 tz=tz1; \ 00901 sza=sza1; \ 00902 tza=tza1; \ 00903 szb=szb1; \ 00904 tzb=tzb1; \ 00905 or1 = r1; \ 00906 og1 = g1; \ 00907 ob1 = b1; \ 00908 oa1 = a1; \ 00909 while (n>=(NB_INTERP-1)) { \ 00910 { \ 00911 PN_stdfloat ss,tt; \ 00912 ss=(sz * zinv); \ 00913 tt=(tz * zinv); \ 00914 s=(int) ss; \ 00915 t=(int) tt; \ 00916 dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \ 00917 dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \ 00918 CALC_MIPMAP_LEVEL(mipmap_level, mipmap_dx, dsdx, dtdx); \ 00919 } \ 00920 { \ 00921 PN_stdfloat ssa,tta; \ 00922 ssa=(sza * zinv); \ 00923 tta=(tza * zinv); \ 00924 sa=(int) ssa; \ 00925 ta=(int) tta; \ 00926 dsadx= (int)( (dszadx - ssa*fdzdx)*zinv ); \ 00927 dtadx= (int)( (dtzadx - tta*fdzdx)*zinv ); \ 00928 CALC_MIPMAP_LEVEL(mipmap_levela, mipmap_dxa, dsadx, dtadx); \ 00929 } \ 00930 { \ 00931 PN_stdfloat ssb,ttb; \ 00932 ssb=(szb * zinv); \ 00933 ttb=(tzb * zinv); \ 00934 sb=(int) ssb; \ 00935 tb=(int) ttb; \ 00936 dsbdx= (int)( (dszbdx - ssb*fdzdx)*zinv ); \ 00937 dtbdx= (int)( (dtzbdx - ttb*fdzdx)*zinv ); \ 00938 CALC_MIPMAP_LEVEL(mipmap_levelb, mipmap_dxb, dsbdx, dtbdx); \ 00939 } \ 00940 fz+=fndzdx; \ 00941 zinv=1.0f / fz; \ 00942 PUT_PIXEL(0); \ 00943 PUT_PIXEL(1); \ 00944 PUT_PIXEL(2); \ 00945 PUT_PIXEL(3); \ 00946 PUT_PIXEL(4); \ 00947 PUT_PIXEL(5); \ 00948 PUT_PIXEL(6); \ 00949 PUT_PIXEL(7); \ 00950 pz+=NB_INTERP; \ 00951 pp=(PIXEL *)((char *)pp + NB_INTERP * PSZB); \ 00952 n-=NB_INTERP; \ 00953 sz+=ndszdx; \ 00954 tz+=ndtzdx; \ 00955 sza+=ndszadx; \ 00956 tza+=ndtzadx; \ 00957 szb+=ndszbdx; \ 00958 tzb+=ndtzbdx; \ 00959 } \ 00960 { \ 00961 PN_stdfloat ss,tt; \ 00962 ss=(sz * zinv); \ 00963 tt=(tz * zinv); \ 00964 s=(int) ss; \ 00965 t=(int) tt; \ 00966 dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \ 00967 dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \ 00968 CALC_MIPMAP_LEVEL(mipmap_level, mipmap_dx, dsdx, dtdx); \ 00969 } \ 00970 { \ 00971 PN_stdfloat ssa,tta; \ 00972 ssa=(sza * zinv); \ 00973 tta=(tza * zinv); \ 00974 sa=(int) ssa; \ 00975 ta=(int) tta; \ 00976 dsadx= (int)( (dszadx - ssa*fdzdx)*zinv ); \ 00977 dtadx= (int)( (dtzadx - tta*fdzdx)*zinv ); \ 00978 CALC_MIPMAP_LEVEL(mipmap_levela, mipmap_dxa, dsadx, dtadx); \ 00979 } \ 00980 { \ 00981 PN_stdfloat ssb,ttb; \ 00982 ssb=(szb * zinv); \ 00983 ttb=(tzb * zinv); \ 00984 sb=(int) ssb; \ 00985 tb=(int) ttb; \ 00986 dsbdx= (int)( (dszbdx - ssb*fdzdx)*zinv ); \ 00987 dtbdx= (int)( (dtzbdx - ttb*fdzdx)*zinv ); \ 00988 CALC_MIPMAP_LEVEL(mipmap_levelb, mipmap_dxb, dsbdx, dtbdx); \ 00989 } \ 00990 while (n>=0) { \ 00991 PUT_PIXEL(0); \ 00992 pz+=1; \ 00993 pp=(PIXEL *)((char *)pp + PSZB); \ 00994 n-=1; \ 00995 } \ 00996 } 00997 00998 #define PIXEL_COUNT pixel_count_smooth_multitex3 00999 01000 #include "ztriangle.h" 01001 } 01002 01003 #undef ACMP 01004 #undef ZCMP 01005 #undef STORE_PIX 01006 #undef STORE_Z 01007 #undef FNAME 01008 #undef INTERP_MIPMAP 01009 #undef CALC_MIPMAP_LEVEL 01010 #undef ZB_LOOKUP_TEXTURE 01011