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.5 by gwlarson, Mon Dec 21 15:31:49 1998 UTC vs.
Revision 3.24 by schorsch, Thu Jan 1 11:21:55 2004 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   #ifdef DOBJ
32   #include "rhdobj.h"
33   #endif
# Line 37 | Line 35 | static char SCCSid[] = "$SunId$ SGI";
35   #include "x11icon.h"
36  
37   #ifndef RAYQLEN
38 < #define RAYQLEN         10240           /* max. rays to queue before flush */
38 > #define RAYQLEN         0               /* max. rays to queue before flush */
39   #endif
40 <
41 < #ifndef PORTALP
42 < #define PORTRED         2               /* portal red color */
45 < #define PORTGRN         -1              /* portal green left alone */
46 < #define PORTBLU         128             /* portal blue color */
47 < #define PORTALP         -1              /* don't use alpha channel */
40 > #ifndef MINWIDTH
41 > #define MINWIDTH        480             /* minimum graphics window width */
42 > #define MINHEIGHT       400             /* minimum graphics window height */
43   #endif
44 < #define isportal(c)     ((PORTRED<0 || (c)[0]==PORTRED) && \
45 <                                (PORTGRN<0 || (c)[1]==PORTGRN) && \
46 <                                (PORTBLU<0 || (c)[2]==PORTBLU) && \
47 <                                (PORTALP<0 || (c)[3]==PORTALP))
44 > #ifndef VIEWDIST
45 > #define VIEWDIST        356             /* assumed viewing distance (mm) */
46 > #endif
47 > #ifndef BORWIDTH
48 > #define BORWIDTH        5               /* border width */
49 > #endif
50  
51   #ifndef FEQ
52   #define FEQ(a,b)        ((a)-(b) <= FTINY && (a)-(b) >= -FTINY)
53   #endif
54  
55 + #define VWHEADLOCK      01              /* head position is locked flag */
56 + #define VWPERSP         02              /* perspective view is set */
57 + #define VWORTHO         04              /* orthographic view is set */
58 + #define VWCHANGE        010             /* view has changed */
59 + #define VWSTEADY        020             /* view is now steady */
60 + #define VWMAPPED        040             /* window is mapped */
61 +
62   #define GAMMA           1.4             /* default gamma correction */
63  
64   #define FRAMESTATE(s)   (((s)&(ShiftMask|ControlMask))==(ShiftMask|ControlMask))
# Line 64 | Line 68 | static char SCCSid[] = "$SunId$ SGI";
68   #define MOVDEG          (-5)            /* degrees to orbit CW/down /frame */
69   #define MOVORB(s)       ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
70  
67 #define MINWIDTH        480             /* minimum graphics window width */
68 #define MINHEIGHT       400             /* minimum graphics window height */
69
70 #define VIEWDIST        356             /* assumed viewing distance (mm) */
71
72 #define BORWIDTH        5               /* border width */
73
71   #define setstereobuf(bid)       (glXWaitGL(), \
72                                  XSGISetStereoBuffer(ourdisplay, gwind, bid), \
73                                  glXWaitX())
# Line 97 | Line 94 | static int     rayqleft = 0;           /* rays left to queue before
94  
95   static XEvent  currentevent;            /* current event */
96  
100 static int  mapped = 0;                 /* window is mapped? */
97   static unsigned long  ourblack=0, ourwhite=~0;
98  
99   static Display  *ourdisplay = NULL;     /* our display */
# Line 115 | Line 111 | static double  dev_zrat;               /* (1. - dev_zmin/dev_zmax) *
111  
112   static int      inpresflags;            /* input result flags */
113  
114 < static int      headlocked;             /* lock vertical motion */
114 > static int      viewflags;              /* what's happening with view */
115  
116 < static int      isperspective;          /* perspective/ortho view */
121 <
122 < static int      viewsteady;             /* is view steady? */
123 <
116 > /*
117   static int  resizewindow(), getevent(), getkey(), moveview(), wipeclean(),
118                  xferdepth(), freedepth(), setglortho(),
119                  setglpersp(), getframe(), getmove(), fixwindow(), mytmflags();
120  
121   static double   getdistance();
122 + */
123 + static void checkglerr(char *where);
124 + static void xferdepth(void);
125 + static void freedepth(void);
126 + static double getdistance(int dx, int dy, FVECT direc);
127 + static int mytmflags(void);
128 + static void getevent(void);
129 + static void draw3dline(register FVECT wp[2]);
130 + static void draw_grids(int fore);
131 + static int moveview(int dx, int dy, int mov, int orb);
132 + static void getframe(XButtonPressedEvent *ebut);
133 + static void getmove(XButtonPressedEvent *ebut);
134 + static void getkey(register XKeyPressedEvent *ekey);
135 + static void fixwindow(register XExposeEvent *eexp);
136 + static void resizewindow(register XConfigureEvent *ersz);
137 + static void waitabit(void);
138 + static void setglpersp(void);
139 + static void setglortho(void);
140 + static void wipeclean(void);
141  
142 +
143   #ifdef STEREO
144 < static int  pushright(), popright();
144 > static void pushright(void);
145 > static void popright(void);
146   #endif
147  
148   extern int      gmPortals;      /* GL portal list id */
# Line 136 | Line 150 | extern int     gmPortals;      /* GL portal list id */
150   extern time_t   time();
151  
152  
153 + extern void
154   dev_open(id)                    /* initialize GLX driver */
155   char  *id;
156   {
157          extern char     *getenv();
158          static RGBPRIMS myprims = STDPRIMS;
159 < #if (PORTALP<0)
160 <        static int      atlBest[] = {GLX_RGBA, GLX_RED_SIZE,8,
161 <                                GLX_GREEN_SIZE,8, GLX_BLUE_SIZE,8,
162 <                                GLX_DEPTH_SIZE,15, None};
163 < #else
164 <        static int      atlBest[] = {GLX_RGBA, GLX_RED_SIZE,8,
150 <                                GLX_GREEN_SIZE,8, GLX_BLUE_SIZE,8,
151 <                                GLX_ALPHA_SIZE,2, GLX_DEPTH_SIZE,15, None};
152 < #endif
159 >        static int      atlBest[] = {GLX_RGBA, GLX_DOUBLEBUFFER,
160 >                                GLX_RED_SIZE,8, GLX_GREEN_SIZE,8,
161 >                                GLX_BLUE_SIZE,8, GLX_DEPTH_SIZE,15, None};
162 >        static int      atlOK[] = {GLX_RGBA, GLX_DOUBLEBUFFER,
163 >                                GLX_RED_SIZE,4, GLX_GREEN_SIZE,4,
164 >                                GLX_BLUE_SIZE,4, GLX_DEPTH_SIZE,15, None};
165          char    *ev;
166          double  gamval = GAMMA;
167          RGBPRIMP        dpri = stdprims;
# Line 180 | Line 192 | char  *id;
192   #endif
193                                          /* find a usable visual */
194          ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlBest);
195 +        if (ourvinf == NULL)
196 +                ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlOK);
197          CHECK(ourvinf==NULL, USER, "no suitable visuals available");
198                                          /* get a context */
199          gctx = glXCreateContext(ourdisplay, ourvinf, NULL, GL_TRUE);
# Line 236 | Line 250 | char  *id;
250          glXMakeCurrent(ourdisplay, gwind, gctx);
251          glEnable(GL_DEPTH_TEST);
252          glDepthFunc(GL_LEQUAL);
253 <        glDisable(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 251 | 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 <        headlocked = 0;                 /* free up head movement */
257 <        viewsteady = 1;                 /* view starts static */
258 <        isperspective = -1;             /* but no view set, yet */
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 268 | Line 282 | char  *id;
282   }
283  
284  
285 < dev_close()                     /* close our display and free resources */
285 > extern void
286 > dev_close(void)                 /* close our display and free resources */
287   {
288   #ifdef DOBJ
289          dobj_cleanup();
# Line 290 | Line 305 | dev_close()                    /* close our display and free resources
305   }
306  
307  
308 < dev_clear()                     /* clear our representation */
308 > extern 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;
318 > extern int
319 > dev_view(                       /* assign new driver view */
320 >        register VIEW   *nv
321 > )
322   {
304        double  d;
305
323          if (nv->type != VT_PER ||               /* check view legality */
324                          nv->horiz > 160. || nv->vert > 160.) {
325                  error(COMMAND, "illegal view type/angle");
# Line 338 | Line 355 | register VIEW  *nv;
355                          XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres);
356                          dev_input();    /* get resize event */
357                  }
358 <                copystruct(&odev.v, nv);        /* setview() already called */
358 >                odev.v = *nv;   /* setview() already called */
359 >                viewflags |= VWCHANGE;
360 >        }
361   #ifdef STEREO
362 <                copystruct(&vwright, nv);
363 <                d = eyesepdist / sqrt(nv->hn2);
364 <                VSUM(vwright.vp, nv->vp, nv->hvec, d);
365 <                /* setview(&vwright);   -- Unnecessary */
362 >        vwright = *nv;
363 >        d = eyesepdist / sqrt(nv->hn2);
364 >        VSUM(vwright.vp, nv->vp, nv->hvec, d);
365 >        /* setview(&vwright);   -- Unnecessary */
366   #endif
348        } else
349                viewsteady = 1;
367          wipeclean();
368          return(1);
369   }
370  
371  
372 < dev_section(gfn, pfn)           /* add octree for geometry rendering */
373 < char    *gfn, *pfn;
372 > extern void
373 > dev_section(            /* add octree for geometry rendering */
374 >        char    *gfn,
375 >        char    *pfn
376 > )
377   {
358        extern char     *index();
359        char    *cp;
360
378          if (gfn == NULL) {
379                  gmEndGeom();
380                  gmEndPortal();
# Line 377 | Line 394 | char   *gfn, *pfn;
394   }
395  
396  
397 < dev_auxcom(cmd, args)           /* process an auxiliary command */
398 < char    *cmd, *args;
397 > extern void
398 > dev_auxcom(             /* process an auxiliary command */
399 >        char    *cmd,
400 >        char    *args
401 > )
402   {
403   #ifdef DOBJ
404 <        if (dobj_command(cmd, args) >= 0)
404 >        int     vischange;
405 >
406 >        if ((vischange = dobj_command(cmd, args)) >= 0) {
407 >                if (vischange) {
408 >                        imm_mode = beam_sync(1) > 0;
409 >                        dev_clear();
410 >                }
411                  return;
412 +        }
413   #endif
414          sprintf(errmsg, "%s: unknown command", cmd);
415          error(COMMAND, errmsg);
416   }
417  
418  
419 < VIEW *
420 < dev_auxview(n, hvres)           /* return nth auxiliary view */
421 < int     n;
422 < int     hvres[2];
419 > extern VIEW *
420 > dev_auxview(            /* return nth auxiliary view */
421 >        int     n,
422 >        int     hvres[2]
423 > )
424   {
425          hvres[0] = odev.hres; hvres[1] = odev.vres;
426          if (n == 0)
# Line 405 | Line 433 | int    hvres[2];
433   }
434  
435  
436 < int
437 < dev_input()                     /* get X11 input */
436 > extern int
437 > dev_input(void)                 /* get X11 input */
438   {
439          inpresflags = 0;
440  
# Line 421 | Line 449 | dev_input()                    /* get X11 input */
449   }
450  
451  
452 < dev_value(c, d, p)              /* add a pixel value to our texture */
453 < COLR    c;
454 < FVECT   d, p;
452 > extern void
453 > dev_value(              /* add a pixel value to our texture */
454 >        COLR    c,
455 >        FVECT   d,
456 >        FVECT   p
457 > )
458   {
459   #ifdef DOBJ
460          if (dobj_lightsamp != NULL) {   /* in light source sampling */
# Line 437 | Line 468 | FVECT  d, p;
468   }
469  
470  
471 < int
472 < dev_flush()                     /* flush output as appropriate */
471 > extern int
472 > dev_flush(void)                 /* flush output as appropriate */
473   {
474          int     ndrawn;
475  
476 <        if (mapped && isperspective > 0) {
476 >        if ((viewflags&(VWMAPPED|VWPERSP)) == (VWMAPPED|VWPERSP)) {
477   #ifdef STEREO
478                  pushright();                    /* draw right eye */
479                  ndrawn = gmDrawGeom();
480   #ifdef DOBJ
481                  ndrawn += dobj_render();
482   #endif
452                if (ndrawn)
453                        gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP);
483                  checkglerr("rendering right eye");
484                  popright();                     /* draw left eye */
485   #endif
# Line 458 | Line 487 | dev_flush()                    /* flush output as appropriate */
487   #ifdef DOBJ
488                  ndrawn += dobj_render();
489   #endif
490 <                if (ndrawn)
462 <                        gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP);
490 >                glXSwapBuffers(ourdisplay, gwind);
491                  checkglerr("rendering base view");
492          }
493 <        if (mapped && viewsteady)
494 <                if (isperspective > 0) {        /* first time after steady */
495 <                        if (ndrawn)
496 <                                xferdepth();    /* transfer and clear depth */
497 <                        setglortho();           /* set orthographic view */
498 <                } else if (!isperspective) {
493 >        if ((viewflags&(VWMAPPED|VWSTEADY|VWPERSP|VWORTHO)) ==
494 >                        (VWMAPPED|VWSTEADY|VWPERSP)) {
495 >                                        /* first time after steady */
496 >                if (ndrawn)
497 >                        xferdepth();    /* transfer and clear depth */
498 >                setglortho();           /* set orthographic view */
499 >
500 >        }
501 >        if ((viewflags&(VWMAPPED|VWSTEADY|VWPERSP|VWORTHO)) ==
502 >                        (VWMAPPED|VWSTEADY|VWORTHO)) {
503 >                                        /* else update cones */
504   #ifdef STEREO
505 <                        pushright();
506 <                        odUpdate(1);            /* draw right eye */
507 <                        popright();
505 >                pushright();
506 >                odUpdate(1);            /* draw right eye */
507 >                popright();
508   #endif
509 <                        odUpdate(0);            /* draw left eye */
510 <                }
511 <        glFlush();                              /* flush OpenGL */
509 >                odUpdate(0);            /* draw left eye */
510 >                glFlush();              /* flush OpenGL */
511 >        }
512          rayqleft = RAYQLEN;
513                                          /* flush X11 and return # pending */
514          return(odev.inpready = XPending(ourdisplay));
515   }
516  
517  
518 < checkglerr(where)               /* check for GL or GLU error */
519 < char    *where;
518 > static void
519 > checkglerr(             /* check for GL or GLU error */
520 >        char    *where
521 > )
522   {
523          register GLenum errcode;
524  
# Line 495 | Line 530 | char   *where;
530   }
531  
532  
533 < static
534 < xferdepth()                     /* load and clear depth buffer */
533 > static void
534 > xferdepth(void)                 /* load and clear depth buffer */
535   {
536          register GLfloat        *dbp;
537 <        register GLubyte        *cbuf;
537 >        register GLubyte        *pbuf;
538  
539          if (depthbuffer == NULL) {      /* allocate private depth buffer */
540   #ifdef STEREO
# Line 512 | Line 547 | xferdepth()                    /* load and clear depth buffer */
547          }
548                                  /* allocate alpha buffer for portals */
549          if (gmPortals)
550 <                cbuf = (GLubyte *)malloc(odev.hres*odev.vres*
516 <                                                        (4*sizeof(GLubyte)));
550 >                pbuf = (GLubyte *)malloc(odev.hres*odev.vres*sizeof(GLubyte));
551          else
552 <                cbuf = NULL;
552 >                pbuf = NULL;
553   #ifdef STEREO
554 <        setstereobuf(STEREO_BUFFER_RIGHT);
554 >        pushright();
555          glReadPixels(0, 0, odev.hres, odev.vres,
556                          GL_DEPTH_COMPONENT, GL_FLOAT, depthright);
557 <        if (cbuf != NULL)
557 >        if (pbuf != NULL) {
558 >                glClear(GL_COLOR_BUFFER_BIT);
559 >                gmDrawPortals(0xff, -1, -1, -1);
560                  glReadPixels(0, 0, odev.hres, odev.vres,
561 <                                GL_RGBA, GL_UNSIGNED_BYTE, cbuf);
561 >                                GL_RED, GL_UNSIGNED_BYTE, pbuf);
562 >        }
563          for (dbp = depthright + odev.hres*odev.vres; dbp-- > depthright; )
564 <                if (cbuf != NULL && isportal(cbuf+4*(dbp-depthright)))
564 >                if (pbuf != NULL && pbuf[dbp-depthright]&0x40)
565                          *dbp = FHUGE;
566                  else
567                          *dbp = mapdepth(*dbp);
568          glClear(GL_DEPTH_BUFFER_BIT);
532        setstereobuf(STEREO_BUFFER_LEFT);
569          odDepthMap(1, depthright);
570 +        popright();
571   #endif
572                                  /* read back depth buffer */
573          glReadPixels(0, 0, odev.hres, odev.vres,
574                          GL_DEPTH_COMPONENT, GL_FLOAT, depthbuffer);
575 <        if (cbuf != NULL)
575 >        if (pbuf != NULL) {
576 >                glClear(GL_COLOR_BUFFER_BIT);           /* find portals */
577 >                gmDrawPortals(0xff, -1, -1, -1);
578                  glReadPixels(0, 0, odev.hres, odev.vres,
579 <                                GL_RGBA, GL_UNSIGNED_BYTE, cbuf);
579 >                                GL_RED, GL_UNSIGNED_BYTE, pbuf);
580 > #ifdef DEBUG
581 >                glXSwapBuffers(ourdisplay, gwind);
582 > #endif
583 >        }
584          for (dbp = depthbuffer + odev.hres*odev.vres; dbp-- > depthbuffer; )
585 <                if (cbuf != NULL && isportal(cbuf+4*(dbp-depthbuffer)))
585 >                if (pbuf != NULL && pbuf[dbp-depthbuffer]&0x40)
586                          *dbp = FHUGE;
587                  else
588                          *dbp = mapdepth(*dbp);
589          glClear(GL_DEPTH_BUFFER_BIT);           /* clear system depth buffer */
547        if (cbuf != NULL)
548                free((char *)cbuf);             /* free our color buffer */
590          odDepthMap(0, depthbuffer);             /* transfer depth data */
591 +        if (pbuf != NULL)
592 +                free((void *)pbuf);             /* free our portal buffer */
593   }
594  
595  
596 < static
597 < freedepth()                             /* free recorded depth buffer */
596 > static void
597 > freedepth(void)                         /* free recorded depth buffer */
598   {
599          if (depthbuffer == NULL)
600                  return;
601   #ifdef STEREO
602          odDepthMap(1, NULL);
603 <        free((char *)depthright);
603 >        free((void *)depthright);
604          depthright = NULL;
605   #endif
606          odDepthMap(0, NULL);
607 <        free((char *)depthbuffer);
607 >        free((void *)depthbuffer);
608          depthbuffer = NULL;
609   }
610  
611  
612   static double
613 < getdistance(dx, dy, direc)      /* distance from fore plane along view ray */
614 < int     dx, dy;
615 < FVECT   direc;
613 > getdistance(    /* distance from fore plane along view ray */
614 >        int     dx,
615 >        int     dy,
616 >        FVECT   direc
617 > )
618   {
619          GLfloat gldepth;
575        GLubyte glcolor[4];
620          double  dist;
621  
622 <        if (dx<0 | dx>=odev.hres | dy<0 | dy>=odev.vres)
622 >        if ((dx<0) | (dx>=odev.hres) | (dy<0) | (dy>=odev.vres))
623                  return(FHUGE);
624          if (depthbuffer != NULL)
625                  dist = depthbuffer[dy*odev.hres + dx];
626          else {
627                  glReadPixels(dx,dy, 1,1, GL_DEPTH_COMPONENT,
628                                  GL_FLOAT, &gldepth);
629 <                if (gmPortals) {
630 <                        glReadPixels(dx,dy, 1,1, GL_RGBA,
587 <                                        GL_UNSIGNED_BYTE, glcolor);
588 <                        if (isportal(glcolor))
589 <                                return(FHUGE);
590 <                }
629 >                if (gldepth <= FTINY)
630 >                        return (FHUGE); /* call failed */
631                  dist = mapdepth(gldepth);
632          }
633          if (dist >= .99*FHUGE)
# Line 597 | Line 637 | FVECT  direc;
637  
638  
639   #ifdef STEREO
640 < static
641 < pushright()                     /* push on right view & buffer */
640 > static void
641 > pushright(void)                 /* push on right view & buffer */
642   {
643          double  d;
644  
645          setstereobuf(STEREO_BUFFER_RIGHT);
646 <        if (isperspective > 0) {
646 >        if (viewflags & VWPERSP) {
647                  glMatrixMode(GL_MODELVIEW);
648                  glPushMatrix();
649                  d = -eyesepdist / sqrt(odev.v.hn2);
# Line 614 | Line 654 | pushright()                    /* push on right view & buffer */
654   }
655  
656  
657 < static
658 < popright()                      /* pop off right view & buffer */
657 > static void
658 > popright(void)                  /* pop off right view & buffer */
659   {
660 <        if (isperspective > 0) {
660 >        if (viewflags & VWPERSP) {
661                  glMatrixMode(GL_MODELVIEW);
662                  glPopMatrix();
663          }
# Line 627 | Line 667 | popright()                     /* pop off right view & buffer */
667  
668  
669   static int
670 < mytmflags()                     /* figure out tone mapping flags */
670 > mytmflags(void)                 /* figure out tone mapping flags */
671   {
672          extern char     *progname;
673          register char   *cp, *tail;
# Line 651 | Line 691 | mytmflags()                    /* figure out tone mapping flags */
691   }
692  
693  
694 < static
695 < getevent()                      /* get next event */
694 > static void
695 > getevent(void)                  /* get next event */
696   {
697          XNextEvent(ourdisplay, levptr(XEvent));
698          switch (levptr(XEvent)->type) {
# Line 660 | Line 700 | getevent()                     /* get next event */
700                  resizewindow(levptr(XConfigureEvent));
701                  break;
702          case UnmapNotify:
703 <                mapped = 0;
703 >                viewflags &= ~VWMAPPED;
704                  break;
705          case MapNotify:
706                  odRemap(0);
707 <                mapped = 1;
707 >                viewflags |= VWMAPPED;
708                  break;
709          case Expose:
710                  fixwindow(levptr(XExposeEvent));
# Line 682 | Line 722 | getevent()                     /* get next event */
722   }
723  
724  
725 < static
726 < draw3dline(wp)                  /* draw 3d line in world coordinates */
727 < register FVECT  wp[2];
725 > static void
726 > draw3dline(                     /* draw 3d line in world coordinates */
727 >        register FVECT  wp[2]
728 > )
729   {
730          glVertex3d(wp[0][0], wp[0][1], wp[0][2]);
731          glVertex3d(wp[1][0], wp[1][1], wp[1][2]);
732   }
733  
734  
735 < static
736 < draw_grids(fore)                /* draw holodeck section grids */
737 < int     fore;
735 > static void
736 > draw_grids(             /* draw holodeck section grids */
737 >        int     fore
738 > )
739   {
740          glPushAttrib(GL_LIGHTING_BIT|GL_ENABLE_BIT);
741          glDisable(GL_LIGHTING);
742          if (fore)
743 <                glColor3ub(0, 255, 255);
743 >                glColor3ub(4, 250, 250);
744          else
745                  glColor3ub(0, 0, 0);
746          glBegin(GL_LINES);              /* draw each grid line */
# Line 709 | Line 751 | int    fore;
751   }
752  
753  
754 < static
755 < moveview(dx, dy, mov, orb)      /* move our view */
756 < int     dx, dy, mov, orb;
754 > static int
755 > moveview(       /* move our view */
756 >        int     dx,
757 >        int     dy,
758 >        int     mov,
759 >        int     orb
760 > )
761   {
762          VIEW    nv;
763          FVECT   odir, v1, wip;
764          double  d, d1;
719        register int    li;
765                                  /* start with old view */
766 <        copystruct(&nv, &odev.v);
766 >        nv = odev.v;
767                                  /* orient our motion */
768          if (viewray(v1, odir, &odev.v,
769                          (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
# Line 751 | Line 796 | int    dx, dy, mov, orb;
796                  d = MOVPCT/100. * mov;
797                  VSUM(nv.vp, nv.vp, odir, d);
798          }
799 <        if (!mov ^ !orb && headlocked) {        /* restore head height */
799 >        if (!mov ^ !orb && viewflags&VWHEADLOCK) {      /* restore height */
800                  VSUM(v1, odev.v.vp, nv.vp, -1.);
801                  d = DOT(v1, nv.vup);
802                  VSUM(nv.vp, nv.vp, odev.v.vup, d);
# Line 764 | Line 809 | int    dx, dy, mov, orb;
809   }
810  
811  
812 < static
813 < getframe(ebut)                          /* get focus frame */
814 < XButtonPressedEvent     *ebut;
812 > static void
813 > getframe(                               /* get focus frame */
814 >        XButtonPressedEvent     *ebut
815 > )
816   {
817          int     startx = ebut->x, starty = ebut->y;
818          int     endx, endy;
# Line 774 | Line 820 | XButtonPressedEvent    *ebut;
820          XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent));
821          endx = levptr(XButtonReleasedEvent)->x;
822          endy = levptr(XButtonReleasedEvent)->y;
823 <        if (endx == startx | endy == starty) {
823 >        if ((endx == startx) | (endy == starty)) {
824                  XBell(ourdisplay, 0);
825                  return;
826          }
# Line 787 | Line 833 | XButtonPressedEvent    *ebut;
833   }
834  
835  
836 < static
837 < getmove(ebut)                           /* get view change */
792 < XButtonPressedEvent     *ebut;
836 > static void
837 > waitabit(void)                          /* pause a moment */
838   {
839 +        struct timespec ts;
840 +        ts.tv_sec = 0;
841 +        ts.tv_nsec = 100000000L;
842 +        nanosleep(&ts, NULL);
843 + }
844 +
845 +
846 + static void
847 + getmove(                                /* get view change */
848 +        XButtonPressedEvent     *ebut
849 + )
850 + {
851          int     movdir = MOVDIR(ebut->button);
852          int     movorb = MOVORB(ebut->state);
853          int     ndrawn;
# Line 800 | Line 857 | XButtonPressedEvent    *ebut;
857  
858          XNoOp(ourdisplay);              /* makes sure we're not idle */
859  
860 <        viewsteady = 0;                 /* flag moving view */
861 <        setglpersp(&odev.v);            /* start us off in perspective */
860 >        viewflags &= ~VWSTEADY;         /* flag moving view */
861 >        setglpersp();                   /* start us off in perspective */
862          while (!XCheckMaskEvent(ourdisplay,
863                          ButtonReleaseMask, levptr(XEvent))) {
864 +                                        /* pause so as not to move too fast */
865 +                waitabit();
866                                          /* get cursor position */
867                  if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
868                                  &rootx, &rooty, &wx, &wy, &statemask))
# Line 821 | Line 880 | XButtonPressedEvent    *ebut;
880   #ifdef DOBJ
881                  ndrawn += dobj_render();
882   #endif
824                if (ndrawn)
825                        gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP);
883                  popright();
884   #endif
885                                          /* redraw octrees */
# Line 830 | Line 887 | XButtonPressedEvent    *ebut;
887   #ifdef DOBJ
888                  ndrawn += dobj_render();        /* redraw objects */
889   #endif
890 <                if (ndrawn)
891 <                        gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP);
835 <                glFlush();
836 <                if (!ndrawn) {
890 >                glXSwapBuffers(ourdisplay, gwind);
891 >                if (!ndrawn)
892                          sleep(1);       /* for reasonable interaction */
838 #ifdef STEREO
839                        pushright();
840                        draw_grids(0);
841                        popright();
842 #endif
843                        draw_grids(0);
844                }
893          }
894          if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */
895                  movdir = MOVDIR(levptr(XButtonReleasedEvent)->button);
# Line 849 | Line 897 | XButtonPressedEvent    *ebut;
897                  wy = levptr(XButtonReleasedEvent)->y;
898                  moveview(wx, odev.vres-1-wy, movdir, movorb);
899          }
900 +        viewflags |= VWSTEADY;          /* done goofing around */
901   }
902  
903  
904 < static
905 < setglpersp(vp)                  /* set perspective view in GL */
857 < register VIEW   *vp;
904 > static void
905 > setglpersp(void)                        /* set perspective view in GL */
906   {
907          double  d, xmin, xmax, ymin, ymax;
908          GLfloat vec[4];
# Line 866 | Line 914 | register VIEW  *vp;
914                  dev_zmax = 100.;
915          } else {
916                  dev_zmin = 0.5*depthlim[0];
917 <                dev_zmax = 1.75*depthlim[1];
917 >                dev_zmax = 1.25*depthlim[1];
918                  if (dev_zmin > dev_zmax/5.)
919                          dev_zmin = dev_zmax/5.;
920          }
# Line 874 | Line 922 | register VIEW  *vp;
922                  dev_zmin = odev.v.vfore;
923          if (odev.v.vaft > FTINY)
924                  dev_zmax = odev.v.vaft;
925 <        if (dev_zmin < dev_zmax/100.)
926 <                dev_zmin = dev_zmax/100.;
925 >        if (dev_zmin*500. < dev_zmax)
926 >                dev_zmin = dev_zmax/500.;
927          setzrat();
928          xmax = dev_zmin * tan(PI/180./2. * odev.v.horiz);
929          xmin = -xmax;
# Line 895 | Line 943 | register VIEW  *vp;
943                  odev.v.vp[2] + odev.v.vdir[2],
944                  odev.v.vup[0], odev.v.vup[1], odev.v.vup[2]);
945          checkglerr("setting perspective view");
898        isperspective = 1;
946          vec[0] = vec[1] = vec[2] = 0.; vec[3] = 1.;
947          glLightModelfv(GL_LIGHT_MODEL_AMBIENT, vec);
948          vec[0] = -odev.v.vdir[0];
# Line 911 | Line 958 | register VIEW  *vp;
958          glEnable(GL_LIGHT0);
959          glEnable(GL_LIGHTING);          /* light our GL objects */
960          glShadeModel(GL_SMOOTH);
961 +        viewflags &= ~VWORTHO;
962 +        viewflags |= VWPERSP;
963   }
964  
965  
966 < static
967 < setglortho()                    /* set up orthographic view for cone drawing */
966 > static void
967 > setglortho(void)                        /* set up orthographic view for cone drawing */
968   {
969 +        glDrawBuffer(GL_FRONT);         /* use single-buffer mode */
970                                          /* set view matrix */
971          glMatrixMode(GL_PROJECTION);
972          glLoadIdentity();
973          glOrtho(0., (double)odev.hres, 0., (double)odev.vres,
974                          0.001*OMAXDEPTH, 1.001*(-OMAXDEPTH));
975          checkglerr("setting orthographic view");
926        isperspective = 0;
976          glDisable(GL_LIGHTING);         /* cones are constant color */
977          glShadeModel(GL_FLAT);
978 +        viewflags &= ~VWPERSP;
979 +        viewflags |= VWORTHO;
980   }
981  
982  
983 < static
984 < wipeclean()                     /* prepare for redraw */
983 > static void
984 > wipeclean(void)                 /* prepare for redraw */
985   {
986 <                                        /* clear depth buffer */
986 >        glDrawBuffer(GL_BACK);          /* use double-buffer mode */
987 >        glReadBuffer(GL_BACK);
988 >                                        /* clear buffers */
989   #ifdef STEREO
990          setstereobuf(STEREO_BUFFER_RIGHT);
991 <        glClear(GL_DEPTH_BUFFER_BIT);
991 >        glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
992          setstereobuf(STEREO_BUFFER_LEFT);
993   #endif
994 <        glClear(GL_DEPTH_BUFFER_BIT);
942 <        if (viewsteady)                 /* clear samples if steady */
943 <                odClean();
994 >        glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
995          freedepth();
996 <        setglpersp(&odev.v);            /* reset view & clipping planes */
996 >        if ((viewflags&(VWCHANGE|VWSTEADY)) ==
997 >                        (VWCHANGE|VWSTEADY)) {  /* clear samples if new */
998 >                odClean();
999 >                viewflags &= ~VWCHANGE;         /* change noted */
1000 >        } else if (viewflags & VWSTEADY)
1001 >                odRedrawAll();
1002 >        setglpersp();                   /* reset view & clipping planes */
1003   }
1004  
1005  
1006 < static
1007 < getkey(ekey)                            /* get input key */
1008 < register XKeyPressedEvent  *ekey;
1006 > static void
1007 > getkey(                         /* get input key */
1008 >        register XKeyPressedEvent  *ekey
1009 > )
1010   {
1011          Window  rootw, childw;
1012          int     rootx, rooty, wx, wy;
# Line 961 | Line 1019 | register XKeyPressedEvent  *ekey;
1019                  return;
1020          switch (buf[0]) {
1021          case 'h':                       /* turn on height motion lock */
1022 <                headlocked = 1;
1022 >                viewflags |= VWHEADLOCK;
1023                  return;
1024          case 'H':                       /* turn off height motion lock */
1025 <                headlocked = 0;
1025 >                viewflags &= ~VWHEADLOCK;
1026                  return;
1027          case 'l':                       /* retrieve last view */
1028                  inpresflags |= DFL(DC_LASTVIEW);
# Line 992 | Line 1050 | register XKeyPressedEvent  *ekey;
1050                  inpresflags |= DFL(DC_RESUME);
1051                  return;
1052          case CTRL('R'):                 /* redraw screen */
1053 <                odRemap(0);
1054 <                glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
1053 >                odRemap(0);                     /* new tone mapping */
1054 >                glClear(GL_DEPTH_BUFFER_BIT);
1055   #ifdef STEREO
1056                  setstereobuf(STEREO_BUFFER_RIGHT);
1057 <                glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
1057 >                glClear(GL_DEPTH_BUFFER_BIT);
1058                  setstereobuf(STEREO_BUFFER_LEFT);
1059   #endif
1060                  return;
1061          case CTRL('L'):                 /* refresh from server */
1062                  if (inpresflags & DFL(DC_REDRAW))
1063 <                        return;
1063 >                        return;                 /* already called */
1064                  XRaiseWindow(ourdisplay, gwind);
1065 <                XFlush(ourdisplay);
1066 <                sleep(1);
1067 <                wipeclean();                    /* fresh display */
1068 <                odRemap(1);                     /* fresh tone mapping */
1011 <                dev_flush();                    /* draw octrees */
1065 >                XFlush(ourdisplay);             /* raise up window */
1066 >                sleep(1);                       /* wait for restacking */
1067 >                dev_clear();                    /* clear buffer and samples */
1068 >                odRemap(1);                     /* start fresh histogram */
1069                  inpresflags |= DFL(DC_REDRAW);  /* resend values from server */
1013                rayqleft = 0;                   /* hold off update */
1070                  return;
1071          case 'K':                       /* kill rtrace process(es) */
1072                  inpresflags |= DFL(DC_KILL);
# Line 1031 | Line 1087 | register XKeyPressedEvent  *ekey;
1087   }
1088  
1089  
1090 < static
1091 < fixwindow(eexp)                         /* repair damage to window */
1092 < register XExposeEvent  *eexp;
1090 > static void
1091 > fixwindow(                              /* repair damage to window */
1092 >        register XExposeEvent  *eexp
1093 > )
1094   {
1095          int     xmin, ymin, xmax, ymax;
1096  
1097 <        if (odev.hres == 0 | odev.vres == 0) {  /* first exposure */
1097 >        if ((odev.hres == 0) | (odev.vres == 0)) {      /* first exposure */
1098                  resizewindow((XConfigureEvent *)eexp);
1099                  return;
1100          }
1101          xmin = eexp->x; xmax = eexp->x + eexp->width;
1102          ymin = odev.vres - eexp->y - eexp->height; ymax = odev.vres - eexp->y;
1103 +
1104 +        if (xmin <= 0 && xmax >= odev.hres-1 &&
1105 +                        ymin <= 0 && ymax >= odev.vres) {
1106 +                DCHECK(eexp->count, WARNING, "multiple clear in fixwindow");
1107 +                wipeclean();                    /* make sure we're go */
1108 +                return;
1109 +        }
1110                                                  /* clear portion of depth */
1111          glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
1112          glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
# Line 1069 | Line 1133 | register XExposeEvent  *eexp;
1133   }
1134  
1135  
1136 < static
1137 < resizewindow(ersz)                      /* resize window */
1138 < register XConfigureEvent  *ersz;
1136 > static void
1137 > resizewindow(                   /* resize window */
1138 >        register XConfigureEvent  *ersz
1139 > )
1140   {
1141          glViewport(0, 0, ersz->width, ersz->height);
1142  
# Line 1085 | Line 1150 | register XConfigureEvent  *ersz;
1150          odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
1151  
1152          inpresflags |= DFL(DC_SETVIEW);
1153 +        viewflags |= VWCHANGE;
1154   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines