Tighten XCUI compositor texture registration
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "Platform/D3D12WindowRenderer.h"
|
||||
#include "XCUIBackend/UITextureRegistration.h"
|
||||
|
||||
#include <XCEngine/RHI/RHIDevice.h>
|
||||
#include <XCEngine/RHI/RHITexture.h>
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <windows.h>
|
||||
@@ -37,12 +36,8 @@ public:
|
||||
virtual bool CreateTextureDescriptor(
|
||||
::XCEngine::RHI::RHIDevice* device,
|
||||
::XCEngine::RHI::RHITexture* texture,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE* outCpuHandle,
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE* outGpuHandle,
|
||||
ImTextureID* outTextureId) = 0;
|
||||
virtual void FreeTextureDescriptor(
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle,
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle) = 0;
|
||||
UITextureRegistration& outRegistration) = 0;
|
||||
virtual void FreeTextureDescriptor(const UITextureRegistration& registration) = 0;
|
||||
};
|
||||
|
||||
std::unique_ptr<IEditorHostCompositor> CreateImGuiHostCompositor();
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "Platform/D3D12WindowRenderer.h"
|
||||
#include "XCUIBackend/UITextureRegistration.h"
|
||||
|
||||
#include <XCEngine/RHI/RHIDevice.h>
|
||||
#include <XCEngine/RHI/RHITexture.h>
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <windows.h>
|
||||
@@ -37,12 +36,8 @@ public:
|
||||
virtual bool CreateTextureDescriptor(
|
||||
::XCEngine::RHI::RHIDevice* device,
|
||||
::XCEngine::RHI::RHITexture* texture,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE* outCpuHandle,
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE* outGpuHandle,
|
||||
ImTextureID* outTextureId) = 0;
|
||||
virtual void FreeTextureDescriptor(
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle,
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle) = 0;
|
||||
UITextureRegistration& outRegistration) = 0;
|
||||
virtual void FreeTextureDescriptor(const UITextureRegistration& registration) = 0;
|
||||
};
|
||||
|
||||
std::unique_ptr<IWindowUICompositor> CreateImGuiWindowUICompositor();
|
||||
|
||||
@@ -67,21 +67,27 @@ public:
|
||||
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(
|
||||
UITextureRegistration& outRegistration) override {
|
||||
ImTextureID textureId = {};
|
||||
if (!m_backend.CreateTextureDescriptor(
|
||||
device,
|
||||
texture,
|
||||
outCpuHandle,
|
||||
outGpuHandle,
|
||||
outTextureId);
|
||||
&outRegistration.cpuHandle,
|
||||
&outRegistration.gpuHandle,
|
||||
&textureId)) {
|
||||
outRegistration = {};
|
||||
return false;
|
||||
}
|
||||
|
||||
outRegistration.texture.nativeHandle = (std::uintptr_t)textureId;
|
||||
outRegistration.texture.width = texture != nullptr ? texture->GetWidth() : 0u;
|
||||
outRegistration.texture.height = texture != nullptr ? texture->GetHeight() : 0u;
|
||||
outRegistration.texture.kind = ::XCEngine::UI::UITextureHandleKind::ImGuiDescriptor;
|
||||
return outRegistration.IsValid();
|
||||
}
|
||||
|
||||
void FreeTextureDescriptor(
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle,
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle) override {
|
||||
m_backend.FreeTextureDescriptor(cpuHandle, gpuHandle);
|
||||
void FreeTextureDescriptor(const UITextureRegistration& registration) override {
|
||||
m_backend.FreeTextureDescriptor(registration.cpuHandle, registration.gpuHandle);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -60,23 +60,17 @@ public:
|
||||
bool CreateTextureDescriptor(
|
||||
::XCEngine::RHI::RHIDevice* device,
|
||||
::XCEngine::RHI::RHITexture* texture,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE* outCpuHandle,
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE* outGpuHandle,
|
||||
ImTextureID* outTextureId) override {
|
||||
UITextureRegistration& outRegistration) override {
|
||||
return m_hostCompositor != nullptr &&
|
||||
m_hostCompositor->CreateTextureDescriptor(
|
||||
device,
|
||||
texture,
|
||||
outCpuHandle,
|
||||
outGpuHandle,
|
||||
outTextureId);
|
||||
outRegistration);
|
||||
}
|
||||
|
||||
void FreeTextureDescriptor(
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle,
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle) override {
|
||||
void FreeTextureDescriptor(const UITextureRegistration& registration) override {
|
||||
if (m_hostCompositor != nullptr) {
|
||||
m_hostCompositor->FreeTextureDescriptor(cpuHandle, gpuHandle);
|
||||
m_hostCompositor->FreeTextureDescriptor(registration);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
23
new_editor/src/XCUIBackend/UITextureRegistration.h
Normal file
23
new_editor/src/XCUIBackend/UITextureRegistration.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <XCEngine/UI/Types.h>
|
||||
|
||||
#include <d3d12.h>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
namespace XCUIBackend {
|
||||
|
||||
struct UITextureRegistration {
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle = {};
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle = {};
|
||||
::XCEngine::UI::UITextureHandle texture = {};
|
||||
|
||||
bool IsValid() const {
|
||||
return cpuHandle.ptr != 0u && gpuHandle.ptr != 0u && texture.IsValid();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace XCUIBackend
|
||||
} // namespace Editor
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user