--- ray/src/hd/rhd_geom.c 1998/12/20 20:35:43 3.2 +++ ray/src/hd/rhd_geom.c 2004/01/01 11:21:55 3.14 @@ -1,15 +1,16 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rhd_geom.c,v 3.14 2004/01/01 11:21:55 schorsch Exp $"; #endif - /* * Geometry drawing operations for OpenGL driver. */ +#include + +#include "rtio.h" #include "radogl.h" #include "rhdriver.h" +#include "rhd_odraw.h" #ifndef MAXGEO #define MAXGEO 8 /* maximum geometry list length */ @@ -19,25 +20,29 @@ static char SCCSid[] = "$SunId$ SGI"; #endif int gmPortals = 0; /* current portal GL list id */ +static int Nlists = 0; /* number of lists allocated */ static char *curportlist[MAXPORT]; /* current portal list */ static char *newportlist[MAXPORT]; /* new portal file list */ static struct gmEntry { char *gfile; /* geometry file name */ FVECT cent; /* centroid */ - FLOAT rad; /* radius */ + RREAL rad; /* radius */ int listid; /* display list identifier */ + int nlists; /* number of lists allocated */ } gmCurrent[MAXGEO], gmNext[MAXGEO]; /* current and next list */ #define FORALLGEOM(ot,i) for (i=0;i= MAXGEO || gmNext[j].gfile == NULL) - glDeleteLists(gmCurrent[i].listid, 1); /* not found */ + if (j >= MAXGEO || gmNext[j].gfile == NULL) { + glDeleteLists(gmCurrent[i].listid, /* not found */ + gmCurrent[i].nlists); + freestr(gmCurrent[i].gfile); + } } - bcopy((char *)gmNext, (char *)gmCurrent, sizeof(gmNext)); - bzero((char *)gmNext, sizeof(gmNext)); + memcpy((void *)gmCurrent, (void *)gmNext, sizeof(gmNext)); + memset((void *)gmNext, '\0', sizeof(gmNext)); } -int -gmDrawGeom(clearports) /* draw current list of octrees (and ports) */ -int clearports; +extern int +gmDrawGeom(void) /* draw current list of octrees */ { register int n; FORALLGEOM(gmCurrent, n) glCallList(gmCurrent[n].listid); - if (!n | !clearports | !gmPortals) - return(n); - /* mark alpha channel over the portals */ - glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); + return(n); +} + + +extern void +gmDrawPortals( /* draw portals with specific RGBA value */ + int r, + int g, + int b, + int a +) +{ + if (!gmPortals || (r<0) & (g<0) & (b<0) & (a<0)) + return; + glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT| + GL_POLYGON_BIT|GL_LIGHTING_BIT); + glDisable(GL_LIGHTING); + glDisable(GL_DITHER); + glShadeModel(GL_FLAT); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + /* don't actually write depth */ glDepthMask(GL_FALSE); - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE); - glClear(GL_COLOR_BUFFER_BIT); - glColor4ub(0, 0, 0, 0xff); /* write alpha buffer as mask */ + /* draw only selected channels */ + glColorMask(r>=0, g>=0, b>=0, a>=0); + glColor4ub(r&0xff, g&0xff, b&0xff, a&0xff); glCallList(gmPortals); /* draw them portals */ glPopAttrib(); - return(n); } -gmDepthLimit(dl, vorg, vdir) /* compute approximate depth limits for view */ -double dl[2]; -FVECT vorg, vdir; +extern void +gmDepthLimit( /* compute approximate depth limits for view */ + double dl[2], + FVECT vorg, + FVECT vdir +) { FVECT v; double dcent; @@ -126,19 +155,17 @@ FVECT vorg, vdir; } -gmNewPortal(pflist) /* add portal file(s) to our new list */ -char *pflist; +extern void +gmNewPortal( /* add portal file(s) to our new list */ + char *pflist +) { - register int i, j; + register int i; char newfile[128]; if (pflist == NULL) return; - while (*pflist) { - atos(newfile, sizeof(newfile), pflist); - if (!*newfile) - break; - pflist = sskip(pflist); + while ((pflist = nextword(newfile, sizeof(newfile), pflist)) != NULL) { FORALLPORT(newportlist,i) if (!strcmp(newportlist[i], newfile)) goto endloop; /* in list already */ @@ -160,15 +187,15 @@ char **ss0, **ss1; } -int -gmEndPortal() /* close portal list and return GL list */ +extern int +gmEndPortal(void) /* close portal list and return GL list */ { register int n; FORALLPORT(newportlist, n); if (!n) { /* free old GL list */ if (gmPortals) - glDeleteLists(gmPortals, 1); + glDeleteLists(gmPortals, Nlists); gmPortals = 0; } else qsort(newportlist, n, sizeof(char *), sstrcmp); @@ -181,12 +208,12 @@ gmEndPortal() /* close portal list and return GL lis FORALLPORT(newportlist, n); dolights = 0; domats = 0; - gmPortals = rgl_filelist(n, newportlist); + gmPortals = rgl_filelist(n, newportlist, &Nlists); break; } FORALLPORT(curportlist, n) /* free old file list */ freestr(curportlist[n]); - bcopy((char *)newportlist, (char *)curportlist, sizeof(newportlist)); - bzero((char *)newportlist, sizeof(newportlist)); + memcpy((void *)curportlist, (void *)newportlist, sizeof(newportlist)); + memset((void *)newportlist, '\0', sizeof(newportlist)); return(gmPortals); /* return GL list id */ }