XRSystemComponent.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 <XR/XRSystemComponent.h>
  9. #include <XR/XRUtils.h>
  10. #include <XR/XRFactory.h>
  11. #include <AzCore/Serialization/SerializeContext.h>
  12. #include <Atom/RPI.Public/XR/XRRenderingInterface.h>
  13. #include <Atom/RHI/ValidationLayer.h>
  14. #include <Atom/RHI/FactoryManagerBus.h>
  15. namespace XR
  16. {
  17. void SystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  18. {
  19. provided.push_back(AZ_CRC_CE("XRSystemService"));
  20. }
  21. void SystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  22. {
  23. required.push_back(AZ_CRC_CE("RHIService"));
  24. }
  25. void SystemComponent::Reflect(AZ::ReflectContext* context)
  26. {
  27. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  28. {
  29. serializeContext->Class<SystemComponent, AZ::Component>()->Version(1);
  30. }
  31. }
  32. void SystemComponent::Activate()
  33. {
  34. // Register XR system interface if openxr is enabled via command line or settings registry
  35. if (IsOpenXREnabled())
  36. {
  37. if (!Factory::IsReady())
  38. {
  39. AZ_Error("OpenXR", false, "OpenXR is enabled but no XR implementations are available. Unable to initialize XR system.");
  40. return;
  41. }
  42. //Get the validation mode
  43. AZ::RHI::ValidationMode validationMode = AZ::RHI::ValidationMode::Disabled;
  44. AZ::RHI::FactoryManagerBus::BroadcastResult(validationMode, &AZ::RHI::FactoryManagerRequest::DetermineValidationMode);
  45. //Init the XRSystem
  46. System::Descriptor descriptor;
  47. descriptor.m_validationMode = validationMode;
  48. m_xrSystem = aznew System();
  49. m_xrSystem->Init(descriptor);
  50. //Register xr system with RPI
  51. AZ::RPI::XRRegisterInterface::Get()->RegisterXRInterface(m_xrSystem.get());
  52. }
  53. }
  54. void SystemComponent::Deactivate()
  55. {
  56. if (m_xrSystem)
  57. {
  58. m_xrSystem->Shutdown();
  59. m_xrSystem.reset();
  60. }
  61. }
  62. }