Skip to content

Commit

Permalink
[hd] Simplifying code for the Render Terminals in the dataSourceLegac…
Browse files Browse the repository at this point in the history
…yPrim

(Internal change: 2271562)
  • Loading branch information
klucknav authored and pixar-oss committed Apr 21, 2023
1 parent 8aa8686 commit 51aa3fe
Showing 1 changed file with 18 additions and 45 deletions.
63 changes: 18 additions & 45 deletions pxr/imaging/hd/dataSourceLegacyPrim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2534,16 +2534,21 @@ _ConvertHdMaterialNetworkToHdDataSources(
}

template <typename SchemaType>
static bool
_ConvertRenderTerminalOutputNodeToHdDataSources(
const HdMaterialNode2 &hdNode,
HdContainerDataSourceHandle *result)
static HdContainerDataSourceHandle
_ConvertRenderTerminalOutputToHdDataSource(const VtValue &outputNodeValue)
{
HD_TRACE_FUNCTION();

if (!outputNodeValue.IsHolding<HdMaterialNode2>()) {
return nullptr;
}

const HdMaterialNode2 outputNode =
outputNodeValue.UncheckedGet<HdMaterialNode2>();

std::vector<TfToken> paramsNames;
std::vector<HdDataSourceBaseHandle> paramsValues;
for (const auto &p : hdNode.parameters) {
for (const auto &p : outputNode.parameters) {
paramsNames.push_back(p.first);
paramsValues.push_back(
HdRetainedTypedSampledDataSource<VtValue>::New(p.second)
Expand All @@ -2557,12 +2562,10 @@ _ConvertRenderTerminalOutputNodeToHdDataSources(
paramsValues.data()),
HdRetainedContainerDataSource::New(),
HdRetainedTypedSampledDataSource<TfToken>::New(
hdNode.nodeTypeId),
outputNode.nodeTypeId),
nullptr /*renderContextNodeIdentifiers*/);

*result = SchemaType::BuildRetained(nodeDS);

return true;
return SchemaType::BuildRetained(nodeDS);
}

HdDataSourceBaseHandle
Expand Down Expand Up @@ -2696,18 +2699,8 @@ HdDataSourceLegacyPrim::_GetIntegratorDataSource()
VtValue integratorValue = _sceneDelegate->Get(
_id, HdIntegratorSchemaTokens->integratorResource);

if (!integratorValue.IsHolding<HdMaterialNode2>()) {
return nullptr;
}

HdMaterialNode2 integratorNode =
integratorValue.UncheckedGet<HdMaterialNode2>();
HdContainerDataSourceHandle integratorDS = nullptr;
if (!_ConvertRenderTerminalOutputNodeToHdDataSources<HdIntegratorSchema>(
integratorNode, &integratorDS)) {
return nullptr;
}
return integratorDS;
return _ConvertRenderTerminalOutputToHdDataSource<HdIntegratorSchema>(
integratorValue);
}

HdDataSourceBaseHandle
Expand All @@ -2716,18 +2709,8 @@ HdDataSourceLegacyPrim::_GetSampleFilterDataSource()
VtValue sampleFilterValue = _sceneDelegate->Get(
_id, HdSampleFilterSchemaTokens->sampleFilterResource);

if (!sampleFilterValue.IsHolding<HdMaterialNode2>()) {
return nullptr;
}

HdMaterialNode2 sampleFilterNode =
sampleFilterValue.UncheckedGet<HdMaterialNode2>();
HdContainerDataSourceHandle sampleFilterDS = nullptr;
if (!_ConvertRenderTerminalOutputNodeToHdDataSources<HdSampleFilterSchema>(
sampleFilterNode, &sampleFilterDS)) {
return nullptr;
}
return sampleFilterDS;
return _ConvertRenderTerminalOutputToHdDataSource<HdSampleFilterSchema>(
sampleFilterValue);
}

HdDataSourceBaseHandle
Expand All @@ -2736,18 +2719,8 @@ HdDataSourceLegacyPrim::_GetDisplayFilterDataSource()
VtValue displayFilterValue = _sceneDelegate->Get(
_id, HdDisplayFilterSchemaTokens->displayFilterResource);

if (!displayFilterValue.IsHolding<HdMaterialNode2>()) {
return nullptr;
}

HdMaterialNode2 displayFilterNode =
displayFilterValue.UncheckedGet<HdMaterialNode2>();
HdContainerDataSourceHandle displayFilterDS = nullptr;
if (!_ConvertRenderTerminalOutputNodeToHdDataSources<HdDisplayFilterSchema>(
displayFilterNode, &displayFilterDS)) {
return nullptr;
}
return displayFilterDS;
return _ConvertRenderTerminalOutputToHdDataSource<HdDisplayFilterSchema>(
displayFilterValue);
}

HdDataSourceBaseHandle
Expand Down

0 comments on commit 51aa3fe

Please sign in to comment.