Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/openxr/extensions/openxr_extension_wrapper.cpp
10278 views
1
/**************************************************************************/
2
/* openxr_extension_wrapper.cpp */
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
#include "openxr_extension_wrapper.h"
32
33
#include "../openxr_api.h"
34
#include "../openxr_api_extension.h"
35
36
void OpenXRExtensionWrapper::_bind_methods() {
37
GDVIRTUAL_BIND(_get_requested_extensions);
38
GDVIRTUAL_BIND(_set_system_properties_and_get_next_pointer, "next_pointer");
39
GDVIRTUAL_BIND(_set_instance_create_info_and_get_next_pointer, "next_pointer");
40
GDVIRTUAL_BIND(_set_session_create_and_get_next_pointer, "next_pointer");
41
GDVIRTUAL_BIND(_set_swapchain_create_info_and_get_next_pointer, "next_pointer");
42
GDVIRTUAL_BIND(_set_hand_joint_locations_and_get_next_pointer, "hand_index", "next_pointer");
43
GDVIRTUAL_BIND(_set_projection_views_and_get_next_pointer, "view_index", "next_pointer");
44
GDVIRTUAL_BIND(_set_frame_wait_info_and_get_next_pointer, "next_pointer");
45
GDVIRTUAL_BIND(_set_frame_end_info_and_get_next_pointer, "next_pointer");
46
GDVIRTUAL_BIND(_set_view_locate_info_and_get_next_pointer, "next_pointer");
47
GDVIRTUAL_BIND(_set_reference_space_create_info_and_get_next_pointer, "reference_space_type", "next_pointer");
48
GDVIRTUAL_BIND(_get_composition_layer_count);
49
GDVIRTUAL_BIND(_get_composition_layer, "index");
50
GDVIRTUAL_BIND(_get_composition_layer_order, "index");
51
GDVIRTUAL_BIND(_get_suggested_tracker_names);
52
GDVIRTUAL_BIND(_on_register_metadata);
53
GDVIRTUAL_BIND(_on_before_instance_created);
54
GDVIRTUAL_BIND(_on_instance_created, "instance");
55
GDVIRTUAL_BIND(_on_instance_destroyed);
56
GDVIRTUAL_BIND(_on_session_created, "session");
57
GDVIRTUAL_BIND(_on_process);
58
GDVIRTUAL_BIND(_on_sync_actions);
59
GDVIRTUAL_BIND(_on_pre_render);
60
GDVIRTUAL_BIND(_on_main_swapchains_created);
61
GDVIRTUAL_BIND(_on_pre_draw_viewport, "viewport");
62
GDVIRTUAL_BIND(_on_post_draw_viewport, "viewport");
63
GDVIRTUAL_BIND(_on_session_destroyed);
64
GDVIRTUAL_BIND(_on_state_idle);
65
GDVIRTUAL_BIND(_on_state_ready);
66
GDVIRTUAL_BIND(_on_state_synchronized);
67
GDVIRTUAL_BIND(_on_state_visible);
68
GDVIRTUAL_BIND(_on_state_focused);
69
GDVIRTUAL_BIND(_on_state_stopping);
70
GDVIRTUAL_BIND(_on_state_loss_pending);
71
GDVIRTUAL_BIND(_on_state_exiting);
72
GDVIRTUAL_BIND(_on_event_polled, "event");
73
GDVIRTUAL_BIND(_set_viewport_composition_layer_and_get_next_pointer, "layer", "property_values", "next_pointer");
74
GDVIRTUAL_BIND(_get_viewport_composition_layer_extension_properties);
75
GDVIRTUAL_BIND(_get_viewport_composition_layer_extension_property_defaults);
76
GDVIRTUAL_BIND(_on_viewport_composition_layer_destroyed, "layer");
77
GDVIRTUAL_BIND(_set_android_surface_swapchain_create_info_and_get_next_pointer, "property_values", "next_pointer");
78
79
ClassDB::bind_method(D_METHOD("get_openxr_api"), &OpenXRExtensionWrapper::_gdextension_get_openxr_api);
80
ClassDB::bind_method(D_METHOD("register_extension_wrapper"), &OpenXRExtensionWrapper::_gdextension_register_extension_wrapper);
81
}
82
83
HashMap<String, bool *> OpenXRExtensionWrapper::get_requested_extensions() {
84
Dictionary request_extension;
85
86
if (GDVIRTUAL_CALL(_get_requested_extensions, request_extension)) {
87
HashMap<String, bool *> result;
88
for (const KeyValue<Variant, Variant> &kv : request_extension) {
89
GDExtensionPtr<bool> value = VariantCaster<GDExtensionPtr<bool>>::cast(kv.value);
90
result.insert(kv.key, value);
91
}
92
return result;
93
}
94
95
return HashMap<String, bool *>();
96
}
97
98
void *OpenXRExtensionWrapper::set_system_properties_and_get_next_pointer(void *p_next_pointer) {
99
uint64_t pointer;
100
101
if (GDVIRTUAL_CALL(_set_system_properties_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
102
return reinterpret_cast<void *>(pointer);
103
}
104
105
return nullptr;
106
}
107
108
void *OpenXRExtensionWrapper::set_instance_create_info_and_get_next_pointer(void *p_next_pointer) {
109
uint64_t pointer;
110
111
if (GDVIRTUAL_CALL(_set_instance_create_info_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
112
return reinterpret_cast<void *>(pointer);
113
}
114
115
return nullptr;
116
}
117
118
void *OpenXRExtensionWrapper::set_session_create_and_get_next_pointer(void *p_next_pointer) {
119
uint64_t pointer;
120
121
if (GDVIRTUAL_CALL(_set_session_create_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
122
return reinterpret_cast<void *>(pointer);
123
}
124
125
return nullptr;
126
}
127
128
void *OpenXRExtensionWrapper::set_swapchain_create_info_and_get_next_pointer(void *p_next_pointer) {
129
uint64_t pointer;
130
131
if (GDVIRTUAL_CALL(_set_swapchain_create_info_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
132
return reinterpret_cast<void *>(pointer);
133
}
134
135
return nullptr;
136
}
137
138
void *OpenXRExtensionWrapper::set_hand_joint_locations_and_get_next_pointer(int p_hand_index, void *p_next_pointer) {
139
uint64_t pointer;
140
141
if (GDVIRTUAL_CALL(_set_hand_joint_locations_and_get_next_pointer, p_hand_index, GDExtensionPtr<void>(p_next_pointer), pointer)) {
142
return reinterpret_cast<void *>(pointer);
143
}
144
145
return nullptr;
146
}
147
148
void *OpenXRExtensionWrapper::set_projection_views_and_get_next_pointer(int p_view_index, void *p_next_pointer) {
149
uint64_t pointer = 0;
150
151
if (GDVIRTUAL_CALL(_set_projection_views_and_get_next_pointer, p_view_index, GDExtensionPtr<void>(p_next_pointer), pointer)) {
152
return reinterpret_cast<void *>(pointer);
153
}
154
155
return nullptr;
156
}
157
158
void *OpenXRExtensionWrapper::set_reference_space_create_info_and_get_next_pointer(int p_reference_space_type, void *p_next_pointer) {
159
uint64_t pointer = 0;
160
161
if (GDVIRTUAL_CALL(_set_reference_space_create_info_and_get_next_pointer, p_reference_space_type, GDExtensionPtr<void>(p_next_pointer), pointer)) {
162
return reinterpret_cast<void *>(pointer);
163
}
164
165
return nullptr;
166
}
167
168
void *OpenXRExtensionWrapper::set_frame_wait_info_and_get_next_pointer(void *p_next_pointer) {
169
uint64_t pointer = 0;
170
171
if (GDVIRTUAL_CALL(_set_frame_wait_info_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
172
return reinterpret_cast<void *>(pointer);
173
}
174
175
return nullptr;
176
}
177
178
void *OpenXRExtensionWrapper::set_frame_end_info_and_get_next_pointer(void *p_next_pointer) {
179
uint64_t pointer = 0;
180
181
if (GDVIRTUAL_CALL(_set_frame_end_info_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
182
return reinterpret_cast<void *>(pointer);
183
}
184
185
return nullptr;
186
}
187
188
void *OpenXRExtensionWrapper::set_view_locate_info_and_get_next_pointer(void *p_next_pointer) {
189
uint64_t pointer = 0;
190
191
if (GDVIRTUAL_CALL(_set_view_locate_info_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
192
return reinterpret_cast<void *>(pointer);
193
}
194
195
return nullptr;
196
}
197
198
PackedStringArray OpenXRExtensionWrapper::get_suggested_tracker_names() {
199
PackedStringArray ret;
200
201
if (GDVIRTUAL_CALL(_get_suggested_tracker_names, ret)) {
202
return ret;
203
}
204
205
return PackedStringArray();
206
}
207
208
int OpenXRExtensionWrapper::get_composition_layer_count() {
209
int count = 0;
210
GDVIRTUAL_CALL(_get_composition_layer_count, count);
211
return count;
212
}
213
214
XrCompositionLayerBaseHeader *OpenXRExtensionWrapper::get_composition_layer(int p_index) {
215
uint64_t pointer;
216
217
if (GDVIRTUAL_CALL(_get_composition_layer, p_index, pointer)) {
218
return reinterpret_cast<XrCompositionLayerBaseHeader *>(pointer);
219
}
220
221
return nullptr;
222
}
223
224
int OpenXRExtensionWrapper::get_composition_layer_order(int p_index) {
225
int order = 0;
226
GDVIRTUAL_CALL(_get_composition_layer_order, p_index, order);
227
return order;
228
}
229
230
void OpenXRExtensionWrapper::on_register_metadata() {
231
GDVIRTUAL_CALL(_on_register_metadata);
232
}
233
234
void OpenXRExtensionWrapper::on_before_instance_created() {
235
GDVIRTUAL_CALL(_on_before_instance_created);
236
}
237
238
void OpenXRExtensionWrapper::on_instance_created(const XrInstance p_instance) {
239
uint64_t instance = (uint64_t)p_instance;
240
GDVIRTUAL_CALL(_on_instance_created, instance);
241
}
242
243
void OpenXRExtensionWrapper::on_instance_destroyed() {
244
GDVIRTUAL_CALL(_on_instance_destroyed);
245
}
246
247
void OpenXRExtensionWrapper::on_session_created(const XrSession p_session) {
248
uint64_t session = (uint64_t)p_session;
249
GDVIRTUAL_CALL(_on_session_created, session);
250
}
251
252
void OpenXRExtensionWrapper::on_process() {
253
GDVIRTUAL_CALL(_on_process);
254
}
255
256
void OpenXRExtensionWrapper::on_sync_actions() {
257
GDVIRTUAL_CALL(_on_sync_actions);
258
}
259
260
void OpenXRExtensionWrapper::on_pre_render() {
261
GDVIRTUAL_CALL(_on_pre_render);
262
}
263
264
void OpenXRExtensionWrapper::on_main_swapchains_created() {
265
GDVIRTUAL_CALL(_on_main_swapchains_created);
266
}
267
268
void OpenXRExtensionWrapper::on_session_destroyed() {
269
GDVIRTUAL_CALL(_on_session_destroyed);
270
}
271
272
void OpenXRExtensionWrapper::on_pre_draw_viewport(RID p_render_target) {
273
GDVIRTUAL_CALL(_on_pre_draw_viewport, p_render_target);
274
}
275
276
void OpenXRExtensionWrapper::on_post_draw_viewport(RID p_render_target) {
277
GDVIRTUAL_CALL(_on_post_draw_viewport, p_render_target);
278
}
279
280
void OpenXRExtensionWrapper::on_state_idle() {
281
GDVIRTUAL_CALL(_on_state_idle);
282
}
283
284
void OpenXRExtensionWrapper::on_state_ready() {
285
GDVIRTUAL_CALL(_on_state_ready);
286
}
287
288
void OpenXRExtensionWrapper::on_state_synchronized() {
289
GDVIRTUAL_CALL(_on_state_synchronized);
290
}
291
292
void OpenXRExtensionWrapper::on_state_visible() {
293
GDVIRTUAL_CALL(_on_state_visible);
294
}
295
296
void OpenXRExtensionWrapper::on_state_focused() {
297
GDVIRTUAL_CALL(_on_state_focused);
298
}
299
300
void OpenXRExtensionWrapper::on_state_stopping() {
301
GDVIRTUAL_CALL(_on_state_stopping);
302
}
303
304
void OpenXRExtensionWrapper::on_state_loss_pending() {
305
GDVIRTUAL_CALL(_on_state_loss_pending);
306
}
307
308
void OpenXRExtensionWrapper::on_state_exiting() {
309
GDVIRTUAL_CALL(_on_state_exiting);
310
}
311
312
bool OpenXRExtensionWrapper::on_event_polled(const XrEventDataBuffer &p_event) {
313
bool event_polled;
314
315
if (GDVIRTUAL_CALL(_on_event_polled, GDExtensionConstPtr<void>(&p_event), event_polled)) {
316
return event_polled;
317
}
318
319
return false;
320
}
321
322
void *OpenXRExtensionWrapper::set_viewport_composition_layer_and_get_next_pointer(const XrCompositionLayerBaseHeader *p_layer, const Dictionary &p_property_values, void *p_next_pointer) {
323
uint64_t pointer = 0;
324
325
if (GDVIRTUAL_CALL(_set_viewport_composition_layer_and_get_next_pointer, GDExtensionConstPtr<void>(p_layer), p_property_values, GDExtensionPtr<void>(p_next_pointer), pointer)) {
326
return reinterpret_cast<void *>(pointer);
327
}
328
329
return p_next_pointer;
330
}
331
332
void OpenXRExtensionWrapper::on_viewport_composition_layer_destroyed(const XrCompositionLayerBaseHeader *p_layer) {
333
GDVIRTUAL_CALL(_on_viewport_composition_layer_destroyed, GDExtensionConstPtr<void>(p_layer));
334
}
335
336
void OpenXRExtensionWrapper::get_viewport_composition_layer_extension_properties(List<PropertyInfo> *p_property_list) {
337
TypedArray<Dictionary> properties;
338
339
if (GDVIRTUAL_CALL(_get_viewport_composition_layer_extension_properties, properties)) {
340
for (int i = 0; i < properties.size(); i++) {
341
p_property_list->push_back(PropertyInfo::from_dict(properties[i]));
342
}
343
}
344
}
345
346
Dictionary OpenXRExtensionWrapper::get_viewport_composition_layer_extension_property_defaults() {
347
Dictionary property_defaults;
348
GDVIRTUAL_CALL(_get_viewport_composition_layer_extension_property_defaults, property_defaults);
349
return property_defaults;
350
}
351
352
void *OpenXRExtensionWrapper::set_android_surface_swapchain_create_info_and_get_next_pointer(const Dictionary &p_property_values, void *p_next_pointer) {
353
uint64_t pointer = 0;
354
355
if (GDVIRTUAL_CALL(_set_android_surface_swapchain_create_info_and_get_next_pointer, p_property_values, GDExtensionPtr<void>(p_next_pointer), pointer)) {
356
return reinterpret_cast<void *>(pointer);
357
}
358
359
return p_next_pointer;
360
}
361
362
Ref<OpenXRAPIExtension> OpenXRExtensionWrapper::_gdextension_get_openxr_api() {
363
static Ref<OpenXRAPIExtension> openxr_api_extension;
364
if (unlikely(openxr_api_extension.is_null())) {
365
openxr_api_extension.instantiate();
366
}
367
return openxr_api_extension;
368
}
369
370
void OpenXRExtensionWrapper::_gdextension_register_extension_wrapper() {
371
OpenXRAPI::register_extension_wrapper(this);
372
}
373
374