--- ray/src/hd/rhd_glx.c 1997/12/26 14:46:21 3.5 +++ ray/src/hd/rhd_glx.c 1998/05/14 13:06:33 3.17 @@ -16,6 +16,10 @@ static char SCCSid[] = "$SunId$ SGI"; #include "x11icon.h" +#ifndef RAYQLEN +#define RAYQLEN 50000 /* max. rays to queue before flush */ +#endif + #ifndef FEQ #define FEQ(a,b) ((a)-(b) <= FTINY && (a)-(b) >= -FTINY) #endif @@ -24,7 +28,7 @@ static char SCCSid[] = "$SunId$ SGI"; #define MAXCONE 16 /* number of different cone sizes */ #endif #ifndef MAXVERT -#define MAXVERT 32 /* maximum number of cone vertices */ +#define MAXVERT 64 /* maximum number of cone vertices */ #endif #ifndef MINVERT #define MINVERT 4 /* minimum number of cone vertices */ @@ -90,16 +94,19 @@ dev_open(id) /* initialize X11 driver */ char *id; { extern char *getenv(); + static RGBPRIMS myprims = STDPRIMS; static int atlBest[] = {GLX_RGBA, GLX_RED_SIZE,8, GLX_GREEN_SIZE,8, GLX_BLUE_SIZE,8, GLX_DEPTH_SIZE,15, None}; - char *gv; + char *ev; double gamval = GAMMA; + RGBPRIMP dpri = stdprims; XSetWindowAttributes ourwinattr; XWMHints ourxwmhints; XSizeHints oursizhints; /* set quadtree globals */ qtMinNodesiz = 3; + qtDepthEps = 0.07; /* open display server */ ourdisplay = XOpenDisplay(NULL); if (ourdisplay == NULL) @@ -111,10 +118,17 @@ char *id; /* get a context */ gctx = glXCreateContext(ourdisplay, ourvinf, NULL, GL_TRUE); /* set gamma and tone mapping */ - if ((gv = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL - || (gv = getenv("DISPLAY_GAMMA")) != NULL) - gamval = atof(gv); - if (tmInit(mytmflags(), stdprims, gamval) == NULL) + if ((ev = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL + || (ev = getenv("DISPLAY_GAMMA")) != NULL) + gamval = atof(ev); + if ((ev = getenv("DISPLAY_PRIMARIES")) != NULL && + sscanf(ev, "%f %f %f %f %f %f %f %f", + &myprims[RED][CIEX],&myprims[RED][CIEY], + &myprims[GRN][CIEX],&myprims[GRN][CIEY], + &myprims[BLU][CIEX],&myprims[BLU][CIEY], + &myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6) + dpri = myprims; + if (tmInit(mytmflags(), dpri, gamval) == NULL) error(SYSTEM, "not enough memory in dev_open"); /* open window */ ourwinattr.background_pixel = ourblack; @@ -161,11 +175,10 @@ char *id; /* map the window */ XMapWindow(ourdisplay, gwind); dev_input(); /* sets size and view angles */ - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* allocate our leaf pile */ - if (!qtAllocLeaves(2 * DisplayWidth(ourdisplay,ourscreen) * - DisplayHeight(ourdisplay,ourscreen) / - (qtMinNodesiz*qtMinNodesiz))) + if (!qtAllocLeaves(DisplayWidth(ourdisplay,ourscreen) * + DisplayHeight(ourdisplay,ourscreen) * 3 / + (qtMinNodesiz*qtMinNodesiz*2))) error(SYSTEM, "insufficient memory for value storage"); odev.name = id; odev.ifd = ConnectionNumber(ourdisplay); @@ -191,6 +204,14 @@ dev_close() /* close our display and free resources } +dev_clear() /* clear our quadtree */ +{ + qtCompost(100); + glClear(GL_DEPTH_BUFFER_BIT); + rayqleft = 0; /* hold off update */ +} + + int dev_view(nv) /* assign new driver view */ register VIEW *nv; @@ -243,6 +264,18 @@ register VIEW *nv; } +VIEW * +dev_auxview(n, hvres) /* return nth auxiliary view */ +int n; +int hvres[2]; +{ + if (n) + return(NULL); + hvres[0] = odev.hres; hvres[1] = odev.vres; + return(&odev.v); +} + + int dev_input() /* get X11 input */ { @@ -262,6 +295,7 @@ dev_flush() /* flush output */ { qtUpdate(); glFlush(); + rayqleft = RAYQLEN; return(XPending(ourdisplay)); } @@ -273,6 +307,9 @@ double rad; { register int ci, j; double apexh, basez; + /* is window mapped? */ + if (!mapped) + return; /* compute apex height (0. to 1.) */ if (ip[2] > 1e6) apexh = 1. - 1./DEPTHFACT; @@ -314,9 +351,9 @@ mytmflags() /* figure out tone mapping flags */ for (cp = tail; *cp && *cp != '.'; cp++) ; if (cp-tail == 3 && !strncmp(tail, "glx", 3)) - return(TM_F_CAMERA); + return(TM_F_CAMERA|TM_F_NOSTDERR); if (cp-tail == 4 && !strncmp(tail, "glxh", 4)) - return(TM_F_HUMAN); + return(TM_F_HUMAN|TM_F_NOSTDERR); error(USER, "illegal driver name"); } @@ -334,7 +371,7 @@ initcones() /* initialize cone vertices */ for (i = 0; i < MAXCONE; i++) { d = (double)i/(MAXCONE-1); d *= d; /* x^2 distribution */ cone[i].rad = minrad + (1.-minrad)*d; - cone[i].nverts = MINVERT + (MAXVERT-MINVERT)*d; + cone[i].nverts = MINVERT + 0.5 + (MAXVERT-MINVERT)*d; cone[i].va = (FVECT *)malloc(cone[i].nverts*sizeof(FVECT)); if (cone[i].va == NULL) error(SYSTEM, "out of memory in initcones"); @@ -567,17 +604,26 @@ register XKeyPressedEvent *ekey; inpresflags |= DFL(DC_RESUME); return; case CTRL('R'): /* redraw screen */ + if (nxtzmax > FTINY) { + curzmax = nxtzmax; + nxtzmax = 0.; + } glClear(GL_DEPTH_BUFFER_BIT); qtRedraw(0, 0, odev.hres, odev.vres); return; case CTRL('L'): /* refresh from server */ if (inpresflags & DFL(DC_REDRAW)) return; + if (nxtzmax > FTINY) { + curzmax = nxtzmax; + nxtzmax = 0.; + } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); draw_grids(); glFlush(); qtCompost(100); /* get rid of old values */ inpresflags |= DFL(DC_REDRAW); /* resend values from server */ + rayqleft = 0; /* hold off update */ return; case 'K': /* kill rtrace process(es) */ inpresflags |= DFL(DC_KILL); @@ -627,6 +673,8 @@ static resizewindow(ersz) /* resize window */ register XConfigureEvent *ersz; { + glViewport(0, 0, ersz->width, ersz->height); + if (ersz->width == odev.hres && ersz->height == odev.vres) return; @@ -635,8 +683,6 @@ register XConfigureEvent *ersz; odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres); odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres); - - glViewport(0, 0, odev.hres, odev.vres); inpresflags |= DFL(DC_SETVIEW); }