| 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 |
| 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; |
| 446 |
|
if (mapped && isperspective > 0) { |
| 447 |
|
#ifdef STEREO |
| 448 |
|
pushright(); /* draw right eye */ |
| 449 |
< |
gmDrawGeom(0); |
| 449 |
> |
ndrawn = gmDrawGeom(); |
| 450 |
|
#ifdef DOBJ |
| 451 |
< |
dobj_render(); |
| 451 |
> |
ndrawn += dobj_render(); |
| 452 |
|
#endif |
| 453 |
+ |
if (ndrawn) |
| 454 |
+ |
gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP); |
| 455 |
|
checkglerr("rendering right eye"); |
| 456 |
|
popright(); /* draw left eye */ |
| 457 |
|
#endif |
| 458 |
< |
ndrawn = gmDrawGeom(1); |
| 458 |
> |
ndrawn = gmDrawGeom(); |
| 459 |
|
#ifdef DOBJ |
| 460 |
|
ndrawn += dobj_render(); |
| 461 |
|
#endif |
| 462 |
+ |
if (ndrawn) |
| 463 |
+ |
gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP); |
| 464 |
|
checkglerr("rendering base view"); |
| 465 |
|
} |
| 466 |
|
if (mapped && viewsteady) { |
| 505 |
|
xferdepth() /* load and clear depth buffer */ |
| 506 |
|
{ |
| 507 |
|
register GLfloat *dbp; |
| 508 |
< |
register GLubyte *abuf; |
| 508 |
> |
register GLubyte *cbuf; |
| 509 |
|
|
| 510 |
< |
if (depthbuffer == NULL) { |
| 510 |
> |
if (depthbuffer == NULL) { /* allocate private depth buffer */ |
| 511 |
|
#ifdef STEREO |
| 512 |
|
depthright = (GLfloat *)malloc( |
| 513 |
|
odev.hres*odev.vres*sizeof(GLfloat)); |
| 517 |
|
if (depthbuffer == NULL) |
| 518 |
|
error(SYSTEM, "out of memory in xferdepth"); |
| 519 |
|
} |
| 520 |
+ |
/* allocate alpha buffer for portals */ |
| 521 |
+ |
if (gmPortals) |
| 522 |
+ |
cbuf = (GLubyte *)malloc(odev.hres*odev.vres* |
| 523 |
+ |
(4*sizeof(GLubyte))); |
| 524 |
+ |
else |
| 525 |
+ |
cbuf = NULL; |
| 526 |
|
#ifdef STEREO |
| 527 |
|
setstereobuf(STEREO_BUFFER_RIGHT); |
| 528 |
|
glReadPixels(0, 0, odev.hres, odev.vres, |
| 529 |
|
GL_DEPTH_COMPONENT, GL_FLOAT, depthright); |
| 530 |
< |
setstereobuf(STEREO_BUFFER_LEFT); |
| 530 |
> |
if (cbuf != NULL) |
| 531 |
> |
glReadPixels(0, 0, odev.hres, odev.vres, |
| 532 |
> |
GL_RGBA, GL_UNSIGNED_BYTE, cbuf); |
| 533 |
|
for (dbp = depthright + odev.hres*odev.vres; dbp-- > depthright; ) |
| 534 |
< |
*dbp = mapdepth(*dbp); |
| 535 |
< |
odDepthMap(1, depthright); |
| 534 |
> |
if (cbuf != NULL && isportal(cbuf+4*(dbp-depthright))) |
| 535 |
> |
*dbp = FHUGE; |
| 536 |
> |
else |
| 537 |
> |
*dbp = mapdepth(*dbp); |
| 538 |
|
glClear(GL_DEPTH_BUFFER_BIT); |
| 539 |
+ |
setstereobuf(STEREO_BUFFER_LEFT); |
| 540 |
+ |
odDepthMap(1, depthright); |
| 541 |
|
#endif |
| 542 |
|
/* read back depth buffer */ |
| 543 |
|
glReadPixels(0, 0, odev.hres, odev.vres, |
| 544 |
|
GL_DEPTH_COMPONENT, GL_FLOAT, depthbuffer); |
| 545 |
< |
/* 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) |
| 545 |
> |
if (cbuf != NULL) |
| 546 |
|
glReadPixels(0, 0, odev.hres, odev.vres, |
| 547 |
< |
GL_ALPHA, GL_UNSIGNED_BYTE, abuf); |
| 547 |
> |
GL_RGBA, GL_UNSIGNED_BYTE, cbuf); |
| 548 |
|
for (dbp = depthbuffer + odev.hres*odev.vres; dbp-- > depthbuffer; ) |
| 549 |
< |
if (abuf != NULL && abuf[dbp-depthbuffer]) |
| 549 |
> |
if (cbuf != NULL && isportal(cbuf+4*(dbp-depthbuffer))) |
| 550 |
|
*dbp = FHUGE; |
| 551 |
|
else |
| 552 |
|
*dbp = mapdepth(*dbp); |
| 553 |
+ |
glClear(GL_DEPTH_BUFFER_BIT); /* clear system depth buffer */ |
| 554 |
+ |
if (cbuf != NULL) |
| 555 |
+ |
free((char *)cbuf); /* free our color buffer */ |
| 556 |
|
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 */ |
| 557 |
|
} |
| 558 |
|
|
| 559 |
|
|
| 579 |
|
FVECT direc; |
| 580 |
|
{ |
| 581 |
|
GLfloat gldepth; |
| 582 |
< |
GLubyte glalpha; |
| 582 |
> |
GLubyte glcolor[4]; |
| 583 |
|
double dist; |
| 584 |
|
|
| 585 |
|
if (dx<0 | dx>=odev.hres | dy<0 | dy>=odev.vres) |
| 589 |
|
else { |
| 590 |
|
glReadPixels(dx,dy, 1,1, GL_DEPTH_COMPONENT, |
| 591 |
|
GL_FLOAT, &gldepth); |
| 592 |
< |
if (gmPortals) |
| 593 |
< |
glReadPixels(dx,dy, 1,1, GL_ALPHA, |
| 594 |
< |
GL_UNSIGNED_BYTE, &glalpha); |
| 595 |
< |
else |
| 596 |
< |
glalpha = 0; |
| 597 |
< |
dist = glalpha ? FHUGE : mapdepth(gldepth); |
| 592 |
> |
if (gmPortals) { |
| 593 |
> |
glReadPixels(dx,dy, 1,1, GL_RGBA, |
| 594 |
> |
GL_UNSIGNED_BYTE, glcolor); |
| 595 |
> |
if (isportal(glcolor)) |
| 596 |
> |
return(FHUGE); |
| 597 |
> |
} |
| 598 |
> |
dist = mapdepth(gldepth); |
| 599 |
|
} |
| 600 |
|
if (dist >= .99*FHUGE) |
| 601 |
|
return(FHUGE); |
| 824 |
|
#ifdef STEREO |
| 825 |
|
pushright(); |
| 826 |
|
draw_grids(1); |
| 827 |
< |
gmDrawGeom(0); |
| 827 |
> |
ndrawn = gmDrawGeom(); |
| 828 |
|
#ifdef DOBJ |
| 829 |
< |
dobj_render(); |
| 829 |
> |
ndrawn += dobj_render(); |
| 830 |
|
#endif |
| 831 |
+ |
if (ndrawn) |
| 832 |
+ |
gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP); |
| 833 |
|
popright(); |
| 834 |
|
#endif |
| 835 |
|
/* redraw octrees */ |
| 836 |
< |
ndrawn = gmDrawGeom(1); |
| 836 |
> |
ndrawn = gmDrawGeom(); |
| 837 |
|
#ifdef DOBJ |
| 838 |
|
ndrawn += dobj_render(); /* redraw objects */ |
| 839 |
|
#endif |
| 840 |
+ |
if (ndrawn) |
| 841 |
+ |
gmDrawPortals(PORTRED, PORTGRN, PORTBLU, PORTALP); |
| 842 |
|
glFlush(); |
| 843 |
|
if (!ndrawn) { |
| 844 |
|
sleep(1); /* for reasonable interaction */ |