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.1 by gwlarson, Fri Dec 18 11:55:19 1998 UTC vs.
Revision 3.3 by gwlarson, Mon Dec 21 11:42:38 1998 UTC

# Line 40 | Line 40 | static char SCCSid[] = "$SunId$ SGI";
40   #define RAYQLEN         10240           /* max. rays to queue before flush */
41   #endif
42  
43 + #ifndef PORTALP
44 + #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 */
48 + #endif
49 + #define isportal(c)     ((PORTRED<0 || (c)[0]==PORTRED) && \
50 +                                (PORTGRN<0 || (c)[1]==PORTGRN) && \
51 +                                (PORTBLU<0 || (c)[2]==PORTBLU) && \
52 +                                (PORTALP<0 || (c)[3]==PORTALP))
53 +
54   #ifndef FEQ
55   #define FEQ(a,b)        ((a)-(b) <= FTINY && (a)-(b) >= -FTINY)
56   #endif
# Line 111 | Line 122 | static int     isperspective;          /* perspective/ortho view *
122   static int      viewsteady;             /* is view steady? */
123  
124   static int  resizewindow(), getevent(), getkey(), moveview(), wipeclean(),
125 <                xferdepth(), setglortho(),
125 >                xferdepth(), freedepth(), setglortho(),
126                  setglpersp(), getframe(), getmove(), fixwindow(), mytmflags();
127  
128   static double   getdistance();
# Line 120 | Line 131 | static double  getdistance();
131   static int  pushright(), popright();
132   #endif
133  
134 + extern int      gmPortals;      /* GL portal list id */
135 +
136   extern time_t   time();
137  
138  
# Line 128 | Line 141 | char  *id;
141   {
142          extern char     *getenv();
143          static RGBPRIMS myprims = STDPRIMS;
144 + #if (PORTALP<0)
145          static int      atlBest[] = {GLX_RGBA, GLX_RED_SIZE,8,
146                                  GLX_GREEN_SIZE,8, GLX_BLUE_SIZE,8,
147                                  GLX_DEPTH_SIZE,15, None};
148 + #else
149 +        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
153          char    *ev;
154          double  gamval = GAMMA;
155          RGBPRIMP        dpri = stdprims;
# Line 256 | Line 275 | dev_close()                    /* close our display and free resources
275   #ifdef DOBJ
276          dobj_cleanup();
277   #endif
278 +        freedepth();
279 +        gmEndGeom();
280 +        gmEndPortal();
281          odDone();
282          glXMakeCurrent(ourdisplay, None, NULL);
283          glXDestroyContext(ourdisplay, gctx);
# Line 332 | Line 354 | register VIEW  *nv;
354   }
355  
356  
357 < dev_section(ofn)                /* add octree for geometry rendering */
358 < char    *ofn;
357 > dev_section(gfn, pfn)           /* add octree for geometry rendering */
358 > char    *gfn, *pfn;
359   {
360          extern char     *index();
361          char    *cp;
362  
363 <        if (ofn == NULL)
364 <                otEndOctree();
365 <        else if (access(ofn, R_OK) == 0)
366 <                otNewOctree(ofn);
363 >        if (gfn == NULL) {
364 >                gmEndGeom();
365 >                gmEndPortal();
366 >                return;
367 >        }
368 >        if (access(gfn, R_OK) == 0)
369 >                gmNewGeom(gfn);
370   #ifdef DEBUG
371          else {
372 <                sprintf(errmsg, "cannot load octree \"%s\"", ofn);
372 >                sprintf(errmsg, "cannot load octree \"%s\"", gfn);
373                  error(WARNING, errmsg);
374          }
375   #endif
376 +        if (pfn != NULL)
377 +                gmNewPortal(pfn);
378   }
379  
380  
# Line 419 | Line 446 | dev_flush()                    /* flush output as appropriate */
446          if (mapped && isperspective > 0) {
447   #ifdef STEREO
448                  pushright();                    /* draw right eye */
449 <                otDrawOctrees();
449 >                ndrawn = gmDrawGeom();
450   #ifdef DOBJ
451 <                dobj_render();
451 >                ndrawn += dobj_render();
452   #endif
453 +                if (ndrawn)
454 +                        gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP);
455                  checkglerr("rendering right eye");
456                  popright();                     /* draw left eye */
457   #endif
458 <                ndrawn = otDrawOctrees();
458 >                ndrawn = gmDrawGeom();
459   #ifdef DOBJ
460                  ndrawn += dobj_render();
461   #endif
462 +                if (ndrawn)
463 +                        gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP);
464                  checkglerr("rendering base view");
465          }
466          if (mapped && viewsteady) {
# Line 474 | Line 505 | static
505   xferdepth()                     /* load and clear depth buffer */
506   {
507          register GLfloat        *dbp;
508 +        register GLubyte        *cbuf;
509  
510 <        if (depthbuffer == NULL) {
510 >        if (depthbuffer == NULL) {      /* allocate private depth buffer */
511   #ifdef STEREO
512                  depthright = (GLfloat *)malloc(
513                                  odev.hres*odev.vres*sizeof(GLfloat));
# Line 485 | Line 517 | xferdepth()                    /* load and clear depth buffer */
517                  if (depthbuffer == NULL)
518                          error(SYSTEM, "out of memory in xferdepth");
519          }
520 +                                /* allocate alpha buffer for portals */
521 +        if (gmPortals)
522 +                cbuf = (GLubyte *)malloc(odev.hres*odev.vres*
523 +                                                        (4*sizeof(GLubyte)));
524 +        else
525 +                cbuf = NULL;
526   #ifdef STEREO
527          setstereobuf(STEREO_BUFFER_RIGHT);
528          glReadPixels(0, 0, odev.hres, odev.vres,
529                          GL_DEPTH_COMPONENT, GL_FLOAT, depthright);
530 <        setstereobuf(STEREO_BUFFER_LEFT);
530 >        if (cbuf != NULL)
531 >                glReadPixels(0, 0, odev.hres, odev.vres,
532 >                                GL_RGBA, GL_UNSIGNED_BYTE, cbuf);
533          for (dbp = depthright + odev.hres*odev.vres; dbp-- > depthright; )
534 <                *dbp = mapdepth(*dbp);
535 <        odDepthMap(1, depthright);
534 >                if (cbuf != NULL && isportal(cbuf+4*(dbp-depthright)))
535 >                        *dbp = FHUGE;
536 >                else
537 >                        *dbp = mapdepth(*dbp);
538          glClear(GL_DEPTH_BUFFER_BIT);
539 +        setstereobuf(STEREO_BUFFER_LEFT);
540 +        odDepthMap(1, depthright);
541   #endif
542 +                                /* read back depth buffer */
543          glReadPixels(0, 0, odev.hres, odev.vres,
544                          GL_DEPTH_COMPONENT, GL_FLOAT, depthbuffer);
545 +        if (cbuf != NULL)
546 +                glReadPixels(0, 0, odev.hres, odev.vres,
547 +                                GL_RGBA, GL_UNSIGNED_BYTE, cbuf);
548          for (dbp = depthbuffer + odev.hres*odev.vres; dbp-- > depthbuffer; )
549 <                *dbp = mapdepth(*dbp);
549 >                if (cbuf != NULL && isportal(cbuf+4*(dbp-depthbuffer)))
550 >                        *dbp = FHUGE;
551 >                else
552 >                        *dbp = mapdepth(*dbp);
553 >        glClear(GL_DEPTH_BUFFER_BIT);           /* clear system depth buffer */
554 >        if (cbuf != NULL)
555 >                free((char *)cbuf);             /* free our color buffer */
556          odDepthMap(0, depthbuffer);             /* transfer depth data */
503        glClear(GL_DEPTH_BUFFER_BIT);           /* clear system buffer */
557   }
558  
559  
560 + static
561 + freedepth()                             /* free recorded depth buffer */
562 + {
563 +        if (depthbuffer == NULL)
564 +                return;
565 + #ifdef STEREO
566 +        odDepthMap(1, NULL);
567 +        free((char *)depthright);
568 +        depthright = NULL;
569 + #endif
570 +        odDepthMap(0, NULL);
571 +        free((char *)depthbuffer);
572 +        depthbuffer = NULL;
573 + }
574 +
575 +
576   static double
577   getdistance(dx, dy, direc)      /* distance from fore plane along view ray */
578   int     dx, dy;
579   FVECT   direc;
580   {
581          GLfloat gldepth;
582 +        GLubyte glcolor[4];
583          double  dist;
584  
585          if (dx<0 | dx>=odev.hres | dy<0 | dy>=odev.vres)
# Line 519 | Line 589 | FVECT  direc;
589          else {
590                  glReadPixels(dx,dy, 1,1, GL_DEPTH_COMPONENT,
591                                  GL_FLOAT, &gldepth);
592 +                if (gmPortals) {
593 +                        glReadPixels(dx,dy, 1,1, GL_RGBA,
594 +                                        GL_UNSIGNED_BYTE, glcolor);
595 +                        if (isportal(glcolor))
596 +                                return(FHUGE);
597 +                }
598                  dist = mapdepth(gldepth);
599          }
600          if (dist >= .99*FHUGE)
# Line 594 | Line 670 | getevent()                     /* get next event */
670                  mapped = 0;
671                  break;
672          case MapNotify:
673 +                odRemap(0);
674                  mapped = 1;
675                  break;
676          case Expose:
# Line 689 | Line 766 | int    dx, dy, mov, orb;
766          if (setview(&nv) != NULL)
767                  return(0);      /* illegal view */
768          dev_view(&nv);
769 <        inpresflags |= DFL(DC_SETVIEW)|DFL(DC_REDRAW);
769 >        inpresflags |= DFL(DC_SETVIEW);
770          return(1);
771   }
772  
# Line 723 | Line 800 | XButtonPressedEvent    *ebut;
800   {
801          int     movdir = MOVDIR(ebut->button);
802          int     movorb = MOVORB(ebut->state);
803 +        int     ndrawn;
804          Window  rootw, childw;
805          int     rootx, rooty, wx, wy;
806          unsigned int    statemask;
# Line 746 | Line 824 | XButtonPressedEvent    *ebut;
824   #ifdef STEREO
825                  pushright();
826                  draw_grids(1);
827 <                otDrawOctrees();
827 >                ndrawn = gmDrawGeom();
828   #ifdef DOBJ
829 <                dobj_render();
829 >                ndrawn += dobj_render();
830   #endif
831 +                if (ndrawn)
832 +                        gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP);
833                  popright();
834   #endif
835                                          /* redraw octrees */
836 <                otDrawOctrees();
836 >                ndrawn = gmDrawGeom();
837   #ifdef DOBJ
838 <                dobj_render();          /* redraw objects */
838 >                ndrawn += dobj_render();        /* redraw objects */
839   #endif
840 +                if (ndrawn)
841 +                        gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP);
842                  glFlush();
843 +                if (!ndrawn) {
844 +                        sleep(1);       /* for reasonable interaction */
845 + #ifdef STEREO
846 +                        pushright();
847 +                        draw_grids(0);
848 +                        popright();
849 + #endif
850 +                        draw_grids(0);
851 +                }
852          }
853          if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */
854                  movdir = MOVDIR(levptr(XButtonReleasedEvent)->button);
# Line 776 | Line 867 | register VIEW  *vp;
867          GLfloat vec[4];
868          double  depthlim[2];
869                                          /* set depth limits */
870 <        otDepthLimit(depthlim, odev.v.vp, odev.v.vdir);
870 >        gmDepthLimit(depthlim, odev.v.vp, odev.v.vdir);
871          if (depthlim[0] >= depthlim[1]) {
872                  dev_zmin = 1.;
873                  dev_zmax = 100.;
874          } else {
875                  dev_zmin = 0.5*depthlim[0];
876 <                dev_zmax = 1.5*depthlim[1];
876 >                dev_zmax = 1.75*depthlim[1];
877                  if (dev_zmin > dev_zmax/5.)
878                          dev_zmin = dev_zmax/5.;
879          }
# Line 857 | Line 948 | wipeclean()                    /* prepare for redraw */
948          glClear(GL_DEPTH_BUFFER_BIT);
949          if (viewsteady)                 /* clear samples if steady */
950                  odClean();
951 <        if (depthbuffer != NULL) {      /* free recorded depth buffer */
861 < #ifdef STEREO
862 <                odDepthMap(1, NULL);
863 <                free((char *)depthright);
864 <                depthright = NULL;
865 < #endif
866 <                odDepthMap(0, NULL);
867 <                free((char *)depthbuffer);
868 <                depthbuffer = NULL;
869 <        }
951 >        freedepth();
952          setglpersp(&odev.v);            /* reset view & clipping planes */
953   }
954  
# Line 917 | Line 999 | register XKeyPressedEvent  *ekey;
999                  inpresflags |= DFL(DC_RESUME);
1000                  return;
1001          case CTRL('R'):                 /* redraw screen */
1002 <                odRemap();
1002 >                odRemap(0);
1003                  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
1004   #ifdef STEREO
1005                  setstereobuf(STEREO_BUFFER_RIGHT);
# Line 932 | Line 1014 | register XKeyPressedEvent  *ekey;
1014                  XFlush(ourdisplay);
1015                  sleep(1);
1016                  wipeclean();                    /* fresh display */
1017 <                odRemap();                      /* new tone mapping */
1017 >                odRemap(1);                     /* fresh tone mapping */
1018                  dev_flush();                    /* draw octrees */
1019                  inpresflags |= DFL(DC_REDRAW);  /* resend values from server */
1020                  rayqleft = 0;                   /* hold off update */
# Line 969 | Line 1051 | register XExposeEvent  *eexp;
1051          xmin = eexp->x; xmax = eexp->x + eexp->width;
1052          ymin = odev.vres - eexp->y - eexp->height; ymax = odev.vres - eexp->y;
1053                                                  /* clear portion of depth */
1054 +        glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
1055          glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
1056          glDepthFunc(GL_ALWAYS);
1057          glBegin(GL_POLYGON);
# Line 988 | Line 1071 | register XExposeEvent  *eexp;
1071          odRedraw(1, xmin, ymin, xmax, ymax);
1072          setstereobuf(STEREO_BUFFER_LEFT);
1073   #endif
1074 <        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
992 <        glDepthFunc(GL_LEQUAL);
1074 >        glPopAttrib();
1075          odRedraw(0, xmin, ymin, xmax, ymax);
1076   }
1077  
# Line 1009 | Line 1091 | register XConfigureEvent  *ersz;
1091          odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres);
1092          odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
1093  
1094 <        inpresflags |= DFL(DC_SETVIEW)|DFL(DC_REDRAW);
1094 >        inpresflags |= DFL(DC_SETVIEW);
1095   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines