--- ray/src/hd/rhd_ogl.c 1998/12/22 12:59:17 3.9 +++ ray/src/hd/rhd_ogl.c 2003/07/21 22:30:18 3.22 @@ -1,9 +1,6 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rhd_ogl.c,v 3.22 2003/07/21 22:30:18 schorsch Exp $"; #endif - /* * OpenGL driver for holodeck display. * Based on GLX driver using T-mesh. @@ -22,12 +19,12 @@ static char SCCSid[] = "$SunId$ SGI"; #include "standard.h" -#include #include #include #ifdef STEREO #include #endif +#include #include "rhd_odraw.h" #ifdef DOBJ @@ -37,8 +34,18 @@ static char SCCSid[] = "$SunId$ SGI"; #include "x11icon.h" #ifndef RAYQLEN -#define RAYQLEN 50000 /* max. rays to queue before flush */ +#define RAYQLEN 0 /* max. rays to queue before flush */ #endif +#ifndef MINWIDTH +#define MINWIDTH 480 /* minimum graphics window width */ +#define MINHEIGHT 400 /* minimum graphics window height */ +#endif +#ifndef VIEWDIST +#define VIEWDIST 356 /* assumed viewing distance (mm) */ +#endif +#ifndef BORWIDTH +#define BORWIDTH 5 /* border width */ +#endif #ifndef FEQ #define FEQ(a,b) ((a)-(b) <= FTINY && (a)-(b) >= -FTINY) @@ -60,13 +67,6 @@ static char SCCSid[] = "$SunId$ SGI"; #define MOVDEG (-5) /* degrees to orbit CW/down /frame */ #define MOVORB(s) ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0) -#define MINWIDTH 480 /* minimum graphics window width */ -#define MINHEIGHT 400 /* minimum graphics window height */ - -#define VIEWDIST 356 /* assumed viewing distance (mm) */ - -#define BORWIDTH 5 /* border width */ - #define setstereobuf(bid) (glXWaitGL(), \ XSGISetStereoBuffer(ourdisplay, gwind, bid), \ glXWaitX()) @@ -231,6 +231,8 @@ char *id; glDisable(GL_CULL_FACE); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); /* figure out sensible view */ pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) / DisplayWidth(ourdisplay, ourscreen); @@ -241,14 +243,14 @@ char *id; setstereobuf(STEREO_BUFFER_LEFT); #endif checkglerr("setting rendering parameters"); - copystruct(&odev.v, &stdview); + odev.v = stdview; odev.v.type = VT_PER; viewflags = VWSTEADY; /* view starts static */ /* map the window */ XMapWindow(ourdisplay, gwind); dev_input(); /* sets size and view angles */ if (!odInit(DisplayWidth(ourdisplay,ourscreen) * - DisplayHeight(ourdisplay,ourscreen) / 4)) + DisplayHeight(ourdisplay,ourscreen) / 3)) error(SYSTEM, "insufficient memory for value storage"); odev.name = id; odev.firstuse = 1; /* can't recycle samples */ @@ -280,7 +282,9 @@ dev_close() /* close our display and free resources dev_clear() /* clear our representation */ { - wipeclean(); + viewflags |= VWCHANGE; /* pretend our view has changed */ + wipeclean(); /* clean off display and samples */ + dev_flush(); /* redraw geometry & get depth */ rayqleft = 0; /* hold off update */ } @@ -326,15 +330,15 @@ register VIEW *nv; XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres); dev_input(); /* get resize event */ } - copystruct(&odev.v, nv); /* setview() already called */ -#ifdef STEREO - copystruct(&vwright, nv); - d = eyesepdist / sqrt(nv->hn2); - VSUM(vwright.vp, nv->vp, nv->hvec, d); - /* setview(&vwright); -- Unnecessary */ -#endif + odev.v = *nv; /* setview() already called */ viewflags |= VWCHANGE; } +#ifdef STEREO + vwright = *nv; + d = eyesepdist / sqrt(nv->hn2); + VSUM(vwright.vp, nv->vp, nv->hvec, d); + /* setview(&vwright); -- Unnecessary */ +#endif wipeclean(); return(1); } @@ -343,7 +347,6 @@ register VIEW *nv; dev_section(gfn, pfn) /* add octree for geometry rendering */ char *gfn, *pfn; { - extern char *index(); char *cp; if (gfn == NULL) { @@ -369,8 +372,15 @@ dev_auxcom(cmd, args) /* process an auxiliary command char *cmd, *args; { #ifdef DOBJ - if (dobj_command(cmd, args) >= 0) + int vischange; + + if ((vischange = dobj_command(cmd, args)) >= 0) { + if (vischange) { + imm_mode = beam_sync(1) > 0; + dev_clear(); + } return; + } #endif sprintf(errmsg, "%s: unknown command", cmd); error(COMMAND, errmsg); @@ -502,28 +512,27 @@ xferdepth() /* load and clear depth buffer */ } /* allocate alpha buffer for portals */ if (gmPortals) - pbuf = (GLubyte *)malloc(odev.hres*odev.vres * - (4*sizeof(GLubyte))); + pbuf = (GLubyte *)malloc(odev.hres*odev.vres*sizeof(GLubyte)); else pbuf = NULL; #ifdef STEREO - setstereobuf(STEREO_BUFFER_RIGHT); + pushright(); glReadPixels(0, 0, odev.hres, odev.vres, GL_DEPTH_COMPONENT, GL_FLOAT, depthright); if (pbuf != NULL) { glClear(GL_COLOR_BUFFER_BIT); gmDrawPortals(0xff, -1, -1, -1); glReadPixels(0, 0, odev.hres, odev.vres, - GL_RGBA, GL_UNSIGNED_BYTE, pbuf); + GL_RED, GL_UNSIGNED_BYTE, pbuf); } for (dbp = depthright + odev.hres*odev.vres; dbp-- > depthright; ) - if (pbuf != NULL && pbuf[4*(dbp-depthright)]&0x40) + if (pbuf != NULL && pbuf[dbp-depthright]&0x40) *dbp = FHUGE; else *dbp = mapdepth(*dbp); glClear(GL_DEPTH_BUFFER_BIT); - setstereobuf(STEREO_BUFFER_LEFT); odDepthMap(1, depthright); + popright(); #endif /* read back depth buffer */ glReadPixels(0, 0, odev.hres, odev.vres, @@ -532,17 +541,20 @@ xferdepth() /* load and clear depth buffer */ glClear(GL_COLOR_BUFFER_BIT); /* find portals */ gmDrawPortals(0xff, -1, -1, -1); glReadPixels(0, 0, odev.hres, odev.vres, - GL_RGBA, GL_UNSIGNED_BYTE, pbuf); + GL_RED, GL_UNSIGNED_BYTE, pbuf); +#ifdef DEBUG + glXSwapBuffers(ourdisplay, gwind); +#endif } for (dbp = depthbuffer + odev.hres*odev.vres; dbp-- > depthbuffer; ) - if (pbuf != NULL && pbuf[4*(dbp-depthbuffer)]&0x40) + if (pbuf != NULL && pbuf[dbp-depthbuffer]&0x40) *dbp = FHUGE; else *dbp = mapdepth(*dbp); glClear(GL_DEPTH_BUFFER_BIT); /* clear system depth buffer */ odDepthMap(0, depthbuffer); /* transfer depth data */ if (pbuf != NULL) - free((char *)pbuf); /* free our portal buffer */ + free((void *)pbuf); /* free our portal buffer */ } @@ -553,11 +565,11 @@ freedepth() /* free recorded depth buffer */ return; #ifdef STEREO odDepthMap(1, NULL); - free((char *)depthright); + free((void *)depthright); depthright = NULL; #endif odDepthMap(0, NULL); - free((char *)depthbuffer); + free((void *)depthbuffer); depthbuffer = NULL; } @@ -707,7 +719,7 @@ int dx, dy, mov, orb; double d, d1; register int li; /* start with old view */ - copystruct(&nv, &odev.v); + nv = odev.v; /* orient our motion */ if (viewray(v1, odir, &odev.v, (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY) @@ -777,6 +789,16 @@ XButtonPressedEvent *ebut; static +waitabit() /* pause a moment */ +{ + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 50000000; + nanosleep(&ts, NULL); +} + + +static getmove(ebut) /* get view change */ XButtonPressedEvent *ebut; { @@ -790,9 +812,11 @@ XButtonPressedEvent *ebut; XNoOp(ourdisplay); /* makes sure we're not idle */ viewflags &= ~VWSTEADY; /* flag moving view */ - setglpersp(&odev.v); /* start us off in perspective */ + setglpersp(); /* start us off in perspective */ while (!XCheckMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent))) { + /* pause so as not to move too fast */ + waitabit(); /* get cursor position */ if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, &rootx, &rooty, &wx, &wy, &statemask)) @@ -832,8 +856,7 @@ XButtonPressedEvent *ebut; static -setglpersp(vp) /* set perspective view in GL */ -register VIEW *vp; +setglpersp() /* set perspective view in GL */ { double d, xmin, xmax, ymin, ymax; GLfloat vec[4]; @@ -845,7 +868,7 @@ register VIEW *vp; dev_zmax = 100.; } else { dev_zmin = 0.5*depthlim[0]; - dev_zmax = 1.75*depthlim[1]; + dev_zmax = 1.25*depthlim[1]; if (dev_zmin > dev_zmax/5.) dev_zmin = dev_zmax/5.; } @@ -853,8 +876,8 @@ register VIEW *vp; dev_zmin = odev.v.vfore; if (odev.v.vaft > FTINY) dev_zmax = odev.v.vaft; - if (dev_zmin < dev_zmax/100.) - dev_zmin = dev_zmax/100.; + if (dev_zmin*500. < dev_zmax) + dev_zmin = dev_zmax/500.; setzrat(); xmax = dev_zmin * tan(PI/180./2. * odev.v.horiz); xmin = -xmax; @@ -928,8 +951,9 @@ wipeclean() /* prepare for redraw */ (VWCHANGE|VWSTEADY)) { /* clear samples if new */ odClean(); viewflags &= ~VWCHANGE; /* change noted */ - } - setglpersp(&odev.v); /* reset view & clipping planes */ + } else if (viewflags & VWSTEADY) + odRedrawAll(); + setglpersp(); /* reset view & clipping planes */ } @@ -979,7 +1003,7 @@ register XKeyPressedEvent *ekey; inpresflags |= DFL(DC_RESUME); return; case CTRL('R'): /* redraw screen */ - odRemap(0); + odRemap(0); /* new tone mapping */ glClear(GL_DEPTH_BUFFER_BIT); #ifdef STEREO setstereobuf(STEREO_BUFFER_RIGHT); @@ -989,15 +1013,13 @@ register XKeyPressedEvent *ekey; return; case CTRL('L'): /* refresh from server */ if (inpresflags & DFL(DC_REDRAW)) - return; + return; /* already called */ XRaiseWindow(ourdisplay, gwind); - XFlush(ourdisplay); - sleep(1); - wipeclean(); /* fresh display */ - odRemap(1); /* fresh tone mapping */ - dev_flush(); /* draw octrees */ + XFlush(ourdisplay); /* raise up window */ + sleep(1); /* wait for restacking */ + dev_clear(); /* clear buffer and samples */ + odRemap(1); /* start fresh histogram */ inpresflags |= DFL(DC_REDRAW); /* resend values from server */ - rayqleft = 0; /* hold off update */ return; case 'K': /* kill rtrace process(es) */ inpresflags |= DFL(DC_KILL); @@ -1030,6 +1052,13 @@ register XExposeEvent *eexp; } xmin = eexp->x; xmax = eexp->x + eexp->width; ymin = odev.vres - eexp->y - eexp->height; ymax = odev.vres - eexp->y; + + if (xmin <= 0 && xmax >= odev.hres-1 && + ymin <= 0 && ymax >= odev.vres) { + DCHECK(eexp->count, WARNING, "multiple clear in fixwindow"); + wipeclean(); /* make sure we're go */ + return; + } /* clear portion of depth */ glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);