c716d812bc
Remove AtomBridgeSystemComponent requirement that the default window context exists before creating the default scene draw interface. DebugDraw gem was crashing because the default scene DebugDisplayRequestBus implementation was not created.
182 lines
7.6 KiB
C++
182 lines
7.6 KiB
C++
/*
|
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
* its licensors.
|
|
*
|
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
* distribution (the "License"). All use of this software is governed by the License,
|
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
*
|
|
*/
|
|
|
|
#include <AtomBridgeSystemComponent.h>
|
|
#include <AtomDebugDisplayViewportInterface.h>
|
|
#include <FlyCameraInputComponent.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::AppearsInAddComponentMenu, AZ_CRC("System", 0xc94d118b))
|
|
->Attribute(Edit::Attributes::AutoExpand, true)
|
|
;
|
|
}
|
|
}
|
|
}
|
|
|
|
AtomBridgeSystemComponent::AtomBridgeSystemComponent()
|
|
{
|
|
}
|
|
|
|
AtomBridgeSystemComponent::~AtomBridgeSystemComponent()
|
|
{
|
|
}
|
|
|
|
void AtomBridgeSystemComponent::GetProvidedServices(ComponentDescriptor::DependencyArrayType& provided)
|
|
{
|
|
provided.push_back(AZ_CRC("AtomBridgeService", 0xdb816a99));
|
|
}
|
|
|
|
void AtomBridgeSystemComponent::GetIncompatibleServices(ComponentDescriptor::DependencyArrayType& incompatible)
|
|
{
|
|
incompatible.push_back(AZ_CRC("AtomBridgeService", 0xdb816a99));
|
|
}
|
|
|
|
void AtomBridgeSystemComponent::GetRequiredServices(ComponentDescriptor::DependencyArrayType& required)
|
|
{
|
|
required.push_back(AZ::RHI::Factory::GetComponentService());
|
|
required.push_back(AZ_CRC("AssetDatabaseService", 0x3abf5601));
|
|
required.push_back(AZ_CRC("RPISystem", 0xf2add773));
|
|
required.push_back(AZ_CRC("BootstrapSystemComponent", 0xb8f32711));
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
void AtomBridgeSystemComponent::Deactivate()
|
|
{
|
|
AZ::RPI::ViewportContextManagerNotificationsBus::Handler::BusDisconnect();
|
|
RPI::Scene* scene = RPI::RPISystemInterface::Get()->GetDefaultScene().get();
|
|
// 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)
|
|
{
|
|
AZ_UNUSED(bootstrapScene);
|
|
// Make default AtomDebugDisplayViewportInterface
|
|
AZStd::shared_ptr<AtomDebugDisplayViewportInterface> mainEntityDebugDisplay = AZStd::make_shared<AtomDebugDisplayViewportInterface>(AzFramework::g_defaultSceneEntityDebugDisplayId);
|
|
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
|