In the middle of multithreading parsers.

This commit is contained in:
zy4n
2025-03-30 22:38:06 +02:00
parent d18b40a7fc
commit 144126ee7a
80 changed files with 2904 additions and 1450 deletions

View File

@@ -5,51 +5,67 @@
#include "config/primitives.hpp"
#include "assets/identifiers.hpp"
#include "assets/data_stores/texture_store.hpp"
#include "assets/data/surface_properties.hpp"
#include "assets/data/uniform_surface_properties.hpp"
#include "util/enum_bitfield_operators.hpp"
namespace assets::material_components
{
using surface_properties = surface_properties;
using transparency = z3d::f32;
using ambient_color_texture = texture_id;
using diffuse_color_texture = texture_id;
using specular_color_texture = texture_id;
using ambient_filter = z3d::vec3;
using diffuse_filter = z3d::vec3;
using specular_filter = z3d::vec3;
using shininess = z3d::f32;
using alpha = z3d::f32;
using ambient_filter_texture = texture_id;
using diffuse_filter_texture = texture_id;
using specular_filter_texture = texture_id;
using shininess_texture = texture_id;
using alpha_texture = texture_id;
using bump_texture = texture_id;
namespace indices
{
inline constexpr z3d::size surface_properties = 0;
inline constexpr z3d::size transparency = 1;
inline constexpr z3d::size ambient_color_texture = 2;
inline constexpr z3d::size diffuse_color_texture = 3;
inline constexpr z3d::size specular_color_texture = 4;
inline constexpr z3d::size shininess_texture = 5;
inline constexpr z3d::size alpha_texture = 6;
inline constexpr z3d::size bump_texture = 7;
enum : z3d::size
{
ambient_filter,
diffuse_filter,
specular_filter,
shininess,
alpha,
ambient_filter_texture,
diffuse_filter_texture,
specular_filter_texture,
shininess_texture,
alpha_texture,
bump_texture
};
}
enum class flags : z3d::u8
{
none = 0,
surface_properties = 1 << indices::surface_properties,
transparency = 1 << indices::transparency,
ambient_filter_texture = 1 << indices::ambient_color_texture,
diffuse_filter_texture = 1 << indices::diffuse_color_texture,
specular_filter_texture = 1 << indices::specular_color_texture,
ambient_filter = 1 << indices::ambient_filter,
diffuse_filter = 1 << indices::diffuse_filter,
specular_filter = 1 << indices::specular_filter,
shininess = 1 << indices::shininess,
alpha = 1 << indices::alpha,
ambient_filter_texture = 1 << indices::ambient_filter_texture,
diffuse_filter_texture = 1 << indices::diffuse_filter_texture,
specular_filter_texture = 1 << indices::specular_filter_texture,
shininess_texture = 1 << indices::shininess_texture,
alpha_texture = 1 << indices::alpha_texture,
bump_texture = 1 << indices::bump_texture
};
using all = z3d::structure<
surface_properties,
transparency,
ambient_color_texture,
diffuse_color_texture,
specular_color_texture,
ambient_filter,
diffuse_filter,
specular_filter,
shininess,
alpha,
ambient_filter_texture,
diffuse_filter_texture,
specular_filter_texture,
shininess_texture,
alpha_texture,
bump_texture

View File

@@ -0,0 +1,58 @@
#pragma once
#include "config/primitives.hpp"
#include "util/enum_bitfield_operators.hpp"
#include <array>
#include <string_view>
namespace assets::mesh_shader_components
{
namespace indices
{
enum : z3d::size
{
face,
line,
point,
luminance,
color,
alpha,
color_texture,
uniform_lighting,
textured_lighting,
uniform_color
};
}
enum class flags : std::uint16_t
{
none = 0,
face = 1 << indices::face,
line = 1 << indices::line,
point = 1 << indices::point,
luminance = 1 << indices::luminance,
color = 1 << indices::color,
alpha = 1 << indices::alpha,
color_texture = 1 << indices::color_texture,
uniform_lighting = 1 << indices::uniform_lighting,
textured_lighting = 1 << indices::textured_lighting,
uniform_color = 1 << indices::uniform_color
};
constexpr inline auto names = std::array<std::string_view, 10>{
"face",
"line",
"point",
"luminance",
"color",
"alpha",
"color_texture",
"uniform_lighting",
"textured_lighting",
"uniform_color"
};
}
DEFINE_ENUM_BITFIELD_OPERATORS(assets::mesh_shader_components::flags)

View File

@@ -16,11 +16,14 @@ using reflectance = z3d::f32;
namespace indices
{
inline constexpr z3d::size position = 0;
inline constexpr z3d::size normal = 1;
inline constexpr z3d::size tex_coord = 2;
inline constexpr z3d::size color = 3;
inline constexpr z3d::size reflectance = 4;
enum : z3d::size
{
position,
normal,
tex_coord,
color,
reflectance
};
}
enum class flags : z3d::u8

View File

@@ -0,0 +1,46 @@
#pragma once
#include "config/primitives.hpp"
#include "util/enum_bitfield_operators.hpp"
#include <array>
#include <string_view>
namespace assets::point_cloud_shader_components
{
enum indices : z3d::size
{
square,
lighting,
luminance,
color,
alpha,
uniform_color,
rainbow
};
enum class flags : std::uint16_t
{
none = 0,
square = 1 << indices::square,
lighting = 1 << indices::lighting,
luminance = 1 << indices::luminance,
color = 1 << indices::color,
alpha = 1 << indices::alpha,
uniform_color = 1 << indices::uniform_color,
rainbow = 1 << indices::rainbow
};
constexpr inline auto names = std::array<std::string_view, 7>{
"square",
"lighting",
"luminance",
"color",
"alpha",
"uniform_color",
"rainbow"
};
}
DEFINE_ENUM_BITFIELD_OPERATORS(assets::point_cloud_shader_components::flags)

View File

@@ -15,10 +15,13 @@ using reflectance = z3d::f32;
namespace indices
{
inline constexpr z3d::size position = 0;
inline constexpr z3d::size normal = 1;
inline constexpr z3d::size color = 2;
inline constexpr z3d::size reflectance = 3;
enum : z3d::size
{
position,
normal,
color,
reflectance
};
} // namespace indices
enum class flags : z3d::u8

View File

@@ -0,0 +1,35 @@
#pragma once
#include <type_traits>
#include "mesh_shader_components.hpp"
#include "point_cloud_shader_components.hpp"
namespace assets::shader_components
{
enum class stage : z3d::u8
{
vertex = 0,
tesselation_control = 1,
tesselation_evaluation = 2,
geometry = 3,
fragment = 4
};
inline constexpr std::size_t count = 5;
inline constexpr auto stage_names = std::array<std::string_view, count>{
"vertex",
"tesselation_control",
"tesselation_evaluation",
"geometry",
"fragment"
};
using flags = std::make_unsigned_t<std::common_type_t<
std::underlying_type_t<mesh_shader_components::flags>,
std::underlying_type_t<point_cloud_shader_components::flags>
>>;
}

View File

@@ -11,8 +11,12 @@ class component_array_set {};
template<typename C, typename... Ts>
class component_array_set<C, z3d::structure<Ts...>>
{
public:
component_array_set() = default;
C component_flags;
z3d::structure<z3d::vector<Ts>...> component_arrays{};
protected:
void clear_component_arrays()
{
@@ -24,10 +28,6 @@ protected:
component_arrays
);
}
C component_flags;
z3d::structure<z3d::vector<Ts>...> component_arrays{};
};
}

View File

@@ -1,7 +1,5 @@
#pragma once
#include <optional>
#include "assets/components/material_components.hpp"
#include "generic/component_set.hpp"
@@ -13,22 +11,27 @@ struct material_data : detail::component_set<material_components::all>
material_data() = default;
material_components::surface_properties& initialized_surface_properties();
[[nodiscard]] inline z3d::optional<material_components::surface_properties>& surface_properties();
[[nodiscard]] inline z3d::optional<material_components::transparency>& transparency();
[[nodiscard]] inline z3d::optional<material_components::ambient_color_texture>& ambient_color_texture_id();
[[nodiscard]] inline z3d::optional<material_components::diffuse_color_texture>& diffuse_color_texture_id();
[[nodiscard]] inline z3d::optional<material_components::specular_color_texture>& specular_color_texture_id();
[[nodiscard]] inline z3d::optional<material_components::ambient_filter>& ambient_filter();
[[nodiscard]] inline z3d::optional<material_components::diffuse_filter>& diffuse_filter();
[[nodiscard]] inline z3d::optional<material_components::specular_filter>& specular_filter();
[[nodiscard]] inline z3d::optional<material_components::shininess>& shininess();
[[nodiscard]] inline z3d::optional<material_components::alpha>& alpha();
[[nodiscard]] inline z3d::optional<material_components::ambient_filter_texture>& specular_filter_texture_id();
[[nodiscard]] inline z3d::optional<material_components::diffuse_filter_texture>& diffuse_filter_texture_id();
[[nodiscard]] inline z3d::optional<material_components::specular_filter_texture>& specular_filter_texture_id();
[[nodiscard]] inline z3d::optional<material_components::shininess_texture>& shininess_texture_id();
[[nodiscard]] inline z3d::optional<material_components::alpha_texture>& alpha_texture_id();
[[nodiscard]] inline z3d::optional<material_components::bump_texture>& bump_texture_id();
[[nodiscard]] inline const z3d::optional<material_components::surface_properties>& surface_properties() const;
[[nodiscard]] inline const z3d::optional<material_components::transparency>& transparency() const;
[[nodiscard]] inline const z3d::optional<material_components::ambient_color_texture>& ambient_color_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::diffuse_color_texture>& diffuse_color_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::specular_color_texture>& specular_color_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::ambient_filter>& ambient_filter() const;
[[nodiscard]] inline const z3d::optional<material_components::diffuse_filter>& diffuse_filter() const;
[[nodiscard]] inline const z3d::optional<material_components::specular_filter>& specular_filter() const;
[[nodiscard]] inline const z3d::optional<material_components::shininess>& shininess() const;
[[nodiscard]] inline const z3d::optional<material_components::alpha>& alpha() const;
[[nodiscard]] inline const z3d::optional<material_components::alpha>& transparency() const;
[[nodiscard]] inline const z3d::optional<material_components::ambient_filter_texture>& specular_filter_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::diffuse_filter_texture>& diffuse_filter_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::specular_filter_texture>& specular_filter_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::shininess_texture>& shininess_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::alpha_texture>& alpha_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::bump_texture>& bump_texture_id() const;
@@ -38,6 +41,6 @@ struct material_data : detail::component_set<material_components::all>
}
#define INCLUDE_DYNAMIC_MATERIAL_DATA_IMPLEMENTATION
#define INCLUDE_MATERIAL_DATA_IMPLEMENTATION
#include "assets/data/material_data.ipp"
#undef INCLUDE_DYNAMIC_MATERIAL_DATA_IMPLEMENTATION
#undef INCLUDE_MATERIAL_DATA_IMPLEMENTATION

View File

@@ -9,11 +9,16 @@
namespace assets
{
class point_cloud_data : detail::component_array_set<
class point_cloud_data : public detail::component_array_set<
point_cloud_vertex_components::flags,
point_cloud_vertex_components::all
> {
public:
using detail::component_array_set<
point_cloud_vertex_components::flags,
point_cloud_vertex_components::all
>::component_array_set;
[[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();

View File

@@ -0,0 +1,11 @@
#pragma once
#include "pose_data.hpp"
namespace assets
{
using pose_list_data = std::vector<pose_data>;
}

View File

@@ -1,6 +1,8 @@
#pragma once
#include "config/primitives.hpp"
#include "assets/components/shader_components.hpp"
#include "assets/model_geometry.hpp"
namespace assets
{
@@ -9,9 +11,20 @@ struct shader_source_data
{
z3d::vector<char> source{};
struct metadata
{
model_geometry::types geometry_type;
shader_components::stage stage{};
shader_components::flags components{};
shader_components::flags static_enable{};
shader_components::flags dynamic_enable{};
} meta;
void clear()
{
source.clear();
meta.stage = {};
meta.components = {};
}
};

View File

@@ -1,16 +0,0 @@
#pragma once
#include "config/primitives.hpp"
namespace assets
{
struct surface_properties
{
z3d::vec3 ambient_filter{ 0.7f, 0.7f, 0.7f };
z3d::vec3 diffuse_filter{ 0.466f, 0.466f, 0.7922f };
z3d::vec3 specular_filter{ 0.5974f, 0.2084f, 0.2084f };
z3d::f32 shininess{ 100.2237f };
};
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "config/primitives.hpp"
namespace assets
{
}

View File

@@ -10,7 +10,7 @@
#include "assets/prefetch_lookups/point_cloud_prefetch_lookup.hpp"
#include "util/string_list.hpp"
#include "assets/file_parsers/kitti_loader.hpp"
#include "assets/file_parsers/kitti_parser.hpp"
#include "assets/file_parsers/uos_loader.hpp"
#include "assets/file_parsers/uos_normal_loader.hpp"
#include "assets/file_parsers/uos_rgb_loader.hpp"
@@ -21,7 +21,7 @@ namespace assets
class point_cloud_loader : public base_dynamic_loader<
point_cloud_vertex_components::flags,
kitti_loader,
kitti_parser,
uos_loader,
uos_normal_loader,
uos_rgb_loader,

View File

@@ -4,6 +4,7 @@
#include "data_stores/material_store.hpp"
#include "data_stores/mesh_store.hpp"
#include "data_stores/point_cloud_store.hpp"
#include "data_stores/pose_list_store.hpp"
#include "data_stores/pose_store.hpp"
#include "data_stores/shader_source_store.hpp"
#include "data_stores/texture_store.hpp"
@@ -18,6 +19,7 @@ struct data_stores
mesh_store meshes;
point_cloud_store point_clouds;
pose_store poses;
pose_list_store pose_lists;
shader_source_store shader_sources;
texture_store textures;
};

View File

@@ -105,13 +105,12 @@ public:
using count_type = ztu::u32;
using component_flag_type = point_cloud_vertex_components::flags;
using data_type = point_cloud_data;
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 = point_cloud_id;
id_type add(const point_cloud_data& point_cloud);
id_type add(id_type id, const data_type& point_cloud);
[[nodiscard]] std::pair<iterator_type, bool> find(id_type id);
@@ -133,10 +132,6 @@ public:
const_iterator cend() const;
view_type view();
const_view_type view() const;
protected:
std::tuple<std::add_pointer_t<Ts>...> component_iterators();

View File

@@ -7,7 +7,7 @@ namespace assets
using material_store = detail::generic_material_store<
material_components::surface_properties,
material_components::transparency,
material_components::alpha,
texture_store::id_type,
texture_store::id_type,
texture_store::id_type,

View File

@@ -0,0 +1,137 @@
#pragma once
#include "generic/generic_basic_store.hpp"
#include "assets/identifiers.hpp"
#include "assets/data/pose_list_data.hpp"
#include "assets/data_views/pose_list_view.hpp"
namespace assets
{
class pose_list_store;
template<typename Char>
class pose_list_store_iterator
{
public:
using size_type = std::size_t;
using length_type = ztu::u32;
using id_type = pose_list_id;
using value_type = std::pair<id_type, pose_list_view>;
using id_iterator_type = id_type const*;
using pose_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 pose_list_store;
pose_list_store_iterator(
id_iterator_type ids,
pose_iterator_type poses,
length_iterator_type lengths,
std::size_t index,
const offset_type& offset
);
public:
constexpr pose_list_store_iterator() noexcept = default;
constexpr pose_list_store_iterator(const pose_list_store_iterator&) noexcept = default;
constexpr pose_list_store_iterator(pose_list_store_iterator&&) noexcept = default;
constexpr pose_list_store_iterator& operator=(const pose_list_store_iterator&) noexcept = default;
constexpr pose_list_store_iterator& operator=(pose_list_store_iterator&&) noexcept = default;
reference operator*() const;
pose_list_store_iterator& operator++();
pose_list_store_iterator operator++(int);
pose_list_store_iterator& operator--();
pose_list_store_iterator operator--(int);
pose_list_store_iterator& operator+=(difference_type n);
pose_list_store_iterator& operator-=(difference_type n);
pose_list_store_iterator operator+(difference_type n) const;
pose_list_store_iterator operator-(difference_type n) const;
difference_type operator-(const pose_list_store_iterator& other) const;
reference operator[](difference_type n) const;
bool operator==(const pose_list_store_iterator& other) const;
bool operator!=(const pose_list_store_iterator& other) const;
bool operator<(const pose_list_store_iterator& other) const;
bool operator<=(const pose_list_store_iterator& other) const;
bool operator>(const pose_list_store_iterator& other) const;
bool operator>=(const pose_list_store_iterator& other) const;
protected:
void calc_offset(difference_type n);
reference dereference() const;
private:
id_iterator_type m_ids{};
pose_iterator_type m_poses{};
length_iterator_type m_lengths{};
size_type m_index{};
offset_type m_offset{};
};
class pose_list_store
{
public:
using size_type = std::size_t;
using count_type = ztu::u32;
using iterator_type = pose_list_store_iterator<char>;
using const_iterator = pose_list_store_iterator<const char>;
using data_type = pose_list_data;
using id_type = pose_list_id;
// TODO not storing metadata
inline id_type add(
id_type id,
const data_type& pose_list
);
[[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;
private:
std::vector<id_type> m_ids;
std::vector<char> m_poses;
std::vector<count_type> m_lengths;
};
}
#define INCLUDE_POSE_LIST_STORE_IMPLEMENTATION
#include "assets/data_stores/pose_list_store.ipp"
#undef INCLUDE_POSE_LIST_STORE_IMPLEMENTATION

View File

@@ -15,12 +15,14 @@ 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 id_type = shader_source_id;
using metadata_type = shader_source_data::metadata;
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 metadata_iterator_type = const metadata_type*;
using offset_type = size_type;
using difference_type = std::ptrdiff_t;
@@ -35,6 +37,7 @@ private:
id_iterator_type ids,
string_iterator_type strings,
length_iterator_type lengths,
metadata_iterator_type metadata,
std::size_t index,
const offset_type& offset
);
@@ -80,6 +83,7 @@ private:
id_iterator_type m_ids{};
string_iterator_type m_strings{};
length_iterator_type m_lengths{};
metadata_iterator_type m_metadata{};
size_type m_index{};
offset_type m_offset{};
};
@@ -95,9 +99,13 @@ public:
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>;
using id_type = shader_source_id;
inline id_type add(const shader_source_data& shader_source);
// TODO not storing metadata
inline id_type add(
shader_source_id id,
const shader_source_data& shader_source
);
[[nodiscard]] inline std::pair<iterator_type, bool> find(id_type id);
@@ -119,15 +127,12 @@ public:
[[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 };
std::vector<shader_source_data::metadata> m_metadata;
};
}

View File

@@ -1,6 +1,6 @@
#pragma once
#include "generic/generic_point_cloud_viwe.hpp"
#include "generic/generic_point_cloud_view.hpp"
namespace assets
{

View File

@@ -0,0 +1,11 @@
#pragma once
#include "assets/data/pose_data.hpp"
namespace assets
{
using pose_list_view = std::span<pose_data>;
}

View File

@@ -1,5 +1,20 @@
#pragma once
#include "config/primitives.hpp"
#include <string_view>
#include "assets/model_geometry.hpp"
#include "assets/components/shader_components.hpp"
using shader_source_view = z3d::string_view;
namespace assets
{
struct shader_source_view
{
std::string_view source;
model_geometry::types geometry_type;
shader_components::stage stage;
shader_components::flags components{};
shader_components::flags static_enable{};
shader_components::flags dynamic_enable{};
};
}

View File

@@ -0,0 +1,10 @@
#pragma once
#include "assets/data/material_data.hpp"
namespace assets
{
material_data generate_fallback_material();
}

View File

@@ -0,0 +1,28 @@
#pragma once
#include "assets/components/texture_components.hpp"
#include "assets/data/texture_data.hpp"
namespace assets
{
struct fallback_color
{
static constexpr auto components = (
texture_components::flags::red |
texture_components::flags::green |
texture_components::flags::blue
);
texture_data::value_type r, g, b;
};
texture_data generate_fallback_texture(
int width = 4,
int height = 4,
std::span<const fallback_color> colors = std::array{
fallback_color{ .r = 255, .g = 0, b = 255 },
fallback_color{ .r = 0, .g = 0, b = 0 }
}
);
}

View File

@@ -1,35 +0,0 @@
#pragma once
#include <filesystem>
#include <vector>
#include <string>
#include "assets/data_stores.hpp"
#include "assets/prefetch_lookup.hpp"
#include "assets/prefetch_queue.hpp"
#include "assets/prefetch_lookups/mesh_prefetch_lookup.hpp"
#include "assets/data/shader_source_data.hpp"
#include "util/string_list.hpp"
namespace assets
{
struct glsl_loader
{
static constexpr auto name = std::string_view("glsl");
[[nodiscard]] static std::error_code prefetch(
const file_dir_list& paths,
prefetch_queue& queue
);
[[nodiscard]] static std::error_code load(
shader_source_data& buffer,
const file_dir_list& paths,
prefetch_lookup& id_lookup,
shader_source_store& store,
bool pedantic = false
);
};
}

View File

@@ -0,0 +1,122 @@
#pragma once
#include <filesystem>
#include "assets/path_id_lookups.hpp"
#include "assets/data_stores/shader_source_store.hpp"
#include "assets/data/shader_source_data.hpp"
namespace assets
{
struct glsl_parser
{
static constexpr auto name = std::string_view("glsl");
using data_type = shader_source_data;
using store_type = shader_source_store;
using lookup_type = shader_source_id_lookup;
[[nodiscard]] std::error_code prefetch(
path_id_lookups& lookups
);
[[nodiscard]] std::error_code load(
const path_id_lookups& lookups,
store_type& store,
bool pedantic = false
);
protected:
class parser_context
{
public:
parser_context(
store_type& m_store,
std::mutex& m_store_mutex
);
void operator()(lookup_type::const_pointer entry) noexcept;
protected:
void reset();
void tokenize_declarations();
[[nodiscard]] bool parse_metadata_from_tokens();
void remove_metadata_declarations();
private:
store_type* m_store;
std::mutex* m_store_mutex;
shader_source_data m_buffer{};
std::vector<std::string_view> m_value_buffer{};
std::vector<std::size_t> m_declaration_value_count_buffer{};
std::array<std::size_t, 4> m_declaration_type_index_buffer{};
};
[[nodiscard]] static std::error_code read_file(
const std::filesystem::path& filename,
std::vector<char>& source
);
static void tokenize_declarations(
std::string_view source,
std::vector<std::string_view>& value_buffer,
std::vector<std::size_t>& declaration_value_count_buffer,
std::array<std::size_t, 4>& declaration_type_index_buffer
);
static [[nodiscard]] bool parse_metadata_from_tokens(
const std::vector<std::string_view>& value_buffer,
const std::vector<std::size_t>& declaration_value_count_buffer,
const std::array<std::size_t, 4>& declaration_type_index_buffer,
shader_source_data& buffer
);
static void remove_metadata_declarations(
const std::vector<std::string_view>& value_buffer,
const std::vector<std::size_t>& declaration_value_count_buffer,
const std::array<std::size_t, 4>& declaration_type_index_buffer,
std::vector<char>& source
);
[[nodiscard]] static bool parse_geometry_declaration(
std::span<const std::string_view> values,
model_geometry::types& geometry_type
);
[[nodiscard]] static bool parse_stage_declaration(
std::span<const std::string_view> values,
shader_components::stage& stage
);
[[nodiscard]] static bool parse_components_declaration(
std::span<const std::string_view> values,
shader_source_data& buffer
);
[[nodiscard]] static bool parse_static_enable_declaration(
std::span<const std::string_view> values,
shader_source_data& buffer
);
[[nodiscard]] static bool parse_dynamic_enable_declaration(
std::span<const std::string_view> values,
shader_source_data& buffer
);
[[nodiscard]] static bool parse_component_tokens(
std::span<const std::string_view> values,
model_geometry::types geometry_type,
shader_components::flags& components
);
private:
std::vector<std::string_view> m_value_token_buffer;
std::vector<std::size_t> m_declaration_token_count_buffer;
std::array<std::size_t, 4> m_declaration_type_index_buffer;
std::vector<lookup_type::const_pointer> m_path_buffer;
};
}

View File

@@ -1,19 +0,0 @@
struct X {
[[nodiscard]] static std::error_code prefetch(
const file_dir_list& paths,
prefetch_queue& queue
);
[[nodiscard]] static std::error_code load(
// space stuff that has to persist
dynamic_X_buffer& buffer,
const file_dir_list& paths,
dynamic_X_store& store,
prefetch_lookup& id_lookup,
bool pedantic = false
);
}

View File

@@ -1,59 +0,0 @@
#pragma once
#include <filesystem>
#include <vector>
#include <span>
#include "assets/data_stores.hpp"
#include "assets/components/point_cloud_vertex_components.hpp"
#include "assets/data/point_cloud_data.hpp"
#include "assets/data_stores/point_cloud_store.hpp"
#include "assets/prefetch_lookup.hpp"
#include "assets/prefetch_queue.hpp"
#include "glm/mat4x4.hpp"
#include "util/result.hpp"
namespace assets
{
struct kitti_loader
{
static constexpr auto name = std::string_view("kitti");
[[nodiscard]] static std::error_code prefetch(
const file_dir_list& paths,
prefetch_queue& queue
);
[[nodiscard]] static std::error_code load(
point_cloud_data& buffer,
const file_dir_list& paths,
prefetch_lookup& id_lookup,
shader_source_store& store,
bool pedantic = false
);
private:
inline static constexpr auto frame_folder = "frames";
[[nodiscard]] static ztu::result<std::size_t> frame_id_from_filename(
std::string_view filename
);
[[nodiscard]] static std::error_code load_point_file(
const std::filesystem::path& filename,
dynamic_point_cloud_buffer& point_cloud
);
static void transform_point_cloud(
std::span<point_cloud_vertex_components::position> points,
const glm::mat4& pose
);
[[nodiscard]] static ztu::result<std::string_view> parent_directory(std::string_view path);
};
}

View File

@@ -0,0 +1,98 @@
#pragma once
#include <filesystem>
#include "assets/data_stores.hpp"
#include "assets/path_id_lookups.hpp"
#include "assets/components/point_cloud_vertex_components.hpp"
#include "assets/data/point_cloud_data.hpp"
#include "assets/data/pose_data.hpp"
#include "assets/data_stores/point_cloud_store.hpp"
#include "assets/data_stores/pose_list_store.hpp"
#include "assets/data_views/pose_list_view.hpp"
#include "util/result.hpp"
namespace assets
{
struct kitti_parser
{
static constexpr auto name = std::string_view("kitti");
using data_type = point_cloud_data;
using store_type = point_cloud_store;
using lookup_type = point_cloud_id_lookup;
[[nodiscard]] std::error_code prefetch(
path_id_lookups& lookups
);
[[nodiscard]] std::error_code load(
path_id_lookups& lookups,
data_stores& stores,
bool pedantic = false
);
protected:
static constexpr auto frame_folder = "frames";
class parser_context
{
public:
parser_context(
const pose_list_id_lookup& pose_list_lookup,
const pose_list_store& pose_list_store,
store_type& m_store,
std::mutex& m_store_mutex
);
void operator()(lookup_type::const_pointer entry) noexcept;
protected:
void reset();
void tokenize_declarations();
[[nodiscard]] bool parse_metadata_from_tokens();
void remove_metadata_declarations();
private:
pose_list_id_lookup const* m_pose_list_lookup;
pose_list_store const* m_pose_list_store;
store_type* m_store;
std::mutex* m_store_mutex;
data_type m_buffer{};
std::filesystem::path m_last_pose_path{};
pose_list_view m_last_pose_list{};
};
[[nodiscard]] static ztu::result<std::size_t> frame_id_from_filename(
std::string_view filename
);
[[nodiscard]] static std::error_code load_point_file(
const std::filesystem::path& filename,
data_type& point_cloud
);
static void transform_point_cloud(
z3d::array_view<point_cloud_vertex_components::position> points,
const pose_data& pose
);
[[nodiscard]] static ztu::result<std::filesystem::path> parent_directory(
const std::filesystem::path& path
);
#
[[nodiscard]] static ztu::result<std::filesystem::path> get_pose_path(
const std::filesystem::path& path
);
private:
std::vector<lookup_type::const_pointer> m_path_buffer;
};
}

View File

@@ -1,37 +0,0 @@
#pragma once
#include <filesystem>
#include "assets/data_stores.hpp"
#include "assets/prefetch_lookup.hpp"
#include "assets/prefetch_queue.hpp"
#include "util/string_list.hpp"
#include "../data_stores"
#include "assets/data"
#include "assets/prefetch_lookups/pose_prefetch_lookup.hpp"
struct kitti_pose_loader
{
static constexpr auto name = std::string_view("kitti_pose");
[[nodiscard]] static std::error_code prefetch(
const file_dir_list& paths,
prefetch_queue& queue
);
[[nodiscard]] static std::error_code load(
dynamic_pose_buffer& buffer,
const file_dir_list& paths,
prefetch_lookup& id_lookup,
shader_source_store& store,
bool pedantic = false
);
private:
static constexpr auto pose_filename = std::string_view{ "pose.txt" };
static std::error_code parse_pose(
std::ifstream& in,
dynamic_pose_buffer& pose
);
};

View File

@@ -0,0 +1,66 @@
#pragma once
#include <filesystem>
#include "assets/path_id_lookups.hpp"
#include "assets/data_stores/pose_list_store.hpp"
#include "assets/data/pose_list_data.hpp"
namespace assets
{
struct kitti_pose_parser
{
static constexpr auto name = std::string_view("kitti_pose");
using data_type = pose_list_data;
using store_type = pose_list_store;
using lookup_type = pose_list_id_lookup;
[[nodiscard]] std::error_code prefetch(
path_id_lookups& lookups
);
[[nodiscard]] std::error_code parse(
const path_id_lookups& lookups,
store_type& store,
bool pedantic = false
);
private:
static constexpr auto pose_filename = std::string_view{ "pose.txt" };
class parser_context
{
public:
parser_context(
store_type& m_store,
std::mutex& m_store_mutex
);
void operator()(lookup_type::const_pointer entry) noexcept;
protected:
void reset();
private:
store_type* m_store;
std::mutex* m_store_mutex;
data_type m_buffer{};
};
static std::error_code parse_file(
const std::filesystem::path& filename,
data_type &poses
);
static std::error_code parse_pose(
std::ifstream& in,
pose_data& pose
);
private:
std::vector<lookup_type::const_pointer> m_path_buffer;
};
}

View File

@@ -3,15 +3,17 @@
#include <filesystem>
#include <system_error>
#include "assets/data_stores.hpp"
#include "assets/prefetch_lookup.hpp"
#include "assets/prefetch_queue.hpp"
#include "assets/data"
#include "../data_stores"
#include "../data_stores"
#include "util/string_lookup.hpp"
#include "assets/data/material_data.hpp"
#include "assets/data/material_library_data.hpp"
#include "assets/data_stores/material_store.hpp"
#include "assets/data_stores/material_library_store.hpp"
#include "util/result.hpp"
namespace assets
{
namespace mtl_loader_error
{
enum class codes {
@@ -54,3 +56,5 @@ protected:
ztu::string_list& texture_filenames
);
};
}

View File

@@ -2,14 +2,15 @@
#include <filesystem>
#include "assets/data_stores.hpp"
#include "assets/prefetch_lookup.hpp"
#include "assets/prefetch_queue.hpp"
#include "assets/data"
#include "util/string_list.hpp"
#include "assets/data/pose_data.hpp"
#include "util/result.hpp"
#include "assets/prefetch_lookups/pose_prefetch_lookup.hpp"
namespace assets
{
struct threedtk_pose_loader
{
static constexpr auto name = std::string_view("3dtk_pose");
@@ -20,7 +21,7 @@ struct threedtk_pose_loader
);
[[nodiscard]] static std::error_code load(
dynamic_pose_buffer& buffer,
pose_data& buffer,
const file_dir_list& paths,
prefetch_lookup& id_lookup,
shader_source_store& store,
@@ -38,3 +39,5 @@ protected:
std::string_view filename
);
};
}

View File

@@ -5,12 +5,27 @@
namespace assets
{
using material_id = z3d::identifier<0>;
using material_library_id = z3d::identifier<1>;
using mesh_id = z3d::identifier<2>;
using point_cloud_id = z3d::identifier<3>;
using pose_id = z3d::identifier<4>;
using shader_source_id = z3d::identifier<5>;
using texture_id = z3d::identifier<6>;
namespace identifier_uuids
{
enum : int {
material,
material_library,
mesh,
point_cloud,
pose,
pose_list,
shader_source,
texture
};
}
using material_id = z3d::identifier<identifier_uuids::material>;
using material_library_id = z3d::identifier<identifier_uuids::material_library>;
using mesh_id = z3d::identifier<identifier_uuids::mesh>;
using point_cloud_id = z3d::identifier<identifier_uuids::point_cloud>;
using pose_id = z3d::identifier<identifier_uuids::pose>;
using pose_list_id = z3d::identifier<identifier_uuids::pose_list>;
using shader_source_id = z3d::identifier<identifier_uuids::shader_source>;
using texture_id = z3d::identifier<identifier_uuids::texture>;
}

View File

@@ -0,0 +1,22 @@
#pragma once
#include "config/primitives.hpp"
namespace assets::model_geometry
{
enum class types : z3d::u8
{
mesh = 0,
point_cloud = 1
};
inline constexpr z3d::size count = 2;
inline constexpr auto names = z3d::array<z3d::string_view, 2>{
"mesh",
"point_cloud"
};
}

View File

@@ -0,0 +1,30 @@
#pragma once
#include "identifiers.hpp"
#include "util/file_id_lookup.hpp"
namespace assets
{
using material_id_lookup = file_id_lookup<material_id>;
using material_library_id_lookup = file_id_lookup<material_library_id>;
using mesh_id_lookup = file_id_lookup<mesh_id>;
using point_cloud_id_lookup = file_id_lookup<point_cloud_id>;
using pose_id_lookup = file_id_lookup<pose_id>;
using pose_list_id_lookup = file_id_lookup<pose_id>;
using shader_source_id_lookup = file_id_lookup<shader_source_id>;
using texture_id_lookup = file_id_lookup<texture_id>;
struct path_id_lookups
{
material_id_lookup materials;
material_library_id_lookup material_libraries;
mesh_id_lookup meshes;
point_cloud_id_lookup point_clouds;
pose_id_lookup poses;
pose_list_id_lookup pose_lists;
shader_source_id_lookup shader_sources;
texture_id_lookup textures;
};
}

View File

@@ -2,7 +2,14 @@
#include <tuple>
#include <array>
#include "glm/gtc/type_aligned.hpp"
#include <vector>
#include <optional>
#include <span>
#include <string_view>
#include <expected>
#include <system_error>
#include "glm/glm.hpp"
#include "util/id_type.hpp"
namespace z3d
@@ -53,10 +60,15 @@ using structure = std::tuple<Ts...>;
using string_view = std::string_view;
template<typename T>
using result = std::expected<T, std::error_code>;
using vertex_index = u32;
using index_triangle = array<vertex_index, 3>;
template<int ID>
using identifier = ztu::id_type<u32, ID>;
}

View File

@@ -1,7 +1,7 @@
#pragma once
#include "assets/data/texture.hpp"
#include "assets/data/surface_properties.hpp"
#include "assets/data/uniform_surface_properties.hpp"
#include "assets/components/material_components.hpp"
#include "opengl/handles/material_handle.hpp"

View File

@@ -17,7 +17,7 @@
#include "opengl/handles/shader_handle_set.hpp"
#include "opengl/shading/requirements/shader_requirements.hpp"
#include "opengl/metadata/shader_set_metadata.hpp"
#include "opengl/shading/requirements/shader_set_requirements.hpp"
#include "opengl/shading/requirements/shader_program_requirements.hpp"
namespace zgl
{
@@ -33,9 +33,9 @@ public:
void process(const store_type& shader_sources);
void get_handles(
void fetch(
const assets::shader_source_store& shader_sources,
std::span<const shading::shader_set_requirements> requirements,
std::span<const shading::shader_program_requirements> requirements,
std::span<shader_set_metadata> metadata,
std::span<shader_handle_set> shader_sets
);
@@ -56,7 +56,7 @@ protected:
std::vector<entry_type> m_shader_lookup{};
private:
std::vector<shading::shader_source_requirements> m_source_requirement_buffer{};
std::vector<shading::shader_requirements> m_source_requirement_buffer{};
std::vector<preprocessed_shader_source_metadata> m_preprocessed_shader_source_metadata_buffer{};
std::vector<const char*> m_source_strings_buffer{};
};

View File

@@ -21,7 +21,7 @@ public:
void process(const store_type& shader_sources);
void get_handles(
void fetch(
const assets::shader_source_store& shader_sources,
std::span<const shading::shader_program_requirements> requirements,
std::span<shader_program_metadata> metadata,
@@ -41,7 +41,7 @@ protected:
std::vector<entry_type> m_shader_program_lookup;
private:
std::vector<shading::shader_set_requirements> m_shader_requirements_buffer;
std::vector<shading::shader_program_requirements> m_shader_requirements_buffer;
std::vector<shader_set_metadata> m_shader_metadata_buffer;
std::vector<shader_handle_set> shader_set_buffer;
};

View File

@@ -9,7 +9,7 @@
#include "util/string_lookup.hpp"
#include "opengl/metadata/shader_source_metadata.hpp"
#include "opengl/shading/requirements/shader_source_requirements.hpp"
#include "opengl/shading/requirements/shader_requirements.hpp"
#include "opengl/metadata/preprocessed_shader_source_metadata.hpp"
#include "assets/data_stores/shader_source_store.hpp"
@@ -30,64 +30,21 @@ public:
void process(const store_type& shader_sources);
void get_shader_sources(
void fetch(
const assets::shader_source_store& shader_sources,
std::span<const shading::shader_source_requirements> requirements,
std::span<const shading::shader_requirements> requirements,
std::span<preprocessed_shader_source_metadata> metadata,
std::vector<const char*>& shader_strings
);
protected:
void tokenize_declarations(std::string_view source);
std::optional<shader_source_metadata> parse_metadata_from_tokens();
[[nodiscard]] static bool parse_stage_declaration(
std::span<const std::string_view> values,
shader_source_metadata& metadata
);
[[nodiscard]] static bool parse_geometry_declaration(
std::span<const std::string_view> tokens,
shader_source_metadata& metadata
);
[[nodiscard]] static bool parse_features_declaration(
std::span<const std::string_view> values,
shader_source_metadata& metadata
);
[[nodiscard]] static bool parse_static_enable_declaration(
std::span<const std::string_view> values,
shader_source_metadata& metadata
);
[[nodiscard]] static bool parse_dynamic_enable_declaration(
std::span<const std::string_view> values,
shader_source_metadata& metadata
);
template<typename T>
static void parse_feature_tokens(
std::span<const std::string_view> values,
const ztu::string_lookup<T>& feature_lookup,
T& features
);
static void get_define_strings(
shading::model_geometry::types geometry,
shading::features::generic::type features,
shading::features::generic::type& feature_count,
assets::model_geometry::types geometry_type,
assets::shader_components::flags components,
assets::shader_components::flags& component_count,
std::vector<const char*>& defines
);
std::vector<entry_type> m_shader_source_lookup;
private:
std::vector<std::string_view> m_value_token_buffer;
std::vector<std::size_t> m_declaration_token_count_buffer;
std::array<std::size_t, 4> m_declaration_type_index_buffer;
};
}

View File

@@ -1,9 +1,7 @@
#pragma once
#include "GL/glew.h"
#include "opengl/shader_uniform.hpp"
#include "opengl/shader_uniform.hpp"
#include "opengl/shading/uniform.hpp"
#include "util/uix.hpp"
#include <span>
@@ -17,12 +15,12 @@ struct shader_program_handle
inline void bind() const;
static void unbind();
template<shader_uniform::info_type VariableInfo, typename T>
template<shading::uniform U, typename T>
void set_uniform(const T& value) const;
[[nodiscard]] attribute_support_type check_attribute_support(std::span<const shader_uniform> attributes) const;
/*[[nodiscard]] attribute_support_type check_attribute_support(std::span<const shader_uniform> attributes) const;
[[nodiscard]] uniform_support_type check_uniform_support(std::span<const shader_uniform> uniforms) const;
[[nodiscard]] uniform_support_type check_uniform_support(std::span<const shader_uniform> uniforms) const;*/
[[nodiscard]] bool valid() const;

View File

@@ -7,9 +7,9 @@ namespace zgl
struct material_metadata
{
texture_handle ambient_color_texture_handle;
texture_handle diffuse_color_texture_handle;
texture_handle specular_color_texture_handle;
texture_handle specular_filter_texture_handle;
texture_handle diffuse_filter_texture_handle;
texture_handle specular_filter_texture_handle;
texture_handle shininess_texture_handle;
texture_handle alpha_texture_handle;
texture_handle bump_texture_handle;

View File

@@ -1,13 +1,15 @@
#pragma once
#include "opengl/shading/features/generic_features.hpp"
#include "assets/components/shader_components.hpp"
namespace zgl
{
struct preprocessed_shader_source_metadata
{
shading::features::generic::type static_enabled{};
shading::features::generic::type dynamic_enable{};
shading::features::generic::type string_count{};
assets::shader_components::flags static_enabled{};
assets::shader_components::flags dynamic_enable{};
// Use same integer type as it guarantees good alignment.
// (even an unsigned byte should hold the maximum number of defines.)
assets::shader_components::flags string_count{};
};
}

View File

@@ -1,16 +1,17 @@
#pragma once
#include "opengl/shading/model_geometry.hpp"
#include "opengl/shading/shader_stage.hpp"
#include "opengl/shading/features/generic_features.hpp"
#include "assets/model_geometry.hpp"
#include "assets/components/shader_components.hpp"
namespace zgl
{
struct shader_metadata
{
shading::model_geometry::types geometry;
shading::stage::types stage;
shading::features::generic::type static_enabled{};
shading::features::generic::type dynamic_enable{};
assets::model_geometry::types geometry_type;
assets::shader_components::stage stage;
assets::shader_components::flags static_enabled{};
assets::shader_components::flags dynamic_enable{};
};
}

View File

@@ -1,15 +1,16 @@
#pragma once
#include "opengl/shading/model_geometry.hpp"
#include "opengl/shading/features/generic_features.hpp"
#include "assets/model_geometry.hpp"
#include "assets/components/shader_components.hpp"
namespace zgl {
namespace zgl
{
struct shader_program_metadata
{
shading::model_geometry::types geometry;
shading::features::generic::type static_enabled{};
shading::features::generic::type dynamic_enable{};
assets::model_geometry::types geometry_type;
assets::shader_components::stage static_enabled{};
assets::shader_components::stage dynamic_enable{};
};
}

View File

@@ -1,12 +1,12 @@
#pragma once
#include "opengl/shading/features/generic_features.hpp"
#include "assets/components/shader_components.hpp"
namespace zgl
{
struct shader_set_metadata
{
shading::features::generic::type static_enabled{};
shading::features::generic::type dynamic_enable{};
assets::shader_components::flags static_enabled{};
assets::shader_components::flags dynamic_enable{};
};
}

View File

@@ -1,91 +1,18 @@
#pragma once
#include <limits>
#include <utility>
#include "assets/model_geometry.hpp"
#include "assets/components/shader_components.hpp"
#include "../shading/model_geometry.hpp"
#include "../shading/shader_stage.hpp"
#include "../shading/features/mesh_features.hpp"
#include "../shading/features/point_cloud_features.hpp"
#include "../shading/features/generic_features.hpp"
#include <algorithm>
// TODO move implementation to .ipp file
namespace zgl
{
template<typename T>
struct shader_features_set
{
T features, static_enable, dynamic_enable;
template<typename U>
[[nodiscard]] shader_features_set<U> cast() const noexcept
{
return {
.features = static_cast<U>(features),
.static_enable = static_cast<U>(static_enable),
.dynamic_enable = static_cast<U>(dynamic_enable)
};
}
// TODO this may not compile
[[nodiscard]] bool operator==(const shader_features_set& other) const noexcept = default;
};
struct shader_source_metadata
{
union combined_feature_set_type {
shader_features_set<shading::features::mesh::flags> mesh;
shader_features_set<shading::features::point_cloud::flags> point_cloud;
};
using generic_feature_set_type = shader_features_set<shading::features::generic::type>;
shading::model_geometry::types geometry;
combined_feature_set_type feature_set;
shading::stage::types stage;
[[nodiscard]] generic_feature_set_type generic_feature_set() const noexcept
{
switch (geometry)
{
case shading::model_geometry::types::mesh:
return feature_set.mesh.cast<shading::features::generic::type>();
case shading::model_geometry::types::point_cloud:
return feature_set.point_cloud.cast<shading::features::generic::type>();
default:
std::unreachable();
}
}
void from_generic_feature_set(const generic_feature_set_type& generic_feature_set) noexcept
{
switch (geometry)
{
case shading::model_geometry::types::mesh:
feature_set.mesh = generic_feature_set.cast<shading::features::mesh::flags>();
case shading::model_geometry::types::point_cloud:
feature_set.point_cloud = generic_feature_set.cast<shading::features::point_cloud::flags>();
}
std::unreachable();
}
bool operator==(const shader_source_metadata& other) const noexcept
{
if (this->stage != other.stage)
{
return false;
}
if (this->geometry != other.geometry)
{
return false;
}
return this->generic_feature_set() == other.generic_feature_set();
}
assets::model_geometry::types geometry_type;
assets::shader_components::stage stage;
assets::shader_components::flags components{};
assets::shader_components::flags static_enable{};
assets::shader_components::flags dynamic_enable{};
};
}

View File

@@ -21,16 +21,18 @@ struct type
namespace indices
{
using type = ztu::u8;
constexpr inline type face = 0;
constexpr inline type line = 1;
constexpr inline type point = 2;
constexpr inline type luminance = 3;
constexpr inline type color = 4;
constexpr inline type alpha = 5;
constexpr inline type lighting = 6;
constexpr inline type texture = 7;
constexpr inline type uniform_color = 8;
enum : z3d::size
{
face,
line,
point,
luminance,
color,
alpha,
lighting,
texture,
uniform_color
};
}
enum class flags : std::uint16_t

View File

@@ -23,14 +23,16 @@ struct type
namespace indices
{
using type = ztu::u8;
constexpr inline type square = 0;
constexpr inline type lighting = 1;
constexpr inline type luminance = 2;
constexpr inline type color = 3;
constexpr inline type alpha = 4;
constexpr inline type uniform_color = 5;
constexpr inline type rainbow = 6;
enum : z3d::size
{
square,
lighting,
luminance,
color,
alpha,
uniform_color,
rainbow
};
}
enum class flags : std::uint8_t

View File

@@ -1,57 +1,14 @@
#pragma once
#include "opengl/shading/model_geometry.hpp"
#include "opengl/shading/features/generic_features.hpp"
#include "assets/model_geometry.hpp"
#include "assets/components/shader_components.hpp"
namespace zgl::shading
{
struct shader_program_requirements
{
model_geometry::types geometry;
features::generic::type features;
assets::model_geometry::types geometry_type;
assets::shader_components::flags components{};
};
}
/*
struct shader_program_metadata
{
using generic_feature_type = std::common_type_t<
std::underlying_type_t<features::mesh::flags>,
std::underlying_type_t<features::point_cloud::flags>
>;
static constexpr auto geometry_bits = static_cast<std::size_t>(std::bit_width(geometry::names.size()));
static constexpr auto feature_bits = sizeof(generic_feature_type) * 8 - geometry_bits;
explicit shader_program_metadata(const features::mesh::flags static_enabled, const features::mesh::flags dynamic_enable) :
shader_program_metadata(
geometry::types::mesh,
static_cast<generic_feature_type>(static_enabled),
static_cast<generic_feature_type>(dynamic_enable)
) {}
explicit shader_program_metadata(const features::point_cloud::flags static_enabled, const features::point_cloud::flags dynamic_enable) :
shader_program_metadata(
geometry::types::point_cloud,
static_cast<generic_feature_type>(static_enabled),
static_cast<generic_feature_type>(dynamic_enable)
) {}
shader_program_metadata(const geometry::types geometry_type, const generic_feature_type static_enabled, generic_feature_type dynamic_enable) :
m_geometry_type{ geometry_type }, m_static_enabled{ static_enabled }, m_dynamic_enable{ dynamic_enable } {}
[[nodiscard]] auto operator<=>(const shader_program_metadata& other) const noexcept
{
return (
std::tie(this->m_geometry_type, std::popcount(this->m_static_enabled), std::popcount(this->m_dynamic_enable)) <=>
std::tie(other.m_geometry_type, std::popcount(other.m_static_enabled), std::popcount(other.m_dynamic_enable))
);
}
[[nodiscard]] bool operator==(const shader_program_metadata& other) const noexcept = default;
geometry::types m_geometry_type : geometry_bits;
generic_feature_type m_static_enabled : feature_bits;
generic_feature_type m_dynamic_enable;
};*/

View File

@@ -1,8 +1,16 @@
#pragma once
#include "shader_source_requirements.hpp"
#include "assets/model_geometry.hpp"
#include "assets/components/shader_components.hpp"
namespace zgl::shading
{
using shader_requirements = shader_source_requirements;
struct shader_requirements
{
assets::model_geometry::types geometry_type;
assets::shader_components::stage stage;
assets::shader_components::flags components{};
};
}

View File

@@ -1,13 +0,0 @@
#pragma once
#include "opengl/shading/features/generic_features.hpp"
namespace zgl::shading
{
struct shader_set_requirements
{
model_geometry::types geometry;
features::generic::type features;
};
}

View File

@@ -1,16 +0,0 @@
#pragma once
#include "opengl/shading/model_geometry.hpp"
#include "opengl/shading/shader_stage.hpp"
#include "opengl/shading/features/generic_features.hpp"
namespace zgl::shading
{
struct shader_source_requirements
{
model_geometry::types geometry;
stage::types stage;
features::generic::type features;
};
}

View File

@@ -11,34 +11,34 @@ namespace zgl::shading::mesh_sampler_uniforms
enum class flags : std::uint16_t
{
none = 0,
ambient_color_texture = 1 << 0,
diffuse_color_texture = 1 << 1,
specular_color_texture = 1 << 2,
specular_filter_texture = 1 << 0,
diffuse_filter_texture = 1 << 1,
specular_filter_texture = 1 << 2,
shininess_texture = 1 << 3,
alpha_texture = 1 << 4,
bump_texture = 1 << 5
};
constexpr inline auto ambient_color_texture = sampler_uniform{ 0 };
constexpr inline auto diffuse_color_texture = sampler_uniform{ 1 };
constexpr inline auto specular_color_texture = sampler_uniform{ 2 };
constexpr inline auto specular_filter_texture = sampler_uniform{ 0 };
constexpr inline auto diffuse_filter_texture = sampler_uniform{ 1 };
constexpr inline auto specular_filter_texture = sampler_uniform{ 2 };
constexpr inline auto shininess_texture = sampler_uniform{ 3 };
constexpr inline auto alpha_texture = sampler_uniform{ 4 };
constexpr inline auto bump_texture = sampler_uniform{ 5 };
constexpr inline auto all = std::array{
ambient_color_texture,
diffuse_color_texture,
specular_color_texture,
specular_filter_texture,
diffuse_filter_texture,
specular_filter_texture,
shininess_texture,
alpha_texture,
bump_texture
};
constexpr inline auto names = std::array{
"ambient_color_texture",
"diffuse_color_texture",
"specular_color_texture",
"specular_filter_texture",
"diffuse_filter_texture",
"specular_filter_texture",
"shininess_texture",
"alpha_texture",
"bump_texture"

View File

@@ -0,0 +1,104 @@
#pragma once
#include <unordered_map>
#include <filesystem>
#include <ranges>
#include <vector>
template<typename ID>
class file_id_lookup
{
public:
using container_type = std::unordered_map<std::filesystem::path, ID>;
using key_type = typename container_type::key_type;
using mapped_type = typename container_type::mapped_type;
using value_type = typename container_type::value_type;
using size_type = typename container_type::size_type;
using difference_type = typename container_type::difference_type;
using hasher = typename container_type::hasher;
using key_equal = typename container_type::key_equal;
using allocator_type = typename container_type::allocator_type;
using reference = typename container_type::reference;
using const_reference = typename container_type::const_reference;
using pointer = typename container_type::pointer;
using const_pointer = typename container_type::const_pointer;
using iterator = typename container_type::iterator;
using const_iterator = typename container_type::const_iterator;
using local_iterator = typename container_type::local_iterator;
using const_local_iterator = typename container_type::const_local_iterator;
using node_type = typename container_type::node_type;
using insert_return_type = typename container_type::insert_return_type;
[[nodiscard]] iterator begin() noexcept { return m_container.begin(); }
[[nodiscard]] const_iterator begin() const noexcept { return m_container.begin(); }
[[nodiscard]] const_iterator cbegin() const noexcept { return m_container.cbegin(); }
[[nodiscard]] iterator end() noexcept { return m_container.end(); }
[[nodiscard]] const_iterator end() const noexcept { return m_container.end(); }
[[nodiscard]] const_iterator cend() const noexcept { return m_container.cend(); }
[[nodiscard]] bool empty() const noexcept { return m_container.empty(); }
[[nodiscard]] size_type size() const noexcept { return m_container.size(); }
[[nodiscard]] size_type max_size() const noexcept { return m_container.max_size(); }
void by_extension(
const std::string_view extension,
std::vector<const_pointer>& dst
) const {
std::ranges::copy(
m_container |
std::views::filter(
[&](const value_type& entry)
{
return entry.first.extension() == extension;
}
) |
std::views::transform(
[&](const value_type& entry)
{
return &entry;
}
),
std::back_inserter(dst)
);
}
std::pair<iterator, bool> try_emplace(const key_type& path)
{
auto it = m_container.find(path);
const auto is_new = it == m_container.end();
if (not is_new)
{
it = m_container.emplace_hint(it, path, ID::next());
}
return { it, is_new };
}
[[nodiscard]] bool contains(const key_type& key) const { return m_container.contains(key); }
[[nodiscard]] size_type count(const key_type& key) const { return m_container.count(key); }
[[nodiscard]] iterator find(const key_type& key) { return m_container.find(key); }
[[nodiscard]] const_iterator find(const key_type& key) const { return m_container.find(key); }
iterator erase(iterator pos) { return m_container.erase(pos); }
iterator erase(const_iterator pos) { return m_container.erase(pos); }
iterator erase(const_iterator first, const_iterator last) { return m_container.erase(first, last); }
size_type erase(const key_type& key) { return m_container.erase(key); }
void clear() noexcept { m_container.clear(); }
private:
static auto extension_filter(const std::string_view& extension)
{
return std::views::filter(
[extension](const key_type& path)
{
return path.extension() == extension;
}
);
}
container_type m_container;
};