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

Comparing ray/src/hd/rhd_glx.c (file contents):
Revision 3.24 by gwlarson, Thu Dec 10 10:45:54 1998 UTC vs.
Revision 3.30 by schorsch, Mon Jul 21 22:30:18 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 GLX driver for holodeck display.
6   * Based on old GLX driver using cones.
# 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
# Line 54 | Line 50 | static char SCCSid[] = "$SunId$ SGI";
50   #define MOVORB(s)       ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
51  
52   #ifndef TARGETFPS
53 < #define TARGETFPS       4.0             /* target frames/sec during motion */
53 > #define TARGETFPS       2.0             /* target frames/sec during motion */
54   #endif
55  
56   #define MINWIDTH        480             /* minimum graphics window width */
# Line 111 | Line 107 | static int  resizewindow(), getevent(), getkey(), move
107   #ifdef STEREO
108   static int  pushright(), popright();
109   #endif
110 + static double   getdistance();
111 + #define mapdepth(d) ((d)> 0.9995 ? FHUGE: dev_zmin/ \
112 +                     (1.-(d)*(1.-dev_zmin/dev_zmax)))
113  
114   extern time_t   time();
115  
# Line 224 | Line 223 | char  *id;
223          setstereobuf(STEREO_BUFFER_LEFT);
224   #endif
225          checkglerr("setting rendering parameters");
226 <        copystruct(&odev.v, &stdview);
226 >        odev.v = stdview;
227          odev.v.type = VT_PER;
228                                          /* map the window */
229          XMapWindow(ourdisplay, gwind);
# Line 261 | Line 260 | dev_close()                    /* close our display and free resources
260   dev_clear()                     /* clear our representation */
261   {
262          smInit(rsL.max_samp);
263 <        wipeclean();
263 >        wipeclean(1);
264          rayqleft = 0;                   /* hold off update */
265   }
266  
# Line 307 | Line 306 | register VIEW  *nv;
306                          XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres);
307                          dev_input();    /* get resize event */
308                  }
309 <                copystruct(&odev.v, nv);        /* setview() already called */
309 >                odev.v = *nv;   /* setview() already called */
310 >        }
311   #ifdef STEREO
312 <                copystruct(&vwright, nv);
313 <                d = eyesepdist / sqrt(nv->hn2);
314 <                VSUM(vwright.vp, nv->vp, nv->hvec, d);
315 <                /* setview(&vwright);   -- Unnecessary */
312 >        vwright = *nv;
313 >        d = eyesepdist / sqrt(nv->hn2);
314 >        VSUM(vwright.vp, nv->vp, nv->hvec, d);
315 >        /* setview(&vwright);   -- Unnecessary */
316   #endif
317 <        }
318 <        wipeclean();
317 >        wipeclean(0);
318          return(1);
319   }
320  
321  
322 + dev_section(gfn, pfn)           /* add octree for geometry rendering */
323 + char    *gfn, *pfn;
324 + {
325 +        /* unimplemented */
326 + }
327 +
328 +
329   dev_auxcom(cmd, args)           /* process an auxiliary command */
330   char    *cmd, *args;
331   {
# Line 398 | Line 404 | dev_flush()                    /* flush output */
404          if (mapped) {
405   #ifdef STEREO
406                  pushright();                    /* update right eye */
407 <                smUpdate(&vwright, 100);
407 >                smUpdate(&vwright, MAXQUALITY);
408   #ifdef DOBJ
409                  dobj_render();                  /* usually in foreground */
410   #endif
411                  popright();                     /* update left eye */
412   #endif
413 <                smUpdate(&odev.v, 100);
413 >                smUpdate(&odev.v, MAXQUALITY);
414                  checkglerr("rendering mesh");
415   #ifdef DOBJ
416                  dobj_render();
# Line 526 | Line 532 | int    fore;
532          checkglerr("drawing grid lines");
533   }
534  
535 + static double
536 + getdistance(dx, dy, direc)      /* distance from fore plane along view ray */
537 + int     dx, dy;
538 + FVECT   direc;
539 + {
540 +        GLfloat gldepth;
541 +        double  dist;
542  
543 +        if (dx<0 | dx>=odev.hres | dy<0 | dy>=odev.vres)
544 +                return(FHUGE);
545 +        glReadPixels(dx,dy, 1,1, GL_DEPTH_COMPONENT,GL_FLOAT, &gldepth);
546 +        dist = mapdepth(gldepth);
547 +        if (dist >= .99*FHUGE)
548 +                return(FHUGE);
549 +        return((dist-odev.v.vfore)/DOT(direc,odev.v.vdir));
550 + }
551 +
552 +
553   static
554   moveview(dx, dy, mov, orb)      /* move our view */
555   int     dx, dy, mov, orb;
556   {
557          VIEW    nv;
558          FVECT   odir, v1, wip;
559 <        double  d;
559 >        double  d,d1;
560          register int    li;
561                                  /* start with old view */
562 <        copystruct(&nv, &odev.v);
562 >        nv = odev.v;
563                                  /* orient our motion */
564          if (viewray(v1, odir, &odev.v,
565                          (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
566                  return(0);              /* outside view */
567          if (mov | orb) {        /* moving relative to geometry */
568 +                d = getdistance(dx, dy, odir);/*distance from front plane */
569   #ifdef DOBJ
570 <                d = dobj_trace(NULL, v1, odir); /* check objects */
570 >                d1 = dobj_trace(NULL, v1, odir);        /* check objects */
571                                                  /* check holodeck */
572 <                if ((li = smFindSamp(v1, odir)) >= 0) {
573 <                        VCOPY(wip, rsL.wp[li]);
550 <                        if (d < .99*FHUGE && d*d <= dist2(v1, wip))
551 <                                li = -1;        /* object is closer */
552 <                } else if (d >= .99*FHUGE)
553 <                        return(0);              /* nothing visible */
554 <                if (li < 0)
555 <                        VSUM(wip, v1, odir, d); /* else get object point */
556 < #else
557 <                if ((li = smFindSamp(v1, odir)) < 0)
558 <                        return(0);      /* not on window */
559 <                VCOPY(wip, rsL.wp[li]);
572 >                if (d1 < d)
573 >                        d = d1;
574   #endif
575 < #ifdef DEBUG
575 >                if (d >= .99*FHUGE)
576 >                        d = 0.5*(dev_zmax+dev_zmin);    /* just guess */
577 >                VSUM(wip, v1, odir, d);
578 >                VSUB(odir, wip, odev.v.vp);
579 > #if 0
580                  fprintf(stderr, "moveview: hit %s at (%f,%f,%f) (t=%f)\n",
581                                  li < 0 ? "object" : "mesh",
582                                  wip[0], wip[1], wip[2],
# Line 566 | Line 584 | int    dx, dy, mov, orb;
584                                  (wip[1]-odev.v.vp[1])*odir[1] +
585                                  (wip[2]-odev.v.vp[2])*odir[2]);
586   #endif
569                VSUM(odir, wip, odev.v.vp, -1.);
587          } else                  /* panning with constant viewpoint */
588                  VCOPY(nv.vdir, odir);
589          if (orb && mov) {               /* orbit left/right */
# Line 626 | Line 643 | XButtonPressedEvent    *ebut;
643   {
644          int     movdir = MOVDIR(ebut->button);
645          int     movorb = MOVORB(ebut->state);
646 <        int     qlevel = 99;
646 >        int     qlevel = MAXQUALITY-1;
647          time_t  lasttime, thistime;
648          int     nframes;
649          Window  rootw, childw;
# Line 635 | Line 652 | XButtonPressedEvent    *ebut;
652  
653          XNoOp(ourdisplay);              /* makes sure we're not idle */
654  
655 <        lasttime = time(0); nframes = 0;
655 >        nframes = 0;
656          while (!XCheckMaskEvent(ourdisplay,
657                          ButtonReleaseMask, levptr(XEvent))) {
658                                          /* get cursor position */
# Line 669 | Line 686 | XButtonPressedEvent    *ebut;
686                  dobj_render();          /* redraw object */
687   #endif
688                  glFlush();
689 <                nframes++;              /* figure out good quality level */
689 >                                        /* figure out good quality level */
690 >                if (!nframes++) {               /* ignore first frame */
691 >                        lasttime = time(0);
692 >                        continue;
693 >                }
694                  thistime = time(0);
695 <                if (thistime - lasttime >= 3 ||
695 >                if (thistime - lasttime >= 6 ||
696                                  nframes > (int)(3*3*TARGETFPS)) {
697 <                        qlevel = thistime<=lasttime ? 1000 :
697 >                        qlevel = thistime<=lasttime ? 3*MAXQUALITY :
698                                  (int)((double)nframes/(thistime-lasttime)
699                                          / TARGETFPS * qlevel + 0.5);
700 <                        lasttime = thistime; nframes = 0;
701 <                        if (qlevel > 99) {
702 <                                if (qlevel > 300) {     /* put on the brakes */
700 >                        nframes = 0;
701 >                        if (qlevel >= MAXQUALITY) {
702 >                                if (qlevel >= 3*MAXQUALITY) {   /* brakes!! */
703                                          sleep(1);
704                                          lasttime++;
705                                  }
706 <                                qlevel = 99;
706 >                                qlevel = MAXQUALITY-1;
707                          } else if (qlevel < 1)
708                                  qlevel = 1;
709                  }
# Line 703 | Line 724 | register VIEW  *vp;
724          double  d, xmin, xmax, ymin, ymax;
725  
726          if (mindpth >= maxdpth) {
727 <                dev_zmin = 0.1;
727 >                dev_zmin = 1.;
728                  dev_zmax = 100.;
729          } else {
730 <                dev_zmin = 0.5*mindpth;
731 <                dev_zmax = 1.5*maxdpth;
711 <                if (dev_zmin > dev_zmax/100.)
712 <                        dev_zmin = dev_zmax/100.;
730 >                dev_zmin = 0.1*mindpth;
731 >                dev_zmax = 5.0*maxdpth;
732          }
733          if (odev.v.vfore > FTINY)
734                  dev_zmin = odev.v.vfore;
735          if (odev.v.vaft > FTINY)
736                  dev_zmax = odev.v.vaft;
737 <        if (dev_zmin < dev_zmax/5000.)
738 <                dev_zmin = dev_zmax/5000.;
737 >        if (dev_zmin*500. < dev_zmax)
738 >                dev_zmax = dev_zmin*500.;
739          xmax = dev_zmin * tan(PI/180./2. * odev.v.horiz);
740          xmin = -xmax;
741          d = odev.v.hoff * (xmax - xmin);
# Line 739 | Line 758 | register VIEW  *vp;
758  
759  
760   static
761 < wipeclean()                     /* prepare for redraw */
761 > wipeclean(tmflag)                       /* prepare for redraw */
762 > int     tmflag;
763   {
764                                          /* clear depth buffer */
765   #ifdef STEREO
# Line 748 | Line 768 | wipeclean()                    /* prepare for redraw */
768          setstereobuf(STEREO_BUFFER_LEFT);
769   #endif
770          glClear(GL_DEPTH_BUFFER_BIT);
771 <        smClean();                      /* reset drawing routines */
771 >        smClean(tmflag);                /* reset drawing routines */
772          setglpersp(&odev.v);            /* reset view & clipping planes */
773   }
774  
# Line 799 | Line 819 | register XKeyPressedEvent  *ekey;
819                  inpresflags |= DFL(DC_RESUME);
820                  return;
821          case CTRL('R'):                 /* redraw screen */
822 <                wipeclean();
822 >                wipeclean(1);
823                  return;
824          case CTRL('L'):                 /* refresh from server */
825                  if (inpresflags & DFL(DC_REDRAW))
# Line 849 | Line 869 | register XExposeEvent  *eexp;
869          }
870          if (eexp->count)                /* wait for final exposure */
871                  return;
872 <        wipeclean();                    /* clear depth */
872 >        wipeclean(0);                   /* clear depth */
873   }
874  
875  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines