From 85e4f0d65ff5d5b7b6e1ba9759cace1907f60634 Mon Sep 17 00:00:00 2001 From: rgba16f <82187279+rgba16f@users.noreply.github.com> Date: Tue, 11 May 2021 16:24:28 -0500 Subject: [PATCH] Fix AzFramework::g_defaultSceneEntityDebugDisplayId not working for the AtomDebugDisplayViewportInstance --- Code/Sandbox/Editor/EditorViewportWidget.cpp | 9 +++++ .../Code/Source/AtomBridgeSystemComponent.cpp | 38 +++++++------------ 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/Code/Sandbox/Editor/EditorViewportWidget.cpp b/Code/Sandbox/Editor/EditorViewportWidget.cpp index 3803867870..631a93af92 100644 --- a/Code/Sandbox/Editor/EditorViewportWidget.cpp +++ b/Code/Sandbox/Editor/EditorViewportWidget.cpp @@ -452,6 +452,15 @@ void EditorViewportWidget::Update() return; } + static bool sentOnWindowCreated = false; + if (!sentOnWindowCreated && windowHandle()->isActive()) + { + sentOnWindowCreated = true; + AzFramework::WindowSystemNotificationBus::Broadcast( + &AzFramework::WindowSystemNotificationBus::Handler::OnWindowCreated, + reinterpret_cast(winId())); + } + m_updatingCameraPosition = true; auto transform = LYTransformToAZTransform(m_Camera.GetMatrix()); m_renderViewport->GetViewportContext()->SetCameraTransform(transform); diff --git a/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomBridgeSystemComponent.cpp b/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomBridgeSystemComponent.cpp index 90731488f4..9148cdba6f 100644 --- a/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomBridgeSystemComponent.cpp +++ b/Gems/AtomLyIntegration/AtomBridge/Code/Source/AtomBridgeSystemComponent.cpp @@ -91,13 +91,9 @@ namespace AZ AZ_UNUSED(dependent); } - static const AZ::Crc32 mainViewportEntityDebugDisplayId = AZ_CRC_CE("MainViewportEntityDebugDisplayId"); - void AtomBridgeSystemComponent::Init() { -#if defined(ENABLE_ATOM_DEBUG_DISPLAY) && ENABLE_ATOM_DEBUG_DISPLAY AZ::RPI::ViewportContextManagerNotificationsBus::Handler::BusConnect(); -#endif } void AtomBridgeSystemComponent::Activate() @@ -112,9 +108,7 @@ namespace AZ void AtomBridgeSystemComponent::Deactivate() { -#if defined(ENABLE_ATOM_DEBUG_DISPLAY) && ENABLE_ATOM_DEBUG_DISPLAY AZ::RPI::ViewportContextManagerNotificationsBus::Handler::BusDisconnect(); -#endif RPI::Scene* scene = RPI::RPISystemInterface::Get()->GetDefaultScene().get(); // Check if scene is emptry since scene might be released already when running AtomSampleViewer if (scene) @@ -193,36 +187,32 @@ namespace AZ renderPipeline = bootstrapScene->GetDefaultRenderPipeline(); renderPipeline->SetDefaultView(m_view); - - auto auxGeomFP = bootstrapScene->GetFeatureProcessor(); - if (auxGeomFP) - { - auxGeomFP->GetOrCreateDrawQueueForView(m_view.get()); - } - -#if defined(ENABLE_ATOM_DEBUG_DISPLAY) && ENABLE_ATOM_DEBUG_DISPLAY - // Make default AtomDebugDisplayViewportInterface for the scene - AZStd::shared_ptr mainEntityDebugDisplay = AZStd::make_shared(mainViewportEntityDebugDisplayId); - m_activeViewportsList[mainViewportEntityDebugDisplayId] = mainEntityDebugDisplay; -#endif } + else + { + m_view = renderPipeline->GetDefaultView(); + } + auto auxGeomFP = bootstrapScene->GetFeatureProcessor(); + if (auxGeomFP) + { + auxGeomFP->GetOrCreateDrawQueueForView(m_view.get()); + } + + // Make default AtomDebugDisplayViewportInterface for the scene + AZStd::shared_ptr mainEntityDebugDisplay = AZStd::make_shared(AzFramework::g_defaultSceneEntityDebugDisplayId); + m_activeViewportsList[AzFramework::g_defaultSceneEntityDebugDisplayId] = mainEntityDebugDisplay; } void AtomBridgeSystemComponent::OnViewportContextAdded(AZ::RPI::ViewportContextPtr viewportContext) { -#if defined(ENABLE_ATOM_DEBUG_DISPLAY) && ENABLE_ATOM_DEBUG_DISPLAY AZStd::shared_ptr viewportDebugDisplay = AZStd::make_shared(viewportContext); m_activeViewportsList[viewportContext->GetId()] = viewportDebugDisplay; -#endif } void AtomBridgeSystemComponent::OnViewportContextRemoved(AzFramework::ViewportId viewportId) { -#if defined(ENABLE_ATOM_DEBUG_DISPLAY) && ENABLE_ATOM_DEBUG_DISPLAY + AZ_Assert(viewportId != AzFramework::g_defaultSceneEntityDebugDisplayId, "Error trying to remove the default scene draw instance"); m_activeViewportsList.erase(viewportId); -#else - AZ_UNUSED(viewportId); -#endif }