This commit is contained in:
ZY4N
2025-03-23 21:11:22 +01:00
parent 510398423a
commit c609d49f0d
49 changed files with 1412 additions and 924 deletions

View File

@@ -0,0 +1,36 @@
#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,32 @@
#pragma once
#include "assets/dynamic_data_stores/dynamic_mesh_store.hpp"
#include "opengl/resource_management/resource_manager.hpp"
#include "opengl/handles/vertex_buffer_handle.hpp"
#include "opengl/metadata/vertex_buffer_metadata.hpp"
namespace zgl
{
class mesh_vertex_buffer_manager
{
public:
using store_type = dynamic_mesh_store;
using store_id_type = store_type::id_type;
using metadata_type = vertex_buffer_metadata;
using handle_type = vertex_buffer_handle;
using resource_manager_type = resource_manager<store_id_type, metadata_type>;
using texture_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<texture_entry_type> get_handle(store_id_type id);
void collect_garbage(bool force = false);
private:
resource_manager_type m_resource_manager;
};
}

View File

@@ -0,0 +1,58 @@
#pragma once
#include <unordered_map>
#include <bit>
#include <format>
#include <ranges>
#include <bits/ranges_algo.h>
#include "assets/dynamic_data_stores/dynamic_shader_source_store.hpp"
#include "opengl/shader_program_lookup.hpp"
#include "opengl/handles/shader_handle.hpp"
#include "util/string_lookup.hpp"
#include "shader_source_manager.hpp"
#include "opengl/metadata/shader_metadata.hpp"
#include "opengl/data/shader_data.hpp"
#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"
namespace zgl
{
class shader_manager
{
using shader_lookup_entry_type = std::pair<shader_metadata, shader_data>;
public:
void process(
const dynamic_shader_source_store& shader_sources
);
void get_handles(
const dynamic_shader_source_store& shader_sources,
std::span<const shading::shader_set_requirements> requirements,
std::span<shader_set_metadata> metadata,
std::span<shader_handle_set> shader_sets
);
protected:
std::optional<std::pair<shader_metadata, shader_handle>> find_shader(
const shading::shader_requirements& requirements
);
static bool compile_shader(
GLenum shader_type,
std::span<const char*> source_strings,
shader_data& shader
);
private:
shader_source_manager m_preprocessor{};
std::vector<shading::shader_source_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{};
std::vector<shader_lookup_entry_type> m_shader_lookup{};
};
}

View File

@@ -0,0 +1,50 @@
#pragma once
#include "shader_manager.hpp"
#include "assets/dynamic_data_stores/dynamic_shader_source_store.hpp"
#include "opengl/data/shader_program_data.hpp"
#include "opengl/shading/requirements/shader_program_requirements.hpp"
#include "opengl/metadata/shader_program_metadata.hpp"
namespace zgl
{
class shader_program_manager
{
using shader_program_lookup_entry_type = std::pair<
shader_program_metadata,
shader_program_data
>;
public:
void process(
const dynamic_shader_source_store& shader_sources
);
void get_handles(
const dynamic_shader_source_store& shader_sources,
std::span<const shading::shader_program_requirements> requirements,
std::span<shader_program_metadata> metadata,
std::span<shader_program_handle> shader_programs
);
protected:
std::optional<std::pair<shader_program_metadata, shader_program_handle>> find_shader_program(
const shading::shader_program_requirements& requirements
);
bool link_shader_program(
const shader_handle_set& shaders
);
shader_manager m_shader_manager;
std::vector<shader_program_lookup_entry_type> m_shader_program_lookup;
private:
std::vector<shading::shader_set_requirements> m_shader_requirements_buffer;
std::vector<shader_set_metadata> m_shader_metadata_buffer;
std::vector<shader_handle_set> shader_set_buffer;
};
}

View File

@@ -0,0 +1,87 @@
#pragma once
#include <string_view>
#include <vector>
#include <optional>
#include <span>
#include "util/string_lookup.hpp"
#include "../metadata/shader_source_metadata.hpp"
#include "opengl/shading/requirements/shader_source_requirements.hpp"
#include "opengl/metadata/preprocessed_shader_source_metadata.hpp"
#include "assets/dynamic_data_stores/dynamic_shader_source_store.hpp"
#include "opengl/shading/shader_source_set.hpp"
namespace zgl {
class shader_source_manager {
public:
void process(
const dynamic_shader_source_store& shader_sources
);
void get_shader_sources(
const dynamic_shader_source_store& shader_sources,
std::span<const shading::shader_source_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,
std::vector<const char*>& defines
);
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;
using source_lookup_entry_type = std::pair<shader_source_metadata, dynamic_shader_source_store::id_type>;
using source_lookup_type = std::vector<source_lookup_entry_type>;
source_lookup_type m_shader_source_lookup;
};
}

View File

@@ -0,0 +1,41 @@
#pragma once
#include <unordered_map>
#include "assets/dynamic_read_buffers/dynamic_texture_buffer.hpp"
#include "assets/dynamic_data_stores/dynamic_texture_store.hpp"
#include "opengl/handles/texture_handle.hpp"
#include <vector>
#include "opengl/metadata/texture_metadata.hpp"
#include "opengl/resource_management/resource_manager.hpp"
namespace zgl
{
class texture_manager
{
public:
using store_type = dynamic_texture_store;
using store_id_type = store_type::id_type;
using metadata_type = texture_metadata;
using handle_type = texture_handle;
using resource_manager_type = resource_manager<store_id_type, metadata_type>;
using texture_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<texture_entry_type> get_handle(store_id_type id);
void collect_garbage(bool force = false);
private:
resource_manager_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;
};
}