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.5 by gwlarson, Mon Dec 21 15:31:49 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 145 | Line 162 | char  *id;
162   #endif
163                                          /* open display server */
164          ourdisplay = XOpenDisplay(NULL);
165 <        if (ourdisplay == NULL)
166 <                error(USER, "cannot open X-windows; DISPLAY variable set?\n");
165 >        CHECK(ourdisplay==NULL, USER,
166 >                        "cannot open X-windows; DISPLAY variable set?");
167   #ifdef STEREO
168          switch (XSGIQueryStereoMode(ourdisplay, ourroot)) {
169          case STEREO_TOP:
# Line 154 | Line 171 | char  *id;
171                  break;
172          case STEREO_OFF:
173                  error(USER,
174 <        "wrong video mode: run \"/usr/gfx/setmon -n STR_TOP\" first");
174 >                "wrong video mode: run \"/usr/gfx/setmon -n STR_TOP\" first");
175          case X_STEREO_UNSUPPORTED:
176                  error(USER, "stereo mode not supported on this screen");
177          default:
# Line 163 | Line 180 | char  *id;
180   #endif
181                                          /* find a usable visual */
182          ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlBest);
183 <        if (ourvinf == NULL)
167 <                error(USER, "no suitable visuals available");
183 >        CHECK(ourvinf==NULL, USER, "no suitable visuals available");
184                                          /* get a context */
185          gctx = glXCreateContext(ourdisplay, ourvinf, NULL, GL_TRUE);
186                                          /* set gamma and tone mapping */
# Line 196 | Line 212 | char  *id;
212   #endif
213                  BORWIDTH, ourvinf->depth, InputOutput, ourvinf->visual,
214                  CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &ourwinattr);
215 <        if (gwind == 0)
200 <                error(SYSTEM, "cannot create window\n");
215 >        CHECK(gwind==0, SYSTEM, "cannot create window");
216          XStoreName(ourdisplay, gwind, id);
217                                          /* set window manager hints */
218          ourxwmhints.flags = InputHint|IconPixmapHint;
# Line 245 | Line 260 | char  *id;
260          XMapWindow(ourdisplay, gwind);
261          dev_input();                    /* sets size and view angles */
262          if (!odInit(DisplayWidth(ourdisplay,ourscreen) *
263 <                        DisplayHeight(ourdisplay,ourscreen) / 10))
263 >                        DisplayHeight(ourdisplay,ourscreen) / 4))
264                  error(SYSTEM, "insufficient memory for value storage");
265          odev.name = id;
266          odev.firstuse = 1;              /* can't recycle samples */
# Line 346 | Line 361 | char   *gfn, *pfn;
361          if (gfn == NULL) {
362                  gmEndGeom();
363                  gmEndPortal();
364 +                wipeclean();            /* new geometry, so redraw it */
365                  return;
366          }
367          if (access(gfn, R_OK) == 0)
# Line 429 | Line 445 | dev_flush()                    /* flush output as appropriate */
445          if (mapped && isperspective > 0) {
446   #ifdef STEREO
447                  pushright();                    /* draw right eye */
448 <                gmDrawGeom(0);
448 >                ndrawn = gmDrawGeom();
449   #ifdef DOBJ
450 <                dobj_render();
450 >                ndrawn += dobj_render();
451   #endif
452 +                if (ndrawn)
453 +                        gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP);
454                  checkglerr("rendering right eye");
455                  popright();                     /* draw left eye */
456   #endif
457 <                ndrawn = gmDrawGeom(1);
457 >                ndrawn = gmDrawGeom();
458   #ifdef DOBJ
459                  ndrawn += dobj_render();
460   #endif
461 +                if (ndrawn)
462 +                        gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP);
463                  checkglerr("rendering base view");
464          }
465 <        if (mapped && viewsteady) {
466 <                if (isperspective) {            /* first time after steady */
447 < #ifdef STEREO
448 <                        pushright();
449 <                        popright();
450 < #endif
465 >        if (mapped && viewsteady)
466 >                if (isperspective > 0) {        /* first time after steady */
467                          if (ndrawn)
468                                  xferdepth();    /* transfer and clear depth */
469                          setglortho();           /* set orthographic view */
470 <                } else {
470 >                } else if (!isperspective) {
471   #ifdef STEREO
472                          pushright();
473                          odUpdate(1);            /* draw right eye */
# Line 459 | Line 475 | dev_flush()                    /* flush output as appropriate */
475   #endif
476                          odUpdate(0);            /* draw left eye */
477                  }
462        }
478          glFlush();                              /* flush OpenGL */
479          rayqleft = RAYQLEN;
480                                          /* flush X11 and return # pending */
# Line 484 | Line 499 | static
499   xferdepth()                     /* load and clear depth buffer */
500   {
501          register GLfloat        *dbp;
502 <        register GLubyte        *abuf;
502 >        register GLubyte        *cbuf;
503  
504 <        if (depthbuffer == NULL) {
504 >        if (depthbuffer == NULL) {      /* allocate private depth buffer */
505   #ifdef STEREO
506                  depthright = (GLfloat *)malloc(
507                                  odev.hres*odev.vres*sizeof(GLfloat));
508   #endif
509                  depthbuffer = (GLfloat *)malloc(
510                                  odev.hres*odev.vres*sizeof(GLfloat));
511 <                if (depthbuffer == NULL)
497 <                        error(SYSTEM, "out of memory in xferdepth");
511 >                CHECK(depthbuffer==NULL, SYSTEM, "out of memory in xferdepth");
512          }
513 +                                /* allocate alpha buffer for portals */
514 +        if (gmPortals)
515 +                cbuf = (GLubyte *)malloc(odev.hres*odev.vres*
516 +                                                        (4*sizeof(GLubyte)));
517 +        else
518 +                cbuf = NULL;
519   #ifdef STEREO
520          setstereobuf(STEREO_BUFFER_RIGHT);
521          glReadPixels(0, 0, odev.hres, odev.vres,
522                          GL_DEPTH_COMPONENT, GL_FLOAT, depthright);
523 <        setstereobuf(STEREO_BUFFER_LEFT);
523 >        if (cbuf != NULL)
524 >                glReadPixels(0, 0, odev.hres, odev.vres,
525 >                                GL_RGBA, GL_UNSIGNED_BYTE, cbuf);
526          for (dbp = depthright + odev.hres*odev.vres; dbp-- > depthright; )
527 <                *dbp = mapdepth(*dbp);
528 <        odDepthMap(1, depthright);
527 >                if (cbuf != NULL && isportal(cbuf+4*(dbp-depthright)))
528 >                        *dbp = FHUGE;
529 >                else
530 >                        *dbp = mapdepth(*dbp);
531          glClear(GL_DEPTH_BUFFER_BIT);
532 +        setstereobuf(STEREO_BUFFER_LEFT);
533 +        odDepthMap(1, depthright);
534   #endif
535                                  /* read back depth buffer */
536          glReadPixels(0, 0, odev.hres, odev.vres,
537                          GL_DEPTH_COMPONENT, GL_FLOAT, depthbuffer);
538 <                                /* 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)
538 >        if (cbuf != NULL)
539                  glReadPixels(0, 0, odev.hres, odev.vres,
540 <                                GL_ALPHA, GL_UNSIGNED_BYTE, abuf);
540 >                                GL_RGBA, GL_UNSIGNED_BYTE, cbuf);
541          for (dbp = depthbuffer + odev.hres*odev.vres; dbp-- > depthbuffer; )
542 <                if (abuf != NULL && abuf[dbp-depthbuffer])
542 >                if (cbuf != NULL && isportal(cbuf+4*(dbp-depthbuffer)))
543                          *dbp = FHUGE;
544                  else
545                          *dbp = mapdepth(*dbp);
546 +        glClear(GL_DEPTH_BUFFER_BIT);           /* clear system depth buffer */
547 +        if (cbuf != NULL)
548 +                free((char *)cbuf);             /* free our color buffer */
549          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 */
550   }
551  
552  
# Line 551 | Line 572 | int    dx, dy;
572   FVECT   direc;
573   {
574          GLfloat gldepth;
575 <        GLubyte glalpha;
575 >        GLubyte glcolor[4];
576          double  dist;
577  
578          if (dx<0 | dx>=odev.hres | dy<0 | dy>=odev.vres)
# Line 561 | Line 582 | FVECT  direc;
582          else {
583                  glReadPixels(dx,dy, 1,1, GL_DEPTH_COMPONENT,
584                                  GL_FLOAT, &gldepth);
585 <                if (gmPortals)
586 <                        glReadPixels(dx,dy, 1,1, GL_ALPHA,
587 <                                GL_UNSIGNED_BYTE, &glalpha);
588 <                else
589 <                        glalpha = 0;
590 <                dist = glalpha ? FHUGE : mapdepth(gldepth);
585 >                if (gmPortals) {
586 >                        glReadPixels(dx,dy, 1,1, GL_RGBA,
587 >                                        GL_UNSIGNED_BYTE, glcolor);
588 >                        if (isportal(glcolor))
589 >                                return(FHUGE);
590 >                }
591 >                dist = mapdepth(gldepth);
592          }
593          if (dist >= .99*FHUGE)
594                  return(FHUGE);
# Line 795 | Line 817 | XButtonPressedEvent    *ebut;
817   #ifdef STEREO
818                  pushright();
819                  draw_grids(1);
820 <                gmDrawGeom(0);
820 >                ndrawn = gmDrawGeom();
821   #ifdef DOBJ
822 <                dobj_render();
822 >                ndrawn += dobj_render();
823   #endif
824 +                if (ndrawn)
825 +                        gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP);
826                  popright();
827   #endif
828                                          /* redraw octrees */
829 <                ndrawn = gmDrawGeom(1);
829 >                ndrawn = gmDrawGeom();
830   #ifdef DOBJ
831                  ndrawn += dobj_render();        /* redraw objects */
832   #endif
833 +                if (ndrawn)
834 +                        gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP);
835                  glFlush();
836                  if (!ndrawn) {
837                          sleep(1);       /* for reasonable interaction */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines