5 #if defined(__WATCOMC__) || defined(_WIN32) || defined(__DJGPP__)
13 #define FILL_POLY_BITS 0x03
15 /* mode bits: 00-wire 01-flat 10-gouraud 11-reserved
17 * bit 3-4: blend mode: 00-none 01-alpha 10-additive 11-reserved
19 void (*fillfunc[])(struct pvertex*, int) = {
30 polyfill_alpha_gouraud,
32 polyfill_alpha_tex_wire,
33 polyfill_alpha_tex_flat,
34 polyfill_alpha_tex_gouraud,
40 polyfill_add_tex_wire,
41 polyfill_add_tex_flat,
42 polyfill_add_tex_gouraud,
43 0, 0, 0, 0, 0, 0, 0, 0, 0
46 struct pimage pfill_fb, pfill_tex;
49 static struct pvertex *edgebuf, *left, *right;
50 static int edgebuf_size;
54 #define CHECKEDGE(x) \
57 assert(x < fbheight); \
63 void polyfill_fbheight(int height)
66 int newsz = (height * 2 + EDGEPAD * 3) * sizeof *edgebuf;
68 if(newsz > edgebuf_size) {
70 if(!(edgebuf = malloc(newsz))) {
71 fprintf(stderr, "failed to allocate edge table buffer (%d bytes)\n", newsz);
76 left = edgebuf + EDGEPAD;
77 right = edgebuf + height + EDGEPAD * 2;
80 memset(edgebuf, 0xaa, EDGEPAD * sizeof *edgebuf);
81 memset(edgebuf + height + EDGEPAD, 0xaa, EDGEPAD * sizeof *edgebuf);
82 memset(edgebuf + height * 2 + EDGEPAD * 2, 0xaa, EDGEPAD * sizeof *edgebuf);
89 void polyfill(int mode, struct pvertex *verts, int nverts)
93 fprintf(stderr, "polyfill mode %d not implemented\n", mode);
98 fillfunc[mode](verts, nverts);
101 void polyfill_wire(struct pvertex *verts, int nverts)
103 int i, x0, y0, x1, y1;
104 struct pvertex *v = verts;
105 unsigned short color = ((v->r << 8) & 0xf800) |
106 ((v->g << 3) & 0x7e0) | ((v->b >> 3) & 0x1f);
108 for(i=0; i<nverts - 1; i++) {
114 if(clip_line(&x0, &y0, &x1, &y1, 0, 0, pfill_fb.width, pfill_fb.height)) {
115 draw_line(x0, y0, x1, y1, color);
118 x0 = verts[0].x >> 8;
119 y0 = verts[0].y >> 8;
120 if(clip_line(&x1, &y1, &x0, &y0, 0, 0, pfill_fb.width, pfill_fb.height)) {
121 draw_line(x1, y1, x0, y0, color);
125 void polyfill_tex_wire(struct pvertex *verts, int nverts)
127 polyfill_wire(verts, nverts); /* TODO */
130 void polyfill_alpha_wire(struct pvertex *verts, int nverts)
132 polyfill_wire(verts, nverts); /* TODO */
135 void polyfill_alpha_tex_wire(struct pvertex *verts, int nverts)
137 polyfill_wire(verts, nverts); /* TODO */
140 void polyfill_add_wire(struct pvertex *verts, int nverts)
142 polyfill_wire(verts, nverts); /* TODO */
145 void polyfill_add_tex_wire(struct pvertex *verts, int nverts)
147 polyfill_wire(verts, nverts); /* TODO */
150 #define NEXTIDX(x) (((x) - 1 + nverts) % nverts)
151 #define PREVIDX(x) (((x) + 1) % nverts)
154 * When HIGH_QUALITY is defined, the rasterizer calculates slopes for attribute
155 * interpolation on each scanline separately; otherwise the slope for each
156 * attribute would be calculated once for the whole polygon, which is faster,
157 * but produces some slight quantization artifacts, due to the limited precision
158 * of fixed-point calculations.
162 /* extra bits of precision to use when interpolating colors.
163 * try tweaking this if you notice strange quantization artifacts.
165 #define COLOR_SHIFT 12
168 #define POLYFILL polyfill_flat
169 #define SCANEDGE scanedge_flat
174 #include "polytmpl.h"
178 #define POLYFILL polyfill_gouraud
179 #define SCANEDGE scanedge_gouraud
184 #include "polytmpl.h"
188 #define POLYFILL polyfill_tex_flat
189 #define SCANEDGE scanedge_tex_flat
194 #include "polytmpl.h"
198 #define POLYFILL polyfill_tex_gouraud
199 #define SCANEDGE scanedge_tex_gouraud
204 #include "polytmpl.h"
208 #define POLYFILL polyfill_alpha_flat
209 #define SCANEDGE scanedge_alpha_flat
214 #include "polytmpl.h"
218 #define POLYFILL polyfill_alpha_gouraud
219 #define SCANEDGE scanedge_alpha_gouraud
224 #include "polytmpl.h"
228 #define POLYFILL polyfill_alpha_tex_flat
229 #define SCANEDGE scanedge_alpha_tex_flat
234 #include "polytmpl.h"
238 #define POLYFILL polyfill_alpha_tex_gouraud
239 #define SCANEDGE scanedge_alpha_tex_gouraud
244 #include "polytmpl.h"
248 #define POLYFILL polyfill_add_flat
249 #define SCANEDGE scanedge_add_flat
254 #include "polytmpl.h"
258 #define POLYFILL polyfill_add_gouraud
259 #define SCANEDGE scanedge_add_gouraud
264 #include "polytmpl.h"
268 #define POLYFILL polyfill_add_tex_flat
269 #define SCANEDGE scanedge_add_tex_flat
274 #include "polytmpl.h"
278 #define POLYFILL polyfill_add_tex_gouraud
279 #define SCANEDGE scanedge_add_tex_gouraud
284 #include "polytmpl.h"