Panda3D
zline.cxx
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include "zbuffer.h"
4 
5 #define ZCMP(z,zpix) ((ZPOINT)(z) >= (ZPOINT)(zpix))
6 
7 void
8 ZB_plot(ZBuffer * zb, ZBufferPoint * p) {
9  ZPOINT *pz;
10  PIXEL *pp;
11  unsigned int zz;
12 
13  pz = zb->zbuf + (p->y * zb->xsize + p->x);
14  pp = (PIXEL *) ((char *) zb->pbuf + zb->linesize * p->y + p->x * PSZB);
15  zz = p->z >> ZB_POINT_Z_FRAC_BITS;
16  if (ZCMP(zz, *pz)) {
17  *pp = RGB_TO_PIXEL(p->r, p->g, p->b);
18  *pz = zz;
19  }
20 }
21 
22 #define INTERP_Z
23 static void
24 ZB_line_flat_z(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2,
25  unsigned int color) {
26 #include "zline.h"
27 }
28 
29 /* line with color interpolation */
30 #define INTERP_Z
31 #define INTERP_RGB
32 static void
33 ZB_line_interp_z(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2) {
34 #include "zline.h"
35 }
36 
37 /* no Z interpolation */
38 
39 static void
40 ZB_line_flat(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2,
41  unsigned int color) {
42 #include "zline.h"
43 }
44 
45 #define INTERP_RGB
46 static void
47 ZB_line_interp(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2) {
48 #include "zline.h"
49 }
50 
51 void
52 ZB_line_z(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2) {
53  unsigned int color1, color2;
54 
55  color1 = RGBA_TO_PIXEL(p1->r, p1->g, p1->b, p1->a);
56  color2 = RGBA_TO_PIXEL(p2->r, p2->g, p2->b, p2->a);
57 
58  /* choose if the line should have its color interpolated or not */
59  if (color1 == color2) {
60  ZB_line_flat_z(zb, p1, p2, color1);
61  } else {
62  ZB_line_interp_z(zb, p1, p2);
63  }
64 }
65 
66 void
67 ZB_line(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2) {
68  unsigned int color1, color2;
69 
70  color1 = RGB_TO_PIXEL(p1->r, p1->g, p1->b);
71  color2 = RGB_TO_PIXEL(p2->r, p2->g, p2->b);
72 
73  /* choose if the line should have its color interpolated or not */
74  if (color1 == color2) {
75  ZB_line_flat(zb, p1, p2, color1);
76  } else {
77  ZB_line_interp(zb, p1, p2);
78  }
79 }