X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2Fpolyfill.c;h=3f94e25849e41bb9d30fcb444b2c547b0c7137df;hp=122b23491f3013278917f50d5356c9e472581491;hb=d956a9d9273eebfacfda58cb3bafff017269d5dc;hpb=dce48eb322ddf2a3c3622fc132ece21ba7653da3 diff --git a/src/polyfill.c b/src/polyfill.c index 122b234..3f94e25 100644 --- a/src/polyfill.c +++ b/src/polyfill.c @@ -2,18 +2,40 @@ #include #include #include +#if defined(__WATCOMC__) || defined(_MSC_VER) || defined(__DJGPP__) +#include +#else #include +#endif #include "polyfill.h" #include "gfxutil.h" -#include "demo.h" +#define FILL_POLY_BITS 0x03 + +/* mode bits: 00-wire 01-flat 10-gouraud 11-reserved + * bit 2: texture + * bit 3: blend + */ void (*fillfunc[])(struct pvertex*, int) = { polyfill_wire, polyfill_flat, - 0, 0, 0 + polyfill_gouraud, + 0, + polyfill_tex_wire, + polyfill_tex_flat, + polyfill_tex_gouraud, + 0, + polyfill_blend_wire, + polyfill_blend_flat, + polyfill_blend_gouraud, + 0, + polyfill_blend_tex_wire, + polyfill_blend_tex_flat, + polyfill_blend_tex_gouraud, + 0 }; -struct pimage pimg_fb, pimg_texture; +struct pimage pfill_fb, pfill_tex; void polyfill(int mode, struct pvertex *verts, int nverts) { @@ -40,103 +62,118 @@ void polyfill_wire(struct pvertex *verts, int nverts) ++v; x1 = v->x >> 8; y1 = v->y >> 8; - if(clip_line(&x0, &y0, &x1, &y1, 0, 0, pimg_fb.width, pimg_fb.height)) { + if(clip_line(&x0, &y0, &x1, &y1, 0, 0, pfill_fb.width, pfill_fb.height)) { draw_line(x0, y0, x1, y1, color); } } x0 = verts[0].x >> 8; y0 = verts[0].y >> 8; - if(clip_line(&x1, &y1, &x0, &y0, 0, 0, pimg_fb.width, pimg_fb.height)) { + if(clip_line(&x1, &y1, &x0, &y0, 0, 0, pfill_fb.width, pfill_fb.height)) { draw_line(x1, y1, x0, y0, color); } } -static uint32_t scan_edge(struct pvertex *v0, struct pvertex *v1, struct pvertex *edge); - -#define NEXTIDX(x) (((x) - 1 + nverts) % nverts) -#define PREVIDX(x) (((x) + 1) % nverts) - -void polyfill_flat(struct pvertex *pv, int nverts) +void polyfill_tex_wire(struct pvertex *verts, int nverts) { - int i; - int topidx = 0, botidx = 0, sltop = pimg_fb.height, slbot = 0; - struct pvertex *left, *right; - uint16_t color = PACK_RGB16(pv[0].r, pv[0].g, pv[0].b); - - for(i=1; i pv[botidx].y) botidx = i; - } - - left = (struct pvertex*)alloca(pimg_fb.height * sizeof *left); - right = (struct pvertex*)alloca(pimg_fb.height * sizeof *right); - memset(left, 0, pimg_fb.height * sizeof *left); - memset(right, 0, pimg_fb.height * sizeof *right); - - for(i=0; i> 8) == (y1 >> 8)) { - if(y0 > y1) { - int idx = y0 >> 8; - left[idx].x = pv[i].x < pv[next].x ? pv[i].x : pv[next].x; - right[idx].x = pv[i].x < pv[next].x ? pv[next].x : pv[i].x; - } - } else { - struct pvertex *edge = y0 > y1 ? left : right; - uint32_t res = scan_edge(pv + i, pv + next, edge); - uint32_t tmp = (res >> 16) & 0xffff; - if(tmp > slbot) slbot = tmp; - if((tmp = res & 0xffff) < sltop) { - sltop = tmp; - } - } - } - - for(i=sltop; i<=slbot; i++) { - int32_t x; - uint16_t *pixptr; - - x = left[i].x; - pixptr = pimg_fb.pixels + i * pimg_fb.width + (x >> 8); - - while(x <= right[i].x) { -#ifdef DEBUG_POLYFILL - *pixptr++ += 15; -#else - *pixptr++ = color; -#endif - x += 256; - } - } + polyfill_wire(verts, nverts); /* TODO */ } -static uint32_t scan_edge(struct pvertex *v0, struct pvertex *v1, struct pvertex *edge) +void polyfill_blend_wire(struct pvertex *verts, int nverts) { - int i; - int32_t x, dx, dy, slope; - int32_t start_idx, end_idx; - - if(v0->y > v1->y) { - struct pvertex *tmp = v0; - v0 = v1; - v1 = tmp; - } - - dy = v1->y - v0->y; - dx = v1->x - v0->x; - slope = (dx << 8) / dy; + polyfill_wire(verts, nverts); /* TODO */ +} - start_idx = v0->y >> 8; - end_idx = v1->y >> 8; +void polyfill_blend_tex_wire(struct pvertex *verts, int nverts) +{ + polyfill_wire(verts, nverts); /* TODO */ +} - x = v0->x; - for(i=start_idx; i