feat: 修复RHI渲染循环问题
- 修复RootSignature参数数量与HelloEarth一致 - 修复StaticMeshComponent中device为nullptr的问题 - 修复CommandList::Reset类型转换问题 - 修复RTV创建使用nullptr而不是rtvDesc - 添加SwapChain的GetCurrentRenderTarget方法 - 修复DepthStencil创建问题(暂时跳过) - 渲染循环基本可运行
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
#pragma comment(lib,"d3dcompiler.lib")
|
||||
#pragma comment(lib,"winmm.lib")
|
||||
|
||||
void EngineLog(const char* msg, ...);
|
||||
|
||||
using namespace XCEngine;
|
||||
using namespace XCEngine::RHI;
|
||||
|
||||
@@ -178,12 +180,15 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hInstancePrev, LPWSTR lpCmdLi
|
||||
return -1;
|
||||
}
|
||||
printf("PipelineState created\n");
|
||||
EngineLog("After PSO created");
|
||||
|
||||
IConstantBuffer* cb = nullptr;
|
||||
if (!CreateConstantBuffer(device, 65536, &cb)) {
|
||||
printf("CreateConstantBuffer Failed!\n");
|
||||
return -1;
|
||||
}
|
||||
printf("ConstantBuffer created\n");
|
||||
EngineLog("After CreateConstantBuffer");
|
||||
|
||||
float matrices[64] = {};
|
||||
matrices[0] = 1.0f; matrices[5] = 1.0f; matrices[10] = 1.0f; matrices[15] = 1.0f;
|
||||
@@ -191,17 +196,28 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hInstancePrev, LPWSTR lpCmdLi
|
||||
matrices[32] = 1.0f; matrices[37] = 1.0f; matrices[42] = 1.0f; matrices[47] = 1.0f;
|
||||
matrices[48] = 1.0f; matrices[53] = 1.0f; matrices[58] = 1.0f; matrices[63] = 1.0f;
|
||||
UpdateConstantBuffer(cb, matrices, sizeof(matrices));
|
||||
printf("ConstantBuffer updated\n");
|
||||
EngineLog("After UpdateConstantBuffer");
|
||||
|
||||
StaticMeshComponent mesh;
|
||||
printf("Starting mesh init...\n");
|
||||
EngineLog("Before mesh.Initialize");
|
||||
if (!mesh.Initialize(cmdList, "Res/Model/Sphere.lhsm")) {
|
||||
printf("Load Mesh Failed!\n");
|
||||
return -1;
|
||||
}
|
||||
printf("Mesh loaded\n");
|
||||
EngineLog("After mesh.Initialize");
|
||||
|
||||
cmdList->Close();
|
||||
printf("CommandList closed\n");
|
||||
EngineLog("After cmdList->Close");
|
||||
|
||||
ICommandQueue* queue = device->GetCommandQueue();
|
||||
void* cmdListPtr = cmdList->GetNativeCommandList();
|
||||
queue->ExecuteCommandLists(&cmdListPtr, 1);
|
||||
printf("Commands executed\n");
|
||||
EngineLog("After ExecuteCommandLists");
|
||||
|
||||
ShowWindow(hwnd, nShowCmd);
|
||||
UpdateWindow(hwnd);
|
||||
@@ -213,7 +229,9 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hInstancePrev, LPWSTR lpCmdLi
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
} else {
|
||||
EngineLog("MainLoop: 1");
|
||||
renderContext.BeginFrame();
|
||||
EngineLog("MainLoop: 2");
|
||||
|
||||
renderContext.SetViewport((float)width, (float)height);
|
||||
renderContext.SetScissor(width, height);
|
||||
@@ -221,15 +239,22 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hInstancePrev, LPWSTR lpCmdLi
|
||||
float color[4] = {0.5f, 0.5f, 0.5f, 1.0f};
|
||||
renderContext.ClearRenderTarget(color);
|
||||
renderContext.ClearDepthStencil();
|
||||
EngineLog("MainLoop: 2e");
|
||||
|
||||
cmdList->SetPipelineState(pso);
|
||||
EngineLog("MainLoop: 2f - SetRootSignature");
|
||||
cmdList->SetRootSignature(rootSignature);
|
||||
EngineLog("MainLoop: 2g - SetPrimitiveTopology");
|
||||
cmdList->SetPrimitiveTopology(PrimitiveTopology::TriangleList);
|
||||
|
||||
EngineLog("MainLoop: 3 - before mesh.Render");
|
||||
mesh.Render(cmdList);
|
||||
EngineLog("MainLoop: 4");
|
||||
|
||||
renderContext.EndFrame();
|
||||
EngineLog("MainLoop: 5");
|
||||
renderContext.Present();
|
||||
EngineLog("MainLoop: 6");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user