From d91e75b6f77d61967a3a9e13406b2f0e35eb60c1 Mon Sep 17 00:00:00 2001 From: Malcolm Nixon Date: Sat, 18 Feb 2023 10:50:55 -0500 Subject: [PATCH] Added render target size multiplier option. Fix formatting --- .../openxr/doc_classes/OpenXRInterface.xml | 3 +++ modules/openxr/openxr_api.cpp | 12 +++++++++-- modules/openxr/openxr_api.h | 5 +++++ modules/openxr/openxr_interface.cpp | 21 +++++++++++++++++++ modules/openxr/openxr_interface.h | 3 +++ 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/modules/openxr/doc_classes/OpenXRInterface.xml b/modules/openxr/doc_classes/OpenXRInterface.xml index f3cc469c9d6..0cf22743ec1 100644 --- a/modules/openxr/doc_classes/OpenXRInterface.xml +++ b/modules/openxr/doc_classes/OpenXRInterface.xml @@ -43,6 +43,9 @@ The display refresh rate for the current HMD. Only functional if this feature is supported by the OpenXR runtime and after the interface has been initialized. + + The render size multiplier for the current HMD. Must be set before the interface has been initialized. + diff --git a/modules/openxr/openxr_api.cpp b/modules/openxr/openxr_api.cpp index ddb3114b595..7bfdbdd2055 100644 --- a/modules/openxr/openxr_api.cpp +++ b/modules/openxr/openxr_api.cpp @@ -1418,8 +1418,8 @@ Size2 OpenXRAPI::get_recommended_target_size() { Size2 target_size; - target_size.width = view_configuration_views[0].recommendedImageRectWidth; - target_size.height = view_configuration_views[0].recommendedImageRectHeight; + target_size.width = view_configuration_views[0].recommendedImageRectWidth * render_target_size_multiplier; + target_size.height = view_configuration_views[0].recommendedImageRectHeight * render_target_size_multiplier; return target_size; } @@ -1953,6 +1953,14 @@ Array OpenXRAPI::get_available_display_refresh_rates() const { return Array(); } +double OpenXRAPI::get_render_target_size_multiplier() const { + return render_target_size_multiplier; +} + +void OpenXRAPI::set_render_target_size_multiplier(double multiplier) { + render_target_size_multiplier = multiplier; +} + OpenXRAPI::OpenXRAPI() { // OpenXRAPI is only constructed if OpenXR is enabled. singleton = this; diff --git a/modules/openxr/openxr_api.h b/modules/openxr/openxr_api.h index 8c642c4ff43..8a8fa7e8543 100644 --- a/modules/openxr/openxr_api.h +++ b/modules/openxr/openxr_api.h @@ -116,6 +116,7 @@ private: XrSessionState session_state = XR_SESSION_STATE_UNKNOWN; bool running = false; XrFrameState frame_state = { XR_TYPE_FRAME_STATE, NULL, 0, 0, false }; + double render_target_size_multiplier = 1.0; OpenXRGraphicsExtensionWrapper *graphics_extension = nullptr; XrSystemGraphicsProperties graphics_properties; @@ -362,6 +363,10 @@ public: void set_display_refresh_rate(float p_refresh_rate); Array get_available_display_refresh_rates() const; + // Render Target size multiplier + double get_render_target_size_multiplier() const; + void set_render_target_size_multiplier(double multiplier); + // action map String get_default_action_map_resource_name(); diff --git a/modules/openxr/openxr_interface.cpp b/modules/openxr/openxr_interface.cpp index 51de9b913af..01227696eac 100644 --- a/modules/openxr/openxr_interface.cpp +++ b/modules/openxr/openxr_interface.cpp @@ -47,6 +47,11 @@ void OpenXRInterface::_bind_methods() { ClassDB::bind_method(D_METHOD("set_display_refresh_rate", "refresh_rate"), &OpenXRInterface::set_display_refresh_rate); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "display_refresh_rate"), "set_display_refresh_rate", "get_display_refresh_rate"); + // Render Target size multiplier + ClassDB::bind_method(D_METHOD("get_render_target_size_multiplier"), &OpenXRInterface::get_render_target_size_multiplier); + ClassDB::bind_method(D_METHOD("set_render_target_size_multiplier", "multiplier"), &OpenXRInterface::set_render_target_size_multiplier); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "render_target_size_multiplier"), "set_render_target_size_multiplier", "get_render_target_size_multiplier"); + ClassDB::bind_method(D_METHOD("is_action_set_active", "name"), &OpenXRInterface::is_action_set_active); ClassDB::bind_method(D_METHOD("set_action_set_active", "name", "active"), &OpenXRInterface::set_action_set_active); ClassDB::bind_method(D_METHOD("get_action_sets"), &OpenXRInterface::get_action_sets); @@ -657,6 +662,22 @@ Array OpenXRInterface::get_action_sets() const { return arr; } +double OpenXRInterface::get_render_target_size_multiplier() const { + if (openxr_api == nullptr) { + return 1.0; + } else { + return openxr_api->get_render_target_size_multiplier(); + } +} + +void OpenXRInterface::set_render_target_size_multiplier(double multiplier) { + if (openxr_api == nullptr) { + return; + } else { + openxr_api->set_render_target_size_multiplier(multiplier); + } +} + Size2 OpenXRInterface::get_render_target_size() { if (openxr_api == nullptr) { return Size2(); diff --git a/modules/openxr/openxr_interface.h b/modules/openxr/openxr_interface.h index 40ee95f02fc..e1ec0350a47 100644 --- a/modules/openxr/openxr_interface.h +++ b/modules/openxr/openxr_interface.h @@ -127,6 +127,9 @@ public: void set_action_set_active(const String &p_action_set, bool p_active); Array get_action_sets() const; + double get_render_target_size_multiplier() const; + void set_render_target_size_multiplier(double multiplier); + virtual Size2 get_render_target_size() override; virtual uint32_t get_view_count() override; virtual Transform3D get_camera_transform() override;