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.7 by gwlarson, Tue Dec 22 09:40:32 1998 UTC vs.
Revision 3.25 by greg, Thu Feb 12 18:55:50 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 + #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 < #ifndef PORTALP
43 < #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 */
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) && \
47 <                                (PORTBLU<0 || (c)[2]==PORTBLU) && \
48 <                                (PORTALP<0 || (c)[3]==PORTALP))
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   #ifndef FEQ
53   #define FEQ(a,b)        ((a)-(b) <= FTINY && (a)-(b) >= -FTINY)
# Line 71 | Line 69 | static char SCCSid[] = "$SunId$ SGI";
69   #define MOVDEG          (-5)            /* degrees to orbit CW/down /frame */
70   #define MOVORB(s)       ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
71  
74 #define MINWIDTH        480             /* minimum graphics window width */
75 #define MINHEIGHT       400             /* minimum graphics window height */
76
77 #define VIEWDIST        356             /* assumed viewing distance (mm) */
78
79 #define BORWIDTH        5               /* border width */
80
72   #define setstereobuf(bid)       (glXWaitGL(), \
73                                  XSGISetStereoBuffer(ourdisplay, gwind, bid), \
74                                  glXWaitX())
# Line 123 | Line 114 | static int     inpresflags;            /* input result flags */
114  
115   static int      viewflags;              /* what's happening with view */
116  
117 + /*
118   static int  resizewindow(), getevent(), getkey(), moveview(), wipeclean(),
119                  xferdepth(), freedepth(), setglortho(),
120                  setglpersp(), getframe(), getmove(), fixwindow(), mytmflags();
121  
122   static double   getdistance();
123 + */
124 + static void checkglerr(char *where);
125 + static void xferdepth(void);
126 + static void freedepth(void);
127 + static double getdistance(int dx, int dy, FVECT direc);
128 + static int mytmflags(void);
129 + static void getevent(void);
130 + static void draw3dline(register FVECT wp[2]);
131 + static void draw_grids(int fore);
132 + static int moveview(int dx, int dy, int mov, int orb);
133 + static void getframe(XButtonPressedEvent *ebut);
134 + static void getmove(XButtonPressedEvent *ebut);
135 + static void getkey(register XKeyPressedEvent *ekey);
136 + static void fixwindow(register XExposeEvent *eexp);
137 + static void resizewindow(register XConfigureEvent *ersz);
138 + static void waitabit(void);
139 + static void setglpersp(void);
140 + static void setglortho(void);
141 + static void wipeclean(void);
142  
143 +
144   #ifdef STEREO
145 < static int  pushright(), popright();
145 > static void pushright(void);
146 > static void popright(void);
147   #endif
148  
149   extern int      gmPortals;      /* GL portal list id */
# Line 138 | Line 151 | extern int     gmPortals;      /* GL portal list id */
151   extern time_t   time();
152  
153  
154 + extern void
155   dev_open(id)                    /* initialize GLX driver */
156   char  *id;
157   {
158          extern char     *getenv();
159          static RGBPRIMS myprims = STDPRIMS;
146 #if (PORTALP<0)
160          static int      atlBest[] = {GLX_RGBA, GLX_DOUBLEBUFFER,
161                                  GLX_RED_SIZE,8, GLX_GREEN_SIZE,8,
162                                  GLX_BLUE_SIZE,8, GLX_DEPTH_SIZE,15, None};
163          static int      atlOK[] = {GLX_RGBA, GLX_DOUBLEBUFFER,
164                                  GLX_RED_SIZE,4, GLX_GREEN_SIZE,4,
165                                  GLX_BLUE_SIZE,4, GLX_DEPTH_SIZE,15, None};
153 #else
154        static int      atlBest[] = {GLX_RGBA, GLX_DOUBLEBUFFER,
155                                GLX_RED_SIZE,8, GLX_GREEN_SIZE,8,
156                                GLX_BLUE_SIZE,8, GLX_ALPHA_SIZE,2,
157                                GLX_DEPTH_SIZE,15, None};
158        static int      atlOK[] = {GLX_RGBA, GLX_DOUBLEBUFFER,
159                                GLX_RED_SIZE,4, GLX_GREEN_SIZE,4,
160                                GLX_BLUE_SIZE,4, GLX_ALPHA_SIZE,2,
161                                GLX_DEPTH_SIZE,15, None};
162 #endif
166          char    *ev;
167          double  gamval = GAMMA;
168          RGBPRIMP        dpri = stdprims;
# Line 248 | Line 251 | char  *id;
251          glXMakeCurrent(ourdisplay, gwind, gctx);
252          glEnable(GL_DEPTH_TEST);
253          glDepthFunc(GL_LEQUAL);
254 <        glEnable(GL_DITHER);
254 >        glClearColor(0, 0, 0, 0);
255          glFrontFace(GL_CCW);
256          glDisable(GL_CULL_FACE);
257          glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
258          glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
259 +        glPixelStorei(GL_PACK_ALIGNMENT, 1);
260 +        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
261                                          /* figure out sensible view */
262          pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
263                          DisplayWidth(ourdisplay, ourscreen);
# Line 263 | Line 268 | char  *id;
268          setstereobuf(STEREO_BUFFER_LEFT);
269   #endif
270          checkglerr("setting rendering parameters");
271 <        copystruct(&odev.v, &stdview);
271 >        odev.v = stdview;
272          odev.v.type = VT_PER;
273          viewflags = VWSTEADY;           /* view starts static */
274                                          /* map the window */
275          XMapWindow(ourdisplay, gwind);
276          dev_input();                    /* sets size and view angles */
277          if (!odInit(DisplayWidth(ourdisplay,ourscreen) *
278 <                        DisplayHeight(ourdisplay,ourscreen) / 4))
278 >                        DisplayHeight(ourdisplay,ourscreen) / 3))
279                  error(SYSTEM, "insufficient memory for value storage");
280          odev.name = id;
281          odev.firstuse = 1;              /* can't recycle samples */
# Line 278 | Line 283 | char  *id;
283   }
284  
285  
286 < dev_close()                     /* close our display and free resources */
286 > extern void
287 > dev_close(void)                 /* close our display and free resources */
288   {
289   #ifdef DOBJ
290          dobj_cleanup();
# Line 300 | Line 306 | dev_close()                    /* close our display and free resources
306   }
307  
308  
309 < dev_clear()                     /* clear our representation */
309 > extern void
310 > dev_clear(void)                 /* clear our representation */
311   {
312 <        wipeclean();
312 >        viewflags |= VWCHANGE;          /* pretend our view has changed */
313 >        wipeclean();                    /* clean off display and samples */
314 >        dev_flush();                    /* redraw geometry & get depth */
315          rayqleft = 0;                   /* hold off update */
316   }
317  
318  
319 < int
320 < dev_view(nv)                    /* assign new driver view */
321 < register VIEW   *nv;
319 > extern int
320 > dev_view(                       /* assign new driver view */
321 >        register VIEW   *nv
322 > )
323   {
314        double  d;
315
324          if (nv->type != VT_PER ||               /* check view legality */
325                          nv->horiz > 160. || nv->vert > 160.) {
326                  error(COMMAND, "illegal view type/angle");
# Line 348 | Line 356 | register VIEW  *nv;
356                          XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres);
357                          dev_input();    /* get resize event */
358                  }
359 <                copystruct(&odev.v, nv);        /* setview() already called */
352 < #ifdef STEREO
353 <                copystruct(&vwright, nv);
354 <                d = eyesepdist / sqrt(nv->hn2);
355 <                VSUM(vwright.vp, nv->vp, nv->hvec, d);
356 <                /* setview(&vwright);   -- Unnecessary */
357 < #endif
359 >                odev.v = *nv;   /* setview() already called */
360                  viewflags |= VWCHANGE;
361          }
362 + #ifdef STEREO
363 +        vwright = *nv;
364 +        d = eyesepdist / sqrt(nv->hn2);
365 +        VSUM(vwright.vp, nv->vp, nv->hvec, d);
366 +        /* setview(&vwright);   -- Unnecessary */
367 + #endif
368          wipeclean();
369          return(1);
370   }
371  
372  
373 < dev_section(gfn, pfn)           /* add octree for geometry rendering */
374 < char    *gfn, *pfn;
373 > extern void
374 > dev_section(            /* add octree for geometry rendering */
375 >        char    *gfn,
376 >        char    *pfn
377 > )
378   {
368        extern char     *index();
369        char    *cp;
370
379          if (gfn == NULL) {
380                  gmEndGeom();
381                  gmEndPortal();
# Line 387 | Line 395 | char   *gfn, *pfn;
395   }
396  
397  
398 < dev_auxcom(cmd, args)           /* process an auxiliary command */
399 < char    *cmd, *args;
398 > extern void
399 > dev_auxcom(             /* process an auxiliary command */
400 >        char    *cmd,
401 >        char    *args
402 > )
403   {
404   #ifdef DOBJ
405 <        if (dobj_command(cmd, args) >= 0)
405 >        int     vischange;
406 >
407 >        if ((vischange = dobj_command(cmd, args)) >= 0) {
408 >                if (vischange) {
409 >                        imm_mode = beam_sync(1) > 0;
410 >                        dev_clear();
411 >                }
412                  return;
413 +        }
414   #endif
415          sprintf(errmsg, "%s: unknown command", cmd);
416          error(COMMAND, errmsg);
417   }
418  
419  
420 < VIEW *
421 < dev_auxview(n, hvres)           /* return nth auxiliary view */
422 < int     n;
423 < int     hvres[2];
420 > extern VIEW *
421 > dev_auxview(            /* return nth auxiliary view */
422 >        int     n,
423 >        int     hvres[2]
424 > )
425   {
426          hvres[0] = odev.hres; hvres[1] = odev.vres;
427          if (n == 0)
# Line 415 | Line 434 | int    hvres[2];
434   }
435  
436  
437 < int
438 < dev_input()                     /* get X11 input */
437 > extern int
438 > dev_input(void)                 /* get X11 input */
439   {
440          inpresflags = 0;
441  
# Line 431 | Line 450 | dev_input()                    /* get X11 input */
450   }
451  
452  
453 < dev_value(c, d, p)              /* add a pixel value to our texture */
454 < COLR    c;
455 < FVECT   d, p;
453 > extern void
454 > dev_value(              /* add a pixel value to our texture */
455 >        COLR    c,
456 >        FVECT   d,
457 >        FVECT   p
458 > )
459   {
460   #ifdef DOBJ
461          if (dobj_lightsamp != NULL) {   /* in light source sampling */
# Line 447 | Line 469 | FVECT  d, p;
469   }
470  
471  
472 < int
473 < dev_flush()                     /* flush output as appropriate */
472 > extern int
473 > dev_flush(void)                 /* flush output as appropriate */
474   {
475          int     ndrawn;
476  
# Line 459 | Line 481 | dev_flush()                    /* flush output as appropriate */
481   #ifdef DOBJ
482                  ndrawn += dobj_render();
483   #endif
462                if (ndrawn && gmPortals)
463                        gmDrawPortals(PORTRED,PORTGRN,PORTBLU,PORTALP);
484                  checkglerr("rendering right eye");
485                  popright();                     /* draw left eye */
486   #endif
# Line 468 | Line 488 | dev_flush()                    /* flush output as appropriate */
488   #ifdef DOBJ
489                  ndrawn += dobj_render();
490   #endif
471                if (ndrawn && gmPortals)
472                        gmDrawPortals(PORTRED,PORTGRN,PORTBLU,PORTALP);
491                  glXSwapBuffers(ourdisplay, gwind);
492                  checkglerr("rendering base view");
493          }
# Line 498 | Line 516 | dev_flush()                    /* flush output as appropriate */
516   }
517  
518  
519 < checkglerr(where)               /* check for GL or GLU error */
520 < char    *where;
519 > static void
520 > checkglerr(             /* check for GL or GLU error */
521 >        char    *where
522 > )
523   {
524          register GLenum errcode;
525  
# Line 511 | Line 531 | char   *where;
531   }
532  
533  
534 < static
535 < xferdepth()                     /* load and clear depth buffer */
534 > static void
535 > xferdepth(void)                 /* load and clear depth buffer */
536   {
537          register GLfloat        *dbp;
538 <        register GLubyte        *cbuf;
538 >        register GLubyte        *pbuf;
539  
540          if (depthbuffer == NULL) {      /* allocate private depth buffer */
541   #ifdef STEREO
# Line 528 | Line 548 | xferdepth()                    /* load and clear depth buffer */
548          }
549                                  /* allocate alpha buffer for portals */
550          if (gmPortals)
551 <                cbuf = (GLubyte *)malloc(odev.hres*odev.vres *
532 <                                                        (4*sizeof(GLubyte)));
551 >                pbuf = (GLubyte *)malloc(odev.hres*odev.vres*sizeof(GLubyte));
552          else
553 <                cbuf = NULL;
553 >                pbuf = NULL;
554   #ifdef STEREO
555 <        setstereobuf(STEREO_BUFFER_RIGHT);
555 >        pushright();
556          glReadPixels(0, 0, odev.hres, odev.vres,
557                          GL_DEPTH_COMPONENT, GL_FLOAT, depthright);
558 <        if (cbuf != NULL)
558 >        if (pbuf != NULL) {
559 >                glClear(GL_COLOR_BUFFER_BIT);
560 >                gmDrawPortals(0xff, -1, -1, -1);
561                  glReadPixels(0, 0, odev.hres, odev.vres,
562 <                                GL_RGBA, GL_UNSIGNED_BYTE, cbuf);
562 >                                GL_RED, GL_UNSIGNED_BYTE, pbuf);
563 >        }
564          for (dbp = depthright + odev.hres*odev.vres; dbp-- > depthright; )
565 <                if (cbuf != NULL && isportal(cbuf+4*(dbp-depthright)))
565 >                if (pbuf != NULL && pbuf[dbp-depthright]&0x40)
566                          *dbp = FHUGE;
567                  else
568                          *dbp = mapdepth(*dbp);
569          glClear(GL_DEPTH_BUFFER_BIT);
548        setstereobuf(STEREO_BUFFER_LEFT);
570          odDepthMap(1, depthright);
571 +        popright();
572   #endif
573                                  /* read back depth buffer */
574          glReadPixels(0, 0, odev.hres, odev.vres,
575                          GL_DEPTH_COMPONENT, GL_FLOAT, depthbuffer);
576 <        if (cbuf != NULL)
576 >        if (pbuf != NULL) {
577 >                glClear(GL_COLOR_BUFFER_BIT);           /* find portals */
578 >                gmDrawPortals(0xff, -1, -1, -1);
579                  glReadPixels(0, 0, odev.hres, odev.vres,
580 <                                GL_RGBA, GL_UNSIGNED_BYTE, cbuf);
580 >                                GL_RED, GL_UNSIGNED_BYTE, pbuf);
581 > #ifdef DEBUG
582 >                glXSwapBuffers(ourdisplay, gwind);
583 > #endif
584 >        }
585          for (dbp = depthbuffer + odev.hres*odev.vres; dbp-- > depthbuffer; )
586 <                if (cbuf != NULL && isportal(cbuf+4*(dbp-depthbuffer)))
586 >                if (pbuf != NULL && pbuf[dbp-depthbuffer]&0x40)
587                          *dbp = FHUGE;
588                  else
589                          *dbp = mapdepth(*dbp);
590          glClear(GL_DEPTH_BUFFER_BIT);           /* clear system depth buffer */
563        if (cbuf != NULL)
564                free((char *)cbuf);             /* free our color buffer */
591          odDepthMap(0, depthbuffer);             /* transfer depth data */
592 +        if (pbuf != NULL)
593 +                free((void *)pbuf);             /* free our portal buffer */
594   }
595  
596  
597 < static
598 < freedepth()                             /* free recorded depth buffer */
597 > static void
598 > freedepth(void)                         /* free recorded depth buffer */
599   {
600          if (depthbuffer == NULL)
601                  return;
602   #ifdef STEREO
603          odDepthMap(1, NULL);
604 <        free((char *)depthright);
604 >        free((void *)depthright);
605          depthright = NULL;
606   #endif
607          odDepthMap(0, NULL);
608 <        free((char *)depthbuffer);
608 >        free((void *)depthbuffer);
609          depthbuffer = NULL;
610   }
611  
612  
613   static double
614 < getdistance(dx, dy, direc)      /* distance from fore plane along view ray */
615 < int     dx, dy;
616 < FVECT   direc;
614 > getdistance(    /* distance from fore plane along view ray */
615 >        int     dx,
616 >        int     dy,
617 >        FVECT   direc
618 > )
619   {
620          GLfloat gldepth;
591        GLubyte glcolor[4];
621          double  dist;
622  
623 <        if (dx<0 | dx>=odev.hres | dy<0 | dy>=odev.vres)
623 >        if ((dx<0) | (dx>=odev.hres) | (dy<0) | (dy>=odev.vres))
624                  return(FHUGE);
625          if (depthbuffer != NULL)
626                  dist = depthbuffer[dy*odev.hres + dx];
627          else {
628                  glReadPixels(dx,dy, 1,1, GL_DEPTH_COMPONENT,
629                                  GL_FLOAT, &gldepth);
630 <                if (gmPortals) {
631 <                        glReadPixels(dx,dy, 1,1, GL_RGBA,
603 <                                        GL_UNSIGNED_BYTE, glcolor);
604 <                        if (isportal(glcolor))
605 <                                return(FHUGE);
606 <                }
630 >                if (gldepth <= FTINY)
631 >                        return (FHUGE); /* call failed */
632                  dist = mapdepth(gldepth);
633          }
634          if (dist >= .99*FHUGE)
# Line 613 | Line 638 | FVECT  direc;
638  
639  
640   #ifdef STEREO
641 < static
642 < pushright()                     /* push on right view & buffer */
641 > static void
642 > pushright(void)                 /* push on right view & buffer */
643   {
644          double  d;
645  
# Line 630 | Line 655 | pushright()                    /* push on right view & buffer */
655   }
656  
657  
658 < static
659 < popright()                      /* pop off right view & buffer */
658 > static void
659 > popright(void)                  /* pop off right view & buffer */
660   {
661          if (viewflags & VWPERSP) {
662                  glMatrixMode(GL_MODELVIEW);
# Line 643 | Line 668 | popright()                     /* pop off right view & buffer */
668  
669  
670   static int
671 < mytmflags()                     /* figure out tone mapping flags */
671 > mytmflags(void)                 /* figure out tone mapping flags */
672   {
673          extern char     *progname;
674          register char   *cp, *tail;
# Line 667 | Line 692 | mytmflags()                    /* figure out tone mapping flags */
692   }
693  
694  
695 < static
696 < getevent()                      /* get next event */
695 > static void
696 > getevent(void)                  /* get next event */
697   {
698          XNextEvent(ourdisplay, levptr(XEvent));
699          switch (levptr(XEvent)->type) {
# Line 698 | Line 723 | getevent()                     /* get next event */
723   }
724  
725  
726 < static
727 < draw3dline(wp)                  /* draw 3d line in world coordinates */
728 < register FVECT  wp[2];
726 > static void
727 > draw3dline(                     /* draw 3d line in world coordinates */
728 >        register FVECT  wp[2]
729 > )
730   {
731          glVertex3d(wp[0][0], wp[0][1], wp[0][2]);
732          glVertex3d(wp[1][0], wp[1][1], wp[1][2]);
733   }
734  
735  
736 < static
737 < draw_grids(fore)                /* draw holodeck section grids */
738 < int     fore;
736 > static void
737 > draw_grids(             /* draw holodeck section grids */
738 >        int     fore
739 > )
740   {
741          glPushAttrib(GL_LIGHTING_BIT|GL_ENABLE_BIT);
742          glDisable(GL_LIGHTING);
743          if (fore)
744 <                glColor3ub(0, 255, 255);
744 >                glColor3ub(4, 250, 250);
745          else
746                  glColor3ub(0, 0, 0);
747          glBegin(GL_LINES);              /* draw each grid line */
# Line 725 | Line 752 | int    fore;
752   }
753  
754  
755 < static
756 < moveview(dx, dy, mov, orb)      /* move our view */
757 < int     dx, dy, mov, orb;
755 > static int
756 > moveview(       /* move our view */
757 >        int     dx,
758 >        int     dy,
759 >        int     mov,
760 >        int     orb
761 > )
762   {
763          VIEW    nv;
764          FVECT   odir, v1, wip;
765          double  d, d1;
735        register int    li;
766                                  /* start with old view */
767 <        copystruct(&nv, &odev.v);
767 >        nv = odev.v;
768                                  /* orient our motion */
769          if (viewray(v1, odir, &odev.v,
770                          (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
# Line 780 | Line 810 | int    dx, dy, mov, orb;
810   }
811  
812  
813 < static
814 < getframe(ebut)                          /* get focus frame */
815 < XButtonPressedEvent     *ebut;
813 > static void
814 > getframe(                               /* get focus frame */
815 >        XButtonPressedEvent     *ebut
816 > )
817   {
818          int     startx = ebut->x, starty = ebut->y;
819          int     endx, endy;
# Line 790 | Line 821 | XButtonPressedEvent    *ebut;
821          XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent));
822          endx = levptr(XButtonReleasedEvent)->x;
823          endy = levptr(XButtonReleasedEvent)->y;
824 <        if (endx == startx | endy == starty) {
824 >        if ((endx == startx) | (endy == starty)) {
825                  XBell(ourdisplay, 0);
826                  return;
827          }
# Line 803 | Line 834 | XButtonPressedEvent    *ebut;
834   }
835  
836  
837 < static
838 < getmove(ebut)                           /* get view change */
808 < XButtonPressedEvent     *ebut;
837 > static void
838 > waitabit(void)                          /* pause a moment */
839   {
840 +        struct timespec ts;
841 +        ts.tv_sec = 0;
842 +        ts.tv_nsec = 100000000L;
843 +        nanosleep(&ts, NULL);
844 + }
845 +
846 +
847 + static void
848 + getmove(                                /* get view change */
849 +        XButtonPressedEvent     *ebut
850 + )
851 + {
852          int     movdir = MOVDIR(ebut->button);
853          int     movorb = MOVORB(ebut->state);
854          int     ndrawn;
# Line 817 | Line 859 | XButtonPressedEvent    *ebut;
859          XNoOp(ourdisplay);              /* makes sure we're not idle */
860  
861          viewflags &= ~VWSTEADY;         /* flag moving view */
862 <        setglpersp(&odev.v);            /* start us off in perspective */
862 >        setglpersp();                   /* start us off in perspective */
863          while (!XCheckMaskEvent(ourdisplay,
864                          ButtonReleaseMask, levptr(XEvent))) {
865 +                                        /* pause so as not to move too fast */
866 +                waitabit();
867                                          /* get cursor position */
868                  if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
869                                  &rootx, &rooty, &wx, &wy, &statemask))
# Line 837 | Line 881 | XButtonPressedEvent    *ebut;
881   #ifdef DOBJ
882                  ndrawn += dobj_render();
883   #endif
840                if (ndrawn && gmPortals)
841                        gmDrawPortals(PORTRED,PORTGRN,PORTBLU,PORTALP);
884                  popright();
885   #endif
886                                          /* redraw octrees */
# Line 846 | Line 888 | XButtonPressedEvent    *ebut;
888   #ifdef DOBJ
889                  ndrawn += dobj_render();        /* redraw objects */
890   #endif
849                if (ndrawn && gmPortals)
850                        gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP);
891                  glXSwapBuffers(ourdisplay, gwind);
892                  if (!ndrawn)
893                          sleep(1);       /* for reasonable interaction */
# Line 862 | Line 902 | XButtonPressedEvent    *ebut;
902   }
903  
904  
905 < static
906 < setglpersp(vp)                  /* set perspective view in GL */
867 < register VIEW   *vp;
905 > static void
906 > setglpersp(void)                        /* set perspective view in GL */
907   {
908          double  d, xmin, xmax, ymin, ymax;
909          GLfloat vec[4];
# Line 876 | Line 915 | register VIEW  *vp;
915                  dev_zmax = 100.;
916          } else {
917                  dev_zmin = 0.5*depthlim[0];
918 <                dev_zmax = 1.75*depthlim[1];
918 >                dev_zmax = 1.25*depthlim[1];
919                  if (dev_zmin > dev_zmax/5.)
920                          dev_zmin = dev_zmax/5.;
921          }
# Line 884 | Line 923 | register VIEW  *vp;
923                  dev_zmin = odev.v.vfore;
924          if (odev.v.vaft > FTINY)
925                  dev_zmax = odev.v.vaft;
926 <        if (dev_zmin < dev_zmax/100.)
927 <                dev_zmin = dev_zmax/100.;
926 >        if (dev_zmin*500. < dev_zmax)
927 >                dev_zmin = dev_zmax/500.;
928          setzrat();
929          xmax = dev_zmin * tan(PI/180./2. * odev.v.horiz);
930          xmin = -xmax;
# Line 925 | Line 964 | register VIEW  *vp;
964   }
965  
966  
967 < static
968 < setglortho()                    /* set up orthographic view for cone drawing */
967 > static void
968 > setglortho(void)                        /* set up orthographic view for cone drawing */
969   {
970          glDrawBuffer(GL_FRONT);         /* use single-buffer mode */
971                                          /* set view matrix */
# Line 942 | Line 981 | setglortho()                   /* set up orthographic view for cone dr
981   }
982  
983  
984 < static
985 < wipeclean()                     /* prepare for redraw */
984 > static void
985 > wipeclean(void)                 /* prepare for redraw */
986   {
987          glDrawBuffer(GL_BACK);          /* use double-buffer mode */
988 +        glReadBuffer(GL_BACK);
989                                          /* clear buffers */
990   #ifdef STEREO
991          setstereobuf(STEREO_BUFFER_RIGHT);
# Line 958 | Line 998 | wipeclean()                    /* prepare for redraw */
998                          (VWCHANGE|VWSTEADY)) {  /* clear samples if new */
999                  odClean();
1000                  viewflags &= ~VWCHANGE;         /* change noted */
1001 <        }
1002 <        setglpersp(&odev.v);            /* reset view & clipping planes */
1001 >        } else if (viewflags & VWSTEADY)
1002 >                odRedrawAll();
1003 >        setglpersp();                   /* reset view & clipping planes */
1004   }
1005  
1006  
1007 < static
1008 < getkey(ekey)                            /* get input key */
1009 < register XKeyPressedEvent  *ekey;
1007 > static void
1008 > getkey(                         /* get input key */
1009 >        register XKeyPressedEvent  *ekey
1010 > )
1011   {
1012          Window  rootw, childw;
1013          int     rootx, rooty, wx, wy;
# Line 1009 | Line 1051 | register XKeyPressedEvent  *ekey;
1051                  inpresflags |= DFL(DC_RESUME);
1052                  return;
1053          case CTRL('R'):                 /* redraw screen */
1054 <                odRemap(0);
1054 >                odRemap(0);                     /* new tone mapping */
1055                  glClear(GL_DEPTH_BUFFER_BIT);
1056   #ifdef STEREO
1057                  setstereobuf(STEREO_BUFFER_RIGHT);
# Line 1019 | Line 1061 | register XKeyPressedEvent  *ekey;
1061                  return;
1062          case CTRL('L'):                 /* refresh from server */
1063                  if (inpresflags & DFL(DC_REDRAW))
1064 <                        return;
1064 >                        return;                 /* already called */
1065                  XRaiseWindow(ourdisplay, gwind);
1066 <                XFlush(ourdisplay);
1067 <                sleep(1);
1068 <                wipeclean();                    /* fresh display */
1069 <                odRemap(1);                     /* fresh tone mapping */
1028 <                dev_flush();                    /* draw octrees */
1066 >                XFlush(ourdisplay);             /* raise up window */
1067 >                sleep(1);                       /* wait for restacking */
1068 >                dev_clear();                    /* clear buffer and samples */
1069 >                odRemap(1);                     /* start fresh histogram */
1070                  inpresflags |= DFL(DC_REDRAW);  /* resend values from server */
1030                rayqleft = 0;                   /* hold off update */
1071                  return;
1072          case 'K':                       /* kill rtrace process(es) */
1073                  inpresflags |= DFL(DC_KILL);
# Line 1048 | Line 1088 | register XKeyPressedEvent  *ekey;
1088   }
1089  
1090  
1091 < static
1092 < fixwindow(eexp)                         /* repair damage to window */
1093 < register XExposeEvent  *eexp;
1091 > static void
1092 > fixwindow(                              /* repair damage to window */
1093 >        register XExposeEvent  *eexp
1094 > )
1095   {
1096          int     xmin, ymin, xmax, ymax;
1097  
1098 <        if (odev.hres == 0 | odev.vres == 0) {  /* first exposure */
1098 >        if ((odev.hres == 0) | (odev.vres == 0)) {      /* first exposure */
1099                  resizewindow((XConfigureEvent *)eexp);
1100                  return;
1101          }
1102          xmin = eexp->x; xmax = eexp->x + eexp->width;
1103          ymin = odev.vres - eexp->y - eexp->height; ymax = odev.vres - eexp->y;
1104 +
1105 +        if (xmin <= 0 && xmax >= odev.hres-1 &&
1106 +                        ymin <= 0 && ymax >= odev.vres) {
1107 +                DCHECK(eexp->count, WARNING, "multiple clear in fixwindow");
1108 +                wipeclean();                    /* make sure we're go */
1109 +                return;
1110 +        }
1111                                                  /* clear portion of depth */
1112          glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
1113          glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
# Line 1086 | Line 1134 | register XExposeEvent  *eexp;
1134   }
1135  
1136  
1137 < static
1138 < resizewindow(ersz)                      /* resize window */
1139 < register XConfigureEvent  *ersz;
1137 > static void
1138 > resizewindow(                   /* resize window */
1139 >        register XConfigureEvent  *ersz
1140 > )
1141   {
1142          glViewport(0, 0, ersz->width, ersz->height);
1143  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines