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