generalized pixel format handling in 3d pipeline master
authorJohn Tsiombikas <jtsiomb@census.gr>
Wed, 4 Sep 2019 10:53:43 +0000 (13:53 +0300)
committerJohn Tsiombikas <jtsiomb@census.gr>
Wed, 4 Sep 2019 10:53:43 +0000 (13:53 +0300)
src/census/3dgfx.c
src/census/3dgfx.h
src/census/census.c
src/census/polyfill.h
src/census/polytmpl.h

index a028262..e8a895d 100644 (file)
@@ -50,7 +50,7 @@ struct g3d_state {
        struct material mtl;
 
        int width, height;
        struct material mtl;
 
        int width, height;
-       uint32_t *pixels;
+       g3d_pixel *pixels;
 
        int vport[4];
 
 
        int vport[4];
 
@@ -511,20 +511,20 @@ void g3d_draw_indexed(int prim, const struct g3d_vertex *varr, int varr_size,
                        if(st->opt & G3D_BLEND) {
                                int r, g, b;
                                int inv_alpha = 255 - pv[0].a;
                        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 {
                        } 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:
                        {
                        }
                        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;
                                draw_line(pv[0].x >> 8, pv[0].y >> 8, pv[1].x >> 8, pv[1].y >> 8, col);
                        }
                        break;
index 0ae58c9..19127a8 100644 (file)
@@ -2,6 +2,24 @@
 #define THREEDGFX_H_
 
 #include "inttypes.h"
 #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;
 
 struct g3d_vertex {
        float x, y, z, w;
index 7eea8d3..7c490db 100644 (file)
@@ -8,7 +8,7 @@
 #include "panic.h"
 
 static void draw_disc(float x, float y, float rad, int sub);
 #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;
 
 static int nverts = 256;
 static long start_time;
@@ -60,7 +60,7 @@ void draw_census(void)
                float t1 = (float)(i + 1) * dt;
                eval_logo(a, t0);
                eval_logo(b, t1);
                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) {
        }
 
        if(anim > 0.0f) {
@@ -98,7 +98,7 @@ static void draw_disc(float x, float y, float rad, int sub)
        g3d_end();
 }
 
        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;
 
 {
        float dx, dy, rx, ry, len;
 
index 0a88098..86c7947 100644 (file)
@@ -2,6 +2,7 @@
 #define POLYFILL_H_
 
 #include "inttypes.h"
 #define POLYFILL_H_
 
 #include "inttypes.h"
+#include "3dgfx.h"
 
 #define POLYFILL_MODE_MASK     0x03
 #define POLYFILL_TEX_BIT       0x04
 
 #define POLYFILL_MODE_MASK     0x03
 #define POLYFILL_TEX_BIT       0x04
@@ -33,7 +34,7 @@ struct pvertex {
 };
 
 struct pimage {
 };
 
 struct pimage {
-       uint32_t *pixels;
+       g3d_pixel *pixels;
        int width, height;
 
        int xshift, yshift;
        int width, height;
 
        int xshift, yshift;
index 03724cf..11ce0fa 100644 (file)
@@ -84,14 +84,14 @@ void POLYFILL(struct pvertex *pv, int nverts)
        int i, winding;
        int topidx = 0, botidx = 0, sltop = pfill_fb.height, slbot = 0;
        struct pvertex *left, *right;
        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 */
        /* 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;
 #endif
 #ifdef GOURAUD
        int32_t r, g, b, dr, dg, db, rslope, gslope, bslope;
@@ -216,7 +216,7 @@ void POLYFILL(struct pvertex *pv, int nverts)
 
        /* for each scanline ... */
        for(i=sltop; i<=slbot; i++) {
 
        /* for each scanline ... */
        for(i=sltop; i<=slbot; i++) {
-               uint32_t *pixptr;
+               g3d_pixel *pixptr;
                int32_t x;
 
                x = left[i].x;
                int32_t x;
 
                x = left[i].x;
@@ -264,7 +264,7 @@ void POLYFILL(struct pvertex *pv, int nverts)
                        int cr, cg, cb;
 #endif
 #ifdef BLEND
                        int cr, cg, cb;
 #endif
 #ifdef BLEND
-                       uint32_t fbcol;
+                       g3d_pixel fbcol;
                        int alpha, inv_alpha;
 #endif
 #ifdef GOURAUD
                        int alpha, inv_alpha;
 #endif
 #ifdef GOURAUD
@@ -289,18 +289,18 @@ void POLYFILL(struct pvertex *pv, int nverts)
                        {
                                int tx = (u >> (16 - pfill_tex.xshift)) & pfill_tex.xmask;
                                int ty = (v >> (16 - pfill_tex.yshift)) & pfill_tex.ymask;
                        {
                                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
                                 */
 #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
 #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
                        }
                        u += uslope;
@@ -321,16 +321,16 @@ void POLYFILL(struct pvertex *pv, int nverts)
 #endif
                        fbcol = *pixptr;
                        inv_alpha = 255 - alpha;
 #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)
                        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
 #endif
 
 #ifdef DEBUG_OVERDRAW