Panda3D
 All Classes Functions Variables Enumerations
zline.h
1 {
2  int n, dx, dy, sx, pp_inc_1, pp_inc_2;
3  int a;
4  PIXEL *pp;
5 #if defined(INTERP_RGB)
6  unsigned int r, g, b;
7 #endif
8 #ifdef INTERP_RGB
9  unsigned int rinc, ginc, binc;
10 #endif
11 #ifdef INTERP_Z
12  ZPOINT *pz;
13  int zinc;
14  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 #endif
37 
38 #undef RGB /* from wingdi.h */
39 #ifdef INTERP_RGB
40 #define RGB(x) x
41 #define RGBPIXEL *pp = RGB_TO_PIXEL(r >> 8,g >> 8,b >> 8)
42 #else /* INTERP_RGB */
43 #define RGB(x)
44 #define RGBPIXEL *pp = color
45 #endif /* INTERP_RGB */
46 
47 #ifdef INTERP_Z
48 #define ZZ(x) x
49 #define PUTPIXEL() \
50  { \
51  zz=z >> ZB_POINT_Z_FRAC_BITS; \
52  if (ZCMP(zz,*pz)) { \
53  RGBPIXEL; \
54  *pz=zz; \
55  } \
56  }
57 #else /* INTERP_Z */
58 #define ZZ(x)
59 #define PUTPIXEL() RGBPIXEL
60 #endif /* INTERP_Z */
61 
62 #define DRAWLINE(dx,dy,inc_1,inc_2) \
63  n=dx;\
64  ZZ(zinc=(p2->z-p1->z)/n);\
65  RGB(rinc=((p2->r-p1->r) << 8)/n;\
66  ginc=((p2->g-p1->g) << 8)/n;\
67  binc=((p2->b-p1->b) << 8)/n);\
68  a=2*dy-dx;\
69  dy=2*dy;\
70  dx=2*dx-dy;\
71  pp_inc_1 = (inc_1) * PSZB;\
72  pp_inc_2 = (inc_2) * PSZB;\
73  do {\
74  PUTPIXEL();\
75  ZZ(z+=zinc);\
76  RGB(r+=rinc;g+=ginc;b+=binc);\
77  if (a>0) { pp=(PIXEL *)((char *)pp + pp_inc_1); ZZ(pz+=(inc_1)); a-=dx; }\
78  else { pp=(PIXEL *)((char *)pp + pp_inc_2); ZZ(pz+=(inc_2)); a+=dy; }\
79  } while (--n >= 0);
80 
81 /* fin macro */
82 
83  if (dx == 0 && dy == 0) {
84  PUTPIXEL();
85  } else if (dx > 0) {
86  if (dx >= dy) {
87  DRAWLINE(dx, dy, sx + 1, 1);
88  } else {
89  DRAWLINE(dy, dx, sx + 1, sx);
90  }
91  } else {
92  dx = -dx;
93  if (dx >= dy) {
94  DRAWLINE(dx, dy, sx - 1, -1);
95  } else {
96  DRAWLINE(dy, dx, sx - 1, sx);
97  }
98  }
99 }
100 
101 #undef INTERP_Z
102 #undef INTERP_RGB
103 
104 /* internal defines */
105 #undef DRAWLINE
106 #undef PUTPIXEL
107 #undef ZZ
108 #undef RGB
109 #undef RGBPIXEL