Skip to content

Commit

Permalink
Defer to default color management in OCIO code for known transforms
Browse files Browse the repository at this point in the history
Make the OCIO color manager derive from the default color management.
  • Loading branch information
JGamache-autodesk committed Aug 20, 2024
1 parent 9130574 commit 3e1ccfc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion source/MaterialXGenShader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ mx_add_library(MaterialXGenShader

if(MATERIALX_BUILD_OCIO)
find_package(OpenColorIO REQUIRED)
target_link_libraries(${TARGET_NAME} OpenColorIO::OpenColorIO)
target_link_libraries(${TARGET_NAME} PUBLIC OpenColorIO::OpenColorIO)
target_compile_definitions(${TARGET_NAME} PUBLIC MATERIALX_BUILD_OCIO)
endif()
13 changes: 13 additions & 0 deletions source/MaterialXGenShader/OpenColorIOManagementSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ OpenColorIOManagementSystemPtr OpenColorIOManagementSystem::create(const OCIO::C
}

OpenColorIOManagementSystem::OpenColorIOManagementSystem(const OCIO::ConstConfigRcPtr& config, const string& target) :
DefaultColorManagementSystem(target),
_target(target),
_config(std::move(config))
{
Expand Down Expand Up @@ -94,6 +95,11 @@ const char* OpenColorIOManagementSystem::getSupportedColorSpaceName(const char*

NodeDefPtr OpenColorIOManagementSystem::getNodeDef(const ColorSpaceTransform& transform) const
{
// See if the default color management system already handles this:
if (auto cmNodeDef = DefaultColorManagementSystem::getNodeDef(transform)) {
return cmNodeDef;
}

OCIO::ConstProcessorRcPtr processor;
// Check if directly supported in the config:
const char* sourceColorSpace = getSupportedColorSpaceName(transform.sourceSpace.c_str());
Expand Down Expand Up @@ -162,11 +168,18 @@ NodeDefPtr OpenColorIOManagementSystem::getNodeDef(const ColorSpaceTransform& tr

bool OpenColorIOManagementSystem::hasImplementation(const string& implName) const
{
if (DefaultColorManagementSystem::hasImplementation(implName)) {
return true;
}
return _implementations.count(implName);
}

ShaderNodeImplPtr OpenColorIOManagementSystem::createImplementation(const string& implName) const
{
if (auto impl = DefaultColorManagementSystem::createImplementation(implName)) {
return impl;
}

if (_implementations.count(implName))
{
return OpenColorIONode::create();
Expand Down
4 changes: 2 additions & 2 deletions source/MaterialXGenShader/OpenColorIOManagementSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <MaterialXCore/Definition.h>

#include <MaterialXGenShader/ColorManagementSystem.h>
#include <MaterialXGenShader/DefaultColorManagementSystem.h>
#include <OpenColorIO/OpenColorABI.h>
#include <OpenColorIO/OpenColorIO.h>

Expand All @@ -29,7 +29,7 @@ using OpenColorIOManagementSystemPtr = std::shared_ptr<class OpenColorIOManageme

/// @class OpenColorIOManagementSystem
/// Class for a default color management system.
class MX_GENSHADER_API OpenColorIOManagementSystem : public ColorManagementSystem
class MX_GENSHADER_API OpenColorIOManagementSystem : public DefaultColorManagementSystem
{
public:
virtual ~OpenColorIOManagementSystem() { }
Expand Down

0 comments on commit 3e1ccfc

Please sign in to comment.