Cycles: Be ready for new OIIO and OSL libraries
Even tho it's not 100% clear when we'll switch to OSL-1.6 we'd better start preparing earlier for this, so we don't spend time on this later. Plus this code helps troubleshooting some OSL issues, which requires testing with latest versions of OSL.
This commit is contained in:
@@ -834,7 +834,7 @@ bool OSLRenderServices::has_userdata(ustring name, TypeDesc type, OSL::ShaderGlo
|
||||
bool OSLRenderServices::texture(ustring filename, TextureOpt &options,
|
||||
OSL::ShaderGlobals *sg,
|
||||
float s, float t, float dsdx, float dtdx,
|
||||
float dsdy, float dtdy, float *result)
|
||||
float dsdy, float dtdy, int nchannels, float *result)
|
||||
{
|
||||
OSL::TextureSystem *ts = osl_ts;
|
||||
ShaderData *sd = (ShaderData *)(sg->renderstate);
|
||||
@@ -869,9 +869,9 @@ bool OSLRenderServices::texture(ustring filename, TextureOpt &options,
|
||||
PtexFilter::Options opts(PtexFilter::f_bicubic, mipmaplerp, sharpness);
|
||||
PtexPtr<PtexFilter> f(PtexFilter::getFilter(r, opts));
|
||||
|
||||
f->eval(result, options.firstchannel, options.nchannels, faceid, u, v, dudx, dvdx, dudy, dvdy);
|
||||
f->eval(result, options.firstchannel, nchannels, faceid, u, v, dudx, dvdx, dudy, dvdy);
|
||||
|
||||
for(int c = r->numChannels(); c < options.nchannels; c++)
|
||||
for(int c = r->numChannels(); c < nchannels; c++)
|
||||
result[c] = result[0];
|
||||
|
||||
return true;
|
||||
@@ -884,11 +884,11 @@ bool OSLRenderServices::texture(ustring filename, TextureOpt &options,
|
||||
float4 rgba = kernel_tex_image_interp(slot, s, 1.0f - t);
|
||||
|
||||
result[0] = rgba[0];
|
||||
if(options.nchannels > 1)
|
||||
if(nchannels > 1)
|
||||
result[1] = rgba[1];
|
||||
if(options.nchannels > 2)
|
||||
if(nchannels > 2)
|
||||
result[2] = rgba[2];
|
||||
if(options.nchannels > 3)
|
||||
if(nchannels > 3)
|
||||
result[3] = rgba[3];
|
||||
status = true;
|
||||
}
|
||||
@@ -898,17 +898,24 @@ bool OSLRenderServices::texture(ustring filename, TextureOpt &options,
|
||||
|
||||
OIIO::TextureSystem::TextureHandle *th = ts->get_texture_handle(filename, thread_info);
|
||||
|
||||
#if OIIO_VERSION < 10500
|
||||
status = ts->texture(th, thread_info,
|
||||
options, s, t, dsdx, dtdx, dsdy, dtdy, result);
|
||||
options, s, t, dsdx, dtdx, dsdy, dtdy,
|
||||
result);
|
||||
#else
|
||||
status = ts->texture(th, thread_info,
|
||||
options, s, t, dsdx, dtdx, dsdy, dtdy,
|
||||
nchannels, result);
|
||||
#endif
|
||||
}
|
||||
|
||||
if(!status) {
|
||||
if(options.nchannels == 3 || options.nchannels == 4) {
|
||||
if(nchannels == 3 || nchannels == 4) {
|
||||
result[0] = 1.0f;
|
||||
result[1] = 0.0f;
|
||||
result[2] = 1.0f;
|
||||
|
||||
if(options.nchannels == 4)
|
||||
if(nchannels == 4)
|
||||
result[3] = 1.0f;
|
||||
}
|
||||
}
|
||||
@@ -919,7 +926,7 @@ bool OSLRenderServices::texture(ustring filename, TextureOpt &options,
|
||||
bool OSLRenderServices::texture3d(ustring filename, TextureOpt &options,
|
||||
OSL::ShaderGlobals *sg, const OSL::Vec3 &P,
|
||||
const OSL::Vec3 &dPdx, const OSL::Vec3 &dPdy,
|
||||
const OSL::Vec3 &dPdz, float *result)
|
||||
const OSL::Vec3 &dPdz, int nchannels, float *result)
|
||||
{
|
||||
OSL::TextureSystem *ts = osl_ts;
|
||||
ShaderData *sd = (ShaderData *)(sg->renderstate);
|
||||
@@ -929,16 +936,22 @@ bool OSLRenderServices::texture3d(ustring filename, TextureOpt &options,
|
||||
|
||||
OIIO::TextureSystem::TextureHandle *th = ts->get_texture_handle(filename, thread_info);
|
||||
|
||||
#if OIIO_VERSION < 10500
|
||||
bool status = ts->texture3d(th, thread_info,
|
||||
options, P, dPdx, dPdy, dPdz, result);
|
||||
#else
|
||||
bool status = ts->texture3d(th, thread_info,
|
||||
options, P, dPdx, dPdy, dPdz,
|
||||
nchannels, result);
|
||||
#endif
|
||||
|
||||
if(!status) {
|
||||
if(options.nchannels == 3 || options.nchannels == 4) {
|
||||
if(nchannels == 3 || nchannels == 4) {
|
||||
result[0] = 1.0f;
|
||||
result[1] = 0.0f;
|
||||
result[2] = 1.0f;
|
||||
|
||||
if(options.nchannels == 4)
|
||||
if(nchannels == 4)
|
||||
result[3] = 1.0f;
|
||||
}
|
||||
|
||||
@@ -949,7 +962,8 @@ bool OSLRenderServices::texture3d(ustring filename, TextureOpt &options,
|
||||
|
||||
bool OSLRenderServices::environment(ustring filename, TextureOpt &options,
|
||||
OSL::ShaderGlobals *sg, const OSL::Vec3 &R,
|
||||
const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy, float *result)
|
||||
const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy,
|
||||
int nchannels, float *result)
|
||||
{
|
||||
OSL::TextureSystem *ts = osl_ts;
|
||||
ShaderData *sd = (ShaderData *)(sg->renderstate);
|
||||
@@ -958,16 +972,23 @@ bool OSLRenderServices::environment(ustring filename, TextureOpt &options,
|
||||
OIIO::TextureSystem::Perthread *thread_info = tdata->oiio_thread_info;
|
||||
|
||||
OIIO::TextureSystem::TextureHandle *th = ts->get_texture_handle(filename, thread_info);
|
||||
|
||||
#if OIIO_VERSION < 10500
|
||||
bool status = ts->environment(th, thread_info,
|
||||
options, R, dRdx, dRdy, result);
|
||||
#else
|
||||
bool status = ts->environment(th, thread_info,
|
||||
options, R, dRdx, dRdy,
|
||||
nchannels, result);
|
||||
#endif
|
||||
|
||||
if(!status) {
|
||||
if(options.nchannels == 3 || options.nchannels == 4) {
|
||||
if(nchannels == 3 || nchannels == 4) {
|
||||
result[0] = 1.0f;
|
||||
result[1] = 0.0f;
|
||||
result[2] = 1.0f;
|
||||
|
||||
if(options.nchannels == 4)
|
||||
if(nchannels == 4)
|
||||
result[3] = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,16 +97,17 @@ public:
|
||||
bool texture(ustring filename, TextureOpt &options,
|
||||
OSL::ShaderGlobals *sg,
|
||||
float s, float t, float dsdx, float dtdx,
|
||||
float dsdy, float dtdy, float *result);
|
||||
float dsdy, float dtdy, int nchannels, float *result);
|
||||
|
||||
bool texture3d(ustring filename, TextureOpt &options,
|
||||
OSL::ShaderGlobals *sg, const OSL::Vec3 &P,
|
||||
const OSL::Vec3 &dPdx, const OSL::Vec3 &dPdy,
|
||||
const OSL::Vec3 &dPdz, float *result);
|
||||
const OSL::Vec3 &dPdz, int nchannels, float *result);
|
||||
|
||||
bool environment(ustring filename, TextureOpt &options,
|
||||
OSL::ShaderGlobals *sg, const OSL::Vec3 &R,
|
||||
const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy, float *result);
|
||||
const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy,
|
||||
int nchannels, float *result);
|
||||
|
||||
bool get_texture_info(OSL::ShaderGlobals *sg, ustring filename, int subimage,
|
||||
ustring dataname, TypeDesc datatype, void *data);
|
||||
@@ -159,6 +160,8 @@ public:
|
||||
static ustring u_v;
|
||||
static ustring u_empty;
|
||||
|
||||
/* Code to make OSL versions transition smooth. */
|
||||
|
||||
#if OSL_LIBRARY_VERSION_CODE < 10500
|
||||
bool get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform, float time) {
|
||||
return get_matrix(NULL, result, xform, time);
|
||||
@@ -223,6 +226,36 @@ public:
|
||||
return get_texture_info(NULL, filename, subimage, dataname, datatype, data);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if OSL_LIBRARY_VERSION_CODE < 10600
|
||||
inline bool texture(ustring filename, TextureOpt &options,
|
||||
OSL::ShaderGlobals *sg,
|
||||
float s, float t, float dsdx, float dtdx,
|
||||
float dsdy, float dtdy, float *result)
|
||||
{
|
||||
return texture(filename, options, sg, s, t, dsdx, dtdx, dsdy, dtdy,
|
||||
options.nchannels, result);
|
||||
}
|
||||
|
||||
inline bool texture3d(ustring filename, TextureOpt &options,
|
||||
OSL::ShaderGlobals *sg, const OSL::Vec3 &P,
|
||||
const OSL::Vec3 &dPdx, const OSL::Vec3 &dPdy,
|
||||
const OSL::Vec3 &dPdz, float *result)
|
||||
{
|
||||
return texture3d(filename, options, sg, P, dPdx, dPdy, dPdz,
|
||||
options.nchannels, result);
|
||||
}
|
||||
|
||||
inline bool environment(ustring filename, TextureOpt &options,
|
||||
OSL::ShaderGlobals *sg, const OSL::Vec3 &R,
|
||||
const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy,
|
||||
float *result)
|
||||
{
|
||||
return environment(filename, options, sg, R, dRdx, dRdy,
|
||||
options.nchannels, result);
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
KernelGlobals *kernel_globals;
|
||||
OSL::TextureSystem *osl_ts;
|
||||
|
||||
Reference in New Issue
Block a user