Hi everyone,
The sample of the SDK renders a single triangle per frame.
I want to render multiple objects per frame (of course, it is fine if there is only one vertex buffer).
Before Dx11, it was possible to implement the rendering of a single object or of multiple objects by simply increasing the loop counter.
In Dx12, however, it seems that this is no longer the case.
Through trial and error, I was finally able to figure out how to do it!
However, I have concerns about whether it is a suitable solution.
For now, I am implementing multiple renderings by creating multiple CBVs.
For example, if I want to render 5 objects, I create 5 CBVs, one for each.
****Initializing Phase****
for (int i = 0; i < 5; i++)
{
cbvDesc.BufferLocation = g_constantBuffer->GetGPUVirtualAddress()+i*CBSize;
D3D12_CPU_DESCRIPTOR_HANDLE cHandle = g_pCbvHeap->GetCPUDescriptorHandleForHeapStart();
cHandle.ptr += i*Stride;
g_pDevice->CreateConstantBufferView(&cbvDesc, cHandle);
}
****Draw Phase****
//Update constant buffer
for (int i = 0; i<5; i++)
{
char* ptr = reinterpret_cast<char*>(g_pCbvDataBegin)+256*i;
(some matrix oparation...)
g_constantBufferData.mWVP = mWVP;
memcpy(ptr, &g_constantBufferData, sizeof(g_constantBufferData));
}
//Draw
for(int i=0;i<5;i++)
{
cbvSrvUavDescHeap.ptr += i * size;
g_pCommandList->SetGraphicsRootDescriptorTable(0, cbvSrvUavDescHeap);
g_pCommandList->DrawInstanced(3, 1, 0, 0);
}
.
Something about this solution feels ‘off’, so I wanted to see what you all think.
Is this the right way to handle this problem?
Thanks!
Best regards,