5 #if defined(__WATCOMC__) || defined(_MSC_VER)
14 void (*fillfunc[])(struct pvertex*, int) = {
20 struct pimage pimg_fb, pimg_texture;
22 void polyfill(int mode, struct pvertex *verts, int nverts)
26 fprintf(stderr, "polyfill mode %d not implemented\n", mode);
31 fillfunc[mode](verts, nverts);
34 void polyfill_wire(struct pvertex *verts, int nverts)
36 int i, x0, y0, x1, y1;
37 struct pvertex *v = verts;
38 unsigned short color = ((v->r << 8) & 0xf800) |
39 ((v->g << 3) & 0x7e0) | ((v->b >> 3) & 0x1f);
41 for(i=0; i<nverts - 1; i++) {
47 if(clip_line(&x0, &y0, &x1, &y1, 0, 0, pimg_fb.width, pimg_fb.height)) {
48 draw_line(x0, y0, x1, y1, color);
53 if(clip_line(&x1, &y1, &x0, &y0, 0, 0, pimg_fb.width, pimg_fb.height)) {
54 draw_line(x1, y1, x0, y0, color);
58 static uint32_t scan_edge(struct pvertex *v0, struct pvertex *v1, struct pvertex *edge);
60 #define NEXTIDX(x) (((x) - 1 + nverts) % nverts)
61 #define PREVIDX(x) (((x) + 1) % nverts)
63 void polyfill_flat(struct pvertex *pv, int nverts)
66 int topidx = 0, botidx = 0, sltop = pimg_fb.height, slbot = 0;
67 struct pvertex *left, *right;
68 uint16_t color = PACK_RGB16(pv[0].r, pv[0].g, pv[0].b);
70 for(i=1; i<nverts; i++) {
71 if(pv[i].y < pv[topidx].y) topidx = i;
72 if(pv[i].y > pv[botidx].y) botidx = i;
75 left = (struct pvertex*)alloca(pimg_fb.height * sizeof *left);
76 right = (struct pvertex*)alloca(pimg_fb.height * sizeof *right);
77 memset(left, 0, pimg_fb.height * sizeof *left);
78 memset(right, 0, pimg_fb.height * sizeof *right);
80 for(i=0; i<nverts; i++) {
81 int next = NEXTIDX(i);
83 int32_t y1 = pv[next].y;
85 if((y0 >> 8) == (y1 >> 8)) {
88 left[idx].x = pv[i].x < pv[next].x ? pv[i].x : pv[next].x;
89 right[idx].x = pv[i].x < pv[next].x ? pv[next].x : pv[i].x;
92 struct pvertex *edge = y0 > y1 ? left : right;
93 uint32_t res = scan_edge(pv + i, pv + next, edge);
94 uint32_t tmp = (res >> 16) & 0xffff;
95 if(tmp > slbot) slbot = tmp;
96 if((tmp = res & 0xffff) < sltop) {
102 for(i=sltop; i<=slbot; i++) {
107 pixptr = pimg_fb.pixels + i * pimg_fb.width + (x >> 8);
109 while(x <= right[i].x) {
110 #ifdef DEBUG_POLYFILL
120 static uint32_t scan_edge(struct pvertex *v0, struct pvertex *v1, struct pvertex *edge)
123 int32_t x, dx, dy, slope;
124 int32_t start_idx, end_idx;
127 struct pvertex *tmp = v0;
134 slope = (dx << 8) / dy;
136 start_idx = v0->y >> 8;
137 end_idx = v1->y >> 8;
140 for(i=start_idx; i<end_idx; i++) {
145 return (uint32_t)start_idx | ((uint32_t)(end_idx - 1) << 16);