XRSession.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/XRSession.h>
  9. #include <XR/XRFactory.h>
  10. #include <XR/XRDevice.h>
  11. #include <XR/XRInput.h>
  12. namespace XR
  13. {
  14. AZ::RHI::ResultCode Session::Init(const Descriptor& descriptor)
  15. {
  16. AZ::RHI::ResultCode result = AZ::RHI::ResultCode::Fail;
  17. m_descriptor = descriptor;
  18. m_space = Factory::Get().CreateSpace();
  19. AZ_Error("XR", m_space, "XR Space was not created");
  20. if (m_space)
  21. {
  22. result = m_space->Init(Space::Descriptor{ m_descriptor.m_validationMode});
  23. AZ_Error("XR", result == AZ::RHI::ResultCode::Success, "XR Space was not initialized");
  24. RETURN_RESULTCODE_IF_UNSUCCESSFUL(result);
  25. }
  26. m_input = Factory::Get().CreateInput();
  27. AZ_Error("XR", m_input, "XR Input was not created");
  28. if (m_input)
  29. {
  30. result = m_input->Init(Input::Descriptor{ m_descriptor.m_instance, m_descriptor.m_device, this });
  31. AZ_Error("XR", result == AZ::RHI::ResultCode::Success, "XR Input was not initialized");
  32. RETURN_RESULTCODE_IF_UNSUCCESSFUL(result);
  33. }
  34. m_descriptor.m_device->RegisterSession(this);
  35. return AZ::RHI::ResultCode::Success;
  36. }
  37. const Session::Descriptor& Session::GetDescriptor() const
  38. {
  39. return m_descriptor;
  40. }
  41. void Session::Shutdown()
  42. {
  43. m_descriptor.m_device->UnRegisterSession();
  44. ShutdownInternal();
  45. }
  46. Input* Session::GetInput() const
  47. {
  48. return m_input.get();
  49. }
  50. Space* Session::GetSpace() const
  51. {
  52. return m_space.get();
  53. }
  54. } // namespace XR