Refactor: use engine封装 for Vertex/Index Buffer operations
This commit is contained in:
@@ -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<std::string, SubMesh*> 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<std::string, SubMesh*>(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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user