tried making naming more uniform and implemented most of the opengl managers
This commit is contained in:
40
include/assets/data_stores/generic/generic_basic_store.hpp
Normal file
40
include/assets/data_stores/generic/generic_basic_store.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <span>
|
||||
|
||||
#include "util/uix.hpp"
|
||||
#include "util/id_type.hpp"
|
||||
|
||||
template<typename T>
|
||||
class generic_basic_store
|
||||
{
|
||||
public:
|
||||
using id_type = ztu::id_type_for<generic_basic_store, ztu::u32>;
|
||||
using container_type = std::vector<T>;
|
||||
using iterator_type = typename container_type::iterator;
|
||||
using const_iterator = typename container_type::const_iterator;
|
||||
|
||||
id_type add(const T& data);
|
||||
|
||||
[[nodiscard]] std::pair<iterator_type, bool> find(id_type id);
|
||||
|
||||
[[nodiscard]] std::pair<const_iterator, bool> find(id_type id) const;
|
||||
|
||||
[[nodiscard]] std::span<T> data();
|
||||
|
||||
[[nodiscard]] std::span<const T> data() const;
|
||||
|
||||
void remove(iterator_type it);
|
||||
|
||||
void clear();
|
||||
|
||||
private:
|
||||
std::vector<T> m_data;
|
||||
std::vector<id_type> m_ids;
|
||||
id_type m_next_data_id{ 1 };
|
||||
};
|
||||
|
||||
#define INCLUDE_GENERIC_BASIC_STORE_IMPLEMENTATION
|
||||
#include "assets/data_stores/generic/generic_basic_store.ipp"
|
||||
#undef INCLUDE_GENERIC_BASIC_STORE_IMPLEMENTATION
|
||||
155
include/assets/data_stores/generic/generic_material_store.hpp
Normal file
155
include/assets/data_stores/generic/generic_material_store.hpp
Normal file
@@ -0,0 +1,155 @@
|
||||
#pragma once
|
||||
|
||||
#include "assets/components/material_components.hpp"
|
||||
#include "assets/data/material_data.hpp"
|
||||
#include "assets/data_views/material_view.hpp"
|
||||
|
||||
|
||||
namespace assets::detail
|
||||
{
|
||||
|
||||
template<typename... Ts>
|
||||
class generic_material_store;
|
||||
|
||||
template<typename... Ts>
|
||||
class generic_material_store_iterator
|
||||
{
|
||||
public:
|
||||
using size_type = std::size_t;
|
||||
using count_type = ztu::u32;
|
||||
using component_flag_type = material_components::flags;
|
||||
using id_type = ztu::id_type_for<generic_material_store<Ts...>, ztu::u32>;
|
||||
using value_type = std::pair<id_type, material_view>;
|
||||
using flag_count_type = std::tuple<component_flag_type>;
|
||||
|
||||
using id_iterator_type = id_type*;
|
||||
using component_iterator_type = std::tuple<std::add_pointer_t<Ts>...>;
|
||||
using flag_count_iterator_type = const flag_count_type*;
|
||||
|
||||
using offsets_type = std::array<size_type, 1 + sizeof...(Ts)>;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using pointer = value_type*;
|
||||
using reference = value_type;
|
||||
using iterator_category = std::random_access_iterator_tag;
|
||||
|
||||
private:
|
||||
friend generic_material_store<Ts...>;
|
||||
|
||||
generic_material_store_iterator(
|
||||
id_iterator_type ids,
|
||||
const component_iterator_type& components,
|
||||
flag_count_iterator_type flag_counts,
|
||||
std::size_t index,
|
||||
const offsets_type& offsets
|
||||
);
|
||||
|
||||
public:
|
||||
constexpr generic_material_store_iterator() noexcept = default;
|
||||
|
||||
constexpr generic_material_store_iterator(const generic_material_store_iterator&) noexcept = default;
|
||||
constexpr generic_material_store_iterator(generic_material_store_iterator&&) noexcept = default;
|
||||
|
||||
constexpr generic_material_store_iterator& operator=(const generic_material_store_iterator&) noexcept = default;
|
||||
constexpr generic_material_store_iterator& operator=(generic_material_store_iterator&&) noexcept = default;
|
||||
|
||||
reference operator*() const;
|
||||
|
||||
generic_material_store_iterator& operator++();
|
||||
generic_material_store_iterator operator++(int);
|
||||
generic_material_store_iterator& operator--();
|
||||
generic_material_store_iterator operator--(int);
|
||||
|
||||
generic_material_store_iterator& operator+=(difference_type n);
|
||||
generic_material_store_iterator& operator-=(difference_type n);
|
||||
generic_material_store_iterator operator+(difference_type n) const;
|
||||
generic_material_store_iterator operator-(difference_type n) const;
|
||||
difference_type operator-(const generic_material_store_iterator& other) const;
|
||||
|
||||
reference operator[](difference_type n) const;
|
||||
|
||||
bool operator==(const generic_material_store_iterator& other) const;
|
||||
bool operator!=(const generic_material_store_iterator& other) const;
|
||||
bool operator<(const generic_material_store_iterator& other) const;
|
||||
bool operator<=(const generic_material_store_iterator& other) const;
|
||||
bool operator>(const generic_material_store_iterator& other) const;
|
||||
bool operator>=(const generic_material_store_iterator& other) const;
|
||||
|
||||
protected:
|
||||
template <std::size_t N>
|
||||
static bool is_component_enabled(component_flag_type flag);
|
||||
|
||||
template <std::size_t... Is>
|
||||
void calc_offsets(std::index_sequence<Is...>, difference_type n);
|
||||
|
||||
template <std::size_t... Is>
|
||||
reference dereference(std::index_sequence<Is...>) const;
|
||||
|
||||
private:
|
||||
id_iterator_type m_ids{};
|
||||
component_iterator_type m_components{};
|
||||
flag_count_iterator_type m_flag_counts{};
|
||||
size_type m_index{};
|
||||
offsets_type m_offsets{};
|
||||
};
|
||||
|
||||
|
||||
template<typename... Ts>
|
||||
class generic_material_store
|
||||
{
|
||||
public:
|
||||
using size_type = std::size_t;
|
||||
using count_type = ztu::u32;
|
||||
using component_flag_type = material_components::flags;
|
||||
|
||||
using iterator_type = generic_material_store_iterator<Ts...>;
|
||||
using const_iterator = generic_material_store_iterator<std::add_const_t<Ts>...>;
|
||||
using view_type = std::ranges::subrange<iterator_type>;
|
||||
using const_view_type = std::ranges::subrange<const_iterator>;
|
||||
using id_type = ztu::id_type_for<generic_material_store, ztu::u32>;
|
||||
|
||||
id_type add(const material_data& material);
|
||||
|
||||
[[nodiscard]] std::pair<iterator_type, bool> find(id_type id);
|
||||
|
||||
[[nodiscard]] std::pair<const_iterator, bool> find(id_type id) const;
|
||||
|
||||
void remove(const iterator_type& it);
|
||||
|
||||
void clear();
|
||||
|
||||
iterator_type begin();
|
||||
|
||||
iterator_type end();
|
||||
|
||||
const_iterator begin() const;
|
||||
|
||||
const_iterator end() const;
|
||||
|
||||
const_iterator cbegin() const;
|
||||
|
||||
const_iterator cend() const;
|
||||
|
||||
view_type view();
|
||||
|
||||
const_view_type view() const;
|
||||
|
||||
protected:
|
||||
std::tuple<std::add_pointer_t<Ts>...> component_iterators();
|
||||
|
||||
std::tuple<std::add_pointer_t<std::add_const_t<Ts>>...> component_iterators() const;
|
||||
|
||||
std::array<count_type, 1 + sizeof...(Ts)> array_counts() const;
|
||||
|
||||
private:
|
||||
std::vector<id_type> m_ids;
|
||||
std::tuple<std::vector<Ts>...> m_component_arrays;
|
||||
std::vector<component_flag_type> m_component_flag_counts;
|
||||
id_type m_next_data_id{ 1 };
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#define INCLUDE_GENERIC_MATERIAL_STORE_IMPLEMENTATION
|
||||
#include "assets/data_stores/generic/generic_material_store.ipp"
|
||||
#undef INCLUDE_GENERIC_MATERIAL_STORE_IMPLEMENTATION
|
||||
167
include/assets/data_stores/generic/generic_mesh_store.hpp
Normal file
167
include/assets/data_stores/generic/generic_mesh_store.hpp
Normal file
@@ -0,0 +1,167 @@
|
||||
#pragma once
|
||||
|
||||
#include "assets/components/mesh_vertex_components.hpp"
|
||||
#include "assets/data_stores/material_store.hpp"
|
||||
#include "assets/data/mesh_data.hpp"
|
||||
#include "assets/data_views/mesh_view.hpp"
|
||||
|
||||
namespace assets::detail
|
||||
{
|
||||
|
||||
template<typename... Ts>
|
||||
class generic_mesh_store;
|
||||
|
||||
template<typename... Ts>
|
||||
class generic_mesh_store_iterator
|
||||
{
|
||||
public:
|
||||
using size_type = std::size_t;
|
||||
using count_type = ztu::u32;
|
||||
using index_type = mesh_data::index_type;
|
||||
using material_id_type = material_store::id_type;
|
||||
using component_flag_type = mesh_vertex_components::flags;
|
||||
using id_type = ztu::id_type_for<generic_mesh_store<Ts...>, ztu::u32>;
|
||||
using value_type = std::pair<id_type, mesh_view>;
|
||||
using flag_count_type = std::tuple<component_flag_type, count_type, count_type>;
|
||||
|
||||
using id_iterator_type = id_type*;
|
||||
using component_iterator_type = std::tuple<std::add_pointer_t<Ts>...>;
|
||||
using index_iterator_type = index_type*;
|
||||
using flag_count_iterator_type = const flag_count_type*;
|
||||
using material_id_iterator_type = material_id_type*;
|
||||
|
||||
using offsets_type = std::array<size_type, 1 + sizeof...(Ts)>;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using pointer = value_type*;
|
||||
using reference = value_type;
|
||||
using iterator_category = std::random_access_iterator_tag;
|
||||
|
||||
private:
|
||||
friend generic_mesh_store<Ts...>;
|
||||
|
||||
generic_mesh_store_iterator(
|
||||
id_iterator_type ids,
|
||||
index_iterator_type indices,
|
||||
const component_iterator_type& components,
|
||||
material_id_iterator_type material_ids,
|
||||
flag_count_iterator_type flag_counts,
|
||||
std::size_t index,
|
||||
const offsets_type& offsets
|
||||
);
|
||||
|
||||
public:
|
||||
constexpr generic_mesh_store_iterator() noexcept = default;
|
||||
|
||||
constexpr generic_mesh_store_iterator(const generic_mesh_store_iterator&) noexcept = default;
|
||||
constexpr generic_mesh_store_iterator(generic_mesh_store_iterator&&) noexcept = default;
|
||||
|
||||
constexpr generic_mesh_store_iterator& operator=(const generic_mesh_store_iterator&) noexcept = default;
|
||||
constexpr generic_mesh_store_iterator& operator=(generic_mesh_store_iterator&&) noexcept = default;
|
||||
|
||||
reference operator*() const;
|
||||
|
||||
generic_mesh_store_iterator& operator++();
|
||||
generic_mesh_store_iterator operator++(int);
|
||||
generic_mesh_store_iterator& operator--();
|
||||
generic_mesh_store_iterator operator--(int);
|
||||
|
||||
generic_mesh_store_iterator& operator+=(difference_type n);
|
||||
generic_mesh_store_iterator& operator-=(difference_type n);
|
||||
generic_mesh_store_iterator operator+(difference_type n) const;
|
||||
generic_mesh_store_iterator operator-(difference_type n) const;
|
||||
difference_type operator-(const generic_mesh_store_iterator& other) const;
|
||||
|
||||
reference operator[](difference_type n) const;
|
||||
|
||||
bool operator==(const generic_mesh_store_iterator& other) const;
|
||||
bool operator!=(const generic_mesh_store_iterator& other) const;
|
||||
bool operator<(const generic_mesh_store_iterator& other) const;
|
||||
bool operator<=(const generic_mesh_store_iterator& other) const;
|
||||
bool operator>(const generic_mesh_store_iterator& other) const;
|
||||
bool operator>=(const generic_mesh_store_iterator& other) const;
|
||||
|
||||
protected:
|
||||
template <std::size_t N>
|
||||
static bool is_component_enabled(component_flag_type flag);
|
||||
|
||||
template <std::size_t... Is>
|
||||
void calc_offsets(std::index_sequence<Is...>, difference_type n);
|
||||
|
||||
template <std::size_t... Is>
|
||||
reference dereference(std::index_sequence<Is...>) const;
|
||||
|
||||
private:
|
||||
id_iterator_type m_ids{};
|
||||
index_iterator_type m_indices{};
|
||||
component_iterator_type m_components{};
|
||||
material_id_iterator_type m_material_ids{};
|
||||
flag_count_iterator_type m_flag_counts{};
|
||||
size_type m_index{};
|
||||
offsets_type m_offsets{};
|
||||
};
|
||||
|
||||
|
||||
template<typename... Ts>
|
||||
class generic_mesh_store
|
||||
{
|
||||
public:
|
||||
using size_type = std::size_t;
|
||||
using count_type = ztu::u32;
|
||||
using index_type = mesh_data::index_type;
|
||||
using component_flag_type = mesh_vertex_components::flags;
|
||||
using material_id_type = material_store::id_type;
|
||||
|
||||
using iterator_type = generic_mesh_store_iterator<Ts...>;
|
||||
using const_iterator = generic_mesh_store_iterator<std::add_const_t<Ts>...>;
|
||||
using view_type = std::ranges::subrange<iterator_type>;
|
||||
using const_view_type = std::ranges::subrange<const_iterator>;
|
||||
using id_type = ztu::id_type_for<generic_mesh_store, ztu::u32>;
|
||||
|
||||
id_type add(const mesh_data& mesh);
|
||||
|
||||
[[nodiscard]] std::pair<iterator_type, bool> find(id_type id);
|
||||
|
||||
[[nodiscard]] std::pair<const_iterator, bool> find(id_type id) const;
|
||||
|
||||
void remove(const iterator_type& it);
|
||||
|
||||
void clear();
|
||||
|
||||
iterator_type begin();
|
||||
|
||||
iterator_type end();
|
||||
|
||||
const_iterator begin() const;
|
||||
|
||||
const_iterator end() const;
|
||||
|
||||
const_iterator cbegin() const;
|
||||
|
||||
const_iterator cend() const;
|
||||
|
||||
view_type view();
|
||||
|
||||
const_view_type view() const;
|
||||
|
||||
protected:
|
||||
std::tuple<std::add_pointer_t<Ts>...> component_iterators();
|
||||
|
||||
std::tuple<std::add_pointer_t<std::add_const_t<Ts>>...> component_iterators() const;
|
||||
|
||||
std::array<count_type, 1 + sizeof...(Ts)> array_counts() const;
|
||||
|
||||
private:
|
||||
std::vector<id_type> m_ids;
|
||||
std::vector<index_type> m_indices;
|
||||
std::tuple<std::vector<Ts>...> m_component_arrays;
|
||||
std::vector<std::tuple<component_flag_type, count_type, count_type>> m_component_flag_counts;
|
||||
std::vector<material_store::id_type> m_material_ids;
|
||||
id_type m_next_data_id{ 1 };
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#define INCLUDE_GENERIC_MESH_STORE_IMPLEMENTATION
|
||||
#include "assets/data_stores/generic/generic_mesh_store.ipp"
|
||||
#undef INCLUDE_GENERIC_MESH_STORE_IMPLEMENTATION
|
||||
161
include/assets/data_stores/generic/generic_point_cloud_store.hpp
Normal file
161
include/assets/data_stores/generic/generic_point_cloud_store.hpp
Normal file
@@ -0,0 +1,161 @@
|
||||
#pragma once
|
||||
|
||||
#include "util/uix.hpp"
|
||||
#include "util/id_type.hpp"
|
||||
#include "assets/components/point_cloud_vertex_components.hpp"
|
||||
#include "assets/data/point_cloud_data.hpp"
|
||||
#include "assets/data_views/point_cloud_view.hpp"
|
||||
|
||||
namespace assets
|
||||
{
|
||||
|
||||
template<typename... Ts>
|
||||
class generic_point_cloud_store;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<typename... Ts>
|
||||
class generic_point_cloud_store_iterator
|
||||
{
|
||||
public:
|
||||
using size_type = std::size_t;
|
||||
using count_type = ztu::u32;
|
||||
using component_flag_type = point_cloud_vertex_components::flags;
|
||||
using id_type = ztu::id_type_for<generic_point_cloud_store<Ts...>, ztu::u32>;
|
||||
using value_type = std::pair<id_type, point_cloud_view>;
|
||||
using flag_count_type = std::tuple<component_flag_type, count_type, count_type>;
|
||||
|
||||
using id_iterator_type = id_type*;
|
||||
using component_iterator_type = std::tuple<std::add_pointer_t<Ts>...>;
|
||||
using flag_count_iterator_type = const flag_count_type*;
|
||||
|
||||
using offsets_type = std::array<size_type, 1 + sizeof...(Ts)>;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using pointer = value_type*;
|
||||
using reference = value_type;
|
||||
using iterator_category = std::random_access_iterator_tag;
|
||||
|
||||
private:
|
||||
friend generic_point_cloud_store<Ts...>;
|
||||
|
||||
generic_point_cloud_store_iterator(
|
||||
id_iterator_type ids,
|
||||
const component_iterator_type& components,
|
||||
flag_count_iterator_type flag_counts,
|
||||
std::size_t index,
|
||||
const offsets_type& offsets
|
||||
);
|
||||
|
||||
public:
|
||||
constexpr generic_point_cloud_store_iterator() noexcept = default;
|
||||
|
||||
constexpr generic_point_cloud_store_iterator(const generic_point_cloud_store_iterator&) noexcept = default;
|
||||
constexpr generic_point_cloud_store_iterator(generic_point_cloud_store_iterator&&) noexcept = default;
|
||||
|
||||
constexpr generic_point_cloud_store_iterator& operator=(const generic_point_cloud_store_iterator&) noexcept = default;
|
||||
constexpr generic_point_cloud_store_iterator& operator=(generic_point_cloud_store_iterator&&) noexcept = default;
|
||||
|
||||
reference operator*() const;
|
||||
|
||||
generic_point_cloud_store_iterator& operator++();
|
||||
generic_point_cloud_store_iterator operator++(int);
|
||||
generic_point_cloud_store_iterator& operator--();
|
||||
generic_point_cloud_store_iterator operator--(int);
|
||||
|
||||
generic_point_cloud_store_iterator& operator+=(difference_type n);
|
||||
generic_point_cloud_store_iterator& operator-=(difference_type n);
|
||||
generic_point_cloud_store_iterator operator+(difference_type n) const;
|
||||
generic_point_cloud_store_iterator operator-(difference_type n) const;
|
||||
difference_type operator-(const generic_point_cloud_store_iterator& other) const;
|
||||
|
||||
reference operator[](difference_type n) const;
|
||||
|
||||
bool operator==(const generic_point_cloud_store_iterator& other) const;
|
||||
bool operator!=(const generic_point_cloud_store_iterator& other) const;
|
||||
bool operator<(const generic_point_cloud_store_iterator& other) const;
|
||||
bool operator<=(const generic_point_cloud_store_iterator& other) const;
|
||||
bool operator>(const generic_point_cloud_store_iterator& other) const;
|
||||
bool operator>=(const generic_point_cloud_store_iterator& other) const;
|
||||
|
||||
protected:
|
||||
template <std::size_t N>
|
||||
static bool is_component_enabled(component_flag_type flag);
|
||||
|
||||
template <std::size_t... Is>
|
||||
void calc_offsets(std::index_sequence<Is...>, difference_type n);
|
||||
|
||||
template <std::size_t... Is>
|
||||
reference dereference(std::index_sequence<Is...>) const;
|
||||
|
||||
private:
|
||||
id_iterator_type m_ids{};
|
||||
component_iterator_type m_components{};
|
||||
flag_count_iterator_type m_flag_counts{};
|
||||
size_type m_index{};
|
||||
offsets_type m_offsets{};
|
||||
};
|
||||
|
||||
|
||||
template<typename... Ts>
|
||||
class generic_point_cloud_store
|
||||
{
|
||||
public:
|
||||
using size_type = std::size_t;
|
||||
using count_type = ztu::u32;
|
||||
using component_flag_type = point_cloud_vertex_components::flags;
|
||||
|
||||
using iterator_type = generic_point_cloud_store_iterator<Ts...>;
|
||||
using const_iterator = generic_point_cloud_store_iterator<std::add_const_t<Ts>...>;
|
||||
using view_type = std::ranges::subrange<iterator_type>;
|
||||
using const_view_type = std::ranges::subrange<const_iterator>;
|
||||
using id_type = ztu::id_type_for<generic_point_cloud_store, ztu::u32>;
|
||||
|
||||
id_type add(const point_cloud_data& point_cloud);
|
||||
|
||||
[[nodiscard]] std::pair<iterator_type, bool> find(id_type id);
|
||||
|
||||
[[nodiscard]] std::pair<const_iterator, bool> find(id_type id) const;
|
||||
|
||||
void remove(const iterator_type& it);
|
||||
|
||||
void clear();
|
||||
|
||||
iterator_type begin();
|
||||
|
||||
iterator_type end();
|
||||
|
||||
const_iterator begin() const;
|
||||
|
||||
const_iterator end() const;
|
||||
|
||||
const_iterator cbegin() const;
|
||||
|
||||
const_iterator cend() const;
|
||||
|
||||
view_type view();
|
||||
|
||||
const_view_type view() const;
|
||||
|
||||
protected:
|
||||
std::tuple<std::add_pointer_t<Ts>...> component_iterators();
|
||||
|
||||
std::tuple<std::add_pointer_t<std::add_const_t<Ts>>...> component_iterators() const;
|
||||
|
||||
std::array<count_type, 1 + sizeof...(Ts)> array_counts() const;
|
||||
|
||||
private:
|
||||
std::vector<id_type> m_ids;
|
||||
std::tuple<std::vector<Ts>...> m_component_arrays;
|
||||
std::vector<std::pair<component_flag_type, count_type>> m_component_flag_counts;
|
||||
id_type m_next_data_id{ 1 };
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#define INCLUDE_GENERIC_POINT_CLOUD_STORE_IMPLEMENTATION
|
||||
#include "assets/data_stores/generic/generic_point_cloud_store.ipp"
|
||||
#undef INCLUDE_GENERIC_POINT_CLOUD_STORE_IMPLEMENTATION
|
||||
Reference in New Issue
Block a user