diff --git a/lib/usd/hdMaya/adapters/aiSkydomeLightAdapter.cpp b/lib/usd/hdMaya/adapters/aiSkydomeLightAdapter.cpp index 33e759d897..752ae302f8 100644 --- a/lib/usd/hdMaya/adapters/aiSkydomeLightAdapter.cpp +++ b/lib/usd/hdMaya/adapters/aiSkydomeLightAdapter.cpp @@ -97,7 +97,7 @@ class HdMayaAiSkyDomeLightAdapter : public HdMayaLightAdapter file.findPlug(MayaAttrs::file::fileTextureName, true).asString().asChar())); } else if (paramName == HdLightTokens->enableColorTemperature) { return VtValue(false); -#if USD_VERSION_NUM >= 1910 +#if USD_VERSION_NUM >= 1910 && USD_VERSION_NUM < 2011 } else if (paramName == HdLightTokens->textureResource) { auto fileObj = GetConnectedFileNode(GetNode(), HdMayaAdapterTokens->color); // TODO: Return a default, white texture? @@ -110,7 +110,7 @@ class HdMayaAiSkyDomeLightAdapter : public HdMayaLightAdapter fileObj, GetFileTexturePath(MFnDependencyNode(fileObj)), GetDelegate()->GetParams().textureMemoryPerTexture) }; -#endif // USD_VERSION_NUM >= 1910 +#endif // USD_VERSION_NUM >= 1910 && USD_VERSION_NUM < 2011 } return {}; } diff --git a/lib/usd/hdMaya/adapters/materialAdapter.cpp b/lib/usd/hdMaya/adapters/materialAdapter.cpp index 4eb6c27e7b..9deddf6eaa 100644 --- a/lib/usd/hdMaya/adapters/materialAdapter.cpp +++ b/lib/usd/hdMaya/adapters/materialAdapter.cpp @@ -21,20 +21,10 @@ #include #include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include #include #include #include -#include #include #include @@ -42,6 +32,19 @@ #include #include +#if USD_VERSION_NUM < 2011 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif // USD_VERSION_NUM < 2011 + PXR_NAMESPACE_OPEN_SCOPE namespace { @@ -105,7 +108,19 @@ void HdMayaMaterialAdapter::Populate() _isPopulated = true; } -#if USD_VERSION_NUM <= 1911 +#if USD_VERSION_NUM > 1911 && USD_VERSION_NUM < 2011 + +HdTextureResource::ID HdMayaMaterialAdapter::GetTextureResourceID(const TfToken& paramName) +{ + return {}; +} + +HdTextureResourceSharedPtr HdMayaMaterialAdapter::GetTextureResource(const SdfPath& textureShaderId) +{ + return {}; +} + +#elif USD_VERSION_NUM <= 1911 // We can't store the shader here explicitly, since it causes a deadlock // due to library dependencies. @@ -194,20 +209,13 @@ HdTextureResourceSharedPtr HdMayaMaterialAdapter::GetTextureResource(const TfTok return {}; } -#else // USD_VERSION_NUM > 1911 - -HdTextureResourceSharedPtr HdMayaMaterialAdapter::GetTextureResource(const SdfPath& textureShaderId) +HdTextureResource::ID HdMayaMaterialAdapter::GetTextureResourceID(const TfToken& paramName) { return {}; } #endif // USD_VERSION_NUM <= 1911 -HdTextureResource::ID HdMayaMaterialAdapter::GetTextureResourceID(const TfToken& paramName) -{ - return {}; -} - VtValue HdMayaMaterialAdapter::GetMaterialResource() { TF_DEBUG(HDMAYA_ADAPTER_MATERIALS).Msg("HdMayaMaterialAdapter::GetMaterialResource()\n"); @@ -317,7 +325,29 @@ class HdMayaShadingEngineAdapter : public HdMayaMaterialAdapter } } -#if USD_VERSION_NUM <= 1911 +#if USD_VERSION_NUM > 1911 && USD_VERSION_NUM < 2011 + + HdTextureResourceSharedPtr GetTextureResource(const SdfPath& textureShaderId) override + { + TF_DEBUG(HDMAYA_ADAPTER_MATERIALS) + .Msg( + "HdMayaShadingEngineAdapter::GetTextureResource(%s): %s\n", + textureShaderId.GetText(), + GetID().GetText()); + if (GetDelegate()->IsHdSt()) { + auto* mObjPtr = TfMapLookupPtr(_materialPathToMobj, textureShaderId); + if (!mObjPtr || (*mObjPtr) == MObject::kNullObj) { + return {}; + } + return GetFileTextureResource( + *mObjPtr, + GetFileTexturePath(MFnDependencyNode(*mObjPtr)), + GetDelegate()->GetParams().textureMemoryPerTexture); + } + return {}; + } + +#elif USD_VERSION_NUM <= 1911 inline bool _RegisterTexture( const MFnDependencyNode& node, @@ -525,28 +555,6 @@ class HdMayaShadingEngineAdapter : public HdMayaMaterialAdapter return {}; } -#else // USD_VERSION_NUM > 1911 - - HdTextureResourceSharedPtr GetTextureResource(const SdfPath& textureShaderId) override - { - TF_DEBUG(HDMAYA_ADAPTER_MATERIALS) - .Msg( - "HdMayaShadingEngineAdapter::GetTextureResource(%s): %s\n", - textureShaderId.GetText(), - GetID().GetText()); - if (GetDelegate()->IsHdSt()) { - auto* mObjPtr = TfMapLookupPtr(_materialPathToMobj, textureShaderId); - if (!mObjPtr || (*mObjPtr) == MObject::kNullObj) { - return {}; - } - return GetFileTextureResource( - *mObjPtr, - GetFileTexturePath(MFnDependencyNode(*mObjPtr)), - GetDelegate()->GetParams().textureMemoryPerTexture); - } - return {}; - } - #endif // USD_VERSION_NUM <= 1911 void _CreateSurfaceMaterialCallback() @@ -563,6 +571,8 @@ class HdMayaShadingEngineAdapter : public HdMayaMaterialAdapter } } +#if USD_VERSION_NUM < 2011 + inline HdTextureResource::ID _GetTextureResourceID(const MObject& fileObj, const TfToken& filePath) { @@ -574,6 +584,8 @@ class HdMayaShadingEngineAdapter : public HdMayaMaterialAdapter return HdTextureResource::ID(hash); } +#endif // USD_VERSION_NUM < 2011 + VtValue GetMaterialResource() override { TF_DEBUG(HDMAYA_ADAPTER_MATERIALS) @@ -641,9 +653,13 @@ class HdMayaShadingEngineAdapter : public HdMayaMaterialAdapter TfToken _surfaceShaderType; // So they live long enough +#if USD_VERSION_NUM < 2011 + std::unordered_map _textureResourceHandles; +#endif // USD_VERSION_NUM < 2011 + MCallbackId _surfaceShaderCallback; #ifdef HDMAYA_OIT_ENABLED bool _isTranslucent = false; diff --git a/lib/usd/hdMaya/adapters/materialAdapter.h b/lib/usd/hdMaya/adapters/materialAdapter.h index 8b7d6c3624..5b18d06e99 100644 --- a/lib/usd/hdMaya/adapters/materialAdapter.h +++ b/lib/usd/hdMaya/adapters/materialAdapter.h @@ -43,7 +43,14 @@ class HdMayaMaterialAdapter : public HdMayaAdapter HDMAYA_API void Populate() override; -#if USD_VERSION_NUM <= 1911 +#if USD_VERSION_NUM > 1911 && USD_VERSION_NUM < 2011 + + HDMAYA_API + virtual HdTextureResourceSharedPtr GetTextureResource(const SdfPath& textureShaderId); + HDMAYA_API + virtual HdTextureResource::ID GetTextureResourceID(const TfToken& paramName); + +#elif USD_VERSION_NUM <= 1911 HDMAYA_API virtual std::string GetSurfaceShaderSource(); @@ -69,16 +76,11 @@ class HdMayaMaterialAdapter : public HdMayaAdapter static const VtValue& GetPreviewMaterialParamValue(const TfToken& paramName); HDMAYA_API virtual HdTextureResourceSharedPtr GetTextureResource(const TfToken& paramName); - -#else // USD_VERSION_NUM > 1911 - HDMAYA_API - virtual HdTextureResourceSharedPtr GetTextureResource(const SdfPath& textureShaderId); + virtual HdTextureResource::ID GetTextureResourceID(const TfToken& paramName); #endif // USD_VERSION_NUM <= 1911 - HDMAYA_API - virtual HdTextureResource::ID GetTextureResourceID(const TfToken& paramName); HDMAYA_API virtual VtValue GetMaterialResource(); diff --git a/lib/usd/hdMaya/delegates/delegateDebugCodes.cpp b/lib/usd/hdMaya/delegates/delegateDebugCodes.cpp index 42fa80f423..def2ecfa3f 100644 --- a/lib/usd/hdMaya/delegates/delegateDebugCodes.cpp +++ b/lib/usd/hdMaya/delegates/delegateDebugCodes.cpp @@ -81,15 +81,6 @@ TF_REGISTRY_FUNCTION(TfDebug) HDMAYA_DELEGATE_GET_SUBDIV_TAGS, "Print information about 'GetSubdivTags' calls to the delegates."); - TF_DEBUG_ENVIRONMENT_SYMBOL( - HDMAYA_DELEGATE_GET_TEXTURE_RESOURCE, - "Print information about 'GetTextureResource' calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - HDMAYA_DELEGATE_GET_TEXTURE_RESOURCE_ID, - "Print information about 'GetTextureResourceID' calls to the " - "delegates."); - TF_DEBUG_ENVIRONMENT_SYMBOL( HDMAYA_DELEGATE_GET_TRANSFORM, "Print information about 'GetTransform' calls to the delegates."); @@ -122,6 +113,19 @@ TF_REGISTRY_FUNCTION(TfDebug) TF_DEBUG_ENVIRONMENT_SYMBOL( HDMAYA_DELEGATE_SELECTION, "Print information about hdMaya delegate selection."); +#if USD_VERSION_NUM < 2011 + + TF_DEBUG_ENVIRONMENT_SYMBOL( + HDMAYA_DELEGATE_GET_TEXTURE_RESOURCE, + "Print information about 'GetTextureResource' calls to the delegates."); + + TF_DEBUG_ENVIRONMENT_SYMBOL( + HDMAYA_DELEGATE_GET_TEXTURE_RESOURCE_ID, + "Print information about 'GetTextureResourceID' calls to the " + "delegates."); + +#endif // USD_VERSION_NUM < 2011 + #if USD_VERSION_NUM <= 1911 TF_DEBUG_ENVIRONMENT_SYMBOL( diff --git a/lib/usd/hdMaya/delegates/delegateDebugCodes.h b/lib/usd/hdMaya/delegates/delegateDebugCodes.h index 0af6248253..87be30a6ea 100644 --- a/lib/usd/hdMaya/delegates/delegateDebugCodes.h +++ b/lib/usd/hdMaya/delegates/delegateDebugCodes.h @@ -38,8 +38,6 @@ TF_DEBUG_CODES( HDMAYA_DELEGATE_GET_PRIMVAR_DESCRIPTORS, HDMAYA_DELEGATE_GET_RENDER_TAG, HDMAYA_DELEGATE_GET_SUBDIV_TAGS, - HDMAYA_DELEGATE_GET_TEXTURE_RESOURCE, - HDMAYA_DELEGATE_GET_TEXTURE_RESOURCE_ID, HDMAYA_DELEGATE_GET_TRANSFORM, HDMAYA_DELEGATE_GET_VISIBLE, HDMAYA_DELEGATE_INSERTDAG, @@ -51,6 +49,18 @@ TF_DEBUG_CODES( HDMAYA_DELEGATE_SELECTION); // clang-format on +// Debug codes for Hydra API that was deprecated with USD 20.11. +// These are declared in a separate block to avoid using a preprocessor +// directive inside the TF_DEBUG_CODES() macro invocation, which breaks +// compilation on Windows. +#if USD_VERSION_NUM < 2011 +// clang-format off +TF_DEBUG_CODES( + HDMAYA_DELEGATE_GET_TEXTURE_RESOURCE, + HDMAYA_DELEGATE_GET_TEXTURE_RESOURCE_ID); +// clang-format on +#endif // USD_VERSION_NUM < 2011 + // Debug codes for Hydra API that was deprecated after USD 19.11. // These are declared in a separate block to avoid using a preprocessor // directive inside the TF_DEBUG_CODES() macro invocation, which breaks diff --git a/lib/usd/hdMaya/delegates/sceneDelegate.cpp b/lib/usd/hdMaya/delegates/sceneDelegate.cpp index 8b095015dc..4f76135ec0 100644 --- a/lib/usd/hdMaya/delegates/sceneDelegate.cpp +++ b/lib/usd/hdMaya/delegates/sceneDelegate.cpp @@ -30,9 +30,7 @@ #include #include #include -#include -#include -#include +#include #include #include @@ -126,6 +124,8 @@ inline bool _RemoveAdapter(const SdfPath& id, F f, M0& m0, M&... m) template inline R _GetDefaultValue() { return {}; } +#if USD_VERSION_NUM < 2011 + // Default return value for HdTextureResource::ID, if not found, should be // -1, not {} - which would be 0 template <> inline HdTextureResource::ID _GetDefaultValue() @@ -133,6 +133,8 @@ template <> inline HdTextureResource::ID _GetDefaultValue return HdTextureResource::ID(-1); } +#endif // USD_VERSION_NUM < 2011 + // This will be nicer to use with automatic parameter deduction for lambdas in // C++14. template inline R _GetValue(const SdfPath&, F) @@ -1130,6 +1132,8 @@ VtValue HdMayaSceneDelegate::GetMaterialResource(const SdfPath& id) return ret.IsEmpty() ? HdMayaMaterialAdapter::GetPreviewMaterialResource(id) : ret; } +#if USD_VERSION_NUM < 2011 + HdTextureResource::ID HdMayaSceneDelegate::GetTextureResourceID(const SdfPath& textureId) { TF_DEBUG(HDMAYA_DELEGATE_GET_TEXTURE_RESOURCE_ID) @@ -1189,6 +1193,8 @@ HdTextureResourceSharedPtr HdMayaSceneDelegate::GetTextureResource(const SdfPath #endif // USD_VERSION_NUM <= 1911 } +#endif // USD_VERSION_NUM < 2011 + bool HdMayaSceneDelegate::_CreateMaterial(const SdfPath& id, const MObject& obj) { TF_DEBUG(HDMAYA_ADAPTER_MATERIALS) diff --git a/lib/usd/hdMaya/delegates/sceneDelegate.h b/lib/usd/hdMaya/delegates/sceneDelegate.h index 7fcca3d896..b100bc16dd 100644 --- a/lib/usd/hdMaya/delegates/sceneDelegate.h +++ b/lib/usd/hdMaya/delegates/sceneDelegate.h @@ -243,11 +243,13 @@ class HdMayaSceneDelegate : public HdMayaDelegateCtx HDMAYA_API VtValue GetMaterialResource(const SdfPath& id) override; +#if USD_VERSION_NUM < 2011 HDMAYA_API HdTextureResource::ID GetTextureResourceID(const SdfPath& textureId) override; HDMAYA_API HdTextureResourceSharedPtr GetTextureResource(const SdfPath& textureId) override; +#endif // USD_VERSION_NUM < 2011 private: bool _CreateMaterial(const SdfPath& id, const MObject& obj); diff --git a/lib/usd/hdMaya/utils.cpp b/lib/usd/hdMaya/utils.cpp index 6d18d6b805..6ed8de90f9 100644 --- a/lib/usd/hdMaya/utils.cpp +++ b/lib/usd/hdMaya/utils.cpp @@ -15,36 +15,38 @@ // #include "utils.h" +#include + +#include +#include +#include +#include + +#if USD_VERSION_NUM < 2011 #include #include +#include #include #include #include #include #include -#include - -#if USD_VERSION_NUM >= 2102 -#include -#else -#include +#include #endif PXR_NAMESPACE_OPEN_SCOPE +#if USD_VERSION_NUM < 2011 + namespace { class UdimTextureFactory : public GlfTextureFactoryBase { public: virtual GlfTextureRefPtr - New(TfToken const& texturePath, -#if USD_VERSION_NUM >= 2102 - HioImage::ImageOriginLocation originLocation = HioImage::OriginLowerLeft) const override -#else + New(TfToken const& texturePath, GlfImage::ImageOriginLocation originLocation = GlfImage::OriginLowerLeft) const override -#endif { const GlfContextCaps& caps = GlfContextCaps::GetInstance(); return GlfUdimTexture::New( @@ -54,12 +56,8 @@ class UdimTextureFactory : public GlfTextureFactoryBase } virtual GlfTextureRefPtr - New(TfTokenVector const& texturePaths, -#if USD_VERSION_NUM >= 2102 - HioImage::ImageOriginLocation originLocation = HioImage::OriginLowerLeft) const override -#else + New(TfTokenVector const& texturePaths, GlfImage::ImageOriginLocation originLocation = GlfImage::OriginLowerLeft) const override -#endif { return nullptr; } @@ -67,6 +65,8 @@ class UdimTextureFactory : public GlfTextureFactoryBase } // namespace +#endif // USD_VERSION_NUM < 2011 + MObject GetConnectedFileNode(const MObject& obj, const TfToken& paramName) { MStatus status; @@ -111,6 +111,8 @@ TfToken GetFileTexturePath(const MFnDependencyNode& fileNode) } } +#if USD_VERSION_NUM < 2011 + std::tuple GetFileTextureWrappingParams(const MObject& fileObj) { const std::tuple def { HdWrapClamp, HdWrapClamp }; @@ -149,11 +151,7 @@ GetFileTextureResource(const MObject& fileObj, const TfToken& filePath, int maxT return {}; } // TODO: handle origin -#if USD_VERSION_NUM >= 2102 - const auto origin = HioImage::OriginLowerLeft; -#else - const auto origin = GlfImage::OriginLowerLeft; -#endif + const auto origin = GlfImage::OriginLowerLeft; GlfTextureHandleRefPtr texture = nullptr; if (textureType == HdTextureType::Udim) { UdimTextureFactory factory; @@ -179,4 +177,6 @@ GetFileTextureResource(const MObject& fileObj, const TfToken& filePath, int maxT maxTextureMemory)); } +#endif // USD_VERSION_NUM < 2011 + PXR_NAMESPACE_CLOSE_SCOPE diff --git a/lib/usd/hdMaya/utils.h b/lib/usd/hdMaya/utils.h index 36e2ac4b14..9cac2bae55 100644 --- a/lib/usd/hdMaya/utils.h +++ b/lib/usd/hdMaya/utils.h @@ -24,8 +24,6 @@ #include #include -#include -#include #include #include @@ -38,8 +36,12 @@ #include #include -#include +#if USD_VERSION_NUM < 2011 +#include +#include + #include +#endif // USD_VERSION_NUM < 2011 PXR_NAMESPACE_OPEN_SCOPE @@ -80,6 +82,8 @@ MObject GetConnectedFileNode(const MFnDependencyNode& node, const TfToken& param HDMAYA_API TfToken GetFileTexturePath(const MFnDependencyNode& fileNode); +#if USD_VERSION_NUM < 2011 + /// \brief Returns the texture resource from a "file" shader node. /// \param fileObj "file" shader object. /// \param filePath Path to the texture file held by "file" shader node. @@ -101,6 +105,8 @@ HdTextureResourceSharedPtr GetFileTextureResource( HDMAYA_API std::tuple GetFileTextureWrappingParams(const MObject& fileObj); +#endif // USD_VERSION_NUM < 2011 + /// \brief Runs a function on all recursive descendents of a selection list /// May optionally filter by node type. The items in the list are also included /// in the set of items that are iterated over (assuming they pass the filter).