Split XCUI hosted preview ImGui presenter seam
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "Application.h"
|
||||
|
||||
#include "XCUIBackend/ImGuiXCUIHostedPreviewPresenter.h"
|
||||
#include "XCUIBackend/ImGuiWindowUICompositor.h"
|
||||
|
||||
#include <XCEngine/Core/Asset/ResourceManager.h>
|
||||
@@ -848,11 +849,14 @@ void Application::RenderQueuedHostedPreviews(
|
||||
drainStats.renderedDrawListCount += overlayStats.drawListCount;
|
||||
drainStats.renderedCommandCount += overlayStats.renderedCommandCount;
|
||||
drainStats.skippedCommandCount += overlayStats.skippedCommandCount;
|
||||
::XCEngine::UI::UITextureHandle previewTexture = {};
|
||||
previewTexture.nativeHandle = static_cast<std::uintptr_t>(previewSurface.imguiTextureId);
|
||||
previewTexture.width = previewSurface.width;
|
||||
previewTexture.height = previewSurface.height;
|
||||
previewTexture.kind = ::XCEngine::UI::UITextureHandleKind::ImGuiDescriptor;
|
||||
m_hostedPreviewSurfaceRegistry.UpdateSurface(
|
||||
queuedFrame.debugName,
|
||||
previewSurface.imguiTextureId,
|
||||
previewSurface.width,
|
||||
previewSurface.height,
|
||||
previewTexture,
|
||||
::XCEngine::UI::UIRect(
|
||||
0.0f,
|
||||
0.0f,
|
||||
|
||||
45
new_editor/src/XCUIBackend/ImGuiXCUIHostedPreviewPresenter.h
Normal file
45
new_editor/src/XCUIBackend/ImGuiXCUIHostedPreviewPresenter.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "XCUIBackend/ImGuiTransitionBackend.h"
|
||||
#include "XCUIBackend/XCUIHostedPreviewPresenter.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
namespace XCUIBackend {
|
||||
|
||||
class ImGuiXCUIHostedPreviewPresenter final : public IXCUIHostedPreviewPresenter {
|
||||
public:
|
||||
bool Present(const XCUIHostedPreviewFrame& frame) override {
|
||||
m_lastStats = {};
|
||||
if (frame.drawData == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_backend.BeginFrame();
|
||||
m_backend.Submit(*frame.drawData);
|
||||
m_lastStats.submittedDrawListCount = m_backend.GetPendingDrawListCount();
|
||||
m_lastStats.submittedCommandCount = m_backend.GetPendingCommandCount();
|
||||
m_lastStats.presented = m_backend.EndFrame(frame.targetDrawList);
|
||||
m_lastStats.flushedDrawListCount = m_backend.GetLastFlushedDrawListCount();
|
||||
m_lastStats.flushedCommandCount = m_backend.GetLastFlushedCommandCount();
|
||||
return m_lastStats.presented;
|
||||
}
|
||||
|
||||
const XCUIHostedPreviewStats& GetLastStats() const override {
|
||||
return m_lastStats;
|
||||
}
|
||||
|
||||
private:
|
||||
ImGuiTransitionBackend m_backend = {};
|
||||
XCUIHostedPreviewStats m_lastStats = {};
|
||||
};
|
||||
|
||||
inline std::unique_ptr<IXCUIHostedPreviewPresenter> CreateImGuiXCUIHostedPreviewPresenter() {
|
||||
return std::make_unique<ImGuiXCUIHostedPreviewPresenter>();
|
||||
}
|
||||
|
||||
} // namespace XCUIBackend
|
||||
} // namespace Editor
|
||||
} // namespace XCEngine
|
||||
@@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "XCUIBackend/ImGuiTransitionBackend.h"
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
#include <XCEngine/UI/Types.h>
|
||||
|
||||
@@ -45,15 +43,15 @@ struct XCUIHostedPreviewQueuedFrame {
|
||||
};
|
||||
|
||||
struct XCUIHostedPreviewSurfaceImage {
|
||||
ImTextureID textureId = {};
|
||||
ImVec2 uvMin = ImVec2(0.0f, 0.0f);
|
||||
ImVec2 uvMax = ImVec2(1.0f, 1.0f);
|
||||
::XCEngine::UI::UITextureHandle texture = {};
|
||||
::XCEngine::UI::UIPoint uvMin = {};
|
||||
::XCEngine::UI::UIPoint uvMax = ::XCEngine::UI::UIPoint(1.0f, 1.0f);
|
||||
::XCEngine::UI::UIRect renderedCanvasRect = {};
|
||||
std::uint32_t surfaceWidth = 0;
|
||||
std::uint32_t surfaceHeight = 0;
|
||||
|
||||
bool IsValid() const {
|
||||
return textureId != ImTextureID{} && surfaceWidth > 0u && surfaceHeight > 0u;
|
||||
return texture.IsValid() && surfaceWidth > 0u && surfaceHeight > 0u;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -114,11 +112,9 @@ public:
|
||||
|
||||
void UpdateSurface(
|
||||
const std::string& debugName,
|
||||
ImTextureID textureId,
|
||||
std::uint32_t surfaceWidth,
|
||||
std::uint32_t surfaceHeight,
|
||||
const ::XCEngine::UI::UITextureHandle& texture,
|
||||
const ::XCEngine::UI::UIRect& renderedCanvasRect) {
|
||||
if (debugName.empty() || textureId == ImTextureID{} || surfaceWidth == 0u || surfaceHeight == 0u) {
|
||||
if (debugName.empty() || !texture.IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -130,16 +126,16 @@ public:
|
||||
descriptor = &m_descriptors.back();
|
||||
}
|
||||
|
||||
descriptor->image.textureId = textureId;
|
||||
descriptor->image.surfaceWidth = surfaceWidth;
|
||||
descriptor->image.surfaceHeight = surfaceHeight;
|
||||
descriptor->image.texture = texture;
|
||||
descriptor->image.surfaceWidth = texture.width;
|
||||
descriptor->image.surfaceHeight = texture.height;
|
||||
descriptor->image.renderedCanvasRect = renderedCanvasRect;
|
||||
descriptor->image.uvMin = ImVec2(
|
||||
renderedCanvasRect.x / static_cast<float>(surfaceWidth),
|
||||
renderedCanvasRect.y / static_cast<float>(surfaceHeight));
|
||||
descriptor->image.uvMax = ImVec2(
|
||||
(renderedCanvasRect.x + renderedCanvasRect.width) / static_cast<float>(surfaceWidth),
|
||||
(renderedCanvasRect.y + renderedCanvasRect.height) / static_cast<float>(surfaceHeight));
|
||||
descriptor->image.uvMin = ::XCEngine::UI::UIPoint(
|
||||
renderedCanvasRect.x / static_cast<float>(texture.width),
|
||||
renderedCanvasRect.y / static_cast<float>(texture.height));
|
||||
descriptor->image.uvMax = ::XCEngine::UI::UIPoint(
|
||||
(renderedCanvasRect.x + renderedCanvasRect.width) / static_cast<float>(texture.width),
|
||||
(renderedCanvasRect.y + renderedCanvasRect.height) / static_cast<float>(texture.height));
|
||||
}
|
||||
|
||||
bool TryGetSurfaceDescriptor(
|
||||
@@ -267,33 +263,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class ImGuiXCUIHostedPreviewPresenter final : public IXCUIHostedPreviewPresenter {
|
||||
public:
|
||||
bool Present(const XCUIHostedPreviewFrame& frame) override {
|
||||
m_lastStats = {};
|
||||
if (frame.drawData == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_backend.BeginFrame();
|
||||
m_backend.Submit(*frame.drawData);
|
||||
m_lastStats.submittedDrawListCount = m_backend.GetPendingDrawListCount();
|
||||
m_lastStats.submittedCommandCount = m_backend.GetPendingCommandCount();
|
||||
m_lastStats.presented = m_backend.EndFrame(frame.targetDrawList);
|
||||
m_lastStats.flushedDrawListCount = m_backend.GetLastFlushedDrawListCount();
|
||||
m_lastStats.flushedCommandCount = m_backend.GetLastFlushedCommandCount();
|
||||
return m_lastStats.presented;
|
||||
}
|
||||
|
||||
const XCUIHostedPreviewStats& GetLastStats() const override {
|
||||
return m_lastStats;
|
||||
}
|
||||
|
||||
private:
|
||||
ImGuiTransitionBackend m_backend = {};
|
||||
XCUIHostedPreviewStats m_lastStats = {};
|
||||
};
|
||||
|
||||
class QueuedNativeXCUIHostedPreviewPresenter final : public IXCUIHostedPreviewPresenter {
|
||||
public:
|
||||
QueuedNativeXCUIHostedPreviewPresenter(
|
||||
@@ -334,9 +303,7 @@ private:
|
||||
XCUIHostedPreviewStats m_lastStats = {};
|
||||
};
|
||||
|
||||
inline std::unique_ptr<IXCUIHostedPreviewPresenter> CreateImGuiXCUIHostedPreviewPresenter() {
|
||||
return std::make_unique<ImGuiXCUIHostedPreviewPresenter>();
|
||||
}
|
||||
std::unique_ptr<IXCUIHostedPreviewPresenter> CreateImGuiXCUIHostedPreviewPresenter();
|
||||
|
||||
inline std::unique_ptr<IXCUIHostedPreviewPresenter> CreateQueuedNativeXCUIHostedPreviewPresenter(
|
||||
XCUIHostedPreviewQueue& queue,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "XCUIDemoPanel.h"
|
||||
|
||||
#include "XCUIBackend/ImGuiXCUIHostedPreviewPresenter.h"
|
||||
#include "XCUIBackend/ImGuiXCUIInputAdapter.h"
|
||||
|
||||
#include <XCEngine/UI/Types.h>
|
||||
@@ -30,6 +31,16 @@ UI::UIRect ToUIRect(const ImVec2& minPoint, const ImVec2& size) {
|
||||
return UI::UIRect(minPoint.x, minPoint.y, size.x, size.y);
|
||||
}
|
||||
|
||||
ImTextureID ToImTextureId(const UI::UITextureHandle& texture) {
|
||||
return texture.IsValid()
|
||||
? static_cast<ImTextureID>(texture.nativeHandle)
|
||||
: ImTextureID{};
|
||||
}
|
||||
|
||||
ImVec2 ToImVec2(const UI::UIPoint& point) {
|
||||
return ImVec2(point.x, point.y);
|
||||
}
|
||||
|
||||
bool ContainsPoint(const UI::UIRect& rect, const UI::UIPoint& point) {
|
||||
return point.x >= rect.x &&
|
||||
point.y >= rect.y &&
|
||||
@@ -216,7 +227,11 @@ void XCUIDemoPanel::Render() {
|
||||
if (validCanvas) {
|
||||
ImGui::SetCursorScreenPos(canvasMin);
|
||||
if (showHostedSurfaceImage) {
|
||||
ImGui::Image(hostedSurfaceImage.textureId, canvasSize, hostedSurfaceImage.uvMin, hostedSurfaceImage.uvMax);
|
||||
ImGui::Image(
|
||||
ToImTextureId(hostedSurfaceImage.texture),
|
||||
canvasSize,
|
||||
ToImVec2(hostedSurfaceImage.uvMin),
|
||||
ToImVec2(hostedSurfaceImage.uvMax));
|
||||
DrawHostedPreviewFrame(drawList, canvasMin, canvasSize);
|
||||
} else {
|
||||
ImGui::InvisibleButton("##XCUIDemoCanvas", canvasSize);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "XCUILayoutLabPanel.h"
|
||||
|
||||
#include "XCUIBackend/ImGuiXCUIHostedPreviewPresenter.h"
|
||||
#include <XCEngine/UI/Types.h>
|
||||
|
||||
#include <imgui.h>
|
||||
@@ -23,6 +24,16 @@ UI::UIRect ToUIRect(const ImVec2& minPoint, const ImVec2& size) {
|
||||
return UI::UIRect(minPoint.x, minPoint.y, size.x, size.y);
|
||||
}
|
||||
|
||||
ImTextureID ToImTextureId(const UI::UITextureHandle& texture) {
|
||||
return texture.IsValid()
|
||||
? static_cast<ImTextureID>(texture.nativeHandle)
|
||||
: ImTextureID{};
|
||||
}
|
||||
|
||||
ImVec2 ToImVec2(const UI::UIPoint& point) {
|
||||
return ImVec2(point.x, point.y);
|
||||
}
|
||||
|
||||
bool ContainsPoint(const UI::UIRect& rect, const UI::UIPoint& point) {
|
||||
return point.x >= rect.x &&
|
||||
point.y >= rect.y &&
|
||||
@@ -197,7 +208,11 @@ void XCUILayoutLabPanel::Render() {
|
||||
if (validCanvas) {
|
||||
ImGui::SetCursorScreenPos(canvasMin);
|
||||
if (showHostedSurfaceImage) {
|
||||
ImGui::Image(hostedSurfaceImage.textureId, canvasSize, hostedSurfaceImage.uvMin, hostedSurfaceImage.uvMax);
|
||||
ImGui::Image(
|
||||
ToImTextureId(hostedSurfaceImage.texture),
|
||||
canvasSize,
|
||||
ToImVec2(hostedSurfaceImage.uvMin),
|
||||
ToImVec2(hostedSurfaceImage.uvMax));
|
||||
DrawHostedPreviewFrame(drawList, canvasMin, canvasSize);
|
||||
} else {
|
||||
ImGui::InvisibleButton("##XCUILayoutLabCanvas", canvasSize);
|
||||
|
||||
Reference in New Issue
Block a user