123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include <AtomBridgeSystemComponent.h>
- #include <AtomDebugDisplayViewportInterface.h>
- #include <FlyCameraInputComponent.h>
- #include <PerViewportDynamicDrawManager.h>
- #include <AzCore/Serialization/SerializeContext.h>
- #include <AzCore/Serialization/EditContext.h>
- #include <AzCore/Serialization/EditContextConstants.inl>
- #include <AzCore/Component/TransformBus.h>
- #include <AzCore/Interface/Interface.h>
- #include <AzFramework/API/ApplicationAPI.h>
- #include <AzFramework/Entity/GameEntityContextBus.h>
- #include <AzCore/Math/MatrixUtils.h>
- #include <Atom/RHI/Factory.h>
- #include <Atom/RPI.Public/RPISystemInterface.h>
- #include <Atom/RPI.Public/View.h>
- #include <Atom/RPI.Public/Scene.h>
- #include <Atom/RPI.Public/RenderPipeline.h>
- #include <Atom/RPI.Public/ViewportContextBus.h>
- #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
- #include <Atom/RPI.Public/AuxGeom/AuxGeomFeatureProcessorInterface.h>
- #include <Atom/Bootstrap/DefaultWindowBus.h>
- namespace AZ
- {
- namespace AtomBridge
- {
- void AtomBridgeSystemComponent::Reflect(ReflectContext* context)
- {
- if (SerializeContext* serialize = azrtti_cast<SerializeContext*>(context))
- {
- serialize->Class<AtomBridgeSystemComponent, Component>()
- ->Version(0)
- ;
- if (EditContext* ec = serialize->GetEditContext())
- {
- ec->Class<AtomBridgeSystemComponent>("AtomBridge", "[Description of functionality provided by this System Component]")
- ->ClassElement(Edit::ClassElements::EditorData, "")
- ->Attribute(Edit::Attributes::AutoExpand, true)
- ;
- }
- }
- }
- AtomBridgeSystemComponent::AtomBridgeSystemComponent()
- {
- }
- AtomBridgeSystemComponent::~AtomBridgeSystemComponent()
- {
- }
- void AtomBridgeSystemComponent::GetProvidedServices(ComponentDescriptor::DependencyArrayType& provided)
- {
- provided.push_back(AZ_CRC_CE("AtomBridgeService"));
- }
- void AtomBridgeSystemComponent::GetIncompatibleServices(ComponentDescriptor::DependencyArrayType& incompatible)
- {
- incompatible.push_back(AZ_CRC_CE("AtomBridgeService"));
- }
- void AtomBridgeSystemComponent::GetRequiredServices(ComponentDescriptor::DependencyArrayType& required)
- {
- required.push_back(AZ::RHI::Factory::GetComponentService());
- required.push_back(AZ_CRC_CE("AssetDatabaseService"));
- required.push_back(AZ_CRC_CE("RPISystem"));
- required.push_back(AZ_CRC_CE("BootstrapSystemComponent"));
- }
- void AtomBridgeSystemComponent::GetDependentServices(ComponentDescriptor::DependencyArrayType& dependent)
- {
- AZ_UNUSED(dependent);
- }
- void AtomBridgeSystemComponent::Init()
- {
- AZ::RPI::ViewportContextManagerNotificationsBus::Handler::BusConnect();
- }
- void AtomBridgeSystemComponent::Activate()
- {
- AzFramework::Render::RenderSystemRequestBus::Handler::BusConnect();
- AtomBridgeRequestBus::Handler::BusConnect();
- AzFramework::Components::DeprecatedComponentsRequestBus::Handler::BusConnect();
- AzFramework::GameEntityContextRequestBus::BroadcastResult(m_entityContextId, &AzFramework::GameEntityContextRequestBus::Events::GetGameEntityContextId);
- AZ::Render::Bootstrap::NotificationBus::Handler::BusConnect();
- m_dynamicDrawManager = AZStd::make_unique<PerViewportDynamicDrawManager>();
- }
- void AtomBridgeSystemComponent::Deactivate()
- {
- m_dynamicDrawManager.reset();
- AZ::RPI::ViewportContextManagerNotificationsBus::Handler::BusDisconnect();
- RPI::Scene* scene = AZ::RPI::Scene::GetSceneForEntityContextId(m_entityContextId);
- // Check if scene is emptry since scene might be released already when running AtomSampleViewer
- if (scene)
- {
- auto auxGeomFP = scene->GetFeatureProcessor<RPI::AuxGeomFeatureProcessorInterface>();
- if (auxGeomFP)
- {
- auxGeomFP->ReleaseDrawQueueForView(m_view.get());
- }
- }
- // Don't want to leave this until our destructor because the AZ::Data::InstanceDatabase may not be valid at that point
- m_view = nullptr;
- AZ::Render::Bootstrap::NotificationBus::Handler::BusDisconnect();
- AzFramework::Components::DeprecatedComponentsRequestBus::Handler::BusDisconnect();
- AtomBridgeRequestBus::Handler::BusDisconnect();
- AzFramework::Render::RenderSystemRequestBus::Handler::BusDisconnect();
- }
- AZStd::string AtomBridgeSystemComponent::GetRendererName() const
- {
- return "Other";
- }
- void AtomBridgeSystemComponent::EnumerateDeprecatedComponents(AzFramework::Components::DeprecatedComponentsList& list) const
- {
- static const AZ::Uuid legacyRenderComponentUuids[] = {
- AZ::Uuid("{FC315B86-3280-4D03-B4F0-5553D7D08432}"), // EditorMeshComponent
- };
- const AZStd::string deprecatedString = " (DEPRECATED By Atom)";
- for (const AZ::Uuid& componentUuid : legacyRenderComponentUuids)
- {
- auto deprecatedEntry = list.find(componentUuid);
- if (deprecatedEntry == list.end())
- {
- list[componentUuid] = AzFramework::Components::DeprecatedInfo{ true, deprecatedString };
- }
- else
- {
- deprecatedEntry->second.m_hideComponent = true;
- deprecatedEntry->second.m_deprecationString += deprecatedString;
- }
- }
- }
- void AtomBridgeSystemComponent::OnBootstrapSceneReady(AZ::RPI::Scene* bootstrapScene)
- {
- // If the pointer is not reset before being assigned, the destructor of the old instance of AtomDebugDisplayViewportInterface
- // would disconnect from DebugDisplayRequestBus immediately after the new instance was connected, since they both use the same
- // id.
- if (auto it = m_activeViewportsList.find(AzFramework::g_defaultSceneEntityDebugDisplayId); it != m_activeViewportsList.end())
- {
- it->second.reset();
- }
- // Make default AtomDebugDisplayViewportInterface
- AZStd::shared_ptr<AtomDebugDisplayViewportInterface> mainEntityDebugDisplay =
- AZStd::make_shared<AtomDebugDisplayViewportInterface>(AzFramework::g_defaultSceneEntityDebugDisplayId, bootstrapScene);
- m_activeViewportsList[AzFramework::g_defaultSceneEntityDebugDisplayId] = mainEntityDebugDisplay;
- }
- void AtomBridgeSystemComponent::OnViewportContextAdded(AZ::RPI::ViewportContextPtr viewportContext)
- {
- AZStd::shared_ptr<AtomDebugDisplayViewportInterface> viewportDebugDisplay = AZStd::make_shared<AtomDebugDisplayViewportInterface>(viewportContext);
- m_activeViewportsList[viewportContext->GetId()] = viewportDebugDisplay;
- }
- void AtomBridgeSystemComponent::OnViewportContextRemoved(AzFramework::ViewportId viewportId)
- {
- AZ_Assert(viewportId != AzFramework::g_defaultSceneEntityDebugDisplayId, "Error trying to remove the default scene draw instance");
- m_activeViewportsList.erase(viewportId);
- }
- } // namespace AtomBridge
- } // namespace AZ
|