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.13 by schorsch, Fri Nov 14 17:22:06 2003 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  
# Line 101 | Line 110 | LUENT  *lp;
110   int
111   loadoctrees()                           /* load octrees we've saved up */
112   {
113 +        int     levelsleft = MAXLEVEL;
114          int     nocts = 0;
115          LUTAB   looptab;
116                                  /* loop through new octree references */
117          while (ottab.tsiz) {
118 <                copystruct(&looptab, &ottab);
118 >                if (!levelsleft--)
119 >                        error(USER, "too many octree levels -- instance loop?");
120 >                looptab = ottab;
121                  ottab.tsiz = 0;
122                  nocts += lu_doall(&looptab, buildoctlist);
123                  lu_done(&looptab);
# Line 118 | Line 130 | static OCTINST *
130   getoct(name)                            /* get/assign octree list id */
131   char    *name;
132   {
121        extern char     *getpath(), *getlibpath();
133          char    *path;
134          register LUENT  *lp;
135          register OCTINST        *op;
# Line 132 | Line 143 | char   *name;
143                  strcpy(lp->key, name);
144          }
145          if ((op = (OCTINST *)lp->data) == NULL) {
146 <                path = getpath(name, getlibpath(), R_OK);
146 >                path = getpath(name, getrlibpath(), R_OK);
147                  if (path == NULL) {
148                          sprintf(errmsg, "cannot find octree \"%s\"", name);
149                          error(USER, errmsg);
# Line 146 | Line 157 | char   *name;
157          return(op);
158   memerr:
159          error(SYSTEM, "out of memory in getoct");
160 +        return NULL; /* pro forma return */
161   }
162  
163  
# Line 164 | Line 176 | FVECT  cent;
176                  sprintf(errmsg, "cannot open octree file \"%s\"", fname);
177                  error(SYSTEM, errmsg);
178          }
179 < #ifdef MSDOS
168 <        setmode(fileno(infp), O_BINARY);
169 < #endif
179 >        SET_FILE_BINARY(infp);
180                                          /* get header */
181          if (checkheader(infp, OCTFMT, NULL) < 0)
182                  octerror(USER, "not an octree");
183                                          /* check format */
184          if ((objsize = ogetint(2)-OCTMAGIC) <= 0 ||
185                          objsize > MAXOBJSIZ || objsize > sizeof(long))
186 <                octerror("incompatible octree format");
186 >                octerror(USER, "incompatible octree format");
187          if (cent != NULL) {             /* get boundaries (compute center) */
188                  for (i = 0; i < 3; i++)
189                          cent[i] = atof(ogetstr(sbuf));
# Line 191 | Line 201 | FVECT  cent;
201   }
202  
203  
204 + int
205   loadoct(fname)                          /* read in objects from octree */
206   char  *fname;
207   {
# Line 202 | Line 213 | char  *fname;
213          
214          infn = fname;
215          infp = fopen(fname, "r");       /* assume already checked */
216 < #ifdef MSDOS
206 <        setmode(fileno(infp), O_BINARY);
207 < #endif
216 >        SET_FILE_BINARY(infp);
217                                          /* skip header */
218          getheader(infp, NULL, NULL);
219                                          /* get format */
# Line 280 | Line 289 | ogetflt()                      /* get a floating point number */
289   }
290          
291  
292 < static
292 > static void
293   skiptree()                              /* skip octree on input */
294   {
295          register int  i;
# Line 305 | Line 314 | skiptree()                             /* skip octree on input */
314   }
315  
316  
317 < static
317 > static int
318   loadobj()                               /* get next object */
319   {
320          static OBJREC    ob;
# Line 331 | Line 340 | loadobj()                              /* get next object */
340                                          /* get name id */
341          ob.oname = ogetstr(idbuf);
342                                          /* get string arguments */
343 <        if (ob.oargs.nsargs = ogetint(2)) {
343 >        if ((ob.oargs.nsargs = ogetint(2))) {
344                  ob.oargs.sarg = (char **)malloc
345                                  (ob.oargs.nsargs*sizeof(char *));
346                  if (ob.oargs.sarg == NULL)
# Line 353 | Line 362 | loadobj()                              /* get next object */
362                  ob.oargs.iarg = NULL;
363   #endif
364                                          /* get real arguments */
365 <        if (ob.oargs.nfargs = ogetint(2)) {
366 <                ob.oargs.farg = (FLOAT *)malloc
367 <                                (ob.oargs.nfargs*sizeof(FLOAT));
365 >        if ((ob.oargs.nfargs = ogetint(2))) {
366 >                ob.oargs.farg = (RREAL *)malloc
367 >                                (ob.oargs.nfargs*sizeof(RREAL));
368                  if (ob.oargs.farg == NULL)
369                          goto memerr;
370                  for (i = 0; i < ob.oargs.nfargs; i++)
# Line 375 | Line 384 | loadobj()                              /* get next object */
384          return(nobjects++);             /* return object id */
385   memerr:
386          error(SYSTEM, "out of memory in loadobj");
387 +        return OVOID; /* pro forma return */
388   }
389  
390  
391 < static
391 > static void
392   octerror(etyp, msg)                     /* octree error */
393   int  etyp;
394   char  *msg;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines