From 51e3dd5adcf574088e58a76099f359c11aac0180 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Mon, 27 Apr 2026 11:22:44 +0200 Subject: [PATCH] factorize post-processing GUI code --- client/scenes/gui_common.cpp | 83 ++++++++++++++++++++++++++++++++++++ client/scenes/gui_common.h | 6 ++- client/scenes/lobby_gui.cpp | 76 +-------------------------------- client/scenes/stream_gui.cpp | 74 ++++---------------------------- 4 files changed, 97 insertions(+), 142 deletions(-) diff --git a/client/scenes/gui_common.cpp b/client/scenes/gui_common.cpp index 550ff8a4..95d00334 100644 --- a/client/scenes/gui_common.cpp +++ b/client/scenes/gui_common.cpp @@ -19,6 +19,7 @@ #include "gui_common.h" +#include "application.h" #include "configuration.h" #include "render/imgui_impl.h" #include "utils/i18n.h" @@ -114,4 +115,86 @@ bool refresh_rate( } return changed; } + +static std::string openxr_post_processing_flag_name(XrCompositionLayerSettingsFlagsFB flag) +{ + switch (flag) + { + case XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SUPER_SAMPLING_BIT_FB: + case XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SHARPENING_BIT_FB: + return _C("openxr_post_processing", "Normal"); + case XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SUPER_SAMPLING_BIT_FB: + case XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SHARPENING_BIT_FB: + return _C("openxr_post_processing", "Quality"); + default: + return _C("openxr_post_processing", "Disabled"); + } +} + +bool post_processing( + imgui_context & imgui_ctx, + configuration & config) +{ + bool changed = false; + if (not application::get_openxr_post_processing_supported()) + return changed; + + ImGui::Text("%s", _S("OpenXR post-processing")); + ImGui::Indent(); + + { + XrCompositionLayerSettingsFlagsFB current = config.openxr_post_processing.super_sampling; + if (ImGui::BeginCombo(_S("Supersampling"), openxr_post_processing_flag_name(current).c_str())) + { + const XrCompositionLayerSettingsFlagsFB selectable_options[]{ + 0, + XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SUPER_SAMPLING_BIT_FB, + XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SUPER_SAMPLING_BIT_FB}; + for (XrCompositionLayerSettingsFlagsFB option: selectable_options) + { + if (ImGui::Selectable(openxr_post_processing_flag_name(option).c_str(), current == option, ImGuiSelectableFlags_SelectOnRelease)) + { + spdlog::info("Setting OpenXR super sampling to {}", openxr_post_processing_flag_name(option)); + config.openxr_post_processing.super_sampling = option; + config.save(); + changed = true; + } + imgui_ctx.vibrate_on_hover(); + } + ImGui::EndCombo(); + } + imgui_ctx.vibrate_on_hover(); + if (ImGui::IsItemHovered()) + imgui_ctx.tooltip(_("Reduce flicker for high contrast edges.\nUseful when the input resolution is high compared to the headset display")); + } + + { + XrCompositionLayerSettingsFlagsFB current = config.openxr_post_processing.sharpening; + if (ImGui::BeginCombo(_S("Sharpening"), openxr_post_processing_flag_name(current).c_str())) + { + const XrCompositionLayerSettingsFlagsFB selectable_options[]{ + 0, + XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SHARPENING_BIT_FB, + XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SHARPENING_BIT_FB}; + for (XrCompositionLayerSettingsFlagsFB option: selectable_options) + { + if (ImGui::Selectable(openxr_post_processing_flag_name(option).c_str(), current == option, ImGuiSelectableFlags_SelectOnRelease)) + { + spdlog::info("Setting OpenXR sharpening to {}", openxr_post_processing_flag_name(option)); + config.openxr_post_processing.sharpening = option; + config.save(); + changed = true; + } + imgui_ctx.vibrate_on_hover(); + } + ImGui::EndCombo(); + } + imgui_ctx.vibrate_on_hover(); + if (ImGui::IsItemHovered()) + imgui_ctx.tooltip(_("Improve clarity of high contrast edges and counteract blur.\nUseful when the input resolution is low compared to the headset display")); + } + + ImGui::Unindent(); + return changed; +} } // namespace wivrn::gui diff --git a/client/scenes/gui_common.h b/client/scenes/gui_common.h index 5475207b..e75ef9ab 100644 --- a/client/scenes/gui_common.h +++ b/client/scenes/gui_common.h @@ -40,5 +40,9 @@ bool refresh_rate( imgui_context & imgui_ctx, configuration & config); -} +bool post_processing( + imgui_context & imgui_ctx, + configuration & config); + +} // namespace gui } // namespace wivrn diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index 2a5c3af9..b835f477 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -93,21 +93,6 @@ static void display_recentering_tip(imgui_context & ctx, const std::string & tip ImGui::PopFont(); } -std::string openxr_post_processing_flag_name(XrCompositionLayerSettingsFlagsFB flag) -{ - switch (flag) - { - case XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SUPER_SAMPLING_BIT_FB: - case XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SHARPENING_BIT_FB: - return _cS("openxr_post_processing", "Normal"); - case XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SUPER_SAMPLING_BIT_FB: - case XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SHARPENING_BIT_FB: - return _cS("openxr_post_processing", "Quality"); - default: - return _cS("openxr_post_processing", "Disabled"); - } -} - void scenes::lobby::gui_connecting(locked_notifiable & pin_request) { using constants::style::button_size; @@ -883,67 +868,8 @@ void scenes::lobby::gui_settings() void scenes::lobby::gui_post_processing() { - auto & config = application::get_config(); - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(20, 20)); - - if (application::get_openxr_post_processing_supported()) - { - ImGui::Text("%s", _S("OpenXR post-processing")); - ImGui::Indent(); - { - XrCompositionLayerSettingsFlagsFB current = config.openxr_post_processing.super_sampling; - if (ImGui::BeginCombo(_S("Supersampling"), openxr_post_processing_flag_name(current).c_str())) - { - const XrCompositionLayerSettingsFlagsFB selectable_options[]{ - 0, - XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SUPER_SAMPLING_BIT_FB, - XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SUPER_SAMPLING_BIT_FB}; - for (XrCompositionLayerSettingsFlagsFB option: selectable_options) - { - if (ImGui::Selectable(openxr_post_processing_flag_name(option).c_str(), current == option, ImGuiSelectableFlags_SelectOnRelease)) - { - config.openxr_post_processing.super_sampling = option; - config.save(); - } - imgui_ctx->vibrate_on_hover(); - } - ImGui::EndCombo(); - } - imgui_ctx->vibrate_on_hover(); - if (ImGui::IsItemHovered()) - { - imgui_ctx->tooltip(_("Reduce flicker for high contrast edges.\nUseful when the input resolution is high compared to the headset display")); - } - } - { - XrCompositionLayerSettingsFlagsFB current = config.openxr_post_processing.sharpening; - if (ImGui::BeginCombo(_S("Sharpening"), openxr_post_processing_flag_name(current).c_str())) - { - const XrCompositionLayerSettingsFlagsFB selectable_options[]{ - 0, - XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SHARPENING_BIT_FB, - XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SHARPENING_BIT_FB}; - for (XrCompositionLayerSettingsFlagsFB option: selectable_options) - { - if (ImGui::Selectable(openxr_post_processing_flag_name(option).c_str(), current == option, ImGuiSelectableFlags_SelectOnRelease)) - { - config.openxr_post_processing.sharpening = option; - config.save(); - } - imgui_ctx->vibrate_on_hover(); - } - ImGui::EndCombo(); - } - imgui_ctx->vibrate_on_hover(); - if (ImGui::IsItemHovered()) - { - imgui_ctx->tooltip(_("Improve clarity of high contrast edges and counteract blur.\nUseful when the input resolution is low compared to the headset display")); - } - } - ImGui::Unindent(); - } - + gui::post_processing(*imgui_ctx, application::get_config()); ImGui::PopStyleVar(); } diff --git a/client/scenes/stream_gui.cpp b/client/scenes/stream_gui.cpp index dcceadb9..659cd8ed 100644 --- a/client/scenes/stream_gui.cpp +++ b/client/scenes/stream_gui.cpp @@ -380,16 +380,15 @@ void scenes::stream::gui_compact_view() static void send_settings_changed_packet(xr::session & session, wivrn_session * network, const configuration & config) { - from_headset::settings_changed packet{ - .preferred_refresh_rate = config.preferred_refresh_rate, - .minimum_refresh_rate = config.minimum_refresh_rate.value_or(0), - .fps_divider = config.fps_divider, - .bitrate_bps = config.bitrate_bps, - }; - network->send_control(std::move(packet)); + network->send_control( + from_headset::settings_changed{ + .preferred_refresh_rate = config.preferred_refresh_rate, + .minimum_refresh_rate = config.minimum_refresh_rate.value_or(0), + .fps_divider = config.fps_divider, + .bitrate_bps = config.bitrate_bps, + }); } -std::string openxr_post_processing_flag_name(XrCompositionLayerSettingsFlagsFB flag); // TODO declaration in a .h file void scenes::stream::gui_settings(float predicted_display_period) { const ImGuiStyle & style = ImGui::GetStyle(); @@ -414,64 +413,7 @@ void scenes::stream::gui_settings(float predicted_display_period) imgui_ctx->tooltip(_("Click to adjust bitrate")); } - if (application::get_openxr_post_processing_supported()) - { - ImGui::Text("%s", _S("OpenXR post-processing")); - ImGui::Indent(); - { - XrCompositionLayerSettingsFlagsFB current = config.openxr_post_processing.super_sampling; - if (ImGui::BeginCombo(_S("Supersampling"), openxr_post_processing_flag_name(current).c_str())) - { - const XrCompositionLayerSettingsFlagsFB selectable_options[]{ - 0, - XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SUPER_SAMPLING_BIT_FB, - XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SUPER_SAMPLING_BIT_FB}; - for (XrCompositionLayerSettingsFlagsFB option: selectable_options) - { - if (ImGui::Selectable(openxr_post_processing_flag_name(option).c_str(), current == option, ImGuiSelectableFlags_SelectOnRelease)) - { - spdlog::info("Setting OpenXR super sampling to {}", openxr_post_processing_flag_name(option)); - config.openxr_post_processing.super_sampling = option; - config.save(); - } - imgui_ctx->vibrate_on_hover(); - } - ImGui::EndCombo(); - } - imgui_ctx->vibrate_on_hover(); - if (ImGui::IsItemHovered()) - { - imgui_ctx->tooltip(_("Reduce flicker for high contrast edges.\nUseful when the input resolution is high compared to the headset display")); - } - } - { - XrCompositionLayerSettingsFlagsFB current = config.openxr_post_processing.sharpening; - if (ImGui::BeginCombo(_S("Sharpening"), openxr_post_processing_flag_name(current).c_str())) - { - const XrCompositionLayerSettingsFlagsFB selectable_options[]{ - 0, - XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SHARPENING_BIT_FB, - XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SHARPENING_BIT_FB}; - for (XrCompositionLayerSettingsFlagsFB option: selectable_options) - { - if (ImGui::Selectable(openxr_post_processing_flag_name(option).c_str(), current == option, ImGuiSelectableFlags_SelectOnRelease)) - { - spdlog::info("Setting OpenXR sharpening to {}", openxr_post_processing_flag_name(option)); - config.openxr_post_processing.sharpening = option; - config.save(); - } - imgui_ctx->vibrate_on_hover(); - } - ImGui::EndCombo(); - } - imgui_ctx->vibrate_on_hover(); - if (ImGui::IsItemHovered()) - { - imgui_ctx->tooltip(_("Improve clarity of high contrast edges and counteract blur.\nUseful when the input resolution is low compared to the headset display")); - } - } - ImGui::Unindent(); - } + gui::post_processing(*imgui_ctx, config); bool send_packet = false; bool save_config = false;