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.21 by gwlarson, Fri Aug 21 11:38:21 1998 UTC vs.
Revision 3.27 by gwlarson, Sun Jan 3 13:40:25 1999 UTC

# Line 21 | Line 21 | static char SCCSid[] = "$SunId$ SGI";
21   #endif
22  
23   #include "standard.h"
24 #include "rhd_sample.h"
24  
25   #include <sys/types.h>
26   #include <GL/glx.h>
# Line 29 | Line 28 | static char SCCSid[] = "$SunId$ SGI";
28   #ifdef STEREO
29   #include <X11/extensions/SGIStereo.h>
30   #endif
31 +
32 + #include "rhd_sample.h"
33   #ifdef DOBJ
34   #include "rhdobj.h"
35   #endif
# Line 36 | Line 37 | static char SCCSid[] = "$SunId$ SGI";
37   #include "x11icon.h"
38  
39   #ifndef RAYQLEN
40 < #define RAYQLEN         250             /* max. rays to queue before flush */
40 > #define RAYQLEN         1024            /* max. rays to queue before flush */
41   #endif
42  
43   #ifndef FEQ
# Line 45 | Line 46 | static char SCCSid[] = "$SunId$ SGI";
46  
47   #define GAMMA           1.4             /* default gamma correction */
48  
49 + #define FRAMESTATE(s)   (((s)&(ShiftMask|ControlMask))==(ShiftMask|ControlMask))
50 +
51   #define MOVPCT          7               /* percent distance to move /frame */
52   #define MOVDIR(b)       ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1)
53   #define MOVDEG          (-5)            /* degrees to orbit CW/down /frame */
# Line 74 | Line 77 | static char SCCSid[] = "$SunId$ SGI";
77  
78   struct driver   odev;                   /* global device driver structure */
79  
80 + char odev_args[64];                     /* command arguments */
81 +
82 + #ifdef STEREO
83   static VIEW     vwright;                /* right eye view */
84 + #endif
85  
86   static int      rayqleft = 0;           /* rays left to queue before flush */
87  
# Line 99 | Line 106 | static int     inpresflags;            /* input result flags */
106   static int      headlocked = 0;         /* lock vertical motion */
107  
108   static int  resizewindow(), getevent(), getkey(), moveview(), wipeclean(),
109 <                setglpersp(), getmove(), fixwindow(), mytmflags();
109 >                setglpersp(), getframe(), getmove(), fixwindow(), mytmflags();
110  
111   #ifdef STEREO
112   static int  pushright(), popright();
# Line 124 | Line 131 | char  *id;
131          XSizeHints      oursizhints;
132                                          /* check for unsupported stereo */
133   #ifdef NOSTEREO
134 <        error(USER, "stereo display driver unavailable");
134 >        error(INTERNAL, "stereo display driver unavailable");
135   #endif
136                                          /* open display server */
137          ourdisplay = XOpenDisplay(NULL);
# Line 216 | Line 223 | char  *id;
223          pheight *= 2.;
224          setstereobuf(STEREO_BUFFER_LEFT);
225   #endif
226 +        checkglerr("setting rendering parameters");
227          copystruct(&odev.v, &stdview);
228          odev.v.type = VT_PER;
229                                          /* map the window */
# Line 272 | Line 280 | register VIEW  *nv;
280                  nv->vert = odev.v.vert;
281                  return(0);
282          }
283 <        if (nv != &odev.v &&                    /* resize window? */
284 <                        (!FEQ(nv->horiz,odev.v.horiz) ||
285 <                                !FEQ(nv->vert,odev.v.vert))) {
286 <                int     dw = DisplayWidth(ourdisplay,ourscreen);
287 <                int     dh = DisplayHeight(ourdisplay,ourscreen);
283 >        if (nv != &odev.v) {
284 >                                                /* resize window? */
285 >                if (!FEQ(nv->horiz,odev.v.horiz) ||
286 >                                !FEQ(nv->vert,odev.v.vert)) {
287 >                        int     dw = DisplayWidth(ourdisplay,ourscreen);
288 >                        int     dh = DisplayHeight(ourdisplay,ourscreen);
289  
290 <                dw -= 25;       /* for window frame */
291 <                dh -= 50;
290 >                        dw -= 25;       /* for window frame */
291 >                        dh -= 50;
292   #ifdef STEREO
293 <                dh /= 2;
293 >                        dh /= 2;
294   #endif
295 <                odev.hres = 2.*VIEWDIST/pwidth *
296 <                                tan(PI/180./2.*nv->horiz);
297 <                odev.vres = 2.*VIEWDIST/pheight *
298 <                                tan(PI/180./2.*nv->vert);
299 <                if (odev.hres > dw) {
300 <                        odev.vres = dw * odev.vres / odev.hres;
301 <                        odev.hres = dw;
295 >                        odev.hres = 2.*VIEWDIST/pwidth *
296 >                                        tan(PI/180./2.*nv->horiz);
297 >                        odev.vres = 2.*VIEWDIST/pheight *
298 >                                        tan(PI/180./2.*nv->vert);
299 >                        if (odev.hres > dw) {
300 >                                odev.vres = dw * odev.vres / odev.hres;
301 >                                odev.hres = dw;
302 >                        }
303 >                        if (odev.vres > dh) {
304 >                                odev.hres = dh * odev.hres / odev.vres;
305 >                                odev.vres = dh;
306 >                        }
307 >                        XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres);
308 >                        dev_input();    /* get resize event */
309                  }
310 <                if (odev.vres > dh) {
295 <                        odev.hres = dh * odev.hres / odev.vres;
296 <                        odev.vres = dh;
297 <                }
298 <                XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres);
299 <                dev_input();    /* get resize event */
310 >                copystruct(&odev.v, nv);        /* setview() already called */
311          }
301        copystruct(&odev.v, nv);        /* setview() already called */
302        setglpersp(&odev.v);
312   #ifdef STEREO
313          copystruct(&vwright, nv);
314          d = eyesepdist / sqrt(nv->hn2);
315          VSUM(vwright.vp, nv->vp, nv->hvec, d);
316          /* setview(&vwright);   -- Unnecessary */
317   #endif
309        checkglerr("setting view");
318          wipeclean();
319          return(1);
320   }
321  
322  
323 + dev_section(gfn, pfn)           /* add octree for geometry rendering */
324 + char    *gfn, *pfn;
325 + {
326 +        /* unimplemented */
327 + }
328 +
329 +
330   dev_auxcom(cmd, args)           /* process an auxiliary command */
331   char    *cmd, *args;
332   {
# Line 367 | Line 382 | FVECT  d, p;
382                  return;
383          }
384   #endif
385 <        smNewSamp(c, d, p);             /* add to display representation */
371 <        if (p != NULL) {
385 >        if (p != NULL) {                /* add depth to our range */
386                  depth = (p[0] - odev.v.vp[0])*d[0] +
387                          (p[1] - odev.v.vp[1])*d[1] +
388                          (p[2] - odev.v.vp[2])*d[2];
# Line 379 | Line 393 | FVECT  d, p;
393                                  maxdpth = depth;
394                  }
395          }
396 +        smNewSamp(c, d, p);             /* add to display representation */
397          if (!--rayqleft)
398                  dev_flush();            /* flush output */
399   }
# Line 387 | Line 402 | FVECT  d, p;
402   int
403   dev_flush()                     /* flush output */
404   {
405 +        if (mapped) {
406   #ifdef STEREO
407 <        pushright();                    /* update right eye */
408 <        glClear(GL_DEPTH_BUFFER_BIT);
393 <        smUpdate(&vwright, 100);
407 >                pushright();                    /* update right eye */
408 >                smUpdate(&vwright, 100);
409   #ifdef DOBJ
410 <        dobj_render();                  /* usually in foreground */
410 >                dobj_render();                  /* usually in foreground */
411   #endif
412 <        popright();                     /* update left eye */
398 <        glClear(GL_DEPTH_BUFFER_BIT);
412 >                popright();                     /* update left eye */
413   #endif
414 <        smUpdate(&odev.v, 100);
414 >                smUpdate(&odev.v, 100);
415 >                checkglerr("rendering mesh");
416   #ifdef DOBJ
417 <        dobj_render();
417 >                dobj_render();
418   #endif
419 <        glFlush();                      /* flush OGL */
420 <        checkglerr("flushing display");
419 >                glFlush();                      /* flush OGL */
420 >        }
421          rayqleft = RAYQLEN;
422                                          /* flush X11 and return # pending */
423          return(odev.inpready = XPending(ourdisplay));
# Line 433 | Line 448 | pushright()                    /* push on right view */
448          glPushMatrix();
449          d = -eyesepdist / sqrt(odev.v.hn2);
450          glTranslated(d*odev.v.hvec[0], d*odev.v.hvec[1], d*odev.v.hvec[2]);
451 +        checkglerr("setting right view");
452   }
453  
454  
# Line 485 | Line 501 | getevent()                     /* get next event */
501                  getkey(levptr(XKeyPressedEvent));
502                  break;
503          case ButtonPress:
504 <                getmove(levptr(XButtonPressedEvent));
504 >                if (FRAMESTATE(levptr(XButtonPressedEvent)->state))
505 >                        getframe(levptr(XButtonPressedEvent));
506 >                else
507 >                        getmove(levptr(XButtonPressedEvent));
508                  break;
509          }
510   }
# Line 501 | Line 520 | register FVECT wp[2];
520  
521  
522   static
523 < draw_grids()                    /* draw holodeck section grids */
523 > draw_grids(fore)                /* draw holodeck section grids */
524 > int     fore;
525   {
526 <        static BYTE     gridrgba[4] = {0x0, 0xff, 0xff, 0x00};
527 <
528 <        if (!mapped)
529 <                return;
510 <        glColor4ub(gridrgba[0], gridrgba[1], gridrgba[2], gridrgba[3]);
526 >        if (fore)
527 >                glColor4ub(0, 255, 255, 0);
528 >        else
529 >                glColor4ub(0, 0, 0, 0);
530          glBegin(GL_LINES);              /* draw each grid line */
531          gridlines(draw3dline);
532          glEnd();
533 +        checkglerr("drawing grid lines");
534   }
535  
536  
# Line 524 | Line 544 | int    dx, dy, mov, orb;
544          register int    li;
545                                  /* start with old view */
546          copystruct(&nv, &odev.v);
547 <                                /* change view direction */
547 >                                /* orient our motion */
548          if (viewray(v1, odir, &odev.v,
549                          (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
550                  return(0);              /* outside view */
551 <        if (mov | orb) {
551 >        if (mov | orb) {        /* moving relative to geometry */
552   #ifdef DOBJ
553                  d = dobj_trace(NULL, v1, odir); /* check objects */
554 <                                                /* is holodeck in front? */
555 <                if ((li = smFindSamp(v1, odir)) >= 0 &&
536 <                                (rsL.wp[li][0] - nv.vp[0])*odir[0] +
537 <                                (rsL.wp[li][1] - nv.vp[1])*odir[1] +
538 <                                (rsL.wp[li][2] - nv.vp[2])*odir[2] < d)
554 >                                                /* check holodeck */
555 >                if ((li = smFindSamp(v1, odir)) >= 0) {
556                          VCOPY(wip, rsL.wp[li]);
557 <                else if (d < .99*FHUGE)         /* object is closer */
558 <                        VSUM(wip, nv.vp, odir, d);
559 <                else                            /* nothing visible */
560 <                        return(0);
557 >                        if (d < .99*FHUGE && d*d <= dist2(v1, wip))
558 >                                li = -1;        /* object is closer */
559 >                } else if (d >= .99*FHUGE)
560 >                        return(0);              /* nothing visible */
561 >                if (li < 0)
562 >                        VSUM(wip, v1, odir, d); /* else get object point */
563   #else
564                  if ((li = smFindSamp(v1, odir)) < 0)
565                          return(0);      /* not on window */
566                  VCOPY(wip, rsL.wp[li]);
567   #endif
568 <                VSUM(odir, wip, nv.vp, -1.);
569 <        } else
568 > #ifdef DEBUG
569 >                fprintf(stderr, "moveview: hit %s at (%f,%f,%f) (t=%f)\n",
570 >                                li < 0 ? "object" : "mesh",
571 >                                wip[0], wip[1], wip[2],
572 >                                (wip[0]-odev.v.vp[0])*odir[0] +
573 >                                (wip[1]-odev.v.vp[1])*odir[1] +
574 >                                (wip[2]-odev.v.vp[2])*odir[2]);
575 > #endif
576 >                VSUM(odir, wip, odev.v.vp, -1.);
577 >        } else                  /* panning with constant viewpoint */
578                  VCOPY(nv.vdir, odir);
579          if (orb && mov) {               /* orbit left/right */
580                  spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov);
# Line 566 | Line 593 | int    dx, dy, mov, orb;
593          }
594          if (!mov ^ !orb && headlocked) {        /* restore head height */
595                  VSUM(v1, odev.v.vp, nv.vp, -1.);
596 <                d = DOT(v1, odev.v.vup);
596 >                d = DOT(v1, nv.vup);
597                  VSUM(nv.vp, nv.vp, odev.v.vup, d);
598          }
599          if (setview(&nv) != NULL)
# Line 578 | Line 605 | int    dx, dy, mov, orb;
605  
606  
607   static
608 + getframe(ebut)                          /* get focus frame */
609 + XButtonPressedEvent     *ebut;
610 + {
611 +        int     startx = ebut->x, starty = ebut->y;
612 +        int     endx, endy;
613 +
614 +        XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent));
615 +        endx = levptr(XButtonReleasedEvent)->x;
616 +        endy = levptr(XButtonReleasedEvent)->y;
617 +        if (endx == startx | endy == starty) {
618 +                XBell(ourdisplay, 0);
619 +                return;
620 +        }
621 +        if (endx < startx) {register int c = endx; endx = startx; startx = c;}
622 +        if (endy < starty) {register int c = endy; endy = starty; starty = c;}
623 +        sprintf(odev_args, "%.3f %.3f %.3f %.3f",
624 +                        (startx+.5)/odev.hres, 1.-(endy+.5)/odev.vres,
625 +                        (endx+.5)/odev.hres, 1.-(starty+.5)/odev.vres);
626 +        inpresflags |= DFL(DC_FOCUS);
627 + }
628 +
629 +
630 + static
631   getmove(ebut)                           /* get view change */
632   XButtonPressedEvent     *ebut;
633   {
# Line 590 | Line 640 | XButtonPressedEvent    *ebut;
640          int     rootx, rooty, wx, wy;
641          unsigned int    statemask;
642  
643 <        XNoOp(ourdisplay);
643 >        XNoOp(ourdisplay);              /* makes sure we're not idle */
644  
645          lasttime = time(0); nframes = 0;
646          while (!XCheckMaskEvent(ourdisplay,
647                          ButtonReleaseMask, levptr(XEvent))) {
648 <
648 >                                        /* get cursor position */
649                  if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
650                                  &rootx, &rooty, &wx, &wy, &statemask))
651                          break;          /* on another screen */
652  
653 +                draw_grids(0);          /* clear old grid lines */
654 + #ifdef STEREO
655 +                pushright(); draw_grids(0); popright();
656 + #endif
657 +                                        /* compute view motion */
658                  if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) {
659                          sleep(1);
660                          lasttime++;
661 <                        continue;
661 >                        continue;       /* cursor in bad place */
662                  }
663 +                draw_grids(1);          /* redraw grid */
664   #ifdef STEREO
665                  pushright();
666 <                glClear(GL_COLOR_BUFFER_BIT);
611 <                draw_grids();
666 >                draw_grids(1);
667                  smUpdate(&vwright, qlevel);
668   #ifdef DOBJ
669                  dobj_render();
670   #endif
671                  popright();
672   #endif
673 <                glClear(GL_COLOR_BUFFER_BIT);
619 <                draw_grids();
673 >                                        /* redraw mesh */
674                  smUpdate(&odev.v, qlevel);
675   #ifdef DOBJ
676 <                dobj_render();
676 >                dobj_render();          /* redraw object */
677   #endif
678                  glFlush();
679 <                checkglerr("moving view");
626 <                nframes++;
679 >                nframes++;              /* figure out good quality level */
680                  thistime = time(0);
681                  if (thistime - lasttime >= 3 ||
682                                  nframes > (int)(3*3*TARGETFPS)) {
# Line 657 | Line 710 | register VIEW  *vp;
710          double  d, xmin, xmax, ymin, ymax;
711  
712          if (mindpth >= maxdpth) {
713 <                dev_zmin = 0.1;
713 >                dev_zmin = 1.;
714                  dev_zmax = 100.;
715          } else {
716                  dev_zmin = 0.5*mindpth;
717 <                dev_zmax = 1.5*maxdpth;
665 <                if (dev_zmin > dev_zmax/100.)
666 <                        dev_zmin = dev_zmax/100.;
717 >                dev_zmax = 5.0*maxdpth;
718          }
719          if (odev.v.vfore > FTINY)
720                  dev_zmin = odev.v.vfore;
721          if (odev.v.vaft > FTINY)
722                  dev_zmax = odev.v.vaft;
723 <        if (dev_zmin < dev_zmax/5000.)
724 <                dev_zmin = dev_zmax/5000.;
723 >        if (dev_zmin < dev_zmax/100.)
724 >                dev_zmin = dev_zmax/100.;
725          xmax = dev_zmin * tan(PI/180./2. * odev.v.horiz);
726          xmin = -xmax;
727          d = odev.v.hoff * (xmax - xmin);
# Line 688 | Line 739 | register VIEW  *vp;
739                  odev.v.vp[1] + odev.v.vdir[1],
740                  odev.v.vp[2] + odev.v.vdir[2],
741                  odev.v.vup[0], odev.v.vup[1], odev.v.vup[2]);
742 +        checkglerr("setting perspective view");
743   }
744  
745  
746   static
747   wipeclean()                     /* prepare for redraw */
748   {
749 +                                        /* clear depth buffer */
750   #ifdef STEREO
751          setstereobuf(STEREO_BUFFER_RIGHT);
752          glClear(GL_DEPTH_BUFFER_BIT);
753          setstereobuf(STEREO_BUFFER_LEFT);
754   #endif
755          glClear(GL_DEPTH_BUFFER_BIT);
756 <        smClean();
756 >        smClean();                      /* reset drawing routines */
757 >        setglpersp(&odev.v);            /* reset view & clipping planes */
758   }
759  
760  
# Line 708 | Line 762 | static
762   getkey(ekey)                            /* get input key */
763   register XKeyPressedEvent  *ekey;
764   {
765 +        Window  rootw, childw;
766 +        int     rootx, rooty, wx, wy;
767 +        unsigned int    statemask;
768          int  n;
769          char    buf[8];
770  
# Line 730 | Line 787 | register XKeyPressedEvent  *ekey;
787          case 'v':                       /* spit out view */
788                  inpresflags |= DFL(DC_GETVIEW);
789                  return;
790 +        case 'f':                       /* frame view position */
791 +                if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
792 +                                &rootx, &rooty, &wx, &wy, &statemask))
793 +                        return;         /* on another screen */
794 +                sprintf(odev_args, "%.4f %.4f", (wx+.5)/odev.hres,
795 +                                1.-(wy+.5)/odev.vres);
796 +                inpresflags |= DFL(DC_FOCUS);
797 +                return;
798 +        case 'F':                       /* unfocus */
799 +                odev_args[0] = '\0';
800 +                inpresflags |= DFL(DC_FOCUS);
801 +                return;
802          case '\n':
803          case '\r':                      /* resume computation */
804                  inpresflags |= DFL(DC_RESUME);
# Line 740 | Line 809 | register XKeyPressedEvent  *ekey;
809          case CTRL('L'):                 /* refresh from server */
810                  if (inpresflags & DFL(DC_REDRAW))
811                          return;
812 +                setglpersp(&odev.v);            /* reset clipping planes */
813                  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
814 <                glDisable(GL_DEPTH_TEST);
815 <                draw_grids();
814 >                glDisable(GL_DEPTH_TEST);       /* so grids will clear */
815 >                draw_grids(1);
816   #ifdef STEREO
817                  pushright();
818                  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
819 <                draw_grids();
819 >                draw_grids(1);
820                  popright();
821   #endif
822                  glEnable(GL_DEPTH_TEST);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines