2 #pragma warning (disable: 4101)
5 #if !defined(GOURAUD) && !defined(TEXMAP) && !defined(ZBUF)
9 void POLYFILL(struct pvertex *varr, int vnum)
11 int i, line, top, bot;
12 struct pvertex *vlast, *v, *vn, *tab;
13 int32_t x, y0, y1, dx, dy, slope, fx, fy;
15 gaw_pixel *fbptr, *pptr, color;
17 int32_t r, g, b, dr, dg, db, rslope, gslope, bslope;
19 int32_t a, da, aslope;
23 int32_t tu, tv, du, dv, uslope, vslope;
28 int32_t z, dz, zslope;
33 /* for flat shading we already know the color, so pack it once */
34 color = PACK_RGB(varr[0].r, varr[0].g, varr[0].b);
37 vlast = varr + vnum - 1;
38 top = pfill_fb.height;
41 for(i=0; i<vnum; i++) {
42 /* scan the edge between the current and next vertex */
46 if(vn->y == v->y) continue; // XXX ???
49 /* inrementing Y: left side */
52 /* decrementing Y: right side, flip vertices to trace bottom->up */
58 /* calculate edge slope */
61 slope = (dx << 8) / dy;
64 r = v->r << COLOR_SHIFT;
65 g = v->g << COLOR_SHIFT;
66 b = v->b << COLOR_SHIFT;
67 dr = (vn->r << COLOR_SHIFT) - r;
68 dg = (vn->g << COLOR_SHIFT) - g;
69 db = (vn->b << COLOR_SHIFT) - b;
70 rslope = (dr << 8) / dy;
71 gslope = (dg << 8) / dy;
72 bslope = (db << 8) / dy;
74 a = v->a << COLOR_SHIFT;
75 da = (vn->a << COLOR_SHIFT) - a;
76 aslope = (da << 8) / dy;
77 #endif /* BLEND_ALPHA */
84 uslope = (du << 8) / dy;
85 vslope = (dv << 8) / dy;
90 zslope = (dz << 8) / dy;
93 y0 = (v->y + 0x100) & 0xffffff00; /* start from the next scanline */
94 fy = y0 - v->y; /* fractional part before the next scanline */
95 fx = (fy * slope) >> 8; /* X adjust for the step to the next scanline */
96 x = v->x + fx; /* adjust X */
97 y1 = vn->y & 0xffffff00; /* last scanline of the edge <= vn->y */
99 /* also adjust other interpolated attributes */
101 r += (fy * rslope) >> 8;
102 g += (fy * gslope) >> 8;
103 b += (fy * bslope) >> 8;
105 a += (fy * aslope) >> 8;
106 #endif /* BLEND_ALPHA */
109 tu += (fy * uslope) >> 8;
110 tv += (fy * vslope) >> 8;
113 z += (fy * zslope) >> 8;
117 if(line < top) top = line;
118 if((y1 >> 8) > bot) bot = y1 >> 8;
120 if(line > 0) tab += line;
122 while(line <= (y1 >> 8) && line < pfill_fb.height) {
124 int val = x < 0 ? 0 : x >> 8;
125 tab->x = val < pfill_fb.width ? val : pfill_fb.width - 1;
132 #endif /* BLEND_ALPHA */
150 #endif /* BLEND_ALPHA */
164 if(bot >= pfill_fb.height) bot = pfill_fb.height - 1;
166 fbptr = pfill_fb.pixels + top * pfill_fb.width;
167 for(i=top; i<=bot; i++) {
169 len = right[i].x - start;
170 /* XXX we probably need more precision in left/right.x */
173 dx = len == 0 ? 256 : (len << 8);
183 rslope = (dr << 8) / dx;
184 gslope = (dg << 8) / dx;
185 bslope = (db << 8) / dx;
189 aslope = (da << 8) / dx;
190 #endif /* BLEND_ALPHA */
195 du = right[i].u - tu;
196 dv = right[i].v - tv;
197 uslope = (du << 8) / dx;
198 vslope = (dv << 8) / dx;
203 zslope = (dz << 8) / dx;
204 zptr = pfill_zbuf + i * pfill_fb.width + start;
207 pptr = fbptr + start;
209 #if defined(GOURAUD) || defined(TEXMAP) || defined(BLEND_ALPHA) || defined(BLEND_ADD)
215 #if defined(BLEND_ALPHA) || defined(BLEND_ADD)
228 /* ZFAIL: advance all attributes and continue */
249 /* we upped the color precision to while interpolating the
250 * edges, now drop the extra bits before packing
252 cr = r < 0 ? 0 : (r >> COLOR_SHIFT);
253 cg = g < 0 ? 0 : (g >> COLOR_SHIFT);
254 cb = b < 0 ? 0 : (b >> COLOR_SHIFT);
259 ca = a < 0 ? 0 : (a >> COLOR_SHIFT);
261 #endif /* BLEND_ALPHA */
264 tx = (tu >> (16 - pfill_tex.xshift)) & pfill_tex.xmask;
265 ty = (tv >> (16 - pfill_tex.yshift)) & pfill_tex.ymask;
266 texel = pfill_tex.pixels[(ty << pfill_tex.xshift) + tx];
272 /* for flat textured, cr,cg,cb would not be initialized */
279 #endif /* !GOURAUD */
280 /* This is not correct, should be /255, but it's much faster
281 * to shift by 8 (/256), and won't make a huge difference
283 cr = (cr * UNPACK_R(texel)) >> 8;
284 cg = (cg * UNPACK_G(texel)) >> 8;
285 cb = (cb * UNPACK_B(texel)) >> 8;
287 ca = (ca * UNPACK_A(texel)) >> 8;
292 inv_alpha = 255 - ca;
294 cr = (cr * ca + UNPACK_R(fbcol) * inv_alpha) >> 8;
295 cg = (cg * ca + UNPACK_G(fbcol) * inv_alpha) >> 8;
296 cb = (cb * ca + UNPACK_B(fbcol) * inv_alpha) >> 8;
297 #endif /* BLEND_ALPHA */
300 cr += UNPACK_R(fbcol);
301 cg += UNPACK_G(fbcol);
302 cb += UNPACK_B(fbcol);
303 #endif /* BLEND_ADD */
305 #ifdef DEBUG_OVERDRAW
306 *pptr++ += DEBUG_OVERDRAW;
308 #if defined(GOURAUD) || defined(TEXMAP) || defined(BLEND_ALPHA) || defined(BLEND_ADD)
309 if(cr >= 255) cr = 255;
310 if(cg >= 255) cg = 255;
311 if(cb >= 255) cb = 255;
312 color = PACK_RGB(cr, cg, cb);
317 fbptr += pfill_fb.width;