From 68edc66fb7aec9c0ccbe5742ac6063a510664074 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Mon, 18 Aug 2025 17:29:53 +0200 Subject: [PATCH] Move *_supported into xr::system --- client/application.cpp | 10 +++++++--- client/application.h | 10 ---------- client/configuration.cpp | 14 +++++--------- client/scene.cpp | 2 -- client/scene.h | 1 - client/scenes/lobby_gui.cpp | 8 ++++---- client/scenes/stream.cpp | 6 +++--- client/xr/body_tracker.h | 16 +++++----------- client/xr/face_tracker.h | 15 ++++----------- client/xr/session.cpp | 2 +- client/xr/system.cpp | 20 ++++++++++++++++--- client/xr/system.h | 38 +++++++++++++++++++++++++++++-------- 12 files changed, 76 insertions(+), 66 deletions(-) diff --git a/client/application.cpp b/client/application.cpp index e49bc994..26837488 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -1261,17 +1262,20 @@ void application::initialize() switch (xr_system_id.passthrough_supported()) { - case xr::system::passthrough_type::no_passthrough: + case xr::passthrough_type::none: spdlog::info(" Passthrough: not supported"); break; - case xr::system::passthrough_type::bw: + case xr::passthrough_type::bw: spdlog::info(" Passthrough: black and white"); break; - case xr::system::passthrough_type::color: + case xr::passthrough_type::color: spdlog::info(" Passthrough: color"); break; } + spdlog::info(" Face tracker: {}", magic_enum::enum_name(xr_system_id.face_tracker_supported())); + spdlog::info(" Body tracker: {}", magic_enum::enum_name(xr_system_id.body_tracker_supported())); + // Log view configurations and blend modes log_views(); diff --git a/client/application.h b/client/application.h index de208576..f81997f4 100644 --- a/client/application.h +++ b/client/application.h @@ -388,21 +388,11 @@ public: return instance().vk_instance; } - static xr::instance & get_instance() - { - return instance().xr_instance; - } - static xr::system & get_system() { return instance().xr_system_id; } - static xr::session & get_session() - { - return instance().xr_session; - } - static vk::raii::PipelineCache & get_pipeline_cache() { return instance().pipeline_cache; diff --git a/client/configuration.cpp b/client/configuration.cpp index 2ea37c41..a8b2bf09 100644 --- a/client/configuration.cpp +++ b/client/configuration.cpp @@ -20,8 +20,6 @@ #include "configuration.h" #include "application.h" -#include "xr/body_tracker.h" -#include "xr/face_tracker.h" #include #include @@ -84,9 +82,7 @@ bool configuration::check_feature(feature f) const { std::lock_guard lock(mutex); - auto & instance = application::get_instance(); auto & system = application::get_system(); - auto & session = application::get_session(); auto it = features.find(f); if (it == features.end()) @@ -108,11 +104,11 @@ bool configuration::check_feature(feature f) const return false; break; case feature::face_tracking: - if (xr::face_tracker_supported(instance, system) == xr::face_tracker_type::none) + if (system.face_tracker_supported() == xr::face_tracker_type::none) return false; break; case feature::body_tracking: - if (xr::body_tracker_supported(instance, system) == xr::body_tracker_type::none) + if (system.body_tracker_supported() == xr::body_tracker_type::none) return false; break; } @@ -149,7 +145,7 @@ void configuration::set_feature(feature f, bool state) configuration::configuration(xr::system & system) { - passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color; + passthrough_enabled = system.passthrough_supported() == xr::passthrough_type::color; features[feature::hand_tracking] = system.hand_tracking_supported(); try { @@ -211,7 +207,7 @@ configuration::configuration(xr::system & system) features[i] = val.get_bool(); } - if (system.passthrough_supported() == xr::system::passthrough_type::no_passthrough) + if (system.passthrough_supported() == xr::passthrough_type::none) passthrough_enabled = false; if (auto val = root["override_foveation_enable"]; val.is_bool()) @@ -237,7 +233,7 @@ configuration::configuration(xr::system & system) resolution_scale = 1.4; sgsr = {}; openxr_post_processing = {}; - passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color; + passthrough_enabled = system.passthrough_supported() == xr::passthrough_type::color; } } diff --git a/client/scene.cpp b/client/scene.cpp index feeb29fe..70474d3a 100644 --- a/client/scene.cpp +++ b/client/scene.cpp @@ -51,8 +51,6 @@ scene::scene(key, const meta & current_meta, std::span support queue_family_index(application::instance().vk_queue_family_index), current_meta(current_meta) { - passthrough_supported = system.passthrough_supported(); - swapchain_format = vk::Format::eUndefined; spdlog::info("Supported swapchain formats:"); diff --git a/client/scene.h b/client/scene.h index e84bbcea..9593100c 100644 --- a/client/scene.h +++ b/client/scene.h @@ -103,7 +103,6 @@ public: protected: vk::Format swapchain_format; vk::Format depth_format; - xr::system::passthrough_type passthrough_supported; bool composition_layer_depth_test_supported; bool composition_layer_color_scale_bias_supported; diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index 33a60dd8..e61c7eb4 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -926,7 +926,7 @@ void scenes::lobby::gui_settings() imgui_ctx->vibrate_on_hover(); } - auto body_tracker = xr::body_tracker_supported(instance, system); + auto body_tracker = system.body_tracker_supported(); { ImGui::BeginDisabled(body_tracker == xr::body_tracker_type::none); bool enabled = config.check_feature(feature::body_tracking); @@ -976,7 +976,7 @@ void scenes::lobby::gui_settings() ImGui::EndDisabled(); } - ImGui::BeginDisabled(passthrough_supported == xr::system::passthrough_type::no_passthrough); + ImGui::BeginDisabled(system.passthrough_supported() == xr::passthrough_type::none); if (ImGui::Checkbox(_S("Enable video passthrough in lobby"), &config.passthrough_enabled)) { setup_passthrough(); @@ -1310,7 +1310,7 @@ void scenes::lobby::gui_first_run() item{ .f = feature::body_tracking, .text = _S("Enable body tracking?"), - .supported = xr::body_tracker_supported(instance, system) != xr::body_tracker_type::none, + .supported = system.body_tracker_supported() != xr::body_tracker_type::none, }, }; @@ -1730,7 +1730,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) }); } - if (xr::body_tracker_supported(instance, system) != xr::body_tracker_type::none) + if (system.body_tracker_supported() != xr::body_tracker_type::none) { items.push_back({ .f = feature::body_tracking, diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index fad4731e..636ef020 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -254,7 +254,7 @@ std::shared_ptr scenes::stream::create(std::unique_ptrinstance, self->system)) + switch (self->system.face_tracker_supported()) { case xr::face_tracker_type::none: info.face_tracking = from_headset::face_type::none; @@ -272,7 +272,7 @@ std::shared_ptr scenes::stream::create(std::unique_ptrinstance, self->system)) + switch (self->system.body_tracker_supported()) { case xr::body_tracker_type::none: break; @@ -289,7 +289,7 @@ std::shared_ptr scenes::stream::create(std::unique_ptrsystem.passthrough_supported() != xr::system::passthrough_type::no_passthrough; + info.passthrough = self->system.passthrough_supported() != xr::passthrough_type::none; info.system_name = std::string(self->system.properties().systemName); audio::get_audio_description(info); diff --git a/client/xr/body_tracker.h b/client/xr/body_tracker.h index 375579db..53428976 100644 --- a/client/xr/body_tracker.h +++ b/client/xr/body_tracker.h @@ -21,29 +21,23 @@ #include "fb_body_tracker.h" #include "htc_body_tracker.h" #include "pico_body_tracker.h" +#include "xr/system.h" #include #include #include +#include namespace xr { class instance; -class system; - -enum class body_tracker_type -{ - none, - fb, - htc, - pico, -}; +class session; using body_tracker = std::variant; -body_tracker_type body_tracker_supported(xr::instance &, xr::system &); - body_tracker make_body_tracker(xr::instance &, xr::system &, xr::session &, std::vector> & generic_trackers, bool full_body, bool hips); +body_tracker_type body_tracker_supported(xr::instance &, xr::system &); + } // namespace xr diff --git a/client/xr/face_tracker.h b/client/xr/face_tracker.h index 7cdd8fe0..36ad1af4 100644 --- a/client/xr/face_tracker.h +++ b/client/xr/face_tracker.h @@ -21,6 +21,7 @@ #include "fb_face_tracker2.h" #include "htc_face_tracker.h" #include "pico_face_tracker.h" +#include "xr/system.h" #include @@ -28,20 +29,12 @@ namespace xr { class instance; -class system; - -enum class face_tracker_type -{ - none, - fb, - htc, - pico, -}; +class session; using face_tracker = std::variant; -face_tracker_type face_tracker_supported(xr::instance &, xr::system &); - face_tracker make_face_tracker(xr::instance &, xr::system &, xr::session &); +face_tracker_type face_tracker_supported(xr::instance &, xr::system &); + } // namespace xr diff --git a/client/xr/session.cpp b/client/xr/session.cpp index bc0cd2af..898c19da 100644 --- a/client/xr/session.cpp +++ b/client/xr/session.cpp @@ -344,7 +344,7 @@ void xr::session::enable_passthrough(xr::system & system) if (not std::holds_alternative(passthrough)) return; - if (system.passthrough_supported() == xr::system::passthrough_type::no_passthrough) + if (system.passthrough_supported() == xr::passthrough_type::none) return; if (utils::contains(application::get_xr_extensions(), XR_FB_PASSTHROUGH_EXTENSION_NAME)) diff --git a/client/xr/system.cpp b/client/xr/system.cpp index 097061e4..02068e00 100644 --- a/client/xr/system.cpp +++ b/client/xr/system.cpp @@ -20,7 +20,9 @@ #include "system.h" #include "application.h" +#include "body_tracker.h" #include "details/enumerate.h" +#include "face_tracker.h" #include "openxr/openxr.h" #include "utils/contains.h" #include "vk/check.h" @@ -44,6 +46,9 @@ xr::system::system(xr::instance & inst, XrFormFactor formfactor) if (inst.has_extension(XR_EXT_HAND_TRACKING_EXTENSION_NAME)) hand_tracking_supported_ = hand_tracking_properties().supportsHandTracking; + + body_tracker = xr::body_tracker_supported(inst, *this); + face_tracker = xr::face_tracker_supported(inst, *this); } XrGraphicsRequirementsVulkan2KHR xr::system::graphics_requirements() const @@ -198,7 +203,7 @@ XrSystemBodyTrackingPropertiesBD xr::system::bd_body_tracking_properties() const return body_tracking_prop; } -xr::system::passthrough_type xr::system::passthrough_supported() const +xr::passthrough_type xr::system::passthrough_supported() const { if (utils::contains(environment_blend_modes(XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO), XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND)) return passthrough_type::color; @@ -227,7 +232,7 @@ xr::system::passthrough_type xr::system::passthrough_supported() const if (passthrough_prop.supportsPassthrough) { if (!(passthrough_prop2.capabilities & XR_PASSTHROUGH_CAPABILITY_BIT_FB)) - return passthrough_type::no_passthrough; + return passthrough_type::none; if (passthrough_prop2.capabilities & XR_PASSTHROUGH_CAPABILITY_COLOR_BIT_FB) return passthrough_type::color; @@ -236,7 +241,16 @@ xr::system::passthrough_type xr::system::passthrough_supported() const } } - return passthrough_type::no_passthrough; + return passthrough_type::none; +} +xr::face_tracker_type xr::system::face_tracker_supported() const +{ + return face_tracker; +} + +xr::body_tracker_type xr::system::body_tracker_supported() const +{ + return body_tracker; } bool xr::system::hand_tracking_supported() const diff --git a/client/xr/system.h b/client/xr/system.h index 7bd9da9b..5797e921 100644 --- a/client/xr/system.h +++ b/client/xr/system.h @@ -32,20 +32,39 @@ namespace xr { class instance; +enum class passthrough_type +{ + none, + bw, + color +}; + +enum class body_tracker_type +{ + none, + fb, + htc, + pico, +}; + +enum class face_tracker_type +{ + none, + fb, + htc, + pico, +}; + class system { instance * inst = nullptr; XrSystemId id = XR_NULL_SYSTEM_ID; bool hand_tracking_supported_ = false; + passthrough_type passthrough; + body_tracker_type body_tracker; + face_tracker_type face_tracker; public: - enum class passthrough_type - { - no_passthrough, - bw, - color - }; - system() = default; system(const system &) = default; system & operator=(const system &) = default; @@ -68,8 +87,11 @@ public: XrSystemFacialTrackingPropertiesHTC htc_face_tracking_properties() const; XrSystemBodyTrackingPropertiesFB fb_body_tracking_properties() const; XrSystemBodyTrackingPropertiesBD bd_body_tracking_properties() const; - passthrough_type passthrough_supported() const; + bool hand_tracking_supported() const; + passthrough_type passthrough_supported() const; + face_tracker_type face_tracker_supported() const; + body_tracker_type body_tracker_supported() const; XrGraphicsRequirementsVulkan2KHR graphics_requirements() const; vk::raii::PhysicalDevice physical_device(vk::raii::Instance & vulkan) const;