X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2Fpolyfill.c;h=3f94e25849e41bb9d30fcb444b2c547b0c7137df;hp=79d1d69ce0cee61da8450aa34b5fdd6aaad054ea;hb=5f36e95f19ad8d7a5a1dd546ffeb54ce95d51749;hpb=0945eeeef21fe85f9a592bfc2e41069a7894b08b diff --git a/src/polyfill.c b/src/polyfill.c index 79d1d69..3f94e25 100644 --- a/src/polyfill.c +++ b/src/polyfill.c @@ -1,16 +1,41 @@ #include #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) { @@ -37,93 +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); } } -#define NEXTIDX(x) (((x) - 1 + nverts) % nverts) -#define PREVIDX(x) (((x) + 1) % nverts) - -#define CALC_EDGE(which) \ - do { \ - which##_x = pv[which##_beg].x; \ - which##_dx = pv[which##_end].x - pv[which##_beg].x; \ - which##_slope = (which##_dx << 8) / which##_dy; \ - } while(0) - -void polyfill_flat(struct pvertex *pv, int nverts) +void polyfill_tex_wire(struct pvertex *verts, int nverts) { - int i, sline, x, slen, top = 0; - int left_beg, left_end, right_beg, right_end; - int32_t left_dy, left_dx, right_dy, right_dx; - int32_t left_slope, right_slope; - int32_t left_x, right_x, y; - uint16_t color = ((pv->r << 8) & 0xf800) | ((pv->g << 3) & 0x7e0) | - ((pv->b >> 3) & 0x1f); - uint16_t *pixptr; - - /* find topmost */ - for(i=1; i> 8; - - for(;;) { - if(y >= pv[left_end].y) { - while(y >= pv[left_end].y) { - left_beg = left_end; - if(left_beg == right_beg) return; - left_end = PREVIDX(left_end); - } - - left_dy = pv[left_end].y - pv[left_beg].y; - CALC_EDGE(left); - } - - if(y >= pv[right_end].y) { - while(y >= pv[right_end].y) { - right_beg = right_end; - if(left_beg == right_beg) return; - right_end = NEXTIDX(right_end); - } + polyfill_wire(verts, nverts); /* TODO */ +} - right_dy = pv[right_end].y - pv[right_beg].y; - CALC_EDGE(right); - } +void polyfill_blend_wire(struct pvertex *verts, int nverts) +{ + polyfill_wire(verts, nverts); /* TODO */ +} - x = left_x >> 8; - slen = (right_x >> 8) - (left_x >> 8); +void polyfill_blend_tex_wire(struct pvertex *verts, int nverts) +{ + polyfill_wire(verts, nverts); /* TODO */ +} - pixptr = pimg_fb.pixels + sline * pimg_fb.width + x; - for(i=0; i