/* * 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 #include #include #include #include #include #include #include #include #include "OpenXRVkBehaviorReflection.h" #include namespace OpenXRVk { void SystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { provided.push_back(XR::Factory::GetPlatformService()); provided.push_back(AZ_CRC_CE("VulkanRequirementsService")); } void SystemComponent::Reflect(AZ::ReflectContext* context) { if (auto serializeContext = azrtti_cast(context)) { serializeContext->Class() ->Version(1); } if (auto behaviorContext = azrtti_cast(context)) { OpenXRBehaviorReflect(*behaviorContext); } AzFramework::InputDeviceXRController::Reflect(context); OpenXRInteractionProfilesAsset::Reflect(context); OpenXRActionSetsAsset::Reflect(context); } XR::Ptr SystemComponent::CreateInstance() { return Instance::Create(); } XR::Ptr SystemComponent::CreateDevice() { return Device::Create(); } XR::Ptr SystemComponent::CreateSession() { return Session::Create(); } XR::Ptr SystemComponent::CreateInput() { return Input::Create(); } XR::Ptr SystemComponent::CreateSpace() { return Space::Create(); } XR::Ptr SystemComponent::CreateSwapChain() { return SwapChain::Create(); } XR::Ptr SystemComponent::CreateSwapChainView() { return SwapChain::View::Create(); } XR::Ptr SystemComponent::CreateSwapChainImage() { return SwapChain::Image::Create(); } void SystemComponent::Activate() { m_actionSetsAssetHandler = AZStd::make_unique(); m_actionSetsAssetHandler->Register(); m_interactionProfilesAssetHandler = AZStd::make_unique(); m_interactionProfilesAssetHandler->Register(); if (XR::IsOpenXREnabled()) { m_instance = AZStd::static_pointer_cast(CreateInstance()); //Get the validation mode AZ::RHI::ValidationMode validationMode = AZ::RHI::ValidationMode::Disabled; AZ::RHI::FactoryManagerBus::BroadcastResult(validationMode, &AZ::RHI::FactoryManagerRequest::DetermineValidationMode); if (m_instance->Init(validationMode) == AZ::RHI::ResultCode::Success) { XR::Factory::Register(this); AZ::Interface::Register(m_instance.get()); } else { AZ_Warning("OpenXRVK", false, "OpenXRVK is not supported on this platform"); m_instance = nullptr; } } } void SystemComponent::Deactivate() { if (m_instance) { XR::Factory::Unregister(this); AZ::Interface::Unregister(m_instance.get()); m_instance = nullptr; } m_actionSetsAssetHandler->Unregister(); m_interactionProfilesAssetHandler->Unregister(); } }