tried making naming more uniform and implemented most of the opengl managers

This commit is contained in:
ZY4N
2025-03-25 02:22:44 +01:00
parent c609d49f0d
commit 71ea2d9237
155 changed files with 4097 additions and 2434 deletions

7
.gitmodules vendored
View File

@@ -1,6 +1,9 @@
[submodule "libraries/include/stb"] [submodule "libraries/include/stb"]
path = libraries/include/stb path = libraries/include/stb
url = https://github.com/nothings/stb url = https://github.com/nothings/stb
[submodule "libraries/include/glm"] [submodule "libraries/stb"]
path = libraries/include/glm path = libraries/stb
url = https://github.com/nothings/stb
[submodule "libraries/glm"]
path = libraries/glm
url = https://github.com/g-truc/glm url = https://github.com/g-truc/glm

3
.idea/vcs.xml generated
View File

@@ -2,6 +2,7 @@
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/libraries/include/glm" vcs="Git" /> <mapping directory="$PROJECT_DIR$/libraries/glm" vcs="Git" />
<mapping directory="$PROJECT_DIR$/libraries/stb" vcs="Git" />
</component> </component>
</project> </project>

View File

@@ -11,13 +11,13 @@ add_executable(z3d main.cpp
include/assets/components/material_components.hpp include/assets/components/material_components.hpp
include/assets/components/point_cloud_vertex_components.hpp include/assets/components/point_cloud_vertex_components.hpp
include/assets/components/mesh_vertex_components.hpp include/assets/components/mesh_vertex_components.hpp
include/assets/dynamic_read_buffers/dynamic_material_buffer.hpp include/assets/data/material_data.hpp
include/assets/dynamic_read_buffers/dynamic_mesh_buffer.hpp include/assets/data/mesh_data.hpp
include/assets/dynamic_read_buffers/dynamic_point_cloud_buffer.hpp include/assets/data/point_cloud_data.hpp
include/assets/data_loaders/kitti_loader.hpp include/assets/file_parsers/kitti_loader.hpp
include/assets/data_loaders/obj_loader.hpp include/assets/file_parsers/obj_loader.hpp
include/assets/data_loaders/stl_loader.hpp include/assets/file_parsers/stl_loader.hpp
include/assets/data_loaders/uos_loader.hpp include/assets/file_parsers/uos_loader.hpp
include/assets/components/mesh_vertex_components.hpp include/assets/components/mesh_vertex_components.hpp
include/scene/camera.hpp include/scene/camera.hpp
include/scene/flying_camera.hpp include/scene/flying_camera.hpp
@@ -42,8 +42,8 @@ add_executable(z3d main.cpp
include/util/string_indexer.hpp include/util/string_indexer.hpp
include/util/string_literal.hpp include/util/string_literal.hpp
include/util/uix.hpp include/util/uix.hpp
source/assets/data_loaders/stl_loader.cpp source/assets/file_parsers/stl_loader.cpp
source/assets/data_loaders/obj_loader.cpp source/assets/file_parsers/obj_loader.cpp
source/scene/flying_camera.cpp source/scene/flying_camera.cpp
source/opengl/data/point_cloud_data.cpp source/opengl/data/point_cloud_data.cpp
source/opengl/handles/shader_program_handle.ipp source/opengl/handles/shader_program_handle.ipp
@@ -62,18 +62,18 @@ add_executable(z3d main.cpp
include/opengl/shader_program_variable.hpp include/opengl/shader_program_variable.hpp
include/opengl/type_utils.hpp include/opengl/type_utils.hpp
include/util/binary_ifstream.hpp include/util/binary_ifstream.hpp
source/assets/data_loaders/kitti_loader.cpp source/assets/file_parsers/kitti_loader.cpp
include/assets/data_loaders/generic/generic_3dtk_loader.hpp include/assets/file_parsers/generic/generic_3dtk_loader.hpp
include/assets/data_loaders/uosr_loader.hpp include/assets/file_parsers/uosr_loader.hpp
include/assets/data_loaders/uos_normal_loader.hpp include/assets/file_parsers/uos_normal_loader.hpp
include/assets/data_loaders/uos_rgb_loader.hpp include/assets/file_parsers/uos_rgb_loader.hpp
include/assets/dynamic_data_loaders/dynamic_mesh_loader.hpp include/assets/data_loaders/mesh_loader.hpp
source/assets/dynamic_data_loaders/dynamic_mesh_loader.cpp source/assets/data_loaders/mesh_loader.cpp
source/assets/dynamic_data_loaders/dynamic_mesh_loader.cpp source/assets/data_loaders/mesh_loader.cpp
include/assets/dynamic_data_loaders/dynamic_point_cloud_loader.hpp include/assets/data_loaders/point_cloud_loader.hpp
include/assets/dynamic_data_loaders/generic/base_dynamic_loader.hpp include/assets/data_loaders/generic/base_dynamic_loader.hpp
source/assets/dynamic_data_loaders/generic/base_dynamic_loader.ipp source/assets/data_loaders/generic/base_dynamic_loader.ipp
source/assets/dynamic_data_loaders/dynamic_point_cloud_loader.cpp source/assets/data_loaders/point_cloud_loader.cpp
include/opengl/handles/matrix_handles.hpp include/opengl/handles/matrix_handles.hpp
include/viewer/instance.hpp include/viewer/instance.hpp
include/opengl/data/material_data.hpp include/opengl/data/material_data.hpp
@@ -86,9 +86,9 @@ add_executable(z3d main.cpp
source/viewer/instance.cpp source/viewer/instance.cpp
include/viewer/asset_loader.hpp include/viewer/asset_loader.hpp
source/viewer/asset_loader.cpp source/viewer/asset_loader.cpp
include/assets/data_loaders/glsl_loader.hpp include/assets/file_parsers/glsl_loader.hpp
include/assets/dynamic_read_buffers/dynamic_shader_buffer.hpp include/assets/data/shader_source_data.hpp
source/assets/data_loaders/glsl_loader.cpp source/assets/file_parsers/glsl_loader.cpp
include/viewer/settings.hpp include/viewer/settings.hpp
include/opengl/data/shader_data.hpp include/opengl/data/shader_data.hpp
source/opengl/data/shader_data.ipp source/opengl/data/shader_data.ipp
@@ -122,58 +122,49 @@ add_executable(z3d main.cpp
include/geometry/normal_estimation.hpp include/geometry/normal_estimation.hpp
include/assets/components/texture_components.hpp include/assets/components/texture_components.hpp
include/util/enum_bitfield_operators.hpp include/util/enum_bitfield_operators.hpp
include/assets/dynamic_read_buffers/dynamic_texture_buffer.hpp include/assets/data/texture_data.hpp
source/assets/dynamic_read_buffers/dynamic_mesh_buffer.ipp source/assets/data/mesh_data.ipp
source/assets/dynamic_read_buffers/dynamic_material_buffer.ipp source/assets/data/material_data.ipp
include/assets/dynamic_read_buffers/generic/dynamic_vertex_buffer.hpp include/assets/data/generic/vertex_array_data.hpp
source/assets/dynamic_read_buffers/dynamic_model_buffer.ipp source/assets/data/texture_data.ipp
source/assets/dynamic_read_buffers/dynamic_texture_buffer.ipp source/assets/data/point_cloud_data.ipp
source/assets/dynamic_read_buffers/dynamic_point_cloud_buffer.ipp include/assets/file_parsers/mtl_loader.hpp
include/assets/data_loaders/mtl_loader.hpp include/assets/data_loaders/material_loader.hpp
include/assets/dynamic_data_loaders/dynamic_material_loader.hpp
include/util/id_type.hpp include/util/id_type.hpp
include/assets/dynamic_data_stores/generic/generic_dynamic_store.hpp include/assets/data_stores/generic/generic_basic_store.hpp
source/assets/dynamic_data_stores/generic/generic_dynamic_store.ipp source/assets/data_stores/generic/generic_basic_store.ipp
include/assets/dynamic_data_stores/dynamic_material_store.hpp include/assets/data_stores/material_store.hpp
include/assets/dynamic_data_stores/dynamic_mesh_store.hpp include/assets/data_stores/mesh_store.hpp
include/assets/dynamic_data_stores/dynamic_point_cloud_store.hpp include/assets/data_stores/point_cloud_store.hpp
include/util/result.hpp include/util/result.hpp
source/assets/data_loaders/mtl_loader.cpp source/assets/file_parsers/mtl_loader.cpp
include/util/line_parser.hpp include/util/line_parser.hpp
include/assets/dynamic_data_loaders/dynamic_texture_loader.hpp include/assets/data_loaders/texture_loader.hpp
source/assets/dynamic_data_loaders/dynamic_texture_loader.cpp source/assets/data_loaders/texture_loader.cpp
include/assets/dynamic_data_stores/dynamic_texture_store.hpp include/assets/data_stores/texture_store.hpp
include/opengl/data_managers/texture_manager.hpp include/opengl/data_managers/texture_manager.hpp
include/assets/dynamic_data_stores/dynamic_vertex_store.hpp
include/assets/prefetch_lookups/mesh_prefetch_lookup.hpp include/assets/prefetch_lookups/mesh_prefetch_lookup.hpp
include/assets/prefetch_lookups/point_cloud_prefetch_lookup.hpp include/assets/prefetch_lookups/point_cloud_prefetch_lookup.hpp
include/assets/prefetch_lookups/material_prefetch_lookup.hpp include/assets/prefetch_lookups/material_prefetch_lookup.hpp
include/assets/prefetch_lookups/texture_prefetch_lookup.hpp include/assets/prefetch_lookups/texture_prefetch_lookup.hpp
include/assets/prefetch_lookups/pose_prefetch_lookup.hpp include/assets/prefetch_lookups/pose_prefetch_lookup.hpp
include/assets/dynamic_data_stores/dynamic_pose_store.hpp include/assets/data_stores/pose_store.hpp
include/assets/data_loaders/kitti_pose_loader.hpp include/assets/file_parsers/kitti_pose_loader.hpp
include/assets/data_loaders/threedtk_pose_loader.hpp include/assets/file_parsers/threedtk_pose_loader.hpp
source/assets/data_loaders/threedtk_pose_loader.cpp source/assets/file_parsers/threedtk_pose_loader.cpp
include/assets/dynamic_read_buffers/dynamic_pose_buffer.hpp include/assets/data/pose_data.hpp
source/assets/data_loaders/kitti_pose_loader.cpp source/assets/file_parsers/kitti_pose_loader.cpp
include/assets/prefetch_queue.hpp include/assets/prefetch_queue.hpp
include/util/string_list.hpp include/util/string_list.hpp
include/assets/dynamic_data_stores/dynamic_material_library_store.hpp include/assets/data_stores/material_library_store.hpp
include/assets/dynamic_data_stores/generic/generic_dynamic_component_store.hpp source/assets/data_stores/generic/generic_dynamic_component_array_store.ipp
source/assets/dynamic_data_stores/generic/generic_dynamic_component_store.ipp include/assets/data/material_library_data.hpp
source/assets/dynamic_data_stores/dynamic_material_store.cpp include/assets/data_loaders/material_library_loader.hpp
include/assets/dynamic_data_stores/generic/generic_dynamic_component_array_store.hpp
source/assets/dynamic_data_stores/generic/generic_dynamic_component_array_store.ipp
source/assets/dynamic_data_stores/dynamic_mesh_store.cpp
include/assets/dynamic_data_stores/generic/generic_dynamic_indexed_component_array_store.hpp
source/assets/dynamic_data_stores/dynamic_point_cloud_store.cpp
include/assets/dynamic_read_buffers/dynamic_material_library_buffer.hpp
include/assets/dynamic_data_loaders/dynamic_material_library_loader.hpp
include/assets/prefetch_lookups/material_library_prefetch_lookup.hpp include/assets/prefetch_lookups/material_library_prefetch_lookup.hpp
include/assets/prefetch_lookups/shader_prefetch_lookup.hpp include/assets/prefetch_lookups/shader_prefetch_lookup.hpp
include/assets/dynamic_data_stores/dynamic_shader_source_store.hpp include/assets/data_stores/shader_source_store.hpp
include/assets/data_loaders/generic/generic_3dtk_loader.hpp include/assets/file_parsers/generic/generic_3dtk_loader.hpp
source/assets/data_loaders/generic/generic_3dtk_loader.ipp source/assets/file_parsers/generic/generic_3dtk_loader.ipp
include/assets/prefetch_lookup.hpp include/assets/prefetch_lookup.hpp
source/assets/prefetch_lookups/pose_prefetch_lookup.cpp source/assets/prefetch_lookups/pose_prefetch_lookup.cpp
include/assets/dynamic_data_store.hpp include/assets/dynamic_data_store.hpp
@@ -202,7 +193,6 @@ add_executable(z3d main.cpp
include/util/reference_counter.hpp include/util/reference_counter.hpp
include/opengl/resource_management/resource_manager.hpp include/opengl/resource_management/resource_manager.hpp
source/opengl/resource_management/resource_manager.ipp source/opengl/resource_management/resource_manager.ipp
include/opengl/data_managers/buffer_manager.hpp
include/opengl/data_managers/shader_manager.hpp include/opengl/data_managers/shader_manager.hpp
include/opengl/data_managers/mesh_vertex_buffer_manager.hpp include/opengl/data_managers/mesh_vertex_buffer_manager.hpp
source/opengl/data_managers/mesh_vertex_buffer_manager.cpp source/opengl/data_managers/mesh_vertex_buffer_manager.cpp
@@ -215,13 +205,32 @@ add_executable(z3d main.cpp
include/opengl/handles/index_buffer_handle.hpp include/opengl/handles/index_buffer_handle.hpp
source/opengl/handles/index_buffer_handle.ipp source/opengl/handles/index_buffer_handle.ipp
include/opengl/metadata/texture_metadata.hpp include/opengl/metadata/texture_metadata.hpp
include/opengl/metadata/vertex_buffer_metadata.hpp include/opengl/vertex_buffer_utils.hpp
include/opengl/data_managers/mesh_index_buffer_manager.hpp
include/opengl/metadata/index_buffer_metadata.hpp
source/opengl/data_managers/mesh_index_buffer_manager.cpp
include/opengl/data_managers/point_cloud_vertex_buffer_manager.hpp
source/opengl/data_managers/point_cloud_vertex_buffer_manager.cpp
include/assets/data_views/mesh_view.hpp
include/assets/data_views/point_cloud_view.hpp
include/assets/data_views/shader_source_view.hpp
include/assets/data_stores/generic/generic_mesh_store.hpp
source/assets/data_stores/generic/generic_mesh_store.ipp
include/assets/data_stores/generic/generic_point_cloud_store.hpp
source/assets/data_stores/generic/generic_point_cloud_store.ipp
include/assets/data_views/material_view.hpp
include/assets/data_views/texture_view.hpp
include/assets/data_stores/generic/generic_material_store.hpp
source/assets/data_stores/generic/generic_material_store.ipp
source/assets/data_stores/shader_source_store.ipp
include/opengl/metadata/mesh_vertex_buffer_metadata.hpp
include/opengl/metadata/point_cloud_vertex_buffer_metadata.hpp
) )
target_include_directories(z3d PRIVATE include) target_include_directories(z3d PRIVATE include)
target_include_directories(z3d PRIVATE source) # for ipp headers target_include_directories(z3d PRIVATE source) # for ipp headers
target_include_directories(z3d PRIVATE libraries/include/glm)
target_include_directories(z3d PRIVATE libraries/include/stb) add_subdirectory(libraries)
find_package(GLEW REQUIRED) find_package(GLEW REQUIRED)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)

View File

@@ -1,20 +1,21 @@
#pragma once #pragma once
#include <tuple> #include <tuple>
#include "../dynamic_read_buffers"
#include "assets/data_stores/texture_store.hpp"
#include "assets/data/surface_properties.hpp" #include "assets/data/surface_properties.hpp"
#include "util/enum_bitfield_operators.hpp" #include "util/enum_bitfield_operators.hpp"
namespace components::material namespace assets::material_components
{ {
using surface_properties = ::surface_properties; using surface_properties = surface_properties;
using transparency = float; using transparency = float;
using ambient_color_texture = ::dynamic_texture_data; using ambient_color_texture = texture_store::id_type;
using diffuse_color_texture = ::dynamic_texture_data; using diffuse_color_texture = texture_store::id_type;
using specular_color_texture = ::dynamic_texture_data; using specular_color_texture = texture_store::id_type;
using shininess_texture = ::dynamic_texture_data; using shininess_texture = texture_store::id_type;
using alpha_texture = ::dynamic_texture_data; using alpha_texture = texture_store::id_type;
using bump_texture = ::dynamic_texture_data; using bump_texture = texture_store::id_type;
namespace indices namespace indices
{ {
@@ -56,4 +57,4 @@ constexpr inline auto count = std::tuple_size_v<all>;
} // namespace material_component } // namespace material_component
DEFINE_ENUM_BITFIELD_OPERATORS(components::material::flags) DEFINE_ENUM_BITFIELD_OPERATORS(assets::material_components::flags)

View File

@@ -4,7 +4,8 @@
#include <tuple> #include <tuple>
#include "util/enum_bitfield_operators.hpp" #include "util/enum_bitfield_operators.hpp"
namespace components::mesh_vertex { namespace assets::mesh_vertex_components
{
using position = std::array<float, 3>; using position = std::array<float, 3>;
using normal = std::array<float, 3>; using normal = std::array<float, 3>;
@@ -35,6 +36,6 @@ enum class flags : std::uint8_t
using all = std::tuple<position, normal, tex_coord, color, reflectance>; using all = std::tuple<position, normal, tex_coord, color, reflectance>;
constexpr inline auto count = std::tuple_size_v<all>; constexpr inline auto count = std::tuple_size_v<all>;
} // namespace components::mesh_vertex } // namespace mesh_vertex_components
DEFINE_ENUM_BITFIELD_OPERATORS(components::mesh_vertex::flags) DEFINE_ENUM_BITFIELD_OPERATORS(assets::mesh_vertex_components::flags)

View File

@@ -4,7 +4,8 @@
#include <tuple> #include <tuple>
#include "util/enum_bitfield_operators.hpp" #include "util/enum_bitfield_operators.hpp"
namespace components::point_cloud_vertex { namespace assets::point_cloud_vertex_components
{
using position = std::array<float, 3>; using position = std::array<float, 3>;
using normal = std::array<float, 3>; using normal = std::array<float, 3>;
@@ -32,6 +33,6 @@ enum class flags : std::uint8_t
using all = std::tuple<position, normal, color, reflectance>; using all = std::tuple<position, normal, color, reflectance>;
constexpr inline auto count = std::tuple_size_v<all>; constexpr inline auto count = std::tuple_size_v<all>;
} // namespace components::point_cloud_vertex } // namespace point_cloud_vertex_components
DEFINE_ENUM_BITFIELD_OPERATORS(components::point_cloud_vertex::flags) DEFINE_ENUM_BITFIELD_OPERATORS(assets::point_cloud_vertex_components::flags)

View File

@@ -4,7 +4,8 @@
#include <cinttypes> #include <cinttypes>
#include "util/enum_bitfield_operators.hpp" #include "util/enum_bitfield_operators.hpp"
namespace components::texture { namespace assets::texture_components
{
using red = std::uint8_t; using red = std::uint8_t;
using green = std::uint8_t; using green = std::uint8_t;
@@ -24,6 +25,6 @@ enum class flags : std::uint8_t
using all = std::tuple<red, green, blue, luminance>; using all = std::tuple<red, green, blue, luminance>;
constexpr inline auto count = std::tuple_size_v<all>; constexpr inline auto count = std::tuple_size_v<all>;
} // namespace components::texture } // namespace texture_components
DEFINE_ENUM_BITFIELD_OPERATORS(components::texture::flags) DEFINE_ENUM_BITFIELD_OPERATORS(assets::texture_components::flags)

View File

@@ -1,16 +1,15 @@
#pragma once #pragma once
#include "util/uix.hpp"
#include <array>
#include <vector> #include <vector>
#include "GL/glew.h"
template<typename C, typename... Ts> template<typename C, typename... Ts>
struct dynamic_vertex_buffer { struct vertex_array_data
{
C component_flags;
std::tuple<std::vector<Ts>...> vertices{}; std::tuple<std::vector<Ts>...> vertices{};
protected: protected:
inline void clear_vertices() void clear_vertices()
{ {
std::apply( std::apply(
[](auto&... vertex_opt) { [](auto&... vertex_opt) {

View File

@@ -0,0 +1,56 @@
#pragma once
#include <optional>
#include "assets/components/material_components.hpp"
#include "assets/data_stores/texture_store.hpp"
namespace assets
{
struct material_data
{
material_data() = default;
material_components::surface_properties& initialized_surface_properties();
[[nodiscard]] inline std::optional<material_components::surface_properties>& surface_properties();
[[nodiscard]] inline std::optional<material_components::transparency>& transparency();
[[nodiscard]] inline std::optional<material_components::ambient_color_texture>& ambient_color_texture_id();
[[nodiscard]] inline std::optional<material_components::diffuse_color_texture>& diffuse_color_texture_id();
[[nodiscard]] inline std::optional<material_components::specular_color_texture>& specular_color_texture_id();
[[nodiscard]] inline std::optional<material_components::shininess_texture>& shininess_texture_id();
[[nodiscard]] inline std::optional<material_components::alpha_texture>& alpha_texture_id();
[[nodiscard]] inline std::optional<material_components::bump_texture>& bump_texture_id();
[[nodiscard]] inline const std::optional<material_components::surface_properties>& surface_properties() const;
[[nodiscard]] inline const std::optional<material_components::transparency>& transparency() const;
[[nodiscard]] inline const std::optional<material_components::ambient_color_texture>& ambient_color_texture_id() const;
[[nodiscard]] inline const std::optional<material_components::diffuse_color_texture>& diffuse_color_texture_id() const;
[[nodiscard]] inline const std::optional<material_components::specular_color_texture>& specular_color_texture_id() const;
[[nodiscard]] inline const std::optional<material_components::shininess_texture>& shininess_texture_id() const;
[[nodiscard]] inline const std::optional<material_components::alpha_texture>& alpha_texture_id() const;
[[nodiscard]] inline const std::optional<material_components::bump_texture>& bump_texture_id() const;
inline void clear();
std::tuple<
std::optional<material_components::surface_properties>,
std::optional<material_components::transparency>,
std::optional<material_components::ambient_color_texture>,
std::optional<material_components::diffuse_color_texture>,
std::optional<material_components::specular_color_texture>,
std::optional<material_components::shininess_texture>,
std::optional<material_components::alpha_texture>,
std::optional<material_components::bump_texture>
> data{
std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt
};
};
}
#define INCLUDE_DYNAMIC_MATERIAL_DATA_IMPLEMENTATION
#include "assets/data/material_data.ipp"
#undef INCLUDE_DYNAMIC_MATERIAL_DATA_IMPLEMENTATION

View File

@@ -0,0 +1,11 @@
#pragma once
#include "util/string_lookup.hpp"
#include "assets/data_stores/material_store.hpp"
namespace assets
{
using material_library_data = ztu::string_lookup<material_store::id_type>;
}

View File

@@ -0,0 +1,53 @@
#pragma once
#include <array>
#include <vector>
#include "util/uix.hpp"
#include "assets/components/mesh_vertex_components.hpp"
#include "generic/vertex_array_data.hpp"
#include "assets/data_stores/material_store.hpp"
namespace assets
{
class mesh_data : public vertex_array_data<
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
> {
public:
using index_type = ztu::u32;
using triangle_type = std::array<index_type, 3>;
[[nodiscard]] inline std::vector<mesh_vertex_components::position>& positions();
[[nodiscard]] inline std::vector<mesh_vertex_components::normal>& normals();
[[nodiscard]] inline std::vector<mesh_vertex_components::tex_coord>& tex_coords();
[[nodiscard]] inline std::vector<mesh_vertex_components::color>& colors();
[[nodiscard]] inline std::vector<mesh_vertex_components::reflectance>& reflectances();
[[nodiscard]] inline std::vector<triangle_type>& triangles();
[[nodiscard]] inline auto& material_id();
[[nodiscard]] inline const std::vector<mesh_vertex_components::position>& positions() const;
[[nodiscard]] inline const std::vector<mesh_vertex_components::normal>& normals() const;
[[nodiscard]] inline const std::vector<mesh_vertex_components::tex_coord>& tex_coords() const;
[[nodiscard]] inline const std::vector<mesh_vertex_components::color>& colors() const;
[[nodiscard]] inline const std::vector<mesh_vertex_components::reflectance>& reflectances() const;
[[nodiscard]] inline const std::vector<triangle_type>& triangles() const;
[[nodiscard]] inline const auto& material_id() const;
inline void clear();
private:
std::vector<triangle_type> m_triangles{};
material_store::id_type m_material_id{};
};
}
#define INCLUDE_DYNAMIC_MESH_DATA_IMPLEMENTATION
#include "assets/data/mesh_data.ipp"
#undef INCLUDE_DYNAMIC_MESH_DATA_IMPLEMENTATION

View File

@@ -0,0 +1,37 @@
#pragma once
#include "assets/components/point_cloud_vertex_components.hpp"
#include <array>
#include <vector>
#include "generic/vertex_array_data.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
> {
public:
[[nodiscard]] inline std::vector<point_cloud_vertex_components::position>& positions();
[[nodiscard]] inline std::vector<point_cloud_vertex_components::normal>& normals();
[[nodiscard]] inline std::vector<point_cloud_vertex_components::color>& colors();
[[nodiscard]] inline std::vector<point_cloud_vertex_components::reflectance>& reflectances();
[[nodiscard]] inline const std::vector<point_cloud_vertex_components::position>& positions() const;
[[nodiscard]] inline const std::vector<point_cloud_vertex_components::normal>& normals() const;
[[nodiscard]] inline const std::vector<point_cloud_vertex_components::color>& colors() const;
[[nodiscard]] inline const std::vector<point_cloud_vertex_components::reflectance>& reflectances() const;
inline void clear();
};
}
#define INCLUDE_DYNAMIC_TEXTURE_DATA_IMPLEMENTATION
#include "assets/data/point_cloud_data.ipp"
#undef INCLUDE_DYNAMIC_TEXTURE_DATA_IMPLEMENTATION

View File

@@ -0,0 +1,10 @@
#pragma once
#include "glm/mat4x4.hpp"
namespace assets
{
using pose_data = glm::mat4;
}

View File

@@ -0,0 +1,18 @@
#pragma once
#include <vector>
namespace assets
{
struct shader_source_data
{
std::vector<char> source{};
void clear()
{
source.clear();
}
};
}

View File

@@ -2,10 +2,15 @@
#include <array> #include <array>
namespace assets
{
struct surface_properties struct surface_properties
{ {
std::array<float, 3> ambient_filter{ 0.7f, 0.7f, 0.7f }; std::array<float, 3> ambient_filter{ 0.7f, 0.7f, 0.7f };
std::array<float, 3> diffuse_filter{ 0.466f, 0.466f, 0.7922f }; std::array<float, 3> diffuse_filter{ 0.466f, 0.466f, 0.7922f };
std::array<float, 3> specular_filter{ 0.5974f, 0.2084f, 0.2084f }; std::array<float, 3> specular_filter{ 0.5974f, 0.2084f, 0.2084f };
float shininess{ 100.2237f }; float shininess{ 100.2237f };
}; };
}

View File

@@ -6,7 +6,11 @@
#include <algorithm> #include <algorithm>
#include "assets/components/texture_components.hpp" #include "assets/components/texture_components.hpp"
class dynamic_texture_buffer { namespace assets
{
class texture_data
{
public: public:
using value_type = std::uint8_t; using value_type = std::uint8_t;
using dim_type = std::int32_t; using dim_type = std::int32_t;
@@ -19,24 +23,24 @@ public:
using iterator = pointer; using iterator = pointer;
using const_iterator = const_pointer; using const_iterator = const_pointer;
dynamic_texture_buffer() = default; texture_data() = default;
inline dynamic_texture_buffer( inline texture_data(
std::unique_ptr<value_type>&& data, std::unique_ptr<value_type[]>&& data,
dim_type width, dim_type width,
dim_type height, dim_type height,
components::texture::flags components texture_components::flags components
);; );;
inline dynamic_texture_buffer(const dynamic_texture_buffer&); inline texture_data(const texture_data&);
inline dynamic_texture_buffer(dynamic_texture_buffer&&) noexcept; inline texture_data(texture_data&&) noexcept;
[[nodiscard]] inline dynamic_texture_buffer& operator=(const dynamic_texture_buffer&); [[nodiscard]] inline texture_data& operator=(const texture_data&);
[[nodiscard]] inline dynamic_texture_buffer& operator=(dynamic_texture_buffer&&) noexcept; [[nodiscard]] inline texture_data& operator=(texture_data&&) noexcept;
[[nodiscard]] inline components::texture::flags components() const; [[nodiscard]] inline texture_components::flags components() const;
[[nodiscard]] inline dim_type width() const; [[nodiscard]] inline dim_type width() const;
@@ -71,9 +75,11 @@ public:
private: private:
std::unique_ptr<value_type[]> m_data{ nullptr }; std::unique_ptr<value_type[]> m_data{ nullptr };
dim_type m_width{ 0 }, m_height{ 0 }; dim_type m_width{ 0 }, m_height{ 0 };
components::texture::flags m_components{ components::texture::flags::none }; texture_components::flags m_components{ texture_components::flags::none };
}; };
}
#define INCLUDE_DYNAMIC_TEXTURE_DATA_IMPLEMENTATION #define INCLUDE_DYNAMIC_TEXTURE_DATA_IMPLEMENTATION
#include "assets/dynamic_read_buffers/dynamic_texture_buffer.ipp" #include "assets/data/texture_data.ipp"
#undef INCLUDE_DYNAMIC_TEXTURE_DATA_IMPLEMENTATION #undef INCLUDE_DYNAMIC_TEXTURE_DATA_IMPLEMENTATION

View File

@@ -3,12 +3,14 @@
#include <optional> #include <optional>
#include <tuple> #include <tuple>
#include "assets/dynamic_data_stores/dynamic_point_cloud_store.hpp" #include "../../data_stores"
#include "util/uix.hpp" #include "util/uix.hpp"
#include "util/string_lookup.hpp" #include "util/string_lookup.hpp"
#include "util/id_type.hpp" #include "util/id_type.hpp"
#include "util/result.hpp" #include "util/result.hpp"
template<typename C, class... Loaders> template<typename C, class... Loaders>
class base_dynamic_loader class base_dynamic_loader
{ {
@@ -26,6 +28,7 @@ public:
protected: protected:
// TODO this seems like I modified this to something that does not make sense
template<typename F> template<typename F>
ztu::result<dynamic_point_cloud_store::id_type> invoke_with_matching_loader(loader_id_type loader_id, F&& f); ztu::result<dynamic_point_cloud_store::id_type> invoke_with_matching_loader(loader_id_type loader_id, F&& f);
@@ -35,5 +38,5 @@ protected:
}; };
#define INCLUDE_BASE_DYNAMIC_LOADER_IMPLEMENTATION #define INCLUDE_BASE_DYNAMIC_LOADER_IMPLEMENTATION
#include "assets/dynamic_data_loaders/generic/base_dynamic_loader.ipp" #include "../../data_loaders"
#undef INCLUDE_BASE_DYNAMIC_LOADER_IMPLEMENTATION #undef INCLUDE_BASE_DYNAMIC_LOADER_IMPLEMENTATION

View File

@@ -2,16 +2,21 @@
#include "assets/prefetch_queue.hpp" #include "assets/prefetch_queue.hpp"
#include "assets/components/material_components.hpp" #include "assets/components/material_components.hpp"
#include "assets/dynamic_read_buffers/dynamic_material_library_buffer.hpp" #include "assets/data/material_library_data.hpp"
#include "assets/dynamic_data_stores/dynamic_material_library_store.hpp" #include "assets/data_stores/material_store.hpp"
#include "assets/prefetch_lookups/material_library_prefetch_lookup.hpp" #include "assets/prefetch_lookups/material_library_prefetch_lookup.hpp"
#include "generic/base_dynamic_loader.hpp" #include "generic/base_dynamic_loader.hpp"
#include "assets/data_loaders/mtl_loader.hpp"
#include "util/string_list.hpp" #include "util/string_list.hpp"
class dynamic_material_library_loader : public base_dynamic_loader< #include "assets/file_parsers/mtl_loader.hpp"
components::material::flags,
// TODO not implemented?!?
namespace assets
{
class material_library_loader : public base_dynamic_loader<
material_components::flags,
mtl_loader mtl_loader
> { > {
public: public:
@@ -25,12 +30,14 @@ public:
[[nodiscard]] std::error_code load( [[nodiscard]] std::error_code load(
loader_id_type loader_id, loader_id_type loader_id,
const ztu::string_list& directories, const ztu::string_list& directories,
dynamic_material_library_store& store, material_library_store& store,
dynamic_material_store& material_store, material_store& material_store,
material_library_prefetch_lookup& id_lookup, material_library_prefetch_lookup& id_lookup,
bool pedantic = false bool pedantic = false
); );
private: private:
dynamic_material_library_buffer m_buffer{}; material_library_data m_buffer{};
}; };
}

View File

@@ -4,14 +4,17 @@
#include "assets/components/material_components.hpp" #include "assets/components/material_components.hpp"
#include "generic/base_dynamic_loader.hpp" #include "generic/base_dynamic_loader.hpp"
#include "assets/data_loaders/mtl_loader.hpp" #include "assets/data_stores/material_store.hpp"
#include "assets/dynamic_data_stores/dynamic_material_store.hpp" #include "assets/data/material_data.hpp"
#include "assets/prefetch_lookups/material_prefetch_lookup.hpp" #include "assets/prefetch_lookups/material_prefetch_lookup.hpp"
#include "util/string_list.hpp" #include "util/string_list.hpp"
class dynamic_material_loader : public base_dynamic_loader< namespace assets
components::material::flags {
// TODO no loaders
class material_loader : public base_dynamic_loader<
material_components::flags
// TODO no loaders (mtl is for material libraries)
> { > {
public: public:
@@ -24,11 +27,13 @@ public:
[[nodiscard]] std::error_code load( [[nodiscard]] std::error_code load(
loader_id_type loader_id, loader_id_type loader_id,
const ztu::string_list& directories, const ztu::string_list& directories,
dynamic_material_store& store, material_store& store,
material_prefetch_lookup& id_lookup, material_prefetch_lookup& id_lookup,
bool pedantic = false bool pedantic = false
); );
private: private:
dynamic_material_buffer m_buffer{}; material_data m_buffer{};
}; };
}

View File

@@ -3,15 +3,17 @@
#include "generic/base_dynamic_loader.hpp" #include "generic/base_dynamic_loader.hpp"
#include <filesystem> #include <filesystem>
#include "assets/dynamic_read_buffers/dynamic_mesh_buffer.hpp" #include "assets/data/mesh_data.hpp"
#include "assets/dynamic_data_stores/dynamic_mesh_store.hpp" #include "assets/data_stores/mesh_store.hpp"
#include "assets/data_loaders/obj_loader.hpp" #include "assets/file_parsers/obj_loader.hpp"
#include "assets/data_loaders/stl_loader.hpp" #include "assets/file_parsers/stl_loader.hpp"
#include "assets/prefetch_lookups/mesh_prefetch_lookup.hpp" #include "assets/prefetch_lookups/mesh_prefetch_lookup.hpp"
namespace assets
{
class dynamic_mesh_loader : public base_dynamic_loader< class mesh_loader : public base_dynamic_loader<
components::mesh_vertex::flags, mesh_vertex_components::flags,
obj_loader, obj_loader,
stl_loader stl_loader
> { > {
@@ -25,11 +27,13 @@ public:
[[nodiscard]] std::error_code load( [[nodiscard]] std::error_code load(
loader_id_type loader_id, loader_id_type loader_id,
const ztu::string_list& directories, const ztu::string_list& directories,
dynamic_mesh_store& store, mesh_store& store,
mesh_prefetch_lookup& id_lookup, mesh_prefetch_lookup& id_lookup,
bool pedantic = false bool pedantic = false
); );
private: private:
dynamic_mesh_buffer m_buffer{}; mesh_data m_buffer{};
}; };
}

View File

@@ -5,20 +5,22 @@
#include "assets/prefetch_queue.hpp" #include "assets/prefetch_queue.hpp"
#include "generic/base_dynamic_loader.hpp" #include "generic/base_dynamic_loader.hpp"
#include "assets/dynamic_read_buffers/dynamic_point_cloud_buffer.hpp" #include "assets/data/point_cloud_data.hpp"
#include "assets/dynamic_data_stores/dynamic_point_cloud_store.hpp" #include "assets/data_stores/point_cloud_store.hpp"
#include "assets/data_loaders/kitti_loader.hpp"
#include "assets/data_loaders/uos_loader.hpp"
#include "assets/data_loaders/uos_normal_loader.hpp"
#include "assets/data_loaders/uos_rgb_loader.hpp"
#include "assets/data_loaders/uosr_loader.hpp"
#include "assets/prefetch_lookups/point_cloud_prefetch_lookup.hpp" #include "assets/prefetch_lookups/point_cloud_prefetch_lookup.hpp"
#include "util/string_list.hpp" #include "util/string_list.hpp"
class dynamic_point_cloud_loader : public base_dynamic_loader< #include "assets/file_parsers/kitti_loader.hpp"
components::point_cloud_vertex::flags, #include "assets/file_parsers/uos_loader.hpp"
#include "assets/file_parsers/uos_normal_loader.hpp"
#include "assets/file_parsers/uos_rgb_loader.hpp"
#include "assets/file_parsers/uosr_loader.hpp"
namespace assets
{
class point_cloud_loader : public base_dynamic_loader<
point_cloud_vertex_components::flags,
kitti_loader, kitti_loader,
uos_loader, uos_loader,
uos_normal_loader, uos_normal_loader,
@@ -36,11 +38,13 @@ public:
[[nodiscard]] std::error_code load( [[nodiscard]] std::error_code load(
loader_id_type loader_id, loader_id_type loader_id,
const ztu::string_list& directories, const ztu::string_list& directories,
dynamic_point_cloud_store& store, point_cloud_store& store,
point_cloud_prefetch_lookup& id_lookup, point_cloud_prefetch_lookup& id_lookup,
bool pedantic = false bool pedantic = false
); );
private: private:
dynamic_point_cloud_buffer m_buffer{}; point_cloud_data m_buffer{};
}; };
}

View File

@@ -8,35 +8,22 @@
#include "util/result.hpp" #include "util/result.hpp"
#include "assets/components/texture_components.hpp" #include "assets/components/texture_components.hpp"
#include "assets/dynamic_read_buffers/dynamic_texture_buffer.hpp" #include "assets/data/texture_data.hpp"
#include "assets/dynamic_data_stores/dynamic_texture_store.hpp" #include "assets/data_stores/texture_store.hpp"
#include "assets/dynamic_data_loader_ctx.hpp" #include "assets/dynamic_data_store.hpp"
#include "assets/prefetch_queue.hpp" #include "assets/prefetch_queue.hpp"
#include "assets/prefetch_lookups/texture_prefetch_lookup.hpp" #include "assets/prefetch_lookups/texture_prefetch_lookup.hpp"
#include "util/string_list.hpp" #include "util/string_list.hpp"
/* namespace assets
* [[nodiscard]] std::error_code prefetch( {
loader_id_type loader_id,
const ztu::string_list& directories,
prefetch_queue& queue
);
[[nodiscard]] std::error_code load( class texture_loader
loader_id_type loader_id,
const ztu::string_list& directories,
dynamic_point_cloud_store& store,
point_cloud_prefetch_lookup& id_lookup,
bool pedantic = false
);
*/
class dynamic_texture_loader
{ {
public: public:
using loader_id_type = ztu::id_type_for<dynamic_texture_loader, ztu::u8>; using loader_id_type = ztu::id_type_for<texture_loader, ztu::u8>;
explicit dynamic_texture_loader(components::texture::flags enabled_components); explicit texture_loader(texture_components::flags enabled_components);
[[nodiscard]] std::optional<loader_id_type> find_loader(const std::string_view& name); [[nodiscard]] std::optional<loader_id_type> find_loader(const std::string_view& name);
@@ -49,12 +36,14 @@ public:
[[nodiscard]] std::error_code load( [[nodiscard]] std::error_code load(
loader_id_type loader_id, loader_id_type loader_id,
const ztu::string_list& directories, const ztu::string_list& directories,
dynamic_texture_store& store, texture_store& store,
texture_prefetch_lookup& id_lookup, texture_prefetch_lookup& id_lookup,
bool pedantic = false bool pedantic = false
); );
private: private:
ztu::string_lookup<loader_id_type> m_loader_id_lookup{}; ztu::string_lookup<loader_id_type> m_loader_id_lookup{};
components::texture::flags m_enabled_components{ components::texture::flags::none }; texture_components::flags m_enabled_components{ texture_components::flags::none };
}; };
}

View File

@@ -7,10 +7,10 @@
#include "util/id_type.hpp" #include "util/id_type.hpp"
template<typename T> template<typename T>
class generic_dynamic_store class generic_basic_store
{ {
public: public:
using id_type = ztu::id_type_for<generic_dynamic_store, ztu::u32>; using id_type = ztu::id_type_for<generic_basic_store, ztu::u32>;
using container_type = std::vector<T>; using container_type = std::vector<T>;
using iterator_type = typename container_type::iterator; using iterator_type = typename container_type::iterator;
using const_iterator = typename container_type::const_iterator; using const_iterator = typename container_type::const_iterator;
@@ -35,6 +35,6 @@ private:
id_type m_next_data_id{ 1 }; id_type m_next_data_id{ 1 };
}; };
#define INCLUDE_GENERIC_DYNAMIC_STORE_IMPLEMENTATION #define INCLUDE_GENERIC_BASIC_STORE_IMPLEMENTATION
#include "assets/dynamic_data_stores/generic_dynamic_store.ipp" #include "assets/data_stores/generic/generic_basic_store.ipp"
#undef INCLUDE_GENERIC_DYNAMIC_STORE_IMPLEMENTATION #undef INCLUDE_GENERIC_BASIC_STORE_IMPLEMENTATION

View 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

View 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

View 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

View File

@@ -0,0 +1,11 @@
#pragma once
#include "generic/generic_basic_store.hpp"
#include "assets/data/material_library_data.hpp"
namespace assets
{
using material_library_store = generic_basic_store<material_library_data>;
}

View File

@@ -0,0 +1,19 @@
#pragma once
#include "generic/generic_material_store.hpp"
namespace assets
{
using material_store = detail::generic_material_store<
material_components::surface_properties,
material_components::transparency,
texture_store::id_type,
texture_store::id_type,
texture_store::id_type,
texture_store::id_type,
texture_store::id_type,
texture_store::id_type
>;
}

View File

@@ -0,0 +1,16 @@
#pragma once
#include "generic/generic_mesh_store.hpp"
namespace assets
{
using mesh_store = detail::generic_mesh_store<
mesh_vertex_components::position,
mesh_vertex_components::normal,
mesh_vertex_components::tex_coord,
mesh_vertex_components::color,
mesh_vertex_components::reflectance
>;
}

View File

@@ -0,0 +1,17 @@
#pragma once
#pragma once
#include "generic/generic_point_cloud_store.hpp"
namespace assets
{
using point_cloud_store = detail::generic_point_cloud_store<
point_cloud_vertex_components::position,
point_cloud_vertex_components::normal,
point_cloud_vertex_components::color,
point_cloud_vertex_components::reflectance
>;
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include "generic/generic_basic_store.hpp"
#include "assets/data/pose_data.hpp"
namespace assets
{
using pose_store = generic_basic_store<pose_data>;
}

View File

@@ -0,0 +1,137 @@
#pragma once
#include "generic/generic_basic_store.hpp"
#include "assets/data/shader_source_data.hpp"
#include "assets/data_views/shader_source_view.hpp"
namespace assets
{
class shader_source_store;
template<typename Char>
class shader_source_store_iterator
{
public:
using size_type = std::size_t;
using length_type = ztu::u32;
using id_type = ztu::id_type_for<shader_source_store, ztu::u32>;
using value_type = std::pair<id_type, shader_source_view>;
using id_iterator_type = id_type const*;
using string_iterator_type = Char*;
using length_iterator_type = const length_type*;
using offset_type = size_type;
using difference_type = std::ptrdiff_t;
using pointer = value_type*;
using reference = value_type;
using iterator_category = std::random_access_iterator_tag;
private:
friend shader_source_store;
shader_source_store_iterator(
id_iterator_type ids,
string_iterator_type strings,
length_iterator_type lengths,
std::size_t index,
const offset_type& offset
);
public:
constexpr shader_source_store_iterator() noexcept = default;
constexpr shader_source_store_iterator(const shader_source_store_iterator&) noexcept = default;
constexpr shader_source_store_iterator(shader_source_store_iterator&&) noexcept = default;
constexpr shader_source_store_iterator& operator=(const shader_source_store_iterator&) noexcept = default;
constexpr shader_source_store_iterator& operator=(shader_source_store_iterator&&) noexcept = default;
reference operator*() const;
shader_source_store_iterator& operator++();
shader_source_store_iterator operator++(int);
shader_source_store_iterator& operator--();
shader_source_store_iterator operator--(int);
shader_source_store_iterator& operator+=(difference_type n);
shader_source_store_iterator& operator-=(difference_type n);
shader_source_store_iterator operator+(difference_type n) const;
shader_source_store_iterator operator-(difference_type n) const;
difference_type operator-(const shader_source_store_iterator& other) const;
reference operator[](difference_type n) const;
bool operator==(const shader_source_store_iterator& other) const;
bool operator!=(const shader_source_store_iterator& other) const;
bool operator<(const shader_source_store_iterator& other) const;
bool operator<=(const shader_source_store_iterator& other) const;
bool operator>(const shader_source_store_iterator& other) const;
bool operator>=(const shader_source_store_iterator& other) const;
protected:
void calc_offset(difference_type n);
reference dereference() const;
private:
id_iterator_type m_ids{};
string_iterator_type m_strings{};
length_iterator_type m_lengths{};
size_type m_index{};
offset_type m_offset{};
};
class shader_source_store
{
public:
using size_type = std::size_t;
using count_type = ztu::u32;
using iterator_type = shader_source_store_iterator<char>;
using const_iterator = shader_source_store_iterator<const char>;
using view_type = std::ranges::subrange<iterator_type>;
using const_view_type = std::ranges::subrange<const_iterator>;
using id_type = ztu::id_type_for<shader_source_store, ztu::u32>;
inline id_type add(const shader_source_data& shader_source);
[[nodiscard]] inline std::pair<iterator_type, bool> find(id_type id);
[[nodiscard]] inline std::pair<const_iterator, bool> find(id_type id) const;
inline void remove(const iterator_type& it);
inline void clear();
[[nodiscard]] inline iterator_type begin();
[[nodiscard]] inline iterator_type end();
[[nodiscard]] inline const_iterator begin() const;
[[nodiscard]] inline const_iterator end() const;
[[nodiscard]] inline const_iterator cbegin() const;
[[nodiscard]] inline const_iterator cend() const;
[[nodiscard]] inline view_type view();
[[nodiscard]] inline const_view_type view() const;
private:
std::vector<id_type> m_ids;
std::vector<char> m_strings;
std::vector<count_type> m_lengths;
id_type m_next_data_id{ 1 };
};
}
#define INCLUDE_SHADER_SOURCE_STORE_IMPLEMENTATION
#include "assets/data_stores/shader_source_store.ipp"
#undef INCLUDE_SHADER_SOURCE_STORE_IMPLEMENTATION

View File

@@ -0,0 +1,12 @@
#pragma once
#include "generic/generic_basic_store.hpp"
#include "assets/data/texture_data.hpp"
namespace assets
{
using texture_store = generic_basic_store<texture_data>;
}

View File

@@ -0,0 +1,10 @@
#pragma once
#include "assets/data/material_data.hpp"
namespace assets
{
using material_view = material_data;
}

View File

@@ -0,0 +1,33 @@
#pragma once
#include <span>
#include <tuple>
#include "assets/components/mesh_vertex_components.hpp"
#include "assets/data/mesh_data.hpp"
#include "assets/data_stores/material_store.hpp"
namespace assets
{
namespace detail
{
template<typename... Ts>
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;
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
>;
}

View File

@@ -0,0 +1,28 @@
#pragma once
#include <span>
#include <tuple>
#include "assets/components/point_cloud_vertex_components.hpp"
namespace assets
{
namespace detail
{
template<typename... Ts>
struct generic_point_cloud_view
{
point_cloud_vertex_components::flags vertex_components;
std::tuple<std::span<Ts>...> vertex_component_arrays;
};
}
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
>;
}

View File

@@ -0,0 +1,5 @@
#pragma once
#include <string_view>
using shader_source_view = std::string_view;

View File

@@ -0,0 +1,15 @@
#pragma once
#include "assets/data/material_data.hpp"
namespace assets
{
struct texture_view
{
std::weak_ptr<std::uint8_t[]> data;
int width, height;
texture_components::flags component_flags;
};
}

View File

@@ -1,21 +1,25 @@
#pragma once #pragma once
#include "dynamic_data_stores/dynamic_material_library_store.hpp" #include "data_stores/material_library_store.hpp"
#include "dynamic_data_stores/dynamic_material_store.hpp" #include "data_stores/material_store.hpp"
#include "dynamic_data_stores/dynamic_mesh_store.hpp" #include "data_stores/mesh_store.hpp"
#include "dynamic_data_stores/dynamic_point_cloud_store.hpp" #include "data_stores/point_cloud_store.hpp"
#include "dynamic_data_stores/dynamic_pose_store.hpp" #include "data_stores/pose_store.hpp"
#include "dynamic_data_stores/dynamic_shader_source_store.hpp" #include "data_stores/shader_source_store.hpp"
#include "dynamic_data_stores/dynamic_texture_store.hpp" #include "data_stores/texture_store.hpp"
namespace assets
{
struct dynamic_data_store struct dynamic_data_store
{ {
dynamic_material_library_store material_libraries; material_library_store material_libraries;
dynamic_material_store materials; material_store materials;
dynamic_mesh_store meshes; mesh_store meshes;
dynamic_point_cloud_store point_clouds; point_cloud_store point_clouds;
dynamic_pose_store poses; pose_store poses;
dynamic_shader_store shaders; shader_source_store shader_sources;
dynamic_texture_store textures; texture_store textures;
}; };
}

View File

@@ -1,6 +0,0 @@
#pragma once
#include "generic/generic_dynamic_store.hpp"
#include "assets/dynamic_read_buffers/dynamic_material_library_buffer.hpp"
using dynamic_material_library_store = generic_dynamic_store<dynamic_material_library_buffer>;

View File

@@ -1,37 +0,0 @@
#pragma once
#include "dynamic_texture_store.hpp"
#include "generic/generic_dynamic_component_store.hpp"
#include "assets/dynamic_read_buffers/dynamic_material_buffer.hpp"
class dynamic_material_store {
using store_type = generic_dynamic_component_store<
components::material::flags,
components::material::surface_properties,
components::material::transparency,
dynamic_texture_store::id_type,
dynamic_texture_store::id_type,
dynamic_texture_store::id_type,
dynamic_texture_store::id_type,
dynamic_texture_store::id_type,
dynamic_texture_store::id_type
>;
public:
using id_type = store_type::id_type;
using iterator_type = store_type::iterator_type;
using const_iterator = store_type::const_iterator;
id_type add(const dynamic_material_buffer& data);
[[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();
private:
store_type m_store;
};

View File

@@ -1,37 +0,0 @@
#pragma once
#include "assets/dynamic_data_stores/generic/generic_dynamic_indexed_component_array_store.hpp"
#include "assets/components/mesh_vertex_components.hpp"
#include "assets/dynamic_read_buffers/dynamic_mesh_buffer.hpp"
class dynamic_mesh_store
{
using store_type = generic_dynamic_indexed_component_array_store<
components::mesh_vertex::flags,
ztu::u32,
components::mesh_vertex::position,
components::mesh_vertex::normal,
components::mesh_vertex::tex_coord,
components::mesh_vertex::color,
components::mesh_vertex::reflectance
>;
public:
using id_type = store_type::id_type;
using iterator_type = store_type::iterator_type;
using const_iterator = store_type::const_iterator;
id_type add(const dynamic_mesh_buffer& mesh_buffer);
[[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();
private:
store_type m_store;
};

View File

@@ -1,36 +0,0 @@
#pragma once
#include "assets/dynamic_data_stores/generic/generic_dynamic_component_array_store.hpp"
#include "assets/components/point_cloud_vertex_components.hpp"
#include "assets/dynamic_read_buffers/dynamic_point_cloud_buffer.hpp"
class dynamic_point_cloud_store
{
using store_type = generic_dynamic_component_array_store<
components::point_cloud_vertex::flags,
components::point_cloud_vertex::position,
components::point_cloud_vertex::normal,
components::point_cloud_vertex::color,
components::point_cloud_vertex::reflectance
>;
public:
using id_type = store_type::id_type;
using iterator_type = store_type::iterator_type;
using const_iterator = store_type::const_iterator;
id_type add(const dynamic_point_cloud_buffer& point_cloud_buffer);
[[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();
private:
store_type m_store;
};

View File

@@ -1,6 +0,0 @@
#pragma once
#include "generic/generic_dynamic_store.hpp"
#include "glm/mat4x4.hpp"
using dynamic_pose_store = generic_dynamic_store<glm::mat4>;

View File

@@ -1,7 +0,0 @@
#pragma once
#include "generic/generic_dynamic_store.hpp"
#include "assets/dynamic_read_buffers/dynamic_shader_buffer.hpp"
// TODO use compressed store where all shaders are condensed into one vector
using dynamic_shader_source_store = generic_dynamic_store<dynamic_shader_buffer>;

View File

@@ -1,6 +0,0 @@
#pragma once
#include "generic/generic_dynamic_store.hpp"
#include "assets/dynamic_read_buffers/dynamic_texture_buffer.hpp"
using dynamic_texture_store = generic_dynamic_store<dynamic_texture_buffer>;

View File

@@ -1,37 +0,0 @@
#pragma once
#include <tuple>
#include <vector>
#include <span>
#include "util/id_type.hpp"
#include "util/uix.hpp"
#include "GL/glew.h"
template<typename C, typename... Ts>
class dynamic_vertex_store {
public:
using id_type = ztu::id_type_for<dynamic_vertex_store, ztu::u32>;
void add(
C component_flags,
std::span<const Ts>... components
);
void 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;
protected:
std::tuple<std::vector<Ts>...> m_component_buffers{};
std::vector<std::size_t> vertex_counts;
std::vector<C> m_components{ 0 };
};
#define INCLUDE_DYNAMIC_MODEL_DATA_IMPLEMENTATION
#include "assets/dynamic_read_buffers/dynamic_model_buffer.ipp"
#undef INCLUDE_DYNAMIC_MODEL_DATA_IMPLEMENTATION

View File

@@ -1,149 +0,0 @@
#pragma once
#include <vector>
#include <span>
#include "util/uix.hpp"
#include "util/id_type.hpp"
#include <tuple>
#include <span>
#include <cstddef>
#include <type_traits>
#include <bitset>
#include <optional>
#include <ranges>
template<typename C, typename... Ts>
class generic_dynamic_component_array_store;
template<typename C, typename... Ts>
class component_array_iterator {
public:
using value_type = std::tuple<std::span<Ts>...>;
using size_type = std::size_t;
using count_type = ztu::u32;
using flag_count_type = std::pair<C, count_type>;
using component_array_pointer_type = std::tuple<std::add_pointer_t<Ts>...>;
using flag_count_pointer_type = const flag_count_type*;
using offsets_type = std::array<size_type, 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_dynamic_component_array_store<C, Ts...>;
component_array_iterator(
component_array_pointer_type components,
flag_count_pointer_type flags,
std::size_t index,
const offsets_type& offsets
);
public:
constexpr component_array_iterator() noexcept = default;
constexpr component_array_iterator(const component_array_iterator&) noexcept = default;
constexpr component_array_iterator(component_array_iterator&&) noexcept = default;
constexpr component_array_iterator& operator=(const component_array_iterator&) noexcept = default;
constexpr component_array_iterator& operator=(component_array_iterator&&) noexcept = default;
reference operator*() const;
component_array_iterator& operator++();
component_array_iterator operator++(int);
component_array_iterator& operator--();
component_array_iterator operator--(int);
component_array_iterator& operator+=(difference_type n);
component_array_iterator& operator-=(difference_type n);
component_array_iterator operator+(difference_type n) const;
component_array_iterator operator-(difference_type n) const;
difference_type operator-(const component_array_iterator& other) const;
reference operator[](difference_type n) const;
bool operator==(const component_array_iterator& other) const;
bool operator!=(const component_array_iterator& other) const;
bool operator<(const component_array_iterator& other) const;
bool operator<=(const component_array_iterator& other) const;
bool operator>(const component_array_iterator& other) const;
bool operator>=(const component_array_iterator& other) const;
protected:
template <std::size_t I>
static bool is_component_enabled(C 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;
template <std::size_t N>
std::tuple_element_t<N, value_type> get_span() const;
private:
value_type m_components{};
const flag_count_type* m_flag_counts{};
size_type m_index{};
offsets_type m_offsets{};
};
template<typename C, typename... Ts>
class generic_dynamic_component_array_store
{
public:
using id_type = ztu::id_type_for<generic_dynamic_component_array_store, ztu::u32>;
using count_type = ztu::u32;
using iterator_type = component_array_iterator<C, Ts...>;
using const_iterator = component_array_iterator<C, std::add_const_t<Ts>...>;
using view_type = std::ranges::subrange<iterator_type>;
using const_view_type = std::ranges::subrange<const_iterator>;
id_type add(const std::tuple<std::vector<Ts>...>& component_arrays);
[[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>...> data_ptrs();
std::tuple<std::add_pointer_t<std::add_const_t<Ts>>...> data_ptrs() const;
std::array<std::size_t, sizeof...(Ts)> data_counts() const;
private:
std::tuple<std::vector<Ts>...> m_component_arrays;
std::vector<std::pair<C, ztu::u32>> m_component_flag_counts;
std::vector<id_type> m_ids;
id_type m_next_data_id{ 1 };
};
#define INCLUDE_GENERIC_DYNAMIC_COMPONENT_ARRAY_STORE_IMPLEMENTATION
#include "assets/dynamic_data_stores/generic/generic_dynamic_component_array_store.ipp"
#undef INCLUDE_GENERIC_DYNAMIC_COMPONENT_ARRAY_STORE_IMPLEMENTATION

View File

@@ -1,147 +0,0 @@
#pragma once
#include <vector>
#include <span>
#include "util/uix.hpp"
#include "util/id_type.hpp"
#include <tuple>
#include <span>
#include <cstddef>
#include <type_traits>
#include <bitset>
#include <optional>
#include <ranges>
template<typename C, typename... Ts>
class generic_dynamic_component_store;
template<typename C, typename... Ts>
class component_iterator {
public:
using value_type = std::tuple<std::add_pointer_t<Ts>...>;
using size_type = std::size_t;
using offsets_type = std::array<size_type, 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_dynamic_component_store<C, Ts...>;
component_iterator(
value_type components,
const C* flags,
std::size_t index,
const offsets_type& offsets
);
public:
constexpr component_iterator() noexcept = default;
constexpr component_iterator(const component_iterator&) noexcept = default;
constexpr component_iterator(component_iterator&&) noexcept = default;
constexpr component_iterator& operator=(const component_iterator&) noexcept = default;
constexpr component_iterator& operator=(component_iterator&&) noexcept = default;
reference operator*() const;
component_iterator& operator++();
component_iterator operator++(int);
component_iterator& operator--();
component_iterator operator--(int);
component_iterator& operator+=(difference_type n);
component_iterator& operator-=(difference_type n);
component_iterator operator+(difference_type n) const;
component_iterator operator-(difference_type n) const;
difference_type operator-(const component_iterator& other) const;
reference operator[](difference_type n) const;
bool operator==(const component_iterator& other) const;
bool operator!=(const component_iterator& other) const;
bool operator<(const component_iterator& other) const;
bool operator<=(const component_iterator& other) const;
bool operator>(const component_iterator& other) const;
bool operator>=(const component_iterator& other) const;
protected:
template <std::size_t I>
static bool is_component_enabled(C 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;
template <std::size_t N>
std::tuple_element_t<N, value_type> get_pointer() const;
private:
value_type m_components{};
const C* m_flags{};
size_type m_index{};
offsets_type m_offsets{};
};
template<typename C, typename... Ts>
class generic_dynamic_component_store
{
public:
using id_type = ztu::id_type_for<generic_dynamic_component_store, ztu::u32>;
using iterator_type = component_iterator<C, Ts...>;
using const_iterator = component_iterator<C, std::add_const_t<Ts>...>;
using view_type = std::ranges::subrange<iterator_type>;
using const_view_type = std::ranges::subrange<const_iterator>;
id_type add(const std::tuple<std::optional<Ts>...>& data);
[[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>...> data_ptrs();
std::tuple<std::add_pointer_t<std::add_const_t<Ts>>...> data_ptrs() const;
std::array<std::size_t, sizeof...(Ts)> data_counts() const;
private:
std::tuple<std::vector<Ts>...> m_components;
std::vector<C> m_component_flags;
std::vector<id_type> m_ids;
id_type m_next_data_id{ 1 };
};
#define INCLUDE_GENERIC_DYNAMIC_COMPONENT_STORE_IMPLEMENTATION
#include "assets/dynamic_data_stores/generic_dynamic_component_store.ipp"
#undef INCLUDE_GENERIC_DYNAMIC_COMPONENT_STORE_IMPLEMENTATION

View File

@@ -1,157 +0,0 @@
#pragma once
#include <vector>
#include <span>
#include "util/uix.hpp"
#include "util/id_type.hpp"
#include <tuple>
#include <span>
#include <cstddef>
#include <type_traits>
#include <bitset>
#include <optional>
#include <ranges>
template<typename C, typename I, typename... Ts>
class generic_dynamic_indexed_component_array_store;
template<typename C, typename I, typename... Ts>
class indexed_component_array_iterator {
public:
using index_type = I;
using value_type = std::tuple<std::span<I>, std::span<Ts>...>;
using size_type = std::size_t;
using count_type = ztu::u32;
using flag_count_type = std::tuple<C, count_type, count_type>;
using index_array_pointer_type = const index_type*;
using component_array_pointer_type = std::tuple<std::add_pointer_t<Ts>...>;
using flag_count_pointer_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_dynamic_indexed_component_array_store<C, I, Ts...>;
indexed_component_array_iterator(
index_array_pointer_type indices,
const component_array_pointer_type& components,
flag_count_pointer_type flag_counts,
std::size_t index,
const offsets_type& offsets
);
public:
constexpr indexed_component_array_iterator() noexcept = default;
constexpr indexed_component_array_iterator(const indexed_component_array_iterator&) noexcept = default;
constexpr indexed_component_array_iterator(indexed_component_array_iterator&&) noexcept = default;
constexpr indexed_component_array_iterator& operator=(const indexed_component_array_iterator&) noexcept = default;
constexpr indexed_component_array_iterator& operator=(indexed_component_array_iterator&&) noexcept = default;
reference operator*() const;
indexed_component_array_iterator& operator++();
indexed_component_array_iterator operator++(int);
indexed_component_array_iterator& operator--();
indexed_component_array_iterator operator--(int);
indexed_component_array_iterator& operator+=(difference_type n);
indexed_component_array_iterator& operator-=(difference_type n);
indexed_component_array_iterator operator+(difference_type n) const;
indexed_component_array_iterator operator-(difference_type n) const;
difference_type operator-(const indexed_component_array_iterator& other) const;
reference operator[](difference_type n) const;
bool operator==(const indexed_component_array_iterator& other) const;
bool operator!=(const indexed_component_array_iterator& other) const;
bool operator<(const indexed_component_array_iterator& other) const;
bool operator<=(const indexed_component_array_iterator& other) const;
bool operator>(const indexed_component_array_iterator& other) const;
bool operator>=(const indexed_component_array_iterator& other) const;
protected:
template <std::size_t N>
static bool is_component_enabled(C 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:
index_array_pointer_type m_indices{};
component_array_pointer_type m_components{};
flag_count_pointer_type m_flag_counts{};
size_type m_index{};
offsets_type m_offsets{};
};
template<typename C, typename I, typename... Ts>
class generic_dynamic_indexed_component_array_store
{
public:
using id_type = ztu::id_type_for<generic_dynamic_indexed_component_array_store, ztu::u32>;
using count_type = ztu::u32;
using iterator_type = indexed_component_array_iterator<C, I, Ts...>;
using const_iterator = indexed_component_array_iterator<C, I, std::add_const_t<Ts>...>;
using view_type = std::ranges::subrange<iterator_type>;
using const_view_type = std::ranges::subrange<const_iterator>;
id_type add(
std::span<const I> indices,
const std::tuple<std::vector<Ts>...>& component_arrays
);
[[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_array_ptrs();
std::tuple<std::add_pointer_t<std::add_const_t<Ts>>...> component_array_ptrs() const;
std::array<std::size_t, 1 + sizeof...(Ts)> array_counts() const;
private:
std::vector<I> m_indices;
std::tuple<std::vector<Ts>...> m_component_arrays;
std::vector<std::pair<C, ztu::u32>> m_component_flag_counts;
std::vector<id_type> m_ids;
id_type m_next_data_id{ 1 };
};
#define INCLUDE_GENERIC_DYNAMIC_INDEXED_COMPONENT_ARRAY_STORE_IMPLEMENTATION
#include "assets/dynamic_data_stores/generic/generic_dynamic_indexed_component_array_store.ipp"
#undef INCLUDE_GENERIC_DYNAMIC_INDEXED_COMPONENT_ARRAY_STORE_IMPLEMENTATION

View File

@@ -1,50 +0,0 @@
#pragma once
#include <optional>
#include "assets/components/material_components.hpp"
#include "assets/dynamic_data_stores/dynamic_texture_store.hpp"
struct dynamic_material_buffer {
dynamic_material_buffer() = default;
components::material::surface_properties& initialized_surface_properties();
[[nodiscard]] inline std::optional<components::material::surface_properties>& surface_properties();
[[nodiscard]] inline std::optional<components::material::transparency>& transparency();
[[nodiscard]] inline std::optional<dynamic_texture_store::id_type>& ambient_color_texture_id();
[[nodiscard]] inline std::optional<dynamic_texture_store::id_type>& diffuse_color_texture_id();
[[nodiscard]] inline std::optional<dynamic_texture_store::id_type>& specular_color_texture_id();
[[nodiscard]] inline std::optional<dynamic_texture_store::id_type>& shininess_texture_id();
[[nodiscard]] inline std::optional<dynamic_texture_store::id_type>& alpha_texture_id();
[[nodiscard]] inline std::optional<dynamic_texture_store::id_type>& bump_texture_id();
[[nodiscard]] inline const std::optional<components::material::surface_properties>& surface_properties() const;
[[nodiscard]] inline const std::optional<components::material::transparency>& transparency() const;
[[nodiscard]] inline const std::optional<dynamic_texture_store::id_type>& ambient_color_texture_id() const;
[[nodiscard]] inline const std::optional<dynamic_texture_store::id_type>& diffuse_color_texture_id() const;
[[nodiscard]] inline const std::optional<dynamic_texture_store::id_type>& specular_color_texture_id() const;
[[nodiscard]] inline const std::optional<dynamic_texture_store::id_type>& shininess_texture_id() const;
[[nodiscard]] inline const std::optional<dynamic_texture_store::id_type>& alpha_texture_id() const;
[[nodiscard]] inline const std::optional<dynamic_texture_store::id_type>& bump_texture_id() const;
inline void clear();
std::tuple<
std::optional<components::material::surface_properties>,
std::optional<components::material::transparency>,
std::optional<dynamic_texture_store::id_type>,
std::optional<dynamic_texture_store::id_type>,
std::optional<dynamic_texture_store::id_type>,
std::optional<dynamic_texture_store::id_type>,
std::optional<dynamic_texture_store::id_type>,
std::optional<dynamic_texture_store::id_type>
> data{
std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt
};
};
#define INCLUDE_DYNAMIC_MATERIAL_DATA_IMPLEMENTATION
#include "assets/dynamic_read_buffers/dynamic_material_buffer.ipp"
#undef INCLUDE_DYNAMIC_MATERIAL_DATA_IMPLEMENTATION

View File

@@ -1,6 +0,0 @@
#pragma once
#include "util/string_lookup.hpp"
#include "assets/dynamic_data_stores/dynamic_material_store.hpp"
using dynamic_material_library_buffer = ztu::string_lookup<dynamic_material_store::id_type>;

View File

@@ -1,48 +0,0 @@
#pragma once
#include <array>
#include <vector>
#include "util/uix.hpp"
#include "assets/components/mesh_vertex_components.hpp"
#include "generic/dynamic_vertex_buffer.hpp"
#include "assets/dynamic_data_stores/dynamic_material_store.hpp"
class dynamic_mesh_buffer : public dynamic_vertex_buffer<
components::mesh_vertex::flags,
components::mesh_vertex::position,
components::mesh_vertex::normal,
components::mesh_vertex::tex_coord,
components::mesh_vertex::color,
components::mesh_vertex::reflectance
> {
public:
using index_type = ztu::u32;
using triangle_type = std::array<index_type, 3>;
[[nodiscard]] inline std::vector<components::mesh_vertex::position>& positions();
[[nodiscard]] inline std::vector<components::mesh_vertex::normal>& normals();
[[nodiscard]] inline std::vector<components::mesh_vertex::tex_coord>& tex_coords();
[[nodiscard]] inline std::vector<components::mesh_vertex::color>& colors();
[[nodiscard]] inline std::vector<components::mesh_vertex::reflectance>& reflectances();
[[nodiscard]] inline std::vector<triangle_type>& triangles();
[[nodiscard]] inline auto& material_id();
[[nodiscard]] inline const std::vector<components::mesh_vertex::position>& positions() const;
[[nodiscard]] inline const std::vector<components::mesh_vertex::normal>& normals() const;
[[nodiscard]] inline const std::vector<components::mesh_vertex::tex_coord>& tex_coords() const;
[[nodiscard]] inline const std::vector<components::mesh_vertex::color>& colors() const;
[[nodiscard]] inline const std::vector<components::mesh_vertex::reflectance>& reflectances() const;
[[nodiscard]] inline const std::vector<triangle_type>& triangles() const;
[[nodiscard]] inline const auto& material_id() const;
inline void clear();
private:
std::vector<triangle_type> m_triangles{};
dynamic_material_store::id_type m_material_id{};
};
#define INCLUDE_DYNAMIC_MESH_DATA_IMPLEMENTATION
#include "assets/dynamic_read_buffers/dynamic_mesh_buffer.ipp"
#undef INCLUDE_DYNAMIC_MESH_DATA_IMPLEMENTATION

View File

@@ -1,32 +0,0 @@
#pragma once
#include "assets/components/point_cloud_vertex_components.hpp"
#include <array>
#include <vector>
#include "generic/dynamic_vertex_buffer.hpp"
class dynamic_point_cloud_buffer : public dynamic_vertex_buffer<
components::point_cloud_vertex::flags,
components::point_cloud_vertex::position,
components::point_cloud_vertex::normal,
components::point_cloud_vertex::color,
components::point_cloud_vertex::reflectance
> {
public:
[[nodiscard]] inline std::vector<components::point_cloud_vertex::position>& positions();
[[nodiscard]] inline std::vector<components::point_cloud_vertex::normal>& normals();
[[nodiscard]] inline std::vector<components::point_cloud_vertex::color>& colors();
[[nodiscard]] inline std::vector<components::point_cloud_vertex::reflectance>& reflectances();
[[nodiscard]] inline const std::vector<components::point_cloud_vertex::position>& positions() const;
[[nodiscard]] inline const std::vector<components::point_cloud_vertex::normal>& normals() const;
[[nodiscard]] inline const std::vector<components::point_cloud_vertex::color>& colors() const;
[[nodiscard]] inline const std::vector<components::point_cloud_vertex::reflectance>& reflectances() const;
inline void clear();
};
#define INCLUDE_DYNAMIC_TEXTURE_DATA_IMPLEMENTATION
#include "assets/dynamic_read_buffers/dynamic_point_cloud_buffer.ipp"
#undef INCLUDE_DYNAMIC_TEXTURE_DATA_IMPLEMENTATION

View File

@@ -1,5 +0,0 @@
#pragma once
#include "glm/mat4x4.hpp"
using dynamic_pose_buffer = glm::mat4;

View File

@@ -1,16 +0,0 @@
#pragma once
#include <vector>
#include "GL/glew.h"
struct dynamic_shader_buffer
{
std::vector<char> source{};
GLenum type{ GL_INVALID_ENUM };
inline void clear()
{
source.clear();
type = GL_INVALID_ENUM;
}
};

View File

@@ -9,8 +9,8 @@
#include "util/string_list.hpp" #include "util/string_list.hpp"
#include "assets/prefetch_queue.hpp" #include "assets/prefetch_queue.hpp"
#include "assets/dynamic_read_buffers/dynamic_point_cloud_buffer.hpp" #include "../../read_buffers"
#include "assets/dynamic_data_stores/dynamic_point_cloud_store.hpp" #include "../../data_stores"
#include "assets/prefetch_lookup.hpp" #include "assets/prefetch_lookup.hpp"
@@ -42,7 +42,7 @@ protected:
); );
void transform_point_cloud( void transform_point_cloud(
std::span<components::point_cloud_vertex::position::value_type> points, std::span<point_cloud_vertex_components::position::value_type> points,
const glm::mat4& pose const glm::mat4& pose
); );
@@ -54,5 +54,5 @@ private:
}; };
#define INCLUDE_GENERIC_3DTK_LOADER_IMPLEMENTATION #define INCLUDE_GENERIC_3DTK_LOADER_IMPLEMENTATION
#include "assets/data_loaders/generic/generic_3dtk_loader.ipp" #include "../../data_parsers"
#undef INCLUDE_GENERIC_3DTK_LOADER_IMPLEMENTATION #undef INCLUDE_GENERIC_3DTK_LOADER_IMPLEMENTATION

View File

@@ -8,9 +8,12 @@
#include "assets/prefetch_lookup.hpp" #include "assets/prefetch_lookup.hpp"
#include "assets/prefetch_queue.hpp" #include "assets/prefetch_queue.hpp"
#include "assets/prefetch_lookups/mesh_prefetch_lookup.hpp" #include "assets/prefetch_lookups/mesh_prefetch_lookup.hpp"
#include "assets/dynamic_read_buffers/dynamic_shader_buffer.hpp" #include "assets/data/shader_source_data.hpp"
#include "util/string_list.hpp" #include "util/string_list.hpp"
namespace assets
{
struct glsl_loader struct glsl_loader
{ {
static constexpr auto name = std::string_view("glsl"); static constexpr auto name = std::string_view("glsl");
@@ -21,10 +24,12 @@ struct glsl_loader
); );
[[nodiscard]] static std::error_code load( [[nodiscard]] static std::error_code load(
dynamic_shader_buffer& buffer, shader_source_data& buffer,
const file_dir_list& paths, const file_dir_list& paths,
prefetch_lookup& id_lookup, prefetch_lookup& id_lookup,
dynamic_shader_source_store& store, shader_source_store& store,
bool pedantic = false bool pedantic = false
); );
}; };
}

View File

@@ -6,13 +6,16 @@
#include "assets/dynamic_data_store.hpp" #include "assets/dynamic_data_store.hpp"
#include "assets/components/point_cloud_vertex_components.hpp" #include "assets/components/point_cloud_vertex_components.hpp"
#include "assets/dynamic_read_buffers/dynamic_point_cloud_buffer.hpp" #include "assets/data/point_cloud_data.hpp"
#include "assets/dynamic_data_stores/dynamic_point_cloud_store.hpp" #include "assets/data_stores/point_cloud_store.hpp"
#include "assets/prefetch_lookup.hpp" #include "assets/prefetch_lookup.hpp"
#include "assets/prefetch_queue.hpp" #include "assets/prefetch_queue.hpp"
#include "glm/mat4x4.hpp" #include "glm/mat4x4.hpp"
#include "util/result.hpp" #include "util/result.hpp"
namespace assets
{
struct kitti_loader struct kitti_loader
{ {
static constexpr auto name = std::string_view("kitti"); static constexpr auto name = std::string_view("kitti");
@@ -23,10 +26,10 @@ struct kitti_loader
); );
[[nodiscard]] static std::error_code load( [[nodiscard]] static std::error_code load(
dynamic_point_cloud_buffer& buffer, point_cloud_data& buffer,
const file_dir_list& paths, const file_dir_list& paths,
prefetch_lookup& id_lookup, prefetch_lookup& id_lookup,
dynamic_shader_source_store& store, shader_source_store& store,
bool pedantic = false bool pedantic = false
); );
@@ -43,7 +46,7 @@ private:
); );
static void transform_point_cloud( static void transform_point_cloud(
std::span<components::point_cloud_vertex::position> points, std::span<point_cloud_vertex_components::position> points,
const glm::mat4& pose const glm::mat4& pose
); );
@@ -51,3 +54,6 @@ private:
}; };
}

View File

@@ -6,8 +6,8 @@
#include "assets/prefetch_lookup.hpp" #include "assets/prefetch_lookup.hpp"
#include "assets/prefetch_queue.hpp" #include "assets/prefetch_queue.hpp"
#include "util/string_list.hpp" #include "util/string_list.hpp"
#include "assets/dynamic_data_stores/dynamic_pose_store.hpp" #include "../data_stores"
#include "assets/dynamic_read_buffers/dynamic_pose_buffer.hpp" #include "assets/data"
#include "assets/prefetch_lookups/pose_prefetch_lookup.hpp" #include "assets/prefetch_lookups/pose_prefetch_lookup.hpp"
struct kitti_pose_loader struct kitti_pose_loader
@@ -23,7 +23,7 @@ struct kitti_pose_loader
dynamic_pose_buffer& buffer, dynamic_pose_buffer& buffer,
const file_dir_list& paths, const file_dir_list& paths,
prefetch_lookup& id_lookup, prefetch_lookup& id_lookup,
dynamic_shader_source_store& store, shader_source_store& store,
bool pedantic = false bool pedantic = false
); );

View File

@@ -6,9 +6,9 @@
#include "assets/dynamic_data_store.hpp" #include "assets/dynamic_data_store.hpp"
#include "assets/prefetch_lookup.hpp" #include "assets/prefetch_lookup.hpp"
#include "assets/prefetch_queue.hpp" #include "assets/prefetch_queue.hpp"
#include "assets/dynamic_read_buffers/dynamic_material_buffer.hpp" #include "assets/data"
#include "assets/dynamic_data_stores/dynamic_material_library_store.hpp" #include "../data_stores"
#include "assets/dynamic_data_stores/dynamic_material_store.hpp" #include "../data_stores"
#include "util/string_lookup.hpp" #include "util/string_lookup.hpp"
#include "util/result.hpp" #include "util/result.hpp"
@@ -41,7 +41,7 @@ struct mtl_loader
dynamic_material_library_buffer& material_library_buffer, dynamic_material_library_buffer& material_library_buffer,
const file_dir_list& paths, const file_dir_list& paths,
prefetch_lookup& id_lookup, prefetch_lookup& id_lookup,
dynamic_shader_source_store& store, shader_source_store& store,
bool pedantic = false bool pedantic = false
); );

View File

@@ -3,8 +3,8 @@
#include <filesystem> #include <filesystem>
#include <system_error> #include <system_error>
#include <string_view> #include <string_view>
#include "assets/dynamic_data_loaders/dynamic_material_loader.hpp" #include "../data_loaders"
#include "assets/dynamic_data_stores/dynamic_mesh_store.hpp" #include "../data_stores"
#include "assets/prefetch_lookup.hpp" #include "assets/prefetch_lookup.hpp"
#include <set> #include <set>

View File

@@ -5,8 +5,8 @@
#include <string_view> #include <string_view>
#include "assets/dynamic_data_store.hpp" #include "assets/dynamic_data_store.hpp"
#include "assets/dynamic_read_buffers/dynamic_mesh_buffer.hpp" #include "assets/data"
#include "assets/dynamic_data_stores/dynamic_mesh_store.hpp" #include "../data_stores"
#include "assets/prefetch_lookup.hpp" #include "assets/prefetch_lookup.hpp"
#include "assets/prefetch_queue.hpp" #include "assets/prefetch_queue.hpp"
@@ -24,7 +24,7 @@ struct stl_loader {
dynamic_mesh_buffer& buffer, dynamic_mesh_buffer& buffer,
const file_dir_list& paths, const file_dir_list& paths,
prefetch_lookup& id_lookup, prefetch_lookup& id_lookup,
dynamic_shader_source_store& store, shader_source_store& store,
bool pedantic = false bool pedantic = false
); );
}; };

View File

@@ -5,7 +5,7 @@
#include "assets/dynamic_data_store.hpp" #include "assets/dynamic_data_store.hpp"
#include "assets/prefetch_lookup.hpp" #include "assets/prefetch_lookup.hpp"
#include "assets/prefetch_queue.hpp" #include "assets/prefetch_queue.hpp"
#include "assets/dynamic_read_buffers/dynamic_pose_buffer.hpp" #include "assets/data"
#include "util/string_list.hpp" #include "util/string_list.hpp"
#include "util/result.hpp" #include "util/result.hpp"
#include "assets/prefetch_lookups/pose_prefetch_lookup.hpp" #include "assets/prefetch_lookups/pose_prefetch_lookup.hpp"
@@ -23,7 +23,7 @@ struct threedtk_pose_loader
dynamic_pose_buffer& buffer, dynamic_pose_buffer& buffer,
const file_dir_list& paths, const file_dir_list& paths,
prefetch_lookup& id_lookup, prefetch_lookup& id_lookup,
dynamic_shader_source_store& store, shader_source_store& store,
bool pedantic = false bool pedantic = false
); );

View File

@@ -8,6 +8,9 @@
#include "prefetch_lookups/shader_prefetch_lookup.hpp" #include "prefetch_lookups/shader_prefetch_lookup.hpp"
#include "prefetch_lookups/texture_prefetch_lookup.hpp" #include "prefetch_lookups/texture_prefetch_lookup.hpp"
namespace assets
{
struct prefetch_lookup struct prefetch_lookup
{ {
texture_prefetch_lookup textures; texture_prefetch_lookup textures;
@@ -16,5 +19,7 @@ struct prefetch_lookup
mesh_prefetch_lookup meshes; mesh_prefetch_lookup meshes;
pose_prefetch_lookup poses; pose_prefetch_lookup poses;
point_cloud_prefetch_lookup point_clouds; point_cloud_prefetch_lookup point_clouds;
shader_prefetch_lookup shaders; shader_source_prefetch_lookup shader_sources;
}; };
}

View File

@@ -2,6 +2,11 @@
#include <filesystem> #include <filesystem>
#include <unordered_map> #include <unordered_map>
#include "assets/dynamic_data_stores/dynamic_material_library_store.hpp" #include "assets/data_stores/material_library_store.hpp"
using material_library_prefetch_lookup = std::unordered_map<std::filesystem::path, dynamic_material_library_store::id_type>; namespace assets
{
using material_library_prefetch_lookup = std::unordered_map<std::filesystem::path, material_library_store::id_type>;
}

View File

@@ -2,6 +2,11 @@
#include <filesystem> #include <filesystem>
#include <unordered_map> #include <unordered_map>
#include "assets/dynamic_data_stores/dynamic_material_store.hpp" #include "assets/data_stores/material_store.hpp"
using material_prefetch_lookup = std::unordered_map<std::filesystem::path, dynamic_material_store::id_type>; namespace assets
{
using material_prefetch_lookup = std::unordered_map<std::filesystem::path, material_store::id_type>;
}

View File

@@ -2,6 +2,11 @@
#include <filesystem> #include <filesystem>
#include <unordered_map> #include <unordered_map>
#include "assets/dynamic_data_stores/dynamic_mesh_store.hpp" #include "assets/data_stores/mesh_store.hpp"
using mesh_prefetch_lookup = std::unordered_map<std::filesystem::path, dynamic_mesh_store::id_type>; namespace assets
{
using mesh_prefetch_lookup = std::unordered_map<std::filesystem::path, mesh_store::id_type>;
}

View File

@@ -2,6 +2,11 @@
#include <filesystem> #include <filesystem>
#include <unordered_map> #include <unordered_map>
#include "assets/dynamic_data_stores/dynamic_point_cloud_store.hpp" #include "assets/data_stores/point_cloud_store.hpp"
using point_cloud_prefetch_lookup = std::unordered_map<std::filesystem::path, dynamic_point_cloud_store::id_type>; namespace assets
{
using point_cloud_prefetch_lookup = std::unordered_map<std::filesystem::path, point_cloud_store::id_type>;
}

View File

@@ -3,43 +3,47 @@
#include <filesystem> #include <filesystem>
#include <unordered_map> #include <unordered_map>
#include "assets/dynamic_data_stores/dynamic_pose_store.hpp"
#include "util/uix.hpp" #include "util/uix.hpp"
#include "assets/data_stores/pose_store.hpp"
class pose_prefetch_lookup { namespace assets
{
class pose_prefetch_lookup
{
public: public:
using index_type = ztu::u32; using index_type = ztu::u32;
using directory_lookup = std::unordered_map<std::filesystem::path, index_type>; using directory_lookup = std::unordered_map<std::filesystem::path, index_type>;
using directory_iterator = std::pair<directory_lookup::iterator, index_type>; using directory_iterator = std::pair<directory_lookup::iterator, index_type>;
using index_lookup = std::vector<index_type>; using index_lookup = std::vector<index_type>;
using index_iterator = index_lookup::iterator; using index_iterator = index_lookup::iterator;
using lookup_type = std::vector<dynamic_pose_store::id_type>; using lookup_type = std::vector<pose_store::id_type>;
using iterator = lookup_type::iterator; using iterator = lookup_type::iterator;
void emplace( void emplace(
const std::filesystem::path& directory, const std::filesystem::path& directory,
index_type index, index_type index,
dynamic_pose_store::id_type id pose_store::id_type id
); );
void emplace_hint_dir( void emplace_hint_dir(
directory_iterator directory_it, directory_iterator directory_it,
index_type index, index_type index,
dynamic_pose_store::id_type id pose_store::id_type id
); );
void emplace_hint_dir_index( void emplace_hint_dir_index(
directory_iterator directory_it, directory_iterator directory_it,
index_iterator index_it, index_iterator index_it,
index_type index, index_type index,
dynamic_pose_store::id_type id pose_store::id_type id
); );
std::pair<directory_iterator, bool> find_directory( std::pair<directory_iterator, bool> find_directory(
const std::filesystem::path& directory const std::filesystem::path& directory
); );
std::pair<index_iterator, dynamic_pose_store::id_type> find_index( std::pair<index_iterator, pose_store::id_type> find_index(
directory_iterator directory_it, directory_iterator directory_it,
index_type index index_type index
); );
@@ -54,3 +58,5 @@ private:
index_lookup m_directory_indices; // count before indices, indices sorted per dir index_lookup m_directory_indices; // count before indices, indices sorted per dir
lookup_type m_pose_ids; // offset by 1 lookup_type m_pose_ids; // offset by 1
}; };
}

View File

@@ -2,6 +2,11 @@
#include <filesystem> #include <filesystem>
#include <unordered_map> #include <unordered_map>
#include "assets/dynamic_data_stores/dynamic_shader_st #include "assets/data_stores/shader_source_store.hpp"
using texture_prefetch_lookup = std::unordered_map<std::filesystem::path, dynamic_texture_store::id_type>; namespace assets
{
using shader_source_prefetch_lookup = std::unordered_map<std::filesystem::path, shader_source_store::id_type>;
}

View File

@@ -2,6 +2,11 @@
#include <filesystem> #include <filesystem>
#include <unordered_map> #include <unordered_map>
#include "assets/dynamic_data_stores/dynamic_texture_store.hpp" #include "assets/data_stores/texture_store.hpp"
using texture_prefetch_lookup = std::unordered_map<std::filesystem::path, dynamic_texture_store::id_type>; namespace assets
{
using texture_prefetch_lookup = std::unordered_map<std::filesystem::path, texture_store::id_type>;
}

View File

@@ -2,12 +2,16 @@
#include "util/string_list.hpp" #include "util/string_list.hpp"
namespace assets
{
struct file_dir_list struct file_dir_list
{ {
ztu::string_list files; ztu::string_list files;
ztu::string_list directories; ztu::string_list directories;
}; };
struct prefetch_queue struct prefetch_queue
{ {
file_dir_list obj_queue; file_dir_list obj_queue;
@@ -25,4 +29,6 @@ struct prefetch_queue
file_dir_list kitti_pose_queue; file_dir_list kitti_pose_queue;
file_dir_list glsl_queue; file_dir_list glsl_queue;
}; };
}

View File

@@ -8,7 +8,7 @@
#include "assets/components/mesh_vertex_components.hpp" #include "assets/components/mesh_vertex_components.hpp"
void estimate_normals( void estimate_normals(
std::span<const components::mesh_vertex::position::value_type> vertices, std::span<const mesh_vertex_components::position::value_type> vertices,
std::span<const std::array<ztu::u32, 3>> triangles, std::span<const std::array<ztu::u32, 3>> triangles,
std::vector<components::mesh_vertex::normal::value_type>& normals std::vector<mesh_vertex_components::normal::value_type>& normals
); );

View File

@@ -20,16 +20,16 @@ private:
const std::optional<surface_properties_handle>& surface_properties_handle, const std::optional<surface_properties_handle>& surface_properties_handle,
const std::optional<alpha_handle>& alpha_handle, const std::optional<alpha_handle>& alpha_handle,
std::optional<texture_data>&& texture_data, std::optional<texture_data>&& texture_data,
components::material::flags components material_components::flags components
); );
public: public:
material_data() = default; material_data() = default;
[[nodiscard]] static std::error_code build_from( [[nodiscard]] static std::error_code build_from(
const std::optional<components::material::texture>& texture_opt, const std::optional<material_texture_components>& texture_opt,
const std::optional<components::material::surface_properties>& surface_properties_opt, const std::optional<material_components::surface_properties>& surface_properties_opt,
const std::optional<components::material::transparency>& transparency_opt, const std::optional<material_components::transparency>& transparency_opt,
material_component::flags components, material_component::flags components,
material_data& data material_data& data
); );

View File

@@ -19,7 +19,7 @@ private:
GLuint index_vbo_id, GLuint index_vbo_id,
GLuint vao_id, GLuint vao_id,
ztu::u32 material_id, ztu::u32 material_id,
components::mesh_vertex::flags components, mesh_vertex_components::flags components,
GLsizei index_count GLsizei index_count
); );
@@ -33,7 +33,7 @@ public:
GLsizei stride, GLsizei stride,
std::span<const ztu::u32> index_buffer, std::span<const ztu::u32> index_buffer,
ztu::u32 material_id, ztu::u32 material_id,
components::mesh_vertex::flags components, mesh_vertex_components::flags components,
mesh_data& data mesh_data& data
); );
@@ -47,7 +47,7 @@ public:
[[nodiscard]] mesh_handle handle() const; [[nodiscard]] mesh_handle handle() const;
[[nodiscard]] components::mesh_vertex::flags components() const; [[nodiscard]] mesh_vertex_components::flags components() const;
[[nodiscard]] ztu::u32 material_id() const; [[nodiscard]] ztu::u32 material_id() const;
@@ -57,8 +57,8 @@ private:
GLuint m_vertex_vbo_id{ 0 }; GLuint m_vertex_vbo_id{ 0 };
GLuint m_index_vbo_id{ 0 }; GLuint m_index_vbo_id{ 0 };
ztu::u32 m_material_id{ 0 }; ztu::u32 m_material_id{ 0 };
components::mesh_vertex::flags m_component_types{ mesh_vertex_components::flags m_component_types{
components::mesh_vertex::flags::none mesh_vertex_components::flags::none
}; };
}; };
} }

View File

@@ -39,13 +39,13 @@ public:
[[nodiscard]] point_cloud_handle handle() const; [[nodiscard]] point_cloud_handle handle() const;
[[nodiscard]] components::point_cloud_vertex::flags components() const; [[nodiscard]] point_cloud_vertex_components::flags components() const;
private: private:
point_cloud_handle m_handle{}; point_cloud_handle m_handle{};
GLuint m_vertex_vbo_id{ 0 }; GLuint m_vertex_vbo_id{ 0 };
components::point_cloud_vertex::flags m_component_types{ point_cloud_vertex_components::flags m_component_types{
components::point_cloud_vertex::flags::none point_cloud_vertex_components::flags::none
}; };
}; };
} }

View File

@@ -1,36 +0,0 @@
#pragma once
namespace zgl
{
class buffer_manager
{
public:
using store_type = dynamic_texture_store;
using store_id_type = store_type::id_type;
using resource_manager_type = resource_manager<store_id_type>;
using resource_type = resource_manager_type::resource_handle;
using handle_type = texture_handle;
static constexpr std::size_t min_garbage_collection_count = 4;
void process(store_type& store);
std::optional<handle_type> get_handle(store_id_type id);
void collect_garbage(bool force = false);
private:
resource_manager<store_id_type> m_resource_manager;
std::vector<std::pair<dynamic_texture_store::id_type, const dynamic_texture_buffer&>> m_texture_buffer;
std::vector<GLuint> m_texture_id_buffer;
};
}

View File

@@ -0,0 +1,35 @@
#pragma once
#include "../../assets/data_stores"
#include "opengl/resource_management/resource_manager.hpp"
#include "opengl/handles/index_buffer_handle.hpp"
#include "opengl/metadata/index_buffer_metadata.hpp"
namespace zgl
{
class mesh_index_buffer_manager
{
public:
using store_type = dynamic_mesh_store;
using store_id_type = store_type::id_type;
using metadata_type = index_buffer_metadata;
using handle_type = index_buffer_handle;
using resource_manager_type = resource_manager<store_id_type, metadata_type>;
using entry_type = std::pair<handle_type, metadata_type>;
static constexpr std::size_t min_garbage_collection_count = 4;
void process(store_type& store);
std::optional<entry_type> get_handle(store_id_type id);
void collect_garbage(bool force = false);
protected:
resource_manager_type m_resource_manager;
private:
std::vector<store_type::iterator_type::value_type> m_mesh_buffer;
std::vector<GLuint> m_buffer_id_buffer;
};
}

View File

@@ -1,32 +1,38 @@
#pragma once #pragma once
#include "assets/dynamic_data_stores/dynamic_mesh_store.hpp" #include "assets/data_stores/mesh_store.hpp"
#include "opengl/resource_management/resource_manager.hpp" #include "opengl/resource_management/resource_manager.hpp"
#include "opengl/handles/vertex_buffer_handle.hpp" #include "opengl/handles/vertex_buffer_handle.hpp"
#include "opengl/metadata/vertex_buffer_metadata.hpp" #include "opengl/metadata/mesh_vertex_buffer_metadata.hpp"
namespace zgl namespace zgl
{ {
class mesh_vertex_buffer_manager class mesh_vertex_buffer_manager
{ {
public: public:
using store_type = dynamic_mesh_store; using store_type = assets::mesh_store;
using store_id_type = store_type::id_type; using store_id_type = store_type::id_type;
using metadata_type = vertex_buffer_metadata; using metadata_type = mesh_vertex_buffer_metadata;
using handle_type = vertex_buffer_handle; using handle_type = vertex_buffer_handle;
using resource_manager_type = resource_manager<store_id_type, metadata_type>; using resource_manager_type = resource_manager<store_id_type, metadata_type>;
using texture_entry_type = std::pair<handle_type, metadata_type>; using entry_type = std::pair<handle_type, metadata_type>;
static constexpr std::size_t min_garbage_collection_count = 4; static constexpr std::size_t min_garbage_collection_count = 4;
void process(store_type& store); void process(store_type& store);
std::optional<texture_entry_type> get_handle(store_id_type id); std::optional<entry_type> get_handle(store_id_type id);
void collect_garbage(bool force = false); void collect_garbage(bool force = false);
private: protected:
resource_manager_type m_resource_manager; resource_manager_type m_resource_manager;
private:
std::vector<store_type::iterator_type::value_type> m_mesh_buffer;
std::vector<GLuint> m_buffer_id_buffer;
std::vector<ztu::u8> m_byte_buffer;
}; };
} }

View File

@@ -0,0 +1,38 @@
#pragma once
#include "assets/data_stores/point_cloud_store.hpp"
#include "opengl/resource_management/resource_manager.hpp"
#include "opengl/handles/vertex_buffer_handle.hpp"
#include "opengl/metadata/point_cloud_vertex_buffer_metadata.hpp"
namespace zgl
{
class point_cloud_vertex_buffer_manager
{
public:
using store_type = assets::point_cloud_store;
using store_id_type = store_type::id_type;
using metadata_type = point_cloud_vertex_buffer_metadata;
using handle_type = vertex_buffer_handle;
using resource_manager_type = resource_manager<store_id_type, metadata_type>;
using entry_type = std::pair<handle_type, metadata_type>;
static constexpr std::size_t min_garbage_collection_count = 4;
void process(store_type& store);
std::optional<entry_type> get_handle(store_id_type id);
void collect_garbage(bool force = false);
protected:
resource_manager_type m_resource_manager;
private:
std::vector<store_type::iterator_type::value_type> m_point_cloud_buffer;
std::vector<GLuint> m_buffer_id_buffer;
std::vector<ztu::u8> m_byte_buffer;
};
}

View File

@@ -6,7 +6,7 @@
#include <ranges> #include <ranges>
#include <bits/ranges_algo.h> #include <bits/ranges_algo.h>
#include "assets/dynamic_data_stores/dynamic_shader_source_store.hpp" #include "assets/data_stores/shader_source_store.hpp"
#include "opengl/shader_program_lookup.hpp" #include "opengl/shader_program_lookup.hpp"
#include "opengl/handles/shader_handle.hpp" #include "opengl/handles/shader_handle.hpp"
#include "util/string_lookup.hpp" #include "util/string_lookup.hpp"
@@ -26,11 +26,11 @@ class shader_manager
public: public:
void process( void process(
const dynamic_shader_source_store& shader_sources const assets::shader_source_store& shader_sources
); );
void get_handles( void get_handles(
const dynamic_shader_source_store& shader_sources, const assets::shader_source_store& shader_sources,
std::span<const shading::shader_set_requirements> requirements, std::span<const shading::shader_set_requirements> requirements,
std::span<shader_set_metadata> metadata, std::span<shader_set_metadata> metadata,
std::span<shader_handle_set> shader_sets std::span<shader_handle_set> shader_sets

View File

@@ -1,7 +1,7 @@
#pragma once #pragma once
#include "shader_manager.hpp" #include "shader_manager.hpp"
#include "assets/dynamic_data_stores/dynamic_shader_source_store.hpp" #include "assets/data_stores/shader_source_store.hpp"
#include "opengl/data/shader_program_data.hpp" #include "opengl/data/shader_program_data.hpp"
#include "opengl/shading/requirements/shader_program_requirements.hpp" #include "opengl/shading/requirements/shader_program_requirements.hpp"
#include "opengl/metadata/shader_program_metadata.hpp" #include "opengl/metadata/shader_program_metadata.hpp"
@@ -18,11 +18,11 @@ class shader_program_manager
public: public:
void process( void process(
const dynamic_shader_source_store& shader_sources const assets::shader_source_store& shader_sources
); );
void get_handles( void get_handles(
const dynamic_shader_source_store& shader_sources, const assets::shader_source_store& shader_sources,
std::span<const shading::shader_program_requirements> requirements, std::span<const shading::shader_program_requirements> requirements,
std::span<shader_program_metadata> metadata, std::span<shader_program_metadata> metadata,
std::span<shader_program_handle> shader_programs std::span<shader_program_handle> shader_programs

View File

@@ -6,11 +6,11 @@
#include <span> #include <span>
#include "util/string_lookup.hpp" #include "util/string_lookup.hpp"
#include "../metadata/shader_source_metadata.hpp" #include "opengl/metadata/shader_source_metadata.hpp"
#include "opengl/shading/requirements/shader_source_requirements.hpp" #include "opengl/shading/requirements/shader_source_requirements.hpp"
#include "opengl/metadata/preprocessed_shader_source_metadata.hpp" #include "opengl/metadata/preprocessed_shader_source_metadata.hpp"
#include "assets/dynamic_data_stores/dynamic_shader_source_store.hpp" #include "assets/data_stores/shader_source_store.hpp"
#include "opengl/shading/shader_source_set.hpp" #include "opengl/shading/shader_source_set.hpp"
namespace zgl { namespace zgl {
@@ -19,11 +19,11 @@ class shader_source_manager {
public: public:
void process( void process(
const dynamic_shader_source_store& shader_sources const assets::shader_source_store& shader_sources
); );
void get_shader_sources( void get_shader_sources(
const dynamic_shader_source_store& shader_sources, const assets::shader_source_store& shader_sources,
std::span<const shading::shader_source_requirements> requirements, std::span<const shading::shader_source_requirements> requirements,
std::span<preprocessed_shader_source_metadata> metadata, std::span<preprocessed_shader_source_metadata> metadata,
std::vector<const char*>& shader_strings std::vector<const char*>& shader_strings
@@ -79,7 +79,7 @@ private:
std::vector<std::size_t> m_declaration_token_count_buffer; std::vector<std::size_t> m_declaration_token_count_buffer;
std::array<std::size_t, 4> m_declaration_type_index_buffer; std::array<std::size_t, 4> m_declaration_type_index_buffer;
using source_lookup_entry_type = std::pair<shader_source_metadata, dynamic_shader_source_store::id_type>; using source_lookup_entry_type = std::pair<shader_source_metadata, assets::shader_source_store::id_type>;
using source_lookup_type = std::vector<source_lookup_entry_type>; using source_lookup_type = std::vector<source_lookup_entry_type>;
source_lookup_type m_shader_source_lookup; source_lookup_type m_shader_source_lookup;

View File

@@ -2,8 +2,8 @@
#include <unordered_map> #include <unordered_map>
#include "assets/dynamic_read_buffers/dynamic_texture_buffer.hpp" #include "../../assets/read_buffers"
#include "assets/dynamic_data_stores/dynamic_texture_store.hpp" #include "../../assets/data_stores"
#include "opengl/handles/texture_handle.hpp" #include "opengl/handles/texture_handle.hpp"
#include <vector> #include <vector>
@@ -20,20 +20,20 @@ public:
using metadata_type = texture_metadata; using metadata_type = texture_metadata;
using handle_type = texture_handle; using handle_type = texture_handle;
using resource_manager_type = resource_manager<store_id_type, metadata_type>; using resource_manager_type = resource_manager<store_id_type, metadata_type>;
using texture_entry_type = std::pair<handle_type, metadata_type>; using entry_type = std::pair<handle_type, metadata_type>;
static constexpr std::size_t min_garbage_collection_count = 4; static constexpr std::size_t min_garbage_collection_count = 4;
void process(store_type& store); void process(store_type& store);
std::optional<texture_entry_type> get_handle(store_id_type id); std::optional<entry_type> get_handle(store_id_type id);
void collect_garbage(bool force = false); void collect_garbage(bool force = false);
private: protected:
resource_manager_type m_resource_manager; resource_manager_type m_resource_manager;
private:
std::vector<std::pair<dynamic_texture_store::id_type, const dynamic_texture_buffer&>> m_texture_buffer; std::vector<std::pair<dynamic_texture_store::id_type, const dynamic_texture_buffer&>> m_texture_buffer;
std::vector<GLuint> m_texture_id_buffer; std::vector<GLuint> m_texture_id_buffer;
}; };

View File

@@ -2,6 +2,7 @@
#include "opengl/resource_management/resource_handle.hpp" #include "opengl/resource_management/resource_handle.hpp"
namespace zgl namespace zgl
{ {

View File

@@ -0,0 +1,16 @@
#pragma once
#include <array>
#include "GL/glew.h"
namespace zgl
{
struct index_buffer_metadata
{
GLsizei count;
GLenum index_type;
};
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include "assets/components/mesh_vertex_components.hpp"
#include "assets/data_stores/material_store.hpp"
namespace zgl
{
struct mesh_vertex_buffer_metadata
{
assets::mesh_vertex_components::flags component_flags;
assets::material_store::id_type material_id{};
};
}

View File

@@ -0,0 +1,14 @@
#pragma once
#include "assets/components/point_cloud_vertex_components.hpp"
namespace zgl
{
struct point_cloud_vertex_buffer_metadata
{
assets::point_cloud_vertex_components::flags component_flags;
std::size_t point_count;
};
}

View File

@@ -7,7 +7,7 @@ namespace zgl
struct texture_metadata struct texture_metadata
{ {
components::texture::flags components; texture_components::flags components;
}; };
} }

View File

@@ -1,26 +0,0 @@
#pragma once
#include "assets/components/texture_components.hpp"
#include <array>
#include "GL/glew.h"
namespace zgl
{
struct vertex_buffer_metadata
{
static constexpr std::size_t max_component_count = 8;
struct component
{
GLenum type{ GL_INVALID_ENUM };
GLint length{ 0 };
};
std::array<component, max_component_count> components{};
GLuint component_count{};
GLsizei stride{};
};
}

View File

@@ -0,0 +1,127 @@
#pragma once
#include "opengl/type_utils.hpp"
#include "opengl/metadata/vertex_buffer_metadata.hpp"
#include "util/specialised_lambda.hpp"
#include <span>
#include <tuple>
#include <vector>
#include <cstring>
#include <bits/ranges_algo.h>
namespace zgl::vertex_buffer_utils
{
namespace detail
{
template <typename T>
concept numeric_type = std::integral<T> or std::floating_point<T>;
template<typename C, typename... Ts>
void for_enabled_components(
const C components,
auto&& f,
std::span<Ts> buffers...
) {
(
[&, index = std::size_t{}](const auto& buffer)
{
if ((components & static_cast<C>(1 << index)) != C{})
{
f(buffer, index);
}
++index;
}(buffers),
...
);
};
}
template<typename C, typename... Ts>
vertex_buffer_metadata generate_metadata(
const C components,
std::span<Ts> buffers...
) {
auto meta = vertex_buffer_metadata{};
detail::for_enabled_components(
components,
ztu::specialised_lambda
{
// Visitor for scalar values
[&]<detail::numeric_type Component>(const std::span<Component>&, std::size_t index)
{
auto& component = meta.components[index];
component.type = type_utils::to_gl_type<Component>();
component.count = 1;
++meta.component_count;
},
// Visitor for numbers
[&]<detail::numeric_type Component, std::size_t Count>(const std::span<std::array<Component, Count>>&, std::size_t index)
{
auto& component = meta.components[index];
component.type = type_utils::to_gl_type<Component>();
component.count = Count;
++meta.component_count;
}
},
buffers...
);
for (const auto& component : std::span(meta.components).subspan(0, meta.component_count))
{
meta.stride += type_utils::size_of(component.type) * component.count;
}
return meta;
}
template<typename C, typename... Ts>
void interlace(
std::vector<ztu::u8>& vertex_buffer,
const C components,
std::span<Ts> buffers...
) {
std::array<std::size_t, sizeof...(buffers)> byte_offsets;
auto stride = std::size_t{};
detail::for_enabled_components(
components,
[&]<class Component>(
const std::span<Component>&,
std::size_t index
) {
byte_offsets[index] = stride;
stride += sizeof(Component);
},
buffers...
);
const auto vertex_count = std::min({ buffers.size()... });
const auto buffer_size = stride * vertex_count;
vertex_buffer.resize(buffer_size);
detail::for_enabled_components(
components,
[&]<class Component>(const std::span<Component>& buffer, std::size_t index)
{
const auto byte_offset = byte_offsets[index];
for (const auto& value : buffer.subspan(0, vertex_count))
{
std::memcpy(
&vertex_buffer[byte_offset],
&value,
sizeof(value)
);
byte_offset += stride;
}
},
buffers...
);
};
}

View File

@@ -18,7 +18,7 @@ class mesh_batch_renderer
{ {
public: public:
using batch_components_type = std::pair< using batch_components_type = std::pair<
components::mesh_vertex::flags, mesh_vertex_components::flags,
material_component::flags material_component::flags
>; >;
using batch_type = mesh_batch; using batch_type = mesh_batch;

View File

@@ -15,7 +15,7 @@ namespace rendering
class point_cloud_batch_renderer class point_cloud_batch_renderer
{ {
public: public:
using batch_components_type = components::point_cloud_vertex::flags; using batch_components_type = point_cloud_vertex_components::flags;
using batch_type = point_cloud_batch; using batch_type = point_cloud_batch;
using batch_index_type = ztu::u32; using batch_index_type = ztu::u32;
using batch_id_type = batch_index_type; using batch_id_type = batch_index_type;

View File

@@ -13,11 +13,11 @@ namespace rendering::requirements::mesh
struct type struct type
{ {
shading::features::mesh::indices::type shader_program_requirement_index{}; shading::features::mesh::indices::type shader_program_requirement_index{};
components::mesh_vertex::flags vertex_requirements{ mesh_vertex_components::flags vertex_requirements{
components::mesh_vertex::flags::none mesh_vertex_components::flags::none
}; };
components::material::flags material_requirements{ material_components::flags material_requirements{
components::material::flags::none material_components::flags::none
}; };
}; };
@@ -34,13 +34,13 @@ enum class flags : std::uint8_t
constexpr inline auto position = type{ constexpr inline auto position = type{
.shader_program_requirement_index = shading::features::mesh::indices::position, .shader_program_requirement_index = shading::features::mesh::indices::position,
.vertex_requirements = components::mesh_vertex::flags::position .vertex_requirements = mesh_vertex_components::flags::position
}; };
constexpr inline auto lit = type{ constexpr inline auto lit = type{
.shader_program_requirement_index = shading::features::mesh::indices::lit, .shader_program_requirement_index = shading::features::mesh::indices::lit,
.vertex_requirements = components::mesh_vertex::flags::normal, .vertex_requirements = mesh_vertex_components::flags::normal,
.material_requirements = components::material::flags::surface_properties .material_requirements = material_components::flags::surface_properties
}; };
constexpr inline auto point = type{ constexpr inline auto point = type{
@@ -49,8 +49,8 @@ constexpr inline auto point = type{
constexpr inline auto textured = type{ constexpr inline auto textured = type{
.shader_program_requirement_index = shading::features::mesh::indices::textured, .shader_program_requirement_index = shading::features::mesh::indices::textured,
.vertex_requirements = components::mesh_vertex::flags::tex_coord, .vertex_requirements = mesh_vertex_components::flags::tex_coord,
.material_requirements = components::material::flags::texture, .material_requirements = material_components::flags::texture,
}; };
constexpr inline auto uniform_color = type{ constexpr inline auto uniform_color = type{
@@ -59,7 +59,7 @@ constexpr inline auto uniform_color = type{
constexpr inline auto uniform_alpha = type{ constexpr inline auto uniform_alpha = type{
.shader_program_requirement_index = shading::features::mesh::indices::uniform_alpha, .shader_program_requirement_index = shading::features::mesh::indices::uniform_alpha,
.material_requirements = components::material::flags::transparency .material_requirements = material_components::flags::transparency
}; };
constexpr inline auto all = std::array{ constexpr inline auto all = std::array{

Some files were not shown because too many files have changed in this diff Show More