[1] | 1 | { |
---|
| 2 | int n, dx, dy, sx, pp_inc_1, pp_inc_2; |
---|
| 3 | register int a; |
---|
| 4 | register PIXEL *pp; |
---|
| 5 | #if defined(INTERP_RGB) || TGL_FEATURE_RENDER_BITS == 24 |
---|
| 6 | register unsigned int r, g, b; |
---|
| 7 | #endif |
---|
| 8 | #ifdef INTERP_RGB |
---|
| 9 | register unsigned int rinc, ginc, binc; |
---|
| 10 | #endif |
---|
| 11 | #ifdef INTERP_Z |
---|
| 12 | register unsigned short *pz; |
---|
| 13 | int zinc; |
---|
| 14 | register int z, zz; |
---|
| 15 | #endif |
---|
| 16 | |
---|
| 17 | if (p1->y > p2->y || (p1->y == p2->y && p1->x > p2->x)) { |
---|
| 18 | ZBufferPoint *tmp; |
---|
| 19 | tmp = p1; |
---|
| 20 | p1 = p2; |
---|
| 21 | p2 = tmp; |
---|
| 22 | } |
---|
| 23 | sx = zb->xsize; |
---|
| 24 | pp = (PIXEL *) ((char *) zb->pbuf + zb->linesize * p1->y + p1->x * PSZB); |
---|
| 25 | #ifdef INTERP_Z |
---|
| 26 | pz = zb->zbuf + (p1->y * sx + p1->x); |
---|
| 27 | z = p1->z; |
---|
| 28 | #endif |
---|
| 29 | |
---|
| 30 | dx = p2->x - p1->x; |
---|
| 31 | dy = p2->y - p1->y; |
---|
| 32 | #ifdef INTERP_RGB |
---|
| 33 | r = p2->r << 8; |
---|
| 34 | g = p2->g << 8; |
---|
| 35 | b = p2->b << 8; |
---|
| 36 | #elif TGL_FEATURE_RENDER_BITS == 24 |
---|
| 37 | /* for 24 bits, we store the colors in different variables */ |
---|
| 38 | r = p2->r >> 8; |
---|
| 39 | g = p2->g >> 8; |
---|
| 40 | b = p2->b >> 8; |
---|
| 41 | #endif |
---|
| 42 | |
---|
| 43 | #ifdef INTERP_RGB |
---|
| 44 | #define RGB(x) x |
---|
| 45 | #if TGL_FEATURE_RENDER_BITS == 24 |
---|
| 46 | #define RGBPIXEL pp[0] = r >> 16, pp[1] = g >> 16, pp[2] = b >> 16 |
---|
| 47 | #else |
---|
| 48 | #define RGBPIXEL *pp = RGB_TO_PIXEL(r >> 8,g >> 8,b >> 8) |
---|
| 49 | #endif |
---|
| 50 | #else /* INTERP_RGB */ |
---|
| 51 | #define RGB(x) |
---|
| 52 | #if TGL_FEATURE_RENDER_BITS == 24 |
---|
| 53 | #define RGBPIXEL pp[0] = r, pp[1] = g, pp[2] = b |
---|
| 54 | #else |
---|
| 55 | #define RGBPIXEL *pp = color |
---|
| 56 | #endif |
---|
| 57 | #endif /* INTERP_RGB */ |
---|
| 58 | |
---|
| 59 | #ifdef INTERP_Z |
---|
| 60 | #define ZZ(x) x |
---|
| 61 | #define PUTPIXEL() \ |
---|
| 62 | { \ |
---|
| 63 | zz=z >> ZB_POINT_Z_FRAC_BITS; \ |
---|
| 64 | if (ZCMP(zz,*pz)) { \ |
---|
| 65 | RGBPIXEL; \ |
---|
| 66 | *pz=zz; \ |
---|
| 67 | } \ |
---|
| 68 | } |
---|
| 69 | #else /* INTERP_Z */ |
---|
| 70 | #define ZZ(x) |
---|
| 71 | #define PUTPIXEL() RGBPIXEL |
---|
| 72 | #endif /* INTERP_Z */ |
---|
| 73 | |
---|
| 74 | #define DRAWLINE(dx,dy,inc_1,inc_2) \ |
---|
| 75 | n=dx;\ |
---|
| 76 | ZZ(zinc=(p2->z-p1->z)/n);\ |
---|
| 77 | RGB(rinc=((p2->r-p1->r) << 8)/n;\ |
---|
| 78 | ginc=((p2->g-p1->g) << 8)/n;\ |
---|
| 79 | binc=((p2->b-p1->b) << 8)/n);\ |
---|
| 80 | a=2*dy-dx;\ |
---|
| 81 | dy=2*dy;\ |
---|
| 82 | dx=2*dx-dy;\ |
---|
| 83 | pp_inc_1 = (inc_1) * PSZB;\ |
---|
| 84 | pp_inc_2 = (inc_2) * PSZB;\ |
---|
| 85 | do {\ |
---|
| 86 | PUTPIXEL();\ |
---|
| 87 | ZZ(z+=zinc);\ |
---|
| 88 | RGB(r+=rinc;g+=ginc;b+=binc);\ |
---|
| 89 | if (a>0) { pp=(PIXEL *)((char *)pp + pp_inc_1); ZZ(pz+=(inc_1)); a-=dx; }\ |
---|
| 90 | else { pp=(PIXEL *)((char *)pp + pp_inc_2); ZZ(pz+=(inc_2)); a+=dy; }\ |
---|
| 91 | } while (--n >= 0); |
---|
| 92 | |
---|
| 93 | /* fin macro */ |
---|
| 94 | |
---|
| 95 | if (dx == 0 && dy == 0) { |
---|
| 96 | PUTPIXEL(); |
---|
| 97 | } else if (dx > 0) { |
---|
| 98 | if (dx >= dy) { |
---|
| 99 | DRAWLINE(dx, dy, sx + 1, 1); |
---|
| 100 | } else { |
---|
| 101 | DRAWLINE(dy, dx, sx + 1, sx); |
---|
| 102 | } |
---|
| 103 | } else { |
---|
| 104 | dx = -dx; |
---|
| 105 | if (dx >= dy) { |
---|
| 106 | DRAWLINE(dx, dy, sx - 1, -1); |
---|
| 107 | } else { |
---|
| 108 | DRAWLINE(dy, dx, sx - 1, sx); |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | #undef INTERP_Z |
---|
| 114 | #undef INTERP_RGB |
---|
| 115 | |
---|
| 116 | /* internal defines */ |
---|
| 117 | #undef DRAWLINE |
---|
| 118 | #undef PUTPIXEL |
---|
| 119 | #undef ZZ |
---|
| 120 | #undef RGB |
---|
| 121 | #undef RGBPIXEL |
---|