From b0ab97fab6f5279461299ee12d3d386627765a89 Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 23 Oct 2023 22:37:36 -0700 Subject: [PATCH] HnTask: added GetTaskContextData method --- Hydrogent/interface/Tasks/HnTask.hpp | 28 +++++++++++++++++++++++++++- Hydrogent/src/Tasks/HnTask.cpp | 13 ++++--------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/Hydrogent/interface/Tasks/HnTask.hpp b/Hydrogent/interface/Tasks/HnTask.hpp index 4646c7ae..78080bb9 100644 --- a/Hydrogent/interface/Tasks/HnTask.hpp +++ b/Hydrogent/interface/Tasks/HnTask.hpp @@ -56,7 +56,33 @@ class HnTask : public pxr::HdTask ITextureView* GetRenderBufferTarget(pxr::HdRenderIndex& RenderIndex, pxr::HdTaskContext* TaskCtx, const pxr::TfToken& Name) const; template - 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()) + { + UNEXPECTED("Type ", param_it->second.GetTypeName(), " is not expected for parameter ", Name); + return false; + } + + Param = param_it->second.UncheckedGet(); + return true; + } + + template + bool GetTaskParams(pxr::HdSceneDelegate* Delegate, ParamType& Param) const { pxr::VtValue ParamsValue = Delegate->Get(GetId(), pxr::HdTokens->params); if (ParamsValue.IsHolding()) diff --git a/Hydrogent/src/Tasks/HnTask.cpp b/Hydrogent/src/Tasks/HnTask.cpp index 0c56d181..55814002 100644 --- a/Hydrogent/src/Tasks/HnTask.cpp +++ b/Hydrogent/src/Tasks/HnTask.cpp @@ -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()) + else { - UNEXPECTED("Render buffer VtValue '", Name, "' is not holding SdfPath"); return nullptr; } - - return GetRenderBufferTarget(RenderIndex, id_it->second.Get()); } } // namespace USD