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