Skip to content
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

remove dependencies on old Hydra texture system from hdMaya for USD releases after 20.11 #961

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/usd/hdMaya/adapters/aiSkydomeLightAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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 {};
}
Expand Down
100 changes: 58 additions & 42 deletions lib/usd/hdMaya/adapters/materialAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,30 @@
#include <hdMaya/adapters/tokens.h>
#include <hdMaya/utils.h>

#include <pxr/base/tf/fileUtils.h>
#include <pxr/imaging/glf/contextCaps.h>
#include <pxr/imaging/glf/textureRegistry.h>
#include <pxr/imaging/glf/udimTexture.h>
#include <pxr/imaging/hd/instanceRegistry.h>
#include <pxr/imaging/hd/material.h>
#include <pxr/imaging/hd/resourceRegistry.h>
#include <pxr/imaging/hdSt/resourceRegistry.h>
#include <pxr/imaging/hdSt/textureResource.h>
#include <pxr/imaging/hdSt/textureResourceHandle.h>
#include <pxr/imaging/hio/glslfx.h>
#include <pxr/usd/sdf/types.h>
#include <pxr/usd/sdr/registry.h>
#include <pxr/usdImaging/usdImaging/textureUtils.h>
#include <pxr/usdImaging/usdImaging/tokens.h>
#include <pxr/usdImaging/usdImagingGL/package.h>

#include <maya/MNodeMessage.h>
#include <maya/MPlug.h>
#include <maya/MPlugArray.h>

#if USD_VERSION_NUM < 2011
#include <pxr/base/tf/fileUtils.h>
#include <pxr/imaging/glf/contextCaps.h>
#include <pxr/imaging/glf/textureRegistry.h>
#include <pxr/imaging/glf/udimTexture.h>
#include <pxr/imaging/hd/instanceRegistry.h>
#include <pxr/imaging/hd/resourceRegistry.h>
#include <pxr/imaging/hdSt/resourceRegistry.h>
#include <pxr/imaging/hdSt/textureResource.h>
#include <pxr/imaging/hdSt/textureResourceHandle.h>
#include <pxr/usdImaging/usdImaging/textureUtils.h>
#endif // USD_VERSION_NUM < 2011

PXR_NAMESPACE_OPEN_SCOPE

namespace {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -563,6 +571,8 @@ class HdMayaShadingEngineAdapter : public HdMayaMaterialAdapter
}
}

#if USD_VERSION_NUM < 2011

inline HdTextureResource::ID
_GetTextureResourceID(const MObject& fileObj, const TfToken& filePath)
{
Expand All @@ -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)
Expand Down Expand Up @@ -641,9 +653,13 @@ class HdMayaShadingEngineAdapter : public HdMayaMaterialAdapter
TfToken _surfaceShaderType;
// So they live long enough

#if USD_VERSION_NUM < 2011

std::unordered_map<TfToken, HdStTextureResourceHandleSharedPtr, TfToken::HashFunctor>
_textureResourceHandles;

#endif // USD_VERSION_NUM < 2011

MCallbackId _surfaceShaderCallback;
#ifdef HDMAYA_OIT_ENABLED
bool _isTranslucent = false;
Expand Down
16 changes: 9 additions & 7 deletions lib/usd/hdMaya/adapters/materialAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();

Expand Down
22 changes: 13 additions & 9 deletions lib/usd/hdMaya/delegates/delegateDebugCodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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(
Expand Down
14 changes: 12 additions & 2 deletions lib/usd/hdMaya/delegates/delegateDebugCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
12 changes: 9 additions & 3 deletions lib/usd/hdMaya/delegates/sceneDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
#include <pxr/imaging/hd/mesh.h>
#include <pxr/imaging/hd/rprim.h>
#include <pxr/imaging/hd/tokens.h>
#include <pxr/imaging/hdx/renderSetupTask.h>
#include <pxr/imaging/hdx/renderTask.h>
#include <pxr/imaging/hdx/tokens.h>
#include <pxr/imaging/hdx/pickTask.h>
#include <pxr/usd/sdf/assetPath.h>
#include <pxr/usd/usdGeom/tokens.h>

Expand Down Expand Up @@ -126,13 +124,17 @@ inline bool _RemoveAdapter(const SdfPath& id, F f, M0& m0, M&... m)

template <typename R> 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<HdTextureResource::ID>()
{
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 <typename T, typename R, typename F> inline R _GetValue(const SdfPath&, F)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lib/usd/hdMaya/delegates/sceneDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading