# HG changeset patch # User John Tsiombikas # Date 1322272788 -7200 # Node ID bce78aaafc68591efd2bc425466d1322e1e0ad1f # Parent 569d62294ae33b8c7729267d1f13a3ad9ea6fcc9 foo diff -r 569d62294ae3 -r bce78aaafc68 dosemu/conio.h --- a/dosemu/conio.h Mon Nov 21 12:45:18 2011 +0200 +++ b/dosemu/conio.h Sat Nov 26 03:59:48 2011 +0200 @@ -2,6 +2,6 @@ #define CONIO_H_ int kbhit(void); -char getch(void); +int getch(void); #endif /* CONIO_H_ */ diff -r 569d62294ae3 -r bce78aaafc68 dosemu/dosemu.c --- a/dosemu/dosemu.c Mon Nov 21 12:45:18 2011 +0200 +++ b/dosemu/dosemu.c Sat Nov 26 03:59:48 2011 +0200 @@ -38,16 +38,21 @@ void set_video_mode(int mode) { int resx = 320, resy = 200; + unsigned int sdl_flags = SDL_HWPALETTE; if(getenv("DOSEMU_DOUBLESIZE")) { resx *= 2; resy *= 2; } + if(getenv("DOSEMU_FULLSCREEN")) { + sdl_flags |= SDL_FULLSCREEN; + } + switch(mode) { case 0x13: SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER); - if(!(fbsurf = SDL_SetVideoMode(resx, resy, 8, SDL_HWPALETTE))) { + if(!(fbsurf = SDL_SetVideoMode(resx, resy, 8, sdl_flags))) { fprintf(stderr, "failed to set video mode\n"); abort(); } @@ -120,9 +125,9 @@ return keybev != 0; } -char getch(void) +int getch(void) { - char res; + int res; while(!keybev) { SDL_Event ev; diff -r 569d62294ae3 -r bce78aaafc68 src/mglgen.c --- a/src/mglgen.c Mon Nov 21 12:45:18 2011 +0200 +++ b/src/mglgen.c Sat Nov 26 03:59:48 2011 +0200 @@ -27,40 +27,40 @@ mgl_begin(MGL_QUADS); /* front */ mgl_normal(0, 0, 1); - mgl_texcoord2f(0, 1); mgl_vertex3f(-hsz, hsz, hsz); - mgl_texcoord2f(0, 0); mgl_vertex3f(-hsz, -hsz, hsz); - mgl_texcoord2f(1, 0); mgl_vertex3f(hsz, -hsz, hsz); - mgl_texcoord2f(1, 1); mgl_vertex3f(hsz, hsz, hsz); + mgl_texcoord2f(0, 0); mgl_vertex3f(-hsz, hsz, hsz); + mgl_texcoord2f(0, 1); mgl_vertex3f(-hsz, -hsz, hsz); + mgl_texcoord2f(1, 1); mgl_vertex3f(hsz, -hsz, hsz); + mgl_texcoord2f(1, 0); mgl_vertex3f(hsz, hsz, hsz); /* back */ mgl_normal(0, 0, -1); - mgl_texcoord2f(0, 1); mgl_vertex3f(hsz, hsz, -hsz); - mgl_texcoord2f(0, 0); mgl_vertex3f(hsz, -hsz, -hsz); - mgl_texcoord2f(1, 0); mgl_vertex3f(-hsz, -hsz, -hsz); - mgl_texcoord2f(1, 1); mgl_vertex3f(-hsz, hsz, -hsz); + mgl_texcoord2f(0, 0); mgl_vertex3f(hsz, hsz, -hsz); + mgl_texcoord2f(0, 1); mgl_vertex3f(hsz, -hsz, -hsz); + mgl_texcoord2f(1, 1); mgl_vertex3f(-hsz, -hsz, -hsz); + mgl_texcoord2f(1, 0); mgl_vertex3f(-hsz, hsz, -hsz); /* right */ mgl_normal(1, 0, 0); - mgl_texcoord2f(0, 1); mgl_vertex3f(hsz, hsz, hsz); - mgl_texcoord2f(0, 0); mgl_vertex3f(hsz, -hsz, hsz); - mgl_texcoord2f(1, 0); mgl_vertex3f(hsz, -hsz, -hsz); - mgl_texcoord2f(1, 1); mgl_vertex3f(hsz, hsz, -hsz); + mgl_texcoord2f(0, 0); mgl_vertex3f(hsz, hsz, hsz); + mgl_texcoord2f(0, 1); mgl_vertex3f(hsz, -hsz, hsz); + mgl_texcoord2f(1, 1); mgl_vertex3f(hsz, -hsz, -hsz); + mgl_texcoord2f(1, 0); mgl_vertex3f(hsz, hsz, -hsz); /* left */ mgl_normal(-1, 0, 0); - mgl_texcoord2f(0, 1); mgl_vertex3f(-hsz, hsz, -hsz); - mgl_texcoord2f(0, 0); mgl_vertex3f(-hsz, -hsz, -hsz); - mgl_texcoord2f(1, 0); mgl_vertex3f(-hsz, -hsz, hsz); - mgl_texcoord2f(1, 1); mgl_vertex3f(-hsz, hsz, hsz); + mgl_texcoord2f(0, 0); mgl_vertex3f(-hsz, hsz, -hsz); + mgl_texcoord2f(0, 1); mgl_vertex3f(-hsz, -hsz, -hsz); + mgl_texcoord2f(1, 1); mgl_vertex3f(-hsz, -hsz, hsz); + mgl_texcoord2f(1, 0); mgl_vertex3f(-hsz, hsz, hsz); /* top */ mgl_normal(0, 1, 0); - mgl_texcoord2f(0, 1); mgl_vertex3f(-hsz, hsz, -hsz); - mgl_texcoord2f(0, 0); mgl_vertex3f(-hsz, hsz, hsz); - mgl_texcoord2f(1, 0); mgl_vertex3f(hsz, hsz, hsz); - mgl_texcoord2f(1, 1); mgl_vertex3f(hsz, hsz, -hsz); + mgl_texcoord2f(0, 0); mgl_vertex3f(-hsz, hsz, -hsz); + mgl_texcoord2f(0, 1); mgl_vertex3f(-hsz, hsz, hsz); + mgl_texcoord2f(1, 1); mgl_vertex3f(hsz, hsz, hsz); + mgl_texcoord2f(1, 0); mgl_vertex3f(hsz, hsz, -hsz); /* bottom */ mgl_normal(0, -1, 0); - mgl_texcoord2f(0, 1); mgl_vertex3f(hsz, -hsz, -hsz); - mgl_texcoord2f(0, 0); mgl_vertex3f(hsz, -hsz, hsz); - mgl_texcoord2f(1, 0); mgl_vertex3f(-hsz, -hsz, hsz); - mgl_texcoord2f(1, 1); mgl_vertex3f(-hsz, -hsz, -hsz); + mgl_texcoord2f(0, 0); mgl_vertex3f(hsz, -hsz, -hsz); + mgl_texcoord2f(0, 1); mgl_vertex3f(hsz, -hsz, hsz); + mgl_texcoord2f(1, 1); mgl_vertex3f(-hsz, -hsz, hsz); + mgl_texcoord2f(1, 0); mgl_vertex3f(-hsz, -hsz, -hsz); mgl_end(); } diff -r 569d62294ae3 -r bce78aaafc68 src/mglimpl.h --- a/src/mglimpl.h Mon Nov 21 12:45:18 2011 +0200 +++ b/src/mglimpl.h Sat Nov 26 03:59:48 2011 +0200 @@ -21,6 +21,13 @@ #define MATRIX_STACK_SIZE 8 #define MAX_LIGHTS 4 +#define ZTILE_SIZE 16384 +#define ZTILE_SHIFT 14 +#define ZTILE_MASK 0x3fff + +#define ZTILE(x) (((x) & ~ZTILE_MASK) >> ZTILE_SHIFT) +#define ZTILE_OFFS(x) ((x) & ZTILE_MASK) + #define ROUND(x) ((x) >= 0.0 ? (x) + 0.5 : (x) - 0.5) typedef struct { @@ -71,7 +78,8 @@ struct framebuffer { int width, height; unsigned char *pixels; - unsigned short **zbuf; /* zbuffer broken in 64k tiles */ + unsigned short **zbuf; /* zbuffer broken in ZTILE_SIZE tiles */ + int num_ztiles; }; diff -r 569d62294ae3 -r bce78aaafc68 src/mglrast.c --- a/src/mglrast.c Mon Nov 21 12:45:18 2011 +0200 +++ b/src/mglrast.c Sat Nov 26 03:59:48 2011 +0200 @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "mingl.h" #include "mglimpl.h" diff -r 569d62294ae3 -r bce78aaafc68 src/mingl.c --- a/src/mingl.c Mon Nov 21 12:45:18 2011 +0200 +++ b/src/mingl.c Sat Nov 26 03:59:48 2011 +0200 @@ -84,8 +84,19 @@ void mgl_free(void) { + int i; + mgl_rast_cleanup(); free(fb.pixels); + fb.pixels = 0; + + if(fb.zbuf) { + for(i=0; ipos.y); end = (int)ROUND(v1->pos.y); - x = v0->pos.x; + if(start >= 0) { + + x = v0->pos.x; #ifdef INTERP_DEPTH - z = v0->pos.z; + z = v0->pos.z; #endif #ifdef INTERP_ENERGY - e = v0->energy; + e = v0->energy; #endif #ifdef INTERP_TEX - u = v0->tc.x; - v = v0->tc.y; + u = v0->tc.x; + v = v0->tc.y; #endif + } else { + float lines = -v0->pos.y; + + x = v0->pos.x + dfdx * lines; +#ifdef INTERP_DEPTH + z = v0->pos.z + dfdz * lines; +#endif +#ifdef INTERP_ENERGY + e = v0->energy + dfde * lines; +#endif +#ifdef INTERP_TEX + u = v0->tc.x + dfdu * lines; + v = v0->tc.y + dfdv * lines; +#endif + start = 0; + } + + if(end >= fb->height) { + end = fb->height - 1; + } + + for(i=start; iflags & MGL_CULL_FACE) { @@ -133,7 +156,6 @@ tmp = x0; x0 = x1; x1 = tmp; - len = -len; left = vright; right = vleft; @@ -142,13 +164,15 @@ right = vright; } - if(x0 < 0) x0 = 0; - if(x1 >= fb->width) x1 = fb->width - 1; - - assert(len >= 0); + if(x1 >= fb->width) { + x1 = fb->width - 1; + } cidx = left[y].cidx; #if !defined(INTERP_DEPTH) && !defined(INTERP_ENERGY) && !defined(INTERP_TEX) + if(x0 < 0) x0 = 0; + len = x1 - x0; + assert(len >= 0); /* no interpolation at all, just memset the whole scanline */ memset(sline + x0, cidx + left[y].energy * st->col_range, len); #else @@ -160,29 +184,72 @@ return; } + if(x0 >= 0) { #ifdef INTERP_DEPTH - z = left[y].pos.z; - dz = right[y].pos.z - z; - dfdz = dz / dx; + z = left[y].pos.z; + dz = right[y].pos.z - z; + dfdz = dz / dx; #endif #ifdef INTERP_ENERGY - e = left[y].energy; - de = right[y].energy - e; - dfde = de / dx; + e = left[y].energy; + de = right[y].energy - e; + dfde = de / dx; #endif #ifdef INTERP_TEX - u = left[y].tc.x; - v = left[y].tc.y; - du = right[y].tc.x - u; - dv = right[y].tc.y - v; - dfdu = du / dx; - dfdv = dv / dx; + u = left[y].tc.x; + v = left[y].tc.y; + du = right[y].tc.x - u; + dv = right[y].tc.y - v; + dfdu = du / dx; + dfdv = dv / dx; #endif + } else { + float dist = -left[y].pos.x; + +#ifdef INTERP_DEPTH + dz = right[y].pos.z - left[y].pos.z; + dfdz = dz / dx; + z = left[y].pos.z + dfdz * dist; +#endif +#ifdef INTERP_ENERGY + de = right[y].energy - left[y].energy; + dfde = de / dx; + e = left[y].energy + dfde * dist; +#endif +#ifdef INTERP_TEX + du = right[y].tc.x - left[y].tc.x; + dv = right[y].tc.y - left[y].tc.y; + dfdu = du / dx; + dfdv = dv / dx; + u = left[y].tc.x + dfdu * dist; + v = left[y].tc.y + dfdv * dist; +#endif + x0 = 0; + } + + len = x1 - x0; for(i=0; ipixels; + unsigned short zval = (unsigned short)(z * USHRT_MAX); + unsigned short *zptr = fb->zbuf[ZTILE(pix)] + ZTILE_OFFS(pix); + + if(z < 0.0 || z >= 1.0 || zval > *zptr) { +# ifdef INTERP_TEX + u += dfdu; + v += dfdv; +# endif +# ifdef INTERP_ENERGY + e += dfde; +# endif + z += dfdz; + continue; + } + + *zptr = zval; z += dfdz; #endif #ifdef INTERP_TEX diff -r 569d62294ae3 -r bce78aaafc68 src/test.c --- a/src/test.c Mon Nov 21 12:45:18 2011 +0200 +++ b/src/test.c Sat Nov 26 03:59:48 2011 +0200 @@ -53,7 +53,7 @@ enum { CUBE, SPHERE, TORUS, NUM_PRIMS }; static int prim = SPHERE; static int auto_rotate = 1; -static float cam_theta, cam_phi; +static float cam_theta, cam_phi, cam_zoom = 4.0; static int mx, my; @@ -154,6 +154,7 @@ } mgl_enable(MGL_CULL_FACE); + mgl_enable(MGL_DEPTH_TEST); mgl_enable(MGL_SMOOTH); mgl_color_range(grad_range - 1); /* gradient range */ @@ -180,6 +181,7 @@ { float angle = get_msec() / 10.0; mgl_clear(0); + mgl_clear_depth(); mgl_matrix_mode(MGL_MODELVIEW); mgl_load_identity(); @@ -190,7 +192,7 @@ mgl_rotate(cam_theta, 0, 1, 0); mgl_rotate(cam_phi, 1, 0, 0); } - mgl_translate(0, 0, -4); + mgl_translate(0, 0, -cam_zoom); switch(prim) { case TORUS: @@ -316,13 +318,19 @@ prev_x = x; prev_y = y; - if(bnstate) { + if(bnstate & MOUSE_LEFT) { cam_theta += dx; cam_phi += dy; if(cam_phi > 90) cam_phi = 90; if(cam_phi < -90) cam_phi = -90; } + if(bnstate & MOUSE_RIGHT) { + cam_zoom += dy * 0.1; + if(cam_zoom < 0.0) { + cam_zoom = 0.0; + } + } } static void sighandler(int s)