summaryrefslogtreecommitdiff
path: root/modules/openxr/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'modules/openxr/extensions')
-rw-r--r--modules/openxr/extensions/openxr_android_extension.cpp30
-rw-r--r--modules/openxr/extensions/openxr_android_extension.h4
-rw-r--r--modules/openxr/extensions/openxr_extension_wrapper.h1
-rw-r--r--modules/openxr/extensions/openxr_htc_vive_tracker_extension.cpp2
-rw-r--r--modules/openxr/extensions/openxr_opengl_extension.cpp152
-rw-r--r--modules/openxr/extensions/openxr_opengl_extension.h5
6 files changed, 88 insertions, 106 deletions
diff --git a/modules/openxr/extensions/openxr_android_extension.cpp b/modules/openxr/extensions/openxr_android_extension.cpp
index 8f6d5c28db..753fc5fa89 100644
--- a/modules/openxr/extensions/openxr_android_extension.cpp
+++ b/modules/openxr/extensions/openxr_android_extension.cpp
@@ -47,10 +47,15 @@ OpenXRAndroidExtension *OpenXRAndroidExtension::get_singleton() {
OpenXRAndroidExtension::OpenXRAndroidExtension(OpenXRAPI *p_openxr_api) :
OpenXRExtensionWrapper(p_openxr_api) {
singleton = this;
- request_extensions[XR_KHR_ANDROID_THREAD_SETTINGS_EXTENSION_NAME] = nullptr; // must be available
+ 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;
}
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...");
+ }
+
EXT_INIT_XR_FUNC(xrInitializeLoaderKHR);
JNIEnv *env = get_jni_env();
@@ -68,6 +73,29 @@ void OpenXRAndroidExtension::on_before_instance_created() {
ERR_FAIL_COND_MSG(XR_FAILED(result), "Failed to call xrInitializeLoaderKHR");
}
+// We're keeping the Android create info struct here to avoid including openxr_platform.h in a header, which would break other extensions.
+// This is reasonably safe as the struct is only used during intialization and the extension is a singleton.
+static XrInstanceCreateInfoAndroidKHR instance_create_info;
+
+void *OpenXRAndroidExtension::set_instance_create_info_and_get_next_pointer(void *p_next_pointer) {
+ if (!create_instance_extension_available) {
+ return nullptr;
+ }
+
+ JNIEnv *env = get_jni_env();
+ JavaVM *vm;
+ env->GetJavaVM(&vm);
+ jobject activity_object = env->NewGlobalRef(static_cast<OS_Android *>(OS::get_singleton())->get_godot_java()->get_activity());
+
+ instance_create_info = {
+ .type = XR_TYPE_INSTANCE_CREATE_INFO_ANDROID_KHR,
+ .next = p_next_pointer,
+ .applicationVM = vm,
+ .applicationActivity = activity_object
+ };
+ return &instance_create_info;
+}
+
OpenXRAndroidExtension::~OpenXRAndroidExtension() {
singleton = nullptr;
}
diff --git a/modules/openxr/extensions/openxr_android_extension.h b/modules/openxr/extensions/openxr_android_extension.h
index eda7022064..087b634756 100644
--- a/modules/openxr/extensions/openxr_android_extension.h
+++ b/modules/openxr/extensions/openxr_android_extension.h
@@ -41,12 +41,16 @@ public:
OpenXRAndroidExtension(OpenXRAPI *p_openxr_api);
virtual void on_before_instance_created() override;
+ virtual void *set_instance_create_info_and_get_next_pointer(void *p_next_pointer) override;
virtual ~OpenXRAndroidExtension() override;
private:
static OpenXRAndroidExtension *singleton;
+ bool loader_init_extension_available = false;
+ bool create_instance_extension_available = false;
+
// Initialize the loader
EXT_PROTO_XRRESULT_FUNC1(xrInitializeLoaderKHR, (const XrLoaderInitInfoBaseHeaderKHR *), loaderInitInfo)
};
diff --git a/modules/openxr/extensions/openxr_extension_wrapper.h b/modules/openxr/extensions/openxr_extension_wrapper.h
index c417c90d11..77b52ab355 100644
--- a/modules/openxr/extensions/openxr_extension_wrapper.h
+++ b/modules/openxr/extensions/openxr_extension_wrapper.h
@@ -65,6 +65,7 @@ public:
virtual void *set_system_properties_and_get_next_pointer(void *p_next_pointer) { return p_next_pointer; }
virtual void *set_session_create_and_get_next_pointer(void *p_next_pointer) { return p_next_pointer; }
virtual void *set_swapchain_create_info_and_get_next_pointer(void *p_next_pointer) { return p_next_pointer; }
+ virtual void *set_instance_create_info_and_get_next_pointer(void *p_next_pointer) { return p_next_pointer; }
virtual void on_before_instance_created() {}
virtual void on_instance_created(const XrInstance p_instance) {}
diff --git a/modules/openxr/extensions/openxr_htc_vive_tracker_extension.cpp b/modules/openxr/extensions/openxr_htc_vive_tracker_extension.cpp
index 4d996e6283..29208efb20 100644
--- a/modules/openxr/extensions/openxr_htc_vive_tracker_extension.cpp
+++ b/modules/openxr/extensions/openxr_htc_vive_tracker_extension.cpp
@@ -91,8 +91,6 @@ bool OpenXRHTCViveTrackerExtension::is_path_supported(const String &p_path) {
return available;
} else if (p_path == "/user/vive_tracker_htcx/role/chest") {
return available;
- } else if (p_path == "/user/vive_tracker_htcx/role/chest") {
- return available;
} else if (p_path == "/user/vive_tracker_htcx/role/camera") {
return available;
} else if (p_path == "/user/vive_tracker_htcx/role/keyboard") {
diff --git a/modules/openxr/extensions/openxr_opengl_extension.cpp b/modules/openxr/extensions/openxr_opengl_extension.cpp
index ee69144123..234c5f8391 100644
--- a/modules/openxr/extensions/openxr_opengl_extension.cpp
+++ b/modules/openxr/extensions/openxr_opengl_extension.cpp
@@ -138,7 +138,7 @@ void *OpenXROpenGLExtension::set_session_create_and_get_next_pointer(void *p_nex
graphics_binding_gl.display = eglGetCurrentDisplay();
graphics_binding_gl.config = (EGLConfig)0; // https://github.com/KhronosGroup/OpenXR-SDK-Source/blob/master/src/tests/hello_xr/graphicsplugin_opengles.cpp#L122
- graphics_binding_gl.context = eglGetCurrentContext();
+ graphics_binding_gl.context = (void *)display_server->window_get_native_handle(DisplayServer::OPENGL_CONTEXT);
#else
graphics_binding_gl.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR;
graphics_binding_gl.next = p_next_pointer;
@@ -160,16 +160,8 @@ void *OpenXROpenGLExtension::set_session_create_and_get_next_pointer(void *p_nex
}
void OpenXROpenGLExtension::get_usable_swapchain_formats(Vector<int64_t> &p_usable_swap_chains) {
-#ifdef WIN32
- p_usable_swap_chains.push_back(GL_SRGB8_ALPHA8);
- p_usable_swap_chains.push_back(GL_RGBA8);
-#elif ANDROID_ENABLED
p_usable_swap_chains.push_back(GL_SRGB8_ALPHA8);
p_usable_swap_chains.push_back(GL_RGBA8);
-#else
- p_usable_swap_chains.push_back(GL_SRGB8_ALPHA8_EXT);
- p_usable_swap_chains.push_back(GL_RGBA8_EXT);
-#endif
}
void OpenXROpenGLExtension::get_usable_depth_formats(Vector<int64_t> &p_usable_depth_formats) {
@@ -294,59 +286,7 @@ void OpenXROpenGLExtension::cleanup_swapchain_graphics_data(void **p_swapchain_g
String OpenXROpenGLExtension::get_swapchain_format_name(int64_t p_swapchain_format) const {
// These are somewhat different per platform, will need to weed some stuff out...
switch (p_swapchain_format) {
-#ifdef WIN32
- // using definitions from GLAD
- ENUM_TO_STRING_CASE(GL_R8_SNORM)
- ENUM_TO_STRING_CASE(GL_RG8_SNORM)
- ENUM_TO_STRING_CASE(GL_RGB8_SNORM)
- ENUM_TO_STRING_CASE(GL_RGBA8_SNORM)
- ENUM_TO_STRING_CASE(GL_R16_SNORM)
- ENUM_TO_STRING_CASE(GL_RG16_SNORM)
- ENUM_TO_STRING_CASE(GL_RGB16_SNORM)
- ENUM_TO_STRING_CASE(GL_RGBA16_SNORM)
- ENUM_TO_STRING_CASE(GL_RGB4)
- ENUM_TO_STRING_CASE(GL_RGB5)
- ENUM_TO_STRING_CASE(GL_RGB8)
- ENUM_TO_STRING_CASE(GL_RGB10)
- ENUM_TO_STRING_CASE(GL_RGB12)
- ENUM_TO_STRING_CASE(GL_RGB16)
- ENUM_TO_STRING_CASE(GL_RGBA2)
- ENUM_TO_STRING_CASE(GL_RGBA4)
- ENUM_TO_STRING_CASE(GL_RGB5_A1)
- ENUM_TO_STRING_CASE(GL_RGBA8)
- ENUM_TO_STRING_CASE(GL_RGB10_A2)
- ENUM_TO_STRING_CASE(GL_RGBA12)
- ENUM_TO_STRING_CASE(GL_RGBA16)
- ENUM_TO_STRING_CASE(GL_RGBA32F)
- ENUM_TO_STRING_CASE(GL_RGB32F)
- ENUM_TO_STRING_CASE(GL_RGBA16F)
- ENUM_TO_STRING_CASE(GL_RGB16F)
- ENUM_TO_STRING_CASE(GL_RGBA32UI)
- ENUM_TO_STRING_CASE(GL_RGB32UI)
- ENUM_TO_STRING_CASE(GL_RGBA16UI)
- ENUM_TO_STRING_CASE(GL_RGB16UI)
- ENUM_TO_STRING_CASE(GL_RGBA8UI)
- ENUM_TO_STRING_CASE(GL_RGB8UI)
- ENUM_TO_STRING_CASE(GL_RGBA32I)
- ENUM_TO_STRING_CASE(GL_RGB32I)
- ENUM_TO_STRING_CASE(GL_RGBA16I)
- ENUM_TO_STRING_CASE(GL_RGB16I)
- ENUM_TO_STRING_CASE(GL_RGBA8I)
- ENUM_TO_STRING_CASE(GL_RGB8I)
- ENUM_TO_STRING_CASE(GL_RGB10_A2UI)
- ENUM_TO_STRING_CASE(GL_SRGB)
- ENUM_TO_STRING_CASE(GL_SRGB8)
- ENUM_TO_STRING_CASE(GL_SRGB_ALPHA)
- ENUM_TO_STRING_CASE(GL_SRGB8_ALPHA8)
- ENUM_TO_STRING_CASE(GL_DEPTH_COMPONENT16)
- ENUM_TO_STRING_CASE(GL_DEPTH_COMPONENT24)
- ENUM_TO_STRING_CASE(GL_DEPTH_COMPONENT32)
- ENUM_TO_STRING_CASE(GL_DEPTH24_STENCIL8)
- ENUM_TO_STRING_CASE(GL_R11F_G11F_B10F)
- ENUM_TO_STRING_CASE(GL_DEPTH_COMPONENT32F)
- ENUM_TO_STRING_CASE(GL_DEPTH32F_STENCIL8)
-
-#elif ANDROID_ENABLED
+#ifdef ANDROID_ENABLED
// using definitions from GLES3/gl3.h
ENUM_TO_STRING_CASE(GL_RGBA4)
@@ -418,44 +358,56 @@ String OpenXROpenGLExtension::get_swapchain_format_name(int64_t p_swapchain_form
ENUM_TO_STRING_CASE(GL_DEPTH24_STENCIL8)
#else
- // using definitions from GL/gl.h
- ENUM_TO_STRING_CASE(GL_ALPHA4_EXT)
- ENUM_TO_STRING_CASE(GL_ALPHA8_EXT)
- ENUM_TO_STRING_CASE(GL_ALPHA12_EXT)
- ENUM_TO_STRING_CASE(GL_ALPHA16_EXT)
- ENUM_TO_STRING_CASE(GL_LUMINANCE4_EXT)
- ENUM_TO_STRING_CASE(GL_LUMINANCE8_EXT)
- ENUM_TO_STRING_CASE(GL_LUMINANCE12_EXT)
- ENUM_TO_STRING_CASE(GL_LUMINANCE16_EXT)
- ENUM_TO_STRING_CASE(GL_LUMINANCE4_ALPHA4_EXT)
- ENUM_TO_STRING_CASE(GL_LUMINANCE6_ALPHA2_EXT)
- ENUM_TO_STRING_CASE(GL_LUMINANCE8_ALPHA8_EXT)
- ENUM_TO_STRING_CASE(GL_LUMINANCE12_ALPHA4_EXT)
- ENUM_TO_STRING_CASE(GL_LUMINANCE12_ALPHA12_EXT)
- ENUM_TO_STRING_CASE(GL_LUMINANCE16_ALPHA16_EXT)
- ENUM_TO_STRING_CASE(GL_INTENSITY_EXT)
- ENUM_TO_STRING_CASE(GL_INTENSITY4_EXT)
- ENUM_TO_STRING_CASE(GL_INTENSITY8_EXT)
- ENUM_TO_STRING_CASE(GL_INTENSITY12_EXT)
- ENUM_TO_STRING_CASE(GL_INTENSITY16_EXT)
- ENUM_TO_STRING_CASE(GL_RGB2_EXT)
- ENUM_TO_STRING_CASE(GL_RGB4_EXT)
- ENUM_TO_STRING_CASE(GL_RGB5_EXT)
- ENUM_TO_STRING_CASE(GL_RGB8_EXT)
- ENUM_TO_STRING_CASE(GL_RGB10_EXT)
- ENUM_TO_STRING_CASE(GL_RGB12_EXT)
- ENUM_TO_STRING_CASE(GL_RGB16_EXT)
- ENUM_TO_STRING_CASE(GL_RGBA2_EXT)
- ENUM_TO_STRING_CASE(GL_RGBA4_EXT)
- ENUM_TO_STRING_CASE(GL_RGB5_A1_EXT)
- ENUM_TO_STRING_CASE(GL_RGBA8_EXT)
- ENUM_TO_STRING_CASE(GL_RGB10_A2_EXT)
- ENUM_TO_STRING_CASE(GL_RGBA12_EXT)
- ENUM_TO_STRING_CASE(GL_RGBA16_EXT)
- ENUM_TO_STRING_CASE(GL_SRGB_EXT)
- ENUM_TO_STRING_CASE(GL_SRGB8_EXT)
- ENUM_TO_STRING_CASE(GL_SRGB_ALPHA_EXT)
- ENUM_TO_STRING_CASE(GL_SRGB8_ALPHA8_EXT)
+ // using definitions from GLAD
+ ENUM_TO_STRING_CASE(GL_R8_SNORM)
+ ENUM_TO_STRING_CASE(GL_RG8_SNORM)
+ ENUM_TO_STRING_CASE(GL_RGB8_SNORM)
+ ENUM_TO_STRING_CASE(GL_RGBA8_SNORM)
+ ENUM_TO_STRING_CASE(GL_R16_SNORM)
+ ENUM_TO_STRING_CASE(GL_RG16_SNORM)
+ ENUM_TO_STRING_CASE(GL_RGB16_SNORM)
+ ENUM_TO_STRING_CASE(GL_RGBA16_SNORM)
+ ENUM_TO_STRING_CASE(GL_RGB4)
+ ENUM_TO_STRING_CASE(GL_RGB5)
+ ENUM_TO_STRING_CASE(GL_RGB8)
+ ENUM_TO_STRING_CASE(GL_RGB10)
+ ENUM_TO_STRING_CASE(GL_RGB12)
+ ENUM_TO_STRING_CASE(GL_RGB16)
+ ENUM_TO_STRING_CASE(GL_RGBA2)
+ ENUM_TO_STRING_CASE(GL_RGBA4)
+ ENUM_TO_STRING_CASE(GL_RGB5_A1)
+ ENUM_TO_STRING_CASE(GL_RGBA8)
+ ENUM_TO_STRING_CASE(GL_RGB10_A2)
+ ENUM_TO_STRING_CASE(GL_RGBA12)
+ ENUM_TO_STRING_CASE(GL_RGBA16)
+ ENUM_TO_STRING_CASE(GL_RGBA32F)
+ ENUM_TO_STRING_CASE(GL_RGB32F)
+ ENUM_TO_STRING_CASE(GL_RGBA16F)
+ ENUM_TO_STRING_CASE(GL_RGB16F)
+ ENUM_TO_STRING_CASE(GL_RGBA32UI)
+ ENUM_TO_STRING_CASE(GL_RGB32UI)
+ ENUM_TO_STRING_CASE(GL_RGBA16UI)
+ ENUM_TO_STRING_CASE(GL_RGB16UI)
+ ENUM_TO_STRING_CASE(GL_RGBA8UI)
+ ENUM_TO_STRING_CASE(GL_RGB8UI)
+ ENUM_TO_STRING_CASE(GL_RGBA32I)
+ ENUM_TO_STRING_CASE(GL_RGB32I)
+ ENUM_TO_STRING_CASE(GL_RGBA16I)
+ ENUM_TO_STRING_CASE(GL_RGB16I)
+ ENUM_TO_STRING_CASE(GL_RGBA8I)
+ ENUM_TO_STRING_CASE(GL_RGB8I)
+ ENUM_TO_STRING_CASE(GL_RGB10_A2UI)
+ ENUM_TO_STRING_CASE(GL_SRGB)
+ ENUM_TO_STRING_CASE(GL_SRGB8)
+ ENUM_TO_STRING_CASE(GL_SRGB_ALPHA)
+ ENUM_TO_STRING_CASE(GL_SRGB8_ALPHA8)
+ ENUM_TO_STRING_CASE(GL_DEPTH_COMPONENT16)
+ ENUM_TO_STRING_CASE(GL_DEPTH_COMPONENT24)
+ ENUM_TO_STRING_CASE(GL_DEPTH_COMPONENT32)
+ ENUM_TO_STRING_CASE(GL_DEPTH24_STENCIL8)
+ ENUM_TO_STRING_CASE(GL_R11F_G11F_B10F)
+ ENUM_TO_STRING_CASE(GL_DEPTH_COMPONENT32F)
+ ENUM_TO_STRING_CASE(GL_DEPTH32F_STENCIL8)
#endif
default: {
return String("Swapchain format 0x") + String::num_int64(p_swapchain_format, 16);
diff --git a/modules/openxr/extensions/openxr_opengl_extension.h b/modules/openxr/extensions/openxr_opengl_extension.h
index b666653c8e..473c5157c0 100644
--- a/modules/openxr/extensions/openxr_opengl_extension.h
+++ b/modules/openxr/extensions/openxr_opengl_extension.h
@@ -59,9 +59,8 @@
#include OPENGL_INCLUDE_H
#define GL_GLEXT_PROTOTYPES 1
#define GL3_PROTOTYPES 1
-#include <GL/gl.h>
-#include <GL/glext.h>
-#include <GL/glx.h>
+#include "thirdparty/glad/glad/gl.h"
+#include "thirdparty/glad/glad/glx.h"
#include <X11/Xlib.h>
#endif