Refactor new editor host resize pipeline

This commit is contained in:
2026-04-13 23:09:02 +08:00
parent 712f99e723
commit 4362008b39
17 changed files with 1481 additions and 929 deletions

View File

@@ -0,0 +1,61 @@
#pragma once
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include "D3D12HostDevice.h"
#include <XCEngine/Rendering/RenderContext.h>
#include <XCEngine/Rendering/RenderSurface.h>
#include <XCEngine/RHI/D3D12/D3D12SwapChain.h>
#include <XCEngine/RHI/D3D12/D3D12Texture.h>
#include <XCEngine/RHI/RHIResourceView.h>
#include <XCEngine/RHI/RHISwapChain.h>
#include <windows.h>
#include <cstdint>
#include <string>
#include <vector>
namespace XCEngine::UI::Editor::Host {
class D3D12WindowSwapChainPresenter {
public:
static constexpr std::uint32_t kSwapChainBufferCount = 3u;
bool Initialize(D3D12HostDevice& hostDevice, HWND hwnd, int width, int height);
void Shutdown();
bool Resize(int width, int height);
bool PreparePresentSurface(const ::XCEngine::Rendering::RenderContext& renderContext);
bool PresentFrame();
const std::string& GetLastError() const;
::XCEngine::RHI::RHISwapChain* GetSwapChain() const;
const ::XCEngine::Rendering::RenderSurface* GetCurrentRenderSurface() const;
const ::XCEngine::RHI::D3D12Texture* GetCurrentBackBufferTexture() const;
const ::XCEngine::RHI::D3D12Texture* GetBackBufferTexture(std::uint32_t index) const;
std::uint32_t GetBackBufferCount() const;
std::uint32_t GetCurrentBackBufferIndex() const;
private:
bool CreateSwapChain(int width, int height);
void DestroySwapChain();
bool RecreateSwapChain(int width, int height);
::XCEngine::RHI::D3D12SwapChain* GetD3D12SwapChain() const;
void ReleaseBackBufferCommandReferences();
void ReleaseBackBufferViews();
bool RecreateBackBufferViews();
HWND m_hwnd = nullptr;
int m_width = 0;
int m_height = 0;
D3D12HostDevice* m_hostDevice = nullptr;
::XCEngine::RHI::RHISwapChain* m_swapChain = nullptr;
std::vector<::XCEngine::RHI::RHIResourceView*> m_backBufferViews = {};
std::vector<::XCEngine::Rendering::RenderSurface> m_backBufferSurfaces = {};
std::string m_lastError = {};
};
} // namespace XCEngine::UI::Editor::Host