Skip to content

Commit

Permalink
Changes for OSL 1.7 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
est77 committed Feb 6, 2016
1 parent 8706abf commit 626d25f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 16 deletions.
10 changes: 10 additions & 0 deletions src/appleseed/renderer/kernel/rendering/baserenderer.cpp
Expand Up @@ -87,7 +87,11 @@ BaseRenderer::BaseRenderer(
RENDERER_LOG_DEBUG("creating OSL shading system...");
m_renderer_services = new RendererServices(m_project, *m_texture_system);

#if OSL_LIBRARY_VERSION_CODE >= 10700
m_shading_system = new OSL::ShadingSystem(
#else
m_shading_system = OSL::ShadingSystem::create(
#endif
m_renderer_services,
m_texture_system,
m_error_handler);
Expand Down Expand Up @@ -122,7 +126,13 @@ BaseRenderer::~BaseRenderer()
#ifdef APPLESEED_WITH_OSL
RENDERER_LOG_DEBUG("destroying OSL shading system...");
m_project.get_scene()->release_optimized_osl_shader_groups();

#if OSL_LIBRARY_VERSION_CODE >= 10700
delete m_shading_system;
#else
OSL::ShadingSystem::destroy(m_shading_system);
#endif

delete m_renderer_services;
#endif

Expand Down
2 changes: 2 additions & 0 deletions src/appleseed/renderer/kernel/rendering/rendererservices.cpp
Expand Up @@ -504,13 +504,15 @@ bool RendererServices::get_userdata(
return false;
}

#if OSL_LIBRARY_VERSION_CODE < 10700
bool RendererServices::has_userdata(
OIIO::ustring name,
OIIO::TypeDesc type,
OSL::ShaderGlobals* sg)
{
return false;
}
#endif

#define IMPLEMENT_ATTR_GETTER(name) \
bool RendererServices::get_##name( \
Expand Down
9 changes: 5 additions & 4 deletions src/appleseed/renderer/kernel/rendering/rendererservices.h
Expand Up @@ -295,11 +295,12 @@ class RendererServices
OSL::ShaderGlobals* sg,
void* val) APPLESEED_OVERRIDE;

// Does the current object have the named user-data associated with it?
#if OSL_LIBRARY_VERSION_CODE < 10700
virtual bool has_userdata(
OIIO::ustring name,
OIIO::TypeDesc type,
OSL::ShaderGlobals* sg) APPLESEED_OVERRIDE;
OIIO::ustring name,
OIIO::TypeDesc type,
OSL::ShaderGlobals* sg) APPLESEED_OVERRIDE;
#endif

private:
// This code based on OSL's test renderer.
Expand Down
33 changes: 21 additions & 12 deletions src/appleseed/renderer/kernel/shading/closures.cpp
Expand Up @@ -44,6 +44,7 @@
BEGIN_OSL_INCLUDES
#include "OSL/genclosure.h"
#include "OSL/oslclosure.h"
#include "OSL/oslversion.h"
END_OSL_INCLUDES

// Boost headers.
Expand Down Expand Up @@ -1125,7 +1126,11 @@ void CompositeSurfaceClosure::process_closure_tree(
if (closure == 0)
return;

#if OSL_LIBRARY_VERSION_CODE >= 10700
switch (closure->id)
#else
switch (closure->type)
#endif
{
case OSL::ClosureColor::MUL:
{
Expand All @@ -1143,7 +1148,7 @@ void CompositeSurfaceClosure::process_closure_tree(
}
break;

case OSL::ClosureColor::COMPONENT:
default:
{
const OSL::ClosureComponent* c = reinterpret_cast<const OSL::ClosureComponent*>(closure);
const Color3f w = weight * Color3f(c->w);
Expand All @@ -1152,8 +1157,6 @@ void CompositeSurfaceClosure::process_closure_tree(
g_closure_convert_funs[c->id](*this, original_shading_basis, c->data(), w);
}
break;

assert_otherwise;
}
}

Expand All @@ -1178,7 +1181,11 @@ void CompositeSubsurfaceClosure::process_closure_tree(
if (closure == 0)
return;

#if OSL_LIBRARY_VERSION_CODE >= 10700
switch (closure->id)
#else
switch (closure->type)
#endif
{
case OSL::ClosureColor::MUL:
{
Expand All @@ -1195,7 +1202,7 @@ void CompositeSubsurfaceClosure::process_closure_tree(
}
break;

case OSL::ClosureColor::COMPONENT:
default:
{
const OSL::ClosureComponent* c = reinterpret_cast<const OSL::ClosureComponent*>(closure);

Expand All @@ -1213,8 +1220,6 @@ void CompositeSubsurfaceClosure::process_closure_tree(
}
}
break;

assert_otherwise;
}
}

Expand Down Expand Up @@ -1253,7 +1258,11 @@ void CompositeEmissionClosure::process_closure_tree(
if (closure == 0)
return;

#if OSL_LIBRARY_VERSION_CODE >= 10700
switch (closure->id)
#else
switch (closure->type)
#endif
{
case OSL::ClosureColor::MUL:
{
Expand All @@ -1270,16 +1279,14 @@ void CompositeEmissionClosure::process_closure_tree(
}
break;

case OSL::ClosureColor::COMPONENT:
default:
{
const OSL::ClosureComponent* c = reinterpret_cast<const OSL::ClosureComponent*>(closure);

if (c->id == EmissionID)
m_total_weight += weight * Color3f(c->w);
}
break;

assert_otherwise;
}
}

Expand All @@ -1296,7 +1303,11 @@ namespace
{
if (closure)
{
#if OSL_LIBRARY_VERSION_CODE >= 10700
switch (closure->id)
#else
switch (closure->type)
#endif
{
case OSL::ClosureColor::MUL:
{
Expand All @@ -1313,14 +1324,12 @@ namespace
}
break;

case OSL::ClosureColor::COMPONENT:
default:
{
const OSL::ClosureComponent* c = reinterpret_cast<const OSL::ClosureComponent*>(closure);
return c->id == closure_id ? Color3f(c->w) : Color3f(0.0f);
}
break;

assert_otherwise;
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/appleseed/renderer/kernel/shading/oslshadergroupexec.cpp
Expand Up @@ -199,7 +199,11 @@ Color3f OSLShaderGroupExec::execute_background(
sg.raytype = VisibilityFlags::CameraRay;

m_osl_shading_system.execute(
#if OSL_LIBRARY_VERSION_CODE >= 10700
m_osl_shading_context,
#else
*m_osl_shading_context,
#endif
*shader_group.shader_group_ref(),
sg);

Expand All @@ -220,7 +224,11 @@ void OSLShaderGroupExec::do_execute(
m_osl_shading_system.renderer());

m_osl_shading_system.execute(
#if OSL_LIBRARY_VERSION_CODE >= 10700
m_osl_shading_context,
#else
*m_osl_shading_context,
#endif
*shader_group.shader_group_ref(),
shading_point.get_osl_shader_globals());
}
Expand Down
1 change: 1 addition & 0 deletions src/appleseed/renderer/kernel/shading/oslshadergroupexec.h
Expand Up @@ -42,6 +42,7 @@
#include "foundation/platform/oslheaderguards.h"
BEGIN_OSL_INCLUDES
#include "OSL/oslexec.h"
#include "OSL/oslversion.h"
END_OSL_INCLUDES

// Forward declarations.
Expand Down

0 comments on commit 626d25f

Please sign in to comment.