7 static int32_t mvmat[16];
8 static int32_t pmat[16];
11 unsigned char *g3d_fbpixels;
12 int g3d_width, g3d_height;
18 memset(mvmat, 0, sizeof mvmat);
19 memset(pmat, 0, sizeof pmat);
20 mvmat[0] = mvmat[5] = mvmat[10] = mvmat[15] = 0x10000;
21 pmat[0] = pmat[5] = pmat[10] = pmat[15] = 0x10000;
26 void g3d_shutdown(void)
30 void g3d_framebuffer(int width, int height, void *fb)
41 void g3d_modelview(const int32_t *m)
43 memcpy(mvmat, m, sizeof mvmat);
46 void g3d_projection(const int32_t *m)
48 memcpy(pmat, m, sizeof pmat);
51 void g3d_color(int cidx)
56 static const int primverts[] = {1, 2, 3, 4};
58 void g3d_draw(int prim, struct g3d_vertex *varr, int vcount)
62 prim_vnum = primverts[prim];
64 for(i=0; i<vcount; i+=prim_vnum) {
65 g3d_draw_prim(prim, varr);
70 int32_t vpscale(int32_t x, int32_t s, int32_t shift);
71 #pragma aux vpscale = \
75 parm [eax] [ebx] [ecx] \
80 void g3d_draw_prim(int prim, struct g3d_vertex *varr)
82 int i, vcount, x, y, x1, y1;
83 struct g3d_vertex v[4];
85 vcount = primverts[prim];
87 for(i=0; i<vcount; i++) {
90 /* transform to view space */
91 g3d_xform(v + i, mvmat);
93 /* transform to homogeneous clip space */
94 g3d_xform(v + i, pmat);
98 /* perspective division */
100 v[i].x = (v[i].x << 4) / (v[i].w >> 4);
101 v[i].y = (v[i].y << 4) / (v[i].w >> 4);
107 /* viewport transform */
108 v[i].x = vpscale(v[i].x, vp[2], 1) + (vp[0] << 8);
109 v[i].y = vpscale(-v[i].y, vp[3], 1) + (vp[1] << 8);
116 if(x >= 0 && y >= 0 && x < XRES && y < YRES) {
117 g3d_fbpixels[y * XRES + x] = g3d_curcidx;