7 void (*fillfunc[])(struct pvertex*, int) = {
13 void polyfill(int mode, struct pvertex *verts, int nverts)
17 fprintf(stderr, "polyfill mode %d not implemented\n", mode);
22 fillfunc[mode](verts, nverts);
25 void polyfill_wire(struct pvertex *verts, int nverts)
27 int i, x0, y0, x1, y1;
28 struct pvertex *v = verts;
29 unsigned short color = ((v->r << 8) & 0xf800) |
30 ((v->g << 3) & 0x7e0) | ((v->b >> 3) & 0x1f);
32 for(i=0; i<nverts - 1; i++) {
38 if(clip_line(&x0, &y0, &x1, &y1, 0, 0, fb_width, fb_height)) {
39 draw_line(x0, y0, x1, y1, color);
44 if(clip_line(&x1, &y1, &x0, &y0, 0, 0, fb_width, fb_height)) {
45 draw_line(x1, y1, x0, y0, color);
49 #define NEXTIDX(x) ((x) ? (x) - 1 : nverts - 1)
50 #define PREVIDX(x) (((x) + 1) % nverts)
52 #define CALC_EDGE(which) \
54 which##_x = pv[which##_beg].x; \
55 which##_dx = pv[which##_end].x - pv[which##_beg].x; \
56 which##_slope = (which##_dx << 8) / which##_dy; \
59 void polyfill_flat(struct pvertex *pv, int nverts)
61 int i, sline, x, slen, top = 0;
62 int left_beg, left_end, right_beg, right_end;
63 int32_t left_dy, left_dx, right_dy, right_dx;
64 int32_t left_slope, right_slope;
65 int32_t left_x, right_x, y;
66 uint16_t color = ((pv->r << 8) & 0xf800) | ((pv->g << 3) & 0x7e0) |
67 ((pv->b >> 3) & 0x1f);
71 for(i=1; i<nverts; i++) {
72 if(pv[i].y < pv[top].y) {
76 left_beg = right_beg = top;
77 left_end = PREVIDX(left_beg);
78 right_end = NEXTIDX(right_beg);
80 if((left_dy = pv[left_end].y - pv[left_beg].y)) {
84 if((right_dy = pv[right_end].y - pv[right_beg].y)) {
89 sline = pv[top].y >> 8;
92 if(y >= pv[left_end].y) {
93 while(y >= pv[left_end].y) {
95 if(left_beg == right_beg) return;
96 left_end = PREVIDX(left_end);
99 left_dy = pv[left_end].y - pv[left_beg].y;
103 if(y >= pv[right_end].y) {
104 while(y >= pv[right_end].y) {
105 right_beg = right_end;
106 if(left_beg == right_beg) return;
107 right_end = NEXTIDX(right_end);
110 right_dy = pv[right_end].y - pv[right_beg].y;
115 slen = (right_x >> 8) - (left_x >> 8);
117 pixptr = (uint16_t*)fb_pixels + sline * fb_width + x;
118 for(i=0; i<slen; i++) {
124 left_x += left_slope;
125 right_x += right_slope;