-
Notifications
You must be signed in to change notification settings - Fork 412
Expand file tree
/
Copy pathrendservices.cpp
More file actions
322 lines (272 loc) · 10.9 KB
/
Copy pathrendservices.cpp
File metadata and controls
322 lines (272 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
#include <vector>
#include <string>
#include <cstdio>
#include "oslexec_pvt.h"
using namespace OSL;
using namespace OSL::pvt;
#include <OpenImageIO/strutil.h>
#include <OpenImageIO/filesystem.h>
OSL_NAMESPACE_ENTER
RendererServices::RendererServices (TextureSystem *texsys)
: m_texturesys(texsys)
{
if (! m_texturesys) {
#if OSL_NO_DEFAULT_TEXTURESYSTEM
// This build option instructs OSL to never create a TextureSystem
// itself. (Most likely reason: this build of OSL is for a renderer
// that replaces OIIO's TextureSystem with its own, and therefore
// wouldn't want to accidentally make an OIIO one here.
OSL_ASSERT (0 && "RendererServices was not passed a working TextureSystem*");
#else
m_texturesys = TextureSystem::create (true /* shared */);
// Make some good guesses about default options
m_texturesys->attribute ("automip", 1);
m_texturesys->attribute ("autotile", 64);
#endif
}
}
TextureSystem *
RendererServices::texturesys () const
{
return m_texturesys;
}
bool
RendererServices::get_inverse_matrix (ShaderGlobals *sg, Matrix44 &result,
TransformationPtr xform, float time)
{
bool ok = get_matrix (sg, result, xform, time);
if (ok)
result.invert ();
return ok;
}
bool
RendererServices::get_inverse_matrix (ShaderGlobals *sg, Matrix44 &result,
TransformationPtr xform)
{
bool ok = get_matrix (sg, result, xform);
if (ok)
result.invert ();
return ok;
}
bool
RendererServices::get_inverse_matrix (ShaderGlobals *sg, Matrix44 &result,
ustring to, float time)
{
bool ok = get_matrix (sg, result, to, time);
if (ok)
result.invert ();
return ok;
}
bool
RendererServices::get_inverse_matrix (ShaderGlobals *sg, Matrix44 &result,
ustring to)
{
bool ok = get_matrix (sg, result, to);
if (ok)
result.invert ();
return ok;
}
RendererServices::TextureHandle *
RendererServices::get_texture_handle (ustring filename, ShadingContext *context)
{
return texturesys()->get_texture_handle (filename, context->texture_thread_info());
}
bool
RendererServices::good (TextureHandle *texture_handle)
{
return texturesys()->good (texture_handle);
}
bool
RendererServices::texture (ustring filename, TextureHandle *texture_handle,
TexturePerthread *texture_thread_info,
TextureOpt &options, ShaderGlobals *sg,
float s, float t, float dsdx, float dtdx,
float dsdy, float dtdy, int nchannels,
float *result, float *dresultds, float *dresultdt,
ustring *errormessage)
{
ShadingContext *context = sg->context;
if (! texture_thread_info)
texture_thread_info = context->texture_thread_info();
if (! texture_handle)
texture_handle = texturesys()->get_texture_handle (filename, texture_thread_info);
bool status = texturesys()->texture (texture_handle, texture_thread_info,
options, s, t, dsdx, dtdx, dsdy, dtdy,
nchannels, result, dresultds, dresultdt);
if (!status) {
std::string err = texturesys()->geterror();
if (err.size() && sg) {
if (errormessage) {
*errormessage = ustring(err);
} else {
context->errorf("[RendererServices::texture] %s", err);
}
} else if (errormessage) {
*errormessage = Strings::unknown;
}
}
return status;
}
bool
RendererServices::texture3d (ustring filename, TextureHandle *texture_handle,
TexturePerthread *texture_thread_info,
TextureOpt &options, ShaderGlobals *sg,
const Vec3 &P, const Vec3 &dPdx, const Vec3 &dPdy,
const Vec3 &dPdz, int nchannels, float *result,
float *dresultds, float *dresultdt, float *dresultdr,
ustring *errormessage)
{
ShadingContext *context = sg->context;
if (! texture_thread_info)
texture_thread_info = context->texture_thread_info();
if (! texture_handle)
texture_handle = texturesys()->get_texture_handle (filename, texture_thread_info);
bool status = texturesys()->texture3d (texture_handle, texture_thread_info,
options, P, dPdx, dPdy, dPdz,
nchannels, result,
dresultds, dresultdt, dresultdr);
if (!status) {
std::string err = texturesys()->geterror();
if (err.size() && sg) {
if (errormessage) {
*errormessage = ustring(err);
} else {
sg->context->errorf("[RendererServices::texture3d] %s", err);
}
} else if (errormessage) {
*errormessage = Strings::unknown;
}
}
return status;
}
bool
RendererServices::environment (ustring filename, TextureHandle *texture_handle,
TexturePerthread *texture_thread_info,
TextureOpt &options, ShaderGlobals *sg,
const Vec3 &R, const Vec3 &dRdx, const Vec3 &dRdy,
int nchannels, float *result,
float *dresultds, float *dresultdt,
ustring *errormessage)
{
ShadingContext *context = sg->context;
if (! texture_thread_info)
texture_thread_info = context->texture_thread_info();
if (! texture_handle)
texture_handle = texturesys()->get_texture_handle (filename, texture_thread_info);
bool status = texturesys()->environment (texture_handle, texture_thread_info,
options, R, dRdx, dRdy,
nchannels, result, dresultds, dresultdt);
if (!status) {
std::string err = texturesys()->geterror();
if (err.size() && sg) {
if (errormessage) {
*errormessage = ustring(err);
} else {
sg->context->errorf("[RendererServices::environment] %s", err);
}
} else if (errormessage) {
*errormessage = Strings::unknown;
}
}
return status;
}
bool
RendererServices::get_texture_info (ustring filename,
TextureHandle *texture_handle,
TexturePerthread *texture_thread_info,
ShadingContext *shading_context,
int subimage, ustring dataname,
TypeDesc datatype,
void *data, ustring *errormessage)
{
if (! texture_thread_info)
texture_thread_info = shading_context->texture_thread_info();
if (! texture_handle)
texture_handle = texturesys()->get_texture_handle (filename, texture_thread_info);
bool status = texturesys()->get_texture_info (texture_handle, texture_thread_info, subimage,
dataname, datatype, data);
if (!status) {
std::string err = texturesys()->geterror();
if (err.size()) {
if (errormessage) {
*errormessage = ustring(err);
} else {
shading_context->errorf("[RendererServices::get_texture_info] %s", err);
}
} else if (errormessage) {
// gettextureinfo failed but did not provide an error, so none should be emitted
*errormessage = ustring();
}
}
return status;
}
bool
RendererServices::get_texture_info_type (ustring filename,
TextureHandle *texture_handle,
TexturePerthread *texture_thread_info,
ShadingContext *shading_context,
int subimage, ustring dataname,
TypeDesc &datatype, ustring *errormessage)
{
if (! texture_thread_info)
texture_thread_info = shading_context->texture_thread_info();
if (! texture_handle)
texture_handle = texturesys()->get_texture_handle (filename, texture_thread_info);
bool status = texturesys()->get_texture_info_type (texture_handle, texture_thread_info, subimage,
dataname, datatype);
if (!status) {
std::string err = texturesys()->geterror();
if (err.size()) {
if (errormessage) {
*errormessage = ustring(err);
} else {
shading_context->errorf("[RendererServices::get_texture_info] %s", err);
}
} else if (errormessage) {
// gettextureinfo failed but did not provide an error, so none should be emitted
*errormessage = ustring();
}
}
return status;
}
bool
RendererServices::get_texture_info(ustring filename,
TextureHandle* texture_handle,
float s, float t,
TexturePerthread* texture_thread_info,
ShadingContext* shading_context,
int subimage, ustring dataname,
TypeDesc datatype, void* data,
ustring* errormessage)
{
#if OIIO_VERSION >= 20307
// Newer versions of the TextureSystem interface are able to determine the
// specific UDIM tile we're using.
if (!texture_thread_info)
texture_thread_info = shading_context->texture_thread_info();
if (!texture_handle)
texture_handle = texturesys()->get_texture_handle(filename,
texture_thread_info);
if (texturesys()->is_udim(texture_handle))
texture_handle = texturesys()->resolve_udim(texture_handle,
texture_thread_info, s, t);
#endif
return get_texture_info(filename, texture_handle, texture_thread_info,
shading_context, subimage, dataname, datatype, data,
errormessage);
}
BatchedRendererServices<16>* RendererServices::batched(WidthOf<16>)
{
// No default implementation for batched services
return nullptr;
}
BatchedRendererServices<8> *
RendererServices::batched(WidthOf<8>)
{
// No default implementation for batched services
return nullptr;
}
OSL_NAMESPACE_EXIT