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.15 by gwlarson, Tue Jan 5 18:16:17 1999 UTC vs.
Revision 3.29 by greg, Tue May 23 13:01:07 2006 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1999 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 20 | Line 17 | static char SCCSid[] = "$SunId$ SGI";
17   #endif
18   #endif
19  
23 #include "standard.h"
20  
21 < #include <sys/types.h>
21 > #include <time.h>
22   #include <GL/glx.h>
23   #include <GL/glu.h>
24   #ifdef STEREO
25   #include <X11/extensions/SGIStereo.h>
26   #endif
27  
28 + #include "standard.h"
29   #include "rhd_odraw.h"
30 + #include "rhdisp.h"
31 + #include "paths.h"
32   #ifdef DOBJ
33   #include "rhdobj.h"
34   #endif
# Line 83 | Line 82 | static char SCCSid[] = "$SunId$ SGI";
82  
83   struct driver   odev;                   /* global device driver structure */
84  
85 + TMstruct        *tmGlobal;              /* global tone-mapping structure */
86 +
87   char odev_args[64];                     /* command arguments */
88  
89   static GLfloat  *depthbuffer = NULL;    /* depth buffer */
# Line 115 | Line 116 | static int     inpresflags;            /* input result flags */
116  
117   static int      viewflags;              /* what's happening with view */
118  
119 + /*
120   static int  resizewindow(), getevent(), getkey(), moveview(), wipeclean(),
121                  xferdepth(), freedepth(), setglortho(),
122                  setglpersp(), getframe(), getmove(), fixwindow(), mytmflags();
123  
124   static double   getdistance();
125 + */
126 + static void checkglerr(char *where);
127 + static void xferdepth(void);
128 + static void freedepth(void);
129 + static double getdistance(int dx, int dy, FVECT direc);
130 + static int mytmflags(void);
131 + static void getevent(void);
132 + static void draw3dline(register FVECT wp[2]);
133 + static void draw_grids(int fore);
134 + static int moveview(int dx, int dy, int mov, int orb);
135 + static void getframe(XButtonPressedEvent *ebut);
136 + static void getmove(XButtonPressedEvent *ebut);
137 + static void getkey(register XKeyPressedEvent *ekey);
138 + static void fixwindow(register XExposeEvent *eexp);
139 + static void resizewindow(register XConfigureEvent *ersz);
140 + static void waitabit(void);
141 + static void setglpersp(void);
142 + static void setglortho(void);
143 + static void wipeclean(void);
144  
145 +
146   #ifdef STEREO
147 < static int  pushright(), popright();
147 > static void pushright(void);
148 > static void popright(void);
149   #endif
150  
151   extern int      gmPortals;      /* GL portal list id */
# Line 130 | Line 153 | extern int     gmPortals;      /* GL portal list id */
153   extern time_t   time();
154  
155  
156 + extern void
157   dev_open(id)                    /* initialize GLX driver */
158   char  *id;
159   {
# Line 187 | Line 211 | char  *id;
211                                  &myprims[BLU][CIEX],&myprims[BLU][CIEY],
212                                  &myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6)
213                  dpri = myprims;
214 <        if (tmInit(mytmflags(), dpri, gamval) == NULL)
214 >        tmGlobal = tmInit(mytmflags(), dpri, gamval);
215 >        if (tmGlobal == NULL)
216                  error(SYSTEM, "not enough memory in dev_open");
217                                          /* open window */
218          ourwinattr.background_pixel = ourblack;
# Line 210 | Line 235 | char  *id;
235                                          /* set window manager hints */
236          ourxwmhints.flags = InputHint|IconPixmapHint;
237          ourxwmhints.input = True;
238 <        ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay,
239 <                        gwind, x11icon_bits, x11icon_width, x11icon_height);
238 >        ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, gwind,
239 >                        (char *)x11icon_bits, x11icon_width, x11icon_height);
240          XSetWMHints(ourdisplay, gwind, &ourxwmhints);
241          oursizhints.min_width = MINWIDTH;
242   #ifdef STEREO
# Line 246 | Line 271 | char  *id;
271          setstereobuf(STEREO_BUFFER_LEFT);
272   #endif
273          checkglerr("setting rendering parameters");
274 <        copystruct(&odev.v, &stdview);
274 >        odev.v = stdview;
275          odev.v.type = VT_PER;
276          viewflags = VWSTEADY;           /* view starts static */
277                                          /* map the window */
# Line 261 | Line 286 | char  *id;
286   }
287  
288  
289 < dev_close()                     /* close our display and free resources */
289 > extern void
290 > dev_close(void)                 /* close our display and free resources */
291   {
292   #ifdef DOBJ
293          dobj_cleanup();
# Line 276 | Line 302 | dev_close()                    /* close our display and free resources
302          gwind = 0;
303          XCloseDisplay(ourdisplay);
304          ourdisplay = NULL;
305 <        tmDone(NULL);
305 >        tmDone(tmGlobal);
306          odev.v.type = 0;
307          odev.hres = odev.vres = 0;
308          odev.ifd = -1;
309   }
310  
311  
312 < dev_clear()                     /* clear our representation */
312 > extern void
313 > dev_clear(void)                 /* clear our representation */
314   {
315          viewflags |= VWCHANGE;          /* pretend our view has changed */
316          wipeclean();                    /* clean off display and samples */
# Line 292 | Line 319 | dev_clear()                    /* clear our representation */
319   }
320  
321  
322 < int
323 < dev_view(nv)                    /* assign new driver view */
324 < register VIEW   *nv;
322 > extern int
323 > dev_view(                       /* assign new driver view */
324 >        register VIEW   *nv
325 > )
326   {
327 + #ifdef STEREO
328          double  d;
329 <
329 > #endif
330          if (nv->type != VT_PER ||               /* check view legality */
331                          nv->horiz > 160. || nv->vert > 160.) {
332                  error(COMMAND, "illegal view type/angle");
# Line 333 | Line 362 | register VIEW  *nv;
362                          XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres);
363                          dev_input();    /* get resize event */
364                  }
365 <                copystruct(&odev.v, nv);        /* setview() already called */
365 >                odev.v = *nv;   /* setview() already called */
366                  viewflags |= VWCHANGE;
367          }
368   #ifdef STEREO
369 <        copystruct(&vwright, nv);
369 >        vwright = *nv;
370          d = eyesepdist / sqrt(nv->hn2);
371          VSUM(vwright.vp, nv->vp, nv->hvec, d);
372          /* setview(&vwright);   -- Unnecessary */
# Line 347 | Line 376 | register VIEW  *nv;
376   }
377  
378  
379 < dev_section(gfn, pfn)           /* add octree for geometry rendering */
380 < char    *gfn, *pfn;
379 > extern void
380 > dev_section(            /* add octree for geometry rendering */
381 >        char    *gfn,
382 >        char    *pfn
383 > )
384   {
353        extern char     *index();
354        char    *cp;
355
385          if (gfn == NULL) {
386                  gmEndGeom();
387                  gmEndPortal();
# Line 372 | Line 401 | char   *gfn, *pfn;
401   }
402  
403  
404 < dev_auxcom(cmd, args)           /* process an auxiliary command */
405 < char    *cmd, *args;
404 > extern void
405 > dev_auxcom(             /* process an auxiliary command */
406 >        char    *cmd,
407 >        char    *args
408 > )
409   {
410   #ifdef DOBJ
411          int     vischange;
# Line 391 | Line 423 | char   *cmd, *args;
423   }
424  
425  
426 < VIEW *
427 < dev_auxview(n, hvres)           /* return nth auxiliary view */
428 < int     n;
429 < int     hvres[2];
426 > extern VIEW *
427 > dev_auxview(            /* return nth auxiliary view */
428 >        int     n,
429 >        int     hvres[2]
430 > )
431   {
432          hvres[0] = odev.hres; hvres[1] = odev.vres;
433          if (n == 0)
# Line 407 | Line 440 | int    hvres[2];
440   }
441  
442  
443 < int
444 < dev_input()                     /* get X11 input */
443 > extern int
444 > dev_input(void)                 /* get X11 input */
445   {
446          inpresflags = 0;
447  
# Line 423 | Line 456 | dev_input()                    /* get X11 input */
456   }
457  
458  
459 < dev_value(c, d, p)              /* add a pixel value to our texture */
460 < COLR    c;
461 < FVECT   d, p;
459 > extern void
460 > dev_value(              /* add a pixel value to our texture */
461 >        COLR    c,
462 >        FVECT   d,
463 >        FVECT   p
464 > )
465   {
466   #ifdef DOBJ
467          if (dobj_lightsamp != NULL) {   /* in light source sampling */
# Line 439 | Line 475 | FVECT  d, p;
475   }
476  
477  
478 < int
479 < dev_flush()                     /* flush output as appropriate */
478 > extern int
479 > dev_flush(void)                 /* flush output as appropriate */
480   {
481          int     ndrawn;
482  
# Line 486 | Line 522 | dev_flush()                    /* flush output as appropriate */
522   }
523  
524  
525 < checkglerr(where)               /* check for GL or GLU error */
526 < char    *where;
525 > static void
526 > checkglerr(             /* check for GL or GLU error */
527 >        char    *where
528 > )
529   {
530          register GLenum errcode;
531  
# Line 499 | Line 537 | char   *where;
537   }
538  
539  
540 < static
541 < xferdepth()                     /* load and clear depth buffer */
540 > static void
541 > xferdepth(void)                 /* load and clear depth buffer */
542   {
543          register GLfloat        *dbp;
544          register GLubyte        *pbuf;
# Line 558 | Line 596 | xferdepth()                    /* load and clear depth buffer */
596          glClear(GL_DEPTH_BUFFER_BIT);           /* clear system depth buffer */
597          odDepthMap(0, depthbuffer);             /* transfer depth data */
598          if (pbuf != NULL)
599 <                free((char *)pbuf);             /* free our portal buffer */
599 >                free((void *)pbuf);             /* free our portal buffer */
600   }
601  
602  
603 < static
604 < freedepth()                             /* free recorded depth buffer */
603 > static void
604 > freedepth(void)                         /* free recorded depth buffer */
605   {
606          if (depthbuffer == NULL)
607                  return;
608   #ifdef STEREO
609          odDepthMap(1, NULL);
610 <        free((char *)depthright);
610 >        free((void *)depthright);
611          depthright = NULL;
612   #endif
613          odDepthMap(0, NULL);
614 <        free((char *)depthbuffer);
614 >        free((void *)depthbuffer);
615          depthbuffer = NULL;
616   }
617  
618  
619   static double
620 < getdistance(dx, dy, direc)      /* distance from fore plane along view ray */
621 < int     dx, dy;
622 < FVECT   direc;
620 > getdistance(    /* distance from fore plane along view ray */
621 >        int     dx,
622 >        int     dy,
623 >        FVECT   direc
624 > )
625   {
626          GLfloat gldepth;
627          double  dist;
628  
629 <        if (dx<0 | dx>=odev.hres | dy<0 | dy>=odev.vres)
629 >        if ((dx<0) | (dx>=odev.hres) | (dy<0) | (dy>=odev.vres))
630                  return(FHUGE);
631          if (depthbuffer != NULL)
632                  dist = depthbuffer[dy*odev.hres + dx];
633          else {
634                  glReadPixels(dx,dy, 1,1, GL_DEPTH_COMPONENT,
635                                  GL_FLOAT, &gldepth);
636 +                if (gldepth <= FTINY)
637 +                        return (FHUGE); /* call failed */
638                  dist = mapdepth(gldepth);
639          }
640          if (dist >= .99*FHUGE)
# Line 602 | Line 644 | FVECT  direc;
644  
645  
646   #ifdef STEREO
647 < static
648 < pushright()                     /* push on right view & buffer */
647 > static void
648 > pushright(void)                 /* push on right view & buffer */
649   {
650          double  d;
651  
# Line 619 | Line 661 | pushright()                    /* push on right view & buffer */
661   }
662  
663  
664 < static
665 < popright()                      /* pop off right view & buffer */
664 > static void
665 > popright(void)                  /* pop off right view & buffer */
666   {
667          if (viewflags & VWPERSP) {
668                  glMatrixMode(GL_MODELVIEW);
# Line 632 | Line 674 | popright()                     /* pop off right view & buffer */
674  
675  
676   static int
677 < mytmflags()                     /* figure out tone mapping flags */
677 > mytmflags(void)                 /* figure out tone mapping flags */
678   {
679          extern char     *progname;
680          register char   *cp, *tail;
# Line 656 | Line 698 | mytmflags()                    /* figure out tone mapping flags */
698   }
699  
700  
701 < static
702 < getevent()                      /* get next event */
701 > static void
702 > getevent(void)                  /* get next event */
703   {
704          XNextEvent(ourdisplay, levptr(XEvent));
705          switch (levptr(XEvent)->type) {
# Line 687 | Line 729 | getevent()                     /* get next event */
729   }
730  
731  
732 < static
733 < draw3dline(wp)                  /* draw 3d line in world coordinates */
734 < register FVECT  wp[2];
732 > static void
733 > draw3dline(                     /* draw 3d line in world coordinates */
734 >        register FVECT  wp[2]
735 > )
736   {
737          glVertex3d(wp[0][0], wp[0][1], wp[0][2]);
738          glVertex3d(wp[1][0], wp[1][1], wp[1][2]);
739   }
740  
741  
742 < static
743 < draw_grids(fore)                /* draw holodeck section grids */
744 < int     fore;
742 > static void
743 > draw_grids(             /* draw holodeck section grids */
744 >        int     fore
745 > )
746   {
747          glPushAttrib(GL_LIGHTING_BIT|GL_ENABLE_BIT);
748          glDisable(GL_LIGHTING);
# Line 714 | Line 758 | int    fore;
758   }
759  
760  
761 < static
762 < moveview(dx, dy, mov, orb)      /* move our view */
763 < int     dx, dy, mov, orb;
761 > static int
762 > moveview(       /* move our view */
763 >        int     dx,
764 >        int     dy,
765 >        int     mov,
766 >        int     orb
767 > )
768   {
769          VIEW    nv;
770          FVECT   odir, v1, wip;
771          double  d, d1;
724        register int    li;
772                                  /* start with old view */
773 <        copystruct(&nv, &odev.v);
773 >        nv = odev.v;
774                                  /* orient our motion */
775          if (viewray(v1, odir, &odev.v,
776                          (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
# Line 769 | Line 816 | int    dx, dy, mov, orb;
816   }
817  
818  
819 < static
820 < getframe(ebut)                          /* get focus frame */
821 < XButtonPressedEvent     *ebut;
819 > static void
820 > getframe(                               /* get focus frame */
821 >        XButtonPressedEvent     *ebut
822 > )
823   {
824          int     startx = ebut->x, starty = ebut->y;
825 <        int     endx, endy;
826 <
825 >        int     endx, endy, midx, midy;
826 >        FVECT   odir, v1;
827 >        double  d, d1;
828 >                                                /* get mouse drag */
829          XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent));
830          endx = levptr(XButtonReleasedEvent)->x;
831          endy = levptr(XButtonReleasedEvent)->y;
832 <        if (endx == startx | endy == starty) {
833 <                XBell(ourdisplay, 0);
832 >        midx = (startx + endx) >> 1;
833 >        midy = (starty + endy) >> 1;
834 >                                                /* set focus distance */
835 >        if (viewray(v1, odir, &odev.v,
836 >                        (midx+.5)/odev.hres, (midy+.5)/odev.vres) < -FTINY)
837                  return;
838 <        }
838 >        d = getdistance(midx, midy, odir);      /* distance from front plane */
839 > #ifdef DOBJ
840 >        d1 = dobj_trace(NULL, v1, odir);
841 >        if (d1 < d)
842 >                d = d1;
843 > #endif
844 >        if (d < .99*FHUGE)
845 >                odev.v.vdist = d + sqrt(dist2(v1, odev.v.vp));
846 >                                                /* set frame for rendering */
847 >        if ((endx == startx) | (endy == starty))
848 >                return;
849          if (endx < startx) {register int c = endx; endx = startx; startx = c;}
850          if (endy < starty) {register int c = endy; endy = starty; starty = c;}
851          sprintf(odev_args, "%.3f %.3f %.3f %.3f",
# Line 792 | Line 855 | XButtonPressedEvent    *ebut;
855   }
856  
857  
858 < static
859 < getmove(ebut)                           /* get view change */
797 < XButtonPressedEvent     *ebut;
858 > static void
859 > waitabit(void)                          /* pause a moment */
860   {
861 +        struct timespec ts;
862 +        ts.tv_sec = 0;
863 +        ts.tv_nsec = 100000000L;
864 +        nanosleep(&ts, NULL);
865 + }
866 +
867 +
868 + static void
869 + getmove(                                /* get view change */
870 +        XButtonPressedEvent     *ebut
871 + )
872 + {
873          int     movdir = MOVDIR(ebut->button);
874          int     movorb = MOVORB(ebut->state);
875          int     ndrawn;
# Line 809 | Line 883 | XButtonPressedEvent    *ebut;
883          setglpersp();                   /* start us off in perspective */
884          while (!XCheckMaskEvent(ourdisplay,
885                          ButtonReleaseMask, levptr(XEvent))) {
886 +                                        /* pause so as not to move too fast */
887 +                waitabit();
888                                          /* get cursor position */
889                  if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
890                                  &rootx, &rooty, &wx, &wy, &statemask))
# Line 847 | Line 923 | XButtonPressedEvent    *ebut;
923   }
924  
925  
926 < static
927 < setglpersp()                    /* set perspective view in GL */
926 > static void
927 > setglpersp(void)                        /* set perspective view in GL */
928   {
929          double  d, xmin, xmax, ymin, ymax;
930          GLfloat vec[4];
# Line 868 | Line 944 | setglpersp()                   /* set perspective view in GL */
944                  dev_zmin = odev.v.vfore;
945          if (odev.v.vaft > FTINY)
946                  dev_zmax = odev.v.vaft;
947 <        if (dev_zmin < dev_zmax/100.)
948 <                dev_zmin = dev_zmax/100.;
947 >        if (dev_zmin*500. < dev_zmax)
948 >                dev_zmin = dev_zmax/500.;
949          setzrat();
950          xmax = dev_zmin * tan(PI/180./2. * odev.v.horiz);
951          xmin = -xmax;
# Line 909 | Line 985 | setglpersp()                   /* set perspective view in GL */
985   }
986  
987  
988 < static
989 < setglortho()                    /* set up orthographic view for cone drawing */
988 > static void
989 > setglortho(void)                        /* set up orthographic view for cone drawing */
990   {
991          glDrawBuffer(GL_FRONT);         /* use single-buffer mode */
992                                          /* set view matrix */
# Line 926 | Line 1002 | setglortho()                   /* set up orthographic view for cone dr
1002   }
1003  
1004  
1005 < static
1006 < wipeclean()                     /* prepare for redraw */
1005 > static void
1006 > wipeclean(void)                 /* prepare for redraw */
1007   {
1008          glDrawBuffer(GL_BACK);          /* use double-buffer mode */
1009          glReadBuffer(GL_BACK);
# Line 945 | Line 1021 | wipeclean()                    /* prepare for redraw */
1021                  viewflags &= ~VWCHANGE;         /* change noted */
1022          } else if (viewflags & VWSTEADY)
1023                  odRedrawAll();
1024 <        setglpersp(&odev.v);            /* reset view & clipping planes */
1024 >        setglpersp();                   /* reset view & clipping planes */
1025   }
1026  
1027  
1028 < static
1029 < getkey(ekey)                            /* get input key */
1030 < register XKeyPressedEvent  *ekey;
1028 > static void
1029 > getkey(                         /* get input key */
1030 >        register XKeyPressedEvent  *ekey
1031 > )
1032   {
1033          Window  rootw, childw;
1034          int     rootx, rooty, wx, wy;
# Line 1032 | Line 1109 | register XKeyPressedEvent  *ekey;
1109   }
1110  
1111  
1112 < static
1113 < fixwindow(eexp)                         /* repair damage to window */
1114 < register XExposeEvent  *eexp;
1112 > static void
1113 > fixwindow(                              /* repair damage to window */
1114 >        register XExposeEvent  *eexp
1115 > )
1116   {
1117          int     xmin, ymin, xmax, ymax;
1118  
1119 <        if (odev.hres == 0 | odev.vres == 0) {  /* first exposure */
1119 >        if ((odev.hres == 0) | (odev.vres == 0)) {      /* first exposure */
1120                  resizewindow((XConfigureEvent *)eexp);
1121                  return;
1122          }
# Line 1077 | Line 1155 | register XExposeEvent  *eexp;
1155   }
1156  
1157  
1158 < static
1159 < resizewindow(ersz)                      /* resize window */
1160 < register XConfigureEvent  *ersz;
1158 > static void
1159 > resizewindow(                   /* resize window */
1160 >        register XConfigureEvent  *ersz
1161 > )
1162   {
1163          glViewport(0, 0, ersz->width, ersz->height);
1164  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines