diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-11-04 13:49:28 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-11-04 14:19:45 +0300 |
commit | d5f978b3ccc7080e442e15f85142b717c47e7e8f (patch) | |
tree | 8ef592ea8dd60bb84b9069c264013a34ea5d5823 /intern | |
parent | d5974eb0266104344084e72211b4644e97f4af67 (diff) |
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.
Diffstat (limited to 'intern')
-rw-r--r-- | intern/cycles/kernel/osl/osl_services.cpp | 51 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/osl_services.h | 39 |
2 files changed, 72 insertions, 18 deletions
diff --git a/intern/cycles/kernel/osl/osl_services.cpp b/intern/cycles/kernel/osl/osl_services.cpp index a9694651e14..e641de041ef 100644 --- a/intern/cycles/kernel/osl/osl_services.cpp +++ b/intern/cycles/kernel/osl/osl_services.cpp @@ -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; } } diff --git a/intern/cycles/kernel/osl/osl_services.h b/intern/cycles/kernel/osl/osl_services.h index 6f928a0d103..fecf20ea57d 100644 --- a/intern/cycles/kernel/osl/osl_services.h +++ b/intern/cycles/kernel/osl/osl_services.h @@ -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; |