-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LOOKDEVX-2128 - Allow specializing the topo neutral graph generator #3503
Merged
seando-adsk
merged 5 commits into
dev
from
gamaj/LOOKDEVX-2128/export_common_color_management_api
Dec 11, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a141ca8
LOOKDEVX-2128 - Allow specializing the topo neutral graph generator
JGamache-autodesk 061d026
Respond to review comment.
JGamache-autodesk 86d68d1
EMSUSD-765 - Update OCIO code to handle new Hydra colorspace info
JGamache-autodesk 00d23a9
Revert "EMSUSD-765 - Update OCIO code to handle new Hydra colorspace …
JGamache-autodesk 7eeb0cb
Make sure to set global state before generating shaders
JGamache-autodesk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(); } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extracted as-is from material.cpp to be used by downstream clients. |
||
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allow downstream clients to specialize that class.