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

View File

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

View File

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

View File

@@ -39,13 +39,13 @@ public:
[[nodiscard]] point_cloud_handle handle() const;
[[nodiscard]] components::point_cloud_vertex::flags components() const;
[[nodiscard]] point_cloud_vertex_components::flags components() const;
private:
point_cloud_handle m_handle{};
GLuint m_vertex_vbo_id{ 0 };
components::point_cloud_vertex::flags m_component_types{
components::point_cloud_vertex::flags::none
point_cloud_vertex_components::flags m_component_types{
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
#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/handles/vertex_buffer_handle.hpp"
#include "opengl/metadata/vertex_buffer_metadata.hpp"
#include "opengl/metadata/mesh_vertex_buffer_metadata.hpp"
namespace zgl
{
class mesh_vertex_buffer_manager
{
public:
using store_type = dynamic_mesh_store;
using store_type = assets::mesh_store;
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 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;
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);
private:
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;
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 <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/handles/shader_handle.hpp"
#include "util/string_lookup.hpp"
@@ -26,11 +26,11 @@ class shader_manager
public:
void process(
const dynamic_shader_source_store& shader_sources
const assets::shader_source_store& shader_sources
);
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<shader_set_metadata> metadata,
std::span<shader_handle_set> shader_sets

View File

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

View File

@@ -6,11 +6,11 @@
#include <span>
#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/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"
namespace zgl {
@@ -19,11 +19,11 @@ class shader_source_manager {
public:
void process(
const dynamic_shader_source_store& shader_sources
const assets::shader_source_store& 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<preprocessed_shader_source_metadata> metadata,
std::vector<const char*>& shader_strings
@@ -79,7 +79,7 @@ private:
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_entry_type = std::pair<shader_source_metadata, assets::shader_source_store::id_type>;
using source_lookup_type = std::vector<source_lookup_entry_type>;
source_lookup_type m_shader_source_lookup;

View File

@@ -2,8 +2,8 @@
#include <unordered_map>
#include "assets/dynamic_read_buffers/dynamic_texture_buffer.hpp"
#include "assets/dynamic_data_stores/dynamic_texture_store.hpp"
#include "../../assets/read_buffers"
#include "../../assets/data_stores"
#include "opengl/handles/texture_handle.hpp"
#include <vector>
@@ -20,20 +20,20 @@ public:
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>;
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<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);
private:
protected:
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<GLuint> m_texture_id_buffer;
};

View File

@@ -2,6 +2,7 @@
#include "opengl/resource_management/resource_handle.hpp"
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
{
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...
);
};
}