/* * WiVRn VR streaming * Copyright (C) 2022 Guillaume Meunier * Copyright (C) 2022 Patrick Nicolas * * 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 "xr/actionset.h" #include "xr/session.h" #include "xr/swapchain.h" #include #include #include #include // See http://www.nirfriedman.com/2018/04/29/unforgettable-factory/ // for automatic registration of scenes class scene { public: struct action_binding { std::string action_name; std::string input_source; }; struct suggested_binding { std::string profile_name; std::vector paths; }; struct meta { // Filled by the scene class std::string name; std::vector> actions; std::vector bindings; // Filled by the application class xr::actionset actionset; std::unordered_map> actions_by_name; std::unordered_map spaces_by_name; }; private: // Force derived classes to inherit from scene_impl instead of scene class key {}; template friend class scene_impl; friend class application; protected: static std::vector scene_registry; xr::instance & instance; xr::system & system; xr::session & session; xr::space & world_space; XrViewConfigurationType viewconfig; vk::raii::Instance& vk_instance; vk::raii::Device& device; vk::raii::PhysicalDevice& physical_device; vk::raii::Queue& queue; vk::raii::CommandPool& commandpool; uint32_t queue_family_index; const meta& current_meta; std::pair get_action(const std::string & name) { return current_meta.actions_by_name.at(name); } XrSpace get_action_space(const std::string & name) { return current_meta.spaces_by_name.at(name); } public: scene(key, const meta&); virtual ~scene(); virtual void render() = 0; virtual void on_unfocused(); virtual void on_focused(); virtual void on_interaction_profile_changed(); virtual void on_reference_space_changed(XrReferenceSpaceType space); virtual void on_session_state_changed(XrSessionState state); }; template class scene_impl : public scene { friend T; friend scene; // Magically register all classes that derive from scene_impl static bool register_scene() { scene_registry.emplace_back(&T::get_meta_scene()); return true; } static inline bool registered = scene_impl::register_scene(); scene_impl() : scene(key{}, T::get_meta_scene()) { (void)registered; } };