Fixed issue in point_cloud_vertex_buffer_manager.cpp
This commit is contained in:
@@ -157,7 +157,6 @@ add_executable(z3d main.cpp
|
||||
include/assets/prefetch_queue.hpp
|
||||
include/util/string_list.hpp
|
||||
include/assets/data_stores/material_library_store.hpp
|
||||
source/assets/data_stores/generic/generic_dynamic_component_array_store.ipp
|
||||
include/assets/data/material_library_data.hpp
|
||||
include/assets/data_loaders/material_library_loader.hpp
|
||||
include/assets/prefetch_lookups/material_library_prefetch_lookup.hpp
|
||||
|
||||
@@ -18,6 +18,7 @@ struct generic_mesh_view
|
||||
mesh_vertex_components::flags component_flags;
|
||||
std::span<mesh_data::index_type> indices;
|
||||
std::tuple<std::span<Ts>...> vertex_component_arrays;
|
||||
std::size_t vertex_count;
|
||||
material_store::id_type material_id;
|
||||
};
|
||||
|
||||
|
||||
@@ -13,8 +13,9 @@ namespace detail
|
||||
template<typename... Ts>
|
||||
struct generic_point_cloud_view
|
||||
{
|
||||
point_cloud_vertex_components::flags vertex_components;
|
||||
point_cloud_vertex_components::flags vertex_component_flags;
|
||||
std::tuple<std::span<Ts>...> vertex_component_arrays;
|
||||
std::size_t point_count;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
|
||||
[[nodiscard]] point_cloud_handle handle() const;
|
||||
|
||||
[[nodiscard]] point_cloud_vertex_components::flags components() const;
|
||||
[[nodiscard]] assets::point_cloud_vertex_components::flags components() const;
|
||||
|
||||
private:
|
||||
point_cloud_handle m_handle{};
|
||||
|
||||
@@ -100,7 +100,10 @@ void interlace(
|
||||
buffers...
|
||||
);
|
||||
|
||||
const auto vertex_count = std::min({ buffers.size()... });
|
||||
const auto vertex_count = std::min({
|
||||
|
||||
buffers.size()...
|
||||
});
|
||||
const auto buffer_size = stride * vertex_count;
|
||||
|
||||
vertex_buffer.resize(buffer_size);
|
||||
|
||||
@@ -1,394 +0,0 @@
|
||||
#ifndef INCLUDE_GENERIC_DYNAMIC_COMPONENT_ARRAY_STORE_IMPLEMENTATION
|
||||
# error Never include this file directly include 'generic_dynamic_component_array_store.hpp'
|
||||
#endif
|
||||
#include <bits/ranges_algo.h>
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
component_array_iterator<C, Ts...>::component_array_iterator(
|
||||
id_array_pointer_type ids,
|
||||
const component_array_pointer_type& components,
|
||||
flag_count_pointer_type flags,
|
||||
std::size_t index,
|
||||
const offsets_type& offsets
|
||||
) :
|
||||
m_ids{ ids },
|
||||
m_components{ components },
|
||||
m_flag_counts{ flags },
|
||||
m_index{ index },
|
||||
m_offsets{ offsets } {}
|
||||
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
typename component_array_iterator<C, Ts...>::reference component_array_iterator<C, Ts...>::operator*() const {
|
||||
return dereference(std::index_sequence_for<Ts...>{});
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
component_array_iterator<C, Ts...>& component_array_iterator<C, Ts...>::operator++() {
|
||||
adjust_offsets(std::index_sequence_for<Ts...>{}, 1);
|
||||
++m_index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
component_array_iterator<C, Ts...> component_array_iterator<C, Ts...>::operator++(int) {
|
||||
component_array_iterator tmp = *this;
|
||||
++(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
component_array_iterator<C, Ts...>& component_array_iterator<C, Ts...>::operator--() {
|
||||
adjust_offsets(std::index_sequence_for<Ts...>{}, -1);
|
||||
--m_index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
component_array_iterator<C, Ts...> component_array_iterator<C, Ts...>::operator--(int) {
|
||||
auto tmp = *this;
|
||||
--(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
component_array_iterator<C, Ts...>& component_array_iterator<C, Ts...>::operator+=(const difference_type n)
|
||||
{
|
||||
adjust_offsets(std::index_sequence_for<Ts...>{}, n);
|
||||
m_index += n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
component_array_iterator<C, Ts...>& component_array_iterator<C, Ts...>::operator-=(const difference_type n)
|
||||
{
|
||||
return (*this) += -n;
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
component_array_iterator<C, Ts...> component_array_iterator<C, Ts...>::operator+(const difference_type n) const
|
||||
{
|
||||
auto tmp = *this;
|
||||
return tmp += n; // TODO clion says n is unused
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
component_array_iterator<C, Ts...> component_array_iterator<C, Ts...>::operator-(const difference_type n) const
|
||||
{
|
||||
auto tmp = *this;
|
||||
return tmp -= n; // TODO clion says n is unused
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
typename component_array_iterator<C, Ts...>::difference_type
|
||||
component_array_iterator<C, Ts...>::operator-(const component_array_iterator& other) const
|
||||
{
|
||||
return static_cast<difference_type>(m_index) - static_cast<difference_type>(other.m_index);
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
typename component_array_iterator<C, Ts...>::reference component_array_iterator<C, Ts...>::operator[](
|
||||
const difference_type n
|
||||
) const {
|
||||
return *((*this) + n);
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
bool component_array_iterator<C, Ts...>::operator==(const component_array_iterator& other) const
|
||||
{
|
||||
return m_ids == other.m_ids and m_index == other.m_index;
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
bool component_array_iterator<C, Ts...>::operator!=(const component_array_iterator& other) const
|
||||
{
|
||||
return not (*this == other);
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
bool component_array_iterator<C, Ts...>::operator<(const component_array_iterator& other) const
|
||||
{
|
||||
return m_index < other.m_index;
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
bool component_array_iterator<C, Ts...>::operator<=(const component_array_iterator& other) const
|
||||
{
|
||||
return m_index <= other.m_index;
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
bool component_array_iterator<C, Ts...>::operator>(const component_array_iterator& other) const
|
||||
{
|
||||
return m_index > other.m_index;
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
bool component_array_iterator<C, Ts...>::operator>=(const component_array_iterator& other) const
|
||||
{
|
||||
return m_index >= other.m_index;
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
template<std::size_t I>
|
||||
bool component_array_iterator<C, Ts...>::is_component_enabled(C flag)
|
||||
{
|
||||
return (flag & (C{1} << I)) != C{};
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
template<std::size_t... Is>
|
||||
void component_array_iterator<C, Ts...>::calc_offsets(std::index_sequence<Is...>, difference_type n)
|
||||
{
|
||||
|
||||
const auto negative = n < difference_type{ 0 };
|
||||
const auto positive = n > difference_type{ 0 };
|
||||
const auto step = difference_type{ positive } - difference_type{ negative };
|
||||
n = negative ? -n : n;
|
||||
|
||||
// TODO template optimize for single steps
|
||||
|
||||
while (n--)
|
||||
{
|
||||
const auto& [ flags, count ] = m_flag_counts[m_index];
|
||||
|
||||
([&] {
|
||||
if (is_component_enabled<Is>(flags))
|
||||
{
|
||||
std::get<Is>(m_offsets) += step * count;
|
||||
}
|
||||
}(), ...);
|
||||
|
||||
m_index += step;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
template<std::size_t... Is>
|
||||
typename component_array_iterator<C, Ts...>::reference
|
||||
component_array_iterator<C, Ts...>::dereference(std::index_sequence<Is...>) const
|
||||
{
|
||||
const auto& [ flags, component_count ] = m_flag_counts[m_index];
|
||||
|
||||
return std::make_pair(
|
||||
m_ids[m_index],
|
||||
std::make_tuple(
|
||||
flags,
|
||||
std::make_tuple(
|
||||
std::span(
|
||||
&std::get<Is>(m_components)[m_offsets[Is]],
|
||||
is_component_enabled<Is>(flags) ? component_count : 0
|
||||
)...
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
std::tuple<std::add_pointer_t<Ts>...> generic_dynamic_component_array_store<C, Ts...>::component_array_ptrs()
|
||||
{
|
||||
return [&]<auto... Is>(std::index_sequence<Is>)
|
||||
{
|
||||
return std::make_tuple(std::get<Is>(m_component_arrays).data()...);
|
||||
}
|
||||
(std::index_sequence_for<Ts...>{});
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
std::tuple<std::add_pointer_t<std::add_const_t<Ts>>...> generic_dynamic_component_array_store<C, Ts...>::component_array_ptrs() const
|
||||
{
|
||||
return [&]<auto... Is>(std::index_sequence<Is>)
|
||||
{
|
||||
return std::make_tuple(std::get<Is>(m_component_arrays).data()...);
|
||||
}
|
||||
(std::index_sequence_for<Ts...>{});
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
std::array<std::size_t, sizeof...(Ts)> generic_dynamic_component_array_store<C, Ts...>::array_counts() const
|
||||
{
|
||||
return [&]<auto... Is>(std::index_sequence<Is>)
|
||||
{
|
||||
return std::array{ std::get<Is>(m_component_arrays).size()... };
|
||||
}
|
||||
(std::index_sequence_for<Ts...>{});
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
typename generic_dynamic_component_array_store<C, Ts...>::id_type generic_dynamic_component_array_store<C, Ts...>::add(
|
||||
const std::tuple<std::vector<Ts>...>& component_arrays
|
||||
) {
|
||||
|
||||
auto component_flags = C{};
|
||||
auto min_component_count = count_type{};
|
||||
|
||||
[&]<auto... Is>(std::integer_sequence<Is...>)
|
||||
{
|
||||
const auto& component_array = std::get<Is>(component_arrays);
|
||||
if (not component_array.empty())
|
||||
{
|
||||
const auto component_count = static_cast<count_type>(component_array.size());
|
||||
if (min_component_count != 0 and component_count < min_component_count)
|
||||
{
|
||||
min_component_count = component_count;
|
||||
}
|
||||
component_flags |= C{ 1 } << Is;
|
||||
}
|
||||
}
|
||||
(std::index_sequence_for<Ts...>{});
|
||||
|
||||
[&]<auto... Is>(std::integer_sequence<Is...>)
|
||||
{
|
||||
const auto& src_array = std::get<Is>(component_arrays);
|
||||
auto& dst_array = std::get<Is>(m_component_arrays);
|
||||
|
||||
if (not src_array.empty())
|
||||
{
|
||||
dst_array.insert(dst_array.end(), src_array.begin(), src_array.begin() + count);
|
||||
}
|
||||
}
|
||||
(std::index_sequence_for<Ts...>{});
|
||||
|
||||
m_component_flag_counts.emplace_back(component_flags, min_component_count);
|
||||
|
||||
const auto id = id_type{ m_next_data_id.index++ };
|
||||
m_ids.push_back(id);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
std::pair<typename generic_dynamic_component_array_store<C, Ts...>::iterator_type, bool> generic_dynamic_component_array_store<C, Ts...>::find(id_type id)
|
||||
{
|
||||
const auto id_it = std::ranges::upper_bound(m_ids, id);
|
||||
|
||||
const auto match = (
|
||||
id_it != m_ids.begin() and
|
||||
*std::prev(id_it) == id
|
||||
);
|
||||
|
||||
const auto index = id_it - m_ids.begin() - match;
|
||||
|
||||
auto it = begin();
|
||||
it += index;
|
||||
|
||||
return { it, match };
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
std::pair<typename generic_dynamic_component_array_store<C, Ts...>::const_iterator, bool> generic_dynamic_component_array_store<C, Ts...>::find(id_type id) const
|
||||
{
|
||||
const auto id_it = std::ranges::upper_bound(m_ids, id);
|
||||
|
||||
const auto match = (
|
||||
id_it != m_ids.begin() and
|
||||
*std::prev(id_it) == id
|
||||
);
|
||||
|
||||
const auto index = id_it - m_ids.begin() - match;
|
||||
|
||||
auto it = begin();
|
||||
it += index;
|
||||
|
||||
return { it, match };
|
||||
}
|
||||
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
void generic_dynamic_component_array_store<C, Ts...>::remove(const iterator_type& it)
|
||||
{
|
||||
[&]<auto... Is>(std::index_sequence<Is>)
|
||||
{
|
||||
([&]{
|
||||
auto& component_vector = std::get<Is>(m_component_arrays);
|
||||
const auto begin = component_vector.begin() + it.m_offsets[Is];
|
||||
const auto end = begin + it.m_flag_counts[it.m_index];
|
||||
component_vector.erase(begin, end);
|
||||
}(), ...);
|
||||
} (std::index_sequence_for<Ts...>{});
|
||||
|
||||
m_component_flag_counts.erase(m_component_flag_counts.begin() + it.m_index);
|
||||
m_ids.erase(m_ids.begin() + it.m_index);
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
void generic_dynamic_component_array_store<C, Ts...>::clear()
|
||||
{
|
||||
[&]<auto... Is>(std::index_sequence<Is>)
|
||||
{
|
||||
std::get<Is>(m_component_arrays).clear();
|
||||
} (std::index_sequence_for<Ts...>{});
|
||||
m_component_flag_counts.clear();
|
||||
m_ids.clear();
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
typename generic_dynamic_component_array_store<C, Ts...>::iterator_type generic_dynamic_component_array_store<C, Ts...>::begin()
|
||||
{
|
||||
return iterator_type{
|
||||
m_ids.data(),
|
||||
component_array_ptrs(),
|
||||
m_component_flag_counts.data(),
|
||||
0,
|
||||
{}
|
||||
};
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
typename generic_dynamic_component_array_store<C, Ts...>::iterator_type generic_dynamic_component_array_store<C, Ts...>::end()
|
||||
{
|
||||
return iterator_type{
|
||||
m_ids.data(),
|
||||
component_array_ptrs(),
|
||||
m_component_flag_counts.data(),
|
||||
m_component_flag_counts.size(),
|
||||
array_counts()
|
||||
};
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
typename generic_dynamic_component_array_store<C, Ts...>::const_iterator generic_dynamic_component_array_store<C, Ts...>::begin() const
|
||||
{
|
||||
return iterator_type{
|
||||
m_ids.data(),
|
||||
component_array_ptrs(),
|
||||
m_component_flag_counts.data(),
|
||||
0,
|
||||
{}
|
||||
};
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
typename generic_dynamic_component_array_store<C, Ts...>::const_iterator generic_dynamic_component_array_store<C, Ts...>::end() const
|
||||
{
|
||||
return iterator_type{
|
||||
m_ids.data(),
|
||||
component_array_ptrs(),
|
||||
m_component_flag_counts.data(),
|
||||
m_component_flag_counts.size(),
|
||||
array_counts()
|
||||
};
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
typename generic_dynamic_component_array_store<C, Ts...>::const_iterator generic_dynamic_component_array_store<C, Ts...>::cbegin() const
|
||||
{
|
||||
return const_cast<const generic_dynamic_component_array_store*>(this)->begin();
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
typename generic_dynamic_component_array_store<C, Ts...>::const_iterator generic_dynamic_component_array_store<C, Ts...>::cend() const
|
||||
{
|
||||
return const_cast<const generic_dynamic_component_array_store*>(this)->end();
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
typename generic_dynamic_component_array_store<C, Ts...>::view_type generic_dynamic_component_array_store<C, Ts...>::view()
|
||||
{
|
||||
return { begin(), end() };
|
||||
}
|
||||
template<typename C, typename... Ts>
|
||||
typename generic_dynamic_component_array_store<C, Ts...>::const_view_type generic_dynamic_component_array_store<C, Ts...>::view() const
|
||||
{
|
||||
return { begin(), end() };
|
||||
}
|
||||
@@ -1,424 +0,0 @@
|
||||
#ifndef INCLUDE_GENERIC_DYNAMIC_INDEXED_COMPONENT_ARRAY_STORE_IMPLEMENTATION
|
||||
# error Never include this file directly include 'generic_dynamic_indexed_component_array_store.hpp'
|
||||
#endif
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <span>
|
||||
#include <tuple>
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <algorithm>
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
indexed_component_array_iterator<C, I, Ts...>::indexed_component_array_iterator(
|
||||
id_array_pointer_type ids,
|
||||
const index_array_pointer_type indices,
|
||||
const component_array_pointer_type& components,
|
||||
const flag_count_pointer_type flag_counts,
|
||||
std::size_t index,
|
||||
const offsets_type& offsets
|
||||
) :
|
||||
m_ids{ ids },
|
||||
m_indices{ indices },
|
||||
m_components{ components },
|
||||
m_flag_counts{ flag_counts },
|
||||
m_index{ index },
|
||||
m_offsets{ offsets } {}
|
||||
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
typename indexed_component_array_iterator<C, I, Ts...>::reference indexed_component_array_iterator<C, I, Ts...>::operator*() const {
|
||||
return dereference(std::index_sequence_for<Ts...>{});
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
indexed_component_array_iterator<C, I, Ts...>& indexed_component_array_iterator<C, I, Ts...>::operator++() {
|
||||
adjust_offsets(std::index_sequence_for<Ts...>{}, 1);
|
||||
++m_index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
indexed_component_array_iterator<C, I, Ts...> indexed_component_array_iterator<C, I, Ts...>::operator++(int) {
|
||||
indexed_component_array_iterator tmp = *this;
|
||||
++(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
indexed_component_array_iterator<C, I, Ts...>& indexed_component_array_iterator<C, I, Ts...>::operator--() {
|
||||
adjust_offsets(std::index_sequence_for<Ts...>{}, -1);
|
||||
--m_index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
indexed_component_array_iterator<C, I, Ts...> indexed_component_array_iterator<C, I, Ts...>::operator--(int) {
|
||||
auto tmp = *this;
|
||||
--(*this);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
indexed_component_array_iterator<C, I, Ts...>& indexed_component_array_iterator<C, I, Ts...>::operator+=(const difference_type n)
|
||||
{
|
||||
adjust_offsets(std::index_sequence_for<Ts...>{}, n);
|
||||
m_index += n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
indexed_component_array_iterator<C, I, Ts...>& indexed_component_array_iterator<C, I, Ts...>::operator-=(const difference_type n)
|
||||
{
|
||||
return (*this) += -n;
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
indexed_component_array_iterator<C, I, Ts...> indexed_component_array_iterator<C, I, Ts...>::operator+(const difference_type n) const
|
||||
{
|
||||
auto tmp = *this;
|
||||
return tmp += n; // TODO clion says n is unused
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
indexed_component_array_iterator<C, I, Ts...> indexed_component_array_iterator<C, I, Ts...>::operator-(const difference_type n) const
|
||||
{
|
||||
auto tmp = *this;
|
||||
return tmp -= n; // TODO clion says n is unused
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
typename indexed_component_array_iterator<C, I, Ts...>::difference_type
|
||||
indexed_component_array_iterator<C, I, Ts...>::operator-(const indexed_component_array_iterator& other) const
|
||||
{
|
||||
return static_cast<difference_type>(m_index) - static_cast<difference_type>(other.m_index);
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
typename indexed_component_array_iterator<C, I, Ts...>::reference indexed_component_array_iterator<C, I, Ts...>::operator[](
|
||||
const difference_type n
|
||||
) const {
|
||||
return *(*this + n);
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
bool indexed_component_array_iterator<C, I, Ts...>::operator==(const indexed_component_array_iterator& other) const
|
||||
{
|
||||
return m_ids == other.m_ids and m_index == other.m_index;
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
bool indexed_component_array_iterator<C, I, Ts...>::operator!=(const indexed_component_array_iterator& other) const
|
||||
{
|
||||
return not (*this == other);
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
bool indexed_component_array_iterator<C, I, Ts...>::operator<(const indexed_component_array_iterator& other) const
|
||||
{
|
||||
return m_index < other.m_index;
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
bool indexed_component_array_iterator<C, I, Ts...>::operator<=(const indexed_component_array_iterator& other) const
|
||||
{
|
||||
return m_index <= other.m_index;
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
bool indexed_component_array_iterator<C, I, Ts...>::operator>(const indexed_component_array_iterator& other) const
|
||||
{
|
||||
return m_index > other.m_index;
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
bool indexed_component_array_iterator<C, I, Ts...>::operator>=(const indexed_component_array_iterator& other) const
|
||||
{
|
||||
return m_index >= other.m_index;
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
template<std::size_t N>
|
||||
bool indexed_component_array_iterator<C, I, Ts...>::is_component_enabled(C flag)
|
||||
{
|
||||
return (flag & (C{1} << N)) != C{};
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
template<std::size_t... Is>
|
||||
void indexed_component_array_iterator<C, I, Ts...>::calc_offsets(
|
||||
std::index_sequence<Is...>,
|
||||
difference_type n
|
||||
) {
|
||||
|
||||
const auto negative = n < difference_type{ 0 };
|
||||
const auto positive = n > difference_type{ 0 };
|
||||
const auto step = difference_type{ positive } - difference_type{ negative };
|
||||
n = negative ? -n : n;
|
||||
|
||||
// TODO template optimize for single steps
|
||||
|
||||
while (n--)
|
||||
{
|
||||
const auto& [ flags, index_count, component_count ] = m_flag_counts[m_index];
|
||||
|
||||
std::get<0>(m_offsets) += step * index_count;
|
||||
|
||||
([&] {
|
||||
if (is_component_enabled<Is>(flags))
|
||||
{
|
||||
std::get<1 + Is>(m_offsets) += step * component_count;
|
||||
}
|
||||
}(), ...);
|
||||
|
||||
m_index += step;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
template<std::size_t... Is>
|
||||
typename indexed_component_array_iterator<C, I, Ts...>::reference
|
||||
indexed_component_array_iterator<C, I, Ts...>::dereference(std::index_sequence<Is...>) const
|
||||
{
|
||||
const auto& [ flags, index_count, component_count ] = m_flag_counts[m_index];
|
||||
|
||||
return std::make_pair(
|
||||
m_ids[m_index],
|
||||
std::make_tuple(
|
||||
flags,
|
||||
std::span(
|
||||
m_indices[m_offsets[0]],
|
||||
index_count
|
||||
),
|
||||
std::make_tuple(
|
||||
std::span(
|
||||
&std::get<Is>(m_components)[m_offsets[1 + Is]],
|
||||
is_component_enabled<Is>(flags) ? component_count : 0
|
||||
)...
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
std::tuple<std::add_pointer_t<Ts>...> generic_dynamic_indexed_component_array_store<C, I, Ts...>::component_array_ptrs()
|
||||
{
|
||||
return [&]<auto... Is>(std::index_sequence<Is>)
|
||||
{
|
||||
return std::make_tuple(std::get<Is>(m_component_arrays).data()...);
|
||||
}
|
||||
(std::index_sequence_for<Ts...>{});
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
std::tuple<std::add_pointer_t<std::add_const_t<Ts>>...> generic_dynamic_indexed_component_array_store<C, I, Ts...>::component_array_ptrs() const
|
||||
{
|
||||
return [&]<auto... Is>(std::index_sequence<Is>)
|
||||
{
|
||||
return std::make_tuple(std::get<Is>(m_component_arrays).data()...);
|
||||
}
|
||||
(std::index_sequence_for<Ts...>{});
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
std::array<std::size_t, 1 + sizeof...(Ts)> generic_dynamic_indexed_component_array_store<C, I, Ts...>::array_counts() const
|
||||
{
|
||||
return [&]<auto... Is>(std::index_sequence<Is>)
|
||||
{
|
||||
return std::array{
|
||||
m_indices.size(),
|
||||
std::get<Is>(m_component_arrays).size()...
|
||||
};
|
||||
}
|
||||
(std::index_sequence_for<Ts...>{});
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
typename generic_dynamic_indexed_component_array_store<C, I,Ts...>::id_type generic_dynamic_indexed_component_array_store<C, I,Ts...>::add(
|
||||
std::span<const I> indices,
|
||||
const std::tuple<std::vector<Ts>...>& component_arrays
|
||||
) {
|
||||
|
||||
auto component_flags = C{};
|
||||
auto min_component_count = count_type{};
|
||||
|
||||
[&]<auto... Is>(std::integer_sequence<Is...>)
|
||||
{
|
||||
const auto& component_array = std::get<Is>(component_arrays);
|
||||
if (not component_array.empty())
|
||||
{
|
||||
const auto component_count = static_cast<count_type>(component_array.size());
|
||||
if (min_component_count != 0 and component_count < min_component_count)
|
||||
{
|
||||
min_component_count = component_count;
|
||||
}
|
||||
component_flags |= C{ 1 } << Is;
|
||||
}
|
||||
}
|
||||
(std::index_sequence_for<Ts...>{});
|
||||
|
||||
m_indices.insert(m_indices.end(), indices.begin(), indices.end());
|
||||
|
||||
[&]<auto... Is>(std::integer_sequence<Is...>)
|
||||
{
|
||||
const auto& src_array = std::get<Is>(component_arrays);
|
||||
auto& dst_array = std::get<Is>(m_component_arrays);
|
||||
|
||||
if (not src_array.empty())
|
||||
{
|
||||
dst_array.insert(dst_array.end(), src_array.begin(), src_array.begin() + min_component_count);
|
||||
}
|
||||
}
|
||||
(std::index_sequence_for<Ts...>{});
|
||||
|
||||
m_component_flag_counts.emplace_back(component_flags, indices.size(), min_component_count);
|
||||
|
||||
const auto id = id_type{ m_next_data_id.index++ };
|
||||
m_ids.push_back(id);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
std::pair<typename generic_dynamic_indexed_component_array_store<C, I,Ts...>::iterator_type, bool> generic_dynamic_indexed_component_array_store<C, I,Ts...>::find(id_type id)
|
||||
{
|
||||
const auto id_it = std::ranges::upper_bound(m_ids, id);
|
||||
|
||||
const auto match = (
|
||||
id_it != m_ids.begin() and
|
||||
*std::prev(id_it) == id
|
||||
);
|
||||
|
||||
const auto index = id_it - m_ids.begin() - match;
|
||||
|
||||
auto it = begin();
|
||||
it += index;
|
||||
|
||||
return { it, match };
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
std::pair<typename generic_dynamic_indexed_component_array_store<C, I,Ts...>::const_iterator, bool> generic_dynamic_indexed_component_array_store<C, I,Ts...>::find(id_type id) const
|
||||
{
|
||||
const auto id_it = std::ranges::upper_bound(m_ids, id);
|
||||
|
||||
const auto match = (
|
||||
id_it != m_ids.begin() and
|
||||
*std::prev(id_it) == id
|
||||
);
|
||||
|
||||
const auto index = id_it - m_ids.begin() - match;
|
||||
|
||||
auto it = begin();
|
||||
it += index;
|
||||
|
||||
return { it, match };
|
||||
}
|
||||
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
void generic_dynamic_indexed_component_array_store<C, I,Ts...>::remove(const iterator_type& it)
|
||||
{
|
||||
m_indices.erase(m_indices.begin() + it.m_offsets[0]);
|
||||
|
||||
[&]<auto... Is>(std::index_sequence<Is>)
|
||||
{
|
||||
([&]{
|
||||
auto& component_vector = std::get<Is>(m_component_arrays);
|
||||
const auto begin = component_vector.begin() + it.m_offsets[1 + Is];
|
||||
const auto end = begin + it.m_flag_counts[it.m_index];
|
||||
component_vector.erase(begin, end);
|
||||
}(), ...);
|
||||
} (std::index_sequence_for<Ts...>{});
|
||||
|
||||
m_component_flag_counts.erase(m_component_flag_counts.begin() + it.m_index);
|
||||
m_ids.erase(m_ids.begin() + it.m_index);
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
void generic_dynamic_indexed_component_array_store<C, I,Ts...>::clear()
|
||||
{
|
||||
m_indices.clear();
|
||||
[&]<auto... Is>(std::index_sequence<Is>)
|
||||
{
|
||||
std::get<Is>(m_component_arrays).clear();
|
||||
} (std::index_sequence_for<Ts...>{});
|
||||
m_component_flag_counts.clear();
|
||||
m_ids.clear();
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
typename generic_dynamic_indexed_component_array_store<C, I,Ts...>::iterator_type generic_dynamic_indexed_component_array_store<C, I,Ts...>::begin()
|
||||
{
|
||||
return iterator_type{
|
||||
m_ids.data(),
|
||||
m_indices.data(),
|
||||
component_array_ptrs(),
|
||||
m_component_flag_counts.data(),
|
||||
0,
|
||||
{}
|
||||
};
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
typename generic_dynamic_indexed_component_array_store<C, I,Ts...>::iterator_type generic_dynamic_indexed_component_array_store<C, I,Ts...>::end()
|
||||
{
|
||||
return iterator_type{
|
||||
m_ids.data(),
|
||||
m_indices.data(),
|
||||
component_array_ptrs(),
|
||||
m_component_flag_counts.data(),
|
||||
m_component_flag_counts.size(),
|
||||
array_counts()
|
||||
};
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
typename generic_dynamic_indexed_component_array_store<C, I,Ts...>::const_iterator generic_dynamic_indexed_component_array_store<C, I,Ts...>::begin() const
|
||||
{
|
||||
return iterator_type{
|
||||
m_ids.data(),
|
||||
m_indices.data(),
|
||||
component_array_ptrs(),
|
||||
m_component_flag_counts.data(),
|
||||
0,
|
||||
{}
|
||||
};
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
typename generic_dynamic_indexed_component_array_store<C, I,Ts...>::const_iterator generic_dynamic_indexed_component_array_store<C, I,Ts...>::end() const
|
||||
{
|
||||
return iterator_type{
|
||||
m_ids.data(),
|
||||
m_indices.data(),
|
||||
component_array_ptrs(),
|
||||
m_component_flag_counts.data(),
|
||||
m_component_flag_counts.size(),
|
||||
array_counts()
|
||||
};
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
typename generic_dynamic_indexed_component_array_store<C, I,Ts...>::const_iterator generic_dynamic_indexed_component_array_store<C, I,Ts...>::cbegin() const
|
||||
{
|
||||
return const_cast<const generic_dynamic_indexed_component_array_store*>(this)->begin();
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
typename generic_dynamic_indexed_component_array_store<C, I,Ts...>::const_iterator generic_dynamic_indexed_component_array_store<C, I,Ts...>::cend() const
|
||||
{
|
||||
return const_cast<const generic_dynamic_indexed_component_array_store*>(this)->end();
|
||||
}
|
||||
|
||||
template<typename C, typename I, typename... Ts>
|
||||
typename generic_dynamic_indexed_component_array_store<C, I,Ts...>::view_type generic_dynamic_indexed_component_array_store<C, I,Ts...>::view()
|
||||
{
|
||||
return { begin(), end() };
|
||||
}
|
||||
template<typename C, typename I, typename... Ts>
|
||||
typename generic_dynamic_indexed_component_array_store<C, I,Ts...>::const_view_type generic_dynamic_indexed_component_array_store<C, I,Ts...>::view() const
|
||||
{
|
||||
return { begin(), end() };
|
||||
}
|
||||
@@ -197,7 +197,8 @@ assets::detail::generic_mesh_store_iterator<Ts...>::dereference(std::index_seque
|
||||
&std::get<Is>(m_components)[m_offsets[1 + Is]],
|
||||
is_component_enabled<Is>(flags) ? component_count : 0
|
||||
)...
|
||||
)
|
||||
),
|
||||
.vertex_count = component_count,
|
||||
.material_id = m_material_ids[m_index]
|
||||
}
|
||||
);
|
||||
|
||||
@@ -183,13 +183,14 @@ assets::detail::generic_point_cloud_store_iterator<Ts...>::dereference(std::inde
|
||||
return std::make_pair(
|
||||
m_ids[m_index],
|
||||
point_cloud_view{
|
||||
.vertex_components = flags,
|
||||
.vertex_component_flags = flags,
|
||||
.vertex_component_arrays = std::make_tuple(
|
||||
std::span(
|
||||
&std::get<Is>(m_components)[m_offsets[1 + Is]],
|
||||
is_component_enabled<Is>(flags) ? component_count : 0
|
||||
)...
|
||||
)
|
||||
.point_count = component_count
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -28,17 +28,14 @@ void zgl::point_cloud_vertex_buffer_manager::process(store_type& store)
|
||||
{
|
||||
auto [ store_id, point_cloud ] = entry;
|
||||
|
||||
const auto& [ components, buffers ] = point_cloud;
|
||||
|
||||
m_byte_buffer.clear();
|
||||
|
||||
const auto meta = std::apply(
|
||||
std::apply(
|
||||
[&](const auto&... component_buffers)
|
||||
{
|
||||
vertex_buffer_utils::interlace(m_byte_buffer, components, component_buffers...);
|
||||
return vertex_buffer_utils::generate_metadata(components, component_buffers...);
|
||||
vertex_buffer_utils::interlace(m_byte_buffer, point_cloud.vertex_component_flags, component_buffers...);
|
||||
},
|
||||
buffers
|
||||
point_cloud.vertex_component_arrays
|
||||
);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer_id);
|
||||
@@ -60,6 +57,11 @@ void zgl::point_cloud_vertex_buffer_manager::process(store_type& store)
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto meta = point_cloud_vertex_buffer_metadata{
|
||||
.component_flags = point_cloud.vertex_component_flags,
|
||||
.point_count = point_cloud.point_count
|
||||
};
|
||||
|
||||
m_resource_manager.add_resource(store_id, buffer_id, meta);
|
||||
|
||||
buffer_id = {};
|
||||
|
||||
Reference in New Issue
Block a user