X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;ds=sidebyside;f=src%2Fpolytmpl.h;h=f36b288a1c24470d6bc743fe8b583d23f84af151;hb=b6c89d9ffbb08c5286448de4773290f0924a420b;hp=12df420c66295c1ec22768087cd52d1be309cead;hpb=1723e332319e7732473814dfc168a13d0bafccb4;p=dosdemo diff --git a/src/polytmpl.h b/src/polytmpl.h index 12df420..f36b288 100644 --- a/src/polytmpl.h +++ b/src/polytmpl.h @@ -69,7 +69,7 @@ static uint32_t SCANEDGE(struct pvertex *v0, struct pvertex *v1, struct pvertex void POLYFILL(struct pvertex *pv, int nverts) { - int i; + int i, winding; int topidx = 0, botidx = 0, sltop = pfill_fb.height, slbot = 0; struct pvertex *left, *right; uint16_t color; @@ -93,6 +93,12 @@ void POLYFILL(struct pvertex *pv, int nverts) if(pv[i].y > pv[botidx].y) botidx = i; } + winding = 0; + for(i=0; i> 4) * ((pv[next].y + pv[i].y) >> 4); + } + /* +1 to avoid crashing due to off-by-one rounding errors in the rasterization */ left = alloca((pfill_fb.height + 1) * sizeof *left); right = alloca((pfill_fb.height + 1) * sizeof *right); @@ -133,9 +139,18 @@ void POLYFILL(struct pvertex *pv, int nverts) if(idx < sltop) sltop = idx; /*}*/ } else { - struct pvertex *edge = y0 > y1 ? left : right; - uint32_t res = SCANEDGE(pv + i, pv + next, edge); - uint32_t tmp = (res >> 16) & 0xffff; + struct pvertex *edge; + uint32_t res, tmp; + + if(winding < 0) { + // clockwise + edge = y0 > y1 ? left : right; + } else { + // counter-clockwise + edge = y0 > y1 ? right : left; + } + res = SCANEDGE(pv + i, pv + next, edge); + tmp = (res >> 16) & 0xffff; if(tmp > slbot) slbot = tmp; if((tmp = res & 0xffff) < sltop) { sltop = tmp;