ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_geom.c
Revision: 3.3
Committed: Mon Dec 21 11:42:37 1998 UTC (25 years, 3 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.2: +20 -10 lines
Log Message:
got portals working with or without alpha buffer

File Contents

# User Rev Content
1 gwlarson 3.1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ SGI";
5     #endif
6    
7     /*
8 gwlarson 3.2 * Geometry drawing operations for OpenGL driver.
9 gwlarson 3.1 */
10    
11     #include "radogl.h"
12 gwlarson 3.2 #include "rhdriver.h"
13 gwlarson 3.1
14 gwlarson 3.2 #ifndef MAXGEO
15     #define MAXGEO 8 /* maximum geometry list length */
16 gwlarson 3.1 #endif
17 gwlarson 3.2 #ifndef MAXPORT
18     #define MAXPORT (MAXGEO*4) /* maximum number of portal files */
19     #endif
20 gwlarson 3.1
21 gwlarson 3.2 int gmPortals = 0; /* current portal GL list id */
22     static char *curportlist[MAXPORT]; /* current portal list */
23     static char *newportlist[MAXPORT]; /* new portal file list */
24    
25     static struct gmEntry {
26     char *gfile; /* geometry file name */
27 gwlarson 3.1 FVECT cent; /* centroid */
28     FLOAT rad; /* radius */
29     int listid; /* display list identifier */
30 gwlarson 3.2 } gmCurrent[MAXGEO], gmNext[MAXGEO]; /* current and next list */
31 gwlarson 3.1
32 gwlarson 3.2 #define FORALLGEOM(ot,i) for (i=0;i<MAXGEO&&ot[i].gfile!=NULL;i++)
33 gwlarson 3.1
34 gwlarson 3.2 #define FORALLPORT(pl,i) for (i=0;i<MAXPORT&&pl[i]!=NULL;i++)
35 gwlarson 3.1
36 gwlarson 3.2 extern char *atos(), *sskip(), *sskip2();
37    
38    
39     gmNewGeom(file) /* add new geometry to next list */
40     char *file;
41 gwlarson 3.1 {
42     register int i, j;
43     /* check if already in next list */
44 gwlarson 3.2 FORALLGEOM(gmNext, i)
45     if (!strcmp(file, gmNext[i].gfile))
46 gwlarson 3.1 return;
47 gwlarson 3.2 if (i >= MAXGEO) {
48 gwlarson 3.1 error(WARNING, "too many section octrees -- ignoring extra");
49     return;
50     }
51     /* check if copy in current list */
52 gwlarson 3.2 FORALLGEOM(gmCurrent, j)
53     if (!strcmp(file, gmCurrent[j].gfile)) {
54     copystruct(&gmNext[i], &gmCurrent[j]);
55 gwlarson 3.1 return;
56     }
57     /* else load new octree */
58 gwlarson 3.2 gmNext[i].gfile = file;
59 gwlarson 3.1 dolights = 0;
60 gwlarson 3.2 domats = 1;
61     gmNext[i].listid = rgl_octlist(file, gmNext[i].cent, &gmNext[i].rad);
62 gwlarson 3.1 #ifdef DEBUG
63     fprintf(stderr, "Loaded octree \"%s\" into listID %d with radius %f\n",
64 gwlarson 3.2 file, gmNext[i].listid, gmNext[i].rad);
65 gwlarson 3.1 #endif
66     }
67    
68    
69 gwlarson 3.2 gmEndGeom() /* make next list current */
70 gwlarson 3.1 {
71     register int i, j;
72    
73 gwlarson 3.2 FORALLGEOM(gmCurrent, i) {
74     FORALLGEOM(gmNext, j)
75     if (gmNext[j].listid == gmCurrent[i].listid)
76 gwlarson 3.1 break;
77 gwlarson 3.2 if (j >= MAXGEO || gmNext[j].gfile == NULL)
78     glDeleteLists(gmCurrent[i].listid, 1); /* not found */
79 gwlarson 3.1 }
80 gwlarson 3.2 bcopy((char *)gmNext, (char *)gmCurrent, sizeof(gmNext));
81     bzero((char *)gmNext, sizeof(gmNext));
82 gwlarson 3.1 }
83    
84    
85     int
86 gwlarson 3.3 gmDrawGeom() /* draw current list of octrees (and ports) */
87 gwlarson 3.1 {
88 gwlarson 3.2 register int n;
89 gwlarson 3.1
90 gwlarson 3.2 FORALLGEOM(gmCurrent, n)
91     glCallList(gmCurrent[n].listid);
92 gwlarson 3.3 return(n);
93     }
94    
95    
96     gmDrawPortals(r, g, b, a) /* draw portals with specific RGBA value */
97     int r, g, b, a;
98     {
99     if (!gmPortals || r<0 & g<0 & b<0 & a<0)
100     return;
101     glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT|
102     GL_POLYGON_BIT|GL_LIGHTING_BIT);
103     glDisable(GL_LIGHTING);
104     glDisable(GL_DITHER);
105     glShadeModel(GL_SMOOTH);
106     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
107     /* don't actually write depth */
108 gwlarson 3.2 glDepthMask(GL_FALSE);
109 gwlarson 3.3 /* draw only selected channels */
110     glColorMask(r>=0, g>=0, b>=0, a>=0);
111     glColor4ub(r&0xff, g&0xff, b&0xff, a&0xff);
112 gwlarson 3.2 glCallList(gmPortals); /* draw them portals */
113     glPopAttrib();
114 gwlarson 3.1 }
115    
116    
117 gwlarson 3.2 gmDepthLimit(dl, vorg, vdir) /* compute approximate depth limits for view */
118 gwlarson 3.1 double dl[2];
119     FVECT vorg, vdir;
120     {
121     FVECT v;
122     double dcent;
123     register int i;
124    
125     dl[0] = FHUGE; dl[1] = 0.;
126 gwlarson 3.2 FORALLGEOM(gmCurrent, i) {
127     VSUB(v, gmCurrent[i].cent, vorg);
128 gwlarson 3.1 dcent = DOT(v, vdir);
129 gwlarson 3.2 if (dl[0] > dcent-gmCurrent[i].rad)
130     dl[0] = dcent-gmCurrent[i].rad;
131     if (dl[1] < dcent+gmCurrent[i].rad)
132     dl[1] = dcent+gmCurrent[i].rad;
133 gwlarson 3.1 }
134     if (dl[0] < 0.)
135     dl[0] = 0.;
136 gwlarson 3.2 }
137    
138    
139     gmNewPortal(pflist) /* add portal file(s) to our new list */
140     char *pflist;
141     {
142     register int i, j;
143     char newfile[128];
144    
145     if (pflist == NULL)
146     return;
147     while (*pflist) {
148     atos(newfile, sizeof(newfile), pflist);
149     if (!*newfile)
150     break;
151     pflist = sskip(pflist);
152     FORALLPORT(newportlist,i)
153     if (!strcmp(newportlist[i], newfile))
154     goto endloop; /* in list already */
155     if (i >= MAXPORT) {
156     error(WARNING, "too many portals -- ignoring extra");
157     return;
158     }
159     newportlist[i] = savestr(newfile);
160     endloop:;
161     }
162     }
163    
164    
165     static int
166     sstrcmp(ss0, ss1)
167     char **ss0, **ss1;
168     {
169     return(strcmp(*ss0, *ss1));
170     }
171    
172    
173     int
174     gmEndPortal() /* close portal list and return GL list */
175     {
176     register int n;
177    
178     FORALLPORT(newportlist, n);
179     if (!n) { /* free old GL list */
180     if (gmPortals)
181     glDeleteLists(gmPortals, 1);
182     gmPortals = 0;
183     } else
184     qsort(newportlist, n, sizeof(char *), sstrcmp);
185     FORALLPORT(newportlist, n) /* compare sorted lists */
186     if (curportlist[n] == NULL ||
187     strcmp(curportlist[n],newportlist[n])) {
188     /* load new list */
189     if (gmPortals)
190     glDeleteLists(gmPortals, 1);
191     FORALLPORT(newportlist, n);
192     dolights = 0;
193     domats = 0;
194     gmPortals = rgl_filelist(n, newportlist);
195     break;
196     }
197     FORALLPORT(curportlist, n) /* free old file list */
198     freestr(curportlist[n]);
199     bcopy((char *)newportlist, (char *)curportlist, sizeof(newportlist));
200     bzero((char *)newportlist, sizeof(newportlist));
201     return(gmPortals); /* return GL list id */
202 gwlarson 3.1 }