git.s-ol.nu ~forks/DiligentFX / 68dc840
GLTF PBR renderer: using FirstIndexLocation and BaseVertex from GLTF model assiduous 10 months ago
2 changed file(s) with 22 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
198198 /// First index for indexed primitives
199199 Uint32 FirstIndex = 0;
200200
201 /// Base vertex for indexed primitives or start vertex location for non-indexed.
202 Uint32 BaseVertex = 0;
203
201204 GLTFNodeRenderInfo() noexcept :
202205 IndexCount{0}
203206 {}
386389 std::function<void(const GLTFNodeRenderInfo&)> RenderNodeCallback;
387390 const size_t SRBTypeId;
388391
392 const Uint32 FirstIndexLocation;
393 const Uint32 BaseVertex;
394
389395 void Render(const GLTF::Node& Node,
390396 GLTF::Material::ALPHA_MODE AlphaMode);
391397 };
910910 if (RenderNodeCallback == nullptr)
911911 {
912912 DrawIndexedAttribs drawAttrs(primitive->IndexCount, VT_UINT32, DRAW_FLAG_VERIFY_ALL);
913 drawAttrs.FirstIndexLocation = primitive->FirstIndex;
913 drawAttrs.FirstIndexLocation = FirstIndexLocation + primitive->FirstIndex;
914 drawAttrs.BaseVertex = BaseVertex;
914915 pCtx->DrawIndexed(drawAttrs);
915916 }
916917 else
917918 {
918919 NodeRI.IndexType = VT_UINT32;
919920 NodeRI.IndexCount = primitive->IndexCount;
920 NodeRI.FirstIndex = primitive->FirstIndex;
921 NodeRI.FirstIndex = FirstIndexLocation + primitive->FirstIndex;
922 NodeRI.BaseVertex = BaseVertex;
921923 RenderNodeCallback(NodeRI);
922924 }
923925 }
926928 if (RenderNodeCallback == nullptr)
927929 {
928930 DrawAttribs drawAttrs(primitive->VertexCount, DRAW_FLAG_VERIFY_ALL);
931 drawAttrs.StartVertexLocation = BaseVertex;
929932 pCtx->Draw(drawAttrs);
930933 }
931934 else
933936 NodeRI.IndexType = VT_UNDEFINED;
934937 NodeRI.VertexCount = primitive->VertexCount;
935938 NodeRI.FirstIndex = 0;
939 NodeRI.BaseVertex = BaseVertex;
936940 RenderNodeCallback(NodeRI);
937941 }
938942 }
955959
956960 if (RenderNodeCallback == nullptr)
957961 {
958 std::array<Uint32, 2> Offsets;
959 std::array<IBuffer*, 2> pVBs = //
962 std::array<Uint32, 2> Offsets = {};
963 std::array<IBuffer*, 2> pVBs =
960964 {
961 GLTFModel.GetBuffer(GLTF::Model::BUFFER_ID_VERTEX0, Offsets[0]),
962 GLTFModel.GetBuffer(GLTF::Model::BUFFER_ID_VERTEX1, Offsets[1]) //
965 GLTFModel.GetBuffer(GLTF::Model::BUFFER_ID_VERTEX0),
966 GLTFModel.GetBuffer(GLTF::Model::BUFFER_ID_VERTEX1) //
963967 };
964968 pCtx->SetVertexBuffers(0, static_cast<Uint32>(pVBs.size()), pVBs.data(), Offsets.data(), RESOURCE_STATE_TRANSITION_MODE_TRANSITION, SET_VERTEX_BUFFERS_FLAG_RESET);
965969
966 Uint32 IBOffset = 0;
967 auto* pIndexBuffer = GLTFModel.GetBuffer(GLTF::Model::BUFFER_ID_INDEX, IBOffset);
968 if (pIndexBuffer)
969 {
970 pCtx->SetIndexBuffer(pIndexBuffer, IBOffset, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
970 if (auto* pIndexBuffer = GLTFModel.GetBuffer(GLTF::Model::BUFFER_ID_INDEX))
971 {
972 pCtx->SetIndexBuffer(pIndexBuffer, 0, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
971973 }
972974 }
973975 else
982984 GLTFModel,
983985 RenderParams,
984986 RenderNodeCallback,
985 SRBTypeId //
987 SRBTypeId,
988 GLTFModel.GetFirstIndexLocation(),
989 GLTFModel.GetBaseVertex() //
986990 };
987991
988992 // Opaque primitives first