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.2 by gwlarson, Sun Dec 20 20:35:43 1998 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines