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.23 by gwlarson, Thu Aug 27 19:33:05 1998 UTC vs.
Revision 3.28 by gwlarson, Thu Jun 10 15:22:21 1999 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1998 Silicon Graphics, Inc. */
1 > /* Copyright (c) 1999 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ SGI";
# Line 21 | Line 21 | static char SCCSid[] = "$SunId$ SGI";
21   #endif
22  
23   #include "standard.h"
24 #include "rhd_sample.h"
24  
26 #include <sys/types.h>
25   #include <GL/glx.h>
26   #include <GL/glu.h>
27   #ifdef STEREO
28   #include <X11/extensions/SGIStereo.h>
29   #endif
30 +
31 + #include "rhd_sample.h"
32   #ifdef DOBJ
33   #include "rhdobj.h"
34   #endif
# Line 36 | Line 36 | static char SCCSid[] = "$SunId$ SGI";
36   #include "x11icon.h"
37  
38   #ifndef RAYQLEN
39 < #define RAYQLEN         250             /* max. rays to queue before flush */
39 > #define RAYQLEN         1024            /* max. rays to queue before flush */
40   #endif
41  
42   #ifndef FEQ
# Line 45 | Line 45 | static char SCCSid[] = "$SunId$ SGI";
45  
46   #define GAMMA           1.4             /* default gamma correction */
47  
48 + #define FRAMESTATE(s)   (((s)&(ShiftMask|ControlMask))==(ShiftMask|ControlMask))
49 +
50   #define MOVPCT          7               /* percent distance to move /frame */
51   #define MOVDIR(b)       ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1)
52   #define MOVDEG          (-5)            /* degrees to orbit CW/down /frame */
53   #define MOVORB(s)       ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
54  
55   #ifndef TARGETFPS
56 < #define TARGETFPS       4.0             /* target frames/sec during motion */
56 > #define TARGETFPS       2.0             /* target frames/sec during motion */
57   #endif
58  
59   #define MINWIDTH        480             /* minimum graphics window width */
# Line 74 | Line 76 | static char SCCSid[] = "$SunId$ SGI";
76  
77   struct driver   odev;                   /* global device driver structure */
78  
79 + char odev_args[64];                     /* command arguments */
80 +
81   #ifdef STEREO
82   static VIEW     vwright;                /* right eye view */
83   #endif
# Line 101 | Line 105 | static int     inpresflags;            /* input result flags */
105   static int      headlocked = 0;         /* lock vertical motion */
106  
107   static int  resizewindow(), getevent(), getkey(), moveview(), wipeclean(),
108 <                setglpersp(), getmove(), fixwindow(), mytmflags();
108 >                setglpersp(), getframe(), getmove(), fixwindow(), mytmflags();
109  
110   #ifdef STEREO
111   static int  pushright(), popright();
112   #endif
113 + static double   getdistance();
114 + #define mapdepth(d) ((d)> 0.9995 ? FHUGE: dev_zmin/ \
115 +                     (1.-(d)*(1.-dev_zmin/dev_zmax)))
116  
117   extern time_t   time();
118  
# Line 256 | Line 263 | dev_close()                    /* close our display and free resources
263   dev_clear()                     /* clear our representation */
264   {
265          smInit(rsL.max_samp);
266 <        wipeclean();
266 >        wipeclean(1);
267          rayqleft = 0;                   /* hold off update */
268   }
269  
# Line 303 | Line 310 | register VIEW  *nv;
310                          dev_input();    /* get resize event */
311                  }
312                  copystruct(&odev.v, nv);        /* setview() already called */
313 +        }
314   #ifdef STEREO
315 <                copystruct(&vwright, nv);
316 <                d = eyesepdist / sqrt(nv->hn2);
317 <                VSUM(vwright.vp, nv->vp, nv->hvec, d);
318 <                /* setview(&vwright);   -- Unnecessary */
315 >        copystruct(&vwright, nv);
316 >        d = eyesepdist / sqrt(nv->hn2);
317 >        VSUM(vwright.vp, nv->vp, nv->hvec, d);
318 >        /* setview(&vwright);   -- Unnecessary */
319   #endif
320 <        }
313 <        wipeclean();
320 >        wipeclean(0);
321          return(1);
322   }
323  
324  
325 + dev_section(gfn, pfn)           /* add octree for geometry rendering */
326 + char    *gfn, *pfn;
327 + {
328 +        /* unimplemented */
329 + }
330 +
331 +
332   dev_auxcom(cmd, args)           /* process an auxiliary command */
333   char    *cmd, *args;
334   {
# Line 393 | Line 407 | dev_flush()                    /* flush output */
407          if (mapped) {
408   #ifdef STEREO
409                  pushright();                    /* update right eye */
410 <                smUpdate(&vwright, 100);
410 >                smUpdate(&vwright, MAXQUALITY);
411   #ifdef DOBJ
412                  dobj_render();                  /* usually in foreground */
413   #endif
414                  popright();                     /* update left eye */
415   #endif
416 <                smUpdate(&odev.v, 100);
416 >                smUpdate(&odev.v, MAXQUALITY);
417                  checkglerr("rendering mesh");
418   #ifdef DOBJ
419                  dobj_render();
# Line 489 | Line 503 | getevent()                     /* get next event */
503                  getkey(levptr(XKeyPressedEvent));
504                  break;
505          case ButtonPress:
506 <                getmove(levptr(XButtonPressedEvent));
506 >                if (FRAMESTATE(levptr(XButtonPressedEvent)->state))
507 >                        getframe(levptr(XButtonPressedEvent));
508 >                else
509 >                        getmove(levptr(XButtonPressedEvent));
510                  break;
511          }
512   }
# Line 518 | Line 535 | int    fore;
535          checkglerr("drawing grid lines");
536   }
537  
538 + static double
539 + getdistance(dx, dy, direc)      /* distance from fore plane along view ray */
540 + int     dx, dy;
541 + FVECT   direc;
542 + {
543 +        GLfloat gldepth;
544 +        double  dist;
545  
546 +        if (dx<0 | dx>=odev.hres | dy<0 | dy>=odev.vres)
547 +                return(FHUGE);
548 +        glReadPixels(dx,dy, 1,1, GL_DEPTH_COMPONENT,GL_FLOAT, &gldepth);
549 +        dist = mapdepth(gldepth);
550 +        if (dist >= .99*FHUGE)
551 +                return(FHUGE);
552 +        return((dist-odev.v.vfore)/DOT(direc,odev.v.vdir));
553 + }
554 +
555 +
556   static
557   moveview(dx, dy, mov, orb)      /* move our view */
558   int     dx, dy, mov, orb;
559   {
560          VIEW    nv;
561          FVECT   odir, v1, wip;
562 <        double  d;
562 >        double  d,d1;
563          register int    li;
564                                  /* start with old view */
565          copystruct(&nv, &odev.v);
# Line 534 | Line 568 | int    dx, dy, mov, orb;
568                          (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
569                  return(0);              /* outside view */
570          if (mov | orb) {        /* moving relative to geometry */
571 +                d = getdistance(dx, dy, odir);/*distance from front plane */
572   #ifdef DOBJ
573 <                d = dobj_trace(NULL, v1, odir); /* check objects */
573 >                d1 = dobj_trace(NULL, v1, odir);        /* check objects */
574                                                  /* check holodeck */
575 <                if ((li = smFindSamp(v1, odir)) >= 0) {
576 <                        VCOPY(wip, rsL.wp[li]);
542 <                        if (d < .99*FHUGE && d*d <= dist2(v1, wip))
543 <                                li = -1;        /* object is closer */
544 <                } else if (d >= .99*FHUGE)
545 <                        return(0);              /* nothing visible */
546 <                if (li < 0)
547 <                        VSUM(wip, v1, odir, d); /* else get object point */
548 < #else
549 <                if ((li = smFindSamp(v1, odir)) < 0)
550 <                        return(0);      /* not on window */
551 <                VCOPY(wip, rsL.wp[li]);
575 >                if (d1 < d)
576 >                        d = d1;
577   #endif
578 <                VSUM(odir, wip, odev.v.vp, -1.);
578 >                if (d >= .99*FHUGE)
579 >                        d = 0.5*(dev_zmax+dev_zmin);    /* just guess */
580 >                VSUM(wip, v1, odir, d);
581 >                VSUB(odir, wip, odev.v.vp);
582 > #if 0
583 >                fprintf(stderr, "moveview: hit %s at (%f,%f,%f) (t=%f)\n",
584 >                                li < 0 ? "object" : "mesh",
585 >                                wip[0], wip[1], wip[2],
586 >                                (wip[0]-odev.v.vp[0])*odir[0] +
587 >                                (wip[1]-odev.v.vp[1])*odir[1] +
588 >                                (wip[2]-odev.v.vp[2])*odir[2]);
589 > #endif
590          } else                  /* panning with constant viewpoint */
591                  VCOPY(nv.vdir, odir);
592          if (orb && mov) {               /* orbit left/right */
# Line 582 | Line 618 | int    dx, dy, mov, orb;
618  
619  
620   static
621 + getframe(ebut)                          /* get focus frame */
622 + XButtonPressedEvent     *ebut;
623 + {
624 +        int     startx = ebut->x, starty = ebut->y;
625 +        int     endx, endy;
626 +
627 +        XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent));
628 +        endx = levptr(XButtonReleasedEvent)->x;
629 +        endy = levptr(XButtonReleasedEvent)->y;
630 +        if (endx == startx | endy == starty) {
631 +                XBell(ourdisplay, 0);
632 +                return;
633 +        }
634 +        if (endx < startx) {register int c = endx; endx = startx; startx = c;}
635 +        if (endy < starty) {register int c = endy; endy = starty; starty = c;}
636 +        sprintf(odev_args, "%.3f %.3f %.3f %.3f",
637 +                        (startx+.5)/odev.hres, 1.-(endy+.5)/odev.vres,
638 +                        (endx+.5)/odev.hres, 1.-(starty+.5)/odev.vres);
639 +        inpresflags |= DFL(DC_FOCUS);
640 + }
641 +
642 +
643 + static
644   getmove(ebut)                           /* get view change */
645   XButtonPressedEvent     *ebut;
646   {
647          int     movdir = MOVDIR(ebut->button);
648          int     movorb = MOVORB(ebut->state);
649 <        int     qlevel = 99;
649 >        int     qlevel = MAXQUALITY-1;
650          time_t  lasttime, thistime;
651          int     nframes;
652          Window  rootw, childw;
# Line 596 | Line 655 | XButtonPressedEvent    *ebut;
655  
656          XNoOp(ourdisplay);              /* makes sure we're not idle */
657  
658 <        lasttime = time(0); nframes = 0;
658 >        nframes = 0;
659          while (!XCheckMaskEvent(ourdisplay,
660                          ButtonReleaseMask, levptr(XEvent))) {
661                                          /* get cursor position */
# Line 630 | Line 689 | XButtonPressedEvent    *ebut;
689                  dobj_render();          /* redraw object */
690   #endif
691                  glFlush();
692 <                nframes++;              /* figure out good quality level */
692 >                                        /* figure out good quality level */
693 >                if (!nframes++) {               /* ignore first frame */
694 >                        lasttime = time(0);
695 >                        continue;
696 >                }
697                  thistime = time(0);
698 <                if (thistime - lasttime >= 3 ||
698 >                if (thistime - lasttime >= 6 ||
699                                  nframes > (int)(3*3*TARGETFPS)) {
700 <                        qlevel = thistime<=lasttime ? 1000 :
700 >                        qlevel = thistime<=lasttime ? 3*MAXQUALITY :
701                                  (int)((double)nframes/(thistime-lasttime)
702                                          / TARGETFPS * qlevel + 0.5);
703 <                        lasttime = thistime; nframes = 0;
704 <                        if (qlevel > 99) {
705 <                                if (qlevel > 300) {     /* put on the brakes */
703 >                        nframes = 0;
704 >                        if (qlevel >= MAXQUALITY) {
705 >                                if (qlevel >= 3*MAXQUALITY) {   /* brakes!! */
706                                          sleep(1);
707                                          lasttime++;
708                                  }
709 <                                qlevel = 99;
709 >                                qlevel = MAXQUALITY-1;
710                          } else if (qlevel < 1)
711                                  qlevel = 1;
712                  }
# Line 664 | Line 727 | register VIEW  *vp;
727          double  d, xmin, xmax, ymin, ymax;
728  
729          if (mindpth >= maxdpth) {
730 <                dev_zmin = 0.1;
730 >                dev_zmin = 1.;
731                  dev_zmax = 100.;
732          } else {
733 <                dev_zmin = 0.5*mindpth;
734 <                dev_zmax = 1.5*maxdpth;
672 <                if (dev_zmin > dev_zmax/100.)
673 <                        dev_zmin = dev_zmax/100.;
733 >                dev_zmin = 0.1*mindpth;
734 >                dev_zmax = 5.0*maxdpth;
735          }
736          if (odev.v.vfore > FTINY)
737                  dev_zmin = odev.v.vfore;
738          if (odev.v.vaft > FTINY)
739                  dev_zmax = odev.v.vaft;
740 <        if (dev_zmin < dev_zmax/5000.)
741 <                dev_zmin = dev_zmax/5000.;
740 >        if (dev_zmin < dev_zmax/500.)
741 >                dev_zmin = dev_zmax/500.;
742          xmax = dev_zmin * tan(PI/180./2. * odev.v.horiz);
743          xmin = -xmax;
744          d = odev.v.hoff * (xmax - xmin);
# Line 700 | Line 761 | register VIEW  *vp;
761  
762  
763   static
764 < wipeclean()                     /* prepare for redraw */
764 > wipeclean(tmflag)                       /* prepare for redraw */
765 > int     tmflag;
766   {
767                                          /* clear depth buffer */
768   #ifdef STEREO
# Line 709 | Line 771 | wipeclean()                    /* prepare for redraw */
771          setstereobuf(STEREO_BUFFER_LEFT);
772   #endif
773          glClear(GL_DEPTH_BUFFER_BIT);
774 <        smClean();                      /* reset drawing routines */
774 >        smClean(tmflag);                /* reset drawing routines */
775          setglpersp(&odev.v);            /* reset view & clipping planes */
776   }
777  
# Line 718 | Line 780 | static
780   getkey(ekey)                            /* get input key */
781   register XKeyPressedEvent  *ekey;
782   {
783 +        Window  rootw, childw;
784 +        int     rootx, rooty, wx, wy;
785 +        unsigned int    statemask;
786          int  n;
787          char    buf[8];
788  
# Line 740 | Line 805 | register XKeyPressedEvent  *ekey;
805          case 'v':                       /* spit out view */
806                  inpresflags |= DFL(DC_GETVIEW);
807                  return;
808 +        case 'f':                       /* frame view position */
809 +                if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
810 +                                &rootx, &rooty, &wx, &wy, &statemask))
811 +                        return;         /* on another screen */
812 +                sprintf(odev_args, "%.4f %.4f", (wx+.5)/odev.hres,
813 +                                1.-(wy+.5)/odev.vres);
814 +                inpresflags |= DFL(DC_FOCUS);
815 +                return;
816 +        case 'F':                       /* unfocus */
817 +                odev_args[0] = '\0';
818 +                inpresflags |= DFL(DC_FOCUS);
819 +                return;
820          case '\n':
821          case '\r':                      /* resume computation */
822                  inpresflags |= DFL(DC_RESUME);
823                  return;
824          case CTRL('R'):                 /* redraw screen */
825 <                wipeclean();
825 >                wipeclean(1);
826                  return;
827          case CTRL('L'):                 /* refresh from server */
828                  if (inpresflags & DFL(DC_REDRAW))
# Line 795 | Line 872 | register XExposeEvent  *eexp;
872          }
873          if (eexp->count)                /* wait for final exposure */
874                  return;
875 <        wipeclean();                    /* clear depth */
875 >        wipeclean(0);                   /* clear depth */
876   }
877  
878  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines