--- ray/src/hd/rhd_glx.c 1997/12/23 18:31:00 3.1 +++ ray/src/hd/rhd_glx.c 1997/12/30 16:59:46 3.9 @@ -6,12 +6,11 @@ static char SCCSid[] = "$SunId$ SGI"; /* * OpenGL GLX driver for holodeck display. - * Based on rview driver. + * Based on x11 driver. */ #include "standard.h" -#include "tonemap.h" -#include "rhdriver.h" +#include "rhd_qtree.h" #include @@ -21,25 +20,20 @@ static char SCCSid[] = "$SunId$ SGI"; #define FEQ(a,b) ((a)-(b) <= FTINY && (a)-(b) >= -FTINY) #endif -#ifndef int4 -#define int4 int +#ifndef MAXCONE +#define MAXCONE 16 /* number of different cone sizes */ #endif - -#ifndef FREEPCT -#define FREEPCT 25 /* percentage of values to free */ +#ifndef MAXVERT +#define MAXVERT 32 /* maximum number of cone vertices */ #endif - -#ifndef NCONEV -#define NCONEV 7 /* number of cone base vertices */ +#ifndef MINVERT +#define MINVERT 4 /* minimum number of cone vertices */ #endif -#ifndef CONEH -#define CONEH 0.25 /* cone height (fraction of depth) */ +#ifndef DEPTHFACT +#define DEPTHFACT 16. /* multiplier for depth tests */ #endif -#ifndef CONEW -#define CONEW 0.035 /* cone width (fraction of screen) */ -#endif -#define GAMMA 2.2 /* default gamma correction */ +#define GAMMA 1.4 /* default gamma correction */ #define MOVPCT 7 /* percent distance to move /frame */ #define MOVDIR(b) ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1) @@ -65,7 +59,6 @@ struct driver odev; /* global device driver structur static XEvent currentevent; /* current event */ static int mapped = 0; /* window is mapped? */ -static unsigned long *pixval = NULL; /* allocated pixels */ static unsigned long ourblack=0, ourwhite=~0; static Display *ourdisplay = NULL; /* our display */ @@ -73,38 +66,24 @@ static XVisualInfo *ourvinf; /* our visual informati static Window gwind = 0; /* our graphics window */ static GLXContext gctx; /* our GLX context */ -static double mindepth = FHUGE; /* minimum depth value so far */ -static double maxdepth = 0.; /* maximum depth value */ - static double pwidth, pheight; /* pixel dimensions (mm) */ -static FVECT conev[NCONEV]; /* drawing cone */ -static double coneh; /* cone height */ +static double curzmax = 1e4; /* current depth upper limit */ +static double nxtzmax = 0.; /* maximum (finite) depth so far */ +static struct { + double rad; /* cone radius */ + int nverts; /* number of vertices */ + FVECT *va; /* allocated vertex array */ +} cone[MAXCONE]; /* precomputed cones for drawing */ + static int inpresflags; /* input result flags */ static int headlocked = 0; /* lock vertical motion */ -static struct { - float (*wp)[3]; /* world intersection point array */ - int4 *wd; /* world direction array */ - TMbright *brt; /* encoded brightness array */ - BYTE (*chr)[3]; /* encoded chrominance array */ - BYTE (*rgb)[3]; /* tone-mapped color array */ - BYTE *alpha; /* alpha values */ - int nl; /* count of values */ - int bl, tl; /* bottom and top (next) value index */ - int tml; /* next value needing tone-mapping */ - int drl; /* next value in need of drawing */ - char *base; /* base of allocated memory */ -} rV; /* our collection of values */ - -#define redraw() (rV.drl = rV.bl) - static int resizewindow(), getevent(), getkey(), moveview(), - setGLview(), getmove(), fixwindow(), mytmflags(), - newvalue(), drawvalue(), Compost(), - FindValue(), AllocValues(), TMapValues(), FreeValues(); + initcones(), freecones(), + getmove(), fixwindow(), mytmflags(); dev_open(id) /* initialize X11 driver */ @@ -113,17 +92,15 @@ char *id; extern char *getenv(); static int atlBest[] = {GLX_RGBA, GLX_RED_SIZE,8, GLX_GREEN_SIZE,8, GLX_BLUE_SIZE,8, - GLX_ALPHA_SIZE,8, GLX_DEPTH_SIZE,23, - /*GLX_DOUBLEBUFFER,*/ None}; - static int atlOK[] = {GLX_RGBA, GLX_RED_SIZE,4, - GLX_GREEN_SIZE,4, GLX_BLUE_SIZE,4, - GLX_ALPHA_SIZE,4, GLX_DEPTH_SIZE,15, - /*GLX_DOUBLEBUFFER,*/ None}; + GLX_DEPTH_SIZE,15, None}; char *gv; double gamval = GAMMA; XSetWindowAttributes ourwinattr; XWMHints ourxwmhints; XSizeHints oursizhints; + /* set quadtree globals */ + qtMinNodesiz = 3; + qtDepthEps = 0.07; /* open display server */ ourdisplay = XOpenDisplay(NULL); if (ourdisplay == NULL) @@ -131,8 +108,6 @@ char *id; /* find a usable visual */ ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlBest); if (ourvinf == NULL) - ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlOK); - if (ourvinf == NULL) error(USER, "no suitable visuals available"); /* get a context */ gctx = glXCreateContext(ourdisplay, ourvinf, NULL, GL_TRUE); @@ -167,13 +142,16 @@ char *id; oursizhints.min_height = MINHEIGHT; oursizhints.flags = PMinSize; XSetNormalHints(ourdisplay, gwind, &oursizhints); - /* map the window and get its size */ - XMapWindow(ourdisplay, gwind); - dev_input(); - /* allocate our value list */ - if (!AllocValues(DisplayWidth(ourdisplay,ourscreen) * - DisplayHeight(ourdisplay,ourscreen) / 4)) - error(SYSTEM, "insufficient memory for value storage"); + /* set GLX context */ + glXMakeCurrent(ourdisplay, gwind, gctx); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LEQUAL); + glShadeModel(GL_FLAT); + glDisable(GL_DITHER); + glDisable(GL_CULL_FACE); + glMatrixMode(GL_PROJECTION); + glOrtho(0., 1., 0., 1., -.01, 1.01); + glTranslated(0., 0., -1.01); /* figure out sensible view */ pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) / DisplayWidth(ourdisplay, ourscreen); @@ -181,20 +159,18 @@ char *id; DisplayHeight(ourdisplay, ourscreen); copystruct(&odev.v, &stdview); odev.v.type = VT_PER; - odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres); - odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres); + /* map the window */ + XMapWindow(ourdisplay, gwind); + dev_input(); /* sets size and view angles */ + /* allocate our leaf pile */ + if (!qtAllocLeaves(DisplayWidth(ourdisplay,ourscreen) * + DisplayHeight(ourdisplay,ourscreen) / + (qtMinNodesiz*qtMinNodesiz))) + error(SYSTEM, "insufficient memory for value storage"); odev.name = id; odev.ifd = ConnectionNumber(ourdisplay); - /* set GLX context and clear buffers */ - glXMakeCurrent(ourdisplay, gwind, gctx); - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LEQUAL); - glShadeModel(GL_FLAT); - glDisable(GL_DITHER); - glDrawBuffer(GL_FRONT_AND_BACK); - glReadBuffer(GL_BACK); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - setGLview(); /* initialize view */ + /* initialize cone array */ + initcones(); } @@ -206,8 +182,9 @@ dev_close() /* close our display and free resources gwind = 0; XCloseDisplay(ourdisplay); ourdisplay = NULL; + qtFreeLeaves(); tmDone(NULL); - FreeValues(); + freecones(); odev.v.type = 0; odev.hres = odev.vres = 0; odev.ifd = -1; @@ -218,14 +195,19 @@ int dev_view(nv) /* assign new driver view */ register VIEW *nv; { - if (nv->type != VT_PER || /* check view legality */ - nv->horiz > 120. || nv->vert > 120.) { + if (nv->type == VT_PAR || /* check view legality */ + nv->horiz > 160. || nv->vert > 160.) { error(COMMAND, "illegal view type/angle"); - nv->type = VT_PER; + nv->type = odev.v.type; nv->horiz = odev.v.horiz; nv->vert = odev.v.vert; return(0); } + if (nv->vfore > FTINY) { + error(COMMAND, "cannot handle fore clipping"); + nv->vfore = 0.; + return(0); + } if (nv != &odev.v) { if (!FEQ(nv->horiz,odev.v.horiz) || /* resize window? */ !FEQ(nv->vert,odev.v.vert)) { @@ -247,12 +229,16 @@ register VIEW *nv; odev.vres = dh; } XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres); + dev_input(); /* get resize event */ } copystruct(&odev.v, nv); - setGLview(); } - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - redraw(); + if (nxtzmax > FTINY) { + curzmax = nxtzmax; + nxtzmax = 0.; + } + glClear(GL_DEPTH_BUFFER_BIT); + qtReplant(); return(1); } @@ -271,32 +257,48 @@ dev_input() /* get X11 input */ } -dev_value(c, p, v) /* add a pixel value to our list */ -COLR c; -FVECT p, v; +int +dev_flush() /* flush output */ { - register int li; - - li = newvalue(); - VCOPY(rV.wp[li], p); - rV.wd[li] = encodedir(v); - tmCvColrs(&rV.brt[li], rV.chr[li], c, 1); + qtUpdate(); + glFlush(); + return(XPending(ourdisplay)); } -int -dev_flush() /* flush output */ +dev_cone(rgb, ip, rad) /* render a cone in view coordinates */ +BYTE rgb[3]; +FVECT ip; +double rad; { - if (mapped) { - TMapValues(0); - while (rV.drl != rV.tl) { - drawvalue(rV.drl); - if (++rV.drl >= rV.nl) - rV.drl = 0; - } - glFlush(); + register int ci, j; + double apexh, basez; + /* compute apex height (0. to 1.) */ + if (ip[2] > 1e6) + apexh = 1. - 1./DEPTHFACT; + else { + if (ip[2] > nxtzmax) + nxtzmax = ip[2]; + if (ip[2] >= curzmax) + apexh = 1. - 1./DEPTHFACT; + else + apexh = 1. - ip[2]/(curzmax*DEPTHFACT); } - return(XPending(ourdisplay)); + rad *= 1.25; /* find conservative cone match */ + for (ci = 0; ci < MAXCONE-1; ci++) + if (cone[ci].rad >= rad) + break; + /* draw it */ + glColor3ub(rgb[0], rgb[1], rgb[2]); + glBegin(GL_TRIANGLE_FAN); + glVertex3d(ip[0], ip[1], apexh); /* start with apex */ + basez = apexh*cone[ci].va[0][2]; /* base z's all the same */ + for (j = 0; j < cone[ci].nverts; j++) /* draw each face */ + glVertex3d(ip[0]+cone[ci].va[j][0], ip[1]+cone[ci].va[j][1], + basez); + /* connect last to first */ + glVertex3d(ip[0]+cone[ci].va[0][0], ip[1]+cone[ci].va[0][1], basez); + glEnd(); /* all done */ } @@ -320,251 +322,47 @@ mytmflags() /* figure out tone mapping flags */ static -setGLview() /* set our GL view */ +initcones() /* initialize cone vertices */ { - double xmin, xmax, ymin, ymax, zmin, zmax; - double d, cx, sx, crad; - FVECT vx, vy; register int i, j; - /* compute view frustum */ - if (normalize(odev.v.vdir) == 0.0) - return; - if (mindepth < maxdepth) { - zmin = 0.25*mindepth; - zmax = 8.0*maxdepth; - } else { - zmin = 0.01; - zmax = 1000.; + double minrad, d; + + if (cone[0].nverts) + freecones(); + minrad = 2.*qtMinNodesiz/(double)(DisplayWidth(ourdisplay,ourscreen) + + DisplayHeight(ourdisplay,ourscreen)); + for (i = 0; i < MAXCONE; i++) { + d = (double)i/(MAXCONE-1); d *= d; /* x^2 distribution */ + cone[i].rad = minrad + (1.-minrad)*d; + cone[i].nverts = MINVERT + (MAXVERT-MINVERT)*d; + cone[i].va = (FVECT *)malloc(cone[i].nverts*sizeof(FVECT)); + if (cone[i].va == NULL) + error(SYSTEM, "out of memory in initcones"); + for (j = cone[i].nverts; j--; ) { + d = 2.*PI * (j+.5) / (cone[i].nverts); + cone[i].va[j][0] = cos(d) * cone[i].rad; + cone[i].va[j][1] = sin(d) * cone[i].rad; + cone[i].va[j][2] = 1. - cone[i].rad; + } } - if (odev.v.vfore > FTINY) - zmin = odev.v.vfore; - if (odev.v.vaft > FTINY) - zmax = odev.v.vaft; - xmax = zmin * tan(PI/180./2. * odev.v.horiz); - xmin = -xmax; - d = odev.v.hoff * (xmax - xmin); - xmin += d; xmax += d; - ymax = zmin * tan(PI/180./2. * odev.v.vert); - ymin = -ymax; - d = odev.v.voff * (ymax - ymin); - ymin += d; ymax += d; - /* set view matrix */ - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustum(xmin, xmax, ymin, ymax, zmin, zmax); - gluLookAt(odev.v.vp[0], odev.v.vp[1], odev.v.vp[2], - odev.v.vp[0] + odev.v.vdir[0], - odev.v.vp[1] + odev.v.vdir[1], - odev.v.vp[2] + odev.v.vdir[2], - odev.v.vup[0], odev.v.vup[1], odev.v.vup[2]); - /* set viewport */ - glViewport(0, 0, odev.hres, odev.vres); - /* initialize cone for Vornoi polys */ - coneh = CONEH*(zmax - zmin); - crad = 0.5 * CONEW * 0.5*(xmax-xmin + ymax-ymin) * (zmin+coneh)/zmin; - vy[0] = vy[1] = vy[2] = 0.; - for (i = 0; i < 3; i++) - if (odev.v.vdir[i] < 0.6 && odev.v.vdir[i] > -0.6) - break; - vy[i] = 1.; - fcross(vx, vy, odev.v.vdir); - normalize(vx); - fcross(vy, odev.v.vdir, vx); - for (j = 0, d = 0.; j < NCONEV; j++, d += 2.*PI/NCONEV) { - cx = crad*cos(d); sx = crad*sin(d); - for (i = 0; i < 3; i++) - conev[j][i] = coneh*odev.v.vdir[i] + - cx*vx[i] + sx*vy[i]; - } } -static int -newvalue() /* allocate a leaf from our pile */ -{ - int li; - - li = rV.tl++; - if (rV.tl >= rV.nl) /* get next leaf in ring */ - rV.tl = 0; - if (rV.tl == rV.bl) /* need to shake some free */ - Compost(FREEPCT); - return(li); -} - - static -drawvalue(li) /* draw a pixel value as a cone */ -register int li; +freecones() /* free cone vertices */ { - static FVECT apex, disp; - double d, h, v; register int i; - /* compute cone's base displacement */ - VCOPY(apex, rV.wp[li]); - disp[0] = apex[0] - odev.v.vp[0]; - disp[1] = apex[1] - odev.v.vp[1]; - disp[2] = apex[2] - odev.v.vp[2]; - if ((d = DOT(disp,odev.v.vdir)) <= odev.v.vfore || d <= FTINY) - return; - if (d > 1e5) { /* background region */ - if (odev.v.vaft > FTINY) - return; - h = maxdepth/d; - disp[0] *= h; disp[1] *= h; disp[2] *= h; - apex[0] = odev.v.vp[0] + disp[0]; - apex[1] = odev.v.vp[1] + disp[1]; - apex[2] = odev.v.vp[2] + disp[2]; - d = maxdepth; - } else if (d > maxdepth) - maxdepth = d; - h = DOT(disp,odev.v.hvec)/(d*odev.v.hn2); - v = DOT(disp,odev.v.vvec)/(d*odev.v.vn2); - if (fabs(h - odev.v.hoff) < 0.5 && fabs(v - odev.v.voff) < 0.5 && - d < mindepth) -{ -fprintf(stderr, "min depth now %lf (%lf,%lf,%lf)\n", d, apex[0], apex[1], apex[2]); - mindepth = d; -} - for (i = 0; i < 3; i++) - disp[i] = apex[i] + coneh*(h*odev.v.hvec[i] + v*odev.v.vvec[i]); - /* draw pyramid (cone approx.) */ - glColor4ub(rV.rgb[li][0], rV.rgb[li][1], rV.rgb[li][2], rV.alpha[li]); - glBegin(GL_TRIANGLE_FAN); - glVertex3f(apex[0], apex[1], apex[2]); - for (i = 0; i < NCONEV; i++) - glVertex3d(conev[i][0] + disp[0], conev[i][1] + disp[1], - conev[i][2] + disp[2]); - /* connect last side to first */ - glVertex3d(conev[0][0] + disp[0], conev[0][1] + disp[1], - conev[0][2] + disp[2]); - glEnd(); /* done */ -} - -#define LEAFSIZ (3*sizeof(float)+sizeof(int4)+\ - sizeof(TMbright)+7*sizeof(BYTE)) - -static -AllocValues(n) /* allocate space for n values */ -register int n; -{ - unsigned nbytes; - register unsigned i; - - if (n <= 0) - return(0); - if (rV.nl >= n) - return(rV.nl); - else if (rV.nl > 0) - free(rV.base); - /* round space up to nearest power of 2 */ - nbytes = n*LEAFSIZ + 8; - for (i = 1024; nbytes > i; i <<= 1) - ; - n = (i - 8) / LEAFSIZ; /* should we make sure n is even? */ - rV.base = (char *)malloc(n*LEAFSIZ); - if (rV.base == NULL) - return(0); - /* assign larger alignment types earlier */ - rV.wp = (float (*)[3])rV.base; - rV.wd = (int4 *)(rV.wp + n); - rV.brt = (TMbright *)(rV.wd + n); - rV.chr = (BYTE (*)[3])(rV.brt + n); - rV.rgb = (BYTE (*)[3])(rV.chr + n); - rV.alpha = (BYTE *)(rV.rgb + n); - rV.nl = n; - rV.drl = rV.tml = rV.bl = rV.tl = 0; - return(n); + for (i = MAXCONE; i--; ) + if (cone[i].nverts) { + free((char *)cone[i].va); + cone[i].va = NULL; + cone[i].nverts = 0; + } } -#undef LEAFSIZ - static -FreeValues() /* free our allocated values */ -{ - if (rV.nl <= 0) - return; - free(rV.base); - rV.base = NULL; - rV.nl = 0; -} - - -static -TMapValues(redo) /* map our values to RGB */ -int redo; -{ - int aorg, alen, borg, blen; - /* recompute mapping? */ - if (redo) - rV.tml = rV.bl; - /* already done? */ - if (rV.tml == rV.tl) - return(1); - /* compute segments */ - aorg = rV.tml; - if (rV.tl >= aorg) { - alen = rV.tl - aorg; - blen = 0; - } else { - alen = rV.nl - aorg; - borg = 0; - blen = rV.tl; - } - /* (re)compute tone mapping? */ - if (rV.tml == rV.bl) { - tmClearHisto(); - tmAddHisto(rV.brt+aorg, alen, 1); - if (blen > 0) - tmAddHisto(rV.brt+borg, blen, 1); - if (tmComputeMapping(0., 0., 0.) != TM_E_OK) - return(0); - rV.drl = rV.bl; - } - if (tmMapPixels(rV.rgb+aorg, rV.brt+aorg, - rV.chr+aorg, alen) != TM_E_OK) - return(0); - if (blen > 0) - tmMapPixels(rV.rgb+borg, rV.brt+borg, - rV.chr+borg, blen); - /* compute unique alpha values */ - rV.tml = rV.tl; - return(1); -} - - -static int -Compost(pct) /* free up some values */ -int pct; -{ - int nused, nclear, nmapped, ndrawn; - /* figure out how many values to clear */ - nclear = rV.nl * pct / 100; - nused = rV.tl - rV.bl; - if (nused <= 0) nused += rV.nl; - nclear -= rV.nl - nused; - if (nclear <= 0) - return(0); - if (nclear >= nused) { /* clear them all */ - rV.drl = rV.tml = rV.bl = rV.tl = 0; - return(nused); - } - /* else clear values from bottom */ - ndrawn = rV.drl - rV.bl; - if (ndrawn < 0) ndrawn += rV.nl; - nmapped = rV.tml - rV.bl; - if (nmapped < 0) nmapped += rV.nl; - rV.bl += nclear; - if (rV.bl >= rV.nl) rV.bl -= rV.nl; - if (ndrawn < nclear) rV.drl = rV.bl; - if (nmapped < nclear) rV.tml = rV.bl; - return(nclear); -} - - -static getevent() /* get next event */ { XNextEvent(ourdisplay, levptr(XEvent)); @@ -603,26 +401,51 @@ register FVECT wp[2]; static draw_grids() /* draw holodeck section grids */ { - static GLubyte gridrgba[4] = {0x0, 0xff, 0xff, 0x00}; - - if (!mapped) + static BYTE gridrgba[4] = {0x0, 0xff, 0xff, 0x00}; + double xmin, xmax, ymin, ymax, zmin, zmax; + double d, cx, sx, crad; + FVECT vx, vy; + register int i, j; + /* can we even do it? */ + if (!mapped || odev.v.type != VT_PER) return; + /* compute view frustum */ + if (normalize(odev.v.vdir) == 0.0) + return; + zmin = 0.01; + zmax = 10000.; + if (odev.v.vfore > FTINY) + zmin = odev.v.vfore; + if (odev.v.vaft > FTINY) + zmax = odev.v.vaft; + xmax = zmin * tan(PI/180./2. * odev.v.horiz); + xmin = -xmax; + d = odev.v.hoff * (xmax - xmin); + xmin += d; xmax += d; + ymax = zmin * tan(PI/180./2. * odev.v.vert); + ymin = -ymax; + d = odev.v.voff * (ymax - ymin); + ymin += d; ymax += d; + /* set view matrix */ + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glFrustum(xmin, xmax, ymin, ymax, zmin, zmax); + gluLookAt(odev.v.vp[0], odev.v.vp[1], odev.v.vp[2], + odev.v.vp[0] + odev.v.vdir[0], + odev.v.vp[1] + odev.v.vdir[1], + odev.v.vp[2] + odev.v.vdir[2], + odev.v.vup[0], odev.v.vup[1], odev.v.vup[2]); + glDisable(GL_DEPTH_TEST); /* write no depth values */ glColor4ub(gridrgba[0], gridrgba[1], gridrgba[2], gridrgba[3]); - /* draw each grid line */ - glBegin(GL_LINES); + glBegin(GL_LINES); /* draw each grid line */ gridlines(draw3dline); glEnd(); + glEnable(GL_DEPTH_TEST); /* restore rendering params */ + glPopMatrix(); } -static int -FindValue(dx, dy) /* find a value on the display */ -int dx, dy; -{ - return(-1); /* not found */ -} - - static moveview(dx, dy, mov, orb) /* move our view */ int dx, dy, mov, orb; @@ -635,9 +458,9 @@ int dx, dy, mov, orb; copystruct(&nv, &odev.v); /* change view direction */ if (mov | orb) { - if ((li = FindValue(dx, dy)) < 0) + if ((li = qtFindLeaf(dx, dy)) < 0) return(0); /* not on window */ - VSUM(odir, rV.wp[li], nv.vp, -1.); + VSUM(odir, qtL.wp[li], nv.vp, -1.); } else { if (viewray(nv.vp, nv.vdir, &odev.v, (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY) @@ -645,14 +468,14 @@ int dx, dy, mov, orb; } if (orb && mov) { /* orbit left/right */ spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov); - VSUM(nv.vp, rV.wp[li], odir, -1.); + VSUM(nv.vp, qtL.wp[li], odir, -1.); spinvector(nv.vdir, nv.vdir, nv.vup, d); } else if (orb) { /* orbit up/down */ fcross(v1, odir, nv.vup); if (normalize(v1) == 0.) return(0); spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb); - VSUM(nv.vp, rV.wp[li], odir, -1.); + VSUM(nv.vp, qtL.wp[li], odir, -1.); spinvector(nv.vdir, nv.vdir, v1, d); } else if (mov) { /* move forward/backward */ d = MOVPCT/100. * mov; @@ -677,10 +500,12 @@ XButtonPressedEvent *ebut; { int movdir = MOVDIR(ebut->button); int movorb = MOVORB(ebut->state); + int oldnodesiz = qtMinNodesiz; Window rootw, childw; int rootx, rooty, wx, wy; unsigned int statemask; + qtMinNodesiz = 24; /* accelerate update rate */ XNoOp(ourdisplay); while (!XCheckMaskEvent(ourdisplay, @@ -694,8 +519,10 @@ XButtonPressedEvent *ebut; sleep(1); continue; } + glClear(GL_COLOR_BUFFER_BIT); + qtUpdate(); draw_grids(); - dev_flush(); + glFlush(); } if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */ movdir = MOVDIR(levptr(XButtonReleasedEvent)->button); @@ -704,6 +531,8 @@ XButtonPressedEvent *ebut; moveview(wx, odev.vres-1-wy, movdir, movorb); } dev_flush(); + + qtMinNodesiz = oldnodesiz; /* restore quadtree resolution */ } @@ -738,20 +567,24 @@ register XKeyPressedEvent *ekey; inpresflags |= DFL(DC_RESUME); return; case CTRL('R'): /* redraw screen */ - TMapValues(1); - redraw(); + if (nxtzmax > FTINY) { + curzmax = nxtzmax; + nxtzmax = 0.; + } + glClear(GL_DEPTH_BUFFER_BIT); + qtRedraw(0, 0, odev.hres, odev.vres); return; case CTRL('L'): /* refresh from server */ if (inpresflags & DFL(DC_REDRAW)) return; + if (nxtzmax > FTINY) { + curzmax = nxtzmax; + nxtzmax = 0.; + } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glDrawBuffer(GL_FRONT); - glDisable(GL_DEPTH_TEST); draw_grids(); - glEnable(GL_DEPTH_TEST); - glDrawBuffer(GL_FRONT_AND_BACK); glFlush(); - Compost(100); /* get rid of old values */ + qtCompost(100); /* get rid of old values */ inpresflags |= DFL(DC_REDRAW); /* resend values from server */ return; case 'K': /* kill rtrace process(es) */ @@ -777,14 +610,24 @@ static fixwindow(eexp) /* repair damage to window */ register XExposeEvent *eexp; { - if (odev.hres == 0 || odev.vres == 0) { /* first exposure */ - odev.hres = eexp->width; - odev.vres = eexp->height; - } - if (eexp->width == odev.hres && eexp->height == odev.vres) - TMapValues(1); - if (!eexp->count) - redraw(); + int xmin, xmax, ymin, ymax; + + if (odev.hres == 0 || odev.vres == 0) /* first exposure */ + resizewindow((XConfigureEvent *)eexp); + xmin = eexp->x; xmax = eexp->x + eexp->width; + ymin = odev.vres - eexp->y - eexp->height; ymax = odev.vres - eexp->y; + /* clear portion of depth */ + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + glDepthFunc(GL_ALWAYS); + glBegin(GL_POLYGON); + glVertex3d((double)xmin/odev.hres, (double)ymin/odev.vres, 0.); + glVertex3d((double)xmax/odev.hres, (double)ymin/odev.vres, 0.); + glVertex3d((double)xmax/odev.hres, (double)ymax/odev.vres, 0.); + glVertex3d((double)xmin/odev.hres, (double)ymax/odev.vres, 0.); + glEnd(); + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glDepthFunc(GL_LEQUAL); + qtRedraw(xmin, ymin, xmax, ymax); } @@ -792,6 +635,8 @@ static resizewindow(ersz) /* resize window */ register XConfigureEvent *ersz; { + glViewport(0, 0, ersz->width, ersz->height); + if (ersz->width == odev.hres && ersz->height == odev.vres) return; @@ -800,8 +645,6 @@ register XConfigureEvent *ersz; odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres); odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres); - - setGLview(); inpresflags |= DFL(DC_SETVIEW); }