OLD | NEW |
1 /* | 1 /* |
2 Copyright (c) 2010 Sony Pictures Imageworks Inc., et al. | 2 Copyright (c) 2010 Sony Pictures Imageworks Inc., et al. |
3 All Rights Reserved. | 3 All Rights Reserved. |
4 | 4 |
5 Redistribution and use in source and binary forms, with or without | 5 Redistribution and use in source and binary forms, with or without |
6 modification, are permitted provided that the following conditions are | 6 modification, are permitted provided that the following conditions are |
7 met: | 7 met: |
8 * Redistributions of source code must retain the above copyright | 8 * Redistributions of source code must retain the above copyright |
9 notice, this list of conditions and the following disclaimer. | 9 notice, this list of conditions and the following disclaimer. |
10 * Redistributions in binary form must reproduce the above copyright | 10 * Redistributions in binary form must reproduce the above copyright |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 // ! exec->all_points_on()); | 84 // ! exec->all_points_on()); |
85 bool varying = true; | 85 bool varying = true; |
86 TypeDesc type = Val.typespec().simpletype(); | 86 TypeDesc type = Val.typespec().simpletype(); |
87 if (Val.typespec().is_closure ()) | 87 if (Val.typespec().is_closure ()) |
88 type = TypeDesc::TypeInt; // Actually store closure indices only | 88 type = TypeDesc::TypeInt; // Actually store closure indices only |
89 size_t datasize = type.size(); | 89 size_t datasize = type.size(); |
90 | 90 |
91 ustring lastname; // Last message name that we matched | 91 ustring lastname; // Last message name that we matched |
92 ParamValue *p = NULL; // Pointer to the PV for the message | 92 ParamValue *p = NULL; // Pointer to the PV for the message |
93 | 93 |
94 for (int i = beginpoint; i < endpoint; ++i) { | 94 SHADE_LOOP_BEGIN |
95 if (runflags[i]) { | 95 if (i == exec->beginpoint() || name[i] != lastname) { |
96 if (i == beginpoint || name[i] != lastname) { | 96 // Different message than last time -- search anew |
97 // Different message than last time -- search anew | 97 p = NULL; |
98 p = NULL; | 98 for (size_t m = 0; m < messages.size() && !p; ++m) |
99 for (size_t m = 0; m < messages.size() && !p; ++m) | 99 if (messages[m].name() == name[i] && |
100 if (messages[m].name() == name[i] && | 100 messages[m].type() == type) |
101 messages[m].type() == type) | 101 p = &messages[m]; |
102 p = &messages[m]; | 102 // If the message doesn't already exist, create it |
103 // If the message doesn't already exist, create it | 103 if (! p) { |
104 if (! p) { | 104 p = & messages.grow (); |
105 p = & messages.grow (); | 105 p->init (name[i], type, |
106 p->init (name[i], type, | 106 varying ? exec->npoints() : 1, NULL); |
107 varying ? exec->npoints() : 1, NULL); | |
108 } | |
109 lastname = name[i]; | |
110 } | 107 } |
| 108 lastname = name[i]; |
| 109 } |
111 | 110 |
112 // Copy the data | 111 // Copy the data |
113 DASSERT (p != NULL); | 112 DASSERT (p != NULL); |
114 char *msgdata = (char *)p->data() + varying*datasize*i; | 113 char *msgdata = (char *)p->data() + varying*datasize*i; |
115 if (Val.typespec().is_closure()) { | 114 if (Val.typespec().is_closure()) { |
116 // Add the closure data to the end of the closure messages | 115 // Add the closure data to the end of the closure messages |
117 closure_msgs.push_back (**(ClosureColor **)Val.data(i)); | 116 closure_msgs.push_back (**(ClosureColor **)Val.data(i)); |
118 // and store its index in the PVL | 117 // and store its index in the PVL |
119 *(int *)msgdata = (int)closure_msgs.size() - 1; | 118 *(int *)msgdata = (int)closure_msgs.size() - 1; |
120 } else { | 119 } else { |
121 // Non-closure types, just memcpy | 120 // Non-closure types, just memcpy |
122 memcpy (msgdata, Val.data(i), datasize); | 121 memcpy (msgdata, Val.data(i), datasize); |
123 } | |
124 } | 122 } |
125 if (! varying) | 123 if (! varying) |
126 break; // Non-uniform case can take early out | 124 break; // Non-uniform case can take early out |
127 } | 125 SHADE_LOOP_END |
128 } | 126 } |
129 | 127 |
130 | 128 |
131 | 129 |
132 // int getmessage (string name, ANY value) | 130 // int getmessage (string name, ANY value) |
133 DECLOP (OP_getmessage) | 131 DECLOP (OP_getmessage) |
134 { | 132 { |
135 ASSERT (nargs == 3); | 133 ASSERT (nargs == 3); |
136 Symbol &Result (exec->sym (args[0])); | 134 Symbol &Result (exec->sym (args[0])); |
137 Symbol &Name (exec->sym (args[1])); | 135 Symbol &Name (exec->sym (args[1])); |
(...skipping 18 matching lines...) Expand all Loading... |
156 std::vector<ClosureColor> &closure_msgs (exec->context()->closure_msgs()); | 154 std::vector<ClosureColor> &closure_msgs (exec->context()->closure_msgs()); |
157 | 155 |
158 TypeDesc type = Val.typespec().simpletype(); | 156 TypeDesc type = Val.typespec().simpletype(); |
159 if (Val.typespec().is_closure ()) | 157 if (Val.typespec().is_closure ()) |
160 type = TypeDesc::TypeInt; // Actually store closure indices only | 158 type = TypeDesc::TypeInt; // Actually store closure indices only |
161 size_t datasize = type.size(); | 159 size_t datasize = type.size(); |
162 | 160 |
163 ustring lastname; // Last message name that we matched | 161 ustring lastname; // Last message name that we matched |
164 ParamValue *p = NULL; // Pointer to the PV for the message | 162 ParamValue *p = NULL; // Pointer to the PV for the message |
165 | 163 |
166 for (int i = beginpoint; i < endpoint; ++i) { | 164 SHADE_LOOP_BEGIN |
167 if (runflags[i]) { | 165 if (i == exec->beginpoint() || name[i] != lastname) { |
168 if (i == beginpoint || name[i] != lastname) { | 166 // Different message than last time -- search anew |
169 // Different message than last time -- search anew | 167 p = NULL; |
170 p = NULL; | 168 for (size_t m = 0; m < messages.size() && !p; ++m) |
171 for (size_t m = 0; m < messages.size() && !p; ++m) | 169 if (messages[m].name() == name[i] && |
172 if (messages[m].name() == name[i] && | 170 messages[m].type() == type) |
173 messages[m].type() == type) | 171 p = &messages[m]; |
174 p = &messages[m]; | 172 if (p && (! varying || Val.is_uniform()) && p->nvalues() > 1) { |
175 if (p && (! varying || Val.is_uniform()) && p->nvalues() > 1) { | 173 // all the parameters to the function were uniform, |
176 // all the parameters to the function were uniform, | 174 // but the message itself is varying, so adjust Val. |
177 // but the message itself is varying, so adjust Val. | 175 exec->adjust_varying (Val, true); |
178 exec->adjust_varying (Val, true); | 176 varying = true; |
179 varying = true; | |
180 } | |
181 lastname = name[i]; | |
182 } | 177 } |
| 178 lastname = name[i]; |
| 179 } |
183 | 180 |
184 if (p) { | 181 if (p) { |
185 result[i] = 1; // found | 182 result[i] = 1; // found |
186 char *msgdata = (char *)p->data() + varying*datasize*i; | 183 char *msgdata = (char *)p->data() + varying*datasize*i; |
187 if (Val.typespec().is_closure()) { | 184 if (Val.typespec().is_closure()) { |
188 // Retrieve the closure index from the PVL | 185 // Retrieve the closure index from the PVL |
189 int index = *(int *)msgdata; | 186 int index = *(int *)msgdata; |
190 ClosureColor *valclose = *(ClosureColor **) Val.data(i); | 187 ClosureColor *valclose = *(ClosureColor **) Val.data(i); |
191 // then copy the closure (or clear it, if out of range) | 188 // then copy the closure (or clear it, if out of range) |
192 if (index < (int)closure_msgs.size()) | 189 if (index < (int)closure_msgs.size()) |
193 *valclose = closure_msgs[index]; | 190 *valclose = closure_msgs[index]; |
194 else | 191 else |
195 valclose->clear (); | 192 valclose->clear (); |
196 } else { | |
197 memcpy (Val.data(i), msgdata, datasize); | |
198 } | |
199 } else { | 193 } else { |
200 result[i] = 0; // not found | 194 memcpy (Val.data(i), msgdata, datasize); |
201 } | 195 } |
| 196 } else { |
| 197 result[i] = 0; // not found |
202 } | 198 } |
203 if (! varying) | 199 if (! varying) |
204 break; // Non-uniform case can take early out | 200 break; // Non-uniform case can take early out |
205 } | 201 SHADE_LOOP_END |
206 | 202 |
207 if (Val.has_derivs ()) | 203 if (Val.has_derivs ()) |
208 exec->zero_derivs (Val); | 204 exec->zero_derivs (Val); |
209 } | 205 } |
210 | 206 |
211 | 207 |
212 | 208 |
213 }; // namespace pvt | 209 }; // namespace pvt |
214 }; // namespace OSL | 210 }; // namespace OSL |
215 #ifdef OSL_NAMESPACE | 211 #ifdef OSL_NAMESPACE |
216 }; // end namespace OSL_NAMESPACE | 212 }; // end namespace OSL_NAMESPACE |
217 #endif | 213 #endif |
OLD | NEW |