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.2 by gwlarson, Sun Dec 20 20:36:48 1998 UTC vs.
Revision 3.4 by gwlarson, Mon Dec 21 15:10:13 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 130 | 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 245 | Line 262 | char  *id;
262          XMapWindow(ourdisplay, gwind);
263          dev_input();                    /* sets size and view angles */
264          if (!odInit(DisplayWidth(ourdisplay,ourscreen) *
265 <                        DisplayHeight(ourdisplay,ourscreen) / 10))
265 >                        DisplayHeight(ourdisplay,ourscreen) / 4))
266                  error(SYSTEM, "insufficient memory for value storage");
267          odev.name = id;
268          odev.firstuse = 1;              /* can't recycle samples */
# Line 346 | Line 363 | char   *gfn, *pfn;
363          if (gfn == NULL) {
364                  gmEndGeom();
365                  gmEndPortal();
366 +                wipeclean();            /* new geometry, so redraw it */
367                  return;
368          }
369          if (access(gfn, R_OK) == 0)
# Line 429 | Line 447 | dev_flush()                    /* flush output as appropriate */
447          if (mapped && isperspective > 0) {
448   #ifdef STEREO
449                  pushright();                    /* draw right eye */
450 <                gmDrawGeom(0);
450 >                ndrawn = gmDrawGeom();
451   #ifdef DOBJ
452 <                dobj_render();
452 >                ndrawn += dobj_render();
453   #endif
454 +                if (ndrawn)
455 +                        gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP);
456                  checkglerr("rendering right eye");
457                  popright();                     /* draw left eye */
458   #endif
459 <                ndrawn = gmDrawGeom(1);
459 >                ndrawn = gmDrawGeom();
460   #ifdef DOBJ
461                  ndrawn += dobj_render();
462   #endif
463 +                if (ndrawn)
464 +                        gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP);
465                  checkglerr("rendering base view");
466          }
467 <        if (mapped && viewsteady) {
468 <                if (isperspective) {            /* first time after steady */
447 < #ifdef STEREO
448 <                        pushright();
449 <                        popright();
450 < #endif
467 >        if (mapped && viewsteady)
468 >                if (isperspective > 0) {        /* first time after steady */
469                          if (ndrawn)
470                                  xferdepth();    /* transfer and clear depth */
471                          setglortho();           /* set orthographic view */
472 <                } else {
472 >                } else if (!isperspective) {
473   #ifdef STEREO
474                          pushright();
475                          odUpdate(1);            /* draw right eye */
# Line 459 | Line 477 | dev_flush()                    /* flush output as appropriate */
477   #endif
478                          odUpdate(0);            /* draw left eye */
479                  }
462        }
480          glFlush();                              /* flush OpenGL */
481          rayqleft = RAYQLEN;
482                                          /* flush X11 and return # pending */
# Line 484 | Line 501 | static
501   xferdepth()                     /* load and clear depth buffer */
502   {
503          register GLfloat        *dbp;
504 <        register GLubyte        *abuf;
504 >        register GLubyte        *cbuf;
505  
506 <        if (depthbuffer == NULL) {
506 >        if (depthbuffer == NULL) {      /* allocate private depth buffer */
507   #ifdef STEREO
508                  depthright = (GLfloat *)malloc(
509                                  odev.hres*odev.vres*sizeof(GLfloat));
# Line 496 | Line 513 | xferdepth()                    /* load and clear depth buffer */
513                  if (depthbuffer == NULL)
514                          error(SYSTEM, "out of memory in xferdepth");
515          }
516 +                                /* allocate alpha buffer for portals */
517 +        if (gmPortals)
518 +                cbuf = (GLubyte *)malloc(odev.hres*odev.vres*
519 +                                                        (4*sizeof(GLubyte)));
520 +        else
521 +                cbuf = NULL;
522   #ifdef STEREO
523          setstereobuf(STEREO_BUFFER_RIGHT);
524          glReadPixels(0, 0, odev.hres, odev.vres,
525                          GL_DEPTH_COMPONENT, GL_FLOAT, depthright);
526 <        setstereobuf(STEREO_BUFFER_LEFT);
526 >        if (cbuf != NULL)
527 >                glReadPixels(0, 0, odev.hres, odev.vres,
528 >                                GL_RGBA, GL_UNSIGNED_BYTE, cbuf);
529          for (dbp = depthright + odev.hres*odev.vres; dbp-- > depthright; )
530 <                *dbp = mapdepth(*dbp);
531 <        odDepthMap(1, depthright);
530 >                if (cbuf != NULL && isportal(cbuf+4*(dbp-depthright)))
531 >                        *dbp = FHUGE;
532 >                else
533 >                        *dbp = mapdepth(*dbp);
534          glClear(GL_DEPTH_BUFFER_BIT);
535 +        setstereobuf(STEREO_BUFFER_LEFT);
536 +        odDepthMap(1, depthright);
537   #endif
538                                  /* read back depth buffer */
539          glReadPixels(0, 0, odev.hres, odev.vres,
540                          GL_DEPTH_COMPONENT, GL_FLOAT, depthbuffer);
541 <                                /* read alpha buffer for portals */
513 <        if (gmPortals)
514 <                abuf = (GLubyte *)malloc(odev.hres*odev.vres*sizeof(GLubyte));
515 <        else
516 <                abuf = NULL;
517 <        if (abuf != NULL)
541 >        if (cbuf != NULL)
542                  glReadPixels(0, 0, odev.hres, odev.vres,
543 <                                GL_ALPHA, GL_UNSIGNED_BYTE, abuf);
543 >                                GL_RGBA, GL_UNSIGNED_BYTE, cbuf);
544          for (dbp = depthbuffer + odev.hres*odev.vres; dbp-- > depthbuffer; )
545 <                if (abuf != NULL && abuf[dbp-depthbuffer])
545 >                if (cbuf != NULL && isportal(cbuf+4*(dbp-depthbuffer)))
546                          *dbp = FHUGE;
547                  else
548                          *dbp = mapdepth(*dbp);
549 +        glClear(GL_DEPTH_BUFFER_BIT);           /* clear system depth buffer */
550 +        if (cbuf != NULL)
551 +                free((char *)cbuf);             /* free our color buffer */
552          odDepthMap(0, depthbuffer);             /* transfer depth data */
526        glClear(GL_DEPTH_BUFFER_BIT);           /* clear system buffer */
527        if (abuf != NULL)
528                free((char *)abuf);             /* free alpha buffer */
553   }
554  
555  
# Line 551 | Line 575 | int    dx, dy;
575   FVECT   direc;
576   {
577          GLfloat gldepth;
578 <        GLubyte glalpha;
578 >        GLubyte glcolor[4];
579          double  dist;
580  
581          if (dx<0 | dx>=odev.hres | dy<0 | dy>=odev.vres)
# Line 561 | Line 585 | FVECT  direc;
585          else {
586                  glReadPixels(dx,dy, 1,1, GL_DEPTH_COMPONENT,
587                                  GL_FLOAT, &gldepth);
588 <                if (gmPortals)
589 <                        glReadPixels(dx,dy, 1,1, GL_ALPHA,
590 <                                GL_UNSIGNED_BYTE, &glalpha);
591 <                else
592 <                        glalpha = 0;
593 <                dist = glalpha ? FHUGE : mapdepth(gldepth);
588 >                if (gmPortals) {
589 >                        glReadPixels(dx,dy, 1,1, GL_RGBA,
590 >                                        GL_UNSIGNED_BYTE, glcolor);
591 >                        if (isportal(glcolor))
592 >                                return(FHUGE);
593 >                }
594 >                dist = mapdepth(gldepth);
595          }
596          if (dist >= .99*FHUGE)
597                  return(FHUGE);
# Line 795 | Line 820 | XButtonPressedEvent    *ebut;
820   #ifdef STEREO
821                  pushright();
822                  draw_grids(1);
823 <                gmDrawGeom(0);
823 >                ndrawn = gmDrawGeom();
824   #ifdef DOBJ
825 <                dobj_render();
825 >                ndrawn += dobj_render();
826   #endif
827 +                if (ndrawn)
828 +                        gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP);
829                  popright();
830   #endif
831                                          /* redraw octrees */
832 <                ndrawn = gmDrawGeom(1);
832 >                ndrawn = gmDrawGeom();
833   #ifdef DOBJ
834                  ndrawn += dobj_render();        /* redraw objects */
835   #endif
836 +                if (ndrawn)
837 +                        gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP);
838                  glFlush();
839                  if (!ndrawn) {
840                          sleep(1);       /* for reasonable interaction */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines