fixes
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
#ifndef INCLUDE_DYNAMIC_MATERIAL_DATA_IMPLEMENTATION
|
||||
# error Never include this file directly include 'dynamic_material_buffer.hpp'
|
||||
#endif
|
||||
|
||||
|
||||
inline std::optional<components::material::surface_properties>& dynamic_material_buffer::surface_properties()
|
||||
{
|
||||
return std::get<components::material::indices::surface_properties>(data);
|
||||
}
|
||||
inline std::optional<components::material::transparency>& dynamic_material_buffer::transparency()
|
||||
{
|
||||
return std::get<components::material::indices::transparency>(data);
|
||||
}
|
||||
inline std::optional<dynamic_texture_store::id_type>& dynamic_material_buffer::ambient_color_texture_id()
|
||||
{
|
||||
return std::get<components::material::indices::ambient_color_texture>(data);
|
||||
}
|
||||
inline std::optional<dynamic_texture_store::id_type>& dynamic_material_buffer::diffuse_color_texture_id()
|
||||
{
|
||||
return std::get<components::material::indices::diffuse_color_texture>(data);
|
||||
}
|
||||
inline std::optional<dynamic_texture_store::id_type>& dynamic_material_buffer::specular_color_texture_id()
|
||||
{
|
||||
return std::get<components::material::indices::specular_color_texture>(data);
|
||||
}
|
||||
inline std::optional<dynamic_texture_store::id_type>& dynamic_material_buffer::shininess_texture_id()
|
||||
{
|
||||
return std::get<components::material::indices::shininess_texture>(data);
|
||||
}
|
||||
inline std::optional<dynamic_texture_store::id_type>& dynamic_material_buffer::alpha_texture_id()
|
||||
{
|
||||
return std::get<components::material::indices::alpha_texture>(data);
|
||||
}
|
||||
inline std::optional<dynamic_texture_store::id_type>& dynamic_material_buffer::bump_texture_id()
|
||||
{
|
||||
return std::get<components::material::indices::bump_texture(data);
|
||||
}
|
||||
|
||||
inline const std::optional<components::material::surface_properties>& dynamic_material_buffer::surface_properties() const
|
||||
{
|
||||
return std::get<components::material::indices::surface_properties>(data);
|
||||
}
|
||||
|
||||
inline const std::optional<components::material::transparency>& dynamic_material_buffer::transparency() const
|
||||
{
|
||||
return std::get<components::material::indices::transparency>(data);
|
||||
}
|
||||
|
||||
inline const std::optional<dynamic_texture_store::id_type>& dynamic_material_buffer::ambient_color_texture_id() const
|
||||
{
|
||||
return std::get<components::material::indices::ambient_color_texture>(data);
|
||||
}
|
||||
|
||||
inline const std::optional<dynamic_texture_store::id_type>& dynamic_material_buffer::diffuse_color_texture_id() const
|
||||
{
|
||||
return std::get<components::material::indices::diffuse_color_texture>(data);
|
||||
}
|
||||
|
||||
inline const std::optional<dynamic_texture_store::id_type>& dynamic_material_buffer::specular_color_texture_id() const
|
||||
{
|
||||
return std::get<components::material::indices::specular_color_texture>(data);
|
||||
}
|
||||
|
||||
inline const std::optional<dynamic_texture_store::id_type>& dynamic_material_buffer::shininess_texture_id() const
|
||||
{
|
||||
return std::get<components::material::indices::shininess_texture>(data);
|
||||
}
|
||||
|
||||
inline const std::optional<dynamic_texture_store::id_type>& dynamic_material_buffer::alpha_texture_id() const
|
||||
{
|
||||
return std::get<components::material::indices::alpha_texture>(data);
|
||||
}
|
||||
|
||||
inline const std::optional<dynamic_texture_store::id_type>& dynamic_material_buffer::bump_texture_id() const
|
||||
{
|
||||
return std::get<components::material::indices::bump_texture>(data);
|
||||
}
|
||||
|
||||
|
||||
inline components::material::surface_properties& dynamic_material_buffer::initialized_surface_properties()
|
||||
{
|
||||
auto& surface_properties_opt = surface_properties();
|
||||
if (not surface_properties_opt)
|
||||
{
|
||||
surface_properties_opt = components::material::surface_properties{};
|
||||
}
|
||||
return *surface_properties_opt;
|
||||
}
|
||||
73
source/assets/dynamic_read_buffers/dynamic_mesh_buffer.ipp
Normal file
73
source/assets/dynamic_read_buffers/dynamic_mesh_buffer.ipp
Normal file
@@ -0,0 +1,73 @@
|
||||
#ifndef INCLUDE_DYNAMIC_MESH_DATA_IMPLEMENTATION
|
||||
# error Never include this file directly include 'dynamic_mesh_buffer.hpp'
|
||||
#endif
|
||||
|
||||
inline std::vector<components::mesh_vertex::position>& dynamic_mesh_buffer::positions()
|
||||
{
|
||||
return std::get<components::mesh_vertex::indices::position>(vertices);
|
||||
}
|
||||
|
||||
inline std::vector<components::mesh_vertex::normal>& dynamic_mesh_buffer::normals()
|
||||
{
|
||||
return std::get<components::mesh_vertex::indices::normal>(vertices);
|
||||
}
|
||||
|
||||
inline std::vector<components::mesh_vertex::tex_coord>& dynamic_mesh_buffer::tex_coords()
|
||||
{
|
||||
return std::get<components::mesh_vertex::indices::tex_coord>(vertices);
|
||||
}
|
||||
|
||||
inline std::vector<components::mesh_vertex::color>& dynamic_mesh_buffer::colors()
|
||||
{
|
||||
return std::get<components::mesh_vertex::indices::color>(vertices);
|
||||
}
|
||||
|
||||
inline std::vector<components::mesh_vertex::reflectance>& dynamic_mesh_buffer::reflectances()
|
||||
{
|
||||
return std::get<components::mesh_vertex::indices::reflectance>(vertices);
|
||||
}
|
||||
|
||||
inline std::vector<dynamic_mesh_buffer::triangle_type>& dynamic_mesh_buffer::triangles()
|
||||
{
|
||||
return m_triangles;
|
||||
}
|
||||
|
||||
inline auto& dynamic_mesh_buffer::material_id()
|
||||
{
|
||||
return m_material_id;
|
||||
}
|
||||
|
||||
inline const std::vector<components::mesh_vertex::position>& dynamic_mesh_buffer::positions() const
|
||||
{
|
||||
return std::get<components::mesh_vertex::indices::position>(vertices);
|
||||
}
|
||||
|
||||
inline const std::vector<components::mesh_vertex::normal>& dynamic_mesh_buffer::normals() const
|
||||
{
|
||||
return std::get<components::mesh_vertex::indices::normal>(vertices);
|
||||
}
|
||||
|
||||
inline const std::vector<components::mesh_vertex::tex_coord>& dynamic_mesh_buffer::tex_coords() const
|
||||
{
|
||||
return std::get<components::mesh_vertex::indices::tex_coord>(vertices);
|
||||
}
|
||||
|
||||
inline const std::vector<components::mesh_vertex::color>& dynamic_mesh_buffer::colors() const
|
||||
{
|
||||
return std::get<components::mesh_vertex::indices::color>(vertices);
|
||||
}
|
||||
|
||||
inline const std::vector<components::mesh_vertex::reflectance>& dynamic_mesh_buffer::reflectances() const
|
||||
{
|
||||
return std::get<components::mesh_vertex::indices::reflectance>(vertices);
|
||||
}
|
||||
|
||||
inline const std::vector<dynamic_mesh_buffer::triangle_type>& dynamic_mesh_buffer::triangles() const
|
||||
{
|
||||
return m_triangles;
|
||||
}
|
||||
|
||||
inline const auto& dynamic_mesh_buffer::material_id() const
|
||||
{
|
||||
return m_material_id;
|
||||
}
|
||||
148
source/assets/dynamic_read_buffers/dynamic_model_buffer.ipp
Normal file
148
source/assets/dynamic_read_buffers/dynamic_model_buffer.ipp
Normal file
@@ -0,0 +1,148 @@
|
||||
#ifndef INCLUDE_DYNAMIC_MODEL_DATA_IMPLEMENTATION
|
||||
# error Never include this file directly include 'dynamic_vertex_buffer.hpp'
|
||||
#endif
|
||||
|
||||
#include "util/specialised_lambda.hpp"
|
||||
#include "opengl/type_utils.hpp"
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
C& dynamic_vertex_buffer<C, Ts...>::components()
|
||||
{
|
||||
return m_components;
|
||||
}
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
const C& dynamic_vertex_buffer<C, Ts...>::components() const
|
||||
{
|
||||
return m_components;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
concept numeric_type = std::integral<T> or std::floating_point<T>;
|
||||
|
||||
template<typename C, typename... Ts>
|
||||
void dynamic_vertex_buffer<C, Ts...>::build_vertex_buffer(
|
||||
std::vector<ztu::u8>& vertex_buffer,
|
||||
std::size_t& component_count,
|
||||
std::array<GLenum, sizeof...(Ts)>& component_types,
|
||||
std::array<GLint, sizeof...(Ts)>& component_lengths,
|
||||
GLsizei& stride
|
||||
) const {
|
||||
const auto for_all_components = [&]<typename T>(auto&& f, const T default_value)
|
||||
{
|
||||
return std::apply(
|
||||
[&](const auto&... component_buffer)
|
||||
{
|
||||
std::array<T, sizeof...(component_buffer)> results{};
|
||||
auto i = std::size_t{};
|
||||
(
|
||||
(
|
||||
results[i] = [&](const auto& buffer, const auto index) -> T
|
||||
{
|
||||
if ((m_components & C{ 1 << index }) != C{})
|
||||
{
|
||||
return f(buffer, index);
|
||||
}
|
||||
return default_value;
|
||||
}(component_buffer, i),
|
||||
++i
|
||||
),
|
||||
...
|
||||
);
|
||||
return results;
|
||||
},
|
||||
m_component_buffers
|
||||
);
|
||||
};
|
||||
|
||||
component_count = 0;
|
||||
component_types = for_all_components(
|
||||
ztu::specialised_lambda
|
||||
{
|
||||
[&component_count]<numeric_type Component, std::size_t Count>(const std::vector<std::array<Component, Count>>&, std::size_t)
|
||||
{
|
||||
++component_count;
|
||||
return zgl::type_utils::to_gl_type<Component>();
|
||||
},
|
||||
[&component_count]<numeric_type Component>(const std::vector<Component>&, std::size_t)
|
||||
{
|
||||
++component_count;
|
||||
return zgl::type_utils::to_gl_type<Component>();
|
||||
}
|
||||
},
|
||||
GLenum{ GL_INVALID_VALUE }
|
||||
);
|
||||
|
||||
const auto element_counts = for_all_components(
|
||||
[]<class Component>(const std::vector<Component>& buffer, std::size_t)
|
||||
{
|
||||
return buffer.size();
|
||||
},
|
||||
std::numeric_limits<std::size_t>::max()
|
||||
);
|
||||
|
||||
const auto minimum_element_count = std::ranges::min(element_counts);
|
||||
|
||||
component_lengths = for_all_components(
|
||||
ztu::specialised_lambda
|
||||
{
|
||||
[]<class Component>(const std::vector<Component>&, std::size_t)
|
||||
{
|
||||
return 1;
|
||||
},
|
||||
[]<class Component, std::size_t Count>(const std::vector<std::array<Component, Count>>&, std::size_t)
|
||||
{
|
||||
return Count;
|
||||
}
|
||||
},
|
||||
GLsizei{ 0 }
|
||||
);
|
||||
|
||||
auto component_sizes = std::array<GLsizei, sizeof...(Ts)>{};
|
||||
for (std::size_t i{}; i != component_sizes.size(); ++i)
|
||||
{
|
||||
component_sizes[i] = component_lengths[i] * zgl::type_utils::size_of(component_types[i]);
|
||||
}
|
||||
|
||||
const auto total_size = minimum_element_count * std::accumulate(
|
||||
component_sizes.begin(),
|
||||
component_sizes.end(),
|
||||
GLsizei{ 0 }
|
||||
);
|
||||
|
||||
vertex_buffer.resize(total_size);
|
||||
|
||||
// Calculate offsets and stride
|
||||
auto component_offsets = component_sizes;
|
||||
stride = 0;
|
||||
for (std::size_t i{}; i != component_offsets.size(); ++i) {
|
||||
component_offsets[i] = stride;
|
||||
stride += component_sizes[i];
|
||||
}
|
||||
|
||||
// Copy all the components over one by one
|
||||
for_all_components(
|
||||
[&]<class Component>(const std::vector<Component>& buffer, std::size_t index)
|
||||
{
|
||||
std::size_t pos = component_offsets[index];
|
||||
for (std::size_t i{}; i != minimum_element_count; ++i)
|
||||
{
|
||||
std::memcpy(
|
||||
&vertex_buffer[pos],
|
||||
buffer[i].data(),
|
||||
component_sizes[index]
|
||||
);
|
||||
pos += stride;
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
0
|
||||
);
|
||||
|
||||
// remove values of unused components
|
||||
std::ignore = std::ranges::remove(component_lengths, 0);
|
||||
std::ignore = std::ranges::remove(component_types, GL_INVALID_VALUE);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef INCLUDE_DYNAMIC_TEXTURE_DATA_IMPLEMENTATION
|
||||
# error Never include this file directly include 'dynamic_point_cloud_buffer.hpp'
|
||||
#endif
|
||||
#include "assets/components/point_cloud_vertex_components.hpp"
|
||||
|
||||
inline std::vector<components::point_cloud_vertex::position>& dynamic_point_cloud_buffer::positions()
|
||||
{
|
||||
return std::get<components::point_cloud_vertex::indices::position>(vertices);
|
||||
}
|
||||
|
||||
inline std::vector<components::point_cloud_vertex::normal>& dynamic_point_cloud_buffer::normals()
|
||||
{
|
||||
return std::get<components::point_cloud_vertex::indices::normal>(vertices);
|
||||
}
|
||||
|
||||
inline std::vector<components::point_cloud_vertex::color>& dynamic_point_cloud_buffer::colors()
|
||||
{
|
||||
return std::get<components::point_cloud_vertex::indices::color>(vertices);
|
||||
}
|
||||
|
||||
inline std::vector<components::point_cloud_vertex::reflectance>& dynamic_point_cloud_buffer::reflectances()
|
||||
{
|
||||
return std::get<components::point_cloud_vertex::indices::reflectance>(vertices);
|
||||
}
|
||||
|
||||
inline const std::vector<components::point_cloud_vertex::position>& dynamic_point_cloud_buffer::positions() const
|
||||
{
|
||||
return std::get<components::point_cloud_vertex::indices::position>(vertices);
|
||||
}
|
||||
|
||||
inline const std::vector<components::point_cloud_vertex::normal>& dynamic_point_cloud_buffer::normals() const
|
||||
{
|
||||
return std::get<components::point_cloud_vertex::indices::normal>(vertices);
|
||||
}
|
||||
|
||||
inline const std::vector<components::point_cloud_vertex::color>& dynamic_point_cloud_buffer::colors() const
|
||||
{
|
||||
return std::get<components::point_cloud_vertex::indices::color>(vertices);
|
||||
}
|
||||
|
||||
inline const std::vector<components::point_cloud_vertex::reflectance>& dynamic_point_cloud_buffer::reflectances() const
|
||||
{
|
||||
return std::get<components::point_cloud_vertex::indices::reflectance>(vertices);
|
||||
}
|
||||
151
source/assets/dynamic_read_buffers/dynamic_texture_buffer.ipp
Normal file
151
source/assets/dynamic_read_buffers/dynamic_texture_buffer.ipp
Normal file
@@ -0,0 +1,151 @@
|
||||
#ifndef INCLUDE_DYNAMIC_TEXTURE_DATA_IMPLEMENTATION
|
||||
# error Never include this file directly include 'dynamic_texture_buffer.hpp'
|
||||
#endif
|
||||
|
||||
|
||||
inline dynamic_texture_buffer::dynamic_texture_buffer(
|
||||
std::unique_ptr<value_type>&& data,
|
||||
const dim_type width,
|
||||
const dim_type height,
|
||||
const components::texture::flags components
|
||||
) :
|
||||
m_data{ std::move(data) },
|
||||
m_width{ width },
|
||||
m_height{ height },
|
||||
m_components{ components }
|
||||
{};
|
||||
|
||||
inline dynamic_texture_buffer::dynamic_texture_buffer(const dynamic_texture_buffer& other) :
|
||||
m_data{ new value_type[other.component_count()] },
|
||||
m_width{ other.m_width },
|
||||
m_height{ other.m_height },
|
||||
m_components{ other.m_components }
|
||||
{
|
||||
std::copy_n(other.m_data.get(), other.m_width * other.m_height, this->m_data.get());
|
||||
}
|
||||
|
||||
inline dynamic_texture_buffer::dynamic_texture_buffer(dynamic_texture_buffer&& other) noexcept :
|
||||
m_data{ std::move(other.m_data) },
|
||||
m_width{ other.m_width },
|
||||
m_height{ other.m_height },
|
||||
m_components{ other.m_components }
|
||||
{
|
||||
other.m_width = 0;
|
||||
other.m_height = 0;
|
||||
other.m_components = components::texture::flags::none;
|
||||
}
|
||||
|
||||
inline dynamic_texture_buffer& dynamic_texture_buffer::operator=(const dynamic_texture_buffer& other)
|
||||
{
|
||||
if (this != &other) [[likely]]
|
||||
{
|
||||
|
||||
const auto m_size = this->component_count();
|
||||
const auto o_size = other.component_count();
|
||||
|
||||
if (o_size > m_size) {
|
||||
this->~dynamic_texture_buffer();
|
||||
this->m_data.reset(new value_type[o_size]);
|
||||
}
|
||||
|
||||
std::copy_n(other.m_data.get(), o_size, this->m_data.get());
|
||||
|
||||
this->m_width = other.m_width;
|
||||
this->m_height = other.m_height;
|
||||
this->m_components = other.m_components;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline dynamic_texture_buffer& dynamic_texture_buffer::operator=(dynamic_texture_buffer&& other) noexcept
|
||||
{
|
||||
if (this != &other) [[likely]]
|
||||
{
|
||||
this->~dynamic_texture_buffer();
|
||||
|
||||
this->m_data = std::move(other.m_data);
|
||||
this->m_width = other.m_width;
|
||||
this->m_height = other.m_height;
|
||||
|
||||
other.m_width = 0;
|
||||
other.m_height = 0;
|
||||
other.m_components = components::texture::flags::none;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline components::texture::flags dynamic_texture_buffer::components() const
|
||||
{
|
||||
return m_components;
|
||||
}
|
||||
|
||||
inline dynamic_texture_buffer::dim_type dynamic_texture_buffer::width() const
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
inline dynamic_texture_buffer::dim_type dynamic_texture_buffer::height() const
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
inline std::pair<dynamic_texture_buffer::dim_type, dynamic_texture_buffer::dim_type> dynamic_texture_buffer::dimensions() const
|
||||
{
|
||||
return { m_width, m_height };
|
||||
}
|
||||
|
||||
inline dynamic_texture_buffer::size_type dynamic_texture_buffer::pixel_count() const
|
||||
{
|
||||
return static_cast<size_type>(m_width) * static_cast<size_type>(m_height);
|
||||
}
|
||||
|
||||
inline dynamic_texture_buffer::size_type dynamic_texture_buffer::component_count() const
|
||||
{
|
||||
return std::popcount(static_cast<std::underlying_type_t<components::texture::flags>>(m_components));
|
||||
}
|
||||
|
||||
inline dynamic_texture_buffer::size_type dynamic_texture_buffer::size() const
|
||||
{
|
||||
return pixel_count() * component_count();
|
||||
}
|
||||
|
||||
inline dynamic_texture_buffer::const_pointer dynamic_texture_buffer::data() const
|
||||
{
|
||||
return m_data.get();
|
||||
}
|
||||
|
||||
inline dynamic_texture_buffer::pointer dynamic_texture_buffer::data()
|
||||
{
|
||||
return m_data.get();
|
||||
}
|
||||
|
||||
inline dynamic_texture_buffer::const_iterator dynamic_texture_buffer::begin() const
|
||||
{
|
||||
return data();
|
||||
}
|
||||
|
||||
inline dynamic_texture_buffer::iterator dynamic_texture_buffer::begin()
|
||||
{
|
||||
return data();
|
||||
}
|
||||
|
||||
inline dynamic_texture_buffer::const_iterator dynamic_texture_buffer::end() const
|
||||
{
|
||||
return begin() + component_count();
|
||||
}
|
||||
|
||||
inline dynamic_texture_buffer::iterator dynamic_texture_buffer::end()
|
||||
{
|
||||
return begin() + component_count();
|
||||
}
|
||||
|
||||
inline dynamic_texture_buffer::const_iterator dynamic_texture_buffer::cbegin() const
|
||||
{
|
||||
return const_cast<const_iterator>(begin());
|
||||
}
|
||||
|
||||
inline dynamic_texture_buffer::const_iterator dynamic_texture_buffer::cend() const
|
||||
{
|
||||
return const_cast<const_iterator>(begin());
|
||||
}
|
||||
Reference in New Issue
Block a user