X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2F3dgfx%2Fpolytmpl.h;h=167d5e1381105d50145d0109695963cf7c382cb8;hp=2072e2b5f19e01b4279084b83f2278e847f3f7b5;hb=7705fa326336feba1a66d5a6ca8a7c27771e4c5f;hpb=57bd2dc519c47f434e3e5acf998fb9c72448cbce diff --git a/src/3dgfx/polytmpl.h b/src/3dgfx/polytmpl.h index 2072e2b..167d5e1 100644 --- a/src/3dgfx/polytmpl.h +++ b/src/3dgfx/polytmpl.h @@ -12,6 +12,9 @@ static uint32_t SCANEDGE(struct pvertex *v0, struct pvertex *v1, struct pvertex #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) { @@ -48,6 +51,11 @@ static uint32_t SCANEDGE(struct pvertex *v0, struct pvertex *v1, struct pvertex 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; @@ -58,7 +66,6 @@ static uint32_t SCANEDGE(struct pvertex *v0, struct pvertex *v1, struct pvertex 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; @@ -66,18 +73,20 @@ static uint32_t SCANEDGE(struct pvertex *v0, struct pvertex *v1, struct pvertex 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); @@ -89,7 +98,7 @@ void POLYFILL(struct pvertex *pv, int nverts) 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 @@ -105,6 +114,9 @@ void POLYFILL(struct pvertex *pv, int nverts) #ifdef TEXMAP int32_t u, v, du, dv, uslope, vslope; #endif +#ifdef ZBUF + int32_t z, dz, zslope; +#endif for(i=1; i slbot) slbot = idx; if(idx < sltop) sltop = idx; @@ -217,12 +233,19 @@ void POLYFILL(struct pvertex *pv, int nverts) 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; @@ -240,9 +263,13 @@ void POLYFILL(struct pvertex *pv, int nverts) 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); @@ -264,11 +291,18 @@ void POLYFILL(struct pvertex *pv, int nverts) 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 @@ -278,6 +312,34 @@ void POLYFILL(struct pvertex *pv, int nverts) #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