diff --git a/modules/openxr/doc_classes/OpenXRAPIExtension.xml b/modules/openxr/doc_classes/OpenXRAPIExtension.xml
index 909b77ea046..e38a51e15c6 100644
--- a/modules/openxr/doc_classes/OpenXRAPIExtension.xml
+++ b/modules/openxr/doc_classes/OpenXRAPIExtension.xml
@@ -329,6 +329,12 @@
[b]Note:[/b] This cannot be called while the OpenXR session is still running.
+
+
+
+ Request the recommended resolution from the OpenXR runtime and update the main swapchain size if it has changed.
+
+
diff --git a/modules/openxr/openxr_api.cpp b/modules/openxr/openxr_api.cpp
index de9c0d1c7ca..70ad0e03f3c 100644
--- a/modules/openxr/openxr_api.cpp
+++ b/modules/openxr/openxr_api.cpp
@@ -2228,6 +2228,27 @@ void OpenXRAPI::_set_render_state_render_region_rt(const Rect2i &p_render_region
openxr_api->render_state.render_region = p_render_region;
}
+void OpenXRAPI::_update_main_swapchain_size_rt() {
+ ERR_NOT_ON_RENDER_THREAD;
+
+ OpenXRAPI *openxr_api = OpenXRAPI::get_singleton();
+ ERR_FAIL_NULL(openxr_api);
+
+ uint32_t view_count_output = 0;
+ XrResult result = openxr_api->xrEnumerateViewConfigurationViews(openxr_api->instance, openxr_api->system_id, openxr_api->view_configuration, openxr_api->get_view_count(), &view_count_output, openxr_api->view_configuration_views.ptr());
+ if (XR_FAILED(result)) {
+ return;
+ }
+
+#ifdef DEBUG_ENABLED
+ for (uint32_t i = 0; i < view_count_output; i++) {
+ print_verbose("OpenXR: Recommended resolution changed");
+ print_verbose(String(" - recommended render width: ") + itos(openxr_api->view_configuration_views[i].recommendedImageRectWidth));
+ print_verbose(String(" - recommended render height: ") + itos(openxr_api->view_configuration_views[i].recommendedImageRectHeight));
+ }
+#endif
+}
+
bool OpenXRAPI::process() {
ERR_FAIL_COND_V(instance == XR_NULL_HANDLE, false);
diff --git a/modules/openxr/openxr_api.h b/modules/openxr/openxr_api.h
index 050236faa44..043abfff423 100644
--- a/modules/openxr/openxr_api.h
+++ b/modules/openxr/openxr_api.h
@@ -371,6 +371,7 @@ private:
static void _set_render_environment_blend_mode_rt(int32_t p_environment_blend_mode);
static void _set_render_state_multiplier_rt(double p_render_target_size_multiplier);
static void _set_render_state_render_region_rt(const Rect2i &p_render_region);
+ static void _update_main_swapchain_size_rt();
_FORCE_INLINE_ void allocate_view_buffers(uint32_t p_view_count, bool p_submit_depth_buffer) {
// If we're rendering on a separate thread, we may still be processing the last frame, don't communicate this till we're ready...
@@ -428,6 +429,13 @@ private:
}
public:
+ _FORCE_INLINE_ void update_main_swapchain_size() {
+ RenderingServer *rendering_server = RenderingServer::get_singleton();
+ ERR_FAIL_NULL(rendering_server);
+
+ rendering_server->call_on_render_thread(callable_mp_static(&OpenXRAPI::_update_main_swapchain_size_rt));
+ }
+
XrInstance get_instance() const { return instance; }
XrSystemId get_system_id() const { return system_id; }
XrSession get_session() const { return session; }
@@ -607,6 +615,7 @@ public:
void unregister_frame_info_extension(OpenXRExtensionWrapper *p_extension);
const Vector get_supported_environment_blend_modes();
+
bool is_environment_blend_mode_supported(XrEnvironmentBlendMode p_blend_mode) const;
bool set_environment_blend_mode(XrEnvironmentBlendMode p_blend_mode);
XrEnvironmentBlendMode get_environment_blend_mode() const { return requested_environment_blend_mode; }
diff --git a/modules/openxr/openxr_api_extension.cpp b/modules/openxr/openxr_api_extension.cpp
index 41ece4227f9..916a03e2724 100644
--- a/modules/openxr/openxr_api_extension.cpp
+++ b/modules/openxr/openxr_api_extension.cpp
@@ -95,6 +95,8 @@ void OpenXRAPIExtension::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_emulate_environment_blend_mode_alpha_blend", "enabled"), &OpenXRAPIExtension::set_emulate_environment_blend_mode_alpha_blend);
ClassDB::bind_method(D_METHOD("is_environment_blend_mode_alpha_supported"), &OpenXRAPIExtension::is_environment_blend_mode_alpha_blend_supported);
+ ClassDB::bind_method(D_METHOD("update_main_swapchain_size"), &OpenXRAPIExtension::update_main_swapchain_size);
+
BIND_ENUM_CONSTANT(OPENXR_ALPHA_BLEND_MODE_SUPPORT_NONE);
BIND_ENUM_CONSTANT(OPENXR_ALPHA_BLEND_MODE_SUPPORT_REAL);
BIND_ENUM_CONSTANT(OPENXR_ALPHA_BLEND_MODE_SUPPORT_EMULATING);
@@ -348,6 +350,11 @@ void OpenXRAPIExtension::set_render_region(const Rect2i &p_render_region) {
OpenXRAPI::get_singleton()->set_render_region(p_render_region);
}
+void OpenXRAPIExtension::update_main_swapchain_size() {
+ ERR_FAIL_NULL(OpenXRAPI::get_singleton());
+ OpenXRAPI::get_singleton()->update_main_swapchain_size();
+}
+
void OpenXRAPIExtension::set_emulate_environment_blend_mode_alpha_blend(bool p_enabled) {
ERR_FAIL_NULL(OpenXRAPI::get_singleton());
OpenXRAPI::get_singleton()->set_emulate_environment_blend_mode_alpha_blend(p_enabled);
diff --git a/modules/openxr/openxr_api_extension.h b/modules/openxr/openxr_api_extension.h
index fce78ce898d..869839feee0 100644
--- a/modules/openxr/openxr_api_extension.h
+++ b/modules/openxr/openxr_api_extension.h
@@ -119,6 +119,8 @@ public:
void set_render_region(const Rect2i &p_render_region);
+ void update_main_swapchain_size();
+
enum OpenXRAlphaBlendModeSupport {
OPENXR_ALPHA_BLEND_MODE_SUPPORT_NONE = 0,
OPENXR_ALPHA_BLEND_MODE_SUPPORT_REAL = 1,