Skip to content

Commit

Permalink
HnTask: added GetTaskContextData method
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Oct 24, 2023
1 parent 566c214 commit b0ab97f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
28 changes: 27 additions & 1 deletion Hydrogent/interface/Tasks/HnTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,33 @@ class HnTask : public pxr::HdTask
ITextureView* GetRenderBufferTarget(pxr::HdRenderIndex& RenderIndex, pxr::HdTaskContext* TaskCtx, const pxr::TfToken& Name) const;

template <typename ParamType>
bool GetTaskParams(pxr::HdSceneDelegate* Delegate, ParamType& Param)
bool GetTaskContextData(pxr::HdTaskContext* TaskCtx, const pxr::TfToken& Name, ParamType& Param) const
{
if (TaskCtx == nullptr)
{
UNEXPECTED("Task context is null");
return false;
}

auto param_it = TaskCtx->find(Name);
if (param_it == TaskCtx->end())
{
UNEXPECTED("Parameter '", Name, "' is not set in the task context");
return false;
}

if (!param_it->second.IsHolding<ParamType>())
{
UNEXPECTED("Type ", param_it->second.GetTypeName(), " is not expected for parameter ", Name);
return false;
}

Param = param_it->second.UncheckedGet<ParamType>();
return true;
}

template <typename ParamType>
bool GetTaskParams(pxr::HdSceneDelegate* Delegate, ParamType& Param) const
{
pxr::VtValue ParamsValue = Delegate->Get(GetId(), pxr::HdTokens->params);
if (ParamsValue.IsHolding<ParamType>())
Expand Down
13 changes: 4 additions & 9 deletions Hydrogent/src/Tasks/HnTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,15 @@ ITextureView* HnTask::GetRenderBufferTarget(pxr::HdRenderIndex& RenderIndex, con

ITextureView* HnTask::GetRenderBufferTarget(pxr::HdRenderIndex& RenderIndex, pxr::HdTaskContext* TaskCtx, const pxr::TfToken& Name) const
{
auto id_it = TaskCtx->find(Name);
if (id_it == TaskCtx->end())
pxr::SdfPath RenderBufferId;
if (GetTaskContextData(TaskCtx, Name, RenderBufferId))
{
UNEXPECTED("Render buffer Name '", Name, "' is not set in the task context");
return nullptr;
return GetRenderBufferTarget(RenderIndex, RenderBufferId);
}

if (!id_it->second.IsHolding<pxr::SdfPath>())
else
{
UNEXPECTED("Render buffer VtValue '", Name, "' is not holding SdfPath");
return nullptr;
}

return GetRenderBufferTarget(RenderIndex, id_it->second.Get<pxr::SdfPath>());
}

} // namespace USD
Expand Down

0 comments on commit b0ab97f

Please sign in to comment.