1 |
– |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Geometry drawing operations for OpenGL driver. |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include <string.h> |
9 |
+ |
|
10 |
+ |
#include "rtio.h" |
11 |
|
#include "radogl.h" |
12 |
|
#include "rhdriver.h" |
13 |
+ |
#include "rhd_odraw.h" |
14 |
|
|
15 |
|
#ifndef MAXGEO |
16 |
|
#define MAXGEO 8 /* maximum geometry list length */ |
20 |
|
#endif |
21 |
|
|
22 |
|
int gmPortals = 0; /* current portal GL list id */ |
23 |
+ |
static int Nlists = 0; /* number of lists allocated */ |
24 |
|
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 |
|
FVECT cent; /* centroid */ |
30 |
< |
FLOAT rad; /* radius */ |
30 |
> |
RREAL rad; /* radius */ |
31 |
|
int listid; /* display list identifier */ |
32 |
+ |
int nlists; /* number of lists allocated */ |
33 |
|
} gmCurrent[MAXGEO], gmNext[MAXGEO]; /* current and next list */ |
34 |
|
|
35 |
|
#define FORALLGEOM(ot,i) for (i=0;i<MAXGEO&&ot[i].gfile!=NULL;i++) |
36 |
|
|
37 |
|
#define FORALLPORT(pl,i) for (i=0;i<MAXPORT&&pl[i]!=NULL;i++) |
38 |
|
|
36 |
– |
extern char *atos(), *sskip(), *sskip2(); |
39 |
|
|
40 |
|
|
41 |
< |
gmNewGeom(file) /* add new geometry to next list */ |
42 |
< |
char *file; |
41 |
> |
|
42 |
> |
extern void |
43 |
> |
gmNewGeom( /* add new geometry to next list */ |
44 |
> |
char *file |
45 |
> |
) |
46 |
|
{ |
47 |
|
register int i, j; |
48 |
|
/* check if already in next list */ |
56 |
|
/* check if copy in current list */ |
57 |
|
FORALLGEOM(gmCurrent, j) |
58 |
|
if (!strcmp(file, gmCurrent[j].gfile)) { |
59 |
< |
copystruct(&gmNext[i], &gmCurrent[j]); |
59 |
> |
gmNext[i] = gmCurrent[j]; |
60 |
|
return; |
61 |
|
} |
62 |
|
/* else load new octree */ |
63 |
< |
gmNext[i].gfile = file; |
63 |
> |
gmNext[i].gfile = savestr(file); |
64 |
|
dolights = 0; |
65 |
|
domats = 1; |
66 |
< |
gmNext[i].listid = rgl_octlist(file, gmNext[i].cent, &gmNext[i].rad); |
66 |
> |
gmNext[i].listid = rgl_octlist(file, gmNext[i].cent, &gmNext[i].rad, |
67 |
> |
&gmNext[i].nlists); |
68 |
> |
gmNext[i].rad *= 1.732; /* go to corners */ |
69 |
|
#ifdef DEBUG |
70 |
|
fprintf(stderr, "Loaded octree \"%s\" into listID %d with radius %f\n", |
71 |
|
file, gmNext[i].listid, gmNext[i].rad); |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
< |
gmEndGeom() /* make next list current */ |
76 |
> |
extern void |
77 |
> |
gmEndGeom(void) /* make next list current */ |
78 |
|
{ |
79 |
|
register int i, j; |
80 |
|
|
82 |
|
FORALLGEOM(gmNext, j) |
83 |
|
if (gmNext[j].listid == gmCurrent[i].listid) |
84 |
|
break; |
85 |
< |
if (j >= MAXGEO || gmNext[j].gfile == NULL) |
86 |
< |
glDeleteLists(gmCurrent[i].listid, 1); /* not found */ |
85 |
> |
if (j >= MAXGEO || gmNext[j].gfile == NULL) { |
86 |
> |
glDeleteLists(gmCurrent[i].listid, /* not found */ |
87 |
> |
gmCurrent[i].nlists); |
88 |
> |
freestr(gmCurrent[i].gfile); |
89 |
> |
} |
90 |
|
} |
91 |
< |
bcopy((char *)gmNext, (char *)gmCurrent, sizeof(gmNext)); |
92 |
< |
bzero((char *)gmNext, sizeof(gmNext)); |
91 |
> |
memcpy((void *)gmCurrent, (void *)gmNext, sizeof(gmNext)); |
92 |
> |
memset((void *)gmNext, '\0', sizeof(gmNext)); |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
< |
int |
97 |
< |
gmDrawGeom() /* draw current list of octrees (and ports) */ |
96 |
> |
extern int |
97 |
> |
gmDrawGeom(void) /* draw current list of octrees */ |
98 |
|
{ |
99 |
|
register int n; |
100 |
|
|
104 |
|
} |
105 |
|
|
106 |
|
|
107 |
< |
gmDrawPortals(r, g, b, a) /* draw portals with specific RGBA value */ |
108 |
< |
int r, g, b, a; |
107 |
> |
extern void |
108 |
> |
gmDrawPortals( /* draw portals with specific RGBA value */ |
109 |
> |
int r, |
110 |
> |
int g, |
111 |
> |
int b, |
112 |
> |
int a |
113 |
> |
) |
114 |
|
{ |
115 |
< |
if (!gmPortals || r<0 & g<0 & b<0 & a<0) |
115 |
> |
if (!gmPortals || (r<0) & (g<0) & (b<0) & (a<0)) |
116 |
|
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 |
< |
glShadeModel(GL_SMOOTH); |
121 |
> |
glShadeModel(GL_FLAT); |
122 |
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); |
123 |
|
/* don't actually write depth */ |
124 |
|
glDepthMask(GL_FALSE); |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
< |
gmDepthLimit(dl, vorg, vdir) /* compute approximate depth limits for view */ |
134 |
< |
double dl[2]; |
135 |
< |
FVECT vorg, vdir; |
133 |
> |
extern void |
134 |
> |
gmDepthLimit( /* compute approximate depth limits for view */ |
135 |
> |
double dl[2], |
136 |
> |
FVECT vorg, |
137 |
> |
FVECT vdir |
138 |
> |
) |
139 |
|
{ |
140 |
|
FVECT v; |
141 |
|
double dcent; |
155 |
|
} |
156 |
|
|
157 |
|
|
158 |
< |
gmNewPortal(pflist) /* add portal file(s) to our new list */ |
159 |
< |
char *pflist; |
158 |
> |
extern void |
159 |
> |
gmNewPortal( /* add portal file(s) to our new list */ |
160 |
> |
char *pflist |
161 |
> |
) |
162 |
|
{ |
163 |
< |
register int i, j; |
163 |
> |
register int i; |
164 |
|
char newfile[128]; |
165 |
|
|
166 |
|
if (pflist == NULL) |
167 |
|
return; |
168 |
< |
while (*pflist) { |
148 |
< |
atos(newfile, sizeof(newfile), pflist); |
149 |
< |
if (!*newfile) |
150 |
< |
break; |
151 |
< |
pflist = sskip(pflist); |
168 |
> |
while ((pflist = nextword(newfile, sizeof(newfile), pflist)) != NULL) { |
169 |
|
FORALLPORT(newportlist,i) |
170 |
|
if (!strcmp(newportlist[i], newfile)) |
171 |
|
goto endloop; /* in list already */ |
187 |
|
} |
188 |
|
|
189 |
|
|
190 |
< |
int |
191 |
< |
gmEndPortal() /* close portal list and return GL list */ |
190 |
> |
extern int |
191 |
> |
gmEndPortal(void) /* close portal list and return GL list */ |
192 |
|
{ |
193 |
|
register int n; |
194 |
|
|
195 |
|
FORALLPORT(newportlist, n); |
196 |
|
if (!n) { /* free old GL list */ |
197 |
|
if (gmPortals) |
198 |
< |
glDeleteLists(gmPortals, 1); |
198 |
> |
glDeleteLists(gmPortals, Nlists); |
199 |
|
gmPortals = 0; |
200 |
|
} else |
201 |
|
qsort(newportlist, n, sizeof(char *), sstrcmp); |
208 |
|
FORALLPORT(newportlist, n); |
209 |
|
dolights = 0; |
210 |
|
domats = 0; |
211 |
< |
gmPortals = rgl_filelist(n, newportlist); |
211 |
> |
gmPortals = rgl_filelist(n, newportlist, &Nlists); |
212 |
|
break; |
213 |
|
} |
214 |
|
FORALLPORT(curportlist, n) /* free old file list */ |
215 |
|
freestr(curportlist[n]); |
216 |
< |
bcopy((char *)newportlist, (char *)curportlist, sizeof(newportlist)); |
217 |
< |
bzero((char *)newportlist, sizeof(newportlist)); |
216 |
> |
memcpy((void *)curportlist, (void *)newportlist, sizeof(newportlist)); |
217 |
> |
memset((void *)newportlist, '\0', sizeof(newportlist)); |
218 |
|
return(gmPortals); /* return GL list id */ |
219 |
|
} |