83 lines
3.1 KiB
C++
83 lines
3.1 KiB
C++
#pragma once
|
|
|
|
#ifndef NOMINMAX
|
|
#define NOMINMAX
|
|
#endif
|
|
|
|
#include "Rendering/Host/ViewportRenderHost.h"
|
|
#include "D3D12HostDevice.h"
|
|
#include "D3D12ShaderResourceDescriptorAllocator.h"
|
|
#include "D3D12WindowCapture.h"
|
|
#include "D3D12WindowSwapChainPresenter.h"
|
|
|
|
#include <XCEngine/Rendering/RenderContext.h>
|
|
#include <XCEngine/Rendering/RenderSurface.h>
|
|
#include <XCEngine/RHI/D3D12/D3D12Texture.h>
|
|
#include <XCEngine/RHI/RHISwapChain.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <filesystem>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
namespace XCEngine::UI::Editor::Host {
|
|
|
|
class D3D12WindowRenderer : public Rendering::Host::ViewportRenderHost {
|
|
public:
|
|
static constexpr std::uint32_t kFrameContextCount =
|
|
D3D12HostDevice::kFrameContextCount;
|
|
static constexpr std::uint32_t kSwapChainBufferCount =
|
|
D3D12WindowSwapChainPresenter::kSwapChainBufferCount;
|
|
|
|
bool Initialize(HWND hwnd, int width, int height);
|
|
void Shutdown();
|
|
bool Resize(int width, int height);
|
|
bool BeginFrame();
|
|
bool PrepareCurrentBackBufferForUiRender();
|
|
bool FinalizeCurrentBackBufferForPresent();
|
|
bool SubmitFrame();
|
|
bool SignalFrameCompletion();
|
|
bool PresentFrame();
|
|
bool CaptureCurrentBackBufferToPng(
|
|
const std::filesystem::path& outputPath,
|
|
std::string& outError);
|
|
void WaitForGpuIdle();
|
|
|
|
ID3D12Device* GetDevice() const;
|
|
ID3D12CommandQueue* GetCommandQueue() const;
|
|
const std::string& GetLastError() const;
|
|
::XCEngine::RHI::RHIDevice* GetRHIDevice() const override;
|
|
std::uint32_t GetViewportResourceRetirementSlotCount() const override;
|
|
bool TryGetActiveViewportResourceRetirementSlot(std::uint32_t& outSlot) const override;
|
|
bool CreateViewportTextureHandle(
|
|
::XCEngine::RHI::RHITexture& texture,
|
|
std::uint32_t width,
|
|
std::uint32_t height,
|
|
::XCEngine::UI::UITextureHandle& outTexture) override;
|
|
void ReleaseViewportTextureHandle(
|
|
::XCEngine::UI::UITextureHandle& texture) override;
|
|
::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 GetActiveFrameSlot() const;
|
|
::XCEngine::Rendering::RenderContext GetRenderContext() const;
|
|
D3D12ShaderResourceDescriptorAllocator& GetTextureDescriptorAllocator();
|
|
const D3D12ShaderResourceDescriptorAllocator& GetTextureDescriptorAllocator() const;
|
|
|
|
private:
|
|
D3D12HostDevice m_hostDevice = {};
|
|
D3D12WindowSwapChainPresenter m_presenter = {};
|
|
D3D12WindowCapture m_capture = {};
|
|
D3D12ShaderResourceDescriptorAllocator m_textureAllocator = {};
|
|
std::uint32_t m_activeFrameSlot = 0u;
|
|
std::uint32_t m_nextFrameSlot = 0u;
|
|
std::uint32_t m_activeBackBufferIndex = 0u;
|
|
std::unordered_map<std::uintptr_t, D3D12_CPU_DESCRIPTOR_HANDLE> m_textureCpuHandles = {};
|
|
std::string m_lastError = {};
|
|
};
|
|
|
|
} // namespace XCEngine::UI::Editor::Host
|