1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/** \file
* \ingroup GHOST
*/
#ifndef __GHOST_XRCONTEXT_H__
#define __GHOST_XRCONTEXT_H__
#include <memory>
#include <vector>
#include "GHOST_IXrContext.h"
struct GHOST_XrCustomFuncs {
/** Function to retrieve (possibly create) a graphics context */
GHOST_XrGraphicsContextBindFn gpu_ctx_bind_fn{nullptr};
/** Function to release (possibly free) a graphics context */
GHOST_XrGraphicsContextUnbindFn gpu_ctx_unbind_fn{nullptr};
/** Custom per-view draw function for Blender side drawing. */
GHOST_XrDrawViewFn draw_view_fn{nullptr};
};
/**
* \brief Main GHOST container to manage OpenXR through.
*
* Creating a context using #GHOST_XrContextCreate involves dynamically connecting to the OpenXR
* runtime, likely reading the OS OpenXR configuration (i.e. active_runtime.json). So this is
* something that should better be done using lazy-initialization.
*/
class GHOST_XrContext : public GHOST_IXrContext {
public:
GHOST_XrContext(const GHOST_XrContextCreateInfo *create_info);
~GHOST_XrContext();
void initialize(const GHOST_XrContextCreateInfo *create_info);
void startSession(const GHOST_XrSessionBeginInfo *begin_info) override;
void endSession() override;
bool hasSession() const override;
bool shouldRunSessionDrawLoop() const override;
void drawSessionViews(void *draw_customdata) override;
static void setErrorHandler(GHOST_XrErrorHandlerFn handler_fn, void *customdata);
void dispatchErrorMessage(const class GHOST_XrException *exception) const override;
void setGraphicsContextBindFuncs(GHOST_XrGraphicsContextBindFn bind_fn,
GHOST_XrGraphicsContextUnbindFn unbind_fn) override;
void setDrawViewFunc(GHOST_XrDrawViewFn draw_view_fn) override;
void handleSessionStateChange(const XrEventDataSessionStateChanged *lifecycle);
const GHOST_XrCustomFuncs *getCustomFuncs() const;
GHOST_TXrGraphicsBinding getGraphicsBindingType() const;
XrInstance getInstance() const;
bool isDebugMode() const;
bool isDebugTimeMode() const;
private:
std::unique_ptr<struct OpenXRInstanceData> m_oxr;
/* The active GHOST XR Session. Null while no session runs. */
std::unique_ptr<class GHOST_XrSession> m_session;
/** Active graphics binding type. */
GHOST_TXrGraphicsBinding m_gpu_binding_type{GHOST_kXrGraphicsUnknown};
/** Names of enabled extensions */
std::vector<const char *> m_enabled_extensions;
/** Names of enabled API-layers */
std::vector<const char *> m_enabled_layers;
static GHOST_XrErrorHandlerFn s_error_handler;
static void *s_error_handler_customdata;
GHOST_XrCustomFuncs m_custom_funcs;
/** Enable debug message prints and OpenXR API validation layers */
bool m_debug{false};
bool m_debug_time{false};
void createOpenXRInstance();
void initDebugMessenger();
void printInstanceInfo();
void printAvailableAPILayersAndExtensionsInfo();
void printExtensionsAndAPILayersToEnable();
void enumerateApiLayers();
void enumerateExtensions();
void enumerateExtensionsEx(std::vector<XrExtensionProperties> &extensions,
const char *layer_name);
void getAPILayersToEnable(std::vector<const char *> &r_ext_names);
void getExtensionsToEnable(std::vector<const char *> &r_ext_names);
GHOST_TXrGraphicsBinding determineGraphicsBindingTypeToEnable(
const GHOST_XrContextCreateInfo *create_info);
};
#endif // __GHOST_XRCONTEXT_H__
|