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.13 by gwlarson, Fri Jan 1 10:41:28 1999 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1998 Silicon Graphics, Inc. */
1 > /* Copyright (c) 1999 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ SGI";
# Line 37 | Line 37 | static char SCCSid[] = "$SunId$ SGI";
37   #include "x11icon.h"
38  
39   #ifndef RAYQLEN
40 < #define RAYQLEN         50000           /* max. rays to queue before flush */
40 > #define RAYQLEN         0               /* 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
43   #ifndef FEQ
44   #define FEQ(a,b)        ((a)-(b) <= FTINY && (a)-(b) >= -FTINY)
45   #endif
# Line 143 | Line 132 | char  *id;
132   {
133          extern char     *getenv();
134          static RGBPRIMS myprims = STDPRIMS;
146 #if (PORTALP<0)
135          static int      atlBest[] = {GLX_RGBA, GLX_DOUBLEBUFFER,
136                                  GLX_RED_SIZE,8, GLX_GREEN_SIZE,8,
137                                  GLX_BLUE_SIZE,8, GLX_DEPTH_SIZE,15, None};
138          static int      atlOK[] = {GLX_RGBA, GLX_DOUBLEBUFFER,
139                                  GLX_RED_SIZE,4, GLX_GREEN_SIZE,4,
140                                  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
141          char    *ev;
142          double  gamval = GAMMA;
143          RGBPRIMP        dpri = stdprims;
# Line 248 | Line 226 | char  *id;
226          glXMakeCurrent(ourdisplay, gwind, gctx);
227          glEnable(GL_DEPTH_TEST);
228          glDepthFunc(GL_LEQUAL);
229 <        glEnable(GL_DITHER);
229 >        glClearColor(0, 0, 0, 0);
230          glFrontFace(GL_CCW);
231          glDisable(GL_CULL_FACE);
232          glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
233          glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
234 +        glPixelStorei(GL_PACK_ALIGNMENT, 1);
235 +        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
236                                          /* figure out sensible view */
237          pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
238                          DisplayWidth(ourdisplay, ourscreen);
# Line 270 | Line 250 | char  *id;
250          XMapWindow(ourdisplay, gwind);
251          dev_input();                    /* sets size and view angles */
252          if (!odInit(DisplayWidth(ourdisplay,ourscreen) *
253 <                        DisplayHeight(ourdisplay,ourscreen) / 4))
253 >                        DisplayHeight(ourdisplay,ourscreen) / 3))
254                  error(SYSTEM, "insufficient memory for value storage");
255          odev.name = id;
256          odev.firstuse = 1;              /* can't recycle samples */
# Line 302 | Line 282 | dev_close()                    /* close our display and free resources
282  
283   dev_clear()                     /* clear our representation */
284   {
285 <        wipeclean();
285 >        viewflags |= VWCHANGE;          /* pretend our view has changed */
286 >        wipeclean();                    /* clean off display and samples */
287 >        dev_flush();                    /* redraw geometry & get depth */
288          rayqleft = 0;                   /* hold off update */
289   }
290  
# Line 391 | Line 373 | dev_auxcom(cmd, args)          /* process an auxiliary command
373   char    *cmd, *args;
374   {
375   #ifdef DOBJ
376 <        if (dobj_command(cmd, args) >= 0)
376 >        int     vischange;
377 >
378 >        if ((vischange = dobj_command(cmd, args)) >= 0) {
379 >                if (vischange) {
380 >                        imm_mode = beam_sync(1) > 0;
381 >                        dev_clear();
382 >                }
383                  return;
384 +        }
385   #endif
386          sprintf(errmsg, "%s: unknown command", cmd);
387          error(COMMAND, errmsg);
# Line 459 | Line 448 | dev_flush()                    /* flush output as appropriate */
448   #ifdef DOBJ
449                  ndrawn += dobj_render();
450   #endif
462                if (ndrawn && gmPortals)
463                        gmDrawPortals(PORTRED,PORTGRN,PORTBLU,PORTALP);
451                  checkglerr("rendering right eye");
452                  popright();                     /* draw left eye */
453   #endif
# Line 468 | Line 455 | dev_flush()                    /* flush output as appropriate */
455   #ifdef DOBJ
456                  ndrawn += dobj_render();
457   #endif
471                if (ndrawn && gmPortals)
472                        gmDrawPortals(PORTRED,PORTGRN,PORTBLU,PORTALP);
458                  glXSwapBuffers(ourdisplay, gwind);
459                  checkglerr("rendering base view");
460          }
# Line 515 | Line 500 | static
500   xferdepth()                     /* load and clear depth buffer */
501   {
502          register GLfloat        *dbp;
503 <        register GLubyte        *cbuf;
503 >        register GLubyte        *pbuf;
504  
505          if (depthbuffer == NULL) {      /* allocate private depth buffer */
506   #ifdef STEREO
# Line 528 | Line 513 | xferdepth()                    /* load and clear depth buffer */
513          }
514                                  /* allocate alpha buffer for portals */
515          if (gmPortals)
516 <                cbuf = (GLubyte *)malloc(odev.hres*odev.vres *
532 <                                                        (4*sizeof(GLubyte)));
516 >                pbuf = (GLubyte *)malloc(odev.hres*odev.vres*sizeof(GLubyte));
517          else
518 <                cbuf = NULL;
518 >                pbuf = NULL;
519   #ifdef STEREO
520 <        setstereobuf(STEREO_BUFFER_RIGHT);
520 >        pushright();
521          glReadPixels(0, 0, odev.hres, odev.vres,
522                          GL_DEPTH_COMPONENT, GL_FLOAT, depthright);
523 <        if (cbuf != NULL)
523 >        if (pbuf != NULL) {
524 >                glClear(GL_COLOR_BUFFER_BIT);
525 >                gmDrawPortals(0xff, -1, -1, -1);
526                  glReadPixels(0, 0, odev.hres, odev.vres,
527 <                                GL_RGBA, GL_UNSIGNED_BYTE, cbuf);
527 >                                GL_RED, GL_UNSIGNED_BYTE, pbuf);
528 >        }
529          for (dbp = depthright + odev.hres*odev.vres; dbp-- > depthright; )
530 <                if (cbuf != NULL && isportal(cbuf+4*(dbp-depthright)))
530 >                if (pbuf != NULL && pbuf[dbp-depthright]&0x40)
531                          *dbp = FHUGE;
532                  else
533                          *dbp = mapdepth(*dbp);
534          glClear(GL_DEPTH_BUFFER_BIT);
548        setstereobuf(STEREO_BUFFER_LEFT);
535          odDepthMap(1, depthright);
536 +        popright();
537   #endif
538                                  /* read back depth buffer */
539          glReadPixels(0, 0, odev.hres, odev.vres,
540                          GL_DEPTH_COMPONENT, GL_FLOAT, depthbuffer);
541 <        if (cbuf != NULL)
541 >        if (pbuf != NULL) {
542 >                glClear(GL_COLOR_BUFFER_BIT);           /* find portals */
543 >                gmDrawPortals(0xff, -1, -1, -1);
544                  glReadPixels(0, 0, odev.hres, odev.vres,
545 <                                GL_RGBA, GL_UNSIGNED_BYTE, cbuf);
545 >                                GL_RED, GL_UNSIGNED_BYTE, pbuf);
546 > #ifdef DEBUG
547 >                glXSwapBuffers(ourdisplay, gwind);
548 > #endif
549 >        }
550          for (dbp = depthbuffer + odev.hres*odev.vres; dbp-- > depthbuffer; )
551 <                if (cbuf != NULL && isportal(cbuf+4*(dbp-depthbuffer)))
551 >                if (pbuf != NULL && pbuf[dbp-depthbuffer]&0x40)
552                          *dbp = FHUGE;
553                  else
554                          *dbp = mapdepth(*dbp);
555          glClear(GL_DEPTH_BUFFER_BIT);           /* clear system depth buffer */
563        if (cbuf != NULL)
564                free((char *)cbuf);             /* free our color buffer */
556          odDepthMap(0, depthbuffer);             /* transfer depth data */
557 +        if (pbuf != NULL)
558 +                free((char *)pbuf);             /* free our portal buffer */
559   }
560  
561  
# Line 588 | Line 581 | int    dx, dy;
581   FVECT   direc;
582   {
583          GLfloat gldepth;
591        GLubyte glcolor[4];
584          double  dist;
585  
586          if (dx<0 | dx>=odev.hres | dy<0 | dy>=odev.vres)
# Line 598 | Line 590 | FVECT  direc;
590          else {
591                  glReadPixels(dx,dy, 1,1, GL_DEPTH_COMPONENT,
592                                  GL_FLOAT, &gldepth);
601                if (gmPortals) {
602                        glReadPixels(dx,dy, 1,1, GL_RGBA,
603                                        GL_UNSIGNED_BYTE, glcolor);
604                        if (isportal(glcolor))
605                                return(FHUGE);
606                }
593                  dist = mapdepth(gldepth);
594          }
595          if (dist >= .99*FHUGE)
# Line 714 | Line 700 | int    fore;
700          glPushAttrib(GL_LIGHTING_BIT|GL_ENABLE_BIT);
701          glDisable(GL_LIGHTING);
702          if (fore)
703 <                glColor3ub(0, 255, 255);
703 >                glColor3ub(4, 250, 250);
704          else
705                  glColor3ub(0, 0, 0);
706          glBegin(GL_LINES);              /* draw each grid line */
# Line 817 | Line 803 | XButtonPressedEvent    *ebut;
803          XNoOp(ourdisplay);              /* makes sure we're not idle */
804  
805          viewflags &= ~VWSTEADY;         /* flag moving view */
806 <        setglpersp(&odev.v);            /* start us off in perspective */
806 >        setglpersp();                   /* start us off in perspective */
807          while (!XCheckMaskEvent(ourdisplay,
808                          ButtonReleaseMask, levptr(XEvent))) {
809                                          /* get cursor position */
# Line 837 | Line 823 | XButtonPressedEvent    *ebut;
823   #ifdef DOBJ
824                  ndrawn += dobj_render();
825   #endif
840                if (ndrawn && gmPortals)
841                        gmDrawPortals(PORTRED,PORTGRN,PORTBLU,PORTALP);
826                  popright();
827   #endif
828                                          /* redraw octrees */
# Line 846 | Line 830 | XButtonPressedEvent    *ebut;
830   #ifdef DOBJ
831                  ndrawn += dobj_render();        /* redraw objects */
832   #endif
849                if (ndrawn && gmPortals)
850                        gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP);
833                  glXSwapBuffers(ourdisplay, gwind);
834                  if (!ndrawn)
835                          sleep(1);       /* for reasonable interaction */
# Line 863 | Line 845 | XButtonPressedEvent    *ebut;
845  
846  
847   static
848 < setglpersp(vp)                  /* set perspective view in GL */
867 < register VIEW   *vp;
848 > setglpersp()                    /* set perspective view in GL */
849   {
850          double  d, xmin, xmax, ymin, ymax;
851          GLfloat vec[4];
# Line 876 | Line 857 | register VIEW  *vp;
857                  dev_zmax = 100.;
858          } else {
859                  dev_zmin = 0.5*depthlim[0];
860 <                dev_zmax = 1.75*depthlim[1];
860 >                dev_zmax = 1.25*depthlim[1];
861                  if (dev_zmin > dev_zmax/5.)
862                          dev_zmin = dev_zmax/5.;
863          }
# Line 946 | Line 927 | static
927   wipeclean()                     /* prepare for redraw */
928   {
929          glDrawBuffer(GL_BACK);          /* use double-buffer mode */
930 +        glReadBuffer(GL_BACK);
931                                          /* clear buffers */
932   #ifdef STEREO
933          setstereobuf(STEREO_BUFFER_RIGHT);
# Line 958 | Line 940 | wipeclean()                    /* prepare for redraw */
940                          (VWCHANGE|VWSTEADY)) {  /* clear samples if new */
941                  odClean();
942                  viewflags &= ~VWCHANGE;         /* change noted */
943 <        }
943 >        } else if (viewflags & VWSTEADY)
944 >                odRedrawAll();
945          setglpersp(&odev.v);            /* reset view & clipping planes */
946   }
947  
# Line 1009 | Line 992 | register XKeyPressedEvent  *ekey;
992                  inpresflags |= DFL(DC_RESUME);
993                  return;
994          case CTRL('R'):                 /* redraw screen */
995 <                odRemap(0);
995 >                odRemap(0);                     /* new tone mapping */
996                  glClear(GL_DEPTH_BUFFER_BIT);
997   #ifdef STEREO
998                  setstereobuf(STEREO_BUFFER_RIGHT);
# Line 1019 | Line 1002 | register XKeyPressedEvent  *ekey;
1002                  return;
1003          case CTRL('L'):                 /* refresh from server */
1004                  if (inpresflags & DFL(DC_REDRAW))
1005 <                        return;
1005 >                        return;                 /* already called */
1006                  XRaiseWindow(ourdisplay, gwind);
1007 <                XFlush(ourdisplay);
1008 <                sleep(1);
1009 <                wipeclean();                    /* fresh display */
1010 <                odRemap(1);                     /* fresh tone mapping */
1028 <                dev_flush();                    /* draw octrees */
1007 >                XFlush(ourdisplay);             /* raise up window */
1008 >                sleep(1);                       /* wait for restacking */
1009 >                dev_clear();                    /* clear buffer and samples */
1010 >                odRemap(1);                     /* start fresh histogram */
1011                  inpresflags |= DFL(DC_REDRAW);  /* resend values from server */
1030                rayqleft = 0;                   /* hold off update */
1012                  return;
1013          case 'K':                       /* kill rtrace process(es) */
1014                  inpresflags |= DFL(DC_KILL);
# Line 1060 | Line 1041 | register XExposeEvent  *eexp;
1041          }
1042          xmin = eexp->x; xmax = eexp->x + eexp->width;
1043          ymin = odev.vres - eexp->y - eexp->height; ymax = odev.vres - eexp->y;
1044 +
1045 +        if (xmin <= 0 && xmax >= odev.hres-1 &&
1046 +                        ymin <= 0 && ymax >= odev.vres) {
1047 +                DCHECK(eexp->count, WARNING, "multiple clear in fixwindow");
1048 +                wipeclean();                    /* make sure we're go */
1049 +                return;
1050 +        }
1051                                                  /* clear portion of depth */
1052          glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
1053          glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines