@@ -8,44 +8,13 @@ namespace xr
88 struct XrSupportedExtensions : ExtensionDispatchTable
99 {
1010 XrSupportedExtensions ()
11- : Names {}
11+ : m_names {}
1212 {
13- uint32_t extensionCount{};
14- XrResult result{ xrEnumerateInstanceExtensionProperties (nullptr , 0 , &extensionCount, nullptr ) };
15- if (result != XR_SUCCESS)
16- {
17- // Avoid failing if device doesn't support OpenXR
18- return ;
19- }
20-
21- m_extensionProperties.resize (extensionCount, { XR_TYPE_EXTENSION_PROPERTIES });
22- XrCheck (xrEnumerateInstanceExtensionProperties (nullptr , extensionCount, &extensionCount, m_extensionProperties.data ()));
23-
24- // D3D11 extension is required, so check if it's supported.
25- for (const char * extensionName : REQUIRED_EXTENSIONS)
26- {
27- if (!TryEnableExtension (extensionName))
28- {
29- throw std::runtime_error{ " Required extension not supported" };
30- }
31- }
32-
33- // Additional optional extensions for enhanced functionality. Track whether enabled in m_optionalExtensions.
34- DepthExtensionSupported = TryEnableExtension (XR_KHR_COMPOSITION_LAYER_DEPTH_EXTENSION_NAME);
35- UnboundedRefSpaceSupported = TryEnableExtension (XR_MSFT_UNBOUNDED_REFERENCE_SPACE_EXTENSION_NAME);
36- SpatialAnchorSupported = TryEnableExtension (XR_MSFT_SPATIAL_ANCHOR_EXTENSION_NAME);
37- SpatialAnchorInteropSupported = TryEnableExtension (XR_MSFT_PERCEPTION_ANCHOR_INTEROP_EXTENSION_NAME);
38- SecondaryViewConfigurationSupported = TryEnableExtension (XR_MSFT_SECONDARY_VIEW_CONFIGURATION_EXTENSION_NAME);
39- FirstPersonObserverSupported = TryEnableExtension (XR_MSFT_FIRST_PERSON_OBSERVER_EXTENSION_NAME);
40- HandInteractionSupported = TryEnableExtension (XR_MSFT_HAND_INTERACTION_EXTENSION_NAME);
41- HandTrackingSupported = TryEnableExtension (XR_EXT_HAND_TRACKING_EXTENSION_NAME);
42- SceneUnderstandingSupported = TryEnableExtension (XR_MSFT_SCENE_UNDERSTANDING_EXTENSION_NAME);
43- SceneUnderstandingSerializationSupported = TryEnableExtension (XR_MSFT_SCENE_UNDERSTANDING_SERIALIZATION_EXTENSION_NAME);
44- EyeTrackingSupported = TryEnableExtension (XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME);
4513 }
4614
4715 bool TryEnableExtension (const char * extensionName)
4816 {
17+ assert (m_initialized);
4918 if (m_supportedExtensionNames.count (extensionName) > 0 )
5019 {
5120 return true ;
@@ -55,7 +24,7 @@ namespace xr
5524 {
5625 if (strcmp (extensionProperty.extensionName , extensionName) == 0 )
5726 {
58- Names .push_back (extensionName);
27+ m_names .push_back (extensionName);
5928 m_supportedExtensionNames.insert (extensionName);
6029 return true ;
6130 }
@@ -65,25 +34,129 @@ namespace xr
6534
6635 bool IsExtensionSupported (const std::string& extensionName) const
6736 {
37+ assert (m_initialized);
6838 return m_supportedExtensionNames.count (extensionName) > 0 ;
6939 }
7040
71- std::vector<const char *> Names{};
72- bool DepthExtensionSupported{ false };
73- bool UnboundedRefSpaceSupported{ false };
74- bool SpatialAnchorSupported{ false };
75- bool SpatialAnchorInteropSupported{ false };
76- bool SecondaryViewConfigurationSupported{ false };
77- bool FirstPersonObserverSupported{ false };
78- bool HandInteractionSupported{ false };
79- bool HandTrackingSupported{ false };
80- bool SceneUnderstandingSupported{ false };
81- bool SceneUnderstandingSerializationSupported{ false };
82- bool EyeTrackingSupported{ false };
41+ bool DepthExtensionSupported () const
42+ {
43+ assert (m_initialized);
44+ return m_depthExtensionSupported;
45+ }
46+ bool UnboundedRefSpaceSupported () const
47+ {
48+ assert (m_initialized);
49+ return m_unboundedRefSpaceSupported;
50+ }
51+ bool SpatialAnchorSupported () const
52+ {
53+ assert (m_initialized);
54+ return m_spatialAnchorSupported;
55+ }
56+ bool SpatialAnchorInteropSupported () const
57+ {
58+ assert (m_initialized);
59+ return m_spatialAnchorInteropSupported;
60+ }
61+ bool SecondaryViewConfigurationSupported () const
62+ {
63+ assert (m_initialized);
64+ return m_secondaryViewConfigurationSupported;
65+ }
66+ bool FirstPersonObserverSupported () const
67+ {
68+ assert (m_initialized);
69+ return m_firstPersonObserverSupported;
70+ }
71+ bool HandInteractionSupported () const
72+ {
73+ assert (m_initialized);
74+ return m_handInteractionSupported;
75+ }
76+ bool HandTrackingSupported () const
77+ {
78+ assert (m_initialized);
79+ return m_handTrackingSupported;
80+ }
81+ bool SceneUnderstandingSupported () const
82+ {
83+ assert (m_initialized);
84+ return m_sceneUnderstandingSupported;
85+ }
86+ bool SceneUnderstandingSerializationSupported () const
87+ {
88+ assert (m_initialized);
89+ return m_sceneUnderstandingSerializationSupported;
90+ }
91+ bool EyeTrackingSupported () const
92+ {
93+ assert (m_initialized);
94+ return m_eyeTrackingSupported;
95+ }
96+
97+ void Initialize ()
98+ {
99+ if (m_initialized)
100+ {
101+ return ;
102+ }
103+ m_initialized = true ;
104+ uint32_t extensionCount{};
105+ XrResult result{ xrEnumerateInstanceExtensionProperties (nullptr , 0 , &extensionCount, nullptr ) };
106+ if (result != XR_SUCCESS)
107+ {
108+ // Avoid failing if device doesn't support OpenXR
109+ return ;
110+ }
83111
112+ m_extensionProperties.resize (extensionCount, { XR_TYPE_EXTENSION_PROPERTIES });
113+ XrCheck (xrEnumerateInstanceExtensionProperties (nullptr , extensionCount, &extensionCount, m_extensionProperties.data ()));
114+
115+ // D3D11 extension is required, so check if it's supported.
116+ for (const char * extensionName : REQUIRED_EXTENSIONS)
117+ {
118+ if (!TryEnableExtension (extensionName))
119+ {
120+ throw std::runtime_error{ " Required extension not supported" };
121+ }
122+ }
123+
124+ // Additional optional extensions for enhanced functionality. Track whether enabled in m_optionalExtensions.
125+ m_depthExtensionSupported = TryEnableExtension (XR_KHR_COMPOSITION_LAYER_DEPTH_EXTENSION_NAME);
126+ m_unboundedRefSpaceSupported = TryEnableExtension (XR_MSFT_UNBOUNDED_REFERENCE_SPACE_EXTENSION_NAME);
127+ m_spatialAnchorSupported = TryEnableExtension (XR_MSFT_SPATIAL_ANCHOR_EXTENSION_NAME);
128+ m_spatialAnchorInteropSupported = TryEnableExtension (XR_MSFT_PERCEPTION_ANCHOR_INTEROP_EXTENSION_NAME);
129+ m_secondaryViewConfigurationSupported = TryEnableExtension (XR_MSFT_SECONDARY_VIEW_CONFIGURATION_EXTENSION_NAME);
130+ m_firstPersonObserverSupported = TryEnableExtension (XR_MSFT_FIRST_PERSON_OBSERVER_EXTENSION_NAME);
131+ m_handInteractionSupported = TryEnableExtension (XR_MSFT_HAND_INTERACTION_EXTENSION_NAME);
132+ m_handTrackingSupported = TryEnableExtension (XR_EXT_HAND_TRACKING_EXTENSION_NAME);
133+ m_sceneUnderstandingSupported = TryEnableExtension (XR_MSFT_SCENE_UNDERSTANDING_EXTENSION_NAME);
134+ m_sceneUnderstandingSerializationSupported = TryEnableExtension (XR_MSFT_SCENE_UNDERSTANDING_SERIALIZATION_EXTENSION_NAME);
135+ m_eyeTrackingSupported = TryEnableExtension (XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME);
136+ }
137+ const std::vector<const char *>& Names () const
138+ {
139+ assert (m_initialized);
140+ return m_names;
141+ }
84142 private:
143+ std::vector<const char *> m_names{};
85144 std::vector<XrExtensionProperties> m_extensionProperties{};
86145 std::unordered_set<std::string> m_supportedExtensionNames{};
146+
147+ bool m_depthExtensionSupported{ false };
148+ bool m_unboundedRefSpaceSupported{ false };
149+ bool m_spatialAnchorSupported{ false };
150+ bool m_spatialAnchorInteropSupported{ false };
151+ bool m_secondaryViewConfigurationSupported{ false };
152+ bool m_firstPersonObserverSupported{ false };
153+ bool m_handInteractionSupported{ false };
154+ bool m_handTrackingSupported{ false };
155+ bool m_sceneUnderstandingSupported{ false };
156+ bool m_sceneUnderstandingSerializationSupported{ false };
157+ bool m_eyeTrackingSupported{ false };
158+
159+ bool m_initialized{ false };
87160 };
88161}
89162#endif
0 commit comments