ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_geom.c
Revision: 3.8
Committed: Fri Jan 29 15:33:36 1999 UTC (25 years, 3 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.7: +8 -4 lines
Log Message:
added number of lists for proper list deallocation

File Contents

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