Blender  V2.93
GHOST_XrContext.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #pragma once
22 
23 #include <memory>
24 #include <vector>
25 
26 #include "GHOST_Xr_intern.h"
27 
28 #include "GHOST_IXrContext.h"
29 
30 struct OpenXRInstanceData;
31 
34  GHOST_XrGraphicsContextBindFn gpu_ctx_bind_fn = nullptr;
36  GHOST_XrGraphicsContextUnbindFn gpu_ctx_unbind_fn = nullptr;
37 
38  GHOST_XrSessionExitFn session_exit_fn = nullptr;
39  void *session_exit_customdata = nullptr;
40 
42  GHOST_XrDrawViewFn draw_view_fn = nullptr;
43 };
44 
52  OPENXR_RUNTIME_WMR, /* Windows Mixed Reality */
53 
55 };
56 
65  public:
66  GHOST_XrContext(const GHOST_XrContextCreateInfo *create_info);
68  void initialize(const GHOST_XrContextCreateInfo *create_info);
69 
70  void startSession(const GHOST_XrSessionBeginInfo *begin_info) override;
71  void endSession() override;
72  bool isSessionRunning() const override;
73  void drawSessionViews(void *draw_customdata) override;
74 
75  static void setErrorHandler(GHOST_XrErrorHandlerFn handler_fn, void *customdata);
76  void dispatchErrorMessage(const class GHOST_XrException *exception) const override;
77 
78  void setGraphicsContextBindFuncs(GHOST_XrGraphicsContextBindFn bind_fn,
79  GHOST_XrGraphicsContextUnbindFn unbind_fn) override;
80  void setDrawViewFunc(GHOST_XrDrawViewFn draw_view_fn) override;
81  bool needsUpsideDownDrawing() const override;
82 
83  void handleSessionStateChange(const XrEventDataSessionStateChanged &lifecycle);
84 
86  const GHOST_XrCustomFuncs &getCustomFuncs() const;
87  GHOST_TXrGraphicsBinding getGraphicsBindingType() const;
88  XrInstance getInstance() const;
89  bool isDebugMode() const;
90  bool isDebugTimeMode() const;
91 
92  private:
93  static GHOST_XrErrorHandlerFn s_error_handler;
94  static void *s_error_handler_customdata;
95 
96  std::unique_ptr<OpenXRInstanceData> m_oxr;
97 
99 
100  /* The active GHOST XR Session. Null while no session runs. */
101  std::unique_ptr<class GHOST_XrSession> m_session;
102 
104  GHOST_TXrGraphicsBinding m_gpu_binding_type = GHOST_kXrGraphicsUnknown;
105 
107  std::vector<const char *> m_enabled_extensions;
109  std::vector<const char *> m_enabled_layers;
110 
111  GHOST_XrCustomFuncs m_custom_funcs;
112 
114  bool m_debug = false;
115  bool m_debug_time = false;
116 
117  void createOpenXRInstance(const std::vector<GHOST_TXrGraphicsBinding> &graphics_binding_types);
118  void storeInstanceProperties();
119  void initDebugMessenger();
120 
121  void printInstanceInfo();
122  void printAvailableAPILayersAndExtensionsInfo();
123  void printExtensionsAndAPILayersToEnable();
124 
125  void initApiLayers();
126  void initExtensions();
127  void initExtensionsEx(std::vector<XrExtensionProperties> &extensions, const char *layer_name);
128  void getAPILayersToEnable(std::vector<const char *> &r_ext_names);
129  void getExtensionsToEnable(const std::vector<GHOST_TXrGraphicsBinding> &graphics_binding_types,
130  std::vector<const char *> &r_ext_names);
131  std::vector<GHOST_TXrGraphicsBinding> determineGraphicsBindingTypesToEnable(
132  const GHOST_XrContextCreateInfo *create_info);
133  GHOST_TXrGraphicsBinding determineGraphicsBindingTypeToUse(
134  const std::vector<GHOST_TXrGraphicsBinding> &enabled_types);
135 };
GHOST_TXrOpenXRRuntimeID
@ OPENXR_RUNTIME_MONADO
@ OPENXR_RUNTIME_UNKNOWN
@ OPENXR_RUNTIME_OCULUS
@ OPENXR_RUNTIME_STEAMVR
@ OPENXR_RUNTIME_WMR
Main GHOST container to manage OpenXR through.
XrInstance getInstance() const
GHOST_TXrOpenXRRuntimeID getOpenXRRuntimeID() const
void setGraphicsContextBindFuncs(GHOST_XrGraphicsContextBindFn bind_fn, GHOST_XrGraphicsContextUnbindFn unbind_fn) override
GHOST_TXrGraphicsBinding getGraphicsBindingType() const
void drawSessionViews(void *draw_customdata) override
void handleSessionStateChange(const XrEventDataSessionStateChanged &lifecycle)
const GHOST_XrCustomFuncs & getCustomFuncs() const
void dispatchErrorMessage(const class GHOST_XrException *exception) const override
bool isDebugTimeMode() const
void setDrawViewFunc(GHOST_XrDrawViewFn draw_view_fn) override
bool needsUpsideDownDrawing() const override
bool isSessionRunning() const override
void startSession(const GHOST_XrSessionBeginInfo *begin_info) override
void endSession() override
GHOST_XrContext(const GHOST_XrContextCreateInfo *create_info)
bool isDebugMode() const
void initialize(const GHOST_XrContextCreateInfo *create_info)
static void setErrorHandler(GHOST_XrErrorHandlerFn handler_fn, void *customdata)
GHOST_XrDrawViewFn draw_view_fn
GHOST_XrSessionExitFn session_exit_fn
GHOST_XrGraphicsContextUnbindFn gpu_ctx_unbind_fn
GHOST_XrGraphicsContextBindFn gpu_ctx_bind_fn