63 lines
2.0 KiB
C++
63 lines
2.0 KiB
C++
#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 = 2u;
|
|
|
|
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 ConfigureFrameLatency();
|
|
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
|