-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3503 from Autodesk/gamaj/LOOKDEVX-2128/export_com…
…mon_color_management_api LOOKDEVX-2128 - Allow specializing the topo neutral graph generator
- Loading branch information
Showing
5 changed files
with
253 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
lib/mayaUsd/render/vp2RenderDelegate/colorManagementPreferences.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// | ||
// Copyright 2023 Autodesk | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
#include "colorManagementPreferences.h" | ||
|
||
#include <maya/MEventMessage.h> | ||
#include <maya/MGlobal.h> | ||
#include <maya/MSceneMessage.h> | ||
|
||
#include <set> | ||
|
||
namespace MAYAUSD_NS_DEF { | ||
|
||
// We will cache the color management preferences since they are used in many loops. | ||
ColorManagementPreferences::~ColorManagementPreferences() { RemoveSinks(); } | ||
|
||
bool ColorManagementPreferences::Active() { return Get()._active; } | ||
|
||
const MString& ColorManagementPreferences::RenderingSpaceName() | ||
{ | ||
return Get()._renderingSpaceName; | ||
} | ||
|
||
const MString& ColorManagementPreferences::sRGBName() { return Get()._sRGBName; } | ||
|
||
std::string ColorManagementPreferences::getFileRule(const std::string& path) | ||
{ | ||
MString colorRuleCmd; | ||
colorRuleCmd.format("colorManagementFileRules -evaluate \"^1s\";", MString(path.c_str())); | ||
return MGlobal::executeCommandStringResult(colorRuleCmd).asChar(); | ||
} | ||
|
||
void ColorManagementPreferences::SetDirty() | ||
{ | ||
auto& self = InternalGet(); | ||
self._dirty = true; | ||
} | ||
|
||
void ColorManagementPreferences::MayaExit() | ||
{ | ||
auto& self = InternalGet(); | ||
self.RemoveSinks(); | ||
} | ||
|
||
ColorManagementPreferences::ColorManagementPreferences() = default; | ||
|
||
const ColorManagementPreferences& ColorManagementPreferences::Get() | ||
{ | ||
auto& self = InternalGet(); | ||
self.Refresh(); | ||
return self; | ||
} | ||
ColorManagementPreferences& ColorManagementPreferences::InternalGet() | ||
{ | ||
static ColorManagementPreferences _self; | ||
return _self; | ||
} | ||
|
||
void ColorManagementPreferences::RemoveSinks() | ||
{ | ||
for (auto id : _mayaColorManagementCallbackIds) { | ||
MMessage::removeCallback(id); | ||
} | ||
_mayaColorManagementCallbackIds.clear(); | ||
} | ||
|
||
void colorManagementRefreshCB(void*) { ColorManagementPreferences::SetDirty(); } | ||
|
||
void mayaExitingCB(void*) { ColorManagementPreferences::MayaExit(); } | ||
|
||
void ColorManagementPreferences::Refresh() | ||
{ | ||
if (_mayaColorManagementCallbackIds.empty()) { | ||
// Monitor color management prefs | ||
_mayaColorManagementCallbackIds.push_back(MEventMessage::addEventCallback( | ||
"colorMgtEnabledChanged", colorManagementRefreshCB, this)); | ||
_mayaColorManagementCallbackIds.push_back(MEventMessage::addEventCallback( | ||
"colorMgtWorkingSpaceChanged", colorManagementRefreshCB, this)); | ||
_mayaColorManagementCallbackIds.push_back(MEventMessage::addEventCallback( | ||
"colorMgtConfigChanged", colorManagementRefreshCB, this)); | ||
_mayaColorManagementCallbackIds.push_back(MEventMessage::addEventCallback( | ||
"colorMgtConfigFilePathChanged", colorManagementRefreshCB, this)); | ||
// The color management settings are quietly reset on file new: | ||
_mayaColorManagementCallbackIds.push_back( | ||
MSceneMessage::addCallback(MSceneMessage::kBeforeNew, colorManagementRefreshCB, this)); | ||
_mayaColorManagementCallbackIds.push_back( | ||
MSceneMessage::addCallback(MSceneMessage::kBeforeOpen, colorManagementRefreshCB, this)); | ||
|
||
// Cleanup on exit: | ||
_mayaColorManagementCallbackIds.push_back( | ||
MSceneMessage::addCallback(MSceneMessage::kMayaExiting, mayaExitingCB, this)); | ||
} | ||
|
||
if (!_dirty) { | ||
return; | ||
} | ||
_dirty = false; | ||
|
||
int isActive = 0; | ||
MGlobal::executeCommand("colorManagementPrefs -q -cmEnabled", isActive, false, false); | ||
if (!isActive) { | ||
_active = false; | ||
return; | ||
} | ||
|
||
_active = true; | ||
|
||
_renderingSpaceName | ||
= MGlobal::executeCommandStringResult("colorManagementPrefs -q -renderingSpaceName"); | ||
|
||
// Need some robustness around sRGB since not all OCIO configs declare it the same way: | ||
const auto sRGBAliases | ||
= std::set<std::string> { "sRGB", "sRGB - Texture", | ||
"srgb_tx", "Utility - sRGB - Texture", | ||
"srgb_texture", "Input - Generic - sRGB - Texture" }; | ||
|
||
MStringArray allInputSpaces; | ||
MGlobal::executeCommand( | ||
"colorManagementPrefs -q -inputSpaceNames", allInputSpaces, false, false); | ||
|
||
for (auto&& spaceName : allInputSpaces) { | ||
if (sRGBAliases.count(spaceName.asChar())) { | ||
_sRGBName = spaceName; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
} // namespace MAYAUSD_NS_DEF |
84 changes: 84 additions & 0 deletions
84
lib/mayaUsd/render/vp2RenderDelegate/colorManagementPreferences.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// | ||
// Copyright 2023 Autodesk | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
#ifndef COLOR_MANAGEMENT_PREFERENCES | ||
#define COLOR_MANAGEMENT_PREFERENCES | ||
|
||
#include <mayaUsd/base/api.h> | ||
|
||
#include <maya/MMessage.h> | ||
#include <maya/MString.h> | ||
|
||
#include <vector> | ||
|
||
namespace MAYAUSD_NS_DEF { | ||
|
||
/*! \brief Cache of color management preferences and queries. | ||
Getting the information involves calling MEL scripts, so we cache the results for better | ||
performance. | ||
*/ | ||
class MAYAUSD_CORE_PUBLIC ColorManagementPreferences | ||
{ | ||
public: | ||
~ColorManagementPreferences(); | ||
|
||
/*! \brief Is color management active. | ||
*/ | ||
static bool Active(); | ||
|
||
/*! \brief The current DCC rendering space name. | ||
*/ | ||
static const MString& RenderingSpaceName(); | ||
|
||
/*! \brief The current DCC color space name for plain sRGB | ||
Color management config files can rename or alias the sRGB color space name. We try a few | ||
common names and remember the first one that is found in the config. | ||
*/ | ||
static const MString& sRGBName(); | ||
|
||
/*! \brief Returns the OCIO color space name according to config file rules. | ||
\param path The path of the file to be color managed. | ||
*/ | ||
static std::string getFileRule(const std::string& path); | ||
|
||
/*! \brief Utility function to reset all cached data. | ||
*/ | ||
static void SetDirty(); | ||
|
||
/*! \brief Utility function to reset all message handlers on exit. | ||
*/ | ||
static void MayaExit(); | ||
|
||
private: | ||
ColorManagementPreferences(); | ||
static const ColorManagementPreferences& Get(); | ||
static ColorManagementPreferences& InternalGet(); | ||
|
||
bool _dirty = true; | ||
bool _active = false; | ||
MString _renderingSpaceName; | ||
MString _sRGBName; | ||
std::vector<MCallbackId> _mayaColorManagementCallbackIds; | ||
|
||
void Refresh(); | ||
void RemoveSinks(); | ||
}; | ||
|
||
} // namespace MAYAUSD_NS_DEF | ||
|
||
#endif |
Oops, something went wrong.