Panda3D

zline.cxx

00001 #include <stdlib.h>
00002 #include <stdio.h>
00003 #include "zbuffer.h"
00004 
00005 #define ZCMP(z,zpix) ((ZPOINT)(z) >= (ZPOINT)(zpix))
00006 
00007 void
00008 ZB_plot(ZBuffer * zb, ZBufferPoint * p) {
00009   ZPOINT *pz;
00010   PIXEL *pp;
00011   unsigned int zz;
00012   
00013   pz = zb->zbuf + (p->y * zb->xsize + p->x);
00014   pp = (PIXEL *) ((char *) zb->pbuf + zb->linesize * p->y + p->x * PSZB);
00015   zz = p->z >> ZB_POINT_Z_FRAC_BITS;
00016   if (ZCMP(zz, *pz)) {
00017     *pp = RGB_TO_PIXEL(p->r, p->g, p->b);
00018     *pz = zz;
00019   }
00020 }
00021 
00022 #define INTERP_Z
00023 static void
00024 ZB_line_flat_z(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2, 
00025                unsigned int color) {
00026 #include "zline.h"
00027 }
00028 
00029 /* line with color interpolation */
00030 #define INTERP_Z
00031 #define INTERP_RGB
00032 static void
00033 ZB_line_interp_z(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2) {
00034 #include "zline.h"
00035 }
00036 
00037 /* no Z interpolation */
00038 
00039 static void
00040 ZB_line_flat(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2, 
00041              unsigned int color) {
00042 #include "zline.h"
00043 }
00044 
00045 #define INTERP_RGB
00046 static void
00047 ZB_line_interp(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2) {
00048 #include "zline.h"
00049 }
00050 
00051 void
00052 ZB_line_z(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2) {
00053   unsigned int color1, color2;
00054 
00055   color1 = RGBA_TO_PIXEL(p1->r, p1->g, p1->b, p1->a);
00056   color2 = RGBA_TO_PIXEL(p2->r, p2->g, p2->b, p2->a);
00057 
00058   /* choose if the line should have its color interpolated or not */
00059   if (color1 == color2) {
00060     ZB_line_flat_z(zb, p1, p2, color1);
00061   } else {
00062     ZB_line_interp_z(zb, p1, p2);
00063   }
00064 }
00065 
00066 void
00067 ZB_line(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2) {
00068   unsigned int color1, color2;
00069 
00070   color1 = RGB_TO_PIXEL(p1->r, p1->g, p1->b);
00071   color2 = RGB_TO_PIXEL(p2->r, p2->g, p2->b);
00072 
00073   /* choose if the line should have its color interpolated or not */
00074   if (color1 == color2) {
00075     ZB_line_flat(zb, p1, p2, color1);
00076   } else {
00077     ZB_line_interp(zb, p1, p2);
00078   }
00079 }
 All Classes Functions Variables Enumerations