diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/ViewportContext.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/ViewportContext.h index 24922fbe98..d3d3155715 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/ViewportContext.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/ViewportContext.h @@ -77,6 +77,8 @@ namespace AZ void OnRenderPipelineAdded(RenderPipelinePtr pipeline) override; //! Ensures our default view remains set when our scene's render pipelines are modified. void OnRenderPipelineRemoved(RenderPipeline* pipeline) override; + //! OnBeginPrepareRender is forwarded to our RenderTick notification to allow subscribers to do rendering. + void OnBeginPrepareRender() override; //WindowNotificationBus interface //! Used to fire a notification when our window resizes diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/ViewportContext.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/ViewportContext.cpp index b67ead9896..c9386b1fc0 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/ViewportContext.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/ViewportContext.cpp @@ -104,12 +104,16 @@ namespace AZ // add the current pipeline to next render tick if it's not already added. if (m_currentPipeline && m_currentPipeline->GetRenderMode() != RenderPipeline::RenderMode::RenderOnce) { - ViewportContextNotificationBus::Event(GetName(), &ViewportContextNotificationBus::Events::OnRenderTick); - ViewportContextIdNotificationBus::Event(GetId(), &ViewportContextIdNotificationBus::Events::OnRenderTick); m_currentPipeline->AddToRenderTickOnce(); } } + void ViewportContext::OnBeginPrepareRender() + { + ViewportContextNotificationBus::Event(GetName(), &ViewportContextNotificationBus::Events::OnRenderTick); + ViewportContextIdNotificationBus::Event(GetId(), &ViewportContextIdNotificationBus::Events::OnRenderTick); + } + AZ::Name ViewportContext::GetName() const { return m_name; diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/ViewportContextManager.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/ViewportContextManager.cpp index 8d578352d8..2b525df4d4 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/ViewportContextManager.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/ViewportContextManager.cpp @@ -57,9 +57,14 @@ namespace AZ return; } viewportData.context = viewportContext; - auto onSizeChanged = [contextName, viewportId](AzFramework::WindowSize size) + auto onSizeChanged = [this, viewportId](AzFramework::WindowSize size) { - ViewportContextNotificationBus::Event(contextName, &ViewportContextNotificationBus::Events::OnViewportSizeChanged, size); + // Ensure we emit OnViewportSizeChanged with the correct name. + auto viewportContext = this->GetViewportContextById(viewportId); + if (viewportContext) + { + ViewportContextNotificationBus::Event(viewportContext->GetName(), &ViewportContextNotificationBus::Events::OnViewportSizeChanged, size); + } ViewportContextIdNotificationBus::Event(viewportId, &ViewportContextIdNotificationBus::Events::OnViewportSizeChanged, size); }; viewportContext->m_name = contextName; @@ -174,6 +179,8 @@ namespace AZ GetOrCreateViewStackForContext(newContextName); viewportContext->m_name = newContextName; UpdateViewForContext(newContextName); + // Ensure anyone listening on per-name viewport size updates gets notified. + ViewportContextNotificationBus::Event(newContextName, &ViewportContextNotificationBus::Events::OnViewportSizeChanged, viewportContext->GetViewportSize()); } void ViewportContextManager::EnumerateViewportContexts(AZStd::function visitorFunction) diff --git a/Gems/AtomLyIntegration/ImguiAtom/Code/Source/ImguiAtomSystemComponent.cpp b/Gems/AtomLyIntegration/ImguiAtom/Code/Source/ImguiAtomSystemComponent.cpp index 3f25228406..2ae62023c7 100644 --- a/Gems/AtomLyIntegration/ImguiAtom/Code/Source/ImguiAtomSystemComponent.cpp +++ b/Gems/AtomLyIntegration/ImguiAtom/Code/Source/ImguiAtomSystemComponent.cpp @@ -58,6 +58,15 @@ namespace AZ auto atomViewportRequests = AZ::Interface::Get(); const AZ::Name contextName = atomViewportRequests->GetDefaultViewportContextName(); AZ::RPI::ViewportContextNotificationBus::Handler::BusConnect(contextName); + +#if defined(IMGUI_ENABLED) + ImGui::ImGuiManagerListenerBus::Broadcast(&ImGui::IImGuiManagerListener::SetResolutionMode, ImGui::ImGuiResolutionMode::LockToResolution); + auto defaultViewportContext = atomViewportRequests->GetDefaultViewportContext(); + if (defaultViewportContext) + { + OnViewportSizeChanged(defaultViewportContext->GetViewportSize()); + } +#endif } void ImguiAtomSystemComponent::Deactivate() @@ -75,6 +84,13 @@ namespace AZ { #if defined(IMGUI_ENABLED) ImGui::ImGuiManagerListenerBus::Broadcast(&ImGui::IImGuiManagerListener::Render); +#endif + } + + void ImguiAtomSystemComponent::OnViewportSizeChanged(AzFramework::WindowSize size) + { +#if defined(IMGUI_ENABLED) + ImGui::ImGuiManagerListenerBus::Broadcast(&ImGui::IImGuiManagerListener::SetImGuiRenderResolution, ImVec2{aznumeric_cast(size.m_width), aznumeric_cast(size.m_height)}); #endif } } diff --git a/Gems/AtomLyIntegration/ImguiAtom/Code/Source/ImguiAtomSystemComponent.h b/Gems/AtomLyIntegration/ImguiAtom/Code/Source/ImguiAtomSystemComponent.h index a554ab0339..d3bdb7c4fc 100644 --- a/Gems/AtomLyIntegration/ImguiAtom/Code/Source/ImguiAtomSystemComponent.h +++ b/Gems/AtomLyIntegration/ImguiAtom/Code/Source/ImguiAtomSystemComponent.h @@ -54,6 +54,7 @@ namespace AZ // ViewportContextNotificationBus overrides... void OnRenderTick() override; + void OnViewportSizeChanged(AzFramework::WindowSize size) override; DebugConsole m_debugConsole; };