| 1 | /**************************************************************************/ |
| 2 | /* openxr_extension_wrapper_extension.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_extension.h" |
| 32 | |
| 33 | #include "../openxr_api.h" |
| 34 | |
| 35 | void OpenXRExtensionWrapperExtension::_bind_methods() { |
| 36 | GDVIRTUAL_BIND(_get_requested_extensions); |
| 37 | GDVIRTUAL_BIND(_set_system_properties_and_get_next_pointer, "next_pointer" ); |
| 38 | GDVIRTUAL_BIND(_set_instance_create_info_and_get_next_pointer, "next_pointer" ); |
| 39 | GDVIRTUAL_BIND(_set_session_create_and_get_next_pointer, "next_pointer" ); |
| 40 | GDVIRTUAL_BIND(_set_swapchain_create_info_and_get_next_pointer, "next_pointer" ); |
| 41 | GDVIRTUAL_BIND(_on_register_metadata); |
| 42 | GDVIRTUAL_BIND(_on_before_instance_created); |
| 43 | GDVIRTUAL_BIND(_on_instance_created, "instance" ); |
| 44 | GDVIRTUAL_BIND(_on_instance_destroyed); |
| 45 | GDVIRTUAL_BIND(_on_session_created, "session" ); |
| 46 | GDVIRTUAL_BIND(_on_process); |
| 47 | GDVIRTUAL_BIND(_on_pre_render); |
| 48 | GDVIRTUAL_BIND(_on_session_destroyed); |
| 49 | GDVIRTUAL_BIND(_on_state_idle); |
| 50 | GDVIRTUAL_BIND(_on_state_ready); |
| 51 | GDVIRTUAL_BIND(_on_state_synchronized); |
| 52 | GDVIRTUAL_BIND(_on_state_visible); |
| 53 | GDVIRTUAL_BIND(_on_state_focused); |
| 54 | GDVIRTUAL_BIND(_on_state_stopping); |
| 55 | GDVIRTUAL_BIND(_on_state_loss_pending); |
| 56 | GDVIRTUAL_BIND(_on_state_exiting); |
| 57 | GDVIRTUAL_BIND(_on_event_polled, "event" ); |
| 58 | |
| 59 | ClassDB::bind_method(D_METHOD("get_openxr_api" ), &OpenXRExtensionWrapperExtension::get_openxr_api); |
| 60 | ClassDB::bind_method(D_METHOD("register_extension_wrapper" ), &OpenXRExtensionWrapperExtension::register_extension_wrapper); |
| 61 | } |
| 62 | |
| 63 | HashMap<String, bool *> OpenXRExtensionWrapperExtension::get_requested_extensions() { |
| 64 | Dictionary request_extension; |
| 65 | |
| 66 | if (GDVIRTUAL_CALL(_get_requested_extensions, request_extension)) { |
| 67 | HashMap<String, bool *> result; |
| 68 | Array keys = request_extension.keys(); |
| 69 | for (int i = 0; i < keys.size(); i++) { |
| 70 | String key = keys.get(i); |
| 71 | GDExtensionPtr<bool> value = VariantCaster<GDExtensionPtr<bool>>::cast(request_extension.get(key, GDExtensionPtr<bool>(nullptr))); |
| 72 | result.insert(key, value); |
| 73 | } |
| 74 | return result; |
| 75 | } |
| 76 | |
| 77 | return HashMap<String, bool *>(); |
| 78 | } |
| 79 | |
| 80 | void *OpenXRExtensionWrapperExtension::set_system_properties_and_get_next_pointer(void *p_next_pointer) { |
| 81 | uint64_t pointer; |
| 82 | |
| 83 | if (GDVIRTUAL_CALL(_set_system_properties_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) { |
| 84 | return reinterpret_cast<void *>(pointer); |
| 85 | } |
| 86 | |
| 87 | return nullptr; |
| 88 | } |
| 89 | |
| 90 | void *OpenXRExtensionWrapperExtension::set_instance_create_info_and_get_next_pointer(void *p_next_pointer) { |
| 91 | uint64_t pointer; |
| 92 | |
| 93 | if (GDVIRTUAL_CALL(_set_instance_create_info_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) { |
| 94 | return reinterpret_cast<void *>(pointer); |
| 95 | } |
| 96 | |
| 97 | return nullptr; |
| 98 | } |
| 99 | |
| 100 | void *OpenXRExtensionWrapperExtension::set_session_create_and_get_next_pointer(void *p_next_pointer) { |
| 101 | uint64_t pointer; |
| 102 | |
| 103 | if (GDVIRTUAL_CALL(_set_session_create_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) { |
| 104 | return reinterpret_cast<void *>(pointer); |
| 105 | } |
| 106 | |
| 107 | return nullptr; |
| 108 | } |
| 109 | |
| 110 | void *OpenXRExtensionWrapperExtension::set_swapchain_create_info_and_get_next_pointer(void *p_next_pointer) { |
| 111 | uint64_t pointer; |
| 112 | |
| 113 | if (GDVIRTUAL_CALL(_set_swapchain_create_info_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) { |
| 114 | return reinterpret_cast<void *>(pointer); |
| 115 | } |
| 116 | |
| 117 | return nullptr; |
| 118 | } |
| 119 | |
| 120 | void OpenXRExtensionWrapperExtension::on_register_metadata() { |
| 121 | GDVIRTUAL_CALL(_on_register_metadata); |
| 122 | } |
| 123 | |
| 124 | void OpenXRExtensionWrapperExtension::on_before_instance_created() { |
| 125 | GDVIRTUAL_CALL(_on_before_instance_created); |
| 126 | } |
| 127 | |
| 128 | void OpenXRExtensionWrapperExtension::on_instance_created(const XrInstance p_instance) { |
| 129 | uint64_t instance = (uint64_t)p_instance; |
| 130 | GDVIRTUAL_CALL(_on_instance_created, instance); |
| 131 | } |
| 132 | |
| 133 | void OpenXRExtensionWrapperExtension::on_instance_destroyed() { |
| 134 | GDVIRTUAL_CALL(_on_instance_destroyed); |
| 135 | } |
| 136 | |
| 137 | void OpenXRExtensionWrapperExtension::on_session_created(const XrSession p_session) { |
| 138 | uint64_t session = (uint64_t)p_session; |
| 139 | GDVIRTUAL_CALL(_on_session_created, session); |
| 140 | } |
| 141 | |
| 142 | void OpenXRExtensionWrapperExtension::on_process() { |
| 143 | GDVIRTUAL_CALL(_on_process); |
| 144 | } |
| 145 | |
| 146 | void OpenXRExtensionWrapperExtension::on_pre_render() { |
| 147 | GDVIRTUAL_CALL(_on_pre_render); |
| 148 | } |
| 149 | |
| 150 | void OpenXRExtensionWrapperExtension::on_session_destroyed() { |
| 151 | GDVIRTUAL_CALL(_on_session_destroyed); |
| 152 | } |
| 153 | |
| 154 | void OpenXRExtensionWrapperExtension::on_state_idle() { |
| 155 | GDVIRTUAL_CALL(_on_state_idle); |
| 156 | } |
| 157 | |
| 158 | void OpenXRExtensionWrapperExtension::on_state_ready() { |
| 159 | GDVIRTUAL_CALL(_on_state_ready); |
| 160 | } |
| 161 | |
| 162 | void OpenXRExtensionWrapperExtension::on_state_synchronized() { |
| 163 | GDVIRTUAL_CALL(_on_state_synchronized); |
| 164 | } |
| 165 | |
| 166 | void OpenXRExtensionWrapperExtension::on_state_visible() { |
| 167 | GDVIRTUAL_CALL(_on_state_visible); |
| 168 | } |
| 169 | |
| 170 | void OpenXRExtensionWrapperExtension::on_state_focused() { |
| 171 | GDVIRTUAL_CALL(_on_state_focused); |
| 172 | } |
| 173 | |
| 174 | void OpenXRExtensionWrapperExtension::on_state_stopping() { |
| 175 | GDVIRTUAL_CALL(_on_state_stopping); |
| 176 | } |
| 177 | |
| 178 | void OpenXRExtensionWrapperExtension::on_state_loss_pending() { |
| 179 | GDVIRTUAL_CALL(_on_state_loss_pending); |
| 180 | } |
| 181 | |
| 182 | void OpenXRExtensionWrapperExtension::on_state_exiting() { |
| 183 | GDVIRTUAL_CALL(_on_state_exiting); |
| 184 | } |
| 185 | |
| 186 | bool OpenXRExtensionWrapperExtension::on_event_polled(const XrEventDataBuffer &p_event) { |
| 187 | bool event_polled; |
| 188 | |
| 189 | if (GDVIRTUAL_CALL(_on_event_polled, GDExtensionConstPtr<void>(&p_event), event_polled)) { |
| 190 | return event_polled; |
| 191 | } |
| 192 | |
| 193 | return false; |
| 194 | } |
| 195 | |
| 196 | Ref<OpenXRAPIExtension> OpenXRExtensionWrapperExtension::get_openxr_api() { |
| 197 | return openxr_api; |
| 198 | } |
| 199 | |
| 200 | void OpenXRExtensionWrapperExtension::register_extension_wrapper() { |
| 201 | OpenXRAPI::register_extension_wrapper(this); |
| 202 | } |
| 203 | |
| 204 | OpenXRExtensionWrapperExtension::OpenXRExtensionWrapperExtension() : |
| 205 | Object(), OpenXRExtensionWrapper() { |
| 206 | openxr_api.instantiate(); |
| 207 | } |
| 208 | |