From: John Tsiombikas Date: Sun, 2 Oct 2016 09:05:41 +0000 (+0300) Subject: setting up to improve the rasterizer X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=commitdiff_plain;h=0945eeeef21fe85f9a592bfc2e41069a7894b08b setting up to improve the rasterizer --- diff --git a/src/3dgfx.c b/src/3dgfx.c index 31e649d..41b3959 100644 --- a/src/3dgfx.c +++ b/src/3dgfx.c @@ -15,6 +15,7 @@ typedef float g3d_matrix[16]; struct g3d_state { unsigned int opt; int frontface; + int fill_mode; g3d_matrix mat[G3D_NUM_MATRICES][STACK_SIZE]; int mtop[G3D_NUM_MATRICES]; @@ -46,6 +47,7 @@ int g3d_init(void) fprintf(stderr, "failed to allocate G3D context\n"); return -1; } + st->fill_mode = POLYFILL_FLAT; for(i=0; iwidth = width; st->height = height; st->pixels = pixels; + + pimg_fb.pixels = pixels; + pimg_fb.width = width; + pimg_fb.height = height; } void g3d_enable(unsigned int opt) @@ -91,6 +97,11 @@ void g3d_front_face(unsigned int order) st->frontface = order; } +void g3d_polygon_mode(int pmode) +{ + st->fill_mode = pmode; +} + void g3d_matrix_mode(int mmode) { st->mmode = mmode; @@ -335,7 +346,7 @@ void g3d_draw_indexed(int prim, const struct g3d_vertex *varr, int varr_size, } } - polyfill_flat(pv, vnum); + polyfill(st->fill_mode, pv, vnum); } } diff --git a/src/3dgfx.h b/src/3dgfx.h index c80ded1..4a3cde5 100644 --- a/src/3dgfx.h +++ b/src/3dgfx.h @@ -30,6 +30,12 @@ enum { /* arg to g3d_front_face */ enum { G3D_CCW, G3D_CW }; +/* arg to g3d_polygon_mode */ +enum { + G3D_WIRE, + G3D_FLAT +}; + /* matrix stacks */ enum { G3D_MODELVIEW, @@ -49,6 +55,7 @@ void g3d_setopt(unsigned int opt, unsigned int mask); unsigned int g3d_getopt(unsigned int mask); void g3d_front_face(unsigned int order); +void g3d_polygon_mode(int pmode); void g3d_matrix_mode(int mmode); diff --git a/src/gfxutil.h b/src/gfxutil.h index 8de5607..f811987 100644 --- a/src/gfxutil.h +++ b/src/gfxutil.h @@ -1,6 +1,12 @@ #ifndef GFXUTIL_H_ #define GFXUTIL_H_ +#define PACK_RGB16(r, g, b) \ + (((((r) >> 3) & 0x1f) << 11) | ((((g) >> 2) & 0x3f) << 5) | (((b) >> 3) & 0x1f)) + +#define PACK_RGB32(r, g, b) \ + ((((r) & 0xff) << 16) | (((g) & 0xff) << 8) | ((b) & 0xff)) + int clip_line(int *x0, int *y0, int *x1, int *y1, int xmin, int ymin, int xmax, int ymax); void draw_line(int x0, int y0, int x1, int y1, unsigned short color); diff --git a/src/polyfill.c b/src/polyfill.c index 3608b33..79d1d69 100644 --- a/src/polyfill.c +++ b/src/polyfill.c @@ -10,6 +10,8 @@ void (*fillfunc[])(struct pvertex*, int) = { 0, 0, 0 }; +struct pimage pimg_fb, pimg_texture; + void polyfill(int mode, struct pvertex *verts, int nverts) { #ifndef NDEBUG @@ -35,13 +37,13 @@ void polyfill_wire(struct pvertex *verts, int nverts) ++v; x1 = v->x >> 8; y1 = v->y >> 8; - if(clip_line(&x0, &y0, &x1, &y1, 0, 0, fb_width, fb_height)) { + if(clip_line(&x0, &y0, &x1, &y1, 0, 0, pimg_fb.width, pimg_fb.height)) { draw_line(x0, y0, x1, y1, color); } } x0 = verts[0].x >> 8; y0 = verts[0].y >> 8; - if(clip_line(&x1, &y1, &x0, &y0, 0, 0, fb_width, fb_height)) { + if(clip_line(&x1, &y1, &x0, &y0, 0, 0, pimg_fb.width, pimg_fb.height)) { draw_line(x1, y1, x0, y0, color); } } @@ -114,9 +116,9 @@ void polyfill_flat(struct pvertex *pv, int nverts) x = left_x >> 8; slen = (right_x >> 8) - (left_x >> 8); - pixptr = (uint16_t*)fb_pixels + sline * fb_width + x; + pixptr = pimg_fb.pixels + sline * pimg_fb.width + x; for(i=0; i 90) phi = 90; + if(phi < -90) phi = -90; + if(phi > 90) phi = 90; + } + } } + prev_mx = mouse_x; + prev_my = mouse_y; + prev_bmask = mouse_bmask; +} - /*float angle = (float)time_msec / 50.0;*/ +static void draw(void) +{ + update(); - memset(fb_pixels, 0, fb_width * fb_height * 2); + memset(lowres_pixels, 0, lowres_width * lowres_height * 2); g3d_matrix_mode(G3D_MODELVIEW); g3d_load_identity(); @@ -88,9 +109,19 @@ static void draw(void) g3d_rotate(phi, 1, 0, 0); g3d_rotate(theta, 0, 1, 0); + g3d_framebuffer(lowres_width, lowres_height, lowres_pixels); /*zsort(&torus);*/ draw_mesh(&cube); + draw_lowres_raster(); + + + g3d_framebuffer(fb_width, fb_height, fb_pixels); + + g3d_polygon_mode(G3D_WIRE); + draw_mesh(&cube); + g3d_polygon_mode(G3D_FLAT); + swap_buffers(fb_pixels); } @@ -288,3 +319,31 @@ static void zsort(struct mesh *m) qsort(m->iarr, nfaces, m->prim * sizeof *m->iarr, zsort_cmp); } + +static void draw_huge_pixel(uint16_t *dest, int dest_width, uint16_t color) +{ + int i, j; + uint16_t grid_color = PACK_RGB16(127, 127, 127); + + for(i=0; i> 8; } -#define PACK_RGB16(r, g, b) \ - (((((r) >> 3) & 0x1f) << 11) | ((((g) >> 2) & 0x3f) << 5) | (((b) >> 3) & 0x1f)) -#define PACK_RGB32(r, g, b) \ - ((((r) & 0xff) << 16) | (((g) & 0xff) << 8) | ((b) & 0xff)) - static void draw_tunnel_range(unsigned short *pix, int xoffs, int yoffs, int starty, int num_lines, long tm) { int i, j;