From 921c229affb2b1da97d7be21d5c86ad045a6fcc3 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Tue, 6 Sep 2016 07:03:44 +0300 Subject: [PATCH] started writing some 3d pipeline stuff --- src/3dgfx.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/3dgfx.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ src/polyfill.c | 41 ++++++++++++++++++++++++++++ src/polyfill.h | 24 +++++++++++++++++ src/polytest.c | 33 +++++++++++++++++++++++ 5 files changed, 249 insertions(+) create mode 100644 src/3dgfx.c create mode 100644 src/3dgfx.h create mode 100644 src/polyfill.c create mode 100644 src/polyfill.h create mode 100644 src/polytest.c diff --git a/src/3dgfx.c b/src/3dgfx.c new file mode 100644 index 0000000..e7aabc2 --- /dev/null +++ b/src/3dgfx.c @@ -0,0 +1,81 @@ +#include +#include "3dgfx.h" + +#define STACK_SIZE 8 +typedef float g3d_matrix[16]; + +struct g3d_state { + unsigned int opt; + + g3d_matrix mat[G3D_NUM_MATRICES][STACK_SIZE]; + int mtop[G3D_NUM_MATRICES]; + + int width, height; + void *pixels; +}; + +static struct g3d_state st; + +void g3d_init(void) +{ + int i; + + memset(&st, 0, sizeof st); + + for(i=0; i +#include +#include "polyfill.h" +#include "gfxutil.h" +#include "demo.h" + +void (*fillfunc[])(struct pvertex*, int) = { + polyfill_wire, + 0, 0, 0, 0 +}; + +void polyfill(int mode, struct pvertex *verts, int nverts) +{ +#ifndef NDEBUG + if(!fillfunc[mode]) { + fprintf(stderr, "polyfill mode %d not implemented\n", mode); + abort(); + } +#endif + + fillfunc[mode](verts, nverts); +} + +void polyfill_wire(struct pvertex *verts, int nverts) +{ + int i; + struct pvertex *v = verts; + unsigned short color = ((v->r << 8) & 0xf800) | + ((v->g << 3) & 0x7e0) | ((v->b >> 3) & 0x1f); + + for(i=0; ix >> 8; + y0 = v->y >> 8; + ++v; + x1 = v->x >> 8; + y1 = v->y >> 8; + clip_line(&x0, &y0, &x1, &y1, 0, 0, fb_width, fb_height); + draw_line(x0, y0, x1, y1, color); + } +} diff --git a/src/polyfill.h b/src/polyfill.h new file mode 100644 index 0000000..57f0dc4 --- /dev/null +++ b/src/polyfill.h @@ -0,0 +1,24 @@ +#ifndef POLYFILL_H_ +#define POLYFILL_H_ + +#include "inttypes.h" + +enum { + POLYFILL_WIRE, + POLYFILL_FLAT, + POLYFILL_GOURAUD, + POLYFILL_TEX, + POLYFILL_TEX_GOURAUD +}; + +/* projected vertices for the rasterizer */ +struct pvertex { + int32_t x, y; /* 24.8 fixed point */ + int32_t u, v; /* 16.16 fixed point */ + unsigned char r, g, b; +}; + +void polyfill(int mode, struct pvertex *verts, int nverts); +void polyfill_wire(struct pvertex *verts, int nverts); + +#endif /* POLYFILL_H_ */ diff --git a/src/polytest.c b/src/polytest.c new file mode 100644 index 0000000..fb8d9af --- /dev/null +++ b/src/polytest.c @@ -0,0 +1,33 @@ +#include +#include +#include "screen.h" + +static int init(void); +static void destroy(void); +static void draw(void); + +static struct screen scr = { + "polytest", + init, + destroy, + 0, 0, + draw +}; + +struct screen *polytest_screen(void) +{ + return &scr; +} + +static int init(void) +{ + return 0; +} + +static void destroy(void) +{ +} + +static void draw(void) +{ +} -- 1.7.10.4