Skip to content

Commit

Permalink
HYDRA-336: add version check to the scene index plugin api (#407)
Browse files Browse the repository at this point in the history
* HYDRA-336: add version as parameter

* HYDRA-336: add version as parameter

* HYDRA-336: add constant num data source entries

* HYDRA-336: remove hardcoded num entries

* HYDRA-336: replace with static assert

* HYDRA-336: replace with static assert
  • Loading branch information
perrauo-adsk authored and GitHub Enterprise committed Apr 19, 2023
1 parent d7dc407 commit a03e617
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions lib/mayaHydra/hydraExtensions/mayaHydra.h.src
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define MAYAHYDRA_MAJOR_VERSION ${MAYAHYDRA_MAJOR_VERSION}
#define MAYAHYDRA_MINOR_VERSION ${MAYAHYDRA_MINOR_VERSION}
#define MAYAHYDRA_PATCH_LEVEL ${MAYAHYDRA_PATCH_LEVEL}
#define MAYAHYDRA_API_VERSION (MAYAHYDRA_MAJOR_VERSION * 10000 + MAYAHYDRA_MINOR_VERSION * 100 + MAYAHYDRA_PATCH_LEVEL)

// MayaHydra public namespace string will never change.
#define MAYAHYDRA_NS MayaHydra
Expand Down
26 changes: 15 additions & 11 deletions lib/mayaHydra/hydraExtensions/sceneIndex/registration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ bool MayaHydraSceneIndexRegistry::_RemoveSceneIndexForNode(const MObject& dagNod
return false;
}

constexpr char kDataSourceEntryNodePathName[] = { "object" };
constexpr char kDataSourceEntryInterpretRprimPathName[] = { "interpretRprimPath" };
constexpr char kSceneIndexPluginSuffix[] = {
"MayaNodeSceneIndexPlugin"
}; // every scene index plugin compatible with the hydra viewport requires this suffix
Expand All @@ -182,23 +180,29 @@ void MayaHydraSceneIndexRegistry::_AddSceneIndexForNode(MObject& dagNode)
= HdSceneIndexPluginRegistry::GetInstance();
if (sceneIndexPluginRegistry.IsRegisteredPlugin(sceneIndexPluginId)) {
using MayaHydraMObjectDataSource = HdRetainedTypedSampledDataSource<MObject>;
using MayaHydraVersionDataSource = HdRetainedTypedSampledDataSource<int>;
// Functions retrieved from the scene index plugin
using MayaHydraInterpretRprimPathDataSource
= HdRetainedTypedSampledDataSource<MayaHydraInterpretRprimPath&>;

// Create the registration record which is then added into the registry if everything
// succeeds
static TfToken sDataSourceEntryNames[] { TfToken("object"),
TfToken("version"),
TfToken("interpretRprimPath") };
constexpr int kDataSourceNumEntries = sizeof(sDataSourceEntryNames) / sizeof(TfToken);
MayaHydraSceneIndexRegistrationPtr registration(new MayaHydraSceneIndexRegistration());

TfToken names[3] {

TfToken(kDataSourceEntryNodePathName), TfToken(kDataSourceEntryInterpretRprimPathName)
};
HdDataSourceBaseHandle values[2] { MayaHydraMObjectDataSource::New(dagNode),
MayaHydraInterpretRprimPathDataSource::New(
registration->interpretRprimPathFn) };
HdDataSourceBaseHandle values[] { MayaHydraMObjectDataSource::New(dagNode),
MayaHydraVersionDataSource::New(MAYAHYDRA_API_VERSION),
MayaHydraInterpretRprimPathDataSource::New(
registration->interpretRprimPathFn) };
static_assert(
sizeof(values) / sizeof(HdDataSourceBaseHandle) == kDataSourceNumEntries,
"Incorrect number of data source entries");
registration->pluginSceneIndex = sceneIndexPluginRegistry.AppendSceneIndex(
sceneIndexPluginId, nullptr, HdRetainedContainerDataSource::New(2, names, values));
sceneIndexPluginId,
nullptr,
HdRetainedContainerDataSource::New(kDataSourceNumEntries, sDataSourceEntryNames, values));
if (TF_VERIFY(
registration->pluginSceneIndex,
"HdSceneIndexBase::AppendSceneIndex failed to create %s scene index from given "
Expand Down

0 comments on commit a03e617

Please sign in to comment.