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

Comparing ray/src/common/rglinst.c (file contents):
Revision 3.1 by gwlarson, Tue Jun 9 11:18:35 1998 UTC vs.
Revision 3.15 by greg, Tue May 25 22:04:13 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   * Routines for reading instances and converting to OpenGL.
6   */
7  
8 + #include "copyright.h"
9 +
10 + #include <stdio.h>
11 + #include <string.h>
12 + #include <time.h>
13 +
14 + #include "platform.h"
15 + #include "paths.h"
16 + #include "resolu.h"
17   #include "radogl.h"
18   #include "octree.h"
19  
20 + #define MAXLEVEL        16              /* maximum instance hierarchy level */
21 +
22   typedef struct {
23          int     listid;                         /* our list id */
24          short   localmatl;                      /* uses local material only */
# Line 18 | Line 26 | typedef struct {
26          char    octfile[256];                   /* octree file path */
27   } OCTINST;                              /* octree to instantiate */
28  
29 < OBJECT  nobjects;                       /* number of objects loaded so far */
29 > static double  ogetflt(void);
30 > static long  ogetint(int);
31 > static char  *ogetstr(char *);
32 > static int  loadobj(void);
33 > static void  skiptree(void);
34 > static void  octerror(int etyp, char *msg);
35 > static OCTINST  *getoct(char *);
36  
23 extern int      free();
24
25 static double  ogetflt();
26 static long  ogetint();
27 static char  *ogetstr();
28 static int  loadobj(), octerror(), skiptree();
29 static OCTINST  *getoct();
30
37   static char  *infn;                     /* input file name */
38   static FILE  *infp;                     /* input file stream */
39   static int  objsize;                    /* size of stored OBJECT's */
40   static short  otypmap[NUMOTYPE+8];      /* object type map */
41  
42 < static long     imhash(mod) char *mod; {return((long)mod);}
42 > static unsigned long    imhash(mod) char *mod; {return((unsigned long)mod);}
43   static LUTAB    imtab = {imhash,NULL,NULL,NULL,0,NULL,0};
44  
45   static LUTAB    ottab = LU_SINIT(free,free);
46  
47  
48 + int
49   o_instance(o)                           /* convert instance to list call */
50   register OBJREC *o;
51   {
# Line 54 | Line 61 | register OBJREC        *o;
61                                  o->oargs.nsargs-1)
62                          objerror(o, USER, "bad transform");
63                  glPushAttrib(GL_TRANSFORM_BIT);
64 <                if (xfs.sca < 1.-FTINY | xfs.sca > 1.+FTINY)
64 >                if ((xfs.sca < 1.-FTINY) | (xfs.sca > 1.+FTINY))
65                          glEnable(GL_NORMALIZE);
66                  glMatrixMode(GL_MODELVIEW);
67                  glPushMatrix();
# Line 67 | Line 74 | register OBJREC        *o;
74          }
75          ot = getoct(o->oargs.sarg[0]);  /* get octree reference */
76          if (ot->localmatl &= o->os != NULL)     /* set material */
77 <                setmaterial(o->os, ot->cent, 0);
77 >                setmaterial((MATREC *)o->os, ot->cent, 0);
78                                          /* call the assigned list */
79          glCallList(ot->listid);
80  
81          if (o->oargs.nsargs > 1) {      /* end transform */
82 +                glMatrixMode(GL_MODELVIEW);
83                  glPopMatrix();
84                  glPopAttrib();
85          }
86          rgl_checkerr("creating instance");
87 +        return(0);
88   }
89  
90  
91   static int
92 < buildoctlist(lp)                        /* build octree list */
93 < LUENT   *lp;
92 > buildoctlist(lp, p)                     /* build octree list */
93 > const LUENT     *lp;
94 > void    *p;
95   {
96          int     old_dolights = dolights, old_domats = domats;
97          register OCTINST        *op = (OCTINST *)lp->data;
# Line 101 | Line 111 | LUENT  *lp;
111   int
112   loadoctrees()                           /* load octrees we've saved up */
113   {
114 +        int     levelsleft = MAXLEVEL;
115          int     nocts = 0;
116          LUTAB   looptab;
117                                  /* loop through new octree references */
118          while (ottab.tsiz) {
119 <                copystruct(&looptab, &ottab);
119 >                if (!levelsleft--)
120 >                        error(USER, "too many octree levels -- instance loop?");
121 >                looptab = ottab;
122                  ottab.tsiz = 0;
123 <                nocts += lu_doall(&looptab, buildoctlist);
123 >                nocts += lu_doall(&looptab, buildoctlist, NULL);
124                  lu_done(&looptab);
125          }
126          return(nocts);
# Line 118 | Line 131 | static OCTINST *
131   getoct(name)                            /* get/assign octree list id */
132   char    *name;
133   {
121        extern char     *getpath(), *getlibpath();
134          char    *path;
135          register LUENT  *lp;
136          register OCTINST        *op;
# Line 132 | Line 144 | char   *name;
144                  strcpy(lp->key, name);
145          }
146          if ((op = (OCTINST *)lp->data) == NULL) {
147 <                path = getpath(name, getlibpath(), R_OK);
147 >                path = getpath(name, getrlibpath(), R_OK);
148                  if (path == NULL) {
149                          sprintf(errmsg, "cannot find octree \"%s\"", name);
150                          error(USER, errmsg);
# Line 146 | Line 158 | char   *name;
158          return(op);
159   memerr:
160          error(SYSTEM, "out of memory in getoct");
161 +        return NULL; /* pro forma return */
162   }
163  
164  
# Line 164 | Line 177 | FVECT  cent;
177                  sprintf(errmsg, "cannot open octree file \"%s\"", fname);
178                  error(SYSTEM, errmsg);
179          }
180 < #ifdef MSDOS
168 <        setmode(fileno(infp), O_BINARY);
169 < #endif
180 >        SET_FILE_BINARY(infp);
181                                          /* get header */
182          if (checkheader(infp, OCTFMT, NULL) < 0)
183                  octerror(USER, "not an octree");
184                                          /* check format */
185          if ((objsize = ogetint(2)-OCTMAGIC) <= 0 ||
186                          objsize > MAXOBJSIZ || objsize > sizeof(long))
187 <                octerror("incompatible octree format");
187 >                octerror(USER, "incompatible octree format");
188          if (cent != NULL) {             /* get boundaries (compute center) */
189                  for (i = 0; i < 3; i++)
190                          cent[i] = atof(ogetstr(sbuf));
# Line 191 | Line 202 | FVECT  cent;
202   }
203  
204  
205 + int
206   loadoct(fname)                          /* read in objects from octree */
207   char  *fname;
208   {
# Line 202 | Line 214 | char  *fname;
214          
215          infn = fname;
216          infp = fopen(fname, "r");       /* assume already checked */
217 < #ifdef MSDOS
206 <        setmode(fileno(infp), O_BINARY);
207 < #endif
217 >        SET_FILE_BINARY(infp);
218                                          /* skip header */
219          getheader(infp, NULL, NULL);
220                                          /* get format */
# Line 280 | Line 290 | ogetflt()                      /* get a floating point number */
290   }
291          
292  
293 < static
293 > static void
294   skiptree()                              /* skip octree on input */
295   {
296          register int  i;
# Line 305 | Line 315 | skiptree()                             /* skip octree on input */
315   }
316  
317  
318 < static
318 > static int
319   loadobj()                               /* get next object */
320   {
321          static OBJREC    ob;
# Line 331 | Line 341 | loadobj()                              /* get next object */
341                                          /* get name id */
342          ob.oname = ogetstr(idbuf);
343                                          /* get string arguments */
344 <        if (ob.oargs.nsargs = ogetint(2)) {
344 >        if ((ob.oargs.nsargs = ogetint(2))) {
345                  ob.oargs.sarg = (char **)malloc
346                                  (ob.oargs.nsargs*sizeof(char *));
347                  if (ob.oargs.sarg == NULL)
# Line 353 | Line 363 | loadobj()                              /* get next object */
363                  ob.oargs.iarg = NULL;
364   #endif
365                                          /* get real arguments */
366 <        if (ob.oargs.nfargs = ogetint(2)) {
367 <                ob.oargs.farg = (FLOAT *)malloc
368 <                                (ob.oargs.nfargs*sizeof(FLOAT));
366 >        if ((ob.oargs.nfargs = ogetint(2))) {
367 >                ob.oargs.farg = (RREAL *)malloc
368 >                                (ob.oargs.nfargs*sizeof(RREAL));
369                  if (ob.oargs.farg == NULL)
370                          goto memerr;
371                  for (i = 0; i < ob.oargs.nfargs; i++)
# Line 375 | Line 385 | loadobj()                              /* get next object */
385          return(nobjects++);             /* return object id */
386   memerr:
387          error(SYSTEM, "out of memory in loadobj");
388 +        return OVOID; /* pro forma return */
389   }
390  
391  
392 < static
392 > static void
393   octerror(etyp, msg)                     /* octree error */
394   int  etyp;
395   char  *msg;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines