OpenXRVkSystemComponent.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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/SerializeContext.h>
  9. #include <Atom/RHI/FactoryManagerBus.h>
  10. #include <OpenXRVk/OpenXRVkDevice.h>
  11. #include <OpenXRVk/OpenXRVkInput.h>
  12. #include <OpenXRVk/OpenXRVkInstance.h>
  13. #include <OpenXRVk/OpenXRVkSession.h>
  14. #include <OpenXRVk/OpenXRVkSpace.h>
  15. #include <OpenXRVk/OpenXRVkSwapChain.h>
  16. #include <OpenXRVk/OpenXRVkSystemComponent.h>
  17. #include <XR/XRUtils.h>
  18. namespace OpenXRVk
  19. {
  20. void SystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  21. {
  22. provided.push_back(XR::Factory::GetPlatformService());
  23. provided.push_back(AZ_CRC_CE("VulkanRequirementsService"));
  24. }
  25. void SystemComponent::Reflect(AZ::ReflectContext* context)
  26. {
  27. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  28. {
  29. serializeContext->Class<SystemComponent, AZ::Component>()
  30. ->Version(1);
  31. }
  32. AzFramework::InputDeviceXRController::Reflect(context);
  33. }
  34. XR::Ptr<XR::Instance> SystemComponent::CreateInstance()
  35. {
  36. return Instance::Create();
  37. }
  38. XR::Ptr<XR::Device> SystemComponent::CreateDevice()
  39. {
  40. return Device::Create();
  41. }
  42. XR::Ptr<XR::Session> SystemComponent::CreateSession()
  43. {
  44. return Session::Create();
  45. }
  46. XR::Ptr<XR::Input> SystemComponent::CreateInput()
  47. {
  48. return Input::Create();
  49. }
  50. XR::Ptr<XR::Space> SystemComponent::CreateSpace()
  51. {
  52. return Space::Create();
  53. }
  54. XR::Ptr<XR::SwapChain> SystemComponent::CreateSwapChain()
  55. {
  56. return SwapChain::Create();
  57. }
  58. XR::Ptr<XR::SwapChain::View> SystemComponent::CreateSwapChainView()
  59. {
  60. return SwapChain::View::Create();
  61. }
  62. XR::Ptr<XR::SwapChain::Image> SystemComponent::CreateSwapChainImage()
  63. {
  64. return SwapChain::Image::Create();
  65. }
  66. void SystemComponent::Activate()
  67. {
  68. if (XR::IsOpenXREnabled())
  69. {
  70. m_instance = AZStd::static_pointer_cast<OpenXRVk::Instance>(CreateInstance());
  71. //Get the validation mode
  72. AZ::RHI::ValidationMode validationMode = AZ::RHI::ValidationMode::Disabled;
  73. AZ::RHI::FactoryManagerBus::BroadcastResult(validationMode, &AZ::RHI::FactoryManagerRequest::DetermineValidationMode);
  74. if (m_instance->Init(validationMode) == AZ::RHI::ResultCode::Success)
  75. {
  76. XR::Factory::Register(this);
  77. AZ::Interface<XR::Instance>::Register(m_instance.get());
  78. }
  79. else
  80. {
  81. AZ_Warning("OpenXRVK", false, "OpenXRVK is not supported on this platform");
  82. m_instance = nullptr;
  83. }
  84. }
  85. }
  86. void SystemComponent::Deactivate()
  87. {
  88. if (m_instance)
  89. {
  90. XR::Factory::Unregister(this);
  91. AZ::Interface<XR::Instance>::Unregister(m_instance.get());
  92. m_instance = nullptr;
  93. }
  94. }
  95. }