From 3e1ccfc89bd506a9a4c7ad2b8759ab8b8387bdf8 Mon Sep 17 00:00:00 2001 From: JGamache-Autodesk Date: Tue, 20 Aug 2024 12:08:00 -0400 Subject: [PATCH] Defer to default color management in OCIO code for known transforms Make the OCIO color manager derive from the default color management. --- source/MaterialXGenShader/CMakeLists.txt | 2 +- .../OpenColorIOManagementSystem.cpp | 13 +++++++++++++ .../OpenColorIOManagementSystem.h | 4 ++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/source/MaterialXGenShader/CMakeLists.txt b/source/MaterialXGenShader/CMakeLists.txt index de922a4e62..b2f48e7e3e 100644 --- a/source/MaterialXGenShader/CMakeLists.txt +++ b/source/MaterialXGenShader/CMakeLists.txt @@ -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() \ No newline at end of file diff --git a/source/MaterialXGenShader/OpenColorIOManagementSystem.cpp b/source/MaterialXGenShader/OpenColorIOManagementSystem.cpp index 0a4aa322c1..d2852a6e91 100644 --- a/source/MaterialXGenShader/OpenColorIOManagementSystem.cpp +++ b/source/MaterialXGenShader/OpenColorIOManagementSystem.cpp @@ -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)) { @@ -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()); @@ -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(); diff --git a/source/MaterialXGenShader/OpenColorIOManagementSystem.h b/source/MaterialXGenShader/OpenColorIOManagementSystem.h index e74325fc39..f81086ffbc 100644 --- a/source/MaterialXGenShader/OpenColorIOManagementSystem.h +++ b/source/MaterialXGenShader/OpenColorIOManagementSystem.h @@ -12,7 +12,7 @@ #include -#include +#include #include #include @@ -29,7 +29,7 @@ using OpenColorIOManagementSystemPtr = std::shared_ptr