ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_geom.c
Revision: 3.14
Committed: Thu Jan 1 11:21:55 2004 UTC (20 years, 3 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad4R2P2, rad5R0, rad5R1, rad3R7P2, rad3R7P1, rad4R2, rad4R1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9, rad4R2P1
Changes since 3.13: +33 -18 lines
Log Message:
Ansification and prototypes.

File Contents

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