| 1 | // SPDX-License-Identifier: LGPL-2.1-only |
| 2 | // Copyright (C) 2021 James Hogan <[email protected]> |
| 3 | |
| 4 | #include "System.h" |
| 5 | |
| 6 | #include <cstring> |
| 7 | |
| 8 | using namespace osgXR::OpenXR; |
| 9 | |
| 10 | void System::getProperties() const |
| 11 | { |
| 12 | XrSystemProperties properties; |
| 13 | properties.type = XR_TYPE_SYSTEM_PROPERTIES; |
| 14 | properties.next = nullptr; |
| 15 | |
| 16 | if (check(xrGetSystemProperties(getXrInstance(), _systemId, &properties), |
| 17 | "get OpenXR system properties")) |
| 18 | { |
| 19 | memcpy(_systemName, properties.systemName, sizeof(_systemName)); |
| 20 | _orientationTracking = properties.trackingProperties.orientationTracking; |
| 21 | _positionTracking = properties.trackingProperties.positionTracking; |
| 22 | } |
| 23 | |
| 24 | _readProperties = true; |
| 25 | } |
| 26 | |
| 27 | const System::ViewConfiguration::Views &System::ViewConfiguration::getViews() const |
| 28 | { |
| 29 | if (!_readViews) |
| 30 | { |
| 31 | uint32_t viewCount = 0; |
| 32 | if (check(xrEnumerateViewConfigurationViews(_system->getXrInstance(), |
| 33 | _system->getXrSystemId(), |
| 34 | _type, |
| 35 | 0, &viewCount, nullptr), |
| 36 | "count OpenXR view configuration views")) |
| 37 | { |
| 38 | if (viewCount) |
| 39 | { |
| 40 | std::vector<XrViewConfigurationView> views(viewCount, |
| 41 | { XR_TYPE_VIEW_CONFIGURATION_VIEW }); |
| 42 | if (check(xrEnumerateViewConfigurationViews(_system->getXrInstance(), |
| 43 | _system->getXrSystemId(), |
| 44 | _type, |
| 45 | views.size(), &viewCount, |
| 46 | views.data()), |
| 47 | "enumerate OpenXR view configuration views")) |
| 48 | { |
| 49 | for (auto &view: views) |
| 50 | _views.push_back(View(view)); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | _readViews = true; |
| 56 | } |
| 57 | |
| 58 | return _views; |
| 59 | } |
| 60 | |
| 61 | const System::ViewConfiguration::EnvBlendModes &System::ViewConfiguration::getEnvBlendModes() const |
| 62 | { |
| 63 | if (!_readEnvBlendModes) |
| 64 | { |
| 65 | uint32_t blendModeCount = 0; |
| 66 | if (check(xrEnumerateEnvironmentBlendModes(_system->getXrInstance(), |
| 67 | _system->getXrSystemId(), |
| 68 | _type, |
| 69 | 0, &blendModeCount, nullptr), |
| 70 | "count OpenXR environment blend modes")) |
| 71 | { |
| 72 | if (blendModeCount) |
| 73 | { |
| 74 | _envBlendModes.resize(blendModeCount); |
| 75 | if (!check(xrEnumerateEnvironmentBlendModes(_system->getXrInstance(), |
| 76 | _system->getXrSystemId(), |
| 77 | _type, |
| 78 | _envBlendModes.size(), |
| 79 | &blendModeCount, |
| 80 | _envBlendModes.data()), |
| 81 | "enumerate OpenXR environment blend modes")) |
| 82 | { |
| 83 | _envBlendModes.resize(0); |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | _readEnvBlendModes = true; |
| 89 | } |
| 90 | |
| 91 | return _envBlendModes; |
| 92 | } |
| 93 | |
| 94 | const System::ViewConfigurations &System::getViewConfigurations() const |
| 95 | { |
| 96 | if (!_readViewConfigurations) |
| 97 | { |
| 98 | uint32_t viewConfigCount = 0; |
| 99 | if (check(xrEnumerateViewConfigurations(getXrInstance(), getXrSystemId(), |
| 100 | 0, &viewConfigCount, nullptr), |
| 101 | "count OpenXR view configuration types")) |
| 102 | { |
| 103 | if (viewConfigCount) |
| 104 | { |
| 105 | std::vector<XrViewConfigurationType> types(viewConfigCount); |
| 106 | if (check(xrEnumerateViewConfigurations(getXrInstance(), getXrSystemId(), |
| 107 | types.size(), &viewConfigCount, |
| 108 | types.data()), |
| 109 | "enumerate OpenXR view configuration types")) |
| 110 | { |
| 111 | _viewConfigurations.reserve(viewConfigCount); |
| 112 | for (auto type: types) |
| 113 | _viewConfigurations.push_back(ViewConfiguration(this, type)); |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | _readViewConfigurations = true; |
| 119 | } |
| 120 | |
| 121 | return _viewConfigurations; |
| 122 | } |