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))
|
|
|
|
|
2014-06-13 12:59:06 +02:00
|
|
|
void ZBuffer::plot(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
|
|
|
|
2014-06-13 12:59:06 +02:00
|
|
|
pz = zbuf + (p->y * xsize + p->x);
|
|
|
|
pp = (PIXEL *)((char *) pbuf.getRawBuffer() + 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;
|
2014-02-20 18:46:49 +01:00
|
|
|
}
|
2005-01-12 15:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define INTERP_Z
|
2014-06-13 12:59:06 +02:00
|
|
|
void ZBuffer::fillLineFlatZ(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
|
2014-06-13 12:59:06 +02:00
|
|
|
void ZBuffer::fillLineInterpZ(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
|
2014-06-13 12:59:06 +02:00
|
|
|
void ZBuffer::fillLineFlat(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
|
2014-06-13 12:59:06 +02:00
|
|
|
void ZBuffer::fillLineInterp(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
|
|
|
}
|
|
|
|
|
2014-06-13 12:59:06 +02:00
|
|
|
void ZBuffer::fillLineZ(ZBufferPoint *p1, ZBufferPoint *p2) {
|
2006-05-16 14:52:36 +00:00
|
|
|
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
|
|
|
|
2014-02-20 18:46:49 +01:00
|
|
|
// choose if the line should have its color interpolated or not
|
2006-05-16 14:52:36 +00:00
|
|
|
if (color1 == color2) {
|
2014-06-13 12:59:06 +02:00
|
|
|
fillLineFlatZ(p1, p2, color1);
|
2006-05-16 14:52:36 +00:00
|
|
|
} else {
|
2014-06-13 12:59:06 +02:00
|
|
|
fillLineInterpZ(p1, p2);
|
2006-05-16 14:52:36 +00:00
|
|
|
}
|
2005-01-12 15:20:02 +00:00
|
|
|
}
|
|
|
|
|
2014-06-13 12:59:06 +02:00
|
|
|
void ZBuffer::fillLine(ZBufferPoint *p1, ZBufferPoint *p2) {
|
2006-05-16 14:52:36 +00:00
|
|
|
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) {
|
2014-06-13 12:59:06 +02:00
|
|
|
fillLineFlat(p1, p2, color1);
|
2006-05-16 14:52:36 +00:00
|
|
|
} else {
|
2014-06-13 12:59:06 +02:00
|
|
|
fillLineInterp(p1, p2);
|
2006-05-16 14:52:36 +00:00
|
|
|
}
|
2005-01-12 15:20:02 +00:00
|
|
|
}
|
2009-05-25 13:19:29 +00:00
|
|
|
|
|
|
|
} // end of namespace TinyGL
|