--- ray/src/hd/rhd_ogl.c 1998/12/22 10:18:44 3.8 +++ ray/src/hd/rhd_ogl.c 1999/01/01 10:41:28 3.13 @@ -1,4 +1,4 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ +/* Copyright (c) 1999 Silicon Graphics, Inc. */ #ifndef lint static char SCCSid[] = "$SunId$ SGI"; @@ -37,23 +37,9 @@ 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 - /* values other than 0 or 255 do not map reliably */ -#ifndef PORTALP -#define PORTRED 0 /* -1, 0 or 255 */ -#define PORTGRN -1 /* -1, 0 or 255 */ -#define PORTBLU 255 /* -1, 0 or 255 */ -#define PORTALP -1 /* -1 or 255 */ -#endif -#define isportal(c) ((PORTRED<0 || (c)[0]==PORTRED) && \ - (PORTGRN<0 || (c)[1]==PORTGRN) && \ - (PORTBLU<0 || (c)[2]==PORTBLU) && \ - (PORTALP<0 || (c)[3]==PORTALP)) -#define doportals() if (gmPortals) \ - gmDrawPortals(PORTRED,PORTGRN,PORTBLU,PORTALP); else - #ifndef FEQ #define FEQ(a,b) ((a)-(b) <= FTINY && (a)-(b) >= -FTINY) #endif @@ -146,23 +132,12 @@ char *id; { extern char *getenv(); static RGBPRIMS myprims = STDPRIMS; -#if (PORTALP<0) static int atlBest[] = {GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE,8, GLX_GREEN_SIZE,8, GLX_BLUE_SIZE,8, GLX_DEPTH_SIZE,15, None}; static int atlOK[] = {GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE,4, GLX_GREEN_SIZE,4, GLX_BLUE_SIZE,4, GLX_DEPTH_SIZE,15, None}; -#else - static int atlBest[] = {GLX_RGBA, GLX_DOUBLEBUFFER, - GLX_RED_SIZE,8, GLX_GREEN_SIZE,8, - GLX_BLUE_SIZE,8, GLX_ALPHA_SIZE,1, - GLX_DEPTH_SIZE,15, None}; - static int atlOK[] = {GLX_RGBA, GLX_DOUBLEBUFFER, - GLX_RED_SIZE,5, GLX_GREEN_SIZE,5, - GLX_BLUE_SIZE,5, GLX_ALPHA_SIZE,1, - GLX_DEPTH_SIZE,15, None}; -#endif char *ev; double gamval = GAMMA; RGBPRIMP dpri = stdprims; @@ -251,11 +226,13 @@ char *id; glXMakeCurrent(ourdisplay, gwind, gctx); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); - glEnable(GL_DITHER); + glClearColor(0, 0, 0, 0); glFrontFace(GL_CCW); 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); @@ -273,7 +250,7 @@ char *id; 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 */ @@ -305,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 */ } @@ -394,8 +373,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); @@ -462,8 +448,6 @@ dev_flush() /* flush output as appropriate */ #ifdef DOBJ ndrawn += dobj_render(); #endif - if (ndrawn) - doportals(); checkglerr("rendering right eye"); popright(); /* draw left eye */ #endif @@ -471,8 +455,6 @@ dev_flush() /* flush output as appropriate */ #ifdef DOBJ ndrawn += dobj_render(); #endif - if (ndrawn) - doportals(); glXSwapBuffers(ourdisplay, gwind); checkglerr("rendering base view"); } @@ -518,7 +500,7 @@ static xferdepth() /* load and clear depth buffer */ { register GLfloat *dbp; - register GLubyte *cbuf; + register GLubyte *pbuf; if (depthbuffer == NULL) { /* allocate private depth buffer */ #ifdef STEREO @@ -531,41 +513,49 @@ xferdepth() /* load and clear depth buffer */ } /* allocate alpha buffer for portals */ if (gmPortals) - cbuf = (GLubyte *)malloc(odev.hres*odev.vres * - (4*sizeof(GLubyte))); + pbuf = (GLubyte *)malloc(odev.hres*odev.vres*sizeof(GLubyte)); else - cbuf = NULL; + pbuf = NULL; #ifdef STEREO - setstereobuf(STEREO_BUFFER_RIGHT); + pushright(); glReadPixels(0, 0, odev.hres, odev.vres, GL_DEPTH_COMPONENT, GL_FLOAT, depthright); - if (cbuf != NULL) + 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, cbuf); + GL_RED, GL_UNSIGNED_BYTE, pbuf); + } for (dbp = depthright + odev.hres*odev.vres; dbp-- > depthright; ) - if (cbuf != NULL && isportal(cbuf+4*(dbp-depthright))) + 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, GL_DEPTH_COMPONENT, GL_FLOAT, depthbuffer); - if (cbuf != NULL) + if (pbuf != NULL) { + glClear(GL_COLOR_BUFFER_BIT); /* find portals */ + gmDrawPortals(0xff, -1, -1, -1); glReadPixels(0, 0, odev.hres, odev.vres, - GL_RGBA, GL_UNSIGNED_BYTE, cbuf); + GL_RED, GL_UNSIGNED_BYTE, pbuf); +#ifdef DEBUG + glXSwapBuffers(ourdisplay, gwind); +#endif + } for (dbp = depthbuffer + odev.hres*odev.vres; dbp-- > depthbuffer; ) - if (cbuf != NULL && isportal(cbuf+4*(dbp-depthbuffer))) + if (pbuf != NULL && pbuf[dbp-depthbuffer]&0x40) *dbp = FHUGE; else *dbp = mapdepth(*dbp); glClear(GL_DEPTH_BUFFER_BIT); /* clear system depth buffer */ - if (cbuf != NULL) - free((char *)cbuf); /* free our color buffer */ odDepthMap(0, depthbuffer); /* transfer depth data */ + if (pbuf != NULL) + free((char *)pbuf); /* free our portal buffer */ } @@ -591,7 +581,6 @@ int dx, dy; FVECT direc; { GLfloat gldepth; - GLubyte glcolor[4]; double dist; if (dx<0 | dx>=odev.hres | dy<0 | dy>=odev.vres) @@ -601,12 +590,6 @@ FVECT direc; else { glReadPixels(dx,dy, 1,1, GL_DEPTH_COMPONENT, GL_FLOAT, &gldepth); - if (gmPortals) { - glReadPixels(dx,dy, 1,1, GL_RGBA, - GL_UNSIGNED_BYTE, glcolor); - if (isportal(glcolor)) - return(FHUGE); - } dist = mapdepth(gldepth); } if (dist >= .99*FHUGE) @@ -820,7 +803,7 @@ 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))) { /* get cursor position */ @@ -840,8 +823,6 @@ XButtonPressedEvent *ebut; #ifdef DOBJ ndrawn += dobj_render(); #endif - if (ndrawn) - doportals(); popright(); #endif /* redraw octrees */ @@ -849,8 +830,6 @@ XButtonPressedEvent *ebut; #ifdef DOBJ ndrawn += dobj_render(); /* redraw objects */ #endif - if (ndrawn) - doportals(); glXSwapBuffers(ourdisplay, gwind); if (!ndrawn) sleep(1); /* for reasonable interaction */ @@ -866,8 +845,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]; @@ -879,7 +857,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.; } @@ -949,8 +927,7 @@ static wipeclean() /* prepare for redraw */ { glDrawBuffer(GL_BACK); /* use double-buffer mode */ - glReadBuffer(GL_FRONT); /* read back visible contents */ - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glReadBuffer(GL_BACK); /* clear buffers */ #ifdef STEREO setstereobuf(STEREO_BUFFER_RIGHT); @@ -958,13 +935,13 @@ wipeclean() /* prepare for redraw */ setstereobuf(STEREO_BUFFER_LEFT); #endif glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE); freedepth(); if ((viewflags&(VWCHANGE|VWSTEADY)) == (VWCHANGE|VWSTEADY)) { /* clear samples if new */ odClean(); viewflags &= ~VWCHANGE; /* change noted */ - } + } else if (viewflags & VWSTEADY) + odRedrawAll(); setglpersp(&odev.v); /* reset view & clipping planes */ } @@ -1015,7 +992,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); @@ -1025,15 +1002,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); @@ -1066,6 +1041,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);