diff options
Diffstat (limited to 'modules/openxr')
-rw-r--r-- | modules/openxr/extensions/openxr_android_extension.cpp | 12 | ||||
-rw-r--r-- | modules/openxr/openxr_api.cpp | 6 | ||||
-rw-r--r-- | modules/openxr/openxr_api.h | 1 | ||||
-rw-r--r-- | modules/openxr/util.h | 6 |
4 files changed, 19 insertions, 6 deletions
diff --git a/modules/openxr/extensions/openxr_android_extension.cpp b/modules/openxr/extensions/openxr_android_extension.cpp index aae284f6bd..4465daf22a 100644 --- a/modules/openxr/extensions/openxr_android_extension.cpp +++ b/modules/openxr/extensions/openxr_android_extension.cpp @@ -51,18 +51,17 @@ 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; } void OpenXRAndroidExtension::on_before_instance_created() { - if (!loader_init_extension_available) { - print_line("OpenXR: XR_KHR_loader_init_android is not reported as available - trying to initialize anyway..."); + if (XR_FAILED(EXT_TRY_INIT_XR_FUNC(xrInitializeLoaderKHR))) { + // XR_KHR_loader_init not supported on this platform + return; } - - EXT_INIT_XR_FUNC(xrInitializeLoaderKHR); + loader_init_extension_available = true; JNIEnv *env = get_jni_env(); JavaVM *vm; @@ -85,6 +84,9 @@ static XrInstanceCreateInfoAndroidKHR instance_create_info; void *OpenXRAndroidExtension::set_instance_create_info_and_get_next_pointer(void *p_next_pointer) { if (!create_instance_extension_available) { + if (!loader_init_extension_available) { + WARN_PRINT("No Android extensions available, couldn't pass JVM and Activity to OpenXR"); + } return nullptr; } diff --git a/modules/openxr/openxr_api.cpp b/modules/openxr/openxr_api.cpp index 33b3c2967f..d556f475d2 100644 --- a/modules/openxr/openxr_api.cpp +++ b/modules/openxr/openxr_api.cpp @@ -1224,8 +1224,12 @@ bool OpenXRAPI::resolve_instance_openxr_symbols() { return true; } +XrResult OpenXRAPI::try_get_instance_proc_addr(const char *p_name, PFN_xrVoidFunction *p_addr) { + return xrGetInstanceProcAddr(instance, p_name, p_addr); +} + XrResult OpenXRAPI::get_instance_proc_addr(const char *p_name, PFN_xrVoidFunction *p_addr) { - XrResult result = xrGetInstanceProcAddr(instance, p_name, p_addr); + XrResult result = try_get_instance_proc_addr(p_name, p_addr); if (result != XR_SUCCESS) { String error_message = String("Symbol ") + p_name + " not found in OpenXR instance."; diff --git a/modules/openxr/openxr_api.h b/modules/openxr/openxr_api.h index a697a5f90a..5fb8de660e 100644 --- a/modules/openxr/openxr_api.h +++ b/modules/openxr/openxr_api.h @@ -305,6 +305,7 @@ public: static bool openxr_is_enabled(bool p_check_run_in_editor = true); _FORCE_INLINE_ static OpenXRAPI *get_singleton() { return singleton; } + XrResult try_get_instance_proc_addr(const char *p_name, PFN_xrVoidFunction *p_addr); XrResult get_instance_proc_addr(const char *p_name, PFN_xrVoidFunction *p_addr); String get_error_string(XrResult result); String get_swapchain_format_name(int64_t p_swapchain_format) const; diff --git a/modules/openxr/util.h b/modules/openxr/util.h index f3fa187faa..6665d45007 100644 --- a/modules/openxr/util.h +++ b/modules/openxr/util.h @@ -53,6 +53,12 @@ #define EXT_INIT_XR_FUNC(name) INIT_XR_FUNC(OpenXRAPI::get_singleton(), name) #define OPENXR_API_INIT_XR_FUNC(name) INIT_XR_FUNC(this, name) +#define TRY_INIT_XR_FUNC(openxr_api, name) \ + openxr_api->try_get_instance_proc_addr(#name, (PFN_xrVoidFunction *)&name##_ptr) + +#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 EXT_PROTO_XRRESULT_FUNC1(func_name, arg1_type, arg1) \ PFN_##func_name func_name##_ptr = nullptr; \ XRAPI_ATTR XrResult XRAPI_CALL func_name(UNPACK arg1_type p_##arg1) const { \ |