Files
XCEngine/new_editor/app/Rendering/Viewport/ViewportHostServiceLifecycle.cpp

72 lines
2.1 KiB
C++

#include "ViewportHostService.h"
namespace XCEngine::UI::Editor::App {
void ViewportHostService::AttachWindowRenderer(
Host::D3D12WindowRenderer& windowRenderer) {
if (m_windowRenderer == &windowRenderer) {
m_device = windowRenderer.GetRHIDevice();
if (m_device != nullptr && !m_textureDescriptorAllocator.IsInitialized()) {
m_textureDescriptorAllocator.Initialize(*m_device);
}
return;
}
Shutdown();
m_windowRenderer = &windowRenderer;
m_device = windowRenderer.GetRHIDevice();
if (m_device != nullptr) {
m_textureDescriptorAllocator.Initialize(*m_device);
}
}
void ViewportHostService::DetachWindowRenderer() {
Shutdown();
}
void ViewportHostService::SetSurfacePresentationEnabled(bool enabled) {
m_surfacePresentationEnabled = enabled;
}
void ViewportHostService::Shutdown() {
for (ViewportEntry& entry : m_entries) {
DestroyViewportEntry(entry);
}
m_textureDescriptorAllocator.Shutdown();
m_windowRenderer = nullptr;
m_device = nullptr;
m_surfacePresentationEnabled = false;
}
void ViewportHostService::BeginFrame() {
for (ViewportEntry& entry : m_entries) {
entry.requestedWidth = 0;
entry.requestedHeight = 0;
entry.requestedThisFrame = false;
entry.renderedThisFrame = false;
entry.kind = (&entry == &m_entries[0]) ? ViewportKind::Scene : ViewportKind::Game;
}
}
ViewportHostService::ViewportEntry& ViewportHostService::GetEntry(
ViewportKind kind) {
const std::size_t index = kind == ViewportKind::Scene ? 0u : 1u;
ViewportEntry& entry = m_entries[index];
entry.kind = kind;
return entry;
}
const ViewportHostService::ViewportEntry& ViewportHostService::GetEntry(
ViewportKind kind) const {
const std::size_t index = kind == ViewportKind::Scene ? 0u : 1u;
return m_entries[index];
}
void ViewportHostService::DestroyViewportEntry(ViewportEntry& entry) {
m_renderTargetManager.DestroyTargets(&m_textureDescriptorAllocator, entry.renderTargets);
entry = {};
}
} // namespace XCEngine::UI::Editor::App