fix: 修复 D3D12SwapChain 重复创建 swapchain 问题

- 添加 Initialize(IDXGISwapChain*, width, height) 重载方法
- 接受已存在的 swapchain 而不是重复创建
- 测试通过,日志显示正常渲染
This commit is contained in:
2026-03-15 18:30:14 +08:00
parent 80a11d1836
commit 88cd65d082
3 changed files with 14 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ public:
~D3D12SwapChain();
bool Initialize(IDXGIFactory4* factory, ID3D12CommandQueue* commandQueue, HWND windowHandle, uint32_t width, uint32_t height, uint32_t bufferCount = 2);
bool Initialize(IDXGISwapChain* swapChain, uint32_t width, uint32_t height);
void Shutdown();
uint32_t GetCurrentBackBufferIndex() const;

View File

@@ -47,6 +47,18 @@ bool D3D12SwapChain::Initialize(IDXGIFactory4* factory, ID3D12CommandQueue* comm
return true;
}
bool D3D12SwapChain::Initialize(IDXGISwapChain* swapChain, uint32_t width, uint32_t height) {
HRESULT hResult = swapChain->QueryInterface(IID_PPV_ARGS(&m_swapChain));
if (FAILED(hResult)) {
return false;
}
m_width = width;
m_height = height;
return true;
}
void D3D12SwapChain::Shutdown() {
m_swapChain.Reset();
}