Debian Codegraph @

3rdparty/osgXR/src/OpenXR/System.h

raw symbols SCIP
1 // SPDX-License-Identifier: LGPL-2.1-only
2 // Copyright (C) 2021 James Hogan <[email protected]>
3
4 #ifndef OSGXR_OPENXR_SYSTEM
5 #define OSGXR_OPENXR_SYSTEM 1
6
7 #include "Instance.h"
8
9 #include <osg/DisplaySettings>
10 #include <osg/ref_ptr>
11
12 #include <algorithm>
13 #include <vector>
14
15 namespace osgXR {
16
17 namespace OpenXR {
18
19 class System
20 {
21 public:
22
23 System(Instance *instance, XrSystemId systemId) :
24 _instance(instance),
25 _systemId(systemId),
26 _readProperties(false),
27 _orientationTracking(false),
28 _positionTracking(false),
29 _readViewConfigurations(false)
30 {
31 }
32
33 // Error checking
34
35 inline bool check(XrResult result, const char *actionMsg) const
36 {
37 return _instance->check(result, actionMsg);
38 }
39
40 // Conversions
41
42 inline Instance *getInstance()
43 {
44 return _instance;
45 }
46 inline const Instance *getInstance() const
47 {
48 return _instance;
49 }
50
51 inline XrInstance getXrInstance() const
52 {
53 return _instance->getXrInstance();
54 }
55
56 inline XrSystemId getXrSystemId() const
57 {
58 return _systemId;
59 }
60
61 // Queries
62
63 void getProperties() const;
64
65 inline const char *getSystemName() const
66 {
67 if (!_readProperties)
68 getProperties();
69 return _systemName;
70 }
71
72 inline bool getOrientationTracking() const
73 {
74 if (!_readProperties)
75 getProperties();
76 return _orientationTracking;
77 }
78
79 inline bool getPositionTracking() const
80 {
81 if (!_readProperties)
82 getProperties();
83 return _positionTracking;
84 }
85
86 class ViewConfiguration
87 {
88
89 public:
90
91 ViewConfiguration(const System *system, XrViewConfigurationType type) :
92 _system(system),
93 _type(type),
94 _readViews(false),
95 _readEnvBlendModes(false)
96 {
97 }
98
99 XrViewConfigurationType getType() const
100 {
101 return _type;
102 }
103
104 // Queries
105
106 class View
107 {
108
109 public:
110
111 struct Viewport
112 {
113 uint32_t x, y, width, height, arrayIndex;
114 };
115
116 View(uint32_t recommendedWidth,
117 uint32_t recommendedHeight,
118 uint32_t recommendedSamples = 1) :
119 _recommendedWidth(recommendedWidth),
120 _recommendedHeight(recommendedHeight),
121 _recommendedSamples(recommendedSamples)
122 {
123 }
124
125 View(const XrViewConfigurationView &view) :
126 _recommendedWidth(view.recommendedImageRectWidth),
127 _recommendedHeight(view.recommendedImageRectHeight),
128 _recommendedSamples(view.recommendedSwapchainSampleCount)
129 {
130 }
131
132 uint32_t getRecommendedWidth() const
133 {
134 return _recommendedWidth;
135 }
136
137 uint32_t getRecommendedHeight() const
138 {
139 return _recommendedHeight;
140 }
141
142
143 uint32_t getRecommendedSamples() const
144 {
145 return _recommendedSamples;
146 }
147
148 /// Tile another view horizontally after this one
149 struct Viewport tileHorizontally(const View &other)
150 {
151 struct Viewport vp;
152 vp.x = _recommendedWidth;
153 vp.y = 0;
154 vp.width = other._recommendedWidth;
155 vp.height = other._recommendedHeight;
156 vp.arrayIndex = 0;
157
158 _recommendedWidth += other._recommendedWidth;
159 _recommendedHeight = std::max(_recommendedHeight,
160 other._recommendedHeight);
161 return vp;
162 }
163
164 protected:
165
166 uint32_t _recommendedWidth;
167 uint32_t _recommendedHeight;
168 uint32_t _recommendedSamples;
169 };
170
171 typedef std::vector<View> Views;
172 const Views &getViews() const;
173
174 typedef std::vector<XrEnvironmentBlendMode> EnvBlendModes;
175 const EnvBlendModes &getEnvBlendModes() const;
176
177 protected:
178
179 inline bool check(XrResult result, const char *actionMsg) const
180 {
181 return _system->getInstance()->check(result, actionMsg);
182 }
183
184 const System *_system;
185 XrViewConfigurationType _type;
186
187 // Views
188 mutable bool _readViews;
189 mutable Views _views;
190
191 // Environment blend modes
192 mutable bool _readEnvBlendModes;
193 mutable EnvBlendModes _envBlendModes;
194 };
195
196 typedef std::vector<ViewConfiguration> ViewConfigurations;
197 const ViewConfigurations &getViewConfigurations() const;
198
199 protected:
200
201 // System data
202 Instance *_instance;
203 XrSystemId _systemId;
204
205 // Properties
206 mutable char _systemName[XR_MAX_SYSTEM_NAME_SIZE];
207 mutable bool _readProperties;
208 mutable bool _orientationTracking;
209 mutable bool _positionTracking;
210
211 // View configurations
212 mutable bool _readViewConfigurations;
213 mutable ViewConfigurations _viewConfigurations;
214
215 };
216
217 } // osgXR::OpenXR
218
219 } // osgXR
220
221 #endif