From 210bc450faa4013ed34d582efa6ba8b7f669713d Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Tue, 17 Mar 2026 00:47:05 +0800 Subject: [PATCH] =?UTF-8?q?Refactor:=20use=20engine=E5=B0=81=E8=A3=85=20fo?= =?UTF-8?q?r=20Vertex/Index=20Buffer=20operations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/D3D12/main.cpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/tests/D3D12/main.cpp b/tests/D3D12/main.cpp index a6f29442..366840aa 100644 --- a/tests/D3D12/main.cpp +++ b/tests/D3D12/main.cpp @@ -114,7 +114,6 @@ struct StaticMeshComponentVertexData { struct SubMesh { XCEngine::RHI::D3D12Buffer mIBO; - D3D12_INDEX_BUFFER_VIEW mIBView; int mIndexCount; }; @@ -125,9 +124,9 @@ struct SubMesh { class StaticMeshComponent { public: XCEngine::RHI::D3D12Buffer mVBO; - D3D12_VERTEX_BUFFER_VIEW mVBOView; StaticMeshComponentVertexData* mVertexData; int mVertexCount; + uint32_t mStride; std::unordered_map mSubMeshes; void SetVertexCount(int inVertexCount) { @@ -166,14 +165,12 @@ public: int temp = 0; fread(&temp, 4, 1, pFile); mVertexCount = temp; + mStride = sizeof(StaticMeshComponentVertexData); mVertexData = new StaticMeshComponentVertexData[mVertexCount]; fread(mVertexData, 1, sizeof(StaticMeshComponentVertexData) * mVertexCount, pFile); mVBO.InitializeWithData(gD3D12Device.GetDevice(), inCommandList, mVertexData, sizeof(StaticMeshComponentVertexData) * mVertexCount, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER); - mVBOView.BufferLocation = mVBO.GetGPUVirtualAddress(); - mVBOView.SizeInBytes = sizeof(StaticMeshComponentVertexData) * mVertexCount; - mVBOView.StrideInBytes = sizeof(StaticMeshComponentVertexData); while (!feof(pFile)) { fread(&temp, 4, 1, pFile); @@ -190,10 +187,6 @@ public: submesh->mIBO.InitializeWithData(gD3D12Device.GetDevice(), inCommandList, indexes, sizeof(unsigned int) * temp, D3D12_RESOURCE_STATE_INDEX_BUFFER); - - submesh->mIBView.BufferLocation = submesh->mIBO.GetGPUVirtualAddress(); - submesh->mIBView.SizeInBytes = sizeof(unsigned int) * temp; - submesh->mIBView.Format = DXGI_FORMAT_R32_UINT; mSubMeshes.insert(std::pair(name, submesh)); delete[] indexes; } @@ -201,10 +194,7 @@ public: } } void Render(XCEngine::RHI::D3D12CommandList& inCommandList) { - D3D12_VERTEX_BUFFER_VIEW vbos[] = { - mVBOView - }; - inCommandList.SetVertexBuffers(0, 1, vbos); + inCommandList.SetVertexBuffer(0, mVBO.GetResource(), 0, mStride); if (mSubMeshes.empty()) { inCommandList.Draw(mVertexCount, 1, 0, 0); }