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 |
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(); |
131 |
|
static int pushright(), popright(); |
132 |
|
#endif |
133 |
|
|
134 |
+ |
extern int gmPortals; /* GL portal list id */ |
135 |
+ |
|
136 |
|
extern time_t time(); |
137 |
|
|
138 |
|
|
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; |
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: |
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: |
180 |
|
#endif |
181 |
|
/* find a usable visual */ |
182 |
|
ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlBest); |
183 |
< |
if (ourvinf == NULL) |
165 |
< |
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 */ |
212 |
|
#endif |
213 |
|
BORWIDTH, ourvinf->depth, InputOutput, ourvinf->visual, |
214 |
|
CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &ourwinattr); |
215 |
< |
if (gwind == 0) |
198 |
< |
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; |
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 */ |
273 |
|
#ifdef DOBJ |
274 |
|
dobj_cleanup(); |
275 |
|
#endif |
276 |
+ |
freedepth(); |
277 |
+ |
gmEndGeom(); |
278 |
+ |
gmEndPortal(); |
279 |
|
odDone(); |
280 |
|
glXMakeCurrent(ourdisplay, None, NULL); |
281 |
|
glXDestroyContext(ourdisplay, gctx); |
352 |
|
} |
353 |
|
|
354 |
|
|
355 |
< |
dev_section(ofn) /* add octree for geometry rendering */ |
356 |
< |
char *ofn; |
355 |
> |
dev_section(gfn, pfn) /* add octree for geometry rendering */ |
356 |
> |
char *gfn, *pfn; |
357 |
|
{ |
358 |
|
extern char *index(); |
359 |
|
char *cp; |
360 |
|
|
361 |
< |
if (ofn == NULL) |
362 |
< |
otEndOctree(); |
363 |
< |
else if (access(ofn, R_OK) == 0) |
364 |
< |
otNewOctree(ofn); |
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) |
368 |
> |
gmNewGeom(gfn); |
369 |
|
#ifdef DEBUG |
370 |
|
else { |
371 |
< |
sprintf(errmsg, "cannot load octree \"%s\"", ofn); |
371 |
> |
sprintf(errmsg, "cannot load octree \"%s\"", gfn); |
372 |
|
error(WARNING, errmsg); |
373 |
|
} |
374 |
|
#endif |
375 |
+ |
if (pfn != NULL) |
376 |
+ |
gmNewPortal(pfn); |
377 |
|
} |
378 |
|
|
379 |
|
|
445 |
|
if (mapped && isperspective > 0) { |
446 |
|
#ifdef STEREO |
447 |
|
pushright(); /* draw right eye */ |
448 |
< |
otDrawOctrees(); |
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 = otDrawOctrees(); |
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 */ |
437 |
< |
#ifdef STEREO |
438 |
< |
pushright(); |
439 |
< |
popright(); |
440 |
< |
#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 */ |
475 |
|
#endif |
476 |
|
odUpdate(0); /* draw left eye */ |
477 |
|
} |
452 |
– |
} |
478 |
|
glFlush(); /* flush OpenGL */ |
479 |
|
rayqleft = RAYQLEN; |
480 |
|
/* flush X11 and return # pending */ |
499 |
|
xferdepth() /* load and clear depth buffer */ |
500 |
|
{ |
501 |
|
register GLfloat *dbp; |
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) |
486 |
< |
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 |
+ |
if (cbuf != NULL) |
539 |
+ |
glReadPixels(0, 0, odev.hres, odev.vres, |
540 |
+ |
GL_RGBA, GL_UNSIGNED_BYTE, cbuf); |
541 |
|
for (dbp = depthbuffer + odev.hres*odev.vres; dbp-- > depthbuffer; ) |
542 |
< |
*dbp = mapdepth(*dbp); |
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 */ |
503 |
– |
glClear(GL_DEPTH_BUFFER_BIT); /* clear system buffer */ |
550 |
|
} |
551 |
|
|
552 |
|
|
553 |
+ |
static |
554 |
+ |
freedepth() /* free recorded depth buffer */ |
555 |
+ |
{ |
556 |
+ |
if (depthbuffer == NULL) |
557 |
+ |
return; |
558 |
+ |
#ifdef STEREO |
559 |
+ |
odDepthMap(1, NULL); |
560 |
+ |
free((char *)depthright); |
561 |
+ |
depthright = NULL; |
562 |
+ |
#endif |
563 |
+ |
odDepthMap(0, NULL); |
564 |
+ |
free((char *)depthbuffer); |
565 |
+ |
depthbuffer = NULL; |
566 |
+ |
} |
567 |
+ |
|
568 |
+ |
|
569 |
|
static double |
570 |
|
getdistance(dx, dy, direc) /* distance from fore plane along view ray */ |
571 |
|
int dx, dy; |
572 |
|
FVECT direc; |
573 |
|
{ |
574 |
|
GLfloat gldepth; |
575 |
+ |
GLubyte glcolor[4]; |
576 |
|
double dist; |
577 |
|
|
578 |
|
if (dx<0 | dx>=odev.hres | dy<0 | dy>=odev.vres) |
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_RGBA, |
587 |
+ |
GL_UNSIGNED_BYTE, glcolor); |
588 |
+ |
if (isportal(glcolor)) |
589 |
+ |
return(FHUGE); |
590 |
+ |
} |
591 |
|
dist = mapdepth(gldepth); |
592 |
|
} |
593 |
|
if (dist >= .99*FHUGE) |
663 |
|
mapped = 0; |
664 |
|
break; |
665 |
|
case MapNotify: |
666 |
+ |
odRemap(0); |
667 |
|
mapped = 1; |
668 |
|
break; |
669 |
|
case Expose: |
759 |
|
if (setview(&nv) != NULL) |
760 |
|
return(0); /* illegal view */ |
761 |
|
dev_view(&nv); |
762 |
< |
inpresflags |= DFL(DC_SETVIEW)|DFL(DC_REDRAW); |
762 |
> |
inpresflags |= DFL(DC_SETVIEW); |
763 |
|
return(1); |
764 |
|
} |
765 |
|
|
793 |
|
{ |
794 |
|
int movdir = MOVDIR(ebut->button); |
795 |
|
int movorb = MOVORB(ebut->state); |
796 |
+ |
int ndrawn; |
797 |
|
Window rootw, childw; |
798 |
|
int rootx, rooty, wx, wy; |
799 |
|
unsigned int statemask; |
817 |
|
#ifdef STEREO |
818 |
|
pushright(); |
819 |
|
draw_grids(1); |
820 |
< |
otDrawOctrees(); |
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 |
< |
otDrawOctrees(); |
829 |
> |
ndrawn = gmDrawGeom(); |
830 |
|
#ifdef DOBJ |
831 |
< |
dobj_render(); /* redraw objects */ |
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 */ |
838 |
+ |
#ifdef STEREO |
839 |
+ |
pushright(); |
840 |
+ |
draw_grids(0); |
841 |
+ |
popright(); |
842 |
+ |
#endif |
843 |
+ |
draw_grids(0); |
844 |
+ |
} |
845 |
|
} |
846 |
|
if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */ |
847 |
|
movdir = MOVDIR(levptr(XButtonReleasedEvent)->button); |
860 |
|
GLfloat vec[4]; |
861 |
|
double depthlim[2]; |
862 |
|
/* set depth limits */ |
863 |
< |
otDepthLimit(depthlim, odev.v.vp, odev.v.vdir); |
863 |
> |
gmDepthLimit(depthlim, odev.v.vp, odev.v.vdir); |
864 |
|
if (depthlim[0] >= depthlim[1]) { |
865 |
|
dev_zmin = 1.; |
866 |
|
dev_zmax = 100.; |
867 |
|
} else { |
868 |
|
dev_zmin = 0.5*depthlim[0]; |
869 |
< |
dev_zmax = 1.5*depthlim[1]; |
869 |
> |
dev_zmax = 1.75*depthlim[1]; |
870 |
|
if (dev_zmin > dev_zmax/5.) |
871 |
|
dev_zmin = dev_zmax/5.; |
872 |
|
} |
941 |
|
glClear(GL_DEPTH_BUFFER_BIT); |
942 |
|
if (viewsteady) /* clear samples if steady */ |
943 |
|
odClean(); |
944 |
< |
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 |
< |
} |
944 |
> |
freedepth(); |
945 |
|
setglpersp(&odev.v); /* reset view & clipping planes */ |
946 |
|
} |
947 |
|
|
992 |
|
inpresflags |= DFL(DC_RESUME); |
993 |
|
return; |
994 |
|
case CTRL('R'): /* redraw screen */ |
995 |
< |
odRemap(); |
995 |
> |
odRemap(0); |
996 |
|
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
997 |
|
#ifdef STEREO |
998 |
|
setstereobuf(STEREO_BUFFER_RIGHT); |
1007 |
|
XFlush(ourdisplay); |
1008 |
|
sleep(1); |
1009 |
|
wipeclean(); /* fresh display */ |
1010 |
< |
odRemap(); /* new tone mapping */ |
1010 |
> |
odRemap(1); /* fresh tone mapping */ |
1011 |
|
dev_flush(); /* draw octrees */ |
1012 |
|
inpresflags |= DFL(DC_REDRAW); /* resend values from server */ |
1013 |
|
rayqleft = 0; /* hold off update */ |
1044 |
|
xmin = eexp->x; xmax = eexp->x + eexp->width; |
1045 |
|
ymin = odev.vres - eexp->y - eexp->height; ymax = odev.vres - eexp->y; |
1046 |
|
/* clear portion of depth */ |
1047 |
+ |
glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); |
1048 |
|
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); |
1049 |
|
glDepthFunc(GL_ALWAYS); |
1050 |
|
glBegin(GL_POLYGON); |
1064 |
|
odRedraw(1, xmin, ymin, xmax, ymax); |
1065 |
|
setstereobuf(STEREO_BUFFER_LEFT); |
1066 |
|
#endif |
1067 |
< |
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
992 |
< |
glDepthFunc(GL_LEQUAL); |
1067 |
> |
glPopAttrib(); |
1068 |
|
odRedraw(0, xmin, ymin, xmax, ymax); |
1069 |
|
} |
1070 |
|
|
1084 |
|
odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres); |
1085 |
|
odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres); |
1086 |
|
|
1087 |
< |
inpresflags |= DFL(DC_SETVIEW)|DFL(DC_REDRAW); |
1087 |
> |
inpresflags |= DFL(DC_SETVIEW); |
1088 |
|
} |