Skip to content

Commit 8adea54

Browse files
committed
OpenXR: Add OpenXRAPIExtension::update_main_swapchain_size()
1 parent 68410ac commit 8adea54

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

modules/openxr/doc_classes/OpenXRAPIExtension.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,12 @@
329329
[b]Note:[/b] This cannot be called while the OpenXR session is still running.
330330
</description>
331331
</method>
332+
<method name="update_main_swapchain_size">
333+
<return type="void" />
334+
<description>
335+
Request the recommended resolution from the OpenXR runtime and update the main swapchain size if it has changed.
336+
</description>
337+
</method>
332338
<method name="xr_result">
333339
<return type="bool" />
334340
<param index="0" name="result" type="int" />

modules/openxr/openxr_api.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,6 +2228,27 @@ void OpenXRAPI::_set_render_state_render_region_rt(const Rect2i &p_render_region
22282228
openxr_api->render_state.render_region = p_render_region;
22292229
}
22302230

2231+
void OpenXRAPI::_update_main_swapchain_size_rt() {
2232+
ERR_NOT_ON_RENDER_THREAD;
2233+
2234+
OpenXRAPI *openxr_api = OpenXRAPI::get_singleton();
2235+
ERR_FAIL_NULL(openxr_api);
2236+
2237+
uint32_t view_count_output = 0;
2238+
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());
2239+
if (XR_FAILED(result)) {
2240+
return;
2241+
}
2242+
2243+
#ifdef DEBUG_ENABLED
2244+
for (uint32_t i = 0; i < view_count_output; i++) {
2245+
print_verbose("OpenXR: Recommended resolution changed");
2246+
print_verbose(String(" - recommended render width: ") + itos(openxr_api->view_configuration_views[i].recommendedImageRectWidth));
2247+
print_verbose(String(" - recommended render height: ") + itos(openxr_api->view_configuration_views[i].recommendedImageRectHeight));
2248+
}
2249+
#endif
2250+
}
2251+
22312252
bool OpenXRAPI::process() {
22322253
ERR_FAIL_COND_V(instance == XR_NULL_HANDLE, false);
22332254

modules/openxr/openxr_api.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ class OpenXRAPI {
371371
static void _set_render_environment_blend_mode_rt(int32_t p_environment_blend_mode);
372372
static void _set_render_state_multiplier_rt(double p_render_target_size_multiplier);
373373
static void _set_render_state_render_region_rt(const Rect2i &p_render_region);
374+
static void _update_main_swapchain_size_rt();
374375

375376
_FORCE_INLINE_ void allocate_view_buffers(uint32_t p_view_count, bool p_submit_depth_buffer) {
376377
// 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 @@ class OpenXRAPI {
428429
}
429430

430431
public:
432+
_FORCE_INLINE_ void update_main_swapchain_size() {
433+
RenderingServer *rendering_server = RenderingServer::get_singleton();
434+
ERR_FAIL_NULL(rendering_server);
435+
436+
rendering_server->call_on_render_thread(callable_mp_static(&OpenXRAPI::_update_main_swapchain_size_rt));
437+
}
438+
431439
XrInstance get_instance() const { return instance; }
432440
XrSystemId get_system_id() const { return system_id; }
433441
XrSession get_session() const { return session; }
@@ -607,6 +615,7 @@ class OpenXRAPI {
607615
void unregister_frame_info_extension(OpenXRExtensionWrapper *p_extension);
608616

609617
const Vector<XrEnvironmentBlendMode> get_supported_environment_blend_modes();
618+
610619
bool is_environment_blend_mode_supported(XrEnvironmentBlendMode p_blend_mode) const;
611620
bool set_environment_blend_mode(XrEnvironmentBlendMode p_blend_mode);
612621
XrEnvironmentBlendMode get_environment_blend_mode() const { return requested_environment_blend_mode; }

modules/openxr/openxr_api_extension.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ void OpenXRAPIExtension::_bind_methods() {
9595
ClassDB::bind_method(D_METHOD("set_emulate_environment_blend_mode_alpha_blend", "enabled"), &OpenXRAPIExtension::set_emulate_environment_blend_mode_alpha_blend);
9696
ClassDB::bind_method(D_METHOD("is_environment_blend_mode_alpha_supported"), &OpenXRAPIExtension::is_environment_blend_mode_alpha_blend_supported);
9797

98+
ClassDB::bind_method(D_METHOD("update_main_swapchain_size"), &OpenXRAPIExtension::update_main_swapchain_size);
99+
98100
BIND_ENUM_CONSTANT(OPENXR_ALPHA_BLEND_MODE_SUPPORT_NONE);
99101
BIND_ENUM_CONSTANT(OPENXR_ALPHA_BLEND_MODE_SUPPORT_REAL);
100102
BIND_ENUM_CONSTANT(OPENXR_ALPHA_BLEND_MODE_SUPPORT_EMULATING);
@@ -348,6 +350,11 @@ void OpenXRAPIExtension::set_render_region(const Rect2i &p_render_region) {
348350
OpenXRAPI::get_singleton()->set_render_region(p_render_region);
349351
}
350352

353+
void OpenXRAPIExtension::update_main_swapchain_size() {
354+
ERR_FAIL_NULL(OpenXRAPI::get_singleton());
355+
OpenXRAPI::get_singleton()->update_main_swapchain_size();
356+
}
357+
351358
void OpenXRAPIExtension::set_emulate_environment_blend_mode_alpha_blend(bool p_enabled) {
352359
ERR_FAIL_NULL(OpenXRAPI::get_singleton());
353360
OpenXRAPI::get_singleton()->set_emulate_environment_blend_mode_alpha_blend(p_enabled);

modules/openxr/openxr_api_extension.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class OpenXRAPIExtension : public RefCounted {
119119

120120
void set_render_region(const Rect2i &p_render_region);
121121

122+
void update_main_swapchain_size();
123+
122124
enum OpenXRAlphaBlendModeSupport {
123125
OPENXR_ALPHA_BLEND_MODE_SUPPORT_NONE = 0,
124126
OPENXR_ALPHA_BLEND_MODE_SUPPORT_REAL = 1,

0 commit comments

Comments
 (0)