/* * WiVRn VR streaming * Copyright (C) 2026 galister * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #pragma once #include "utils/handle.h" #include "utils/thread_safe.h" #include "wivrn_packets.h" #include "xr/swapchain.h" #include #include #include #include namespace xr { class instance; class session; class system; } // namespace xr namespace client_foveation { using angles = std::array; inline constexpr float default_convergence_distance = 1.0f; // Default foveation target is 1 m forward and 10 degrees below horizontal. inline constexpr float default_foveation_pitch = -0.17453292519943295f; // -10 degrees struct manual_override { bool enabled = false; float pitch = default_foveation_pitch; float distance = default_convergence_distance; }; // Unified class for static, meta and eye-gaze based foveation. class center { public: static constexpr size_t view_count = 2; static constexpr int32_t dummy_swapchain_size = 512; struct projection_layer { XrCompositionLayerFlags flags; XrSpace space; std::array views; }; center(xr::instance &, xr::system &, xr::session &, vk::raii::Device &, vk::raii::CommandPool &, thread_safe &, vk::Format swapchain_format); ~center(); bool supports_meta() const; manual_override get_manual_mode() const; void set_manual_mode(manual_override mode); bool is_cropped(std::span submitted_fov, std::span valid) const; bool needs_swapchain_recreation(bool cropped) const; bool use_meta_swapchain(bool cropped) const; void on_swapchain_recreated(bool cropped); void set_cropped(bool cropped); void update(std::span submitted_fov, std::span valid, XrSwapchain stream_swapchain, XrTime display_time); std::optional get_layer() const; std::optional take_packet(); private: mutable thread_safe manual_mode_{}; xr::instance & instance; xr::session & session; vk::raii::Device & device; vk::raii::CommandPool & commandpool; thread_safe & queue; vk::Format swapchain_format; PFN_xrCreateFoveationProfileFB xrCreateFoveationProfileFB = nullptr; PFN_xrDestroyFoveationProfileFB xrDestroyFoveationProfileFB = nullptr; PFN_xrUpdateSwapchainFB xrUpdateSwapchainFB = nullptr; PFN_xrGetFoveationEyeTrackedStateMETA xrGetFoveationEyeTrackedStateMETA = nullptr; std::optional> foveation_profile; std::array headset_fov{}; std::optional cropped_mode; xr::swapchain dummy_swapchain; std::optional layer_; std::optional packet_; bool update_meta_swapchain(XrSwapchain swapchain) const; std::optional meta_angles(XrSwapchain swapchain, std::span fov) const; void create_dummy_swapchain(); }; } // namespace client_foveation