summaryrefslogtreecommitdiffstats
path: root/modules/openxr
diff options
context:
space:
mode:
authorYuri Sizov <yuris@humnom.net>2023-07-27 15:22:22 +0200
committerYuri Sizov <yuris@humnom.net>2023-07-27 15:22:22 +0200
commit37c3e2e55bed4e290d1551d90300f785e1932593 (patch)
treebf733f0a3918251aa3055251497e144b4b9f2583 /modules/openxr
parent0c2399d6ecc69c923d0bc480c29767df29b5f68d (diff)
parentd600e6eb1bc0aad51b61a42ac18861696e63732a (diff)
downloadredot-engine-37c3e2e55bed4e290d1551d90300f785e1932593.tar.gz
Merge pull request #68259 from konczg/openxr_extension_wrapper_gdextension
Add GDExtension support for OpenXR extension wrappers
Diffstat (limited to 'modules/openxr')
-rw-r--r--modules/openxr/SCsub2
-rw-r--r--modules/openxr/extensions/openxr_android_extension.cpp1
-rw-r--r--modules/openxr/extensions/openxr_extension_wrapper_extension.cpp207
-rw-r--r--modules/openxr/extensions/openxr_extension_wrapper_extension.h115
-rw-r--r--modules/openxr/openxr_api.cpp1
-rw-r--r--modules/openxr/openxr_api_extension.cpp130
-rw-r--r--modules/openxr/openxr_api_extension.h76
-rw-r--r--modules/openxr/register_types.cpp8
-rw-r--r--modules/openxr/util.h11
9 files changed, 551 insertions, 0 deletions
diff --git a/modules/openxr/SCsub b/modules/openxr/SCsub
index fbff4c7f8f..f49dc390de 100644
--- a/modules/openxr/SCsub
+++ b/modules/openxr/SCsub
@@ -114,6 +114,8 @@ env_openxr.add_source_files(module_obj, "extensions/openxr_fb_display_refresh_ra
env_openxr.add_source_files(module_obj, "extensions/openxr_pico_controller_extension.cpp")
env_openxr.add_source_files(module_obj, "extensions/openxr_wmr_controller_extension.cpp")
env_openxr.add_source_files(module_obj, "extensions/openxr_ml2_controller_extension.cpp")
+env_openxr.add_source_files(module_obj, "extensions/openxr_extension_wrapper_extension.cpp")
+env_openxr.add_source_files(module_obj, "extensions/openxr_api_extension.cpp")
env.modules_sources += module_obj
diff --git a/modules/openxr/extensions/openxr_android_extension.cpp b/modules/openxr/extensions/openxr_android_extension.cpp
index 98687d5f20..c6082ca404 100644
--- a/modules/openxr/extensions/openxr_android_extension.cpp
+++ b/modules/openxr/extensions/openxr_android_extension.cpp
@@ -53,6 +53,7 @@ OpenXRAndroidExtension::OpenXRAndroidExtension() {
HashMap<String, bool *> OpenXRAndroidExtension::get_requested_extensions() {
HashMap<String, bool *> request_extensions;
+ request_extensions[XR_KHR_LOADER_INIT_ANDROID_EXTENSION_NAME] = &loader_init_extension_available;
request_extensions[XR_KHR_ANDROID_CREATE_INSTANCE_EXTENSION_NAME] = &create_instance_extension_available;
return request_extensions;
diff --git a/modules/openxr/extensions/openxr_extension_wrapper_extension.cpp b/modules/openxr/extensions/openxr_extension_wrapper_extension.cpp
new file mode 100644
index 0000000000..81ba9c56b8
--- /dev/null
+++ b/modules/openxr/extensions/openxr_extension_wrapper_extension.cpp
@@ -0,0 +1,207 @@
+/**************************************************************************/
+/* openxr_extension_wrapper_extension.cpp */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/**************************************************************************/
+
+#include "openxr_extension_wrapper_extension.h"
+
+#include "../openxr_api.h"
+
+void OpenXRExtensionWrapperExtension::_bind_methods() {
+ GDVIRTUAL_BIND(_get_requested_extensions);
+ GDVIRTUAL_BIND(_set_system_properties_and_get_next_pointer, "next_pointer");
+ GDVIRTUAL_BIND(_set_instance_create_info_and_get_next_pointer, "next_pointer");
+ GDVIRTUAL_BIND(_set_session_create_and_get_next_pointer, "next_pointer");
+ GDVIRTUAL_BIND(_set_swapchain_create_info_and_get_next_pointer, "next_pointer");
+ GDVIRTUAL_BIND(_on_register_metadata);
+ GDVIRTUAL_BIND(_on_before_instance_created);
+ GDVIRTUAL_BIND(_on_instance_created, "instance");
+ GDVIRTUAL_BIND(_on_instance_destroyed);
+ GDVIRTUAL_BIND(_on_session_created, "session");
+ GDVIRTUAL_BIND(_on_process);
+ GDVIRTUAL_BIND(_on_pre_render);
+ GDVIRTUAL_BIND(_on_session_destroyed);
+ GDVIRTUAL_BIND(_on_state_idle);
+ GDVIRTUAL_BIND(_on_state_ready);
+ GDVIRTUAL_BIND(_on_state_synchronized);
+ GDVIRTUAL_BIND(_on_state_visible);
+ GDVIRTUAL_BIND(_on_state_focused);
+ GDVIRTUAL_BIND(_on_state_stopping);
+ GDVIRTUAL_BIND(_on_state_loss_pending);
+ GDVIRTUAL_BIND(_on_state_exiting);
+ GDVIRTUAL_BIND(_on_event_polled, "event");
+
+ ClassDB::bind_method(D_METHOD("get_openxr_api"), &OpenXRExtensionWrapperExtension::get_openxr_api);
+ ClassDB::bind_method(D_METHOD("register_extension_wrapper"), &OpenXRExtensionWrapperExtension::register_extension_wrapper);
+}
+
+HashMap<String, bool *> OpenXRExtensionWrapperExtension::get_requested_extensions() {
+ Dictionary request_extension;
+
+ if (GDVIRTUAL_CALL(_get_requested_extensions, request_extension)) {
+ HashMap<String, bool *> result;
+ Array keys = request_extension.keys();
+ for (int i = 0; i < keys.size(); i++) {
+ String key = keys.get(i);
+ GDExtensionPtr<bool> value = VariantCaster<GDExtensionPtr<bool>>::cast(request_extension.get(key, GDExtensionPtr<bool>(nullptr)));
+ result.insert(key, value);
+ }
+ return result;
+ }
+
+ return HashMap<String, bool *>();
+}
+
+void *OpenXRExtensionWrapperExtension::set_system_properties_and_get_next_pointer(void *p_next_pointer) {
+ uint64_t pointer;
+
+ if (GDVIRTUAL_CALL(_set_system_properties_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
+ return reinterpret_cast<void *>(pointer);
+ }
+
+ return nullptr;
+}
+
+void *OpenXRExtensionWrapperExtension::set_instance_create_info_and_get_next_pointer(void *p_next_pointer) {
+ uint64_t pointer;
+
+ if (GDVIRTUAL_CALL(_set_instance_create_info_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
+ return reinterpret_cast<void *>(pointer);
+ }
+
+ return nullptr;
+}
+
+void *OpenXRExtensionWrapperExtension::set_session_create_and_get_next_pointer(void *p_next_pointer) {
+ uint64_t pointer;
+
+ if (GDVIRTUAL_CALL(_set_session_create_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
+ return reinterpret_cast<void *>(pointer);
+ }
+
+ return nullptr;
+}
+
+void *OpenXRExtensionWrapperExtension::set_swapchain_create_info_and_get_next_pointer(void *p_next_pointer) {
+ uint64_t pointer;
+
+ if (GDVIRTUAL_CALL(_set_swapchain_create_info_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
+ return reinterpret_cast<void *>(pointer);
+ }
+
+ return nullptr;
+}
+
+void OpenXRExtensionWrapperExtension::on_register_metadata() {
+ GDVIRTUAL_CALL(_on_register_metadata);
+}
+
+void OpenXRExtensionWrapperExtension::on_before_instance_created() {
+ GDVIRTUAL_CALL(_on_before_instance_created);
+}
+
+void OpenXRExtensionWrapperExtension::on_instance_created(const XrInstance p_instance) {
+ uint64_t instance = reinterpret_cast<uint64_t>(p_instance);
+ GDVIRTUAL_CALL(_on_instance_created, instance);
+}
+
+void OpenXRExtensionWrapperExtension::on_instance_destroyed() {
+ GDVIRTUAL_CALL(_on_instance_destroyed);
+}
+
+void OpenXRExtensionWrapperExtension::on_session_created(const XrSession p_session) {
+ uint64_t session = reinterpret_cast<uint64_t>(p_session);
+ GDVIRTUAL_CALL(_on_session_created, session);
+}
+
+void OpenXRExtensionWrapperExtension::on_process() {
+ GDVIRTUAL_CALL(_on_process);
+}
+
+void OpenXRExtensionWrapperExtension::on_pre_render() {
+ GDVIRTUAL_CALL(_on_pre_render);
+}
+
+void OpenXRExtensionWrapperExtension::on_session_destroyed() {
+ GDVIRTUAL_CALL(_on_session_destroyed);
+}
+
+void OpenXRExtensionWrapperExtension::on_state_idle() {
+ GDVIRTUAL_CALL(_on_state_idle);
+}
+
+void OpenXRExtensionWrapperExtension::on_state_ready() {
+ GDVIRTUAL_CALL(_on_state_ready);
+}
+
+void OpenXRExtensionWrapperExtension::on_state_synchronized() {
+ GDVIRTUAL_CALL(_on_state_synchronized);
+}
+
+void OpenXRExtensionWrapperExtension::on_state_visible() {
+ GDVIRTUAL_CALL(_on_state_visible);
+}
+
+void OpenXRExtensionWrapperExtension::on_state_focused() {
+ GDVIRTUAL_CALL(_on_state_focused);
+}
+
+void OpenXRExtensionWrapperExtension::on_state_stopping() {
+ GDVIRTUAL_CALL(_on_state_stopping);
+}
+
+void OpenXRExtensionWrapperExtension::on_state_loss_pending() {
+ GDVIRTUAL_CALL(_on_state_loss_pending);
+}
+
+void OpenXRExtensionWrapperExtension::on_state_exiting() {
+ GDVIRTUAL_CALL(_on_state_exiting);
+}
+
+bool OpenXRExtensionWrapperExtension::on_event_polled(const XrEventDataBuffer &p_event) {
+ bool event_polled;
+
+ if (GDVIRTUAL_CALL(_on_event_polled, GDExtensionConstPtr<void>(&p_event), event_polled)) {
+ return event_polled;
+ }
+
+ return false;
+}
+
+Ref<OpenXRAPIExtension> OpenXRExtensionWrapperExtension::get_openxr_api() {
+ return openxr_api;
+}
+
+void OpenXRExtensionWrapperExtension::register_extension_wrapper() {
+ OpenXRAPI::register_extension_wrapper(this);
+}
+
+OpenXRExtensionWrapperExtension::OpenXRExtensionWrapperExtension() :
+ Object(), OpenXRExtensionWrapper() {
+ openxr_api.instantiate();
+}
diff --git a/modules/openxr/extensions/openxr_extension_wrapper_extension.h b/modules/openxr/extensions/openxr_extension_wrapper_extension.h
new file mode 100644
index 0000000000..5c5e64f927
--- /dev/null
+++ b/modules/openxr/extensions/openxr_extension_wrapper_extension.h
@@ -0,0 +1,115 @@
+/**************************************************************************/
+/* openxr_extension_wrapper_extension.h */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/**************************************************************************/
+
+#ifndef OPENXR_EXTENSION_WRAPPER_EXTENSION_H
+#define OPENXR_EXTENSION_WRAPPER_EXTENSION_H
+
+#include "../openxr_api_extension.h"
+#include "openxr_extension_wrapper.h"
+
+#include "core/object/ref_counted.h"
+#include "core/os/os.h"
+#include "core/os/thread_safe.h"
+#include "core/variant/native_ptr.h"
+
+class OpenXRExtensionWrapperExtension : public Object, OpenXRExtensionWrapper {
+ GDCLASS(OpenXRExtensionWrapperExtension, Object);
+
+protected:
+ _THREAD_SAFE_CLASS_
+
+ static void _bind_methods();
+
+ Ref<OpenXRAPIExtension> openxr_api;
+
+public:
+ virtual HashMap<String, bool *> get_requested_extensions() override;
+
+ GDVIRTUAL0R(Dictionary, _get_requested_extensions);
+
+ virtual void *set_system_properties_and_get_next_pointer(void *p_next_pointer) override;
+ virtual void *set_instance_create_info_and_get_next_pointer(void *p_next_pointer) override;
+ virtual void *set_session_create_and_get_next_pointer(void *p_next_pointer) override;
+ virtual void *set_swapchain_create_info_and_get_next_pointer(void *p_next_pointer) override;
+
+ //TODO workaround as GDExtensionPtr<void> return type results in build error in godot-cpp
+ GDVIRTUAL1R(uint64_t, _set_system_properties_and_get_next_pointer, GDExtensionPtr<void>);
+ GDVIRTUAL1R(uint64_t, _set_instance_create_info_and_get_next_pointer, GDExtensionPtr<void>);
+ GDVIRTUAL1R(uint64_t, _set_session_create_and_get_next_pointer, GDExtensionPtr<void>);
+ GDVIRTUAL1R(uint64_t, _set_swapchain_create_info_and_get_next_pointer, GDExtensionPtr<void>);
+
+ virtual void on_register_metadata() override;
+ virtual void on_before_instance_created() override;
+ virtual void on_instance_created(const XrInstance p_instance) override;
+ virtual void on_instance_destroyed() override;
+ virtual void on_session_created(const XrSession p_session) override;
+ virtual void on_process() override;
+ virtual void on_pre_render() override;
+ virtual void on_session_destroyed() override;
+
+ GDVIRTUAL0(_on_register_metadata);
+ GDVIRTUAL0(_on_before_instance_created);
+ GDVIRTUAL1(_on_instance_created, uint64_t);
+ GDVIRTUAL0(_on_instance_destroyed);
+ GDVIRTUAL1(_on_session_created, uint64_t);
+ GDVIRTUAL0(_on_process);
+ GDVIRTUAL0(_on_pre_render);
+ GDVIRTUAL0(_on_session_destroyed);
+
+ virtual void on_state_idle() override;
+ virtual void on_state_ready() override;
+ virtual void on_state_synchronized() override;
+ virtual void on_state_visible() override;
+ virtual void on_state_focused() override;
+ virtual void on_state_stopping() override;
+ virtual void on_state_loss_pending() override;
+ virtual void on_state_exiting() override;
+
+ GDVIRTUAL0(_on_state_idle);
+ GDVIRTUAL0(_on_state_ready);
+ GDVIRTUAL0(_on_state_synchronized);
+ GDVIRTUAL0(_on_state_visible);
+ GDVIRTUAL0(_on_state_focused);
+ GDVIRTUAL0(_on_state_stopping);
+ GDVIRTUAL0(_on_state_loss_pending);
+ GDVIRTUAL0(_on_state_exiting);
+
+ virtual bool on_event_polled(const XrEventDataBuffer &p_event) override;
+
+ GDVIRTUAL1R(bool, _on_event_polled, GDExtensionConstPtr<void>);
+
+ Ref<OpenXRAPIExtension> get_openxr_api();
+
+ void register_extension_wrapper();
+
+ OpenXRExtensionWrapperExtension();
+};
+
+#endif // OPENXR_EXTENSION_WRAPPER_EXTENSION_H
diff --git a/modules/openxr/openxr_api.cpp b/modules/openxr/openxr_api.cpp
index c5efe609c2..91684b55b9 100644
--- a/modules/openxr/openxr_api.cpp
+++ b/modules/openxr/openxr_api.cpp
@@ -30,6 +30,7 @@
#include "openxr_api.h"
+#include "extensions/openxr_extension_wrapper_extension.h"
#include "openxr_interface.h"
#include "openxr_util.h"
diff --git a/modules/openxr/openxr_api_extension.cpp b/modules/openxr/openxr_api_extension.cpp
new file mode 100644
index 0000000000..f0f0835f78
--- /dev/null
+++ b/modules/openxr/openxr_api_extension.cpp
@@ -0,0 +1,130 @@
+/**************************************************************************/
+/* openxr_api_extension.cpp */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/**************************************************************************/
+
+#include "openxr_api_extension.h"
+
+void OpenXRAPIExtension::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("get_instance"), &OpenXRAPIExtension::get_instance);
+ ClassDB::bind_method(D_METHOD("get_system_id"), &OpenXRAPIExtension::get_system_id);
+ ClassDB::bind_method(D_METHOD("get_session"), &OpenXRAPIExtension::get_session);
+
+ ClassDB::bind_method(D_METHOD("transform_from_pose", "pose"), &OpenXRAPIExtension::transform_from_pose);
+ ClassDB::bind_method(D_METHOD("xr_result", "result", "format", "args"), &OpenXRAPIExtension::xr_result);
+ ClassDB::bind_static_method("OpenXRAPIExtension", D_METHOD("openxr_is_enabled", "check_run_in_editor"), &OpenXRAPIExtension::openxr_is_enabled);
+ ClassDB::bind_method(D_METHOD("get_instance_proc_addr", "name"), &OpenXRAPIExtension::get_instance_proc_addr);
+ ClassDB::bind_method(D_METHOD("get_error_string", "result"), &OpenXRAPIExtension::get_error_string);
+ ClassDB::bind_method(D_METHOD("get_swapchain_format_name", "swapchain_format"), &OpenXRAPIExtension::get_swapchain_format_name);
+
+ ClassDB::bind_method(D_METHOD("is_initialized"), &OpenXRAPIExtension::is_initialized);
+ ClassDB::bind_method(D_METHOD("is_running"), &OpenXRAPIExtension::is_running);
+
+ ClassDB::bind_method(D_METHOD("get_play_space"), &OpenXRAPIExtension::get_play_space);
+ ClassDB::bind_method(D_METHOD("get_next_frame_time"), &OpenXRAPIExtension::get_next_frame_time);
+ ClassDB::bind_method(D_METHOD("can_render"), &OpenXRAPIExtension::can_render);
+}
+
+uint64_t OpenXRAPIExtension::get_instance() {
+ ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), 0);
+ return (uint64_t)OpenXRAPI::get_singleton()->get_instance();
+}
+
+uint64_t OpenXRAPIExtension::get_system_id() {
+ ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), 0);
+ return (uint64_t)OpenXRAPI::get_singleton()->get_system_id();
+}
+
+uint64_t OpenXRAPIExtension::get_session() {
+ ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), 0);
+ return (uint64_t)OpenXRAPI::get_singleton()->get_session();
+}
+
+Transform3D OpenXRAPIExtension::transform_from_pose(GDExtensionConstPtr<const void> p_pose) {
+ ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), Transform3D());
+ return OpenXRAPI::get_singleton()->transform_from_pose(*(XrPosef *)p_pose.data);
+}
+
+bool OpenXRAPIExtension::xr_result(uint64_t result, String format, Array args) {
+ ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), false);
+ return OpenXRAPI::get_singleton()->xr_result((XrResult)result, format.utf8().get_data(), args);
+}
+
+bool OpenXRAPIExtension::openxr_is_enabled(bool p_check_run_in_editor) {
+ ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), false);
+ return OpenXRAPI::openxr_is_enabled(p_check_run_in_editor);
+}
+
+uint64_t OpenXRAPIExtension::get_instance_proc_addr(String p_name) {
+ ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), 0);
+ CharString str = p_name.utf8();
+ PFN_xrVoidFunction addr = nullptr;
+ XrResult result = OpenXRAPI::get_singleton()->get_instance_proc_addr(str.get_data(), &addr);
+ if (result != XR_SUCCESS) {
+ return 0;
+ }
+ return reinterpret_cast<uint64_t>(addr);
+}
+
+String OpenXRAPIExtension::get_error_string(uint64_t result) {
+ ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), String());
+ return OpenXRAPI::get_singleton()->get_error_string((XrResult)result);
+}
+
+String OpenXRAPIExtension::get_swapchain_format_name(int64_t p_swapchain_format) {
+ ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), String());
+ return OpenXRAPI::get_singleton()->get_swapchain_format_name(p_swapchain_format);
+}
+
+bool OpenXRAPIExtension::is_initialized() {
+ ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), false);
+ return OpenXRAPI::get_singleton()->is_initialized();
+}
+
+bool OpenXRAPIExtension::is_running() {
+ ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), false);
+ return OpenXRAPI::get_singleton()->is_running();
+}
+
+uint64_t OpenXRAPIExtension::get_play_space() {
+ ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), 0);
+ return (uint64_t)OpenXRAPI::get_singleton()->get_play_space();
+}
+
+int64_t OpenXRAPIExtension::get_next_frame_time() {
+ ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), 0);
+ return (XrTime)OpenXRAPI::get_singleton()->get_next_frame_time();
+}
+
+bool OpenXRAPIExtension::can_render() {
+ ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), false);
+ return OpenXRAPI::get_singleton()->can_render();
+}
+
+OpenXRAPIExtension::OpenXRAPIExtension() {
+}
diff --git a/modules/openxr/openxr_api_extension.h b/modules/openxr/openxr_api_extension.h
new file mode 100644
index 0000000000..98f87c7aa1
--- /dev/null
+++ b/modules/openxr/openxr_api_extension.h
@@ -0,0 +1,76 @@
+/**************************************************************************/
+/* openxr_api_extension.h */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/**************************************************************************/
+
+#ifndef OPENXR_API_EXTENSION_H
+#define OPENXR_API_EXTENSION_H
+
+#include "openxr_api.h"
+
+#include "core/object/ref_counted.h"
+#include "core/os/os.h"
+#include "core/os/thread_safe.h"
+#include "core/variant/native_ptr.h"
+
+class OpenXRAPIExtension : public RefCounted {
+ GDCLASS(OpenXRAPIExtension, RefCounted);
+
+protected:
+ _THREAD_SAFE_CLASS_
+
+ static void _bind_methods();
+
+public:
+ uint64_t get_instance();
+ uint64_t get_system_id();
+ uint64_t get_session();
+
+ // Helper method to convert an XrPosef to a Transform3D.
+ Transform3D transform_from_pose(GDExtensionConstPtr<const void> p_pose);
+
+ bool xr_result(uint64_t result, String format, Array args = Array());
+
+ static bool openxr_is_enabled(bool p_check_run_in_editor = true);
+
+ //TODO workaround as GDExtensionPtr<void> return type results in build error in godot-cpp
+ uint64_t get_instance_proc_addr(String p_name);
+ String get_error_string(uint64_t result);
+ String get_swapchain_format_name(int64_t p_swapchain_format);
+
+ bool is_initialized();
+ bool is_running();
+
+ uint64_t get_play_space();
+ int64_t get_next_frame_time();
+ bool can_render();
+
+ OpenXRAPIExtension();
+};
+
+#endif // OPENXR_API_EXTENSION_H
diff --git a/modules/openxr/register_types.cpp b/modules/openxr/register_types.cpp
index 27b179a788..5d636c2b70 100644
--- a/modules/openxr/register_types.cpp
+++ b/modules/openxr/register_types.cpp
@@ -36,6 +36,9 @@
#include "action_map/openxr_interaction_profile.h"
#include "action_map/openxr_interaction_profile_meta_data.h"
#include "openxr_interface.h"
+
+#include "extensions/openxr_extension_wrapper_extension.h"
+
#include "scene/openxr_hand.h"
#include "extensions/openxr_composition_layer_depth_extension.h"
@@ -87,6 +90,11 @@ static void _editor_init() {
#endif
void initialize_openxr_module(ModuleInitializationLevel p_level) {
+ if (p_level == MODULE_INITIALIZATION_LEVEL_CORE) {
+ GDREGISTER_CLASS(OpenXRExtensionWrapperExtension);
+ GDREGISTER_CLASS(OpenXRAPIExtension);
+ }
+
if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS) {
if (OpenXRAPI::openxr_is_enabled(false)) {
// Always register our extension wrappers even if we don't initialize OpenXR.
diff --git a/modules/openxr/util.h b/modules/openxr/util.h
index 6665d45007..d95bc3bb8e 100644
--- a/modules/openxr/util.h
+++ b/modules/openxr/util.h
@@ -58,6 +58,17 @@
#define EXT_TRY_INIT_XR_FUNC(name) TRY_INIT_XR_FUNC(OpenXRAPI::get_singleton(), name)
#define OPENXR_TRY_API_INIT_XR_FUNC(name) TRY_INIT_XR_FUNC(this, name)
+#define GDEXTENSION_INIT_XR_FUNC(name) \
+ do { \
+ name##_ptr = reinterpret_cast<PFN_##name>(get_openxr_api()->get_instance_proc_addr(#name)); \
+ ERR_FAIL_COND(name##_ptr == nullptr); \
+ } while (0)
+
+#define GDEXTENSION_INIT_XR_FUNC_V(name) \
+ do { \
+ name##_ptr = reinterpret_cast<PFN_##name>(get_openxr_api()->get_instance_proc_addr(#name)); \
+ ERR_FAIL_COND_V(name##_ptr == nullptr, false); \
+ } while (0)
#define EXT_PROTO_XRRESULT_FUNC1(func_name, arg1_type, arg1) \
PFN_##func_name func_name##_ptr = nullptr; \