From d18b40a7fc3ff509ed5ae6524ca36a5f9916d307 Mon Sep 17 00:00:00 2001 From: ZY4N Date: Fri, 28 Mar 2025 13:09:34 +0100 Subject: [PATCH] stuff... --- CMakeLists.txt | 7 ++- .../assets/components/material_components.hpp | 37 +++++------ .../components/mesh_vertex_components.hpp | 32 ++++++---- .../point_cloud_vertex_components.hpp | 27 ++++---- .../assets/components/texture_components.hpp | 17 +++-- .../data/generic/component_array_set.hpp | 33 ++++++++++ include/assets/data/generic/component_set.hpp | 32 ++++++++++ .../assets/data/generic/vertex_array_data.hpp | 21 ------- include/assets/data/material_data.hpp | 49 ++++++--------- include/assets/data/material_library_data.hpp | 4 +- include/assets/data/mesh_data.hpp | 50 ++++++--------- include/assets/data/point_cloud_data.hpp | 11 ++-- include/assets/data/pose_data.hpp | 4 +- include/assets/data/shader_source_data.hpp | 4 +- include/assets/data/surface_properties.hpp | 10 +-- include/assets/data/texture_data.hpp | 15 ++--- .../generic/generic_basic_store.hpp | 12 ++-- .../generic/generic_material_store.hpp | 5 +- .../generic/generic_mesh_store.hpp | 8 +-- .../generic/generic_point_cloud_store.hpp | 8 +-- .../data_views/generic/generic_mesh_view.hpp | 23 +++++++ .../generic/generic_point_cloud_viwe.hpp | 17 +++++ include/assets/data_views/mesh_view.hpp | 28 +-------- .../assets/data_views/point_cloud_view.hpp | 21 +------ .../assets/data_views/shader_source_view.hpp | 4 +- include/assets/data_views/texture_view.hpp | 7 ++- .../generic/generic_3dtk_loader.hpp | 4 +- include/assets/identifiers.hpp | 16 +++++ include/config/primitives.hpp | 62 +++++++++++++++++++ include/util/id_type.hpp | 26 +++++--- source/assets/data/material_data.ipp | 39 +++++------- source/assets/data/mesh_data.ipp | 28 ++++----- source/assets/data/point_cloud_data.ipp | 2 +- .../generic/generic_material_store.ipp | 2 +- 34 files changed, 393 insertions(+), 272 deletions(-) create mode 100644 include/assets/data/generic/component_array_set.hpp create mode 100644 include/assets/data/generic/component_set.hpp delete mode 100644 include/assets/data/generic/vertex_array_data.hpp create mode 100644 include/assets/data_views/generic/generic_mesh_view.hpp create mode 100644 include/assets/data_views/generic/generic_point_cloud_viwe.hpp create mode 100644 include/assets/identifiers.hpp create mode 100644 include/config/primitives.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ab01ad..ab5ac53 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,7 +125,7 @@ add_executable(z3d main.cpp include/assets/data/texture_data.hpp source/assets/data/mesh_data.ipp source/assets/data/material_data.ipp - include/assets/data/generic/vertex_array_data.hpp + include/assets/data/generic/component_array_set.hpp source/assets/data/texture_data.ipp source/assets/data/point_cloud_data.ipp include/assets/file_parsers/mtl_loader.hpp @@ -232,6 +232,11 @@ add_executable(z3d main.cpp include/opengl/shading/uniform_block.hpp include/opengl/shading/uniform_blocks/mesh_uniform_blocks.hpp include/opengl/shading/uniform_blocks/point_cloud_uniform_blocks.hpp + include/config/primitives.hpp + include/assets/data/generic/component_set.hpp + include/assets/data_views/generic/generic_mesh_view.hpp + include/assets/data_views/generic/generic_point_cloud_viwe.hpp + include/assets/identifiers.hpp ) target_include_directories(z3d PRIVATE include) diff --git a/include/assets/components/material_components.hpp b/include/assets/components/material_components.hpp index b3f01ad..645b002 100644 --- a/include/assets/components/material_components.hpp +++ b/include/assets/components/material_components.hpp @@ -2,6 +2,8 @@ #include +#include "config/primitives.hpp" +#include "assets/identifiers.hpp" #include "assets/data_stores/texture_store.hpp" #include "assets/data/surface_properties.hpp" #include "util/enum_bitfield_operators.hpp" @@ -9,28 +11,27 @@ namespace assets::material_components { using surface_properties = surface_properties; -using transparency = float; -using ambient_color_texture = texture_store::id_type; -using diffuse_color_texture = texture_store::id_type; -using specular_color_texture = texture_store::id_type; -using shininess_texture = texture_store::id_type; -using alpha_texture = texture_store::id_type; -using bump_texture = texture_store::id_type; +using transparency = z3d::f32; +using ambient_color_texture = texture_id; +using diffuse_color_texture = texture_id; +using specular_color_texture = texture_id; +using shininess_texture = texture_id; +using alpha_texture = texture_id; +using bump_texture = texture_id; namespace indices { -using type = std::size_t; -inline constexpr type surface_properties = 0; -inline constexpr type transparency = 1; -inline constexpr type ambient_color_texture = 2; -inline constexpr type diffuse_color_texture = 3; -inline constexpr type specular_color_texture = 4; -inline constexpr type shininess_texture = 5; -inline constexpr type alpha_texture = 6; -inline constexpr type bump_texture = 7; +inline constexpr z3d::size surface_properties = 0; +inline constexpr z3d::size transparency = 1; +inline constexpr z3d::size ambient_color_texture = 2; +inline constexpr z3d::size diffuse_color_texture = 3; +inline constexpr z3d::size specular_color_texture = 4; +inline constexpr z3d::size shininess_texture = 5; +inline constexpr z3d::size alpha_texture = 6; +inline constexpr z3d::size bump_texture = 7; } -enum class flags : std::uint8_t +enum class flags : z3d::u8 { none = 0, surface_properties = 1 << indices::surface_properties, @@ -43,7 +44,7 @@ enum class flags : std::uint8_t bump_texture = 1 << indices::bump_texture }; -using all = std::tuple< +using all = z3d::structure< surface_properties, transparency, ambient_color_texture, diff --git a/include/assets/components/mesh_vertex_components.hpp b/include/assets/components/mesh_vertex_components.hpp index 87be280..e09c39d 100755 --- a/include/assets/components/mesh_vertex_components.hpp +++ b/include/assets/components/mesh_vertex_components.hpp @@ -1,5 +1,6 @@ #pragma once +#include "config/primitives.hpp" #include #include #include "util/enum_bitfield_operators.hpp" @@ -7,23 +8,22 @@ namespace assets::mesh_vertex_components { -using position = std::array; -using normal = std::array; -using tex_coord = std::array; -using color = std::array; -using reflectance = std::array; +using position = z3d::vec3; +using normal = z3d::vec3; +using tex_coord = z3d::vec2; +using color = z3d::vec3; +using reflectance = z3d::f32; namespace indices { -using type = std::size_t; -inline constexpr type position = 0; -inline constexpr type normal = 1; -inline constexpr type tex_coord = 2; -inline constexpr type color = 3; -inline constexpr type reflectance = 4; +inline constexpr z3d::size position = 0; +inline constexpr z3d::size normal = 1; +inline constexpr z3d::size tex_coord = 2; +inline constexpr z3d::size color = 3; +inline constexpr z3d::size reflectance = 4; } -enum class flags : std::uint8_t +enum class flags : z3d::u8 { none = 0, position = 1 << indices::position, @@ -33,7 +33,13 @@ enum class flags : std::uint8_t reflectance = 1 << indices::reflectance }; -using all = std::tuple; +using all = z3d::structure< + position, + normal, + tex_coord, + color, + reflectance +>; constexpr inline auto count = std::tuple_size_v; } // namespace mesh_vertex_components diff --git a/include/assets/components/point_cloud_vertex_components.hpp b/include/assets/components/point_cloud_vertex_components.hpp index 1f8c561..e383267 100755 --- a/include/assets/components/point_cloud_vertex_components.hpp +++ b/include/assets/components/point_cloud_vertex_components.hpp @@ -1,5 +1,6 @@ #pragma once +#include "config/primitives.hpp" #include #include #include "util/enum_bitfield_operators.hpp" @@ -7,21 +8,20 @@ namespace assets::point_cloud_vertex_components { -using position = std::array; -using normal = std::array; -using color = std::array; -using reflectance = std::array; +using position = z3d::vec3; +using normal = z3d::vec3; +using color = z3d::vec3; +using reflectance = z3d::f32; namespace indices { -using type = std::size_t; -inline constexpr type position = 0; -inline constexpr type normal = 1; -inline constexpr type color = 2; -inline constexpr type reflectance = 3; +inline constexpr z3d::size position = 0; +inline constexpr z3d::size normal = 1; +inline constexpr z3d::size color = 2; +inline constexpr z3d::size reflectance = 3; } // namespace indices -enum class flags : std::uint8_t +enum class flags : z3d::u8 { none = 0, position = 1 << indices::position, @@ -30,7 +30,12 @@ enum class flags : std::uint8_t reflectance = 1 << indices::reflectance }; -using all = std::tuple; +using all = z3d::structure< + position, + normal, + color, + reflectance +>; constexpr inline auto count = std::tuple_size_v; } // namespace point_cloud_vertex_components diff --git a/include/assets/components/texture_components.hpp b/include/assets/components/texture_components.hpp index 651eb81..58022a2 100644 --- a/include/assets/components/texture_components.hpp +++ b/include/assets/components/texture_components.hpp @@ -1,5 +1,6 @@ #pragma once +#include "config/primitives.hpp" #include #include #include "util/enum_bitfield_operators.hpp" @@ -7,10 +8,11 @@ namespace assets::texture_components { -using red = std::uint8_t; -using green = std::uint8_t; -using blue = std::uint8_t; -using luminance = std::uint8_t; +using red = z3d::u8; +using green = z3d::u8; +using blue = z3d::u8; +using alpha = z3d::u8; +using luminance = z3d::u8; enum class flags : std::uint8_t { @@ -22,7 +24,12 @@ enum class flags : std::uint8_t alpha = 1 << 5 }; -using all = std::tuple; +using all = z3d::structure< + red, + green, + blue, + luminance +>; constexpr inline auto count = std::tuple_size_v; } // namespace texture_components diff --git a/include/assets/data/generic/component_array_set.hpp b/include/assets/data/generic/component_array_set.hpp new file mode 100644 index 0000000..2f5fb23 --- /dev/null +++ b/include/assets/data/generic/component_array_set.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include "config/primitives.hpp" + +namespace assets::detail +{ + +template +class component_array_set {}; + +template +class component_array_set> +{ + component_array_set() = default; + +protected: + void clear_component_arrays() + { + std::apply( + [](auto&... component_array) + { + (component_array.clear(), ...); + }, + component_arrays + ); + } + + C component_flags; + z3d::structure...> component_arrays{}; + +}; + +} diff --git a/include/assets/data/generic/component_set.hpp b/include/assets/data/generic/component_set.hpp new file mode 100644 index 0000000..4c4dbed --- /dev/null +++ b/include/assets/data/generic/component_set.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include "config/primitives.hpp" + +namespace assets::detail { + +template +class component_set {}; + + +template +class component_set> +{ +public: + component_set() = default; + +protected: + void clear_components() + { + std::apply( + [](std::optional&... component) + { + (component.reset(), ...); + }, + components + ); + } + + z3d::structure> components{}; +}; + +} diff --git a/include/assets/data/generic/vertex_array_data.hpp b/include/assets/data/generic/vertex_array_data.hpp deleted file mode 100644 index 2ebb9c0..0000000 --- a/include/assets/data/generic/vertex_array_data.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include - -template -struct vertex_array_data -{ - C component_flags; - std::tuple...> vertices{}; - -protected: - void clear_vertices() - { - std::apply( - [](auto&... vertex_opt) { - (vertex_opt.clear(), ...); - }, - vertices - ); - } -}; diff --git a/include/assets/data/material_data.hpp b/include/assets/data/material_data.hpp index 3ac8ccb..6a0a2c5 100755 --- a/include/assets/data/material_data.hpp +++ b/include/assets/data/material_data.hpp @@ -3,50 +3,37 @@ #include #include "assets/components/material_components.hpp" -#include "assets/data_stores/texture_store.hpp" +#include "generic/component_set.hpp" namespace assets { -struct material_data +struct material_data : detail::component_set { material_data() = default; material_components::surface_properties& initialized_surface_properties(); - [[nodiscard]] inline std::optional& surface_properties(); - [[nodiscard]] inline std::optional& transparency(); - [[nodiscard]] inline std::optional& ambient_color_texture_id(); - [[nodiscard]] inline std::optional& diffuse_color_texture_id(); - [[nodiscard]] inline std::optional& specular_color_texture_id(); - [[nodiscard]] inline std::optional& shininess_texture_id(); - [[nodiscard]] inline std::optional& alpha_texture_id(); - [[nodiscard]] inline std::optional& bump_texture_id(); + [[nodiscard]] inline z3d::optional& surface_properties(); + [[nodiscard]] inline z3d::optional& transparency(); + [[nodiscard]] inline z3d::optional& ambient_color_texture_id(); + [[nodiscard]] inline z3d::optional& diffuse_color_texture_id(); + [[nodiscard]] inline z3d::optional& specular_color_texture_id(); + [[nodiscard]] inline z3d::optional& shininess_texture_id(); + [[nodiscard]] inline z3d::optional& alpha_texture_id(); + [[nodiscard]] inline z3d::optional& bump_texture_id(); - [[nodiscard]] inline const std::optional& surface_properties() const; - [[nodiscard]] inline const std::optional& transparency() const; - [[nodiscard]] inline const std::optional& ambient_color_texture_id() const; - [[nodiscard]] inline const std::optional& diffuse_color_texture_id() const; - [[nodiscard]] inline const std::optional& specular_color_texture_id() const; - [[nodiscard]] inline const std::optional& shininess_texture_id() const; - [[nodiscard]] inline const std::optional& alpha_texture_id() const; - [[nodiscard]] inline const std::optional& bump_texture_id() const; + [[nodiscard]] inline const z3d::optional& surface_properties() const; + [[nodiscard]] inline const z3d::optional& transparency() const; + [[nodiscard]] inline const z3d::optional& ambient_color_texture_id() const; + [[nodiscard]] inline const z3d::optional& diffuse_color_texture_id() const; + [[nodiscard]] inline const z3d::optional& specular_color_texture_id() const; + [[nodiscard]] inline const z3d::optional& shininess_texture_id() const; + [[nodiscard]] inline const z3d::optional& alpha_texture_id() const; + [[nodiscard]] inline const z3d::optional& bump_texture_id() const; inline void clear(); - - std::tuple< - std::optional, - std::optional, - std::optional, - std::optional, - std::optional, - std::optional, - std::optional, - std::optional - > data{ - std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt - }; }; } diff --git a/include/assets/data/material_library_data.hpp b/include/assets/data/material_library_data.hpp index 6755c66..0fd6ec1 100644 --- a/include/assets/data/material_library_data.hpp +++ b/include/assets/data/material_library_data.hpp @@ -1,11 +1,11 @@ #pragma once #include "util/string_lookup.hpp" -#include "assets/data_stores/material_store.hpp" +#include "assets/identifiers.hpp" namespace assets { -using material_library_data = ztu::string_lookup; +using material_library_data = ztu::string_lookup; } diff --git a/include/assets/data/mesh_data.hpp b/include/assets/data/mesh_data.hpp index 43cb9e8..05cbd13 100644 --- a/include/assets/data/mesh_data.hpp +++ b/include/assets/data/mesh_data.hpp @@ -1,49 +1,39 @@ #pragma once -#include -#include - -#include "util/uix.hpp" #include "assets/components/mesh_vertex_components.hpp" -#include "generic/vertex_array_data.hpp" -#include "assets/data_stores/material_store.hpp" +#include "generic/component_array_set.hpp" +#include "assets/identifiers.hpp" namespace assets { -class mesh_data : public vertex_array_data< +class mesh_data : detail::component_array_set< mesh_vertex_components::flags, - mesh_vertex_components::position, - mesh_vertex_components::normal, - mesh_vertex_components::tex_coord, - mesh_vertex_components::color, - mesh_vertex_components::reflectance + mesh_vertex_components::all > { public: - using index_type = ztu::u32; - using triangle_type = std::array; - [[nodiscard]] inline std::vector& positions(); - [[nodiscard]] inline std::vector& normals(); - [[nodiscard]] inline std::vector& tex_coords(); - [[nodiscard]] inline std::vector& colors(); - [[nodiscard]] inline std::vector& reflectances(); - [[nodiscard]] inline std::vector& triangles(); - [[nodiscard]] inline auto& material_id(); + [[nodiscard]] inline z3d::vector& positions(); + [[nodiscard]] inline z3d::vector& normals(); + [[nodiscard]] inline z3d::vector& tex_coords(); + [[nodiscard]] inline z3d::vector& colors(); + [[nodiscard]] inline z3d::vector& reflectances(); + [[nodiscard]] inline z3d::vector& triangles(); + [[nodiscard]] inline auto& material(); - [[nodiscard]] inline const std::vector& positions() const; - [[nodiscard]] inline const std::vector& normals() const; - [[nodiscard]] inline const std::vector& tex_coords() const; - [[nodiscard]] inline const std::vector& colors() const; - [[nodiscard]] inline const std::vector& reflectances() const; - [[nodiscard]] inline const std::vector& triangles() const; - [[nodiscard]] inline const auto& material_id() const; + [[nodiscard]] inline const z3d::vector& positions() const; + [[nodiscard]] inline const z3d::vector& normals() const; + [[nodiscard]] inline const z3d::vector& tex_coords() const; + [[nodiscard]] inline const z3d::vector& colors() const; + [[nodiscard]] inline const z3d::vector& reflectances() const; + [[nodiscard]] inline const z3d::vector& triangles() const; + [[nodiscard]] inline const auto& material() const; inline void clear(); private: - std::vector m_triangles{}; - material_store::id_type m_material_id{}; + z3d::vector m_triangles{}; + material_id m_material_id{}; }; } diff --git a/include/assets/data/point_cloud_data.hpp b/include/assets/data/point_cloud_data.hpp index 65c9d2a..9580b73 100644 --- a/include/assets/data/point_cloud_data.hpp +++ b/include/assets/data/point_cloud_data.hpp @@ -4,17 +4,14 @@ #include #include -#include "generic/vertex_array_data.hpp" +#include "generic/component_array_set.hpp" namespace assets { -class point_cloud_data : public vertex_array_data< - point_cloud_vertex_components::flags, - point_cloud_vertex_components::position, - point_cloud_vertex_components::normal, - point_cloud_vertex_components::color, - point_cloud_vertex_components::reflectance +class point_cloud_data : detail::component_array_set< + point_cloud_vertex_components::flags, + point_cloud_vertex_components::all > { public: [[nodiscard]] inline std::vector& positions(); diff --git a/include/assets/data/pose_data.hpp b/include/assets/data/pose_data.hpp index b413d80..bb76a1d 100644 --- a/include/assets/data/pose_data.hpp +++ b/include/assets/data/pose_data.hpp @@ -1,10 +1,10 @@ #pragma once -#include "glm/mat4x4.hpp" +#include "config/primitives.hpp" namespace assets { -using pose_data = glm::mat4; +using pose_data = z3d::mat4; } diff --git a/include/assets/data/shader_source_data.hpp b/include/assets/data/shader_source_data.hpp index a99ac54..3597852 100644 --- a/include/assets/data/shader_source_data.hpp +++ b/include/assets/data/shader_source_data.hpp @@ -1,13 +1,13 @@ #pragma once -#include +#include "config/primitives.hpp" namespace assets { struct shader_source_data { - std::vector source{}; + z3d::vector source{}; void clear() { diff --git a/include/assets/data/surface_properties.hpp b/include/assets/data/surface_properties.hpp index bbd980e..efa1db8 100644 --- a/include/assets/data/surface_properties.hpp +++ b/include/assets/data/surface_properties.hpp @@ -1,16 +1,16 @@ #pragma once -#include +#include "config/primitives.hpp" namespace assets { struct surface_properties { - std::array ambient_filter{ 0.7f, 0.7f, 0.7f }; - std::array diffuse_filter{ 0.466f, 0.466f, 0.7922f }; - std::array specular_filter{ 0.5974f, 0.2084f, 0.2084f }; - float shininess{ 100.2237f }; + z3d::vec3 ambient_filter{ 0.7f, 0.7f, 0.7f }; + z3d::vec3 diffuse_filter{ 0.466f, 0.466f, 0.7922f }; + z3d::vec3 specular_filter{ 0.5974f, 0.2084f, 0.2084f }; + z3d::f32 shininess{ 100.2237f }; }; } diff --git a/include/assets/data/texture_data.hpp b/include/assets/data/texture_data.hpp index c82e00f..5d14e5a 100755 --- a/include/assets/data/texture_data.hpp +++ b/include/assets/data/texture_data.hpp @@ -12,21 +12,22 @@ namespace assets class texture_data { public: - using value_type = std::uint8_t; - using dim_type = std::int32_t; - using size_type = std::make_signed_t; + using value_type = z3d::u8; + using dim_type = z3d::i32; + using size_type = z3d::size; using difference_type = size_type; using reference = value_type&; using const_reference = const value_type&; - using pointer = std::uint8_t*; - using const_pointer = const std::uint8_t*; + using pointer = value_type*; + using const_pointer = const value_type*; using iterator = pointer; using const_iterator = const_pointer; + using container_type = std::unique_ptr; texture_data() = default; inline texture_data( - std::unique_ptr&& data, + container_type&& data, dim_type width, dim_type height, texture_components::flags components @@ -73,7 +74,7 @@ public: void inline clear(); private: - std::unique_ptr m_data{ nullptr }; + container_type m_data{ nullptr }; dim_type m_width{ 0 }, m_height{ 0 }; texture_components::flags m_components{ texture_components::flags::none }; }; diff --git a/include/assets/data_stores/generic/generic_basic_store.hpp b/include/assets/data_stores/generic/generic_basic_store.hpp index 0101725..9cb547c 100644 --- a/include/assets/data_stores/generic/generic_basic_store.hpp +++ b/include/assets/data_stores/generic/generic_basic_store.hpp @@ -6,20 +6,19 @@ #include "util/uix.hpp" #include "util/id_type.hpp" -template +template class generic_basic_store { public: - using id_type = ztu::id_type_for; using container_type = std::vector; using iterator_type = typename container_type::iterator; using const_iterator = typename container_type::const_iterator; - id_type add(const T& data); + ID add(const T& data); - [[nodiscard]] std::pair find(id_type id); + [[nodiscard]] std::pair find(ID id); - [[nodiscard]] std::pair find(id_type id) const; + [[nodiscard]] std::pair find(ID id) const; [[nodiscard]] std::span data(); @@ -31,8 +30,7 @@ public: private: std::vector m_data; - std::vector m_ids; - id_type m_next_data_id{ 1 }; + std::vector m_ids; }; #define INCLUDE_GENERIC_BASIC_STORE_IMPLEMENTATION diff --git a/include/assets/data_stores/generic/generic_material_store.hpp b/include/assets/data_stores/generic/generic_material_store.hpp index 7a40c33..d8ae0c2 100644 --- a/include/assets/data_stores/generic/generic_material_store.hpp +++ b/include/assets/data_stores/generic/generic_material_store.hpp @@ -18,7 +18,7 @@ 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...>, ztu::u32>; + using id_type = material_id; using value_type = std::pair; using flag_count_type = std::tuple; @@ -105,7 +105,7 @@ public: using const_iterator = generic_material_store_iterator...>; using view_type = std::ranges::subrange; using const_view_type = std::ranges::subrange; - using id_type = ztu::id_type_for; + using id_type = material_id; id_type add(const material_data& material); @@ -144,7 +144,6 @@ private: std::vector m_ids; std::tuple...> m_component_arrays; std::vector m_component_flag_counts; - id_type m_next_data_id{ 1 }; }; } diff --git a/include/assets/data_stores/generic/generic_mesh_store.hpp b/include/assets/data_stores/generic/generic_mesh_store.hpp index f61f0f1..84f08ba 100644 --- a/include/assets/data_stores/generic/generic_mesh_store.hpp +++ b/include/assets/data_stores/generic/generic_mesh_store.hpp @@ -17,10 +17,10 @@ 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 index_type = z3d::vertex_index; using material_id_type = material_store::id_type; using component_flag_type = mesh_vertex_components::flags; - using id_type = ztu::id_type_for>, ztu::u32>; + using id_type = mesh_id; using value_type = std::pair; using flag_count_type = std::tuple; @@ -107,7 +107,7 @@ class generic_mesh_store public: using size_type = std::size_t; using count_type = ztu::u32; - using index_type = mesh_data::index_type; + using index_type = z3d::vertex_index; using component_flag_type = mesh_vertex_components::flags; using material_id_type = material_store::id_type; @@ -115,7 +115,7 @@ public: using const_iterator = generic_mesh_store_iterator...>; using view_type = std::ranges::subrange; using const_view_type = std::ranges::subrange; - using id_type = ztu::id_type_for; + using id_type = mesh_id; id_type add(const mesh_data& mesh); diff --git a/include/assets/data_stores/generic/generic_point_cloud_store.hpp b/include/assets/data_stores/generic/generic_point_cloud_store.hpp index e201fe9..c521ba2 100644 --- a/include/assets/data_stores/generic/generic_point_cloud_store.hpp +++ b/include/assets/data_stores/generic/generic_point_cloud_store.hpp @@ -19,10 +19,10 @@ template class generic_point_cloud_store_iterator { public: - using size_type = std::size_t; - using count_type = ztu::u32; + using size_type = z3d::size; + using count_type = z3d::u32; using component_flag_type = point_cloud_vertex_components::flags; - using id_type = ztu::id_type_for...>, ztu::u32>; + using id_type = point_cloud_id; using value_type = std::pair; using flag_count_type = std::tuple; @@ -109,7 +109,7 @@ public: using const_iterator = generic_point_cloud_store_iterator...>; using view_type = std::ranges::subrange; using const_view_type = std::ranges::subrange; - using id_type = ztu::id_type_for; + using id_type = point_cloud_id; id_type add(const point_cloud_data& point_cloud); diff --git a/include/assets/data_views/generic/generic_mesh_view.hpp b/include/assets/data_views/generic/generic_mesh_view.hpp new file mode 100644 index 0000000..78ef297 --- /dev/null +++ b/include/assets/data_views/generic/generic_mesh_view.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "config/primitives.hpp" +#include "assets/components/mesh_vertex_components.hpp" +#include "assets/data_stores/material_store.hpp" + +namespace assets::detail +{ + +template +struct generic_mesh_view {}; + +template +struct generic_mesh_view> +{ + mesh_vertex_components::flags component_flags; + z3d::array_view triangles; + z3d::structure...> vertex_component_arrays; + z3d::vertex_index vertex_count; + material_store::id_type material_id; +}; + +} diff --git a/include/assets/data_views/generic/generic_point_cloud_viwe.hpp b/include/assets/data_views/generic/generic_point_cloud_viwe.hpp new file mode 100644 index 0000000..57ed1d4 --- /dev/null +++ b/include/assets/data_views/generic/generic_point_cloud_viwe.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include "config/primitives.hpp" +#include "assets/components/point_cloud_vertex_components.hpp" + +namespace assets::detail +{ + +template +struct generic_point_cloud_view +{ + point_cloud_vertex_components::flags vertex_component_flags; + z3d::structure...> vertex_component_arrays; + z3d::vertex_index point_count; +}; + +} diff --git a/include/assets/data_views/mesh_view.hpp b/include/assets/data_views/mesh_view.hpp index 57fbd3e..b6f4f70 100644 --- a/include/assets/data_views/mesh_view.hpp +++ b/include/assets/data_views/mesh_view.hpp @@ -1,34 +1,12 @@ #pragma once -#include -#include - -#include "assets/components/mesh_vertex_components.hpp" -#include "assets/data/mesh_data.hpp" -#include "assets/data_stores/material_store.hpp" +#include "generic/generic_mesh_view.hpp" namespace assets { -namespace detail -{ -template -struct generic_mesh_view -{ - mesh_vertex_components::flags component_flags; - std::span indices; - std::tuple...> vertex_component_arrays; - std::size_t vertex_count; - material_store::id_type material_id; -}; - -} - using mesh_view = detail::generic_mesh_view< - mesh_vertex_components::position, - mesh_vertex_components::normal, - mesh_vertex_components::tex_coord, - mesh_vertex_components::color, - mesh_vertex_components::reflectance + mesh_vertex_components::all >; + } \ No newline at end of file diff --git a/include/assets/data_views/point_cloud_view.hpp b/include/assets/data_views/point_cloud_view.hpp index 2da41e7..3a7859b 100644 --- a/include/assets/data_views/point_cloud_view.hpp +++ b/include/assets/data_views/point_cloud_view.hpp @@ -1,29 +1,12 @@ #pragma once -#include -#include - -#include "assets/components/point_cloud_vertex_components.hpp" +#include "generic/generic_point_cloud_viwe.hpp" namespace assets { -namespace detail -{ -template -struct generic_point_cloud_view -{ - point_cloud_vertex_components::flags vertex_component_flags; - std::tuple...> vertex_component_arrays; - std::size_t point_count; -}; -} - using point_cloud_view = detail::generic_point_cloud_view< - point_cloud_vertex_components::position, - point_cloud_vertex_components::normal, - point_cloud_vertex_components::color, - point_cloud_vertex_components::reflectance + point_cloud_vertex_components::all >; } \ No newline at end of file diff --git a/include/assets/data_views/shader_source_view.hpp b/include/assets/data_views/shader_source_view.hpp index 7c4f1a1..954ac59 100644 --- a/include/assets/data_views/shader_source_view.hpp +++ b/include/assets/data_views/shader_source_view.hpp @@ -1,5 +1,5 @@ #pragma once -#include +#include "config/primitives.hpp" -using shader_source_view = std::string_view; +using shader_source_view = z3d::string_view; diff --git a/include/assets/data_views/texture_view.hpp b/include/assets/data_views/texture_view.hpp index da644bf..d331503 100644 --- a/include/assets/data_views/texture_view.hpp +++ b/include/assets/data_views/texture_view.hpp @@ -1,14 +1,15 @@ #pragma once -#include "assets/data/material_data.hpp" +#include "assets/components/texture_components.hpp" +#include namespace assets { struct texture_view { - std::weak_ptr data; - int width, height; + std::weak_ptr data; + z3d::i32 width, height; texture_components::flags component_flags; }; diff --git a/include/assets/file_parsers/generic/generic_3dtk_loader.hpp b/include/assets/file_parsers/generic/generic_3dtk_loader.hpp index c66b65b..feccde4 100644 --- a/include/assets/file_parsers/generic/generic_3dtk_loader.hpp +++ b/include/assets/file_parsers/generic/generic_3dtk_loader.hpp @@ -9,8 +9,8 @@ #include "util/string_list.hpp" #include "assets/prefetch_queue.hpp" -#include "../../read_buffers" -#include "../../data_stores" +#include "assets/data/point_cloud_data.hpp" +#include "assets/data_stores/point_cloud_store.hpp" #include "assets/prefetch_lookup.hpp" diff --git a/include/assets/identifiers.hpp b/include/assets/identifiers.hpp new file mode 100644 index 0000000..326b993 --- /dev/null +++ b/include/assets/identifiers.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "config/primitives.hpp" + +namespace assets +{ + +using material_id = z3d::identifier<0>; +using material_library_id = z3d::identifier<1>; +using mesh_id = z3d::identifier<2>; +using point_cloud_id = z3d::identifier<3>; +using pose_id = z3d::identifier<4>; +using shader_source_id = z3d::identifier<5>; +using texture_id = z3d::identifier<6>; + +} diff --git a/include/config/primitives.hpp b/include/config/primitives.hpp new file mode 100644 index 0000000..6a7dfdf --- /dev/null +++ b/include/config/primitives.hpp @@ -0,0 +1,62 @@ +#pragma once + +#include +#include +#include "glm/gtc/type_aligned.hpp" +#include "util/id_type.hpp" + +namespace z3d +{ + +using u8 = std::uint8_t; +using u16 = std::uint16_t; +using u32 = std::uint32_t; +using u64 = std::uint64_t; + +using i8 = std::int8_t; +using i16 = std::int16_t; +using i32 = std::int32_t; +using i64 = std::int64_t; + +using size = ssize_t; + +using f32 = float; +using f64 = double; + +template +using vec = glm::vec; + +using vec2 = vec<2, f32>; +using vec3 = vec<3, f32>; +using vec4 = vec<4, f32>; + +template +using mat = glm::mat; + +using mat3 = mat<4, 4, f32>; +using mat4 = mat<4, 4, f32>; + +template +using optional = std::optional; + +template +using array = std::array; + +template +using vector = std::vector; + +template +using array_view = std::span; + +template +using structure = std::tuple; + +using string_view = std::string_view; + +using vertex_index = u32; +using index_triangle = array; + +template +using identifier = ztu::id_type; + +} diff --git a/include/util/id_type.hpp b/include/util/id_type.hpp index ac91005..72d1d59 100644 --- a/include/util/id_type.hpp +++ b/include/util/id_type.hpp @@ -1,25 +1,31 @@ #pragma once +#include + namespace ztu { -template -class id_type_for + +template +class id_type { - friend Parent; + explicit constexpr id_type(Index index) : index{ index } {} - using index_type = IndexType; + static constexpr id_type next() + { + static std::atomic next_index{ 1 }; + return id_type{ next_index.fetch_add(1, std::memory_order_seq_cst) }; + } - explicit constexpr id_type_for(index_type index) : index{ index } {} - - index_type index{}; + Index index{}; public: - constexpr id_type_for() = default; - constexpr auto operator<=>(const id_type_for&) const = default; + constexpr id_type() = default; + constexpr auto operator<=>(const id_type&) const = default; constexpr operator bool() const { - return index == index_type{}; + return index == Index{}; } }; + } \ No newline at end of file diff --git a/source/assets/data/material_data.ipp b/source/assets/data/material_data.ipp index 32c9a7a..b7b7289 100644 --- a/source/assets/data/material_data.ipp +++ b/source/assets/data/material_data.ipp @@ -5,75 +5,75 @@ inline std::optional& assets::material_data::surface_properties() { - return std::get(data); + return std::get(components); } inline std::optional& assets::material_data::transparency() { - return std::get(data); + return std::get(components); } inline std::optional& assets::material_data::ambient_color_texture_id() { - return std::get(data); + return std::get(components); } inline std::optional& assets::material_data::diffuse_color_texture_id() { - return std::get(data); + return std::get(components); } inline std::optional& assets::material_data::specular_color_texture_id() { - return std::get(data); + return std::get(components); } inline std::optional& assets::material_data::shininess_texture_id() { - return std::get(data); + return std::get(components); } inline std::optional& assets::material_data::alpha_texture_id() { - return std::get(data); + return std::get(components); } inline std::optional& assets::material_data::bump_texture_id() { - return std::get& assets::material_data::surface_properties() const { - return std::get(data); + return std::get(components); } inline const std::optional& assets::material_data::transparency() const { - return std::get(data); + return std::get(components); } inline const std::optional& assets::material_data::ambient_color_texture_id() const { - return std::get(data); + return std::get(components); } inline const std::optional& assets::material_data::diffuse_color_texture_id() const { - return std::get(data); + return std::get(components); } inline const std::optional& assets::material_data::specular_color_texture_id() const { - return std::get(data); + return std::get(components); } inline const std::optional& assets::material_data::shininess_texture_id() const { - return std::get(data); + return std::get(components); } inline const std::optional& assets::material_data::alpha_texture_id() const { - return std::get(data); + return std::get(components); } inline const std::optional& assets::material_data::bump_texture_id() const { - return std::get(data); + return std::get(components); } @@ -89,11 +89,6 @@ inline assets::material_components::surface_properties& assets::material_data::i inline void assets::material_data::clear() { - std::apply( - [](auto&... data_opt) { - (data_opt.reset(), ...); - }, - data - ); + clear_components(); } diff --git a/source/assets/data/mesh_data.ipp b/source/assets/data/mesh_data.ipp index 8a6ea62..e416e92 100644 --- a/source/assets/data/mesh_data.ipp +++ b/source/assets/data/mesh_data.ipp @@ -4,62 +4,62 @@ inline std::vector& assets::mesh_data::positions() { - return std::get(vertices); + return std::get(component_arrays); } inline std::vector& assets::mesh_data::normals() { - return std::get(vertices); + return std::get(component_arrays); } inline std::vector& assets::mesh_data::tex_coords() { - return std::get(vertices); + return std::get(component_arrays); } inline std::vector& assets::mesh_data::colors() { - return std::get(vertices); + return std::get(component_arrays); } inline std::vector& assets::mesh_data::reflectances() { - return std::get(vertices); + return std::get(component_arrays); } -inline std::vector& assets::mesh_data::triangles() +inline std::vector& assets::mesh_data::triangles() { return m_triangles; } -inline auto& assets::mesh_data::material_id() +inline auto& assets::mesh_data::material() { return m_material_id; } inline const std::vector& assets::mesh_data::positions() const { - return std::get(vertices); + return std::get(component_arrays); } inline const std::vector& assets::mesh_data::normals() const { - return std::get(vertices); + return std::get(component_arrays); } inline const std::vector& assets::mesh_data::tex_coords() const { - return std::get(vertices); + return std::get(component_arrays); } inline const std::vector& assets::mesh_data::colors() const { - return std::get(vertices); + return std::get(component_arrays); } inline const std::vector& assets::mesh_data::reflectances() const { - return std::get(vertices); + return std::get(component_arrays); } inline const std::vector& assets::mesh_data::triangles() const @@ -67,14 +67,14 @@ inline const std::vector& assets::mesh_data::t return m_triangles; } -inline const auto& assets::mesh_data::material_id() const +inline const auto& assets::mesh_data::material() const { return m_material_id; } inline void assets::mesh_data::clear() { - clear_vertices(); + clear_component_arrays(); m_triangles.clear(); m_material_id = {}; } diff --git a/source/assets/data/point_cloud_data.ipp b/source/assets/data/point_cloud_data.ipp index 679be40..83fe3f2 100644 --- a/source/assets/data/point_cloud_data.ipp +++ b/source/assets/data/point_cloud_data.ipp @@ -45,5 +45,5 @@ inline const std::vector& as inline void assets::point_cloud_data::clear() { - clear_vertices(); + clear_component_arrays(); } \ No newline at end of file diff --git a/source/assets/data_stores/generic/generic_material_store.ipp b/source/assets/data_stores/generic/generic_material_store.ipp index d908bf2..41613c2 100644 --- a/source/assets/data_stores/generic/generic_material_store.ipp +++ b/source/assets/data_stores/generic/generic_material_store.ipp @@ -229,7 +229,7 @@ assets::detail::generic_material_store::array_counts() const template typename assets::detail::generic_material_store::id_type assets::detail::generic_material_store::add( - const material_data& material + const component_set& material ) { const auto id = id_type{ m_next_data_id.index++ };