Blender V4.3
GHOST_XrContext.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
11#include <memory>
12#include <vector>
13
14#include "GHOST_Xr_intern.hh"
15
16#include "GHOST_IXrContext.hh"
17
19
22 GHOST_XrGraphicsContextBindFn gpu_ctx_bind_fn = nullptr;
24 GHOST_XrGraphicsContextUnbindFn gpu_ctx_unbind_fn = nullptr;
25
26 GHOST_XrSessionCreateFn session_create_fn = nullptr;
27 GHOST_XrSessionExitFn session_exit_fn = nullptr;
28 void *session_exit_customdata = nullptr;
29
31 GHOST_XrDrawViewFn draw_view_fn = nullptr;
32
34 GHOST_XrPassthroughEnabledFn passthrough_enabled_fn = nullptr;
35
37 GHOST_XrDisablePassthroughFn disable_passthrough_fn = nullptr;
38};
39
52
61 public:
62 GHOST_XrContext(const GHOST_XrContextCreateInfo *create_info);
64 void initialize(const GHOST_XrContextCreateInfo *create_info);
65
66 void startSession(const GHOST_XrSessionBeginInfo *begin_info) override;
67 void endSession() override;
68 bool isSessionRunning() const override;
69 void drawSessionViews(void *draw_customdata) override;
70
72 GHOST_XrSession *getSession() override;
73 const GHOST_XrSession *getSession() const 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 void setPassthroughEnabledFunc(GHOST_XrPassthroughEnabledFn passthrough_enabled_fn) override;
82 void setDisablePassthroughFunc(GHOST_XrDisablePassthroughFn disable_passthrough_fn) override;
83 bool needsUpsideDownDrawing() const override;
84
85 void handleSessionStateChange(const XrEventDataSessionStateChanged &lifecycle);
86
89 GHOST_TXrGraphicsBinding getGraphicsBindingType() const;
90 XrInstance getInstance() const;
91 bool isDebugMode() const;
92 bool isDebugTimeMode() const;
93
94 bool isExtensionEnabled(const char *ext) const;
95
96 private:
97 static GHOST_XrErrorHandlerFn s_error_handler;
98 static void *s_error_handler_customdata;
99
100 std::unique_ptr<OpenXRInstanceData> m_oxr;
101
103
104 /* The active GHOST XR Session. Null while no session runs. */
105 std::unique_ptr<class GHOST_XrSession> m_session;
106
108 GHOST_TXrGraphicsBinding m_gpu_binding_type = GHOST_kXrGraphicsUnknown;
109
111 std::vector<const char *> m_enabled_extensions;
113 std::vector<const char *> m_enabled_layers;
114
115 GHOST_XrCustomFuncs m_custom_funcs;
116
118 bool m_debug = false;
119 bool m_debug_time = false;
120
121 void createOpenXRInstance(const std::vector<GHOST_TXrGraphicsBinding> &graphics_binding_types);
122 void storeInstanceProperties();
123 void initDebugMessenger();
124
125 void printSDKVersion();
126 void printInstanceInfo();
127 void printAvailableAPILayersAndExtensionsInfo();
128 void printExtensionsAndAPILayersToEnable();
129
130 void initApiLayers();
131 void initExtensions();
132 void initExtensionsEx(std::vector<XrExtensionProperties> &extensions, const char *layer_name);
133 void getAPILayersToEnable(std::vector<const char *> &r_ext_names);
134 void getExtensionsToEnable(const std::vector<GHOST_TXrGraphicsBinding> &graphics_binding_types,
135 std::vector<const char *> &r_ext_names);
136 std::vector<GHOST_TXrGraphicsBinding> determineGraphicsBindingTypesToEnable(
137 const GHOST_XrContextCreateInfo *create_info);
138 GHOST_TXrGraphicsBinding determineGraphicsBindingTypeToUse(
139 const std::vector<GHOST_TXrGraphicsBinding> &enabled_types,
140 const GHOST_XrContextCreateInfo *create_info);
141};
GHOST_TXrOpenXRRuntimeID
@ OPENXR_RUNTIME_MONADO
@ OPENXR_RUNTIME_UNKNOWN
@ OPENXR_RUNTIME_OCULUS
@ OPENXR_RUNTIME_STEAMVR
@ OPENXR_RUNTIME_WMR
@ OPENXR_RUNTIME_VARJO
void initialize()
Main GHOST container to manage OpenXR through.
XrInstance getInstance() const
void setDisablePassthroughFunc(GHOST_XrDisablePassthroughFn disable_passthrough_fn) override
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
static void setErrorHandler(GHOST_XrErrorHandlerFn handler_fn, void *customdata)
void setPassthroughEnabledFunc(GHOST_XrPassthroughEnabledFn passthrough_enabled_fn) override
GHOST_XrSession * getSession() override
GHOST_XrDrawViewFn draw_view_fn
GHOST_XrSessionExitFn session_exit_fn
GHOST_XrSessionCreateFn session_create_fn
GHOST_XrDisablePassthroughFn disable_passthrough_fn
GHOST_XrGraphicsContextUnbindFn gpu_ctx_unbind_fn
GHOST_XrGraphicsContextBindFn gpu_ctx_bind_fn
GHOST_XrPassthroughEnabledFn passthrough_enabled_fn