10 void (*fillfunc[])(struct pvertex*, int) = {
16 struct pimage pimg_fb, pimg_texture;
18 void polyfill(int mode, struct pvertex *verts, int nverts)
22 fprintf(stderr, "polyfill mode %d not implemented\n", mode);
27 fillfunc[mode](verts, nverts);
30 void polyfill_wire(struct pvertex *verts, int nverts)
32 int i, x0, y0, x1, y1;
33 struct pvertex *v = verts;
34 unsigned short color = ((v->r << 8) & 0xf800) |
35 ((v->g << 3) & 0x7e0) | ((v->b >> 3) & 0x1f);
37 for(i=0; i<nverts - 1; i++) {
43 if(clip_line(&x0, &y0, &x1, &y1, 0, 0, pimg_fb.width, pimg_fb.height)) {
44 draw_line(x0, y0, x1, y1, color);
49 if(clip_line(&x1, &y1, &x0, &y0, 0, 0, pimg_fb.width, pimg_fb.height)) {
50 draw_line(x1, y1, x0, y0, color);
54 static void scan_edge(struct pvertex *v0, struct pvertex *v1, struct pvertex *edge);
56 #define NEXTIDX(x) (((x) - 1 + nverts) % nverts)
57 #define PREVIDX(x) (((x) + 1) % nverts)
59 void polyfill_flat(struct pvertex *pv, int nverts)
63 int topidx = 0, botidx = 0, sline;
64 struct pvertex *left, *right;
65 /*uint16_t color = PACK_RGB16(pv[0].r, pv[0].g, pv[0].b);*/
67 for(i=1; i<nverts; i++) {
68 if(pv[i].y < pv[topidx].y) topidx = i;
69 if(pv[i].y > pv[botidx].y) botidx = i;
72 left = (struct pvertex*)alloca(pimg_fb.height * sizeof *left);
73 right = (struct pvertex*)alloca(pimg_fb.height * sizeof *right);
74 memset(left, 0, pimg_fb.height * sizeof *left);
75 memset(right, 0, pimg_fb.height * sizeof *right);
77 for(i=0; i<nverts; i++) {
78 int next = NEXTIDX(i);
80 int32_t y1 = pv[next].y;
82 if((y0 >> 8) == (y1 >> 8)) {
85 left[idx].x = pv[i].x < pv[next].x ? pv[i].x : pv[next].x;
86 right[idx].x = pv[i].x < pv[next].x ? pv[next].x : pv[i].x;
89 scan_edge(pv + i, pv + next, y0 > y1 ? left : right);
94 while(y < pv[botidx].y) {
101 pixptr = pimg_fb.pixels + sline * pimg_fb.width + (x >> 8);
103 while(x <= right[sline].x) {
111 static void scan_edge(struct pvertex *v0, struct pvertex *v1, struct pvertex *edge)
113 int32_t x, y, dx, dy, slope;
117 struct pvertex *tmp = v0;
124 slope = (dx << 8) / dy;