66 lines
2.2 KiB
C++
66 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#ifndef NOMINMAX
|
|
#define NOMINMAX
|
|
#endif
|
|
|
|
#include "Ports/ViewportRenderPort.h"
|
|
#include "D3D12HostDevice.h"
|
|
#include "D3D12ShaderResourceDescriptorAllocator.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 <string>
|
|
#include <unordered_map>
|
|
|
|
namespace XCEngine::UI::Editor::Host {
|
|
|
|
class D3D12WindowRenderer : public Ports::ViewportRenderPort {
|
|
public:
|
|
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 PreparePresentSurface();
|
|
bool SubmitFrame(bool presentSwapChain);
|
|
bool SignalFrameCompletion();
|
|
bool PresentFrame();
|
|
|
|
ID3D12Device* GetDevice() const;
|
|
ID3D12CommandQueue* GetCommandQueue() const;
|
|
const std::string& GetLastError() const;
|
|
::XCEngine::RHI::RHIDevice* GetRHIDevice() 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;
|
|
::XCEngine::Rendering::RenderContext GetRenderContext() const;
|
|
|
|
private:
|
|
D3D12HostDevice m_hostDevice = {};
|
|
D3D12WindowSwapChainPresenter m_presenter = {};
|
|
D3D12ShaderResourceDescriptorAllocator m_viewportTextureAllocator = {};
|
|
std::uint32_t m_activeBackBufferIndex = 0u;
|
|
std::unordered_map<std::uintptr_t, D3D12_CPU_DESCRIPTOR_HANDLE> m_viewportTextureCpuHandles = {};
|
|
std::string m_lastError = {};
|
|
};
|
|
|
|
} // namespace XCEngine::UI::Editor::Host
|