1 |
greg |
2.1 |
#ifndef lint |
2 |
greg |
2.17 |
static const char RCSid[] = "$Id: preload.c,v 2.16 2018/06/26 14:42:18 greg Exp $"; |
3 |
greg |
2.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* Preload associated object structures to maximize memory sharing. |
6 |
greg |
2.6 |
* |
7 |
|
|
* External symbols declared in ray.h |
8 |
|
|
*/ |
9 |
|
|
|
10 |
greg |
2.7 |
#include "copyright.h" |
11 |
greg |
2.1 |
|
12 |
greg |
2.10 |
#include "ray.h" |
13 |
greg |
2.1 |
#include "otypes.h" |
14 |
|
|
#include "face.h" |
15 |
|
|
#include "cone.h" |
16 |
greg |
2.2 |
#include "instance.h" |
17 |
greg |
2.9 |
#include "mesh.h" |
18 |
greg |
2.5 |
#include "data.h" |
19 |
schorsch |
2.8 |
#include "func.h" |
20 |
greg |
2.10 |
#include "bsdf.h" |
21 |
greg |
2.1 |
|
22 |
|
|
|
23 |
greg |
2.6 |
/* KEEP THIS ROUTINE CONSISTENT WITH THE DIFFERENT OBJECT FUNCTIONS! */ |
24 |
|
|
|
25 |
|
|
|
26 |
greg |
2.13 |
int |
27 |
schorsch |
2.8 |
load_os( /* load associated data for object */ |
28 |
greg |
2.13 |
OBJREC *op |
29 |
schorsch |
2.8 |
) |
30 |
greg |
2.1 |
{ |
31 |
greg |
2.14 |
DATARRAY *dp; |
32 |
|
|
SDData *sd; |
33 |
|
|
|
34 |
|
|
SDretainSet = SDretainAll; |
35 |
greg |
2.6 |
|
36 |
greg |
2.1 |
switch (op->otype) { |
37 |
|
|
case OBJ_FACE: /* polygon */ |
38 |
|
|
getface(op); |
39 |
|
|
return(1); |
40 |
|
|
case OBJ_CONE: /* cone */ |
41 |
|
|
case OBJ_RING: /* disk */ |
42 |
|
|
case OBJ_CYLINDER: /* cylinder */ |
43 |
|
|
case OBJ_CUP: /* inverted cone */ |
44 |
|
|
case OBJ_TUBE: /* inverted cylinder */ |
45 |
|
|
getcone(op, 1); |
46 |
|
|
return(1); |
47 |
|
|
case OBJ_INSTANCE: /* octree instance */ |
48 |
|
|
getinstance(op, IO_ALL); |
49 |
|
|
return(1); |
50 |
greg |
2.9 |
case OBJ_MESH: /* mesh instance */ |
51 |
|
|
getmeshinst(op, IO_ALL); |
52 |
|
|
return(1); |
53 |
greg |
2.5 |
case PAT_CPICT: /* color picture */ |
54 |
|
|
if (op->oargs.nsargs < 4) |
55 |
|
|
goto sargerr; |
56 |
|
|
getpict(op->oargs.sarg[3]); |
57 |
greg |
2.6 |
getfunc(op, 4, 0x3<<5, 0); |
58 |
greg |
2.5 |
return(1); |
59 |
|
|
case PAT_CDATA: /* color data */ |
60 |
greg |
2.17 |
if (op->oargs.nsargs < 4) |
61 |
|
|
goto sargerr; |
62 |
greg |
2.6 |
dp = getdata(op->oargs.sarg[3]); |
63 |
|
|
getdata(op->oargs.sarg[4]); |
64 |
|
|
getdata(op->oargs.sarg[5]); |
65 |
|
|
getfunc(op, 6, ((1<<dp->nd)-1)<<7, 0); |
66 |
|
|
return(1); |
67 |
|
|
case PAT_BDATA: /* brightness data */ |
68 |
|
|
if (op->oargs.nsargs < 2) |
69 |
|
|
goto sargerr; |
70 |
|
|
dp = getdata(op->oargs.sarg[1]); |
71 |
|
|
getfunc(op, 2, ((1<<dp->nd)-1)<<3, 0); |
72 |
|
|
return(1); |
73 |
|
|
case PAT_BFUNC: /* brightness function */ |
74 |
|
|
getfunc(op, 1, 0x1, 0); |
75 |
|
|
return(1); |
76 |
|
|
case PAT_CFUNC: /* color function */ |
77 |
|
|
getfunc(op, 3, 0x7, 0); |
78 |
|
|
return(1); |
79 |
greg |
2.17 |
case PAT_SPECFUNC: /* spectral function */ |
80 |
|
|
getfunc(op, 1, 0, 0); |
81 |
|
|
return(1); |
82 |
|
|
case PAT_SPECFILE: /* spectrum file */ |
83 |
|
|
if (op->oargs.nsargs < 1) |
84 |
|
|
goto sargerr; |
85 |
|
|
getdata(op->oargs.sarg[0]); |
86 |
|
|
return(1); |
87 |
|
|
case PAT_SPECDATA: /* spectral data file */ |
88 |
|
|
if (op->oargs.nsargs < 2) |
89 |
|
|
goto sargerr; |
90 |
|
|
dp = getdata(op->oargs.sarg[1]); |
91 |
|
|
getfunc(op, 2, ((1<<(dp->nd-1)) - 1)<<3, 0); |
92 |
|
|
return(1); |
93 |
|
|
case PAT_SPECPICT: /* spectral picture */ |
94 |
|
|
if (op->oargs.nsargs < 2) |
95 |
|
|
goto sargerr; |
96 |
|
|
getspec(op->oargs.sarg[1]); |
97 |
|
|
getfunc(op, 2, 0x3<<3, 0); |
98 |
|
|
return(1); |
99 |
greg |
2.5 |
case TEX_DATA: /* texture data */ |
100 |
|
|
if (op->oargs.nsargs < 6) |
101 |
|
|
goto sargerr; |
102 |
greg |
2.6 |
dp = getdata(op->oargs.sarg[3]); |
103 |
greg |
2.5 |
getdata(op->oargs.sarg[4]); |
104 |
|
|
getdata(op->oargs.sarg[5]); |
105 |
greg |
2.6 |
getfunc(op, 6, ((1<<dp->nd)-1)<<7, 1); |
106 |
|
|
return(1); |
107 |
|
|
case TEX_FUNC: /* texture function */ |
108 |
|
|
getfunc(op, 3, 0x7, 1); |
109 |
|
|
return(1); |
110 |
|
|
case MIX_DATA: /* mixture data */ |
111 |
|
|
dp = getdata(op->oargs.sarg[3]); |
112 |
|
|
getfunc(op, 4, ((1<<dp->nd)-1)<<5, 0); |
113 |
|
|
return(1); |
114 |
|
|
case MIX_PICT: /* mixture picture */ |
115 |
|
|
getpict(op->oargs.sarg[3]); |
116 |
|
|
getfunc(op, 4, 0x3<<5, 0); |
117 |
|
|
return(1); |
118 |
|
|
case MIX_FUNC: /* mixture function */ |
119 |
|
|
getfunc(op, 3, 0x4, 0); |
120 |
|
|
return(1); |
121 |
|
|
case MAT_PLASTIC2: /* anisotropic plastic */ |
122 |
|
|
case MAT_METAL2: /* anisotropic metal */ |
123 |
|
|
getfunc(op, 3, 0x7, 1); |
124 |
|
|
return(1); |
125 |
|
|
case MAT_BRTDF: /* BRDTfunc material */ |
126 |
|
|
getfunc(op, 9, 0x3f, 0); |
127 |
greg |
2.5 |
return(1); |
128 |
greg |
2.10 |
case MAT_BSDF: /* BSDF material */ |
129 |
|
|
if (op->oargs.nsargs < 6) |
130 |
|
|
goto sargerr; |
131 |
|
|
getfunc(op, 5, 0x1d, 1); |
132 |
greg |
2.14 |
sd = loadBSDF(op->oargs.sarg[1]); |
133 |
|
|
if (sd != NULL) SDfreeCache(sd); |
134 |
greg |
2.10 |
return(1); |
135 |
greg |
2.16 |
case MAT_ABSDF: /* aBSDF material */ |
136 |
greg |
2.15 |
if (op->oargs.nsargs < 5) |
137 |
|
|
goto sargerr; |
138 |
|
|
getfunc(op, 4, 0xe, 1); |
139 |
|
|
sd = loadBSDF(op->oargs.sarg[0]); |
140 |
|
|
if (sd != NULL) SDfreeCache(sd); |
141 |
|
|
return(1); |
142 |
greg |
2.5 |
case MAT_PDATA: /* plastic BRDF data */ |
143 |
|
|
case MAT_MDATA: /* metal BRDF data */ |
144 |
|
|
case MAT_TDATA: /* trans BRDF data */ |
145 |
|
|
if (op->oargs.nsargs < 2) |
146 |
|
|
goto sargerr; |
147 |
|
|
getdata(op->oargs.sarg[1]); |
148 |
greg |
2.6 |
getfunc(op, 2, 0, 0); |
149 |
|
|
return(1); |
150 |
|
|
case MAT_PFUNC: /* plastic BRDF func */ |
151 |
|
|
case MAT_MFUNC: /* metal BRDF func */ |
152 |
|
|
case MAT_TFUNC: /* trans BRDF func */ |
153 |
|
|
getfunc(op, 1, 0, 0); |
154 |
|
|
return(1); |
155 |
|
|
case MAT_DIRECT1: /* prism1 material */ |
156 |
|
|
getfunc(op, 4, 0xf, 1); |
157 |
|
|
return(1); |
158 |
|
|
case MAT_DIRECT2: /* prism2 material */ |
159 |
|
|
getfunc(op, 8, 0xff, 1); |
160 |
greg |
2.5 |
return(1); |
161 |
greg |
2.1 |
} |
162 |
greg |
2.6 |
/* nothing to load for the remaining types */ |
163 |
greg |
2.2 |
return(0); |
164 |
greg |
2.5 |
sargerr: |
165 |
|
|
objerror(op, USER, "too few string arguments"); |
166 |
schorsch |
2.8 |
return 0; /* pro forma return */ |
167 |
greg |
2.1 |
} |
168 |
|
|
|
169 |
|
|
|
170 |
greg |
2.13 |
void |
171 |
schorsch |
2.8 |
preload_objs(void) /* preload object data structures */ |
172 |
greg |
2.1 |
{ |
173 |
greg |
2.13 |
OBJECT on; |
174 |
greg |
2.3 |
/* note that nobjects may change during loop */ |
175 |
greg |
2.1 |
for (on = 0; on < nobjects; on++) |
176 |
|
|
load_os(objptr(on)); |
177 |
greg |
2.3 |
} |