X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fxgl.c;h=7d22b2bc4e65cab65946a9cab5ed721effc6ec38;hb=ee0d92a6e621e6a8135b16914a09def52bd70a4b;hp=8f59d90fb2dee2a5380006d3db42e8b958e69717;hpb=f9fb40518b148be5e472ae4d47651d594ec5421b;p=gbajam22 diff --git a/src/xgl.c b/src/xgl.c index 8f59d90..7d22b2b 100644 --- a/src/xgl.c +++ b/src/xgl.c @@ -20,6 +20,7 @@ along with this program. If not, see . #include "xgl.h" #include "polyfill.h" #include "debug.h" +#include "util.h" #define MAT_STACK_SIZE 4 @@ -29,6 +30,8 @@ static int mtop; static unsigned int opt; static int32_t ldir[3]; +static int cur_cidx; + static void draw_ptlines(int prim, const struct xvertex *varr, int vcount); @@ -116,8 +119,13 @@ void xgl_mult_matrix(const int32_t *m2) } } +#if 0 #define XSIN(x) (int32_t)(sin(x / 65536.0f) * 65536.0f) #define XCOS(x) (int32_t)(cos(x / 65536.0f) * 65536.0f) +#else +#define XSIN(x) SIN(((x) << 8) / (X_2PI >> 8)) +#define XCOS(x) COS(((x) << 8) / (X_2PI >> 8)) +#endif void xgl_translate(int32_t x, int32_t y, int32_t z) { @@ -174,14 +182,19 @@ void xgl_scale(int32_t x, int32_t y, int32_t z) xgl_mult_matrix(m); } -static void xform(struct xvertex *out, const struct xvertex *in, const int32_t *m) +void xgl_index(int cidx) +{ + cur_cidx = cidx; +} + +static inline void xform(struct xvertex *out, const struct xvertex *in, const int32_t *m) { out->x = XMUL(m[0], in->x) + XMUL(m[4], in->y) + XMUL(m[8], in->z) + m[12]; out->y = XMUL(m[1], in->x) + XMUL(m[5], in->y) + XMUL(m[9], in->z) + m[13]; out->z = XMUL(m[2], in->x) + XMUL(m[6], in->y) + XMUL(m[10], in->z) + m[14]; } -static void xform_norm(struct xvertex *out, const struct xvertex *in, const int32_t *m) +static inline void xform_norm(struct xvertex *out, const struct xvertex *in, const int32_t *m) { out->nx = XMUL(m[0], in->nx) + XMUL(m[4], in->ny) + XMUL(m[8], in->nz); out->ny = XMUL(m[1], in->nx) + XMUL(m[5], in->ny) + XMUL(m[9], in->nz); @@ -191,8 +204,9 @@ static void xform_norm(struct xvertex *out, const struct xvertex *in, const int3 /* d = 1.0 / tan(fov/2) */ #define PROJ_D 0x20000 /* near Z = 0.5 */ -#define NEAR_Z 0x40000 +#define NEAR_Z 0x18000 +ARM_IWRAM void xgl_draw(int prim, const struct xvertex *varr, int vcount) { int i, cidx, clipnum; @@ -206,14 +220,11 @@ void xgl_draw(int prim, const struct xvertex *varr, int vcount) } while(vcount >= prim) { - cidx = 0xff;//varr->cidx; + cidx = cur_cidx;//varr->cidx; xform(xv, varr, mat[mtop]); xform_norm(xv, varr, mat[mtop]); - /* backfacing check */ - if(xv->nz > 0) goto skip_poly; - /* if(opt & XGL_LIGHTING) { ndotl = (xv->nx >> 8) * ldir[0] + (xv->ny >> 8) * ldir[1] + (xv->nz >> 8) * ldir[2]; @@ -223,19 +234,18 @@ void xgl_draw(int prim, const struct xvertex *varr, int vcount) } */ - for(i=0; i 0) { - xform(xv + i, varr + i, mat[mtop]); - } - xv[i].x = (xv[i].x << 1) / (xv[i].z >> 8); /* assume aspect: ~2 */ - xv[i].y = (xv[i].y << 2) / (xv[i].z >> 8); /* the shift is * PROJ_D */ - /* transform result is 24.8 */ + /* transform the rest of the vertices to view space */ + for(i=1; i> 8); /* assume aspect: ~2 */ + xvclip[i].y = (xvclip[i].y << 2) / (xvclip[i].z >> 8); /* the shift is * PROJ_D */ + /* transform result is 24.8 */ /* viewport */ pv[i].x = (((xvclip[i].x + 0x100) >> 1) * vp[2]) + (vp[0] << 8); pv[i].y = (((0x100 - xvclip[i].y) >> 1) * vp[3]) + (vp[1] << 8); @@ -293,14 +303,13 @@ void xgl_xyzzy(void) mat[mtop][12] = mat[mtop][13] = 0; } -/* 24.8 */ #define ISECT_NEAR(v0, v1) ((((v0)->z - NEAR_Z) << 8) / ((v0)->z - (v1)->z)) #define LERP_VATTR(res, v0, v1, t) \ do { \ - (res)->x = (v0)->x + (((v1)->x - (v0)->x) * (t) >> 8); \ - (res)->y = (v0)->y + (((v1)->y - (v0)->y) * (t) >> 8); \ - (res)->z = (v0)->z + (((v1)->z - (v0)->nx) >> 8) * (t); \ + (res)->x = (v0)->x + (((v1)->x - (v0)->x) >> 8) * (t); \ + (res)->y = (v0)->y + (((v1)->y - (v0)->y) >> 8) * (t); \ + (res)->z = (v0)->z + (((v1)->z - (v0)->z) >> 8) * (t); \ (res)->nx = (v0)->nx + (((v1)->nx - (v0)->nx) >> 8) * (t); \ (res)->ny = (v0)->ny + (((v1)->ny - (v0)->ny) >> 8) * (t); \ (res)->nz = (v0)->nz + (((v1)->nz - (v0)->nz) >> 8) * (t); \ @@ -309,6 +318,7 @@ void xgl_xyzzy(void) (res)->lit = (v0)->lit + (((v1)->lit - (v0)->lit) >> 8) * (t); \ } while(0) +ARM_IWRAM static int clip_edge_near(struct xvertex *poly, int *vnumptr, struct xvertex *v0, struct xvertex *v1) { int vnum = *vnumptr; @@ -354,6 +364,7 @@ static int clip_edge_near(struct xvertex *poly, int *vnumptr, struct xvertex *v0 } /* special case near-plane clipper */ +ARM_IWRAM int xgl_clip_near(struct xvertex *vout, int *voutnum, struct xvertex *vin, int vnum) { int i, nextidx, res;