X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fgaw%2Fpolyfill.c;h=e6a87f62a937b525f474e29320fb3db15980c5fb;hb=15a4548ff09afb37dd33786cafd50b060a64f840;hp=efdee716aad4951e7aa9571fcc7a0c459976c719;hpb=b0088adf036a53139f67ebf96f1bbb55abf199f4;p=retroray diff --git a/src/gaw/polyfill.c b/src/gaw/polyfill.c index efdee71..e6a87f6 100644 --- a/src/gaw/polyfill.c +++ b/src/gaw/polyfill.c @@ -56,27 +56,27 @@ void (*fillfunc[])(struct pvertex*, int) = { polyfill_add_tex_flat, polyfill_add_tex_gouraud, 0, 0, 0, 0, 0, 0, 0, 0, 0, - polyfill_wire, + polyfill_wire_zbuf, polyfill_flat_zbuf, polyfill_gouraud_zbuf, 0, - polyfill_tex_wire, + polyfill_tex_wire_zbuf, polyfill_tex_flat_zbuf, polyfill_tex_gouraud_zbuf, 0, - polyfill_alpha_wire, + polyfill_alpha_wire_zbuf, polyfill_alpha_flat_zbuf, polyfill_alpha_gouraud_zbuf, 0, - polyfill_alpha_tex_wire, + polyfill_alpha_tex_wire_zbuf, polyfill_alpha_tex_flat_zbuf, polyfill_alpha_tex_gouraud_zbuf, 0, - polyfill_add_wire, + polyfill_add_wire_zbuf, polyfill_add_flat_zbuf, polyfill_add_gouraud_zbuf, 0, - polyfill_add_tex_wire, + polyfill_add_tex_wire_zbuf, polyfill_add_tex_flat_zbuf, polyfill_add_tex_gouraud_zbuf, 0, 0, 0, 0, 0, 0, 0, 0, 0 @@ -139,27 +139,7 @@ void polyfill(int mode, struct pvertex *verts, int nverts) void polyfill_wire(struct pvertex *verts, int nverts) { - /* - int i, x0, y0, x1, y1; - struct pvertex *v = verts; - uint32_t color = PACK_RGB(v->r, v->g, v->b); - - for(i=0; ix >> 8; - y0 = v->y >> 8; - ++v; - x1 = v->x >> 8; - y1 = v->y >> 8; - 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, pfill_fb.width, pfill_fb.height)) { - draw_line(x1, y1, x0, y0, color); - } - */ + draw_line(verts); } void polyfill_tex_wire(struct pvertex *verts, int nverts) @@ -187,6 +167,37 @@ void polyfill_add_tex_wire(struct pvertex *verts, int nverts) polyfill_wire(verts, nverts); /* TODO */ } +void polyfill_wire_zbuf(struct pvertex *verts, int nverts) +{ + draw_line_zbuf(verts); +} + +void polyfill_tex_wire_zbuf(struct pvertex *verts, int nverts) +{ + polyfill_wire_zbuf(verts, nverts); /* TODO */ +} + +void polyfill_alpha_wire_zbuf(struct pvertex *verts, int nverts) +{ + polyfill_wire_zbuf(verts, nverts); /* TODO */ +} + +void polyfill_alpha_tex_wire_zbuf(struct pvertex *verts, int nverts) +{ + polyfill_wire_zbuf(verts, nverts); /* TODO */ +} + +void polyfill_add_wire_zbuf(struct pvertex *verts, int nverts) +{ + polyfill_wire_zbuf(verts, nverts); /* TODO */ +} + +void polyfill_add_tex_wire_zbuf(struct pvertex *verts, int nverts) +{ + polyfill_wire_zbuf(verts, nverts); /* TODO */ +} + + #define VNEXT(p) (((p) == vlast) ? varr : (p) + 1) #define VPREV(p) ((p) == varr ? vlast : (p) - 1) #define VSUCC(p, side) ((side) == 0 ? VNEXT(p) : VPREV(p)) @@ -415,3 +426,136 @@ void polyfill_add_tex_wire(struct pvertex *verts, int nverts) #include "polytmpl.h" #undef POLYFILL + +void draw_line(struct pvertex *verts) +{ + int32_t x0, y0, x1, y1; + int i, dx, dy, x_inc, y_inc, error; + uint32_t *fb = pfill_fb.pixels; + uint32_t color = PACK_RGB(verts[0].r, verts[0].g, verts[0].b); + + x0 = verts[0].x >> 8; + y0 = verts[0].y >> 8; + x1 = verts[1].x >> 8; + y1 = verts[1].y >> 8; + + fb += y0 * pfill_fb.width + x0; + + dx = x1 - x0; + dy = y1 - y0; + + if(dx >= 0) { + x_inc = 1; + } else { + x_inc = -1; + dx = -dx; + } + if(dy >= 0) { + y_inc = pfill_fb.width; + } else { + y_inc = -pfill_fb.width; + dy = -dy; + } + + if(dx > dy) { + error = dy * 2 - dx; + for(i=0; i<=dx; i++) { + *fb = color; + if(error >= 0) { + error -= dx * 2; + fb += y_inc; + } + error += dy * 2; + fb += x_inc; + } + } else { + error = dx * 2 - dy; + for(i=0; i<=dy; i++) { + *fb = color; + if(error >= 0) { + error -= dy * 2; + fb += x_inc; + } + error += dx * 2; + fb += y_inc; + } + } +} + +void draw_line_zbuf(struct pvertex *verts) +{ + int32_t x0, y0, x1, y1, z0, z1, z, dz, zslope; + int i, dx, dy, x_inc, y_inc, error; + uint32_t *fb = pfill_fb.pixels; + uint32_t *zptr = pfill_zbuf; + uint32_t color = PACK_RGB(verts[0].r, verts[0].g, verts[0].b); + + x0 = verts[0].x >> 8; + y0 = verts[0].y >> 8; + x1 = verts[1].x >> 8; + y1 = verts[1].y >> 8; + z0 = verts[0].z; + z1 = verts[1].z; + + fb += y0 * pfill_fb.width + x0; + zptr += y0 * pfill_fb.width + x0; + + dx = x1 - x0; + dy = y1 - y0; + dz = z1 - z0; + + if(dx >= 0) { + x_inc = 1; + } else { + x_inc = -1; + dx = -dx; + } + if(dy >= 0) { + y_inc = pfill_fb.width; + } else { + y_inc = -pfill_fb.width; + dy = -dy; + } + + z = z0; + + if(dx > dy) { + zslope = dx ? (dz << 8) / (verts[1].x - verts[0].x) : 0; + error = dy * 2 - dx; + for(i=0; i<=dx; i++) { + if(z <= *zptr) { + *fb = color; + *zptr = z; + } + if(error >= 0) { + error -= dx * 2; + fb += y_inc; + zptr += y_inc; + } + error += dy * 2; + fb += x_inc; + + zptr += x_inc; + z += zslope; + } + } else { + zslope = dy ? (dz << 8) / (verts[1].y - verts[0].y) : 0; + error = dx * 2 - dy; + for(i=0; i<=dy; i++) { + if(z <= *zptr) { + *fb = color; + *zptr = z; + } + if(error >= 0) { + error -= dy * 2; + fb += x_inc; + zptr += x_inc; + } + error += dx * 2; + fb += y_inc; + + zptr += y_inc; + z += zslope; + } + } +}