ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_geom.c
(Generate patch)

Comparing ray/src/hd/rhd_geom.c (file contents):
Revision 3.1 by gwlarson, Fri Dec 18 11:55:19 1998 UTC vs.
Revision 3.14 by schorsch, Thu Jan 1 11:21:55 2004 UTC

# Line 1 | Line 1
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 < * Octree drawing operations for OpenGL driver.
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 MAXOCTREE
16 < #define MAXOCTREE       8               /* maximum octrees to load at once */
15 > #ifndef MAXGEO
16 > #define MAXGEO          8               /* maximum geometry list length */
17   #endif
18 + #ifndef MAXPORT
19 + #define MAXPORT         (MAXGEO*4)      /* maximum number of portal files */
20 + #endif
21  
22 < static struct otEntry {
23 <        char    *otfile;                /* octree file name */
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 < } otCurrent[MAXOCTREE], otNext[MAXOCTREE];      /* current and next list */
32 >        int     nlists;                 /* number of lists allocated */
33 > } gmCurrent[MAXGEO], gmNext[MAXGEO];    /* current and next list */
34  
35 < #define FORALLOCT(ot,i)         for (i=0;i<MAXOCTREE&&ot[i].otfile!=NULL;i++)
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  
39 < otNewOctree(fname)              /* add new octree to next list */
40 < char    *fname;
39 >
40 >
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 */
49 <        FORALLOCT(otNext, i)
50 <                if (!strcmp(fname, otNext[i].otfile))
49 >        FORALLGEOM(gmNext, i)
50 >                if (!strcmp(file, gmNext[i].gfile))
51                          return;
52 <        if (i >= MAXOCTREE) {
52 >        if (i >= MAXGEO) {
53                  error(WARNING, "too many section octrees -- ignoring extra");
54                  return;
55          }
56                                          /* check if copy in current list */
57 <        FORALLOCT(otCurrent, j)
58 <                if (!strcmp(fname, otCurrent[j].otfile)) {
59 <                        copystruct(&otNext[i], &otCurrent[i]);
57 >        FORALLGEOM(gmCurrent, j)
58 >                if (!strcmp(file, gmCurrent[j].gfile)) {
59 >                        gmNext[i] = gmCurrent[j];
60                          return;
61                  }
62                                          /* else load new octree */
63 <        otNext[i].otfile = fname;
63 >        gmNext[i].gfile = savestr(file);
64          dolights = 0;
65 <        otNext[i].listid = rgl_octlist(fname, otNext[i].cent, &otNext[i].rad);
65 >        domats = 1;
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 <                        fname, otNext[i].listid, otNext[i].rad);
71 >                        file, gmNext[i].listid, gmNext[i].rad);
72   #endif
73   }
74  
75  
76 < otEndOctree()                   /* make next list current */
76 > extern void
77 > gmEndGeom(void)                 /* make next list current */
78   {
79          register int    i, j;
80  
81 <        FORALLOCT(otCurrent, i) {
82 <                FORALLOCT(otNext, j)
83 <                        if (otNext[j].listid == otCurrent[i].listid)
81 >        FORALLGEOM(gmCurrent, i) {
82 >                FORALLGEOM(gmNext, j)
83 >                        if (gmNext[j].listid == gmCurrent[i].listid)
84                                  break;
85 <                if (j >= MAXOCTREE || otNext[j].otfile == NULL)
86 <                        glDeleteLists(otCurrent[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 *)otNext, (char *)otCurrent, sizeof(otNext));
92 <        otNext[0].otfile = NULL;
91 >        memcpy((void *)gmCurrent, (void *)gmNext, sizeof(gmNext));
92 >        memset((void *)gmNext, '\0', sizeof(gmNext));
93   }
94  
95  
96 < int
97 < otDrawOctrees()                 /* draw current list of octrees */
96 > extern int
97 > gmDrawGeom(void)                        /* draw current list of octrees */
98   {
99 <        register int    i;
99 >        register int    n;
100  
101 <        FORALLOCT(otCurrent, i)
102 <                glCallList(otCurrent[i].listid);
103 <        return(i);
101 >        FORALLGEOM(gmCurrent, n)
102 >                glCallList(gmCurrent[n].listid);
103 >        return(n);
104   }
105  
106  
107 < otDepthLimit(dl, vorg, vdir)    /* compute approximate depth limits for view */
108 < double  dl[2];
109 < FVECT   vorg, vdir;
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))
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_FLAT);
122 +        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
123 +                                        /* don't actually write depth */
124 +        glDepthMask(GL_FALSE);
125 +                                        /* 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 +        glCallList(gmPortals);          /* draw them portals */
129 +        glPopAttrib();
130 + }
131 +
132 +
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;
142          register int    i;
143  
144          dl[0] = FHUGE; dl[1] = 0.;
145 <        FORALLOCT(otCurrent, i) {
146 <                VSUB(v, otCurrent[i].cent, vorg);
145 >        FORALLGEOM(gmCurrent, i) {
146 >                VSUB(v, gmCurrent[i].cent, vorg);
147                  dcent = DOT(v, vdir);
148 <                if (dl[0] > dcent-otCurrent[i].rad)
149 <                        dl[0] = dcent-otCurrent[i].rad;
150 <                if (dl[1] < dcent+otCurrent[i].rad)
151 <                        dl[1] = dcent+otCurrent[i].rad;
148 >                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          }
153          if (dl[0] < 0.)
154                  dl[0] = 0.;
155 + }
156 +
157 +
158 + extern void
159 + gmNewPortal(            /* add portal file(s) to our new list */
160 +        char    *pflist
161 + )
162 + {
163 +        register int    i;
164 +        char    newfile[128];
165 +
166 +        if (pflist == NULL)
167 +                return;
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 */
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 + 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, Nlists);
199 +                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 +                        gmPortals = rgl_filelist(n, newportlist, &Nlists);
212 +                        break;
213 +                }
214 +        FORALLPORT(curportlist, n)              /* free old file list */
215 +                freestr(curportlist[n]);
216 +        memcpy((void *)curportlist, (void *)newportlist, sizeof(newportlist));
217 +        memset((void *)newportlist, '\0', sizeof(newportlist));
218 +        return(gmPortals);                      /* return GL list id */
219   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines