| 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 | 
  | 
 * Load Radiance object(s) and create OpenGL display lists | 
| 6 | 
  | 
 */ | 
| 7 | 
  | 
 | 
| 8 | 
+ | 
#include "copyright.h" | 
| 9 | 
+ | 
 | 
| 10 | 
  | 
#include "radogl.h" | 
| 11 | 
  | 
 | 
| 12 | 
  | 
#ifndef NLIST2ALLOC | 
| 13 | 
  | 
#define NLIST2ALLOC     16              /* batch of display lists to get */ | 
| 14 | 
  | 
#endif | 
| 15 | 
  | 
 | 
| 17 | 
– | 
extern int      o_sphere(), o_face(), o_cone(), o_ring(), | 
| 18 | 
– | 
                o_source(), o_instance(); | 
| 19 | 
– | 
 | 
| 20 | 
– | 
extern int      m_normal(), m_glass(), m_aniso(), m_brdf(), m_brdf2(), | 
| 21 | 
– | 
                m_light(), m_prism(), m_mirror(); | 
| 22 | 
– | 
 | 
| 16 | 
  | 
FUN  ofun[NUMOTYPE] = INIT_OTYPE; | 
| 17 | 
  | 
 | 
| 18 | 
+ | 
static int      nextlist, nlistleft = 0; | 
| 19 | 
  | 
 | 
| 20 | 
< | 
static | 
| 20 | 
> | 
 | 
| 21 | 
> | 
static void | 
| 22 | 
  | 
initotypes()                    /* initialize ofun array */ | 
| 23 | 
  | 
{ | 
| 24 | 
  | 
        if (ofun[OBJ_SPHERE].funp == o_sphere) | 
| 64 | 
  | 
int | 
| 65 | 
  | 
newglist()                      /* allocate an OGL list id */ | 
| 66 | 
  | 
{ | 
| 67 | 
< | 
        static int      nextlist, nleft = 0; | 
| 73 | 
< | 
 | 
| 74 | 
< | 
        if (!nleft--) { | 
| 67 | 
> | 
        if (!nlistleft--) { | 
| 68 | 
  | 
                nextlist = glGenLists(NLIST2ALLOC); | 
| 69 | 
< | 
                nleft = NLIST2ALLOC-1; | 
| 69 | 
> | 
                if (!nextlist) | 
| 70 | 
> | 
                        error(SYSTEM, "no list space left in newglist"); | 
| 71 | 
> | 
                nlistleft = NLIST2ALLOC-1; | 
| 72 | 
  | 
        } | 
| 73 | 
  | 
        return(nextlist++); | 
| 74 | 
  | 
} | 
| 75 | 
  | 
 | 
| 76 | 
  | 
 | 
| 77 | 
+ | 
void | 
| 78 | 
  | 
rgl_checkerr(where)             /* check for GL or GLU error */ | 
| 79 | 
  | 
char    *where; | 
| 80 | 
  | 
{ | 
| 89 | 
  | 
 | 
| 90 | 
  | 
 | 
| 91 | 
  | 
int | 
| 92 | 
< | 
rgl_filelist(ic, inp)           /* load scene files into display list */ | 
| 92 | 
> | 
rgl_filelist(ic, inp, nl)       /* load scene files into display list */ | 
| 93 | 
  | 
int     ic; | 
| 94 | 
  | 
char    **inp; | 
| 95 | 
+ | 
int     *nl;                    /* returned number of lists (optional) */ | 
| 96 | 
  | 
{ | 
| 97 | 
  | 
        int     listid; | 
| 98 | 
  | 
 | 
| 107 | 
  | 
        glEndList();            /* end of top display list */ | 
| 108 | 
  | 
        lightdefs();            /* define light sources */ | 
| 109 | 
  | 
        loadoctrees();          /* load octrees (sublists) for instances */ | 
| 110 | 
+ | 
        if (nl != NULL)         /* return total number of lists allocated */ | 
| 111 | 
+ | 
                *nl = nextlist - listid; | 
| 112 | 
  | 
        return(listid);         /* all done -- return list id */ | 
| 113 | 
  | 
} | 
| 114 | 
  | 
 | 
| 115 | 
  | 
 | 
| 116 | 
  | 
int | 
| 117 | 
< | 
rgl_octlist(fname, cent, radp)  /* load octree objects into display list */ | 
| 117 | 
> | 
rgl_octlist(fname, cent, radp, nl)      /* load scen into display list */ | 
| 118 | 
  | 
char    *fname; | 
| 119 | 
  | 
FVECT   cent;                   /* returned octree center (optional) */ | 
| 120 | 
< | 
double  *radp;                  /* returned octree size (optional) */ | 
| 120 | 
> | 
FLOAT   *radp;                  /* returned octree size (optional) */ | 
| 121 | 
> | 
int     *nl;                    /* returned number of lists (optional) */ | 
| 122 | 
  | 
{ | 
| 123 | 
  | 
        double  r; | 
| 124 | 
  | 
        int     listid; | 
| 137 | 
  | 
        glEndList();            /* close top list */ | 
| 138 | 
  | 
        lightdefs();            /* define light sources */ | 
| 139 | 
  | 
        loadoctrees();          /* load referenced octrees into sublists */ | 
| 140 | 
+ | 
        if (nl != NULL)         /* return total number of lists allocated */ | 
| 141 | 
+ | 
                *nl = nextlist - listid; | 
| 142 | 
  | 
        return(listid); | 
| 143 | 
  | 
} | 
| 144 | 
  | 
 | 
| 145 | 
  | 
 | 
| 146 | 
+ | 
void | 
| 147 | 
  | 
rgl_load(inpspec)               /* convert scene description into OGL calls */ | 
| 148 | 
  | 
char    *inpspec; | 
| 149 | 
  | 
{ | 
| 186 | 
  | 
} | 
| 187 | 
  | 
 | 
| 188 | 
  | 
 | 
| 189 | 
+ | 
void | 
| 190 | 
  | 
rgl_object(name, fp)                    /* read the next object */ | 
| 191 | 
  | 
char  *name; | 
| 192 | 
  | 
FILE  *fp; | 
| 198 | 
  | 
        strcpy(sbuf, "EOF"); | 
| 199 | 
  | 
        fgetword(sbuf, MAXSTR, fp); | 
| 200 | 
  | 
        ob.omod = 0;                    /* use ob.os for pointer to material */ | 
| 201 | 
< | 
        if (!strcmp(sbuf, VOIDID)) | 
| 201 | 
> | 
        if (!strcmp(sbuf, VOIDID) || !strcmp(sbuf, ALIASMOD)) | 
| 202 | 
  | 
                ob.os = NULL; | 
| 203 | 
  | 
        else | 
| 204 | 
  | 
                ob.os = (char *)getmatp(sbuf); | 
| 205 | 
  | 
                                        /* get type */ | 
| 206 | 
  | 
        strcpy(sbuf, "EOF"); | 
| 207 | 
  | 
        fgetword(sbuf, MAXSTR, fp); | 
| 208 | 
< | 
        if (!strcmp(sbuf, ALIASID)) | 
| 205 | 
< | 
                ob.otype = -1; | 
| 206 | 
< | 
        else if ((ob.otype = otype(sbuf)) < 0) { | 
| 208 | 
> | 
        if ((ob.otype = otype(sbuf)) < 0) { | 
| 209 | 
  | 
                sprintf(errmsg, "(%s): unknown type \"%s\"", name, sbuf); | 
| 210 | 
  | 
                error(USER, errmsg); | 
| 211 | 
  | 
        } | 
| 214 | 
  | 
        fgetword(sbuf, MAXSTR, fp); | 
| 215 | 
  | 
        ob.oname = sbuf; | 
| 216 | 
  | 
                                        /* get arguments */ | 
| 217 | 
< | 
        if (ob.otype == -1) { | 
| 217 | 
> | 
        if (ob.otype == MOD_ALIAS) { | 
| 218 | 
  | 
                char  sbuf2[MAXSTR];            /* get alias */ | 
| 219 | 
  | 
                strcpy(sbuf2, "EOF"); | 
| 220 | 
  | 
                fgetword(sbuf2, MAXSTR, fp); |