Files

118 lines
4.5 KiB
C++

/*
* WiVRn VR streaming
* Copyright (C) 2022 Guillaume Meunier <[email protected]>
* Copyright (C) 2022 Patrick Nicolas <[email protected]>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "utils/handle.h"
#include "utils/thread_safe.h"
#include <span>
#include <string>
#include <vector>
#include <vulkan/vulkan_raii.hpp>
#include <openxr/openxr.h>
#include "hand_tracker.h"
#include "passthrough.h"
#include "space.h"
namespace xr
{
class instance;
class system;
class session : public utils::handle<XrSession, xrDestroySession>
{
instance * inst = nullptr;
xr::passthrough passthrough;
thread_safe<vk::raii::Queue> * queue = nullptr;
PFN_xrGetDisplayRefreshRateFB xrGetDisplayRefreshRateFB = nullptr;
PFN_xrEnumerateDisplayRefreshRatesFB xrEnumerateDisplayRefreshRatesFB = nullptr;
PFN_xrRequestDisplayRefreshRateFB xrRequestDisplayRefreshRateFB = nullptr;
PFN_xrPerfSettingsSetPerformanceLevelEXT xrPerfSettingsSetPerformanceLevelEXT = nullptr;
PFN_xrRequestBoundaryVisibilityMETA xrRequestBoundaryVisibilityMETA = nullptr;
XrBoundaryVisibilityMETA runtime_boundary_visibility = XR_BOUNDARY_VISIBILITY_NOT_SUPPRESSED_META;
bool passthrough_boundary_enabled = true;
bool boundary_request_failed = false;
void update_boundary_visibility();
public:
session() = default;
session(instance &, system &, vk::raii::Instance &, vk::raii::PhysicalDevice &, vk::raii::Device &, thread_safe<vk::raii::Queue> & queue, int queue_family_index);
std::vector<XrReferenceSpaceType> get_reference_spaces() const;
space create_reference_space(XrReferenceSpaceType ref, const XrPosef & pose = {{0, 0, 0, 1}, {0, 0, 0}});
space create_action_space(XrAction action, const XrPosef & pose = {{0, 0, 0, 1}, {0, 0, 0}});
hand_tracker create_hand_tracker(XrHandEXT hand, XrHandJointSetEXT hand_joint_set = XR_HAND_JOINT_SET_DEFAULT_EXT);
std::vector<vk::Format> get_swapchain_formats() const;
XrFrameState wait_frame();
void begin_frame();
void end_frame(XrTime display_time, const std::vector<XrCompositionLayerBaseHeader *> & layers, XrEnvironmentBlendMode blend_mode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE);
void begin_session(XrViewConfigurationType view_config);
void end_session();
std::pair<XrViewStateFlags, std::vector<XrView>> locate_views(XrViewConfigurationType view_config_type,
XrTime display_time,
XrSpace space);
XrViewStateFlags locate_views(XrViewConfigurationType view_config_type,
XrTime display_time,
XrSpace space,
std::vector<XrView> & views);
std::string get_current_interaction_profile(const std::string & path);
void attach_actionsets(const std::vector<XrActionSet> & actionsets);
std::vector<std::string> sources_for_action(XrAction a);
std::vector<std::string> localized_sources_for_action(
XrAction action,
XrInputSourceLocalizedNameFlags components = XR_INPUT_SOURCE_LOCALIZED_NAME_USER_PATH_BIT | XR_INPUT_SOURCE_LOCALIZED_NAME_INTERACTION_PROFILE_BIT | XR_INPUT_SOURCE_LOCALIZED_NAME_COMPONENT_BIT);
float get_current_refresh_rate();
std::vector<float> get_refresh_rates();
void set_refresh_rate(float);
void sync_actions(XrActionSet action_set, XrPath subaction_path = XR_NULL_PATH);
void sync_actions(XrActionSet action_set, const std::string & subaction_path);
void sync_actions(std::span<XrActionSet> action_sets);
void enable_passthrough(xr::system &);
void disable_passthrough();
xr::passthrough & get_passthrough()
{
return passthrough;
}
void set_performance_level(XrPerfSettingsDomainEXT, XrPerfSettingsLevelEXT);
bool boundary_visibility_supported() const
{
return xrRequestBoundaryVisibilityMETA;
}
void set_passthrough_boundary_enabled(bool);
void on_boundary_visibility_changed(XrBoundaryVisibilityMETA);
};
} // namespace xr