3
0

PreviewRendererSystemComponent.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/Serialization/EditContext.h>
  9. #include <AzCore/Serialization/EditContextConstants.inl>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. #include <PreviewRenderer/PreviewRendererSystemComponent.h>
  12. #include <Atom/RPI.Public/RPISystemInterface.h>
  13. namespace AtomToolsFramework
  14. {
  15. void PreviewRendererSystemComponent::Reflect(AZ::ReflectContext* context)
  16. {
  17. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  18. {
  19. serialize->Class<PreviewRendererSystemComponent, AZ::Component>()
  20. ->Version(0);
  21. if (AZ::EditContext* ec = serialize->GetEditContext())
  22. {
  23. ec->Class<PreviewRendererSystemComponent>("PreviewRendererSystemComponent", "System component that manages a global PreviewRenderer.")
  24. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  25. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  26. ;
  27. }
  28. }
  29. }
  30. void PreviewRendererSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  31. {
  32. provided.push_back(AZ_CRC_CE("PreviewRendererSystem"));
  33. }
  34. void PreviewRendererSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  35. {
  36. dependent.push_back(AZ_CRC_CE("RPISystem"));
  37. }
  38. void PreviewRendererSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  39. {
  40. incompatible.push_back(AZ_CRC_CE("PreviewRendererSystem"));
  41. }
  42. void PreviewRendererSystemComponent::Init()
  43. {
  44. }
  45. void PreviewRendererSystemComponent::Activate()
  46. {
  47. AZ::SystemTickBus::Handler::BusConnect();
  48. AzFramework::ApplicationLifecycleEvents::Bus::Handler::BusConnect();
  49. PreviewRendererSystemRequestBus::Handler::BusConnect();
  50. }
  51. void PreviewRendererSystemComponent::Deactivate()
  52. {
  53. PreviewRendererSystemRequestBus::Handler::BusDisconnect();
  54. AzFramework::ApplicationLifecycleEvents::Bus::Handler::BusDisconnect();
  55. AZ::SystemTickBus::Handler::BusDisconnect();
  56. m_previewRenderer.reset();
  57. }
  58. void PreviewRendererSystemComponent::OnApplicationAboutToStop()
  59. {
  60. m_previewRenderer.reset();
  61. }
  62. void PreviewRendererSystemComponent::OnSystemTick()
  63. {
  64. // Do not create the preview reader until the RPI has been initialized
  65. if (AZ::RPI::RPISystemInterface::Get() && AZ::RPI::RPISystemInterface::Get()->IsInitialized())
  66. {
  67. if (!m_previewRenderer)
  68. {
  69. m_previewRenderer.reset(aznew AtomToolsFramework::PreviewRenderer(
  70. "PreviewRendererSystemComponent Preview Scene", "PreviewRendererSystemComponent Preview Pipeline"));
  71. }
  72. AZ::SystemTickBus::Handler::BusDisconnect();
  73. }
  74. }
  75. } // namespace AtomToolsFramework