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.8 by gwlarson, Tue Dec 22 10:18:44 1998 UTC vs.
Revision 3.34 by greg, Fri Feb 12 00:53:56 2021 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 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 37 | Line 36 | static char SCCSid[] = "$SunId$ SGI";
36   #include "x11icon.h"
37  
38   #ifndef RAYQLEN
39 < #define RAYQLEN         50000           /* max. rays to queue before flush */
39 > #define RAYQLEN         0               /* max. rays to queue before flush */
40   #endif
41 <
42 <                        /* values other than 0 or 255 do not map reliably */
43 < #ifndef PORTALP
45 < #define PORTRED         0               /* -1, 0 or 255 */
46 < #define PORTGRN         -1              /* -1, 0 or 255 */
47 < #define PORTBLU         255             /* -1, 0 or 255 */
48 < #define PORTALP         -1              /* -1 or 255 */
41 > #ifndef MINWIDTH
42 > #define MINWIDTH        480             /* minimum graphics window width */
43 > #define MINHEIGHT       400             /* minimum graphics window height */
44   #endif
45 < #define isportal(c)     ((PORTRED<0 || (c)[0]==PORTRED) && \
46 <                                (PORTGRN<0 || (c)[1]==PORTGRN) && \
52 <                                (PORTBLU<0 || (c)[2]==PORTBLU) && \
53 <                                (PORTALP<0 || (c)[3]==PORTALP))
54 < #define doportals()     if (gmPortals) \
55 <                        gmDrawPortals(PORTRED,PORTGRN,PORTBLU,PORTALP); else
56 <
57 < #ifndef FEQ
58 < #define FEQ(a,b)        ((a)-(b) <= FTINY && (a)-(b) >= -FTINY)
45 > #ifndef VIEWDIST
46 > #define VIEWDIST        356             /* assumed viewing distance (mm) */
47   #endif
48 + #ifndef BORWIDTH
49 + #define BORWIDTH        5               /* border width */
50 + #endif
51  
52   #define VWHEADLOCK      01              /* head position is locked flag */
53   #define VWPERSP         02              /* perspective view is set */
# Line 74 | Line 65 | static char SCCSid[] = "$SunId$ SGI";
65   #define MOVDEG          (-5)            /* degrees to orbit CW/down /frame */
66   #define MOVORB(s)       ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
67  
77 #define MINWIDTH        480             /* minimum graphics window width */
78 #define MINHEIGHT       400             /* minimum graphics window height */
79
80 #define VIEWDIST        356             /* assumed viewing distance (mm) */
81
82 #define BORWIDTH        5               /* border width */
83
68   #define setstereobuf(bid)       (glXWaitGL(), \
69                                  XSGISetStereoBuffer(ourdisplay, gwind, bid), \
70                                  glXWaitX())
# Line 94 | Line 78 | static char SCCSid[] = "$SunId$ SGI";
78  
79   struct driver   odev;                   /* global device driver structure */
80  
81 + TMstruct        *tmGlobal;              /* global tone-mapping structure */
82 +
83   char odev_args[64];                     /* command arguments */
84  
85   static GLfloat  *depthbuffer = NULL;    /* depth buffer */
# Line 126 | Line 112 | static int     inpresflags;            /* input result flags */
112  
113   static int      viewflags;              /* what's happening with view */
114  
115 + /*
116   static int  resizewindow(), getevent(), getkey(), moveview(), wipeclean(),
117                  xferdepth(), freedepth(), setglortho(),
118                  setglpersp(), getframe(), getmove(), fixwindow(), mytmflags();
119  
120   static double   getdistance();
121 + */
122 + static void checkglerr(char *where);
123 + static void xferdepth(void);
124 + static void freedepth(void);
125 + static double getdistance(int dx, int dy, FVECT direc);
126 + static int mytmflags(void);
127 + static void getevent(void);
128 + static void draw3dline(FVECT wp[2]);
129 + static void draw_grids(int fore);
130 + static int moveview(int dx, int dy, int mov, int orb);
131 + static void getframe(XButtonPressedEvent *ebut);
132 + static void getmove(XButtonPressedEvent *ebut);
133 + static void getkey(XKeyPressedEvent *ekey);
134 + static void fixwindow(XExposeEvent *eexp);
135 + static void resizewindow(XConfigureEvent *ersz);
136 + static void waitabit(void);
137 + static void setglpersp(void);
138 + static void setglortho(void);
139 + static void wipeclean(void);
140  
141 +
142   #ifdef STEREO
143 < static int  pushright(), popright();
143 > static void pushright(void);
144 > static void popright(void);
145   #endif
146  
147   extern int      gmPortals;      /* GL portal list id */
# Line 141 | Line 149 | extern int     gmPortals;      /* GL portal list id */
149   extern time_t   time();
150  
151  
152 + void
153   dev_open(id)                    /* initialize GLX driver */
154   char  *id;
155   {
156          extern char     *getenv();
157          static RGBPRIMS myprims = STDPRIMS;
149 #if (PORTALP<0)
158          static int      atlBest[] = {GLX_RGBA, GLX_DOUBLEBUFFER,
159                                  GLX_RED_SIZE,8, GLX_GREEN_SIZE,8,
160                                  GLX_BLUE_SIZE,8, GLX_DEPTH_SIZE,15, None};
161          static int      atlOK[] = {GLX_RGBA, GLX_DOUBLEBUFFER,
162                                  GLX_RED_SIZE,4, GLX_GREEN_SIZE,4,
163                                  GLX_BLUE_SIZE,4, GLX_DEPTH_SIZE,15, None};
156 #else
157        static int      atlBest[] = {GLX_RGBA, GLX_DOUBLEBUFFER,
158                                GLX_RED_SIZE,8, GLX_GREEN_SIZE,8,
159                                GLX_BLUE_SIZE,8, GLX_ALPHA_SIZE,1,
160                                GLX_DEPTH_SIZE,15, None};
161        static int      atlOK[] = {GLX_RGBA, GLX_DOUBLEBUFFER,
162                                GLX_RED_SIZE,5, GLX_GREEN_SIZE,5,
163                                GLX_BLUE_SIZE,5, GLX_ALPHA_SIZE,1,
164                                GLX_DEPTH_SIZE,15, None};
165 #endif
164          char    *ev;
165          double  gamval = GAMMA;
166          RGBPRIMP        dpri = stdprims;
# Line 209 | Line 207 | char  *id;
207                                  &myprims[BLU][CIEX],&myprims[BLU][CIEY],
208                                  &myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6)
209                  dpri = myprims;
210 <        if (tmInit(mytmflags(), dpri, gamval) == NULL)
210 >        tmGlobal = tmInit(mytmflags(), dpri, gamval);
211 >        if (tmGlobal == NULL)
212                  error(SYSTEM, "not enough memory in dev_open");
213                                          /* open window */
214          ourwinattr.background_pixel = ourblack;
# Line 232 | Line 231 | char  *id;
231                                          /* set window manager hints */
232          ourxwmhints.flags = InputHint|IconPixmapHint;
233          ourxwmhints.input = True;
234 <        ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay,
235 <                        gwind, x11icon_bits, x11icon_width, x11icon_height);
234 >        ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, gwind,
235 >                        (char *)x11icon_bits, x11icon_width, x11icon_height);
236          XSetWMHints(ourdisplay, gwind, &ourxwmhints);
237          oursizhints.min_width = MINWIDTH;
238   #ifdef STEREO
# Line 251 | Line 250 | char  *id;
250          glXMakeCurrent(ourdisplay, gwind, gctx);
251          glEnable(GL_DEPTH_TEST);
252          glDepthFunc(GL_LEQUAL);
253 <        glEnable(GL_DITHER);
253 >        glClearColor(0, 0, 0, 0);
254          glFrontFace(GL_CCW);
255          glDisable(GL_CULL_FACE);
256          glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
257          glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
258 +        glPixelStorei(GL_PACK_ALIGNMENT, 1);
259 +        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
260                                          /* figure out sensible view */
261          pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
262                          DisplayWidth(ourdisplay, ourscreen);
# Line 266 | Line 267 | char  *id;
267          setstereobuf(STEREO_BUFFER_LEFT);
268   #endif
269          checkglerr("setting rendering parameters");
270 <        copystruct(&odev.v, &stdview);
270 >        odev.v = stdview;
271          odev.v.type = VT_PER;
272          viewflags = VWSTEADY;           /* view starts static */
273                                          /* map the window */
274          XMapWindow(ourdisplay, gwind);
275          dev_input();                    /* sets size and view angles */
276          if (!odInit(DisplayWidth(ourdisplay,ourscreen) *
277 <                        DisplayHeight(ourdisplay,ourscreen) / 4))
277 >                        DisplayHeight(ourdisplay,ourscreen) / 3))
278                  error(SYSTEM, "insufficient memory for value storage");
279          odev.name = id;
280          odev.firstuse = 1;              /* can't recycle samples */
# Line 281 | Line 282 | char  *id;
282   }
283  
284  
285 < dev_close()                     /* close our display and free resources */
285 > void
286 > dev_close(void)                 /* close our display and free resources */
287   {
288   #ifdef DOBJ
289          dobj_cleanup();
# Line 296 | Line 298 | dev_close()                    /* close our display and free resources
298          gwind = 0;
299          XCloseDisplay(ourdisplay);
300          ourdisplay = NULL;
301 <        tmDone(NULL);
301 >        tmDone(tmGlobal);
302          odev.v.type = 0;
303          odev.hres = odev.vres = 0;
304          odev.ifd = -1;
305   }
306  
307  
308 < dev_clear()                     /* clear our representation */
308 > void
309 > dev_clear(void)                 /* clear our representation */
310   {
311 <        wipeclean();
311 >        viewflags |= VWCHANGE;          /* pretend our view has changed */
312 >        wipeclean();                    /* clean off display and samples */
313 >        dev_flush();                    /* redraw geometry & get depth */
314          rayqleft = 0;                   /* hold off update */
315   }
316  
317  
318   int
319 < dev_view(nv)                    /* assign new driver view */
320 < register VIEW   *nv;
319 > dev_view(                       /* assign new driver view */
320 >        VIEW    *nv
321 > )
322   {
323 + #ifdef STEREO
324          double  d;
325 <
325 > #endif
326          if (nv->type != VT_PER ||               /* check view legality */
327                          nv->horiz > 160. || nv->vert > 160.) {
328                  error(COMMAND, "illegal view type/angle");
# Line 326 | Line 333 | register VIEW  *nv;
333          }
334          if (nv != &odev.v) {
335                                                  /* resize window? */
336 <                if (!FEQ(nv->horiz,odev.v.horiz) ||
337 <                                !FEQ(nv->vert,odev.v.vert)) {
336 >                if (!FABSEQ(nv->horiz,odev.v.horiz) ||
337 >                                !FABSEQ(nv->vert,odev.v.vert)) {
338                          int     dw = DisplayWidth(ourdisplay,ourscreen);
339                          int     dh = DisplayHeight(ourdisplay,ourscreen);
340  
# Line 351 | Line 358 | register VIEW  *nv;
358                          XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres);
359                          dev_input();    /* get resize event */
360                  }
361 <                copystruct(&odev.v, nv);        /* setview() already called */
355 < #ifdef STEREO
356 <                copystruct(&vwright, nv);
357 <                d = eyesepdist / sqrt(nv->hn2);
358 <                VSUM(vwright.vp, nv->vp, nv->hvec, d);
359 <                /* setview(&vwright);   -- Unnecessary */
360 < #endif
361 >                odev.v = *nv;   /* setview() already called */
362                  viewflags |= VWCHANGE;
363          }
364 + #ifdef STEREO
365 +        vwright = *nv;
366 +        d = eyesepdist / sqrt(nv->hn2);
367 +        VSUM(vwright.vp, nv->vp, nv->hvec, d);
368 +        /* setview(&vwright);   -- Unnecessary */
369 + #endif
370          wipeclean();
371          return(1);
372   }
373  
374  
375 < dev_section(gfn, pfn)           /* add octree for geometry rendering */
376 < char    *gfn, *pfn;
375 > void
376 > dev_section(            /* add octree for geometry rendering */
377 >        char    *gfn,
378 >        char    *pfn
379 > )
380   {
371        extern char     *index();
372        char    *cp;
373
381          if (gfn == NULL) {
382                  gmEndGeom();
383                  gmEndPortal();
# Line 390 | Line 397 | char   *gfn, *pfn;
397   }
398  
399  
400 < dev_auxcom(cmd, args)           /* process an auxiliary command */
401 < char    *cmd, *args;
400 > void
401 > dev_auxcom(             /* process an auxiliary command */
402 >        char    *cmd,
403 >        char    *args
404 > )
405   {
406   #ifdef DOBJ
407 <        if (dobj_command(cmd, args) >= 0)
407 >        int     vischange;
408 >
409 >        if ((vischange = dobj_command(cmd, args)) >= 0) {
410 >                if (vischange) {
411 >                        imm_mode = beam_sync(1) > 0;
412 >                        dev_clear();
413 >                }
414                  return;
415 +        }
416   #endif
417          sprintf(errmsg, "%s: unknown command", cmd);
418          error(COMMAND, errmsg);
# Line 403 | Line 420 | char   *cmd, *args;
420  
421  
422   VIEW *
423 < dev_auxview(n, hvres)           /* return nth auxiliary view */
424 < int     n;
425 < int     hvres[2];
423 > dev_auxview(            /* return nth auxiliary view */
424 >        int     n,
425 >        int     hvres[2]
426 > )
427   {
428          hvres[0] = odev.hres; hvres[1] = odev.vres;
429          if (n == 0)
# Line 419 | Line 437 | int    hvres[2];
437  
438  
439   int
440 < dev_input()                     /* get X11 input */
440 > dev_input(void)                 /* get X11 input */
441   {
442          inpresflags = 0;
443  
# Line 434 | Line 452 | dev_input()                    /* get X11 input */
452   }
453  
454  
455 < dev_value(c, d, p)              /* add a pixel value to our texture */
456 < COLR    c;
457 < FVECT   d, p;
455 > void
456 > dev_value(              /* add a pixel value to our texture */
457 >        COLR    c,
458 >        FVECT   d,
459 >        FVECT   p
460 > )
461   {
462   #ifdef DOBJ
463          if (dobj_lightsamp != NULL) {   /* in light source sampling */
# Line 451 | Line 472 | FVECT  d, p;
472  
473  
474   int
475 < dev_flush()                     /* flush output as appropriate */
475 > dev_flush(void)                 /* flush output as appropriate */
476   {
477          int     ndrawn;
478  
# Line 462 | Line 483 | dev_flush()                    /* flush output as appropriate */
483   #ifdef DOBJ
484                  ndrawn += dobj_render();
485   #endif
465                if (ndrawn)
466                        doportals();
486                  checkglerr("rendering right eye");
487                  popright();                     /* draw left eye */
488   #endif
# Line 471 | Line 490 | dev_flush()                    /* flush output as appropriate */
490   #ifdef DOBJ
491                  ndrawn += dobj_render();
492   #endif
474                if (ndrawn)
475                        doportals();
493                  glXSwapBuffers(ourdisplay, gwind);
494                  checkglerr("rendering base view");
495          }
# Line 501 | Line 518 | dev_flush()                    /* flush output as appropriate */
518   }
519  
520  
521 < checkglerr(where)               /* check for GL or GLU error */
522 < char    *where;
521 > static void
522 > checkglerr(             /* check for GL or GLU error */
523 >        char    *where
524 > )
525   {
526 <        register GLenum errcode;
526 >        GLenum  errcode;
527  
528          while ((errcode = glGetError()) != GL_NO_ERROR) {
529                  sprintf(errmsg, "OpenGL error %s: %s",
# Line 514 | Line 533 | char   *where;
533   }
534  
535  
536 < static
537 < xferdepth()                     /* load and clear depth buffer */
536 > static void
537 > xferdepth(void)                 /* load and clear depth buffer */
538   {
539 <        register GLfloat        *dbp;
540 <        register GLubyte        *cbuf;
539 >        GLfloat *dbp;
540 >        GLubyte *pbuf;
541  
542          if (depthbuffer == NULL) {      /* allocate private depth buffer */
543   #ifdef STEREO
# Line 531 | Line 550 | xferdepth()                    /* load and clear depth buffer */
550          }
551                                  /* allocate alpha buffer for portals */
552          if (gmPortals)
553 <                cbuf = (GLubyte *)malloc(odev.hres*odev.vres *
535 <                                                        (4*sizeof(GLubyte)));
553 >                pbuf = (GLubyte *)malloc(odev.hres*odev.vres*sizeof(GLubyte));
554          else
555 <                cbuf = NULL;
555 >                pbuf = NULL;
556   #ifdef STEREO
557 <        setstereobuf(STEREO_BUFFER_RIGHT);
557 >        pushright();
558          glReadPixels(0, 0, odev.hres, odev.vres,
559                          GL_DEPTH_COMPONENT, GL_FLOAT, depthright);
560 <        if (cbuf != NULL)
560 >        if (pbuf != NULL) {
561 >                glClear(GL_COLOR_BUFFER_BIT);
562 >                gmDrawPortals(0xff, -1, -1, -1);
563                  glReadPixels(0, 0, odev.hres, odev.vres,
564 <                                GL_RGBA, GL_UNSIGNED_BYTE, cbuf);
564 >                                GL_RED, GL_UNSIGNED_BYTE, pbuf);
565 >        }
566          for (dbp = depthright + odev.hres*odev.vres; dbp-- > depthright; )
567 <                if (cbuf != NULL && isportal(cbuf+4*(dbp-depthright)))
567 >                if (pbuf != NULL && pbuf[dbp-depthright]&0x40)
568                          *dbp = FHUGE;
569                  else
570                          *dbp = mapdepth(*dbp);
571          glClear(GL_DEPTH_BUFFER_BIT);
551        setstereobuf(STEREO_BUFFER_LEFT);
572          odDepthMap(1, depthright);
573 +        popright();
574   #endif
575                                  /* read back depth buffer */
576          glReadPixels(0, 0, odev.hres, odev.vres,
577                          GL_DEPTH_COMPONENT, GL_FLOAT, depthbuffer);
578 <        if (cbuf != NULL)
578 >        if (pbuf != NULL) {
579 >                glClear(GL_COLOR_BUFFER_BIT);           /* find portals */
580 >                gmDrawPortals(0xff, -1, -1, -1);
581                  glReadPixels(0, 0, odev.hres, odev.vres,
582 <                                GL_RGBA, GL_UNSIGNED_BYTE, cbuf);
582 >                                GL_RED, GL_UNSIGNED_BYTE, pbuf);
583 > #ifdef DEBUG
584 >                glXSwapBuffers(ourdisplay, gwind);
585 > #endif
586 >        }
587          for (dbp = depthbuffer + odev.hres*odev.vres; dbp-- > depthbuffer; )
588 <                if (cbuf != NULL && isportal(cbuf+4*(dbp-depthbuffer)))
588 >                if (pbuf != NULL && pbuf[dbp-depthbuffer]&0x40)
589                          *dbp = FHUGE;
590                  else
591                          *dbp = mapdepth(*dbp);
592          glClear(GL_DEPTH_BUFFER_BIT);           /* clear system depth buffer */
566        if (cbuf != NULL)
567                free((char *)cbuf);             /* free our color buffer */
593          odDepthMap(0, depthbuffer);             /* transfer depth data */
594 +        if (pbuf != NULL)
595 +                free((void *)pbuf);             /* free our portal buffer */
596   }
597  
598  
599 < static
600 < freedepth()                             /* free recorded depth buffer */
599 > static void
600 > freedepth(void)                         /* free recorded depth buffer */
601   {
602          if (depthbuffer == NULL)
603                  return;
604   #ifdef STEREO
605          odDepthMap(1, NULL);
606 <        free((char *)depthright);
606 >        free((void *)depthright);
607          depthright = NULL;
608   #endif
609          odDepthMap(0, NULL);
610 <        free((char *)depthbuffer);
610 >        free((void *)depthbuffer);
611          depthbuffer = NULL;
612   }
613  
614  
615   static double
616 < getdistance(dx, dy, direc)      /* distance from fore plane along view ray */
617 < int     dx, dy;
618 < FVECT   direc;
616 > getdistance(    /* distance from fore plane along view ray */
617 >        int     dx,
618 >        int     dy,
619 >        FVECT   direc
620 > )
621   {
622          GLfloat gldepth;
594        GLubyte glcolor[4];
623          double  dist;
624  
625 <        if (dx<0 | dx>=odev.hres | dy<0 | dy>=odev.vres)
625 >        if ((dx<0) | (dx>=odev.hres) | (dy<0) | (dy>=odev.vres))
626                  return(FHUGE);
627          if (depthbuffer != NULL)
628                  dist = depthbuffer[dy*odev.hres + dx];
629          else {
630                  glReadPixels(dx,dy, 1,1, GL_DEPTH_COMPONENT,
631                                  GL_FLOAT, &gldepth);
632 <                if (gmPortals) {
633 <                        glReadPixels(dx,dy, 1,1, GL_RGBA,
606 <                                        GL_UNSIGNED_BYTE, glcolor);
607 <                        if (isportal(glcolor))
608 <                                return(FHUGE);
609 <                }
632 >                if (gldepth <= FTINY)
633 >                        return (FHUGE); /* call failed */
634                  dist = mapdepth(gldepth);
635          }
636          if (dist >= .99*FHUGE)
# Line 616 | Line 640 | FVECT  direc;
640  
641  
642   #ifdef STEREO
643 < static
644 < pushright()                     /* push on right view & buffer */
643 > static void
644 > pushright(void)                 /* push on right view & buffer */
645   {
646          double  d;
647  
# Line 633 | Line 657 | pushright()                    /* push on right view & buffer */
657   }
658  
659  
660 < static
661 < popright()                      /* pop off right view & buffer */
660 > static void
661 > popright(void)                  /* pop off right view & buffer */
662   {
663          if (viewflags & VWPERSP) {
664                  glMatrixMode(GL_MODELVIEW);
# Line 646 | Line 670 | popright()                     /* pop off right view & buffer */
670  
671  
672   static int
673 < mytmflags()                     /* figure out tone mapping flags */
673 > mytmflags(void)                 /* figure out tone mapping flags */
674   {
675          extern char     *progname;
676 <        register char   *cp, *tail;
676 >        char    *cp, *tail;
677                                          /* find basic name */
678          for (cp = tail = progname; *cp; cp++)
679                  if (*cp == '/')
# Line 670 | Line 694 | mytmflags()                    /* figure out tone mapping flags */
694   }
695  
696  
697 < static
698 < getevent()                      /* get next event */
697 > static void
698 > getevent(void)                  /* get next event */
699   {
700          XNextEvent(ourdisplay, levptr(XEvent));
701          switch (levptr(XEvent)->type) {
# Line 692 | Line 716 | getevent()                     /* get next event */
716                  getkey(levptr(XKeyPressedEvent));
717                  break;
718          case ButtonPress:
719 <                if (FRAMESTATE(levptr(XButtonPressedEvent)->state))
720 <                        getframe(levptr(XButtonPressedEvent));
719 >                if (FRAMESTATE(levptr(XButtonPressedEvent)->state))
720 >                        getframe(levptr(XButtonPressedEvent));
721                  else
722 <                        getmove(levptr(XButtonPressedEvent));
722 >                        switch (levptr(XButtonPressedEvent)->button) {
723 >                        case Button4:           /* wheel up */
724 >                        case Button5:           /* wheel down */
725 >                                break;
726 >                        default:
727 >                                getmove(levptr(XButtonPressedEvent));
728 >                                break;
729 >                        }
730                  break;
731          }
732   }
733  
734  
735 < static
736 < draw3dline(wp)                  /* draw 3d line in world coordinates */
737 < register FVECT  wp[2];
735 > static void
736 > draw3dline(                     /* draw 3d line in world coordinates */
737 >        FVECT   wp[2]
738 > )
739   {
740          glVertex3d(wp[0][0], wp[0][1], wp[0][2]);
741          glVertex3d(wp[1][0], wp[1][1], wp[1][2]);
742   }
743  
744  
745 < static
746 < draw_grids(fore)                /* draw holodeck section grids */
747 < int     fore;
745 > static void
746 > draw_grids(             /* draw holodeck section grids */
747 >        int     fore
748 > )
749   {
750          glPushAttrib(GL_LIGHTING_BIT|GL_ENABLE_BIT);
751          glDisable(GL_LIGHTING);
# Line 728 | Line 761 | int    fore;
761   }
762  
763  
764 < static
765 < moveview(dx, dy, mov, orb)      /* move our view */
766 < int     dx, dy, mov, orb;
764 > static int
765 > moveview(       /* move our view */
766 >        int     dx,
767 >        int     dy,
768 >        int     mov,
769 >        int     orb
770 > )
771   {
772          VIEW    nv;
773          FVECT   odir, v1, wip;
774 <        double  d, d1;
775 <        register int    li;
774 >        double  d;
775 > #ifdef DOBJ
776 >        double d1;
777 > #endif
778                                  /* start with old view */
779 <        copystruct(&nv, &odev.v);
779 >        nv = odev.v;
780                                  /* orient our motion */
781          if (viewray(v1, odir, &odev.v,
782                          (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
# Line 760 | Line 799 | int    dx, dy, mov, orb;
799                  VSUM(nv.vp, wip, odir, -1.);
800                  spinvector(nv.vdir, nv.vdir, nv.vup, d);
801          } else if (orb) {               /* orbit up/down */
802 <                fcross(v1, odir, nv.vup);
803 <                if (normalize(v1) == 0.)
802 >                if (geodesic(odir, odir, nv.vup,
803 >                                d=MOVDEG*PI/180.*orb, GEOD_RAD) == 0.0)
804                          return(0);
766                spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb);
805                  VSUM(nv.vp, wip, odir, -1.);
806 <                spinvector(nv.vdir, nv.vdir, v1, d);
806 >                geodesic(nv.vdir, nv.vdir, nv.vup, d, GEOD_RAD);
807          } else if (mov) {               /* move forward/backward */
808                  d = MOVPCT/100. * mov;
809                  VSUM(nv.vp, nv.vp, odir, d);
# Line 783 | Line 821 | int    dx, dy, mov, orb;
821   }
822  
823  
824 < static
825 < getframe(ebut)                          /* get focus frame */
826 < XButtonPressedEvent     *ebut;
824 > static void
825 > getframe(                               /* get focus frame */
826 >        XButtonPressedEvent     *ebut
827 > )
828   {
829          int     startx = ebut->x, starty = ebut->y;
830 <        int     endx, endy;
831 <
830 >        int     endx, endy, midx, midy;
831 >        FVECT   odir, v1;
832 >        double  d;
833 > #ifdef DOBJ
834 >        double d1;
835 > #endif
836 >                                                /* get mouse drag */
837          XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent));
838          endx = levptr(XButtonReleasedEvent)->x;
839          endy = levptr(XButtonReleasedEvent)->y;
840 <        if (endx == startx | endy == starty) {
841 <                XBell(ourdisplay, 0);
840 >        midx = (startx + endx) >> 1;
841 >        midy = (starty + endy) >> 1;
842 >                                                /* set focus distance */
843 >        if (viewray(v1, odir, &odev.v,
844 >                        (midx+.5)/odev.hres, (midy+.5)/odev.vres) < -FTINY)
845                  return;
846 <        }
847 <        if (endx < startx) {register int c = endx; endx = startx; startx = c;}
848 <        if (endy < starty) {register int c = endy; endy = starty; starty = c;}
846 >        d = getdistance(midx, midy, odir);      /* distance from front plane */
847 > #ifdef DOBJ
848 >        d1 = dobj_trace(NULL, v1, odir);
849 >        if (d1 < d)
850 >                d = d1;
851 > #endif
852 >        if (d < .99*FHUGE)
853 >                odev.v.vdist = d + sqrt(dist2(v1, odev.v.vp));
854 >                                                /* set frame for rendering */
855 >        if ((endx == startx) | (endy == starty))
856 >                return;
857 >        if (endx < startx) {int c = endx; endx = startx; startx = c;}
858 >        if (endy < starty) {int c = endy; endy = starty; starty = c;}
859          sprintf(odev_args, "%.3f %.3f %.3f %.3f",
860                          (startx+.5)/odev.hres, 1.-(endy+.5)/odev.vres,
861                          (endx+.5)/odev.hres, 1.-(starty+.5)/odev.vres);
# Line 806 | Line 863 | XButtonPressedEvent    *ebut;
863   }
864  
865  
866 < static
867 < getmove(ebut)                           /* get view change */
811 < XButtonPressedEvent     *ebut;
866 > static void
867 > waitabit(void)                          /* pause a moment */
868   {
869 +        struct timespec ts;
870 +        ts.tv_sec = 0;
871 +        ts.tv_nsec = 100000000L;
872 +        nanosleep(&ts, NULL);
873 + }
874 +
875 +
876 + static void
877 + getmove(                                /* get view change */
878 +        XButtonPressedEvent     *ebut
879 + )
880 + {
881          int     movdir = MOVDIR(ebut->button);
882          int     movorb = MOVORB(ebut->state);
883          int     ndrawn;
# Line 820 | Line 888 | XButtonPressedEvent    *ebut;
888          XNoOp(ourdisplay);              /* makes sure we're not idle */
889  
890          viewflags &= ~VWSTEADY;         /* flag moving view */
891 <        setglpersp(&odev.v);            /* start us off in perspective */
891 >        setglpersp();                   /* start us off in perspective */
892          while (!XCheckMaskEvent(ourdisplay,
893                          ButtonReleaseMask, levptr(XEvent))) {
894 +                                        /* pause so as not to move too fast */
895 +                waitabit();
896                                          /* get cursor position */
897                  if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
898                                  &rootx, &rooty, &wx, &wy, &statemask))
# Line 840 | Line 910 | XButtonPressedEvent    *ebut;
910   #ifdef DOBJ
911                  ndrawn += dobj_render();
912   #endif
843                if (ndrawn)
844                        doportals();
913                  popright();
914   #endif
915                                          /* redraw octrees */
# Line 849 | Line 917 | XButtonPressedEvent    *ebut;
917   #ifdef DOBJ
918                  ndrawn += dobj_render();        /* redraw objects */
919   #endif
852                if (ndrawn)
853                        doportals();
920                  glXSwapBuffers(ourdisplay, gwind);
921                  if (!ndrawn)
922                          sleep(1);       /* for reasonable interaction */
# Line 865 | Line 931 | XButtonPressedEvent    *ebut;
931   }
932  
933  
934 < static
935 < setglpersp(vp)                  /* set perspective view in GL */
870 < register VIEW   *vp;
934 > static void
935 > setglpersp(void)                        /* set perspective view in GL */
936   {
937          double  d, xmin, xmax, ymin, ymax;
938          GLfloat vec[4];
# Line 879 | Line 944 | register VIEW  *vp;
944                  dev_zmax = 100.;
945          } else {
946                  dev_zmin = 0.5*depthlim[0];
947 <                dev_zmax = 1.75*depthlim[1];
947 >                dev_zmax = 1.25*depthlim[1];
948                  if (dev_zmin > dev_zmax/5.)
949                          dev_zmin = dev_zmax/5.;
950          }
# Line 887 | Line 952 | register VIEW  *vp;
952                  dev_zmin = odev.v.vfore;
953          if (odev.v.vaft > FTINY)
954                  dev_zmax = odev.v.vaft;
955 <        if (dev_zmin < dev_zmax/100.)
956 <                dev_zmin = dev_zmax/100.;
955 >        if (dev_zmin*500. < dev_zmax)
956 >                dev_zmin = dev_zmax/500.;
957          setzrat();
958          xmax = dev_zmin * tan(PI/180./2. * odev.v.horiz);
959          xmin = -xmax;
# Line 928 | Line 993 | register VIEW  *vp;
993   }
994  
995  
996 < static
997 < setglortho()                    /* set up orthographic view for cone drawing */
996 > static void
997 > setglortho(void)                        /* set up orthographic view for cone drawing */
998   {
999          glDrawBuffer(GL_FRONT);         /* use single-buffer mode */
1000                                          /* set view matrix */
# Line 945 | Line 1010 | setglortho()                   /* set up orthographic view for cone dr
1010   }
1011  
1012  
1013 < static
1014 < wipeclean()                     /* prepare for redraw */
1013 > static void
1014 > wipeclean(void)                 /* prepare for redraw */
1015   {
1016          glDrawBuffer(GL_BACK);          /* use double-buffer mode */
1017 <        glReadBuffer(GL_FRONT);         /* read back visible contents */
953 <        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1017 >        glReadBuffer(GL_BACK);
1018                                          /* clear buffers */
1019   #ifdef STEREO
1020          setstereobuf(STEREO_BUFFER_RIGHT);
# Line 958 | Line 1022 | wipeclean()                    /* prepare for redraw */
1022          setstereobuf(STEREO_BUFFER_LEFT);
1023   #endif
1024          glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
961        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
1025          freedepth();
1026          if ((viewflags&(VWCHANGE|VWSTEADY)) ==
1027                          (VWCHANGE|VWSTEADY)) {  /* clear samples if new */
1028                  odClean();
1029                  viewflags &= ~VWCHANGE;         /* change noted */
1030 <        }
1031 <        setglpersp(&odev.v);            /* reset view & clipping planes */
1030 >        } else if (viewflags & VWSTEADY)
1031 >                odRedrawAll();
1032 >        setglpersp();                   /* reset view & clipping planes */
1033   }
1034  
1035  
1036 < static
1037 < getkey(ekey)                            /* get input key */
1038 < register XKeyPressedEvent  *ekey;
1036 > static void
1037 > getkey(                         /* get input key */
1038 >        XKeyPressedEvent  *ekey
1039 > )
1040   {
1041          Window  rootw, childw;
1042          int     rootx, rooty, wx, wy;
# Line 1015 | Line 1080 | register XKeyPressedEvent  *ekey;
1080                  inpresflags |= DFL(DC_RESUME);
1081                  return;
1082          case CTRL('R'):                 /* redraw screen */
1083 <                odRemap(0);
1083 >                odRemap(0);                     /* new tone mapping */
1084                  glClear(GL_DEPTH_BUFFER_BIT);
1085   #ifdef STEREO
1086                  setstereobuf(STEREO_BUFFER_RIGHT);
# Line 1025 | Line 1090 | register XKeyPressedEvent  *ekey;
1090                  return;
1091          case CTRL('L'):                 /* refresh from server */
1092                  if (inpresflags & DFL(DC_REDRAW))
1093 <                        return;
1093 >                        return;                 /* already called */
1094                  XRaiseWindow(ourdisplay, gwind);
1095 <                XFlush(ourdisplay);
1096 <                sleep(1);
1097 <                wipeclean();                    /* fresh display */
1098 <                odRemap(1);                     /* fresh tone mapping */
1034 <                dev_flush();                    /* draw octrees */
1095 >                XFlush(ourdisplay);             /* raise up window */
1096 >                sleep(1);                       /* wait for restacking */
1097 >                dev_clear();                    /* clear buffer and samples */
1098 >                odRemap(1);                     /* start fresh histogram */
1099                  inpresflags |= DFL(DC_REDRAW);  /* resend values from server */
1036                rayqleft = 0;                   /* hold off update */
1100                  return;
1101          case 'K':                       /* kill rtrace process(es) */
1102                  inpresflags |= DFL(DC_KILL);
# Line 1054 | Line 1117 | register XKeyPressedEvent  *ekey;
1117   }
1118  
1119  
1120 < static
1121 < fixwindow(eexp)                         /* repair damage to window */
1122 < register XExposeEvent  *eexp;
1120 > static void
1121 > fixwindow(                              /* repair damage to window */
1122 >        XExposeEvent  *eexp
1123 > )
1124   {
1125          int     xmin, ymin, xmax, ymax;
1126  
1127 <        if (odev.hres == 0 | odev.vres == 0) {  /* first exposure */
1127 >        if ((odev.hres == 0) | (odev.vres == 0)) {      /* first exposure */
1128                  resizewindow((XConfigureEvent *)eexp);
1129                  return;
1130          }
1131          xmin = eexp->x; xmax = eexp->x + eexp->width;
1132          ymin = odev.vres - eexp->y - eexp->height; ymax = odev.vres - eexp->y;
1133 +
1134 +        if (xmin <= 0 && xmax >= odev.hres-1 &&
1135 +                        ymin <= 0 && ymax >= odev.vres) {
1136 +                DCHECK(eexp->count, WARNING, "multiple clear in fixwindow");
1137 +                wipeclean();                    /* make sure we're go */
1138 +                return;
1139 +        }
1140                                                  /* clear portion of depth */
1141          glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
1142          glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
# Line 1092 | Line 1163 | register XExposeEvent  *eexp;
1163   }
1164  
1165  
1166 < static
1167 < resizewindow(ersz)                      /* resize window */
1168 < register XConfigureEvent  *ersz;
1166 > static void
1167 > resizewindow(                   /* resize window */
1168 >        XConfigureEvent  *ersz
1169 > )
1170   {
1171          glViewport(0, 0, ersz->width, ersz->height);
1172  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines