Add XCUI window compositor seam
This commit is contained in:
99
new_editor/src/XCUIBackend/ImGuiHostCompositor.cpp
Normal file
99
new_editor/src/XCUIBackend/ImGuiHostCompositor.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
#include "XCUIBackend/IEditorHostCompositor.h"
|
||||
|
||||
#include "UI/ImGuiBackendBridge.h"
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
namespace XCUIBackend {
|
||||
|
||||
namespace {
|
||||
|
||||
class ImGuiHostCompositor final : public IEditorHostCompositor {
|
||||
public:
|
||||
bool Initialize(
|
||||
HWND hwnd,
|
||||
::XCEngine::Editor::Platform::D3D12WindowRenderer& windowRenderer,
|
||||
const ConfigureFontsCallback& configureFonts) override {
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||
|
||||
if (configureFonts) {
|
||||
configureFonts();
|
||||
}
|
||||
|
||||
ImGui::StyleColorsDark();
|
||||
m_backend.Initialize(
|
||||
hwnd,
|
||||
windowRenderer.GetDevice(),
|
||||
windowRenderer.GetCommandQueue(),
|
||||
windowRenderer.GetSrvHeap(),
|
||||
windowRenderer.GetSrvDescriptorSize(),
|
||||
windowRenderer.GetSrvDescriptorCount());
|
||||
return true;
|
||||
}
|
||||
|
||||
void Shutdown() override {
|
||||
m_backend.Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
|
||||
bool HandleWindowMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) override {
|
||||
return ::XCEngine::Editor::UI::ImGuiBackendBridge::HandleWindowMessage(
|
||||
hwnd,
|
||||
message,
|
||||
wParam,
|
||||
lParam);
|
||||
}
|
||||
|
||||
void BeginFrame() override {
|
||||
m_backend.BeginFrame();
|
||||
}
|
||||
|
||||
void EndFrameAndPresent(
|
||||
::XCEngine::Editor::Platform::D3D12WindowRenderer& windowRenderer,
|
||||
const float clearColor[4],
|
||||
const RenderCallback& beforeUiRender,
|
||||
const RenderCallback& afterUiRender) override {
|
||||
ImGui::Render();
|
||||
windowRenderer.Render(m_backend, clearColor, beforeUiRender, afterUiRender);
|
||||
}
|
||||
|
||||
bool CreateTextureDescriptor(
|
||||
::XCEngine::RHI::RHIDevice* device,
|
||||
::XCEngine::RHI::RHITexture* texture,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE* outCpuHandle,
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE* outGpuHandle,
|
||||
ImTextureID* outTextureId) override {
|
||||
return m_backend.CreateTextureDescriptor(
|
||||
device,
|
||||
texture,
|
||||
outCpuHandle,
|
||||
outGpuHandle,
|
||||
outTextureId);
|
||||
}
|
||||
|
||||
void FreeTextureDescriptor(
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle,
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle) override {
|
||||
m_backend.FreeTextureDescriptor(cpuHandle, gpuHandle);
|
||||
}
|
||||
|
||||
private:
|
||||
::XCEngine::Editor::UI::ImGuiBackendBridge m_backend;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<IEditorHostCompositor> CreateImGuiHostCompositor() {
|
||||
return std::make_unique<ImGuiHostCompositor>();
|
||||
}
|
||||
|
||||
} // namespace XCUIBackend
|
||||
} // namespace Editor
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user