Split XCUI hosted preview ImGui presenter seam
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user