Blender  V3.3
GHOST_XrContext.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #pragma once
8 
9 #include <memory>
10 #include <vector>
11 
12 #include "GHOST_Xr_intern.h"
13 
14 #include "GHOST_IXrContext.h"
15 
16 struct OpenXRInstanceData;
17 
20  GHOST_XrGraphicsContextBindFn gpu_ctx_bind_fn = nullptr;
22  GHOST_XrGraphicsContextUnbindFn gpu_ctx_unbind_fn = nullptr;
23 
24  GHOST_XrSessionCreateFn session_create_fn = nullptr;
25  GHOST_XrSessionExitFn session_exit_fn = nullptr;
26  void *session_exit_customdata = nullptr;
27 
29  GHOST_XrDrawViewFn draw_view_fn = nullptr;
30 };
31 
39  OPENXR_RUNTIME_WMR, /* Windows Mixed Reality */
41 
43 };
44 
53  public:
54  GHOST_XrContext(const GHOST_XrContextCreateInfo *create_info);
56  void initialize(const GHOST_XrContextCreateInfo *create_info);
57 
58  void startSession(const GHOST_XrSessionBeginInfo *begin_info) override;
59  void endSession() override;
60  bool isSessionRunning() const override;
61  void drawSessionViews(void *draw_customdata) override;
62 
64  GHOST_XrSession *getSession() override;
65  const GHOST_XrSession *getSession() const override;
66 
67  static void setErrorHandler(GHOST_XrErrorHandlerFn handler_fn, void *customdata);
68  void dispatchErrorMessage(const class GHOST_XrException *exception) const override;
69 
70  void setGraphicsContextBindFuncs(GHOST_XrGraphicsContextBindFn bind_fn,
71  GHOST_XrGraphicsContextUnbindFn unbind_fn) override;
72  void setDrawViewFunc(GHOST_XrDrawViewFn draw_view_fn) override;
73  bool needsUpsideDownDrawing() const override;
74 
75  void handleSessionStateChange(const XrEventDataSessionStateChanged &lifecycle);
76 
78  const GHOST_XrCustomFuncs &getCustomFuncs() const;
79  GHOST_TXrGraphicsBinding getGraphicsBindingType() const;
80  XrInstance getInstance() const;
81  bool isDebugMode() const;
82  bool isDebugTimeMode() const;
83 
84  bool isExtensionEnabled(const char *ext) const;
85 
86  private:
87  static GHOST_XrErrorHandlerFn s_error_handler;
88  static void *s_error_handler_customdata;
89 
90  std::unique_ptr<OpenXRInstanceData> m_oxr;
91 
93 
94  /* The active GHOST XR Session. Null while no session runs. */
95  std::unique_ptr<class GHOST_XrSession> m_session;
96 
98  GHOST_TXrGraphicsBinding m_gpu_binding_type = GHOST_kXrGraphicsUnknown;
99 
101  std::vector<const char *> m_enabled_extensions;
103  std::vector<const char *> m_enabled_layers;
104 
105  GHOST_XrCustomFuncs m_custom_funcs;
106 
108  bool m_debug = false;
109  bool m_debug_time = false;
110 
111  void createOpenXRInstance(const std::vector<GHOST_TXrGraphicsBinding> &graphics_binding_types);
112  void storeInstanceProperties();
113  void initDebugMessenger();
114 
115  void printSDKVersion();
116  void printInstanceInfo();
117  void printAvailableAPILayersAndExtensionsInfo();
118  void printExtensionsAndAPILayersToEnable();
119 
120  void initApiLayers();
121  void initExtensions();
122  void initExtensionsEx(std::vector<XrExtensionProperties> &extensions, const char *layer_name);
123  void getAPILayersToEnable(std::vector<const char *> &r_ext_names);
124  void getExtensionsToEnable(const std::vector<GHOST_TXrGraphicsBinding> &graphics_binding_types,
125  std::vector<const char *> &r_ext_names);
126  std::vector<GHOST_TXrGraphicsBinding> determineGraphicsBindingTypesToEnable(
127  const GHOST_XrContextCreateInfo *create_info);
128  GHOST_TXrGraphicsBinding determineGraphicsBindingTypeToUse(
129  const std::vector<GHOST_TXrGraphicsBinding> &enabled_types,
130  const GHOST_XrContextCreateInfo *create_info);
131 };
GHOST_TXrOpenXRRuntimeID
@ OPENXR_RUNTIME_MONADO
@ OPENXR_RUNTIME_UNKNOWN
@ OPENXR_RUNTIME_OCULUS
@ OPENXR_RUNTIME_STEAMVR
@ OPENXR_RUNTIME_WMR
@ OPENXR_RUNTIME_VARJO
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
bool isExtensionEnabled(const char *ext) const
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_XrSession * getSession() override
GHOST_XrDrawViewFn draw_view_fn
GHOST_XrSessionExitFn session_exit_fn
GHOST_XrSessionCreateFn session_create_fn
GHOST_XrGraphicsContextUnbindFn gpu_ctx_unbind_fn
GHOST_XrGraphicsContextBindFn gpu_ctx_bind_fn