MCPcopy Create free account
hub / github.com/DiligentGraphics/DiligentFX / UpdateVertexBuffers

Method UpdateVertexBuffers

Hydrogent/src/HnMesh.cpp:1103–1168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1101}
1102
1103void HnMesh::UpdateVertexBuffers(HnRenderDelegate& RenderDelegate)
1104{
1105 const RenderDeviceX_N& Device{RenderDelegate.GetDevice()};
1106
1107 if (!m_StagingVertexData)
1108 {
1109 UNEXPECTED("Vertex data is null");
1110 return;
1111 }
1112
1113 for (auto source_it : m_StagingVertexData->Sources)
1114 {
1115 const pxr::HdBufferSource* pSource = source_it.second.get();
1116 if (pSource == nullptr)
1117 continue;
1118 const pxr::TfToken& PrimName = source_it.first;
1119
1120 const auto NumElements = pSource->GetNumElements();
1121 const auto ElementType = pSource->GetTupleType().type;
1122 const auto ElementSize = HdDataSizeOfType(ElementType);
1123 if (PrimName == pxr::HdTokens->points)
1124 VERIFY(ElementType == pxr::HdTypeFloatVec3, "Unexpected vertex element type");
1125 else if (PrimName == pxr::HdTokens->normals)
1126 VERIFY(ElementType == pxr::HdTypeFloatVec3, "Unexpected normal element type");
1127 else if (PrimName == pxr::HdTokens->displayColor)
1128 VERIFY(ElementType == pxr::HdTypeFloatVec3, "Unexpected vertex color element type");
1129
1130 RefCntAutoPtr<IBuffer> pBuffer;
1131 if (!m_VertexData.PoolAllocation)
1132 {
1133 const auto BufferName = GetId().GetString() + " - " + PrimName.GetString();
1134 BufferDesc Desc{
1135 BufferName.c_str(),
1136 NumElements * ElementSize,
1137 BIND_VERTEX_BUFFER,
1138 USAGE_IMMUTABLE,
1139 };
1140
1141 BufferData InitData{pSource->GetData(), Desc.Size};
1142 pBuffer = Device.CreateBuffer(Desc, &InitData);
1143
1144 StateTransitionDesc Barrier{pBuffer, RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_VERTEX_BUFFER, STATE_TRANSITION_FLAG_UPDATE_STATE};
1145 RenderDelegate.GetDeviceContext()->TransitionResourceStates(1, &Barrier);
1146 }
1147 else
1148 {
1149 auto idx_it = m_VertexData.NameToPoolIndex.find(PrimName);
1150 if (idx_it != m_VertexData.NameToPoolIndex.end())
1151 {
1152 pBuffer = m_VertexData.PoolAllocation->GetBuffer(idx_it->second);
1153
1154 IDeviceContext* pCtx = RenderDelegate.GetDeviceContext();
1155 VERIFY_EXPR(m_VertexData.PoolAllocation->GetVertexCount() == NumElements);
1156 pCtx->UpdateBuffer(pBuffer, m_VertexData.PoolAllocation->GetStartVertex() * ElementSize, NumElements * ElementSize, pSource->GetData(), RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
1157 }
1158 else
1159 {
1160 UNEXPECTED("Failed to find vertex buffer index for ", PrimName);

Callers 1

CommitResourcesMethod · 0.80

Calls 6

GetNumElementsMethod · 0.80
GetTupleTypeMethod · 0.80
GetDataMethod · 0.80
GetDeviceContextMethod · 0.80
GetBufferMethod · 0.80
GetDeviceMethod · 0.45

Tested by

no test coverage detected