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

Method UpdateIndexBuffer

Hydrogent/src/HnMesh.cpp:1170–1237  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1168}
1169
1170void HnMesh::UpdateIndexBuffer(HnRenderDelegate& RenderDelegate)
1171{
1172 VERIFY_EXPR(m_StagingIndexData);
1173
1174 auto PrepareIndexBuffer = [&](const char* BufferName,
1175 const void* pData,
1176 size_t DataSize,
1177 IBufferSuballocation* pSuballocation) {
1178 const std::string Name = GetId().GetString() + " - " + BufferName;
1179
1180 IDeviceContext* pCtx = RenderDelegate.GetDeviceContext();
1181 if (pSuballocation == nullptr)
1182 {
1183 BufferDesc Desc{
1184 Name.c_str(),
1185 DataSize,
1186 BIND_INDEX_BUFFER,
1187 USAGE_IMMUTABLE,
1188 };
1189 BufferData InitData{pData, Desc.Size};
1190
1191 const RenderDeviceX_N& Device{RenderDelegate.GetDevice()};
1192 RefCntAutoPtr<IBuffer> pBuffer = Device.CreateBuffer(Desc, &InitData);
1193
1194 StateTransitionDesc Barrier{pBuffer, RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_INDEX_BUFFER, STATE_TRANSITION_FLAG_UPDATE_STATE};
1195 pCtx->TransitionResourceStates(1, &Barrier);
1196
1197 return pBuffer;
1198 }
1199 else
1200 {
1201 RefCntAutoPtr<IBuffer> pBuffer{pSuballocation->GetBuffer()};
1202 VERIFY_EXPR(pSuballocation->GetSize() == DataSize);
1203 pCtx->UpdateBuffer(pBuffer, pSuballocation->GetOffset(), DataSize, pData, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
1204 return pBuffer;
1205 }
1206 };
1207
1208 if (!m_StagingIndexData->Faces.Indices.empty())
1209 {
1210 VERIFY_EXPR(m_IndexData.NumFaceTriangles == static_cast<size_t>(m_StagingIndexData->Faces.Indices.size()));
1211 static_assert(sizeof(m_StagingIndexData->Faces.Indices[0]) == sizeof(Uint32) * 3, "Unexpected triangle data size");
1212 m_IndexData.Faces = PrepareIndexBuffer("Triangle Index Buffer",
1213 m_StagingIndexData->Faces.Indices.data(),
1214 m_IndexData.NumFaceTriangles * sizeof(Uint32) * 3,
1215 m_IndexData.FaceAllocation);
1216 }
1217
1218 if (!m_StagingIndexData->MeshEdgeIndices.empty())
1219 {
1220 VERIFY_EXPR(m_IndexData.NumEdges == static_cast<Uint32>(m_StagingIndexData->MeshEdgeIndices.size()));
1221 m_IndexData.Edges = PrepareIndexBuffer("Edge Index Buffer",
1222 m_StagingIndexData->MeshEdgeIndices.data(),
1223 m_IndexData.NumEdges * sizeof(Uint32) * 2,
1224 m_IndexData.EdgeAllocation);
1225 }
1226
1227 if (!m_StagingIndexData->PointIndices.empty())

Callers 2

CommitResourcesMethod · 0.80
BeginMethod · 0.80

Calls 3

GetDeviceContextMethod · 0.80
GetBufferMethod · 0.80
GetDeviceMethod · 0.45

Tested by

no test coverage detected