Skip to content

Commit

Permalink
Hydrogent: minor updates to render delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Oct 24, 2023
1 parent 5acc7ab commit 09091f4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Hydrogent/interface/HnRenderDelegate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class HnRenderDelegate final : public pxr::HdRenderDelegate
std::unordered_map<pxr::SdfPath, std::shared_ptr<HnMesh>, pxr::SdfPath::Hash> m_Meshes;
std::unordered_map<Uint32, pxr::SdfPath> m_MeshUIDToPrimId;

std::unordered_map<pxr::HdBprim*, std::unique_ptr<pxr::HdBprim>> m_BPrims;
std::unordered_map<pxr::SdfPath, std::unique_ptr<pxr::HdBprim>, pxr::SdfPath::Hash> m_BPrims;
};

} // namespace USD
Expand Down
34 changes: 26 additions & 8 deletions Hydrogent/src/HnRenderDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,26 @@ void HnRenderDelegate::DestroyInstancer(pxr::HdInstancer* instancer)
pxr::HdRprim* HnRenderDelegate::CreateRprim(pxr::TfToken const& typeId,
pxr::SdfPath const& rprimId)
{
auto it = m_Meshes.emplace(rprimId, HnMesh::Create(typeId, rprimId, m_MeshUIDCounter.fetch_add(1)));
if (typeId == pxr::HdPrimTypeTokens->mesh)
{
auto it = m_Meshes.emplace(rprimId, HnMesh::Create(typeId, rprimId, m_MeshUIDCounter.fetch_add(1)));

m_MeshUIDToPrimId[it.first->second->GetUID()] = rprimId;
return it.first->second.get();
m_MeshUIDToPrimId[it.first->second->GetUID()] = rprimId;
return it.first->second.get();
}
else
{
UNEXPECTED("Unexpected Rprim Type: ", typeId.GetText());
return nullptr;
}
}

void HnRenderDelegate::DestroyRprim(pxr::HdRprim* rPrim)
{
m_Meshes.erase(rPrim->GetId());
if (rPrim != nullptr)
{
m_Meshes.erase(rPrim->GetId());
}
}

pxr::HdSprim* HnRenderDelegate::CreateSprim(pxr::TfToken const& typeId,
Expand All @@ -168,8 +179,8 @@ pxr::HdSprim* HnRenderDelegate::CreateSprim(pxr::TfToken const& typeId,
else
{
UNEXPECTED("Unexpected Sprim Type: ", typeId.GetText());
return nullptr;
}
return nullptr;
}

pxr::HdSprim* HnRenderDelegate::CreateFallbackSprim(pxr::TfToken const& typeId)
Expand All @@ -196,10 +207,14 @@ pxr::HdBprim* HnRenderDelegate::CreateBprim(pxr::TfToken const& typeId,
{
auto RenderBuffer = std::make_unique<HnRenderBuffer>(bprimId);
auto* BPrim = RenderBuffer.get();
m_BPrims.emplace(BPrim, std::move(RenderBuffer));
m_BPrims.emplace(bprimId, std::move(RenderBuffer));
return BPrim;
}
return nullptr;
else
{
UNEXPECTED("Unexpected Bprim Type: ", typeId.GetText());
return nullptr;
}
}

pxr::HdBprim* HnRenderDelegate::CreateFallbackBprim(pxr::TfToken const& typeId)
Expand All @@ -209,7 +224,10 @@ pxr::HdBprim* HnRenderDelegate::CreateFallbackBprim(pxr::TfToken const& typeId)

void HnRenderDelegate::DestroyBprim(pxr::HdBprim* bprim)
{
m_BPrims.erase(bprim);
if (bprim != nullptr)
{
m_BPrims.erase(bprim->GetId());
}
}

void HnRenderDelegate::CommitResources(pxr::HdChangeTracker* tracker)
Expand Down

0 comments on commit 09091f4

Please sign in to comment.