From 6f60cc11c812c46522a20fc36b22a60bdb1af036 Mon Sep 17 00:00:00 2001 From: ZY4N Date: Thu, 27 Mar 2025 19:47:32 +0100 Subject: [PATCH] std140 implementation --- CMakeLists.txt | 12 +- .../generic/generic_material_store.hpp | 2 +- .../generic/generic_mesh_store.hpp | 2 +- .../generic/generic_point_cloud_store.hpp | 2 +- .../opengl/data_managers/material_manager.hpp | 41 ++ .../mesh_index_buffer_manager.hpp | 2 +- .../mesh_vertex_buffer_manager.hpp | 2 +- .../point_cloud_vertex_buffer_manager.hpp | 2 +- .../opengl/data_managers/shader_manager.hpp | 6 +- .../data_managers/shader_program_manager.hpp | 3 +- .../data_managers/shader_source_manager.hpp | 2 +- .../opengl/data_managers/texture_manager.hpp | 2 +- include/opengl/handles/material_handle.hpp | 9 +- .../opengl/handles/shader_program_handle.hpp | 10 +- include/opengl/metadata/material_metadata.hpp | 18 + .../uniform_buffer_alignment_metadata.hpp | 17 + include/opengl/shader_program_lookup.hpp | 8 +- include/opengl/shader_program_variable.hpp | 16 - .../shading/attributes/mesh_attributes.hpp | 14 +- .../attributes/point_cloud_attributes.hpp | 12 +- include/opengl/shading/sampler_uniform.hpp | 13 + .../mesh_samplers_uniforms.hpp | 48 +++ include/opengl/shading/uniform.hpp | 14 + include/opengl/shading/uniform_block.hpp | 13 + .../uniform_blocks/mesh_uniform_blocks.hpp | 33 ++ .../point_cloud_uniform_blocks.hpp | 32 ++ .../opengl/shading/uniforms/mesh_uniforms.hpp | 32 +- .../shading/uniforms/point_cloud_uniforms.hpp | 20 +- include/opengl/type_utils.hpp | 371 +++++++++++++++++- include/opengl/types.hpp | 30 ++ include/opengl/vertex_buffer_utils.hpp | 88 ----- shaders/fragment_mesh_face.glsl | 44 ++- shaders/vertex_mesh_face.glsl | 4 +- shaders/vertex_mesh_point.glsl | 5 + shaders/vertex_point_cloud.glsl | 4 + .../mesh_index_buffer_manager.cpp | 4 +- .../mesh_vertex_buffer_manager.cpp | 20 +- .../point_cloud_vertex_buffer_manager.cpp | 20 +- .../opengl/data_managers/shader_manager.cpp | 11 +- .../data_managers/shader_program_manager.cpp | 7 +- .../data_managers/shader_source_manager.cpp | 7 +- .../opengl/data_managers/texture_manager.cpp | 7 +- .../opengl/handles/shader_program_handle.cpp | 4 +- .../opengl/handles/shader_program_handle.ipp | 2 +- source/opengl/shader_program_lookup.cpp | 8 +- 45 files changed, 789 insertions(+), 234 deletions(-) create mode 100644 include/opengl/data_managers/material_manager.hpp create mode 100644 include/opengl/metadata/material_metadata.hpp create mode 100644 include/opengl/metadata/uniform_buffer_alignment_metadata.hpp delete mode 100644 include/opengl/shader_program_variable.hpp create mode 100644 include/opengl/shading/sampler_uniform.hpp create mode 100644 include/opengl/shading/sampler_uniforms/mesh_samplers_uniforms.hpp create mode 100644 include/opengl/shading/uniform.hpp create mode 100644 include/opengl/shading/uniform_block.hpp create mode 100644 include/opengl/shading/uniform_blocks/mesh_uniform_blocks.hpp create mode 100644 include/opengl/shading/uniform_blocks/point_cloud_uniform_blocks.hpp create mode 100644 include/opengl/types.hpp delete mode 100644 include/opengl/vertex_buffer_utils.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e29a054..5ab01ad 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,7 +59,7 @@ add_executable(z3d main.cpp include/rendering/batch_renderers/point_cloud_batch_renderer.hpp source/rendering/batches/mesh_batch.ipp source/rendering/batches/point_cloud_batch.ipp - include/opengl/shader_program_variable.hpp + include/opengl/shading/uniform.hpp include/opengl/type_utils.hpp include/util/binary_ifstream.hpp source/assets/file_parsers/kitti_loader.cpp @@ -204,7 +204,6 @@ add_executable(z3d main.cpp include/opengl/handles/index_buffer_handle.hpp source/opengl/handles/index_buffer_handle.ipp include/opengl/metadata/texture_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 @@ -224,6 +223,15 @@ add_executable(z3d main.cpp 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 + include/opengl/data_managers/material_manager.hpp + include/opengl/metadata/uniform_buffer_alignment_metadata.hpp + include/opengl/types.hpp + include/opengl/metadata/material_metadata.hpp + include/opengl/shading/sampler_uniforms/mesh_samplers_uniforms.hpp + include/opengl/shading/sampler_uniform.hpp + include/opengl/shading/uniform_block.hpp + include/opengl/shading/uniform_blocks/mesh_uniform_blocks.hpp + include/opengl/shading/uniform_blocks/point_cloud_uniform_blocks.hpp ) target_include_directories(z3d PRIVATE include) diff --git a/include/assets/data_stores/generic/generic_material_store.hpp b/include/assets/data_stores/generic/generic_material_store.hpp index 6e162d8..7a40c33 100644 --- a/include/assets/data_stores/generic/generic_material_store.hpp +++ b/include/assets/data_stores/generic/generic_material_store.hpp @@ -18,7 +18,7 @@ public: using size_type = std::size_t; using count_type = ztu::u32; using component_flag_type = material_components::flags; - using id_type = ztu::id_type_for, ztu::u32>; + using id_type = ztu::id_type_for...>, ztu::u32>; using value_type = std::pair; using flag_count_type = std::tuple; diff --git a/include/assets/data_stores/generic/generic_mesh_store.hpp b/include/assets/data_stores/generic/generic_mesh_store.hpp index 3ab9bf0..f61f0f1 100644 --- a/include/assets/data_stores/generic/generic_mesh_store.hpp +++ b/include/assets/data_stores/generic/generic_mesh_store.hpp @@ -20,7 +20,7 @@ public: 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, ztu::u32>; + using id_type = ztu::id_type_for>, ztu::u32>; using value_type = std::pair; using flag_count_type = std::tuple; diff --git a/include/assets/data_stores/generic/generic_point_cloud_store.hpp b/include/assets/data_stores/generic/generic_point_cloud_store.hpp index c7fa9bf..e201fe9 100644 --- a/include/assets/data_stores/generic/generic_point_cloud_store.hpp +++ b/include/assets/data_stores/generic/generic_point_cloud_store.hpp @@ -22,7 +22,7 @@ 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, ztu::u32>; + using id_type = ztu::id_type_for...>, ztu::u32>; using value_type = std::pair; using flag_count_type = std::tuple; diff --git a/include/opengl/data_managers/material_manager.hpp b/include/opengl/data_managers/material_manager.hpp new file mode 100644 index 0000000..fea5db1 --- /dev/null +++ b/include/opengl/data_managers/material_manager.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include "assets/data/material_data.hpp" +#include "assets/data_stores/material_store.hpp" +#include "opengl/handles/material_handle.hpp" +#include + +#include "assets/data_stores.hpp" +#include "opengl/metadata/material_metadata.hpp" +#include "opengl/resource_management/resource_manager.hpp" + +namespace zgl +{ +class material_manager +{ +public: + using store_type = assets::material_store; + using store_id_type = store_type::id_type; + using metadata_type = material_metadata; + using handle_type = material_handle; + using resource_manager_type = resource_manager; + // TODO add reference and const_reference + using entry_type = std::pair; + + static constexpr std::size_t min_garbage_collection_count = 4; + + void process(const store_type& materials); + + std::optional get_handle(store_id_type id); + + void collect_garbage(bool force = false); + +protected: + resource_manager_type m_resource_manager; + +private: + std::vector> m_material_buffer; + std::vector m_material_id_buffer; +}; + +} diff --git a/include/opengl/data_managers/mesh_index_buffer_manager.hpp b/include/opengl/data_managers/mesh_index_buffer_manager.hpp index 43bfe8d..9a7dc91 100644 --- a/include/opengl/data_managers/mesh_index_buffer_manager.hpp +++ b/include/opengl/data_managers/mesh_index_buffer_manager.hpp @@ -20,7 +20,7 @@ public: static constexpr std::size_t min_garbage_collection_count = 4; - void process(const assets::data_stores& stores); + void process(const store_type& meshes); std::optional get_handle(store_id_type id); diff --git a/include/opengl/data_managers/mesh_vertex_buffer_manager.hpp b/include/opengl/data_managers/mesh_vertex_buffer_manager.hpp index bfede74..64e4523 100644 --- a/include/opengl/data_managers/mesh_vertex_buffer_manager.hpp +++ b/include/opengl/data_managers/mesh_vertex_buffer_manager.hpp @@ -21,7 +21,7 @@ public: static constexpr std::size_t min_garbage_collection_count = 4; - void process(const assets::data_stores& stores); + void process(const store_type& meshes); std::optional get_handle(store_id_type id); diff --git a/include/opengl/data_managers/point_cloud_vertex_buffer_manager.hpp b/include/opengl/data_managers/point_cloud_vertex_buffer_manager.hpp index 6005b01..71fcac7 100644 --- a/include/opengl/data_managers/point_cloud_vertex_buffer_manager.hpp +++ b/include/opengl/data_managers/point_cloud_vertex_buffer_manager.hpp @@ -21,7 +21,7 @@ public: static constexpr std::size_t min_garbage_collection_count = 4; - void process(const assets::data_stores& stores); + void process(const store_type& point_clouds); std::optional get_handle(store_id_type id); diff --git a/include/opengl/data_managers/shader_manager.hpp b/include/opengl/data_managers/shader_manager.hpp index 02e34de..632915b 100644 --- a/include/opengl/data_managers/shader_manager.hpp +++ b/include/opengl/data_managers/shader_manager.hpp @@ -23,15 +23,15 @@ namespace zgl { class shader_manager { +public: + using store_type = shader_source_manager::store_type; using metadata_type = shader_metadata; using data_type = shader_data; using handle_type = shader_handle; using entry_type = std::pair; using entry_view_type = std::pair; -public: - - void process(const assets::data_stores& stores); + void process(const store_type& shader_sources); void get_handles( const assets::shader_source_store& shader_sources, diff --git a/include/opengl/data_managers/shader_program_manager.hpp b/include/opengl/data_managers/shader_program_manager.hpp index e14a1c3..f422cb2 100644 --- a/include/opengl/data_managers/shader_program_manager.hpp +++ b/include/opengl/data_managers/shader_program_manager.hpp @@ -12,13 +12,14 @@ namespace zgl class shader_program_manager { public: + using store_type = shader_manager::store_type; using metadata_type = shader_program_metadata; using data_type = shader_program_data; using handle_type = shader_program_handle; using entry_type = std::pair; using entry_view_type = std::pair; - void process(const assets::data_stores& stores); + void process(const store_type& shader_sources); void get_handles( const assets::shader_source_store& shader_sources, diff --git a/include/opengl/data_managers/shader_source_manager.hpp b/include/opengl/data_managers/shader_source_manager.hpp index 37325a0..6e145f5 100644 --- a/include/opengl/data_managers/shader_source_manager.hpp +++ b/include/opengl/data_managers/shader_source_manager.hpp @@ -28,7 +28,7 @@ public: using entry_type = std::pair; using entry_view_type = std::pair; - void process(const assets::data_stores& stores); + void process(const store_type& shader_sources); void get_shader_sources( const assets::shader_source_store& shader_sources, diff --git a/include/opengl/data_managers/texture_manager.hpp b/include/opengl/data_managers/texture_manager.hpp index 83ccdf6..eb760ed 100644 --- a/include/opengl/data_managers/texture_manager.hpp +++ b/include/opengl/data_managers/texture_manager.hpp @@ -25,7 +25,7 @@ public: static constexpr std::size_t min_garbage_collection_count = 4; - void process(const assets::data_stores& stores); + void process(const store_type& textures); std::optional get_handle(store_id_type id); diff --git a/include/opengl/handles/material_handle.hpp b/include/opengl/handles/material_handle.hpp index ce420df..99e1d4b 100644 --- a/include/opengl/handles/material_handle.hpp +++ b/include/opengl/handles/material_handle.hpp @@ -7,10 +7,11 @@ namespace zgl { -struct material_handle +// TODO implement +struct material_handle : resource_handle { - std::optional texture{ std::nullopt }; - std::optional surface_properties{ std::nullopt }; - std::optional alpha{ std::nullopt }; + inline void bind() const; + inline static void unbind(); }; + } diff --git a/include/opengl/handles/shader_program_handle.hpp b/include/opengl/handles/shader_program_handle.hpp index 5a3d9af..d0b2dec 100644 --- a/include/opengl/handles/shader_program_handle.hpp +++ b/include/opengl/handles/shader_program_handle.hpp @@ -1,9 +1,9 @@ #pragma once #include "GL/glew.h" -#include "opengl/shader_program_variable.hpp" +#include "opengl/shader_uniform.hpp" -#include "opengl/shader_program_variable.hpp" +#include "opengl/shader_uniform.hpp" #include "util/uix.hpp" #include @@ -17,12 +17,12 @@ struct shader_program_handle inline void bind() const; static void unbind(); - template + template void set_uniform(const T& value) const; - [[nodiscard]] attribute_support_type check_attribute_support(std::span attributes) const; + [[nodiscard]] attribute_support_type check_attribute_support(std::span attributes) const; - [[nodiscard]] uniform_support_type check_uniform_support(std::span uniforms) const; + [[nodiscard]] uniform_support_type check_uniform_support(std::span uniforms) const; [[nodiscard]] bool valid() const; diff --git a/include/opengl/metadata/material_metadata.hpp b/include/opengl/metadata/material_metadata.hpp new file mode 100644 index 0000000..c2dc08a --- /dev/null +++ b/include/opengl/metadata/material_metadata.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include "opengl/handles/texture_handle.hpp" + +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 shininess_texture_handle; + texture_handle alpha_texture_handle; + texture_handle bump_texture_handle; +}; + +} diff --git a/include/opengl/metadata/uniform_buffer_alignment_metadata.hpp b/include/opengl/metadata/uniform_buffer_alignment_metadata.hpp new file mode 100644 index 0000000..22f0e33 --- /dev/null +++ b/include/opengl/metadata/uniform_buffer_alignment_metadata.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include +#include + +namespace zgl +{ + +template +struct uniform_buffer_alignment_metadata +{ + std::array byte_offsets{}; + std::size_t byte_size{}; +}; + + +} diff --git a/include/opengl/shader_program_lookup.hpp b/include/opengl/shader_program_lookup.hpp index b6b0061..abb7810 100644 --- a/include/opengl/shader_program_lookup.hpp +++ b/include/opengl/shader_program_lookup.hpp @@ -10,14 +10,14 @@ class shader_program_lookup public: void add( const shader_program_handle& shader_program_handle, - std::span all_attributes, - std::span all_uniforms + std::span all_attributes, + std::span all_uniforms ); [[nodiscard]] std::optional find( shader_program_handle::attribute_support_type attributes, shader_program_handle::uniform_support_type uniforms, - std::span all_attributes + std::span all_attributes ) const; void print(); @@ -27,7 +27,7 @@ private: [[nodiscard]] static attribute_locations_type attribute_location_flags( shader_program_handle::attribute_support_type attributes, - std::span all_attributes + std::span all_attributes ); struct attribute_entry_type diff --git a/include/opengl/shader_program_variable.hpp b/include/opengl/shader_program_variable.hpp deleted file mode 100644 index 63def71..0000000 --- a/include/opengl/shader_program_variable.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "GL/glew.h" - -namespace zgl -{ -struct shader_program_variable -{ - struct info_type - { - GLenum type; - GLint location; - } info; - const char* name; -}; -} diff --git a/include/opengl/shading/attributes/mesh_attributes.hpp b/include/opengl/shading/attributes/mesh_attributes.hpp index 32f3af4..0ab9dfc 100644 --- a/include/opengl/shading/attributes/mesh_attributes.hpp +++ b/include/opengl/shading/attributes/mesh_attributes.hpp @@ -1,6 +1,6 @@ #pragma once -#include "opengl/shader_program_variable.hpp" +#include "opengl/shader_uniform.hpp" #include "util/enum_bitfield_operators.hpp" #include @@ -20,12 +20,12 @@ enum class flags : std::uint8_t tex_coord = 1 << 5 }; -constexpr inline auto position = shader_program_variable({ GL_FLOAT_VEC3, 0 }, "model_vertex_position"); -constexpr inline auto normal = shader_program_variable({ GL_FLOAT_VEC3, 1 }, "model_vertex_normal"); -constexpr inline auto luminance = shader_program_variable({ GL_FLOAT, 2 }, "model_vertex_l"); -constexpr inline auto color = shader_program_variable({ GL_FLOAT_VEC3, 2 }, "model_vertex_rgb"); -constexpr inline auto alpha = shader_program_variable({ GL_FLOAT, 3 }, "model_vertex_a"); -constexpr inline auto tex_coord = shader_program_variable({ GL_FLOAT_VEC2, 2 }, "model_vertex_tex_coord"); +constexpr inline auto position = shader_uniform({ GL_FLOAT_VEC3, 0 }, "model_vertex_position"); +constexpr inline auto normal = shader_uniform({ GL_FLOAT_VEC3, 1 }, "model_vertex_normal"); +constexpr inline auto luminance = shader_uniform({ GL_FLOAT, 2 }, "model_vertex_l"); +constexpr inline auto color = shader_uniform({ GL_FLOAT_VEC3, 2 }, "model_vertex_rgb"); +constexpr inline auto alpha = shader_uniform({ GL_FLOAT, 3 }, "model_vertex_a"); +constexpr inline auto tex_coord = shader_uniform({ GL_FLOAT_VEC2, 2 }, "model_vertex_tex_coord"); constexpr inline auto all = std::array{ position, normal, luminance, color, alpha, tex_coord diff --git a/include/opengl/shading/attributes/point_cloud_attributes.hpp b/include/opengl/shading/attributes/point_cloud_attributes.hpp index 05b5dc6..749ac25 100644 --- a/include/opengl/shading/attributes/point_cloud_attributes.hpp +++ b/include/opengl/shading/attributes/point_cloud_attributes.hpp @@ -1,6 +1,6 @@ #pragma once -#include "opengl/shader_program_variable.hpp" +#include "opengl/shader_uniform.hpp" #include #include "util/enum_bitfield_operators.hpp" #include @@ -18,11 +18,11 @@ enum class flags : std::uint8_t alpha = 1 << 3 }; -constexpr inline auto position = shader_program_variable({ GL_FLOAT_VEC3, 0 }, "model_vertex_position"); -constexpr inline auto normal = shader_program_variable({ GL_FLOAT_VEC3, 1 }, "model_vertex_normal"); -constexpr inline auto luminance = shader_program_variable({ GL_FLOAT_VEC3, 1 }, "model_vertex_l"); -constexpr inline auto color = shader_program_variable({ GL_FLOAT_VEC3, 1 }, "model_vertex_rgb"); -constexpr inline auto alpha = shader_program_variable({ GL_FLOAT_VEC3, 1 }, "model_vertex_a"); +constexpr inline auto position = shader_uniform({ GL_FLOAT_VEC3, 0 }, "model_vertex_position"); +constexpr inline auto normal = shader_uniform({ GL_FLOAT_VEC3, 1 }, "model_vertex_normal"); +constexpr inline auto luminance = shader_uniform({ GL_FLOAT_VEC3, 1 }, "model_vertex_l"); +constexpr inline auto color = shader_uniform({ GL_FLOAT_VEC3, 1 }, "model_vertex_rgb"); +constexpr inline auto alpha = shader_uniform({ GL_FLOAT_VEC3, 1 }, "model_vertex_a"); constexpr inline auto all = std::array{ position, normal, luminance, color, alpha diff --git a/include/opengl/shading/sampler_uniform.hpp b/include/opengl/shading/sampler_uniform.hpp new file mode 100644 index 0000000..5a4978a --- /dev/null +++ b/include/opengl/shading/sampler_uniform.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include "GL/glew.h" + +namespace zgl::shading +{ + +struct sampler_uniform +{ + GLenum binding_location; +}; + +} diff --git a/include/opengl/shading/sampler_uniforms/mesh_samplers_uniforms.hpp b/include/opengl/shading/sampler_uniforms/mesh_samplers_uniforms.hpp new file mode 100644 index 0000000..7baa5a3 --- /dev/null +++ b/include/opengl/shading/sampler_uniforms/mesh_samplers_uniforms.hpp @@ -0,0 +1,48 @@ +#pragma once + +#include "opengl/shading/sampler_uniform.hpp" +#include + +#include "util/enum_bitfield_operators.hpp" + +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, + 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 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, + shininess_texture, + alpha_texture, + bump_texture +}; + +constexpr inline auto names = std::array{ + "ambient_color_texture", + "diffuse_color_texture", + "specular_color_texture", + "shininess_texture", + "alpha_texture", + "bump_texture" +}; +} + +DEFINE_ENUM_BITFIELD_OPERATORS(zgl::shading::mesh_sampler_uniforms::flags) diff --git a/include/opengl/shading/uniform.hpp b/include/opengl/shading/uniform.hpp new file mode 100644 index 0000000..9b48b0d --- /dev/null +++ b/include/opengl/shading/uniform.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include "GL/glew.h" + +namespace zgl::shading +{ + +struct uniform +{ + GLenum type; + GLint location; +}; + +} diff --git a/include/opengl/shading/uniform_block.hpp b/include/opengl/shading/uniform_block.hpp new file mode 100644 index 0000000..7b6dc5c --- /dev/null +++ b/include/opengl/shading/uniform_block.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include "GL/glew.h" + +namespace zgl::shading +{ + +struct uniform_block +{ + GLenum binding_location; +}; + +} diff --git a/include/opengl/shading/uniform_blocks/mesh_uniform_blocks.hpp b/include/opengl/shading/uniform_blocks/mesh_uniform_blocks.hpp new file mode 100644 index 0000000..c8c02cb --- /dev/null +++ b/include/opengl/shading/uniform_blocks/mesh_uniform_blocks.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include "opengl/shading/uniform_block.hpp" +#include + +#include "util/enum_bitfield_operators.hpp" + +namespace zgl::shading::mesh_uniform_blocks +{ + +enum class flags : std::uint16_t +{ + none = 0, + material = 1 << 0, + lighting = 1 << 1 +}; + +constexpr inline auto material = uniform_block{ 0 }; +constexpr inline auto lighting = uniform_block{ 1 }; + +constexpr inline auto all = std::array{ + material, + lighting +}; + +constexpr inline auto names = std::array{ + "material", + "lighting" +}; + +} + +DEFINE_ENUM_BITFIELD_OPERATORS(zgl::shading::mesh_uniform_blocks::flags) diff --git a/include/opengl/shading/uniform_blocks/point_cloud_uniform_blocks.hpp b/include/opengl/shading/uniform_blocks/point_cloud_uniform_blocks.hpp new file mode 100644 index 0000000..040c41c --- /dev/null +++ b/include/opengl/shading/uniform_blocks/point_cloud_uniform_blocks.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include "opengl/shading/uniform_block.hpp" +#include + +#include "util/enum_bitfield_operators.hpp" + +namespace zgl::shading::point_cloud_uniform_blocks +{ + +enum class flags : std::uint16_t +{ + none = 0, + material = 1 << 0, + lighting = 1 << 1 +}; + +constexpr inline auto material = uniform_block{ 0 }; +constexpr inline auto lighting = uniform_block{ 1 }; + +constexpr inline auto all = std::array{ + material, + lighting +}; + +constexpr inline auto names = std::array{ + "material", + "lighting" +}; +} + +DEFINE_ENUM_BITFIELD_OPERATORS(zgl::shading::point_cloud_uniform_blocks::flags) diff --git a/include/opengl/shading/uniforms/mesh_uniforms.hpp b/include/opengl/shading/uniforms/mesh_uniforms.hpp index 2d9a966..e52a39e 100644 --- a/include/opengl/shading/uniforms/mesh_uniforms.hpp +++ b/include/opengl/shading/uniforms/mesh_uniforms.hpp @@ -1,10 +1,10 @@ #pragma once -#include "opengl/shader_program_variable.hpp" +#include "opengl/shading/uniform_types/uniform.hpp" #include #include "util/enum_bitfield_operators.hpp" -namespace zgl::shading::uniforms::mesh +namespace zgl::shading::mesh_uniforms { enum class flags : std::uint16_t @@ -25,19 +25,19 @@ enum class flags : std::uint16_t shininess = 1 << 12 }; -constexpr inline auto mvp_matrix = shader_program_variable({ GL_FLOAT_MAT4, 0 }, "mvp_matrix"); -constexpr inline auto model_matrix = shader_program_variable({ GL_FLOAT_MAT4, 1 }, "model_matrix"); -constexpr inline auto point_size = shader_program_variable({ GL_FLOAT, 2 }, "point_size"); -constexpr inline auto tex = shader_program_variable({ GL_SAMPLER_2D, 3 }, "tex"); -constexpr inline auto color = shader_program_variable({ GL_FLOAT_VEC4, 4 }, "color"); -constexpr inline auto view_pos = shader_program_variable({ GL_FLOAT_VEC3, 5 }, "view_pos"); -constexpr inline auto point_light_direction = shader_program_variable({ GL_FLOAT_VEC3, 6 }, "point_light_direction"); -constexpr inline auto point_light_color = shader_program_variable({ GL_FLOAT_VEC3, 7 }, "point_light_color"); -constexpr inline auto ambient_light_color = shader_program_variable({ GL_FLOAT_VEC3, 8 }, "ambient_light_color"); -constexpr inline auto ambient_filter = shader_program_variable({ GL_FLOAT_VEC3, 9 }, "ambient_filter"); -constexpr inline auto diffuse_filter = shader_program_variable({ GL_FLOAT_VEC3, 10 }, "diffuse_filter"); -constexpr inline auto specular_filter = shader_program_variable({ GL_FLOAT_VEC3, 11 }, "specular_filter"); -constexpr inline auto shininess = shader_program_variable({ GL_FLOAT, 12 }, "shininess"); +constexpr inline auto mvp_matrix = uniform{ GL_FLOAT_MAT4, 0 }; +constexpr inline auto model_matrix = uniform{ GL_FLOAT_MAT4, 1 }; +constexpr inline auto point_size = uniform{ GL_FLOAT, 2 }; +constexpr inline auto tex = uniform{ GL_SAMPLER_2D, 3 }; +constexpr inline auto color = uniform{ GL_FLOAT_VEC4, 4 }; +constexpr inline auto view_pos = uniform{ GL_FLOAT_VEC3, 5 }; +constexpr inline auto point_light_direction = uniform{ GL_FLOAT_VEC3, 6 }; +constexpr inline auto point_light_color = uniform{ GL_FLOAT_VEC3, 7 }; +constexpr inline auto ambient_light_color = uniform{ GL_FLOAT_VEC3, 8 }; +constexpr inline auto ambient_filter = uniform{ GL_FLOAT_VEC3, 9 }; +constexpr inline auto diffuse_filter = uniform{ GL_FLOAT_VEC3, 10 }; +constexpr inline auto specular_filter = uniform{ GL_FLOAT_VEC3, 11 }; +constexpr inline auto shininess = uniform{ GL_FLOAT, 12 }; constexpr inline auto all = std::array{ mvp_matrix, @@ -72,4 +72,4 @@ constexpr inline auto names = std::array{ }; } -DEFINE_ENUM_BITFIELD_OPERATORS(zgl::shading::uniforms::mesh::flags) +DEFINE_ENUM_BITFIELD_OPERATORS(zgl::shading::mesh_uniforms::flags) diff --git a/include/opengl/shading/uniforms/point_cloud_uniforms.hpp b/include/opengl/shading/uniforms/point_cloud_uniforms.hpp index a41a5f4..850f2da 100644 --- a/include/opengl/shading/uniforms/point_cloud_uniforms.hpp +++ b/include/opengl/shading/uniforms/point_cloud_uniforms.hpp @@ -1,10 +1,10 @@ #pragma once -#include "opengl/shader_program_variable.hpp" +#include "opengl/shading/uniform_types/uniform.hpp" #include "util/enum_bitfield_operators.hpp" #include -namespace zgl::shading::uniforms::point_cloud +namespace zgl::shading::point_cloud_uniforms { enum class flags : std::uint8_t @@ -19,13 +19,13 @@ enum class flags : std::uint8_t rainbow_scale_y = 1 << 6 }; -constexpr inline auto mvp_matrix = shader_program_variable({ GL_FLOAT_MAT4, 0 }, "mvp_matrix"); -constexpr inline auto point_size = shader_program_variable({ GL_FLOAT, 1 }, "point_size"); -constexpr inline auto color = shader_program_variable({ GL_FLOAT_VEC4, 2 }, "color"); -constexpr inline auto model_matrix = shader_program_variable({ GL_FLOAT_MAT4, 3 }, "model_matrix"); -constexpr inline auto camera_position = shader_program_variable({ GL_FLOAT_VEC3, 4 }, "camera_position"); -constexpr inline auto rainbow_offset_y = shader_program_variable({ GL_FLOAT, 5 }, "rainbow_offset_y"); -constexpr inline auto rainbow_scale_y = shader_program_variable({ GL_FLOAT, 6 }, "rainbow_scale_y"); +constexpr inline auto mvp_matrix = uniform{ GL_FLOAT_MAT4, 0 }; +constexpr inline auto point_size = uniform{ GL_FLOAT, 1 }; +constexpr inline auto color = uniform{ GL_FLOAT_VEC4, 2 }; +constexpr inline auto model_matrix = uniform{ GL_FLOAT_MAT4, 3 }; +constexpr inline auto camera_position = uniform{ GL_FLOAT_VEC3, 4 }; +constexpr inline auto rainbow_offset_y = uniform{ GL_FLOAT, 5 }; +constexpr inline auto rainbow_scale_y = uniform{ GL_FLOAT, 6 }; constexpr inline auto all = std::array{ mvp_matrix, @@ -49,4 +49,4 @@ constexpr inline auto names = std::array{ } -DEFINE_ENUM_BITFIELD_OPERATORS(zgl::shading::uniforms::point_cloud::flags) +DEFINE_ENUM_BITFIELD_OPERATORS(zgl::shading::point_cloud_uniforms::flags) diff --git a/include/opengl/type_utils.hpp b/include/opengl/type_utils.hpp index 9956830..da1a8da 100755 --- a/include/opengl/type_utils.hpp +++ b/include/opengl/type_utils.hpp @@ -1,8 +1,16 @@ #pragma once -#include #include "GL/glew.h" #include "util/uix.hpp" +#include "types.hpp" +#include +#include +#include +#include +#include +#include +#include + namespace zgl::type_utils { @@ -68,4 +76,365 @@ constexpr GLsizei size_of(GLenum type) { return 0; } } + + +template +void interlace_vertex_buffer( + std::vector& vertex_buffer, + const C components, + const std::size_t element_count, + std::tuple...> vertex_component_arrays +) { + + const auto for_enabled_components = [&](auto&& f) + { + std::apply( + [&](const auto&... vertex_component_array) + { + [&](std::index_sequence) { + ( + [&] { + if ((components & (C{ 1 } << Is)) != C{}) + { + f(vertex_component_array, Is); + } + }, + ... + ); + }(std::index_sequence_for{}); + }, + vertex_component_arrays + ); + }; + + std::array byte_offsets; + auto stride = std::size_t{}; + + for_enabled_components( + [&]( + const std::span&, + std::size_t index + ) { + byte_offsets[index] = stride; + stride += sizeof(Component); + } + ); + + const auto buffer_size = stride * element_count; + + vertex_buffer.resize(buffer_size); + + for_enabled_components( + [&](const std::span& buffer, std::size_t index) + { + const auto byte_offset = byte_offsets[index]; + for (const auto& value : buffer.subspan(0, element_count)) + { + std::memcpy( + &vertex_buffer[byte_offset], + &value, + sizeof(value) + ); + byte_offset += stride; + } + } + ); +}; + +namespace detail +{ +constexpr std::size_t round_up_to(const std::size_t value, const std::size_t base) +{ + return ((value + base - 1) / base) * base; +} + +template +constexpr auto to_array(R&& r) +{ + std::array, C> values; + + if constexpr (requires { std::ranges::size(r); }) + { + assert(std::ranges::size(r) == C); + } + + for (auto&& [src, dst] : std::ranges::views::zip(r, values)) + { + dst = std::move(src); + } + + return values; +} + +template +struct last +{ + using type = typename last::type; +}; + + +template +struct last +{ + using type = T; +}; + + +template +class std140_info {}; + +template +class std140_info +{ + // 1. If the member is a scalar consuming N basic machine units, the base alignment is N. + +public: + using type = T; + static constexpr std::size_t base_alignment = 4; + static constexpr std::size_t size = 4; + + static void write(std::span buffer, const type& s) + { + assert(size == buffer.size()); + std::memcpy( + buffer.data(), + &s, + sizeof(type) + ); + } +}; + +template +class std140_info> +{ + // 2. If the member is a two- or four-component vector with components consuming N basic machine units, + // the base alignment is 2N or 4N, respectively. + // 3. If the member is a three-component vector with components consuming N basic machine units, + // the base alignment is 4N. + + using component_info = std140_info; + static constexpr std::size_t padded_count = L + (L & 1); + static constexpr std::size_t element_alignment = component_info::base_alignment; + +public: + using type = vec; + static constexpr std::size_t base_alignment = padded_count * component_info::size; + static constexpr std::size_t size = L * component_info::size; + + static void write(std::span buffer, const type& v) + { + assert(size == buffer.size()); + for (const auto [ index, component ] : std::ranges::views::enumerate(v)) + { + component_info::write( + buffer.subspan(index * element_alignment, component_info::size), + component + ); + } + } +}; + +template +class std140_info> +{ + // 4. If the member is an array of scalars, the base alignment and array + // stride are set to match the base alignment of a single array element, according + // to rules (1), (2), and (3), and rounded up to the base alignment of a vec4. The + // array may have padding at the end; the base offset of the member following + // the array is rounded up to the next multiple of the base alignment. + + using element_info = std140_info; + static constexpr auto element_alignment = round_up_to( + std140_info::base_alignment, + std140_info>::base_alignment + ); + +public: + using type = array; + static constexpr std::size_t base_alignment = element_alignment; + static constexpr std::size_t size = C * element_alignment; + + static void write(std::span buffer, const type& a) + { + assert(size == buffer.size()); + for (const auto [ index, component ] : std::ranges::views::enumerate(a)) + { + element_info::write( + buffer.subspan(index * element_alignment, element_info::size), + component + ); + } + } +}; + +template +class std140_info, C>> +{ + // 4. If the member is an array of vectors, the base alignment and array + // stride are set to match the base alignment of a single array element, according + // to rules (1), (2), and (3), and rounded up to the base alignment of a vec4. The + // array may have padding at the end; the base offset of the member following + // the array is rounded up to the next multiple of the base alignment. + + using element_info = std140_info; + static constexpr auto element_alignment = round_up_to( + element_info::base_alignment, + std140_info>::base_alignment + ); + +public: + using type = array, C>; + static constexpr std::size_t base_alignment = element_alignment; + static constexpr std::size_t size = C * element_alignment; + + static void write(std::span buffer, const type& a) + { + assert(size == buffer.size()); + for (const auto [ index, component ] : std::ranges::views::enumerate(a)) + { + element_info::write( + buffer.subspan(index * element_alignment, element_info::size), + component + ); + } + } +}; + +template +class std140_info> +{ + // 5. If the member is a column-major matrix with C columns and R rows, + // the matrix is stored identically to an array of C column vectors with R components each, + // according to rule(4). + + using column_info = vec; + using array_info = std140_info>; + static constexpr std::size_t element_alignment = array_info::element_alignment; + +public: + using type = mat; + static constexpr std::size_t base_alignment = array_info::base_alignment; + static constexpr std::size_t size = array_info::size; + + static void write(std::span buffer, const type& m) + { + assert(size == buffer.size()); + for (glm::length_t index{}; index != Dim; ++index) + { + column_info::write( + buffer.subspan(index * element_alignment, column_info::size), + m[index] + ); + } + } +}; + +template +class std140_info> +{ + // 9. If the member is a structure, the base alignment of the structure is N, + // where N is the largest base alignment value of any of its members, and rounded + // up to the base alignment of a vec4. The individual members of this sub- + // structure are then assigned offsets by applying this set of rules recursively, + // where the base offset of the first member of the sub-structure is equal to the + // aligned offset of the structure. The structure may have padding at the end; + // the base offset of the member following the sub-structure is rounded up to + // the next multiple of the base alignment of the structure + + static constexpr auto C = sizeof...(Ts); + static constexpr auto N = round_up_to( + std::max({ std140_info::base_alignment... }), + std140_info>::base_alignment + ); + static constexpr auto offsets = to_array( + std::array{ std::pair{ std140_info::base_alignment, std140_info::size }... } | + std::ranges::transform_view( + [offset = std::size_t{}](const auto& info) mutable + { + const auto [ alignment, size ] = info; + const auto aligned_offset = round_up_to(offset, alignment); + offset = aligned_offset + size; + return aligned_offset; + } + ) + ); + +public: + using type = structure; + static constexpr std::size_t base_alignment = N; + static constexpr std::size_t size = round_up_to( + offsets.back() + std140_info::type>::size, + base_alignment + ); + + static void write(std::span buffer, const type& s) + { + assert(size == buffer.size()); + std::apply( + [&](const Ts&... elements) + { + [&](std::index_sequence) { + ( + std140_info::write( + buffer.subspan(offsets[Is], std140_info::size), + elements + ), + ... + ); + }(std::index_sequence_for{}); + }, + s + ); + } +}; + + +template +class std140_info, C>> +{ + // 10. If the member is an array of S structures, the S elements of the array are laid + // out in order, according to rule(9). + + using element_info = std140_info>; + static constexpr auto N = round_up_to( + element_info::base_alignment, + std140_info>::base_alignment + ); + static constexpr std::size_t element_alignment = element_info::base_alignment; + +public: + using type = array, C>; + static constexpr std::size_t base_alignment = N; + static constexpr std::size_t size = round_up_to( + C * element_alignment, + base_alignment + ); + + static void write(std::span buffer, const type& a) + { + assert(size == buffer.size()); + for (const auto [ index, component ] : std::ranges::views::enumerate(a)) + { + element_info::write( + buffer.subspan(index * element_alignment, element_info::size), + component + ); + } + } +}; + +} + +template +constexpr auto generate_std140_buffer(const T& value) +{ + using info = detail::std140_info; + + std::array buffer{}; + + info::write(buffer, value); + + return buffer; +} + } // namespace zgl::type_utils diff --git a/include/opengl/types.hpp b/include/opengl/types.hpp new file mode 100644 index 0000000..0919132 --- /dev/null +++ b/include/opengl/types.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include "glm/gtc/type_aligned.hpp" + +namespace zgl +{ + +template +concept scalar = ( + std::is_same_v or + std::is_same_v or + std::is_same_v or + std::is_same_v +); + +template +using vec = glm::vec; + +template +using mat = glm::mat; + +template +using array = std::array; + +template +using structure = std::tuple; + +} diff --git a/include/opengl/vertex_buffer_utils.hpp b/include/opengl/vertex_buffer_utils.hpp deleted file mode 100644 index 23d4e34..0000000 --- a/include/opengl/vertex_buffer_utils.hpp +++ /dev/null @@ -1,88 +0,0 @@ -#pragma once - -#include "opengl/type_utils.hpp" -#include "opengl/metadata/vertex_buffer_metadata.hpp" -#include "util/specialised_lambda.hpp" -#include -#include -#include -#include -#include - -namespace zgl::vertex_buffer_utils -{ - -namespace detail -{ - -template -concept numeric_type = std::integral or std::floating_point; - -template -void for_enabled_components( - const C components, - auto&& f, - std::span buffers... -) { - ( - [&, index = std::size_t{}](const auto& buffer) - { - if ((components & static_cast(1 << index)) != C{}) - { - f(buffer, index); - } - ++index; - }(buffers), - ... - ); -}; - -} - - -template -void interlace( - std::vector& vertex_buffer, - const C components, - const std::size_t element_count, - std::span buffers... -) { - std::array byte_offsets; - auto stride = std::size_t{}; - - detail::for_enabled_components( - components, - [&]( - const std::span&, - std::size_t index - ) { - byte_offsets[index] = stride; - stride += sizeof(Component); - }, - buffers... - ); - - const auto buffer_size = stride * element_count; - - vertex_buffer.resize(buffer_size); - - detail::for_enabled_components( - components, - [&](const std::span& buffer, std::size_t index) - { - const auto byte_offset = byte_offsets[index]; - for (const auto& value : buffer.subspan(0, element_count)) - { - std::memcpy( - &vertex_buffer[byte_offset], - &value, - sizeof(value) - ); - byte_offset += stride; - } - }, - buffers... - ); -}; - -} diff --git a/shaders/fragment_mesh_face.glsl b/shaders/fragment_mesh_face.glsl index 7fcfb99..9502a6b 100644 --- a/shaders/fragment_mesh_face.glsl +++ b/shaders/fragment_mesh_face.glsl @@ -7,19 +7,45 @@ //------------[ Uniforms ]------------// #ifdef TEXTURE -layout (location = 3) uniform sampler2D tex; +layout (binding = 0) uniform sampler2D tex; #endif #ifdef LIGHTING -layout (location = 5) uniform vec3 view_pos; -layout (location = 6) uniform vec3 point_light_direction; -layout (location = 7) uniform vec3 point_light_color; -layout (location = 8) uniform vec3 ambient_light_color; -layout (location = 9) uniform vec3 ambient_filter; -layout (location = 10) uniform vec3 diffuse_filter; -layout (location = 11) uniform vec3 specular_filter; -layout (location = 12) uniform float shininess; +// layout (location = 5) uniform vec3 view_pos; +// layout (location = 6) uniform vec3 point_light_direction; +// layout (location = 7) uniform vec3 point_light_color; +// layout (location = 8) uniform vec3 ambient_light_color; + +// layout (location = 9) uniform vec3 ambient_filter; +// layout (location = 10) uniform vec3 diffuse_filter; +// layout (location = 11) uniform vec3 specular_filter; +// layout (location = 12) uniform float shininess; #endif +layout (std140, binding = 0) uniform Material +{ + uniform vec3 ambient_filter; + uniform vec3 diffuse_filter; + uniform vec3 specular_filter; + uniform float shininess; + uniform float alpha; +}; + +layout (std140, binding = 1) uniform Lighting +{ + layout (location = 1) uniform mat4 model_matrix; + layout (location = 5) uniform vec3 view_pos; + layout (location = 6) uniform vec3 point_light_direction; + layout (location = 7) uniform vec3 point_light_color; + layout (location = 8) uniform vec3 ambient_light_color; +}; + +uniform sampler2D ambient_color_texture; +uniform sampler2D diffuse_color_texture; +uniform sampler2D specular_color_texture; +uniform sampler2D shininess_texture; +uniform sampler2D alpha_texture; +uniform sampler2D bump_texture; + //------------[ Inputs ]------------// layout (location = 0) in vec4 frag_color; diff --git a/shaders/vertex_mesh_face.glsl b/shaders/vertex_mesh_face.glsl index b924399..6b9f076 100644 --- a/shaders/vertex_mesh_face.glsl +++ b/shaders/vertex_mesh_face.glsl @@ -13,9 +13,11 @@ //------------[ Uniforms ]------------// layout (location = 0) uniform mat4 mvp_matrix; + #ifdef LIGHTING -layout (location = 1) uniform mat4 model_matrix; +//layout (location = 1) uniform mat4 model_matrix; #endif +// Can be replaced by material ambient filter, right?!? #ifdef U_RGBA layout (location = 4) uniform vec4 color; #endif diff --git a/shaders/vertex_mesh_point.glsl b/shaders/vertex_mesh_point.glsl index 9bf04c9..0e70e1a 100644 --- a/shaders/vertex_mesh_point.glsl +++ b/shaders/vertex_mesh_point.glsl @@ -16,15 +16,20 @@ layout (location = 0) uniform mat4 mvp_matrix; #ifdef LIGHTING layout (location = 1) uniform mat4 model_matrix; #endif + layout (location = 2) uniform float point_size; + #ifdef U_RGBA layout (location = 4) uniform vec4 color; #endif + #ifdef LIGHTING + layout (location = 5) uniform vec3 view_pos; layout (location = 6) uniform vec3 point_light_direction; layout (location = 7) uniform vec3 point_light_color; layout (location = 8) uniform vec3 ambient_light_color; + layout (location = 9) uniform vec3 ambient_filter; layout (location = 10) uniform vec3 diffuse_filter; layout (location = 11) uniform vec3 specular_filter; diff --git a/shaders/vertex_point_cloud.glsl b/shaders/vertex_point_cloud.glsl index b6d1444..ea193a1 100644 --- a/shaders/vertex_point_cloud.glsl +++ b/shaders/vertex_point_cloud.glsl @@ -14,13 +14,17 @@ //------------[ Uniforms ]------------// layout (location = 0) uniform mat4 mvp_matrix; layout (location = 1) uniform float point_size; + #ifdef U_RGBA layout (location = 2) uniform vec4 color; #endif + + #ifdef LIGHTING layout (location = 3) uniform mat4 model_matrix; layout (location = 4) uniform vec3 camera_position; #endif + #ifdef RAINBOW layout (location = 5) uniform float rainbow_offset_y; layout (location = 6) uniform float rainbow_scale_y; diff --git a/source/opengl/data_managers/mesh_index_buffer_manager.cpp b/source/opengl/data_managers/mesh_index_buffer_manager.cpp index 33cf1f9..a33b17e 100644 --- a/source/opengl/data_managers/mesh_index_buffer_manager.cpp +++ b/source/opengl/data_managers/mesh_index_buffer_manager.cpp @@ -4,9 +4,9 @@ #include "opengl/error.hpp" #include "opengl/type_utils.hpp" -void zgl::mesh_index_buffer_manager::process(const assets::data_stores& stores) +void zgl::mesh_index_buffer_manager::process(const store_type& meshes) { - for (const auto& [ id, mesh ] : stores.meshes) + for (const auto& [ id, mesh ] : meshes) { if (not m_resource_manager.has_resource(id)) { diff --git a/source/opengl/data_managers/mesh_vertex_buffer_manager.cpp b/source/opengl/data_managers/mesh_vertex_buffer_manager.cpp index 7146684..c32a137 100644 --- a/source/opengl/data_managers/mesh_vertex_buffer_manager.cpp +++ b/source/opengl/data_managers/mesh_vertex_buffer_manager.cpp @@ -2,12 +2,12 @@ #include "util/logger.hpp" #include "opengl/error.hpp" -#include "opengl/vertex_buffer_utils.hpp" +#include "opengl/type_utils.hpp" -void zgl::mesh_vertex_buffer_manager::process(const assets::data_stores& stores) +void zgl::mesh_vertex_buffer_manager::process(const store_type& meshes) { - for (const auto& [ id, mesh ] : stores.meshes) + for (const auto& [ id, mesh ] : meshes) { if (not m_resource_manager.has_resource(id)) { @@ -30,16 +30,10 @@ void zgl::mesh_vertex_buffer_manager::process(const assets::data_stores& stores) m_byte_buffer.clear(); - std::apply( - [&](const auto&... component_buffers) - { - vertex_buffer_utils::interlace( - m_byte_buffer, - mesh.component_flags, - mesh.vertex_count, - component_buffers... - ); - }, + type_utils::interlace_vertex_buffer( + m_byte_buffer, + mesh.component_flags, + mesh.vertex_count, mesh.vertex_component_arrays ); diff --git a/source/opengl/data_managers/point_cloud_vertex_buffer_manager.cpp b/source/opengl/data_managers/point_cloud_vertex_buffer_manager.cpp index 0e1f7ac..fae6f05 100644 --- a/source/opengl/data_managers/point_cloud_vertex_buffer_manager.cpp +++ b/source/opengl/data_managers/point_cloud_vertex_buffer_manager.cpp @@ -2,12 +2,12 @@ #include "util/logger.hpp" #include "opengl/error.hpp" -#include "opengl/vertex_buffer_utils.hpp" +#include "opengl/type_utils.hpp" -void zgl::point_cloud_vertex_buffer_manager::process(const assets::data_stores& stores) +void zgl::point_cloud_vertex_buffer_manager::process(const store_type& point_clouds) { - for (const auto& [ id, point_cloud ] : stores.point_clouds) + for (const auto& [ id, point_cloud ] : point_clouds) { if (not m_resource_manager.has_resource(id)) { @@ -30,16 +30,10 @@ void zgl::point_cloud_vertex_buffer_manager::process(const assets::data_stores& m_byte_buffer.clear(); - std::apply( - [&](const auto&... component_buffers) - { - vertex_buffer_utils::interlace( - m_byte_buffer, - point_cloud.vertex_component_flags, - point_cloud.point_count, - component_buffers... - ); - }, + type_utils::interlace_vertex_buffer( + m_byte_buffer, + point_cloud.vertex_component_flags, + point_cloud.point_count, point_cloud.vertex_component_arrays ); diff --git a/source/opengl/data_managers/shader_manager.cpp b/source/opengl/data_managers/shader_manager.cpp index ddbeb89..6e1167a 100644 --- a/source/opengl/data_managers/shader_manager.cpp +++ b/source/opengl/data_managers/shader_manager.cpp @@ -79,6 +79,11 @@ std::optional> zgl::shader_m return std::nullopt; } +void zgl::shader_manager::process(const store_type& shader_sources) +{ + m_preprocessor.process(shader_sources); +} + void zgl::shader_manager::get_handles( const assets::shader_source_store& shader_sources, std::span requirements, @@ -256,9 +261,3 @@ bool zgl::shader_manager::compile_shader( return true; } - -void zgl::shader_manager::process( - const assets::data_stores& stores -) { - m_preprocessor.process(stores); -} \ No newline at end of file diff --git a/source/opengl/data_managers/shader_program_manager.cpp b/source/opengl/data_managers/shader_program_manager.cpp index f8d049e..2483506 100644 --- a/source/opengl/data_managers/shader_program_manager.cpp +++ b/source/opengl/data_managers/shader_program_manager.cpp @@ -24,10 +24,9 @@ struct prioritized_metadata_comparator } }; -void zgl::shader_program_manager::process( - const assets::data_stores& stores -) { - m_shader_manager.preprocess(stores); +void zgl::shader_program_manager::process(const store_type& shader_sources) +{ + m_shader_manager.process(shader_sources); } void zgl::shader_program_manager::get_handles( diff --git a/source/opengl/data_managers/shader_source_manager.cpp b/source/opengl/data_managers/shader_source_manager.cpp index 64951b0..3b647a4 100644 --- a/source/opengl/data_managers/shader_source_manager.cpp +++ b/source/opengl/data_managers/shader_source_manager.cpp @@ -76,12 +76,11 @@ private: -void zgl::shader_source_manager::process( - const assets::data_stores& stores -) { +void zgl::shader_source_manager::process(const store_type& shader_sources) +{ namespace language = shading::shader_metadata_language; - for (const auto& [ id, shader_source ] : stores.shader_sources) + for (const auto& [ id, shader_source ] : shader_sources) { m_value_token_buffer.clear(); m_declaration_token_count_buffer.clear(); diff --git a/source/opengl/data_managers/texture_manager.cpp b/source/opengl/data_managers/texture_manager.cpp index 94373aa..30768a1 100644 --- a/source/opengl/data_managers/texture_manager.cpp +++ b/source/opengl/data_managers/texture_manager.cpp @@ -5,12 +5,11 @@ #include "opengl/error.hpp" -void zgl::texture_manager::process( - const assets::data_stores& stores -) { +void zgl::texture_manager::process(const store_type& textures) +{ m_texture_buffer.clear(); - for (const auto& [ id, texture ] : stores.textures) + for (const auto& [ id, texture ] : textures) { if (not m_resource_manager.has_resource(id)) { diff --git a/source/opengl/handles/shader_program_handle.cpp b/source/opengl/handles/shader_program_handle.cpp index 90136f4..67afd22 100644 --- a/source/opengl/handles/shader_program_handle.cpp +++ b/source/opengl/handles/shader_program_handle.cpp @@ -9,7 +9,7 @@ namespace zgl { shader_program_handle::attribute_support_type shader_program_handle::check_attribute_support( - const std::span attributes + const std::span attributes ) const { auto attribute_candidates = attribute_support_type{}; @@ -76,7 +76,7 @@ shader_program_handle::attribute_support_type shader_program_handle::check_attri } shader_program_handle::uniform_support_type shader_program_handle::check_uniform_support( - const std::span uniforms + const std::span uniforms ) const { auto uniform_candidates = uniform_support_type{}; diff --git a/source/opengl/handles/shader_program_handle.ipp b/source/opengl/handles/shader_program_handle.ipp index a7c6e02..ba183d1 100755 --- a/source/opengl/handles/shader_program_handle.ipp +++ b/source/opengl/handles/shader_program_handle.ipp @@ -17,7 +17,7 @@ inline void shader_program_handle::unbind() glUseProgram(0); } -template +template void shader_program_handle::set_uniform(const T& value) const { if constexpr (std::same_as) diff --git a/source/opengl/shader_program_lookup.cpp b/source/opengl/shader_program_lookup.cpp index 7f317da..c00552a 100644 --- a/source/opengl/shader_program_lookup.cpp +++ b/source/opengl/shader_program_lookup.cpp @@ -11,8 +11,8 @@ namespace zgl void shader_program_lookup::add( const shader_program_handle& shader_program_handle, - const std::span all_attributes, - const std::span all_uniforms + const std::span all_attributes, + const std::span all_uniforms ) { const auto attributes = shader_program_handle.check_attribute_support(all_attributes); const auto uniforms = shader_program_handle.check_uniform_support(all_uniforms); @@ -72,7 +72,7 @@ void shader_program_lookup::add( std::optional shader_program_lookup::find( shader_program_handle::attribute_support_type attributes, shader_program_handle::uniform_support_type uniforms, - const std::span all_attributes + const std::span all_attributes ) const { const auto lower_uniform = std::ranges::lower_bound( @@ -158,7 +158,7 @@ std::optional shader_program_lookup::find( shader_program_lookup::attribute_locations_type shader_program_lookup::attribute_location_flags( shader_program_handle::attribute_support_type attributes, - std::span all_attributes + std::span all_attributes ) { auto location_flags = ztu::u32{ 0 };