1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id: preload.c,v 2.10 2011/02/18 00:40:25 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 |
extern int |
27 |
load_os( /* load associated data for object */ |
28 |
register OBJREC *op |
29 |
) |
30 |
{ |
31 |
DATARRAY *dp; |
32 |
SDData *sd; |
33 |
|
34 |
switch (op->otype) { |
35 |
case OBJ_FACE: /* polygon */ |
36 |
getface(op); |
37 |
return(1); |
38 |
case OBJ_CONE: /* cone */ |
39 |
case OBJ_RING: /* disk */ |
40 |
case OBJ_CYLINDER: /* cylinder */ |
41 |
case OBJ_CUP: /* inverted cone */ |
42 |
case OBJ_TUBE: /* inverted cylinder */ |
43 |
getcone(op, 1); |
44 |
return(1); |
45 |
case OBJ_INSTANCE: /* octree instance */ |
46 |
getinstance(op, IO_ALL); |
47 |
return(1); |
48 |
case OBJ_MESH: /* mesh instance */ |
49 |
getmeshinst(op, IO_ALL); |
50 |
return(1); |
51 |
case PAT_CPICT: /* color picture */ |
52 |
if (op->oargs.nsargs < 4) |
53 |
goto sargerr; |
54 |
getpict(op->oargs.sarg[3]); |
55 |
getfunc(op, 4, 0x3<<5, 0); |
56 |
return(1); |
57 |
case PAT_CDATA: /* color data */ |
58 |
dp = getdata(op->oargs.sarg[3]); |
59 |
getdata(op->oargs.sarg[4]); |
60 |
getdata(op->oargs.sarg[5]); |
61 |
getfunc(op, 6, ((1<<dp->nd)-1)<<7, 0); |
62 |
return(1); |
63 |
case PAT_BDATA: /* brightness data */ |
64 |
if (op->oargs.nsargs < 2) |
65 |
goto sargerr; |
66 |
dp = getdata(op->oargs.sarg[1]); |
67 |
getfunc(op, 2, ((1<<dp->nd)-1)<<3, 0); |
68 |
return(1); |
69 |
case PAT_BFUNC: /* brightness function */ |
70 |
getfunc(op, 1, 0x1, 0); |
71 |
return(1); |
72 |
case PAT_CFUNC: /* color function */ |
73 |
getfunc(op, 3, 0x7, 0); |
74 |
return(1); |
75 |
case TEX_DATA: /* texture data */ |
76 |
if (op->oargs.nsargs < 6) |
77 |
goto sargerr; |
78 |
dp = getdata(op->oargs.sarg[3]); |
79 |
getdata(op->oargs.sarg[4]); |
80 |
getdata(op->oargs.sarg[5]); |
81 |
getfunc(op, 6, ((1<<dp->nd)-1)<<7, 1); |
82 |
return(1); |
83 |
case TEX_FUNC: /* texture function */ |
84 |
getfunc(op, 3, 0x7, 1); |
85 |
return(1); |
86 |
case MIX_DATA: /* mixture data */ |
87 |
dp = getdata(op->oargs.sarg[3]); |
88 |
getfunc(op, 4, ((1<<dp->nd)-1)<<5, 0); |
89 |
return(1); |
90 |
case MIX_PICT: /* mixture picture */ |
91 |
getpict(op->oargs.sarg[3]); |
92 |
getfunc(op, 4, 0x3<<5, 0); |
93 |
return(1); |
94 |
case MIX_FUNC: /* mixture function */ |
95 |
getfunc(op, 3, 0x4, 0); |
96 |
return(1); |
97 |
case MAT_PLASTIC2: /* anisotropic plastic */ |
98 |
case MAT_METAL2: /* anisotropic metal */ |
99 |
getfunc(op, 3, 0x7, 1); |
100 |
return(1); |
101 |
case MAT_BRTDF: /* BRDTfunc material */ |
102 |
getfunc(op, 9, 0x3f, 0); |
103 |
return(1); |
104 |
case MAT_BSDF: /* BSDF material */ |
105 |
if (op->oargs.nsargs < 6) |
106 |
goto sargerr; |
107 |
getfunc(op, 5, 0x1d, 1); |
108 |
loadBSDF(op->oargs.sarg[1]); |
109 |
return(1); |
110 |
case MAT_PDATA: /* plastic BRDF data */ |
111 |
case MAT_MDATA: /* metal BRDF data */ |
112 |
case MAT_TDATA: /* trans BRDF data */ |
113 |
if (op->oargs.nsargs < 2) |
114 |
goto sargerr; |
115 |
getdata(op->oargs.sarg[1]); |
116 |
getfunc(op, 2, 0, 0); |
117 |
return(1); |
118 |
case MAT_PFUNC: /* plastic BRDF func */ |
119 |
case MAT_MFUNC: /* metal BRDF func */ |
120 |
case MAT_TFUNC: /* trans BRDF func */ |
121 |
getfunc(op, 1, 0, 0); |
122 |
return(1); |
123 |
case MAT_DIRECT1: /* prism1 material */ |
124 |
getfunc(op, 4, 0xf, 1); |
125 |
return(1); |
126 |
case MAT_DIRECT2: /* prism2 material */ |
127 |
getfunc(op, 8, 0xff, 1); |
128 |
return(1); |
129 |
} |
130 |
/* nothing to load for the remaining types */ |
131 |
return(0); |
132 |
sargerr: |
133 |
objerror(op, USER, "too few string arguments"); |
134 |
return 0; /* pro forma return */ |
135 |
} |
136 |
|
137 |
|
138 |
extern void |
139 |
preload_objs(void) /* preload object data structures */ |
140 |
{ |
141 |
register OBJECT on; |
142 |
/* note that nobjects may change during loop */ |
143 |
for (on = 0; on < nobjects; on++) |
144 |
load_os(objptr(on)); |
145 |
} |