2008-01-26 11:47:23 +00:00
|
|
|
|
2009-05-08 07:32:33 +00:00
|
|
|
#include "graphics/tinygl/zbuffer.h"
|
2005-01-12 15:20:02 +00:00
|
|
|
|
2009-05-25 13:19:29 +00:00
|
|
|
namespace TinyGL {
|
|
|
|
|
2005-01-12 15:20:02 +00:00
|
|
|
#define ZCMP(z,zpix) ((z) >= (zpix))
|
|
|
|
|
2006-05-16 14:52:36 +00:00
|
|
|
void ZB_plot(ZBuffer * zb, ZBufferPoint * p) {
|
2012-02-13 19:19:03 +01:00
|
|
|
unsigned int *pz;
|
2006-05-16 14:52:36 +00:00
|
|
|
PIXEL *pp;
|
2005-01-12 15:20:02 +00:00
|
|
|
|
2006-05-16 14:52:36 +00:00
|
|
|
pz = zb->zbuf + (p->y * zb->xsize + p->x);
|
2012-01-24 18:20:33 +01:00
|
|
|
pp = (PIXEL *)((char *) zb->pbuf.getRawBuffer() + zb->linesize * p->y + p->x * PSZB);
|
2012-02-13 19:19:03 +01:00
|
|
|
if (ZCMP((unsigned int)p->z, *pz)) {
|
2006-05-16 07:28:47 +00:00
|
|
|
*pp = RGB_TO_PIXEL(p->r, p->g, p->b);
|
2012-02-13 19:19:03 +01:00
|
|
|
*pz = p->z;
|
2005-01-12 15:20:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define INTERP_Z
|
2006-05-16 14:52:36 +00:00
|
|
|
static void ZB_line_flat_z(ZBuffer *zb, ZBufferPoint *p1, ZBufferPoint *p2, int color) {
|
2009-05-08 07:32:33 +00:00
|
|
|
#include "graphics/tinygl/zline.h"
|
2005-01-12 15:20:02 +00:00
|
|
|
}
|
|
|
|
|
2006-05-16 14:52:36 +00:00
|
|
|
// line with color interpolation
|
2005-01-12 15:20:02 +00:00
|
|
|
#define INTERP_Z
|
|
|
|
#define INTERP_RGB
|
2006-05-16 14:52:36 +00:00
|
|
|
static void ZB_line_interp_z(ZBuffer *zb, ZBufferPoint *p1, ZBufferPoint *p2) {
|
2009-05-08 07:32:33 +00:00
|
|
|
#include "graphics/tinygl/zline.h"
|
2005-01-12 15:20:02 +00:00
|
|
|
}
|
|
|
|
|
2006-05-16 14:52:36 +00:00
|
|
|
// no Z interpolation
|
|
|
|
static void ZB_line_flat(ZBuffer *zb, ZBufferPoint *p1, ZBufferPoint *p2, int color) {
|
2009-05-08 07:32:33 +00:00
|
|
|
#include "graphics/tinygl/zline.h"
|
2005-01-12 15:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define INTERP_RGB
|
2006-05-16 14:52:36 +00:00
|
|
|
static void ZB_line_interp(ZBuffer *zb, ZBufferPoint *p1, ZBufferPoint *p2) {
|
2009-05-08 07:32:33 +00:00
|
|
|
#include "graphics/tinygl/zline.h"
|
2005-01-12 15:20:02 +00:00
|
|
|
}
|
|
|
|
|
2006-05-16 14:52:36 +00:00
|
|
|
void ZB_line_z(ZBuffer *zb, ZBufferPoint *p1, ZBufferPoint *p2) {
|
|
|
|
int color1, color2;
|
2005-01-12 15:20:02 +00:00
|
|
|
|
2006-05-16 14:52:36 +00:00
|
|
|
color1 = RGB_TO_PIXEL(p1->r, p1->g, p1->b);
|
|
|
|
color2 = RGB_TO_PIXEL(p2->r, p2->g, p2->b);
|
2005-01-12 15:20:02 +00:00
|
|
|
|
2006-05-16 14:52:36 +00:00
|
|
|
// choose if the line should have its color interpolated or not
|
|
|
|
if (color1 == color2) {
|
|
|
|
ZB_line_flat_z(zb, p1, p2, color1);
|
|
|
|
} else {
|
|
|
|
ZB_line_interp_z(zb, p1, p2);
|
|
|
|
}
|
2005-01-12 15:20:02 +00:00
|
|
|
}
|
|
|
|
|
2006-05-16 14:52:36 +00:00
|
|
|
void ZB_line(ZBuffer *zb, ZBufferPoint *p1, ZBufferPoint *p2) {
|
|
|
|
int color1, color2;
|
2005-01-12 15:20:02 +00:00
|
|
|
|
2006-05-16 14:52:36 +00:00
|
|
|
color1 = RGB_TO_PIXEL(p1->r, p1->g, p1->b);
|
|
|
|
color2 = RGB_TO_PIXEL(p2->r, p2->g, p2->b);
|
2005-01-12 15:20:02 +00:00
|
|
|
|
2006-05-16 14:52:36 +00:00
|
|
|
// choose if the line should have its color interpolated or not
|
|
|
|
if (color1 == color2) {
|
|
|
|
ZB_line_flat(zb, p1, p2, color1);
|
|
|
|
} else {
|
|
|
|
ZB_line_interp(zb, p1, p2);
|
|
|
|
}
|
2005-01-12 15:20:02 +00:00
|
|
|
}
|
2009-05-25 13:19:29 +00:00
|
|
|
|
|
|
|
} // end of namespace TinyGL
|