Add rendering engine

This commit is contained in:
Guillaume Meunier
2024-01-28 11:33:32 +01:00
parent 814663beae
commit 95d1020559
45 changed files with 4170 additions and 1863 deletions
+32
View File
@@ -0,0 +1,32 @@
/*
* WiVRn VR streaming
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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 <concepts>
namespace utils
{
template<typename T>
requires std::integral<T>
T align_up(T alignment, T value)
{
return ((value + alignment - 1) / alignment) * alignment;
}
}
+96
View File
@@ -0,0 +1,96 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
*
* 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 <spdlog/fmt/fmt.h>
#include <glm/fwd.hpp>
// /usr/include/fmt/chrono.h:2017
template<glm::length_t L, typename T, glm::qualifier Q, typename Char>
struct fmt::formatter<glm::vec<L, T, Q>, Char> //: fmt::formatter<T>
{
// auto parse(basic_format_parse_context<Char>& ctx) const -> decltype(ctx.begin())
// {
// auto begin = ctx.begin(), end = ctx.end();
// // if (begin != end && *begin == 'L') {
// // ++begin;
// // localized = true;
// // }
// return begin;
// }
auto parse(basic_format_parse_context<Char>& ctx) const // -> decltype(ctx.begin())
{
return ctx.begin();
}
template <typename FormatContext>
auto format(const glm::vec<L, T, Q>& v, FormatContext& ctx) const -> decltype(ctx.out())
{
if constexpr (L == 1)
{
return fmt::format_to(ctx.out(), "[ {} ]", v.x);
}
if constexpr (L == 2)
{
return fmt::format_to(ctx.out(), "[ {}, {} ]", v.x, v.y);
}
if constexpr (L == 3)
{
return fmt::format_to(ctx.out(), "[ {}, {}, {} ]", v.x, v.y, v.z);
}
if constexpr (L == 4)
{
return fmt::format_to(ctx.out(), "[ {}, {}, {}, {} ]", v.x, v.y, v.z, v.w);
}
// return formatter<std::string_view>(
// auto time = std::tm();
// time.tm_wday = static_cast<int>(wd.c_encoding());
// detail::get_locale loc(localized, ctx.locale());
// auto w = detail::tm_writer<decltype(ctx.out()), Char>(loc, ctx.out(), time);
// w.on_abbr_weekday();
// return w.out();
}
};
/*
template<glm::length_t C, glm::length_t R, typename T, glm::qualifier Q>
struct fmt::formatter<glm::mat<C, R, T, Q>> : fmt::formatter<std::string>
{
};
template<typename T, glm::qualifier Q>
struct fmt::formatter<glm::qua<T, Q>> : fmt::formatter<std::string>
{
};*/
+63
View File
@@ -0,0 +1,63 @@
/*
* WiVRn VR streaming
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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 <boost/pfr/core.hpp>
#include <type_traits>
#include <vulkan/vulkan.hpp>
namespace utils
{
template<typename T>
struct is_vk_flags : std::false_type {};
template<typename T>
struct is_vk_flags<vk::Flags<T>> : std::true_type {};
template<typename T>
struct magic_hash
{
std::size_t operator()(const T & info) const noexcept
{
size_t h = 0;
boost::pfr::for_each_field(info, [&](const auto & member) {
using U = std::remove_cvref_t<decltype(member)>;
if constexpr (is_vk_flags<U>::value)
{
using V = U::MaskType;
std::hash<V> hasher;
h = std::rotl(h, 5) ^ hasher(static_cast<V>(member));
}
else
{
std::hash<U> hasher;
h = std::rotl(h, 5) ^ hasher(member);
}
});
return h;
}
};
}
+25 -2
View File
@@ -25,12 +25,34 @@
namespace utils
{
template<typename T>
concept has_const_iterator = requires {
std::declval<typename T::const_iterator>();
};
template<typename T, bool> struct get_const_iterator_aux;
template<typename T> struct get_const_iterator_aux<T, true>
{
using const_iterator = T::const_iterator;
};
template<typename T> struct get_const_iterator_aux<T, false>
{
using const_iterator = T::iterator;
};
template<typename T>
using get_const_iterator = get_const_iterator_aux<T, has_const_iterator<T>>::const_iterator;
template <typename T>
struct enumerate_range
{
struct iterator
{
using underlying_iterator = std::conditional_t<std::is_const_v<T>, typename T::const_iterator, typename T::iterator>;
using underlying_iterator = std::conditional_t<std::is_const_v<T>, get_const_iterator<T>, typename T::iterator>;
using underlying_value_type = std::conditional_t<std::is_const_v<T>, const typename T::value_type, typename T::value_type>;
size_t index;
@@ -38,7 +60,8 @@ struct enumerate_range
std::pair<size_t, underlying_value_type &> operator*() const
{
return {index, *it};
underlying_value_type & x = *it;
return {index, x};
}
iterator & operator++()