TINYGL: Removed unnecessary files and updated changelog.

This commit is contained in:
Stefano Musumeci 2014-06-17 17:00:43 +02:00
parent 4555f10cd8
commit e373f12d64
9 changed files with 52 additions and 531 deletions

View File

@ -48,7 +48,6 @@ MODULE_OBJS := \
tinygl/zline.o \
tinygl/zmath.o \
tinygl/ztriangle.o \
tinygl/ztriangle_shadow.o
ifdef USE_SCALERS
MODULE_OBJS += \

View File

@ -22,5 +22,7 @@ The changes made from the original version of TinyGL 0.4 are:
* Changed the math-functions to use const-pointers if possible.
* Reformatted the source to use the same code-formatting conventions as the rest of ResidualVM (indentation-wise, not variable-naming wise)
* Refactored all the maths code in a C++ fashion, removed some unused functions.
* Heavily refactored the triangle and line drawing routines
* Renamed ZBuffer into FrameBuffer and moved all the external C functions as member functions.
For more information refer to log changes in github: https://github.com/residualvm/residualvm
For more information refer to log changes in github: https://github.com/residualvm/residualvm

View File

@ -93,7 +93,7 @@ FrameBuffer::~FrameBuffer() {
gl_free(zbuf);
}
Buffer* FrameBuffer::genOffscreenBuffer() {
Buffer *FrameBuffer::genOffscreenBuffer() {
Buffer *buf = (Buffer *)gl_malloc(sizeof(Buffer));
buf->pbuf = (byte *)gl_malloc(this->ysize * this->linesize);
int size = this->xsize * this->ysize * sizeof(unsigned int);
@ -108,7 +108,7 @@ void FrameBuffer::delOffscreenBuffer(Buffer *buf) {
gl_free(buf);
}
void FrameBuffer::clear( int clear_z, int z, int clear_color, int r, int g, int b ) {
void FrameBuffer::clear(int clear_z, int z, int clear_color, int r, int g, int b) {
uint32 color;
byte *pp;
@ -125,7 +125,7 @@ void FrameBuffer::clear( int clear_z, int z, int clear_color, int r, int g, int
}
}
void FrameBuffer::blitOffscreenBuffer( Buffer* buf ) {
void FrameBuffer::blitOffscreenBuffer(Buffer *buf) {
// TODO: could be faster, probably.
if (buf->used) {
for (int i = 0; i < this->xsize * this->ysize; ++i) {
@ -140,7 +140,7 @@ void FrameBuffer::blitOffscreenBuffer( Buffer* buf ) {
}
}
void FrameBuffer::selectOffscreenBuffer( Buffer* buf ) {
void FrameBuffer::selectOffscreenBuffer(Buffer *buf) {
if (buf) {
this->pbuf = buf->pbuf;
this->zbuf = buf->zbuf;
@ -151,13 +151,13 @@ void FrameBuffer::selectOffscreenBuffer( Buffer* buf ) {
}
}
void FrameBuffer::clearOffscreenBuffer( Buffer* buf ) {
void FrameBuffer::clearOffscreenBuffer(Buffer *buf) {
memset(buf->pbuf, 0, this->ysize * this->linesize);
memset(buf->zbuf, 0, this->ysize * this->xsize * sizeof(unsigned int));
buf->used = false;
}
void FrameBuffer::setTexture( const Graphics::PixelBuffer &texture ) {
void FrameBuffer::setTexture(const Graphics::PixelBuffer &texture) {
current_texture = texture;
}

View File

@ -26,7 +26,7 @@ namespace TinyGL {
// display modes
#define ZB_MODE_5R6G5B 1 // true color 16 bits
#define RGB_TO_PIXEL(r,g,b) cmode.RGBToColor(r, g, b)
#define RGB_TO_PIXEL(r, g, b) cmode.RGBToColor(r, g, b)
typedef byte PIXEL;
#define PSZSH 4

View File

@ -8,9 +8,9 @@ namespace TinyGL {
template <bool interpRGB, bool interpZ>
FORCEINLINE static void putPixel(PIXEL *pp, const Graphics::PixelFormat &cmode, unsigned int *pz, unsigned int &z, int &color, unsigned int &r, unsigned int &g, unsigned int &b) {
if (interpZ) {
if (ZCMP(z,*pz)) {
if (ZCMP(z, *pz)) {
if (interpRGB) {
*pp = RGB_TO_PIXEL(r >> 8,g >> 8,b >> 8);
*pp = RGB_TO_PIXEL(r >> 8, g >> 8, b >> 8);
}
else {
*pp = color;
@ -20,7 +20,7 @@ FORCEINLINE static void putPixel(PIXEL *pp, const Graphics::PixelFormat &cmode,
}
else {
if (interpRGB) {
*pp = RGB_TO_PIXEL(r >> 8,g >> 8,b >> 8);
*pp = RGB_TO_PIXEL(r >> 8, g >> 8, b >> 8);
}
else {
*pp = color;
@ -47,7 +47,7 @@ FORCEINLINE static void drawLine(ZBufferPoint *p1, ZBufferPoint *p2, PIXEL *pp,
int pp_inc_1 = (inc_1) * PSZB;
int pp_inc_2 = (inc_2) * PSZB;
do {
putPixel<interpRGB,interpZ>(pp, cmode, pz, z, color, r, g, b);
putPixel<interpRGB, interpZ>(pp, cmode, pz, z, color, r, g, b);
if (interpZ) {
z += zinc;
}
@ -87,7 +87,7 @@ void FrameBuffer::fillLine(ZBufferPoint *p1, ZBufferPoint *p2, int color) {
p2 = tmp;
}
sx = xsize;
pp = (PIXEL *)((char *) pbuf.getRawBuffer() + linesize * p1->y + p1->x * PSZB);
pp = (PIXEL *)((char *)pbuf.getRawBuffer() + linesize * p1->y + p1->x * PSZB);
if (interpZ) {
pz = zbuf + (p1->y * sx + p1->x);
z = p1->z;
@ -104,16 +104,16 @@ void FrameBuffer::fillLine(ZBufferPoint *p1, ZBufferPoint *p2, int color) {
putPixel<interpRGB,interpZ>(pp, cmode, pz, z, color, r, g, b);
} else if (dx > 0) {
if (dx >= dy) {
drawLine<interpRGB,interpZ>(p1, p2, pp, cmode, pz, z, color, r, g, b, dx, dy, sx + 1, 1);
drawLine<interpRGB, interpZ>(p1, p2, pp, cmode, pz, z, color, r, g, b, dx, dy, sx + 1, 1);
} else {
drawLine<interpRGB,interpZ>(p1, p2, pp, cmode, pz, z, color, r, g, b, dx, dy, sx + 1, sx);
drawLine<interpRGB, interpZ>(p1, p2, pp, cmode, pz, z, color, r, g, b, dx, dy, sx + 1, sx);
}
} else {
dx = -dx;
if (dx >= dy) {
drawLine<interpRGB,interpZ>(p1, p2, pp, cmode, pz, z, color, r, g, b, dx, dy, sx - 1, -1);
drawLine<interpRGB, interpZ>(p1, p2, pp, cmode, pz, z, color, r, g, b, dx, dy, sx - 1, -1);
} else {
drawLine<interpRGB,interpZ>(p1, p2, pp, cmode, pz, z, color, r, g, b, dx, dy, sx - 1, sx);
drawLine<interpRGB, interpZ>(p1, p2, pp, cmode, pz, z, color, r, g, b, dx, dy, sx - 1, sx);
}
}
}
@ -127,11 +127,11 @@ void FrameBuffer::plot(ZBufferPoint *p) {
unsigned int r, g, b;
int col = RGB_TO_PIXEL(p->r, p->g, p->b);
unsigned int z = p->z;
putPixel<false,true>(pp, cmode, pz, z, col, r, g, b);
putPixel<false, true>(pp, cmode, pz, z, col, r, g, b);
}
void FrameBuffer::fillLineFlatZ(ZBufferPoint *p1, ZBufferPoint *p2, int color) {
#include "graphics/tinygl/zline.h"
fillLine<false, true>(p1, p2, color);
}
// line with color interpolation
@ -141,11 +141,11 @@ void FrameBuffer::fillLineInterpZ(ZBufferPoint *p1, ZBufferPoint *p2) {
// no Z interpolation
void FrameBuffer::fillLineFlat(ZBufferPoint *p1, ZBufferPoint *p2, int color) {
fillLine<false, true>(p1, p2, color);
fillLine<false, false>(p1, p2, color);
}
void FrameBuffer::fillLineInterp(ZBufferPoint *p1, ZBufferPoint *p2) {
fillLine<true, false>(p1, p2, 0);
fillLine<false, true>(p1, p2, 0);
}
void FrameBuffer::fillLineZ(ZBufferPoint *p1, ZBufferPoint *p2) {

View File

@ -1,114 +0,0 @@
{
int n, dx, dy, sx, pp_inc_1, pp_inc_2;
register int a;
register PIXEL *pp;
#if defined(INTERP_RGB)
register unsigned int r, g, b;
#endif
#ifdef INTERP_RGB
register unsigned int rinc, ginc, binc;
#endif
#ifdef INTERP_Z
register unsigned int *pz;
int zinc;
register unsigned int z;
#endif
if (p1->y > p2->y || (p1->y == p2->y && p1->x > p2->x)) {
ZBufferPoint *tmp;
tmp = p1;
p1 = p2;
p2 = tmp;
}
sx = xsize;
pp = (PIXEL *)((char *) pbuf.getRawBuffer() + linesize * p1->y + p1->x * PSZB);
#ifdef INTERP_Z
pz = zbuf + (p1->y * sx + p1->x);
z = p1->z;
#endif
dx = p2->x - p1->x;
dy = p2->y - p1->y;
#ifdef INTERP_RGB
r = p2->r << 8;
g = p2->g << 8;
b = p2->b << 8;
#endif
#ifdef INTERP_RGB
#define RGB(x) x
#define RGBPIXEL *pp = RGB_TO_PIXEL(r >> 8,g >> 8,b >> 8)
#else // INTERP_RGB
#define RGB(x)
#define RGBPIXEL *pp = color
#endif // INTERP_RGB
#ifdef INTERP_Z
#define ZZ(x) x
#define PUTPIXEL() \
{ \
if (ZCMP(z, *pz)) { \
RGBPIXEL; \
*pz = z; \
} \
}
#else // INTERP_Z
#define ZZ(x)
#define PUTPIXEL() RGBPIXEL
#endif // INTERP_Z
#define DRAWLINE(dx, dy, inc_1, inc_2) \
n = dx; \
ZZ(zinc = (p2->z - p1->z)/n); \
RGB(rinc=((p2->r - p1->r) << 8)/n; \
ginc=((p2->g - p1->g) << 8)/n; \
binc=((p2->b - p1->b) << 8)/n); \
a = 2 * dy - dx; \
dy = 2 * dy; \
dx = 2 * dx - dy; \
pp_inc_1 = (inc_1) * PSZB; \
pp_inc_2 = (inc_2) * PSZB; \
do { \
PUTPIXEL(); \
ZZ(z += zinc); \
RGB(r += rinc; g += ginc; b += binc); \
if (a > 0) { \
pp = (PIXEL *)((char *)pp + pp_inc_1); \
ZZ(pz+=(inc_1)); \
a -= dx; \
} else { \
pp = (PIXEL *)((char *)pp + pp_inc_2); \
ZZ(pz += (inc_2)); \
a += dy; \
} \
} while (--n >= 0);
// fin macro
if (dx == 0 && dy == 0) {
PUTPIXEL();
} else if (dx > 0) {
if (dx >= dy) {
DRAWLINE(dx, dy, sx + 1, 1);
} else {
DRAWLINE(dy, dx, sx + 1, sx);
}
} else {
dx = -dx;
if (dx >= dy) {
DRAWLINE(dx, dy, sx - 1, -1);
} else {
DRAWLINE(dy, dx, sx - 1, sx);
}
}
}
#undef INTERP_Z
#undef INTERP_RGB
// internal defines
#undef DRAWLINE
#undef PUTPIXEL
#undef ZZ
#undef RGB
#undef RGBPIXEL

View File

@ -384,22 +384,22 @@ void FrameBuffer::fillTriangle(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint
}
while (n >= 3) {
if (drawLogic == DRAW_DEPTH_ONLY) {
putPixelDepth(pz,0,z,dzdx);
putPixelDepth(pz,1,z,dzdx);
putPixelDepth(pz,2,z,dzdx);
putPixelDepth(pz,3,z,dzdx);
putPixelDepth(pz, 0, z ,dzdx);
putPixelDepth(pz, 1, z, dzdx);
putPixelDepth(pz, 2, z, dzdx);
putPixelDepth(pz, 3, z, dzdx);
}
if (drawLogic == DRAW_FLAT) {
putPixelFlat(pp,pz,0,z,color,dzdx);
putPixelFlat(pp,pz,1,z,color,dzdx);
putPixelFlat(pp,pz,2,z,color,dzdx);
putPixelFlat(pp,pz,3,z,color,dzdx);
putPixelFlat(pp, pz, 0, z, color, dzdx);
putPixelFlat(pp, pz, 1, z, color, dzdx);
putPixelFlat(pp, pz, 2, z, color, dzdx);
putPixelFlat(pp, pz, 3, z, color, dzdx);
}
if (drawLogic == DRAW_MAPPING) {
putPixelMapping(pp,pz,texture,0,z,t,s,dzdx,dsdx,dtdx);
putPixelMapping(pp,pz,texture,1,z,t,s,dzdx,dsdx,dtdx);
putPixelMapping(pp,pz,texture,2,z,t,s,dzdx,dsdx,dtdx);
putPixelMapping(pp,pz,texture,3,z,t,s,dzdx,dsdx,dtdx);
putPixelMapping(pp, pz, texture, 0, z, t, s, dzdx, dsdx, dtdx);
putPixelMapping(pp, pz, texture, 1, z, t, s, dzdx, dsdx, dtdx);
putPixelMapping(pp, pz, texture, 2, z, t, s, dzdx, dsdx, dtdx);
putPixelMapping(pp, pz, texture, 3, z, t, s, dzdx, dsdx, dtdx);
}
if (interpZ) {
pz += 4;
@ -409,13 +409,13 @@ void FrameBuffer::fillTriangle(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint
}
while (n >= 0) {
if (drawLogic == DRAW_DEPTH_ONLY) {
putPixelDepth(pz,0,z,dzdx);
putPixelDepth(pz, 0, z, dzdx);
}
if (drawLogic == DRAW_FLAT) {
putPixelFlat(pp,pz,0,z,color,dzdx);
putPixelFlat(pp, pz, 0, z, color, dzdx);
}
if (drawLogic == DRAW_MAPPING) {
putPixelMapping(pp,pz,texture,0,z,t,s,dzdx,dsdx,dtdx);
putPixelMapping(pp, pz, texture, 0, z, t, s, dzdx, dsdx, dtdx);
}
if (interpZ) {
pz += 1;
@ -494,7 +494,7 @@ void FrameBuffer::fillTriangle(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint
buf = (byte *)pp1 + x1 * bpp;
pz = pz1 + x1;
z = z1;
rgb =(r1 << 16) & 0xFFC00000;
rgb = (r1 << 16) & 0xFFC00000;
rgb |= (g1 >> 5) & 0x000007FF;
rgb |= (b1 << 5) & 0x001FF000;
drgbdx = _drgbdx;
@ -548,7 +548,8 @@ void FrameBuffer::fillTriangle(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint
zinv = (float)(1.0 / fz);
}
for (int _a = 0; _a < 8; _a++) {
putPixelMappingPerspective(buf, textureFormat, texture, pz, _a, z, t, s, tmp, rgb, dzdx, dsdx, dtdx, drgbdx);
putPixelMappingPerspective(buf, textureFormat, texture, pz, _a, z, t, s, tmp, rgb, dzdx, dsdx, dtdx,
drgbdx);
}
pz += NB_INTERP;
buf.shiftBy(NB_INTERP);
@ -568,7 +569,8 @@ void FrameBuffer::fillTriangle(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint
}
while (n >= 0) {
putPixelMappingPerspective(buf, textureFormat, texture, pz, 0, z, t, s, tmp, rgb, dzdx, dsdx, dtdx, drgbdx);
putPixelMappingPerspective(buf, textureFormat, texture, pz, 0, z, t, s, tmp, rgb, dzdx, dsdx, dtdx,
drgbdx);
pz += 1;
buf.shiftBy(1);
n -= 1;
@ -642,7 +644,7 @@ void FrameBuffer::fillTriangleDepthOnly(ZBufferPoint *p0, ZBufferPoint *p1, ZBuf
const bool interpRGB = false;
const bool interpST = false;
const bool interpSTZ = false;
fillTriangle<interpRGB,interpZ,interpST,interpSTZ,DRAW_DEPTH_ONLY>(p0, p1, p2);
fillTriangle<interpRGB, interpZ, interpST, interpSTZ, DRAW_DEPTH_ONLY>(p0, p1, p2);
}
@ -651,17 +653,16 @@ void FrameBuffer::fillTriangleFlat(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPo
const bool interpRGB = false;
const bool interpST = false;
const bool interpSTZ = false;
fillTriangle<interpRGB,interpZ,interpST,interpSTZ,DRAW_FLAT>(p0, p1, p2);
fillTriangle<interpRGB, interpZ ,interpST, interpSTZ, DRAW_FLAT>(p0, p1, p2);
}
// Smooth filled triangle.
// The code below is very tricky :) -- Not anymore :P
void FrameBuffer::fillTriangleSmooth(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint *p2) {
const bool interpZ = true;
const bool interpRGB = true;
const bool interpST = false;
const bool interpSTZ = false;
fillTriangle<interpRGB,interpZ,interpST,interpSTZ,DRAW_SMOOTH>(p0, p1, p2);
fillTriangle<interpRGB, interpZ, interpST, interpSTZ, DRAW_SMOOTH>(p0, p1, p2);
}
void FrameBuffer::fillTriangleMapping(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint *p2) {
@ -669,15 +670,16 @@ void FrameBuffer::fillTriangleMapping(ZBufferPoint *p0, ZBufferPoint *p1, ZBuffe
const bool interpRGB = false;
const bool interpST = true;
const bool interpSTZ = false;
fillTriangle<interpRGB,interpZ,interpST,interpSTZ,DRAW_MAPPING>(p0, p1, p2);
fillTriangle<interpRGB, interpZ, interpST, interpSTZ, DRAW_MAPPING>(p0, p1, p2);
}
void FrameBuffer::fillTriangleMappingPerspective(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint *p2) {
void FrameBuffer::fillTriangleMappingPerspective(ZBufferPoint *p0, ZBufferPoint *p1,
ZBufferPoint *p2) {
const bool interpZ = true;
const bool interpRGB = true;
const bool interpST = false;
const bool interpSTZ = true;
fillTriangle<interpRGB,interpZ,interpST,interpSTZ,DRAW_MAPPING_PERSPECTIVE>(p0, p1, p2);
fillTriangle<interpRGB, interpZ, interpST, interpSTZ, DRAW_MAPPING_PERSPECTIVE>(p0, p1, p2);
}
void FrameBuffer::fillTriangleFlatShadowMask(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint *p2) {
@ -685,7 +687,7 @@ void FrameBuffer::fillTriangleFlatShadowMask(ZBufferPoint *p0, ZBufferPoint *p1,
const bool interpRGB = false;
const bool interpST = false;
const bool interpSTZ = false;
fillTriangle<interpRGB,interpZ,interpST,interpSTZ,DRAW_SHADOW_MASK>(p0, p1, p2);
fillTriangle<interpRGB, interpZ, interpST, interpSTZ, DRAW_SHADOW_MASK>(p0, p1, p2);
}
void FrameBuffer::fillTriangleFlatShadow(ZBufferPoint *p0, ZBufferPoint *p1, ZBufferPoint *p2) {
@ -693,7 +695,7 @@ void FrameBuffer::fillTriangleFlatShadow(ZBufferPoint *p0, ZBufferPoint *p1, ZBu
const bool interpRGB = false;
const bool interpST = false;
const bool interpSTZ = false;
fillTriangle<interpRGB,interpZ,interpST,interpSTZ,DRAW_SHADOW>(p0, p1, p2);
fillTriangle<interpRGB, interpZ, interpST, interpSTZ, DRAW_SHADOW>(p0, p1, p2);
}

View File

@ -1,362 +0,0 @@
// We draw a triangle with various interpolations
{
ZBufferPoint *tp, *pr1 = 0, *pr2 = 0, *l1 = 0, *l2 = 0;
float fdx1, fdx2, fdy1, fdy2, fz, d1, d2;
unsigned int *pz1;
PIXEL *pp1;
int part, update_left, update_right;
int nb_lines, dx1, dy1, tmp, dx2, dy2;
int error = 0, derror = 0;
int x1 = 0, dxdy_min = 0, dxdy_max = 0;
// warning: x2 is multiplied by 2^16
int x2 = 0, dx2dy2 = 0;
#ifdef INTERP_Z
int z1 = 0, dzdx, dzdy, dzdl_min = 0, dzdl_max = 0;
#endif
#ifdef INTERP_RGB
int r1 = 0, drdx, drdy, drdl_min = 0, drdl_max = 0;
int g1 = 0, dgdx, dgdy, dgdl_min = 0, dgdl_max = 0;
int b1 = 0, dbdx, dbdy, dbdl_min = 0, dbdl_max = 0;
#endif
#ifdef INTERP_ST
int s1 = 0, dsdx, dsdy, dsdl_min = 0, dsdl_max = 0;
int t1 = 0, dtdx, dtdy, dtdl_min = 0, dtdl_max = 0;
#endif
#ifdef INTERP_STZ
float sz1, dszdx, dszdy, dszdl_min, dszdl_max;
float tz1, dtzdx, dtzdy, dtzdl_min, dtzdl_max;
#endif
// we sort the vertex with increasing y
if (p1->y < p0->y) {
tp = p0;
p0 = p1;
p1 = tp;
}
if (p2->y < p0->y) {
tp = p2;
p2 = p1;
p1 = p0;
p0 = tp;
} else if (p2->y < p1->y) {
tp = p1;
p1 = p2;
p2 = tp;
}
// we compute dXdx and dXdy for all interpolated values
fdx1 = (float)(p1->x - p0->x);
fdy1 = (float)(p1->y - p0->y);
fdx2 = (float)(p2->x - p0->x);
fdy2 = (float)(p2->y - p0->y);
fz = fdx1 * fdy2 - fdx2 * fdy1;
if (fz == 0)
return;
fz = (float)(1.0 / fz);
fdx1 *= fz;
fdy1 *= fz;
fdx2 *= fz;
fdy2 *= fz;
#ifdef INTERP_Z
d1 = (float)(p1->z - p0->z);
d2 = (float)(p2->z - p0->z);
dzdx = (int)(fdy2 * d1 - fdy1 * d2);
dzdy = (int)(fdx1 * d2 - fdx2 * d1);
#endif
#ifdef INTERP_RGB
d1 = (float)(p1->r - p0->r);
d2 = (float)(p2->r - p0->r);
drdx = (int)(fdy2 * d1 - fdy1 * d2);
drdy = (int)(fdx1 * d2 - fdx2 * d1);
d1 = (float)(p1->g - p0->g);
d2 = (float)(p2->g - p0->g);
dgdx = (int)(fdy2 * d1 - fdy1 * d2);
dgdy = (int)(fdx1 * d2 - fdx2 * d1);
d1 = (float)(p1->b - p0->b);
d2 = (float)(p2->b - p0->b);
dbdx = (int)(fdy2 * d1 - fdy1 * d2);
dbdy = (int)(fdx1 * d2 - fdx2 * d1);
#endif
#ifdef INTERP_ST
d1 = (float)(p1->s - p0->s);
d2 = (float)(p2->s - p0->s);
dsdx = (int)(fdy2 * d1 - fdy1 * d2);
dsdy = (int)(fdx1 * d2 - fdx2 * d1);
d1 = (float)(p1->t - p0->t);
d2 = (float)(p2->t - p0->t);
dtdx = (int)(fdy2 * d1 - fdy1 * d2);
dtdy = (int)(fdx1 * d2 - fdx2 * d1);
#endif
#ifdef INTERP_STZ
{
float zz;
zz = (float)p0->z;
p0->sz = (float)p0->s * zz;
p0->tz = (float)p0->t * zz;
zz = (float)p1->z;
p1->sz = (float)p1->s * zz;
p1->tz = (float)p1->t * zz;
zz = (float) p2->z;
p2->sz = (float)p2->s * zz;
p2->tz = (float)p2->t * zz;
d1 = p1->sz - p0->sz;
d2 = p2->sz - p0->sz;
dszdx = (fdy2 * d1 - fdy1 * d2);
dszdy = (fdx1 * d2 - fdx2 * d1);
d1 = p1->tz - p0->tz;
d2 = p2->tz - p0->tz;
dtzdx = (fdy2 * d1 - fdy1 * d2);
dtzdy = (fdx1 * d2 - fdx2 * d1);
}
#endif
// screen coordinates
pp1 = (PIXEL *)((char *)pbuf.getRawBuffer() + linesize * p0->y);
pz1 = zbuf + p0->y * xsize;
DRAW_INIT();
for (part = 0; part < 2; part++) {
if (part == 0) {
if (fz > 0) {
update_left = 1;
update_right = 1;
l1 = p0;
l2 = p2;
pr1 = p0;
pr2 = p1;
} else {
update_left = 1;
update_right = 1;
l1 = p0;
l2 = p1;
pr1 = p0;
pr2 = p2;
}
nb_lines = p1->y - p0->y;
} else {
// second part
if (fz > 0) {
update_left = 0;
update_right = 1;
pr1 = p1;
pr2 = p2;
} else {
update_left = 1;
update_right = 0;
l1 = p1;
l2 = p2;
}
nb_lines = p2->y - p1->y + 1;
}
// compute the values for the left edge
if (update_left) {
dy1 = l2->y - l1->y;
dx1 = l2->x - l1->x;
if (dy1 > 0)
tmp = (dx1 << 16) / dy1;
else
tmp = 0;
x1 = l1->x;
error = 0;
derror = tmp & 0x0000ffff;
dxdy_min = tmp >> 16;
dxdy_max = dxdy_min + 1;
#ifdef INTERP_Z
z1 = l1->z;
dzdl_min = (dzdy + dzdx * dxdy_min);
dzdl_max = dzdl_min + dzdx;
#endif
#ifdef INTERP_RGB
r1 = l1->r;
drdl_min = (drdy + drdx * dxdy_min);
drdl_max = drdl_min + drdx;
g1 = l1->g;
dgdl_min = (dgdy + dgdx * dxdy_min);
dgdl_max = dgdl_min + dgdx;
b1 = l1->b;
dbdl_min = (dbdy + dbdx * dxdy_min);
dbdl_max = dbdl_min + dbdx;
#endif
#ifdef INTERP_ST
s1 = l1->s;
dsdl_min = (dsdy + dsdx * dxdy_min);
dsdl_max = dsdl_min + dsdx;
t1 = l1->t;
dtdl_min = (dtdy + dtdx * dxdy_min);
dtdl_max = dtdl_min + dtdx;
#endif
#ifdef INTERP_STZ
sz1 = l1->sz;
dszdl_min = (dszdy + dszdx * dxdy_min);
dszdl_max = dszdl_min + dszdx;
tz1 = l1->tz;
dtzdl_min = (dtzdy + dtzdx * dxdy_min);
dtzdl_max = dtzdl_min + dtzdx;
#endif
}
// compute values for the right edge
if (update_right) {
dx2 = (pr2->x - pr1->x);
dy2 = (pr2->y - pr1->y);
if (dy2 > 0)
dx2dy2 = (dx2 << 16) / dy2;
else
dx2dy2 = 0;
x2 = pr1->x << 16;
}
// we draw all the scan line of the part
while (nb_lines > 0) {
nb_lines--;
#ifndef DRAW_LINE
// generic draw line
{
register PIXEL *pp;
register int n;
#ifdef INTERP_Z
register unsigned int *pz;
register unsigned int z;
#endif
#ifdef INTERP_RGB
register unsigned int or1, og1, ob1;
#endif
#ifdef INTERP_ST
register unsigned int s, t;
#endif
#ifdef INTERP_STZ
float sz, tz;
#endif
n = (x2 >> 16) - x1;
pp = (PIXEL *)((char *)pp1 + x1 * PSZB);
#ifdef INTERP_Z
pz = pz1 + x1;
z = z1;
#endif
#ifdef INTERP_RGB
or1 = r1;
og1 = g1;
ob1 = b1;
#endif
#ifdef INTERP_ST
s = s1;
t = t1;
#endif
#ifdef INTERP_STZ
sz = sz1;
tz = tz1;
#endif
while (n >= 3) {
PUT_PIXEL(0);
PUT_PIXEL(1);
PUT_PIXEL(2);
PUT_PIXEL(3);
#ifdef INTERP_Z
pz += 4;
#endif
pp = (PIXEL *)((char *)pp + 4 * PSZB);
n -= 4;
}
while (n >= 0) {
PUT_PIXEL(0);
#ifdef INTERP_Z
pz += 1;
#endif
pp = (PIXEL *)((char *)pp + PSZB);
n -= 1;
}
}
#else
DRAW_LINE();
#endif
// left edge
error += derror;
if (error > 0) {
error -= 0x10000;
x1 += dxdy_max;
#ifdef INTERP_Z
z1 += dzdl_max;
#endif
#ifdef INTERP_RGB
r1 += drdl_max;
g1 += dgdl_max;
b1 += dbdl_max;
#endif
#ifdef INTERP_ST
s1 += dsdl_max;
t1 += dtdl_max;
#endif
#ifdef INTERP_STZ
sz1 += dszdl_max;
tz1 += dtzdl_max;
#endif
} else {
x1 += dxdy_min;
#ifdef INTERP_Z
z1 += dzdl_min;
#endif
#ifdef INTERP_RGB
r1 += drdl_min;
g1 += dgdl_min;
b1 += dbdl_min;
#endif
#ifdef INTERP_ST
s1 += dsdl_min;
t1 += dtdl_min;
#endif
#ifdef INTERP_STZ
sz1 += dszdl_min;
tz1 += dtzdl_min;
#endif
}
// right edge
x2 += dx2dy2;
// screen coordinates
pp1 = (PIXEL *)((char *)pp1 + linesize);
pz1 += xsize;
}
}
}
#undef INTERP_Z
#undef INTERP_RGB
#undef INTERP_ST
#undef INTERP_STZ
#undef DRAW_INIT
#undef DRAW_LINE
#undef PUT_PIXEL

View File

@ -1,6 +0,0 @@
#include "graphics/tinygl/zbuffer.h"
namespace TinyGL {
} // end of namespace TinyGL