2 #pragma warning (disable: 4101)
5 #if !defined(GOURAUD) && !defined(TEXMAP) && !defined(ZBUF)
9 void POLYFILL(struct pvertex *varr)
11 int i, line, top, bot;
12 struct pvertex *v, *vn, *tab;
13 int32_t x, y0, y1, dx, dy, slope, fx, fy;
15 g3d_pixel *fbptr, *pptr, color;
17 int32_t lum, dl, lumslope;
20 int32_t tu, tv, du, dv, uslope, vslope;
25 int32_t z, dz, zslope;
30 /* for flat shading we already know the intensity */
34 top = pfill_fb.height;
38 /* scan the edge between the current and next vertex */
42 if(vn->y == v->y) continue; /* XXX ??? */
45 /* inrementing Y: left side */
48 /* decrementing Y: right side, flip vertices to trace bottom->up */
54 /* calculate edge slope */
57 slope = (dx << 8) / dy;
60 lum = v->l << COLOR_SHIFT;
61 dl = (vn->l << COLOR_SHIFT) - lum;
62 lumslope = (dl << 8) / dy;
69 uslope = (du << 8) / dy;
70 vslope = (dv << 8) / dy;
75 zslope = (dz << 8) / dy;
78 y0 = (v->y + 0x100) & 0xffffff00; /* start from the next scanline */
79 fy = y0 - v->y; /* fractional part before the next scanline */
80 fx = (fy * slope) >> 8; /* X adjust for the step to the next scanline */
81 x = v->x + fx; /* adjust X */
82 y1 = vn->y & 0xffffff00; /* last scanline of the edge <= vn->y */
84 /* also adjust other interpolated attributes */
86 lum += (fy * lumslope) >> 8;
90 tu += uslope * (fy / 256.0f);
91 tv += vslope * (fy / 256.0f);
93 tu += (fy * uslope) >> 8;
94 tv += (fy * vslope) >> 8;
98 z += (fy * zslope) >> 8;
102 if(line < top) top = line;
103 if((y1 >> 8) > bot) bot = y1 >> 8;
105 if(line > 0) tab += line;
107 while(line <= (y1 >> 8) && line < pfill_fb.height) {
109 int val = x < 0 ? 0 : x >> 8;
110 tab->x = val < pfill_fb.width ? val : pfill_fb.width - 1;
139 if(bot >= pfill_fb.height) bot = pfill_fb.height - 1;
141 fbptr = pfill_fb.pixels + top * pfill_fb.width;
142 for(i=top; i<=bot; i++) {
144 len = right[i].x - start;
145 /* XXX we probably need more precision in left/right.x */
148 dx = len == 0 ? 256 : (len << 8);
160 zptr = pfill_zbuf + i * pfill_fb.width + start;
163 pptr = fbptr + start;
165 #if defined(GOURAUD) || defined(TEXMAP)
175 /* ZFAIL: advance all attributes and continue */
191 /* we upped the color precision to while interpolating the
192 * edges, now drop the extra bits before packing
194 inten = lum < 0 ? 0 : (lum >> COLOR_SHIFT);
198 tx = (tu >> (16 - pfill_tex.xshift)) & pfill_tex.xmask;
199 ty = (tv >> (16 - pfill_tex.yshift)) & pfill_tex.ymask;
200 texel = pfill_tex.pixels[(ty << pfill_tex.xshift) + tx];
206 /* for flat textured, cr,cg,cb would not be initialized */
208 #endif /* !GOURAUD */
209 inten = shade_color(texel, inten); /* was inten * texel */
212 #ifdef DEBUG_OVERDRAW
213 *pptr++ += DEBUG_OVERDRAW;
215 #if defined(GOURAUD) || defined(TEXMAP)
221 fbptr += pfill_fb.width;