Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/openxr/util.h
10277 views
1
/**************************************************************************/
2
/* util.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#define UNPACK(...) __VA_ARGS__
34
35
#define INIT_XR_FUNC_V(openxr_api, name) \
36
if constexpr (true) { \
37
XrResult get_instance_proc_addr_result; \
38
get_instance_proc_addr_result = openxr_api->get_instance_proc_addr(#name, (PFN_xrVoidFunction *)&name##_ptr); \
39
ERR_FAIL_COND_V(XR_FAILED(get_instance_proc_addr_result), false); \
40
} else \
41
((void)0)
42
43
#define EXT_INIT_XR_FUNC_V(name) INIT_XR_FUNC_V(OpenXRAPI::get_singleton(), name)
44
#define OPENXR_API_INIT_XR_FUNC_V(name) INIT_XR_FUNC_V(this, name)
45
46
#define INIT_XR_FUNC(openxr_api, name) \
47
if constexpr (true) { \
48
XrResult get_instance_proc_addr_result; \
49
get_instance_proc_addr_result = openxr_api->get_instance_proc_addr(#name, (PFN_xrVoidFunction *)&name##_ptr); \
50
ERR_FAIL_COND(XR_FAILED(get_instance_proc_addr_result)); \
51
} else \
52
((void)0)
53
54
#define EXT_INIT_XR_FUNC(name) INIT_XR_FUNC(OpenXRAPI::get_singleton(), name)
55
#define OPENXR_API_INIT_XR_FUNC(name) INIT_XR_FUNC(this, name)
56
57
#define TRY_INIT_XR_FUNC(openxr_api, name) \
58
openxr_api->try_get_instance_proc_addr(#name, (PFN_xrVoidFunction *)&name##_ptr)
59
60
#define EXT_TRY_INIT_XR_FUNC(name) TRY_INIT_XR_FUNC(OpenXRAPI::get_singleton(), name)
61
#define OPENXR_TRY_API_INIT_XR_FUNC(name) TRY_INIT_XR_FUNC(this, name)
62
#define GDEXTENSION_INIT_XR_FUNC(name) \
63
if constexpr (true) { \
64
name##_ptr = reinterpret_cast<PFN_##name>(get_openxr_api()->get_instance_proc_addr(#name)); \
65
ERR_FAIL_NULL(name##_ptr); \
66
} else \
67
((void)0)
68
69
#define GDEXTENSION_INIT_XR_FUNC_V(name) \
70
if constexpr (true) { \
71
name##_ptr = reinterpret_cast<PFN_##name>(get_openxr_api()->get_instance_proc_addr(#name)); \
72
ERR_FAIL_NULL_V(name##_ptr, false); \
73
} else \
74
((void)0)
75
76
#define EXT_PROTO_XRRESULT_FUNC1(func_name, arg1_type, arg1) \
77
PFN_##func_name func_name##_ptr = nullptr; \
78
XRAPI_ATTR XrResult XRAPI_CALL func_name(UNPACK arg1_type p_##arg1) const { \
79
if (!func_name##_ptr) { \
80
return XR_ERROR_HANDLE_INVALID; \
81
} \
82
return (*func_name##_ptr)(p_##arg1); \
83
}
84
85
#define EXT_PROTO_XRRESULT_FUNC2(func_name, arg1_type, arg1, arg2_type, arg2) \
86
PFN_##func_name func_name##_ptr = nullptr; \
87
XRAPI_ATTR XrResult XRAPI_CALL func_name(UNPACK arg1_type p_##arg1, UNPACK arg2_type p_##arg2) const { \
88
if (!func_name##_ptr) { \
89
return XR_ERROR_HANDLE_INVALID; \
90
} \
91
return (*func_name##_ptr)(p_##arg1, p_##arg2); \
92
}
93
94
#define EXT_PROTO_XRRESULT_FUNC3(func_name, arg1_type, arg1, arg2_type, arg2, arg3_type, arg3) \
95
PFN_##func_name func_name##_ptr = nullptr; \
96
XRAPI_ATTR XrResult XRAPI_CALL func_name(UNPACK arg1_type p_##arg1, UNPACK arg2_type p_##arg2, UNPACK arg3_type p_##arg3) const { \
97
if (!func_name##_ptr) { \
98
return XR_ERROR_HANDLE_INVALID; \
99
} \
100
return (*func_name##_ptr)(p_##arg1, p_##arg2, p_##arg3); \
101
}
102
103
#define EXT_PROTO_XRRESULT_FUNC4(func_name, arg1_type, arg1, arg2_type, arg2, arg3_type, arg3, arg4_type, arg4) \
104
PFN_##func_name func_name##_ptr = nullptr; \
105
XRAPI_ATTR XrResult XRAPI_CALL func_name(UNPACK arg1_type p_##arg1, UNPACK arg2_type p_##arg2, UNPACK arg3_type p_##arg3, UNPACK arg4_type p_##arg4) const { \
106
if (!func_name##_ptr) { \
107
return XR_ERROR_HANDLE_INVALID; \
108
} \
109
return (*func_name##_ptr)(p_##arg1, p_##arg2, p_##arg3, p_##arg4); \
110
}
111
112
#define EXT_PROTO_XRRESULT_FUNC5(func_name, arg1_type, arg1, arg2_type, arg2, arg3_type, arg3, arg4_type, arg4, arg5_type, arg5) \
113
PFN_##func_name func_name##_ptr = nullptr; \
114
XRAPI_ATTR XrResult XRAPI_CALL func_name(UNPACK arg1_type p_##arg1, UNPACK arg2_type p_##arg2, UNPACK arg3_type p_##arg3, UNPACK arg4_type p_##arg4, UNPACK arg5_type p_##arg5) const { \
115
if (!func_name##_ptr) { \
116
return XR_ERROR_HANDLE_INVALID; \
117
} \
118
return (*func_name##_ptr)(p_##arg1, p_##arg2, p_##arg3, p_##arg4, p_##arg5); \
119
}
120
121
#define EXT_PROTO_XRRESULT_FUNC6(func_name, arg1_type, arg1, arg2_type, arg2, arg3_type, arg3, arg4_type, arg4, arg5_type, arg5, arg6_type, arg6) \
122
PFN_##func_name func_name##_ptr = nullptr; \
123
XRAPI_ATTR XrResult XRAPI_CALL func_name(UNPACK arg1_type p_##arg1, UNPACK arg2_type p_##arg2, UNPACK arg3_type p_##arg3, UNPACK arg4_type p_##arg4, UNPACK arg5_type p_##arg5, UNPACK arg6_type p_##arg6) const { \
124
if (!func_name##_ptr) { \
125
return XR_ERROR_HANDLE_INVALID; \
126
} \
127
return (*func_name##_ptr)(p_##arg1, p_##arg2, p_##arg3, p_##arg4, p_##arg5, p_##arg6); \
128
}
129
130