struct material mtl;
int width, height;
- uint32_t *pixels;
+ g3d_pixel *pixels;
int vport[4];
if(st->opt & G3D_BLEND) {
int r, g, b;
int inv_alpha = 255 - pv[0].a;
- uint32_t *dest = st->pixels + (pv[0].y >> 8) * st->width + (pv[0].x >> 8);
- r = ((int)pv[0].r * pv[0].a + UNPACK_R32(*dest) * inv_alpha) >> 8;
- g = ((int)pv[0].g * pv[0].a + UNPACK_G32(*dest) * inv_alpha) >> 8;
- b = ((int)pv[0].b * pv[0].a + UNPACK_B32(*dest) * inv_alpha) >> 8;
- *dest++ = PACK_RGB16(r, g, b);
+ g3d_pixel *dest = st->pixels + (pv[0].y >> 8) * st->width + (pv[0].x >> 8);
+ r = ((int)pv[0].r * pv[0].a + G3D_UNPACK_R(*dest) * inv_alpha) >> 8;
+ g = ((int)pv[0].g * pv[0].a + G3D_UNPACK_G(*dest) * inv_alpha) >> 8;
+ b = ((int)pv[0].b * pv[0].a + G3D_UNPACK_B(*dest) * inv_alpha) >> 8;
+ *dest++ = G3D_PACK_RGB(r, g, b);
} else {
- uint32_t *dest = st->pixels + (pv[0].y >> 8) * st->width + (pv[0].x >> 8);
- *dest = PACK_RGB32(pv[0].r, pv[0].g, pv[0].b);
+ g3d_pixel *dest = st->pixels + (pv[0].y >> 8) * st->width + (pv[0].x >> 8);
+ *dest = G3D_PACK_RGB(pv[0].r, pv[0].g, pv[0].b);
}
break;
case 2:
{
- uint32_t col = PACK_RGB32(pv[0].r, pv[0].g, pv[0].b);
+ g3d_pixel col = G3D_PACK_RGB(pv[0].r, pv[0].g, pv[0].b);
draw_line(pv[0].x >> 8, pv[0].y >> 8, pv[1].x >> 8, pv[1].y >> 8, col);
}
break;
#define THREEDGFX_H_
#include "inttypes.h"
+#include "gfxutil.h"
+
+#define G3D_PIXFMT32
+typedef uint32_t g3d_pixel;
+
+#ifdef G3D_PIXFMT16
+#define G3D_PACK_RGB(r, g, b) PACK_RGB16(r, g, b)
+#define G3D_UNPACK_R(c) UNPACK_R16(c)
+#define G3D_UNPACK_G(c) UNPACK_G16(c)
+#define G3D_UNPACK_B(c) UNPACK_B16(c)
+#endif
+#ifdef G3D_PIXFMT32
+#define G3D_PACK_RGB(r, g, b) PACK_RGB32(r, g, b)
+#define G3D_UNPACK_R(c) UNPACK_R32(c)
+#define G3D_UNPACK_G(c) UNPACK_G32(c)
+#define G3D_UNPACK_B(c) UNPACK_B32(c)
+#endif
+
struct g3d_vertex {
float x, y, z, w;
#include "panic.h"
static void draw_disc(float x, float y, float rad, int sub);
-static void draw_line(float x0, float y0, float x1, float y1, float rad);
+static void draw_fatline(float x0, float y0, float x1, float y1, float rad);
static int nverts = 256;
static long start_time;
float t1 = (float)(i + 1) * dt;
eval_logo(a, t0);
eval_logo(b, t1);
- draw_line(a[0], a[1], b[0], b[1], 0.02);
+ draw_fatline(a[0], a[1], b[0], b[1], 0.02);
}
if(anim > 0.0f) {
g3d_end();
}
-static void draw_line(float x0, float y0, float x1, float y1, float rad)
+static void draw_fatline(float x0, float y0, float x1, float y1, float rad)
{
float dx, dy, rx, ry, len;
#define POLYFILL_H_
#include "inttypes.h"
+#include "3dgfx.h"
#define POLYFILL_MODE_MASK 0x03
#define POLYFILL_TEX_BIT 0x04
};
struct pimage {
- uint32_t *pixels;
+ g3d_pixel *pixels;
int width, height;
int xshift, yshift;
int i, winding;
int topidx = 0, botidx = 0, sltop = pfill_fb.height, slbot = 0;
struct pvertex *left, *right;
- uint32_t color;
+ g3d_pixel color;
/* the following variables are used for interpolating horizontally accros scanlines */
#if defined(GOURAUD) || defined(TEXMAP)
int mid;
int32_t dx, tmp;
#else
/* flat version, just pack the color now */
- color = PACK_RGB32(pv[0].r, pv[0].g, pv[0].b);
+ color = G3D_PACK_RGB(pv[0].r, pv[0].g, pv[0].b);
#endif
#ifdef GOURAUD
int32_t r, g, b, dr, dg, db, rslope, gslope, bslope;
/* for each scanline ... */
for(i=sltop; i<=slbot; i++) {
- uint32_t *pixptr;
+ g3d_pixel *pixptr;
int32_t x;
x = left[i].x;
int cr, cg, cb;
#endif
#ifdef BLEND
- uint32_t fbcol;
+ g3d_pixel fbcol;
int alpha, inv_alpha;
#endif
#ifdef GOURAUD
{
int tx = (u >> (16 - pfill_tex.xshift)) & pfill_tex.xmask;
int ty = (v >> (16 - pfill_tex.yshift)) & pfill_tex.ymask;
- uint32_t texel = pfill_tex.pixels[(ty << pfill_tex.xshift) + tx];
+ g3d_pixel texel = pfill_tex.pixels[(ty << pfill_tex.xshift) + tx];
#ifdef GOURAUD
/* This is not correct, should be /255, but it's much faster
* to shift by 8 (/256), and won't make a huge difference
*/
- cr = (cr * UNPACK_R32(texel)) >> 8;
- cg = (cg * UNPACK_G32(texel)) >> 8;
- cb = (cb * UNPACK_B32(texel)) >> 8;
+ cr = (cr * G3D_UNPACK_R(texel)) >> 8;
+ cg = (cg * G3D_UNPACK_G(texel)) >> 8;
+ cb = (cb * G3D_UNPACK_B(texel)) >> 8;
#else
- cr = UNPACK_R32(texel);
- cg = UNPACK_G32(texel);
- cb = UNPACK_B32(texel);
+ cr = G3D_UNPACK_R(texel);
+ cg = G3D_UNPACK_G(texel);
+ cb = G3D_UNPACK_B(texel);
#endif
}
u += uslope;
#endif
fbcol = *pixptr;
inv_alpha = 255 - alpha;
- cr = (cr * alpha + UNPACK_R32(fbcol) * inv_alpha) >> 8;
- cg = (cg * alpha + UNPACK_G32(fbcol) * inv_alpha) >> 8;
- cb = (cb * alpha + UNPACK_B32(fbcol) * inv_alpha) >> 8;
+ cr = (cr * alpha + G3D_UNPACK_R(fbcol) * inv_alpha) >> 8;
+ cg = (cg * alpha + G3D_UNPACK_G(fbcol) * inv_alpha) >> 8;
+ cb = (cb * alpha + G3D_UNPACK_B(fbcol) * inv_alpha) >> 8;
if(cr > 255) cr = 255;
if(cg > 255) cg = 255;
if(cb > 255) cb = 255;
#endif /* BLEND */
#if defined(GOURAUD) || defined(TEXMAP) || defined(BLEND)
- color = PACK_RGB32(cr, cg, cb);
+ color = G3D_PACK_RGB(cr, cg, cb);
#endif
#ifdef DEBUG_OVERDRAW