#ifdef TEXMAP
int32_t u, v, du, dv, uslope, vslope;
#endif
+#ifdef ZBUF
+ int32_t z, dz, zslope;
+#endif
int32_t start_idx, end_idx;
if(v0->y > v1->y) {
uslope = (du << 8) / dy;
vslope = (dv << 8) / dy;
#endif
+#ifdef ZBUF
+ z = v0->z;
+ dz = v1->z - v0->z;
+ zslope = (dz << 8) / dy;
+#endif
start_idx = v0->y >> 8;
end_idx = v1->y >> 8;
x += slope;
#ifdef GOURAUD
/* we'll store the color in the edge tables with COLOR_SHIFT extra bits of precision */
- CHECKEDGE(i);
edge[i].r = r;
edge[i].g = g;
edge[i].b = b;
g += gslope;
b += bslope;
#ifdef BLEND_ALPHA
- CHECKEDGE(i);
edge[i].a = a;
a += aslope;
#endif
#endif /* GOURAUD */
#ifdef TEXMAP
- CHECKEDGE(i);
edge[i].u = u;
edge[i].v = v;
u += uslope;
v += vslope;
#endif
+#ifdef ZBUF
+ edge[i].z = z;
+ z += zslope;
+#endif
}
return (uint32_t)start_idx | ((uint32_t)(end_idx - 1) << 16);
int topidx = 0, botidx = 0, sltop = pfill_fb.height, slbot = 0;
g3d_pixel color;
/* the following variables are used for interpolating horizontally accros scanlines */
-#if defined(GOURAUD) || defined(TEXMAP)
+#if defined(GOURAUD) || defined(TEXMAP) || defined(ZBUF)
int mid;
int32_t dx, tmp;
#else
#ifdef TEXMAP
int32_t u, v, du, dv, uslope, vslope;
#endif
+#ifdef ZBUF
+ int32_t z, dz, zslope;
+#endif
for(i=1; i<nverts; i++) {
if(pv[i].y < pv[topidx].y) topidx = i;
right[idx].u = pv[i1].u;
right[idx].v = pv[i1].v;
#endif
+#ifdef ZBUF
+ left[idx].z = pv[i0].z;
+ right[idx].z = pv[i1].z;
+#endif
CHECKEDGE(idx);
if(idx > slbot) slbot = idx;
if(idx < sltop) sltop = idx;
uslope = (du << 8) / dx;
vslope = (dv << 8) / dx;
#endif
+#ifdef ZBUF
+ dz = right[mid].z - left[mid].z;
+ zslope = (dz << 8) / dx;
+#endif
#endif /* !defined(HIGH_QUALITY) */
/* for each scanline ... */
for(i=sltop; i<=slbot; i++) {
g3d_pixel *pixptr;
int32_t x;
+#ifdef ZBUF
+ uint16_t *zptr;
+#endif
CHECKEDGE(i);
x = left[i].x;
u = left[i].u;
v = left[i].v;
#endif
+#ifdef ZBUF
+ z = left[i].z;
+ zptr = pfill_zbuf + i * pfill_fb.width + (x >> 8);
+#endif
CHECKEDGE(i);
-#if defined(HIGH_QUALITY) && (defined(GOURAUD) || defined(TEXMAP))
+#if defined(HIGH_QUALITY) && (defined(GOURAUD) || defined(TEXMAP) || defined(ZBUF))
if(!(dx = right[i].x - left[i].x)) dx = 256;
CHECKEDGE(i);
uslope = (du << 8) / dx;
vslope = (dv << 8) / dx;
#endif
+#ifdef ZBUF
+ dz = right[i].z - left[i].z;
+ zslope = (dz << 8) / dx;
+#endif
#endif /* HIGH_QUALITY */
CHECKEDGE(i);
/* go across the scanline interpolating if necessary */
while(x <= right[i].x) {
+ /*if(x == (180 << 8) && i == 174) {
+ asm("int $3");
+ }*/
#if defined(GOURAUD) || defined(TEXMAP) || defined(BLEND_ALPHA) || defined(BLEND_ADD)
int cr, cg, cb;
#endif
#ifdef BLEND_ALPHA
int alpha, inv_alpha;
#endif
+
+#ifdef ZBUF
+ int32_t cz = z;
+ z += zslope;
+
+ if(z <= *zptr) {
+ *zptr++ = z;
+ } else {
+#ifdef GOURAUD
+ r += rslope;
+ g += gslope;
+ b += bslope;
+#ifdef BLEND_ALPHA
+ a += aslope;
+#endif
+#endif
+#ifdef TEXMAP
+ u += uslope;
+ v += vslope;
+#endif
+ /* skip pixel */
+ pixptr++;
+ zptr++;
+ x += 256;
+ continue;
+ }
+#endif
+
#ifdef GOURAUD
/* we upped the color precision to while interpolating the
* edges, now drop the extra bits before packing