ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_ogl.c
(Generate patch)

Comparing ray/src/hd/rhd_ogl.c (file contents):
Revision 3.9 by gwlarson, Tue Dec 22 12:59:17 1998 UTC vs.
Revision 3.19 by greg, Sat Feb 22 02:07:24 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * OpenGL driver for holodeck display.
6   * Based on GLX driver using T-mesh.
# Line 22 | Line 19 | static char SCCSid[] = "$SunId$ SGI";
19  
20   #include "standard.h"
21  
25 #include <sys/types.h>
22   #include <GL/glx.h>
23   #include <GL/glu.h>
24   #ifdef STEREO
25   #include <X11/extensions/SGIStereo.h>
26   #endif
27 + #include <time.h>
28  
29   #include "rhd_odraw.h"
30   #ifdef DOBJ
# Line 37 | Line 34 | static char SCCSid[] = "$SunId$ SGI";
34   #include "x11icon.h"
35  
36   #ifndef RAYQLEN
37 < #define RAYQLEN         50000           /* max. rays to queue before flush */
37 > #define RAYQLEN         0               /* max. rays to queue before flush */
38   #endif
39 + #ifndef MINWIDTH
40 + #define MINWIDTH        480             /* minimum graphics window width */
41 + #define MINHEIGHT       400             /* minimum graphics window height */
42 + #endif
43 + #ifndef VIEWDIST
44 + #define VIEWDIST        356             /* assumed viewing distance (mm) */
45 + #endif
46 + #ifndef BORWIDTH
47 + #define BORWIDTH        5               /* border width */
48 + #endif
49  
50   #ifndef FEQ
51   #define FEQ(a,b)        ((a)-(b) <= FTINY && (a)-(b) >= -FTINY)
# Line 60 | Line 67 | static char SCCSid[] = "$SunId$ SGI";
67   #define MOVDEG          (-5)            /* degrees to orbit CW/down /frame */
68   #define MOVORB(s)       ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
69  
63 #define MINWIDTH        480             /* minimum graphics window width */
64 #define MINHEIGHT       400             /* minimum graphics window height */
65
66 #define VIEWDIST        356             /* assumed viewing distance (mm) */
67
68 #define BORWIDTH        5               /* border width */
69
70   #define setstereobuf(bid)       (glXWaitGL(), \
71                                  XSGISetStereoBuffer(ourdisplay, gwind, bid), \
72                                  glXWaitX())
# Line 231 | Line 231 | char  *id;
231          glDisable(GL_CULL_FACE);
232          glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
233          glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
234 +        glPixelStorei(GL_PACK_ALIGNMENT, 1);
235 +        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
236                                          /* figure out sensible view */
237          pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
238                          DisplayWidth(ourdisplay, ourscreen);
# Line 248 | Line 250 | char  *id;
250          XMapWindow(ourdisplay, gwind);
251          dev_input();                    /* sets size and view angles */
252          if (!odInit(DisplayWidth(ourdisplay,ourscreen) *
253 <                        DisplayHeight(ourdisplay,ourscreen) / 4))
253 >                        DisplayHeight(ourdisplay,ourscreen) / 3))
254                  error(SYSTEM, "insufficient memory for value storage");
255          odev.name = id;
256          odev.firstuse = 1;              /* can't recycle samples */
# Line 280 | Line 282 | dev_close()                    /* close our display and free resources
282  
283   dev_clear()                     /* clear our representation */
284   {
285 <        wipeclean();
285 >        viewflags |= VWCHANGE;          /* pretend our view has changed */
286 >        wipeclean();                    /* clean off display and samples */
287 >        dev_flush();                    /* redraw geometry & get depth */
288          rayqleft = 0;                   /* hold off update */
289   }
290  
# Line 327 | Line 331 | register VIEW  *nv;
331                          dev_input();    /* get resize event */
332                  }
333                  copystruct(&odev.v, nv);        /* setview() already called */
330 #ifdef STEREO
331                copystruct(&vwright, nv);
332                d = eyesepdist / sqrt(nv->hn2);
333                VSUM(vwright.vp, nv->vp, nv->hvec, d);
334                /* setview(&vwright);   -- Unnecessary */
335 #endif
334                  viewflags |= VWCHANGE;
335          }
336 + #ifdef STEREO
337 +        copystruct(&vwright, nv);
338 +        d = eyesepdist / sqrt(nv->hn2);
339 +        VSUM(vwright.vp, nv->vp, nv->hvec, d);
340 +        /* setview(&vwright);   -- Unnecessary */
341 + #endif
342          wipeclean();
343          return(1);
344   }
# Line 369 | Line 373 | dev_auxcom(cmd, args)          /* process an auxiliary command
373   char    *cmd, *args;
374   {
375   #ifdef DOBJ
376 <        if (dobj_command(cmd, args) >= 0)
376 >        int     vischange;
377 >
378 >        if ((vischange = dobj_command(cmd, args)) >= 0) {
379 >                if (vischange) {
380 >                        imm_mode = beam_sync(1) > 0;
381 >                        dev_clear();
382 >                }
383                  return;
384 +        }
385   #endif
386          sprintf(errmsg, "%s: unknown command", cmd);
387          error(COMMAND, errmsg);
# Line 502 | Line 513 | xferdepth()                    /* load and clear depth buffer */
513          }
514                                  /* allocate alpha buffer for portals */
515          if (gmPortals)
516 <                pbuf = (GLubyte *)malloc(odev.hres*odev.vres *
506 <                                (4*sizeof(GLubyte)));
516 >                pbuf = (GLubyte *)malloc(odev.hres*odev.vres*sizeof(GLubyte));
517          else
518                  pbuf = NULL;
519   #ifdef STEREO
520 <        setstereobuf(STEREO_BUFFER_RIGHT);
520 >        pushright();
521          glReadPixels(0, 0, odev.hres, odev.vres,
522                          GL_DEPTH_COMPONENT, GL_FLOAT, depthright);
523          if (pbuf != NULL) {
524                  glClear(GL_COLOR_BUFFER_BIT);
525                  gmDrawPortals(0xff, -1, -1, -1);
526                  glReadPixels(0, 0, odev.hres, odev.vres,
527 <                                GL_RGBA, GL_UNSIGNED_BYTE, pbuf);
527 >                                GL_RED, GL_UNSIGNED_BYTE, pbuf);
528          }
529          for (dbp = depthright + odev.hres*odev.vres; dbp-- > depthright; )
530 <                if (pbuf != NULL && pbuf[4*(dbp-depthright)]&0x40)
530 >                if (pbuf != NULL && pbuf[dbp-depthright]&0x40)
531                          *dbp = FHUGE;
532                  else
533                          *dbp = mapdepth(*dbp);
534          glClear(GL_DEPTH_BUFFER_BIT);
525        setstereobuf(STEREO_BUFFER_LEFT);
535          odDepthMap(1, depthright);
536 +        popright();
537   #endif
538                                  /* read back depth buffer */
539          glReadPixels(0, 0, odev.hres, odev.vres,
# Line 532 | Line 542 | xferdepth()                    /* load and clear depth buffer */
542                  glClear(GL_COLOR_BUFFER_BIT);           /* find portals */
543                  gmDrawPortals(0xff, -1, -1, -1);
544                  glReadPixels(0, 0, odev.hres, odev.vres,
545 <                                GL_RGBA, GL_UNSIGNED_BYTE, pbuf);
545 >                                GL_RED, GL_UNSIGNED_BYTE, pbuf);
546 > #ifdef DEBUG
547 >                glXSwapBuffers(ourdisplay, gwind);
548 > #endif
549          }
550          for (dbp = depthbuffer + odev.hres*odev.vres; dbp-- > depthbuffer; )
551 <                if (pbuf != NULL && pbuf[4*(dbp-depthbuffer)]&0x40)
551 >                if (pbuf != NULL && pbuf[dbp-depthbuffer]&0x40)
552                          *dbp = FHUGE;
553                  else
554                          *dbp = mapdepth(*dbp);
555          glClear(GL_DEPTH_BUFFER_BIT);           /* clear system depth buffer */
556          odDepthMap(0, depthbuffer);             /* transfer depth data */
557          if (pbuf != NULL)
558 <                free((char *)pbuf);             /* free our portal buffer */
558 >                free((void *)pbuf);             /* free our portal buffer */
559   }
560  
561  
# Line 553 | Line 566 | freedepth()                            /* free recorded depth buffer */
566                  return;
567   #ifdef STEREO
568          odDepthMap(1, NULL);
569 <        free((char *)depthright);
569 >        free((void *)depthright);
570          depthright = NULL;
571   #endif
572          odDepthMap(0, NULL);
573 <        free((char *)depthbuffer);
573 >        free((void *)depthbuffer);
574          depthbuffer = NULL;
575   }
576  
# Line 777 | Line 790 | XButtonPressedEvent    *ebut;
790  
791  
792   static
793 + waitabit()                              /* pause a moment */
794 + {
795 +        struct timespec ts;
796 +        ts.tv_sec = 0;
797 +        ts.tv_nsec = 5000000;
798 +        nanosleep(&ts, NULL);
799 + }
800 +
801 +
802 + static
803   getmove(ebut)                           /* get view change */
804   XButtonPressedEvent     *ebut;
805   {
# Line 790 | Line 813 | XButtonPressedEvent    *ebut;
813          XNoOp(ourdisplay);              /* makes sure we're not idle */
814  
815          viewflags &= ~VWSTEADY;         /* flag moving view */
816 <        setglpersp(&odev.v);            /* start us off in perspective */
816 >        setglpersp();                   /* start us off in perspective */
817          while (!XCheckMaskEvent(ourdisplay,
818                          ButtonReleaseMask, levptr(XEvent))) {
819 +                                        /* pause so as not to move too fast */
820 +                waitabit();
821                                          /* get cursor position */
822                  if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
823                                  &rootx, &rooty, &wx, &wy, &statemask))
# Line 832 | Line 857 | XButtonPressedEvent    *ebut;
857  
858  
859   static
860 < setglpersp(vp)                  /* set perspective view in GL */
836 < register VIEW   *vp;
860 > setglpersp()                    /* set perspective view in GL */
861   {
862          double  d, xmin, xmax, ymin, ymax;
863          GLfloat vec[4];
# Line 845 | Line 869 | register VIEW  *vp;
869                  dev_zmax = 100.;
870          } else {
871                  dev_zmin = 0.5*depthlim[0];
872 <                dev_zmax = 1.75*depthlim[1];
872 >                dev_zmax = 1.25*depthlim[1];
873                  if (dev_zmin > dev_zmax/5.)
874                          dev_zmin = dev_zmax/5.;
875          }
# Line 853 | Line 877 | register VIEW  *vp;
877                  dev_zmin = odev.v.vfore;
878          if (odev.v.vaft > FTINY)
879                  dev_zmax = odev.v.vaft;
880 <        if (dev_zmin < dev_zmax/100.)
881 <                dev_zmin = dev_zmax/100.;
880 >        if (dev_zmin*500. < dev_zmax)
881 >                dev_zmin = dev_zmax/500.;
882          setzrat();
883          xmax = dev_zmin * tan(PI/180./2. * odev.v.horiz);
884          xmin = -xmax;
# Line 928 | Line 952 | wipeclean()                    /* prepare for redraw */
952                          (VWCHANGE|VWSTEADY)) {  /* clear samples if new */
953                  odClean();
954                  viewflags &= ~VWCHANGE;         /* change noted */
955 <        }
956 <        setglpersp(&odev.v);            /* reset view & clipping planes */
955 >        } else if (viewflags & VWSTEADY)
956 >                odRedrawAll();
957 >        setglpersp();                   /* reset view & clipping planes */
958   }
959  
960  
# Line 979 | Line 1004 | register XKeyPressedEvent  *ekey;
1004                  inpresflags |= DFL(DC_RESUME);
1005                  return;
1006          case CTRL('R'):                 /* redraw screen */
1007 <                odRemap(0);
1007 >                odRemap(0);                     /* new tone mapping */
1008                  glClear(GL_DEPTH_BUFFER_BIT);
1009   #ifdef STEREO
1010                  setstereobuf(STEREO_BUFFER_RIGHT);
# Line 989 | Line 1014 | register XKeyPressedEvent  *ekey;
1014                  return;
1015          case CTRL('L'):                 /* refresh from server */
1016                  if (inpresflags & DFL(DC_REDRAW))
1017 <                        return;
1017 >                        return;                 /* already called */
1018                  XRaiseWindow(ourdisplay, gwind);
1019 <                XFlush(ourdisplay);
1020 <                sleep(1);
1021 <                wipeclean();                    /* fresh display */
1022 <                odRemap(1);                     /* fresh tone mapping */
998 <                dev_flush();                    /* draw octrees */
1019 >                XFlush(ourdisplay);             /* raise up window */
1020 >                sleep(1);                       /* wait for restacking */
1021 >                dev_clear();                    /* clear buffer and samples */
1022 >                odRemap(1);                     /* start fresh histogram */
1023                  inpresflags |= DFL(DC_REDRAW);  /* resend values from server */
1000                rayqleft = 0;                   /* hold off update */
1024                  return;
1025          case 'K':                       /* kill rtrace process(es) */
1026                  inpresflags |= DFL(DC_KILL);
# Line 1030 | Line 1053 | register XExposeEvent  *eexp;
1053          }
1054          xmin = eexp->x; xmax = eexp->x + eexp->width;
1055          ymin = odev.vres - eexp->y - eexp->height; ymax = odev.vres - eexp->y;
1056 +
1057 +        if (xmin <= 0 && xmax >= odev.hres-1 &&
1058 +                        ymin <= 0 && ymax >= odev.vres) {
1059 +                DCHECK(eexp->count, WARNING, "multiple clear in fixwindow");
1060 +                wipeclean();                    /* make sure we're go */
1061 +                return;
1062 +        }
1063                                                  /* clear portion of depth */
1064          glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
1065          glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines