Ocean
Passthrough.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_PLATFORM_META_QUEST_OPENXR_PASSTHROUGH_H
9 #define META_OCEAN_PLATFORM_META_QUEST_OPENXR_PASSTHROUGH_H
10 
12 
14 
15 namespace Ocean
16 {
17 
18 namespace Platform
19 {
20 
21 namespace Meta
22 {
23 
24 namespace Quest
25 {
26 
27 namespace OpenXR
28 {
29 
30 /**
31  * This class implements a wrapper for passthrough.
32  * This object uses the Android feature 'com.oculus.feature.PASSTHROUGH'.
33  * @ingroup platformmetaquestopenxr
34  */
35 class OCEAN_PLATFORM_META_QUEST_OPENXR_EXPORT Passthrough final
36 {
37  public:
38 
39  /**
40  * Definition of an unordered set holding strings.
41  */
42  typedef std::unordered_set<std::string> StringSet;
43 
44  public:
45 
46  /**
47  * Default constructor.
48  */
49  Passthrough() = default;
50 
51  /**
52  * Destructs this passthrough object and releases all associated resources.
53  */
55 
56  /**
57  * Move constructor.
58  * @param passthrough The object to be moved
59  */
60  inline Passthrough(Passthrough&& passthrough);
61 
62  /**
63  * Initializes this passthrough object.
64  * @param session The OpenXR session to be used, must be valid
65  * @param xrPassthroughLayerPurposeFB The purpose to be used
66  * @return True, if succeeded
67  */
68  inline bool initialize(const Platform::OpenXR::Session& session, const XrPassthroughLayerPurposeFB& xrPassthroughLayerPurposeFB = XR_PASSTHROUGH_LAYER_PURPOSE_RECONSTRUCTION_FB);
69 
70  /**
71  * Initializes this passthrough object.
72  * @param xrInstance The OpenXR instance to be used, must be valid
73  * @param xrSession The OpenXR session to be used, must be valid
74  * @param xrPassthroughLayerPurposeFB The purpose to be used
75  * @return True, if succeeded
76  */
77  bool initialize(const XrInstance& xrInstance, const XrSession& xrSession, const XrPassthroughLayerPurposeFB& xrPassthroughLayerPurposeFB = XR_PASSTHROUGH_LAYER_PURPOSE_RECONSTRUCTION_FB);
78 
79  /**
80  * Starts passthrough.
81  * @return True, if succeeded
82  */
83  bool start();
84 
85  /**
86  * Pauses passthrough.
87  * @return True, if succeeded
88  */
89  bool pause();
90 
91  /**
92  * Returns whether passthrough is started.
93  * @return True, if so
94  */
95  bool isStarted() const;
96 
97  /**
98  * Explicitly releases the passthrough object and all associated resources.
99  */
100  void release();
101 
102  /**
103  * Returns the OpenXR passthrough layer.
104  * @return The passthrough's layer
105  */
106  inline XrPassthroughLayerFB xrPassthroughLayerFB() const;
107 
108  /**
109  * Returns the lock of the passthrough.
110  * @return The passthrough's lock.
111  */
112  inline Lock& lock() const;
113 
114  /**
115  * Returns whether this object holds initialized and valid OpenXR hand trackers.
116  * @return True, if so
117  */
118  inline bool isValid() const;
119 
120  /**
121  * Move operator.
122  * @param passthrough The object to be moved
123  * @return Reference to this object
124  */
126 
127  /**
128  * Returns the names of the necessary OpenXR extensions necessary for hand tracking.
129  * @return The necessary OpenXR extensions
130  */
132 
133  protected:
134 
135  /**
136  * Disabled copy constructor.
137  */
138  Passthrough(const Passthrough&) = delete;
139 
140  /**
141  * Disabled assign operator.
142  * @return Reference to this object
143  */
144  Passthrough& operator=(const Passthrough&) = delete;
145 
146  protected:
147 
148  /// The OpenXR instance.
149  XrInstance xrInstance_ = XR_NULL_HANDLE;
150 
151  /// The OpenXR session.
152  XrSession xrSession_ = XR_NULL_HANDLE;
153 
154  /// The OpenXR passthrough handle.
155  XrPassthroughFB xrPassthroughFB_ = XR_NULL_HANDLE;
156 
157  /// The OpenXR passthrough layer handle.
158  XrPassthroughLayerFB xrPassthroughLayerFB_ = XR_NULL_HANDLE;
159 
160  /// The OpenXR passthrough create function.
161  PFN_xrCreatePassthroughFB xrCreatePassthroughFB_ = nullptr;
162 
163  /// The OpenXR passthrough destroy function.
164  PFN_xrDestroyPassthroughFB xrDestroyPassthroughFB_ = nullptr;
165 
166  /// The OpenXR passthrough start function.
167  PFN_xrPassthroughStartFB xrPassthroughStartFB_ = nullptr;
168 
169  /// The OpenXR passthrough pause function.
170  PFN_xrPassthroughPauseFB xrPassthroughPauseFB_ = nullptr;
171 
172  /// The OpenXR passthrough create layer function.
173  PFN_xrCreatePassthroughLayerFB xrCreatePassthroughLayerFB_ = nullptr;
174 
175  /// The OpeXR passthrough destroy layer function.
176  PFN_xrDestroyPassthroughLayerFB xrDestroyPassthroughLayerFB_ = nullptr;
177 
178  /// The OpenXR passthrough resume layer function.
179  PFN_xrPassthroughLayerResumeFB xrPassthroughLayerResumeFB_ = nullptr;
180 
181  /// The OpenXR passthrough set style function.
182  PFN_xrPassthroughLayerSetStyleFB xrPassthroughLayerSetStyleFB_ = nullptr;
183 
184  /// True, if passthrough is currently started.
185  bool isStarted_ = false;
186 
187  /// The lock object.
188  mutable Lock lock_;
189 };
190 
192 {
193  *this = std::move(passthrough);
194 }
195 
196 bool Passthrough::initialize(const Platform::OpenXR::Session& session, const XrPassthroughLayerPurposeFB& xrPassthroughLayerPurposeFB)
197 {
198  ocean_assert(session.isValid());
199 
200  return initialize(session.xrInstance(), session, xrPassthroughLayerPurposeFB);
201 }
202 
203 inline XrPassthroughLayerFB Passthrough::xrPassthroughLayerFB() const
204 {
205  return xrPassthroughLayerFB_;
206 }
207 
208 inline Lock& Passthrough::lock() const
209 {
210  return lock_;
211 }
212 
213 inline bool Passthrough::isValid() const
214 {
215  const ScopedLock scopedLock(lock_);
216 
217  return xrInstance_ != XR_NULL_HANDLE;
218 }
219 
220 }
221 
222 }
223 
224 }
225 
226 }
227 
228 }
229 
230 #endif // META_OCEAN_PLATFORM_META_QUEST_OPENXR_PASSTHROUGH_H
This class implements a recursive lock object.
Definition: Lock.h:31
This class implements a wrapper for passthrough.
Definition: Passthrough.h:36
Lock & lock() const
Returns the lock of the passthrough.
Definition: Passthrough.h:208
Passthrough & operator=(const Passthrough &)=delete
Disabled assign operator.
Lock lock_
The lock object.
Definition: Passthrough.h:188
bool isStarted() const
Returns whether passthrough is started.
XrInstance xrInstance_
The OpenXR instance.
Definition: Passthrough.h:149
bool isValid() const
Returns whether this object holds initialized and valid OpenXR hand trackers.
Definition: Passthrough.h:213
static const StringSet & necessaryOpenXRExtensionNames()
Returns the names of the necessary OpenXR extensions necessary for hand tracking.
~Passthrough()
Destructs this passthrough object and releases all associated resources.
XrPassthroughLayerFB xrPassthroughLayerFB_
The OpenXR passthrough layer handle.
Definition: Passthrough.h:158
bool initialize(const XrInstance &xrInstance, const XrSession &xrSession, const XrPassthroughLayerPurposeFB &xrPassthroughLayerPurposeFB=XR_PASSTHROUGH_LAYER_PURPOSE_RECONSTRUCTION_FB)
Initializes this passthrough object.
Passthrough(const Passthrough &)=delete
Disabled copy constructor.
Passthrough & operator=(Passthrough &&passthrough)
Move operator.
void release()
Explicitly releases the passthrough object and all associated resources.
bool initialize(const Platform::OpenXR::Session &session, const XrPassthroughLayerPurposeFB &xrPassthroughLayerPurposeFB=XR_PASSTHROUGH_LAYER_PURPOSE_RECONSTRUCTION_FB)
Initializes this passthrough object.
Definition: Passthrough.h:196
XrPassthroughLayerFB xrPassthroughLayerFB() const
Returns the OpenXR passthrough layer.
Definition: Passthrough.h:203
std::unordered_set< std::string > StringSet
Definition of an unordered set holding strings.
Definition: Passthrough.h:42
This class wraps an OpenXR session.
Definition: Session.h:32
XrInstance xrInstance() const
Returns the OpenXR instance associated with this session.
Definition: Session.h:359
bool isValid() const
Returns whether this object holds a valid OpenXR instance.
This class implements a scoped lock object for recursive lock objects.
Definition: Lock.h:135
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15