std140 implementation

This commit is contained in:
ZY4N
2025-03-27 19:47:32 +01:00
parent 70893c083b
commit 6f60cc11c8
45 changed files with 789 additions and 234 deletions

View File

@@ -59,7 +59,7 @@ add_executable(z3d main.cpp
include/rendering/batch_renderers/point_cloud_batch_renderer.hpp include/rendering/batch_renderers/point_cloud_batch_renderer.hpp
source/rendering/batches/mesh_batch.ipp source/rendering/batches/mesh_batch.ipp
source/rendering/batches/point_cloud_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/opengl/type_utils.hpp
include/util/binary_ifstream.hpp include/util/binary_ifstream.hpp
source/assets/file_parsers/kitti_loader.cpp source/assets/file_parsers/kitti_loader.cpp
@@ -204,7 +204,6 @@ add_executable(z3d main.cpp
include/opengl/handles/index_buffer_handle.hpp include/opengl/handles/index_buffer_handle.hpp
source/opengl/handles/index_buffer_handle.ipp source/opengl/handles/index_buffer_handle.ipp
include/opengl/metadata/texture_metadata.hpp include/opengl/metadata/texture_metadata.hpp
include/opengl/vertex_buffer_utils.hpp
include/opengl/data_managers/mesh_index_buffer_manager.hpp include/opengl/data_managers/mesh_index_buffer_manager.hpp
include/opengl/metadata/index_buffer_metadata.hpp include/opengl/metadata/index_buffer_metadata.hpp
source/opengl/data_managers/mesh_index_buffer_manager.cpp 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 source/assets/data_stores/shader_source_store.ipp
include/opengl/metadata/mesh_vertex_buffer_metadata.hpp include/opengl/metadata/mesh_vertex_buffer_metadata.hpp
include/opengl/metadata/point_cloud_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) target_include_directories(z3d PRIVATE include)

View File

@@ -18,7 +18,7 @@ public:
using size_type = std::size_t; using size_type = std::size_t;
using count_type = ztu::u32; using count_type = ztu::u32;
using component_flag_type = material_components::flags; using component_flag_type = material_components::flags;
using id_type = ztu::id_type_for<generic_material_store<Ts...>, ztu::u32>; using id_type = ztu::id_type_for<generic_material_store<std::remove_const_t<Ts>...>, ztu::u32>;
using value_type = std::pair<id_type, material_view>; using value_type = std::pair<id_type, material_view>;
using flag_count_type = std::tuple<component_flag_type>; using flag_count_type = std::tuple<component_flag_type>;

View File

@@ -20,7 +20,7 @@ public:
using index_type = mesh_data::index_type; using index_type = mesh_data::index_type;
using material_id_type = material_store::id_type; using material_id_type = material_store::id_type;
using component_flag_type = mesh_vertex_components::flags; using component_flag_type = mesh_vertex_components::flags;
using id_type = ztu::id_type_for<generic_mesh_store<Ts...>, ztu::u32>; using id_type = ztu::id_type_for<generic_mesh_store<std::remove_const_t<Ts...>>, ztu::u32>;
using value_type = std::pair<id_type, mesh_view>; using value_type = std::pair<id_type, mesh_view>;
using flag_count_type = std::tuple<component_flag_type, count_type, count_type>; using flag_count_type = std::tuple<component_flag_type, count_type, count_type>;

View File

@@ -22,7 +22,7 @@ public:
using size_type = std::size_t; using size_type = std::size_t;
using count_type = ztu::u32; using count_type = ztu::u32;
using component_flag_type = point_cloud_vertex_components::flags; using component_flag_type = point_cloud_vertex_components::flags;
using id_type = ztu::id_type_for<generic_point_cloud_store<Ts...>, ztu::u32>; using id_type = ztu::id_type_for<generic_point_cloud_store<std::remove_const_t<Ts>...>, ztu::u32>;
using value_type = std::pair<id_type, point_cloud_view>; using value_type = std::pair<id_type, point_cloud_view>;
using flag_count_type = std::tuple<component_flag_type, count_type, count_type>; using flag_count_type = std::tuple<component_flag_type, count_type, count_type>;

View File

@@ -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 <vector>
#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<store_id_type, metadata_type>;
// TODO add reference and const_reference
using entry_type = std::pair<const handle_type&, const metadata_type&>;
static constexpr std::size_t min_garbage_collection_count = 4;
void process(const store_type& materials);
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<std::pair<store_id_type, const assets::material_data&>> m_material_buffer;
std::vector<GLuint> m_material_id_buffer;
};
}

View File

@@ -20,7 +20,7 @@ public:
static constexpr std::size_t min_garbage_collection_count = 4; 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<entry_type> get_handle(store_id_type id); std::optional<entry_type> get_handle(store_id_type id);

View File

@@ -21,7 +21,7 @@ public:
static constexpr std::size_t min_garbage_collection_count = 4; 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<entry_type> get_handle(store_id_type id); std::optional<entry_type> get_handle(store_id_type id);

View File

@@ -21,7 +21,7 @@ public:
static constexpr std::size_t min_garbage_collection_count = 4; 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<entry_type> get_handle(store_id_type id); std::optional<entry_type> get_handle(store_id_type id);

View File

@@ -23,15 +23,15 @@ namespace zgl
{ {
class shader_manager class shader_manager
{ {
public:
using store_type = shader_source_manager::store_type;
using metadata_type = shader_metadata; using metadata_type = shader_metadata;
using data_type = shader_data; using data_type = shader_data;
using handle_type = shader_handle; using handle_type = shader_handle;
using entry_type = std::pair<metadata_type, data_type>; using entry_type = std::pair<metadata_type, data_type>;
using entry_view_type = std::pair<metadata_type, handle_type>; using entry_view_type = std::pair<metadata_type, handle_type>;
public: void process(const store_type& shader_sources);
void process(const assets::data_stores& stores);
void get_handles( void get_handles(
const assets::shader_source_store& shader_sources, const assets::shader_source_store& shader_sources,

View File

@@ -12,13 +12,14 @@ namespace zgl
class shader_program_manager class shader_program_manager
{ {
public: public:
using store_type = shader_manager::store_type;
using metadata_type = shader_program_metadata; using metadata_type = shader_program_metadata;
using data_type = shader_program_data; using data_type = shader_program_data;
using handle_type = shader_program_handle; using handle_type = shader_program_handle;
using entry_type = std::pair<metadata_type, data_type>; using entry_type = std::pair<metadata_type, data_type>;
using entry_view_type = std::pair<metadata_type, handle_type>; using entry_view_type = std::pair<metadata_type, handle_type>;
void process(const assets::data_stores& stores); void process(const store_type& shader_sources);
void get_handles( void get_handles(
const assets::shader_source_store& shader_sources, const assets::shader_source_store& shader_sources,

View File

@@ -28,7 +28,7 @@ public:
using entry_type = std::pair<metadata_type, store_id_type>; using entry_type = std::pair<metadata_type, store_id_type>;
using entry_view_type = std::pair<preprocessed_shader_source_metadata, handle_type>; using entry_view_type = std::pair<preprocessed_shader_source_metadata, handle_type>;
void process(const assets::data_stores& stores); void process(const store_type& shader_sources);
void get_shader_sources( void get_shader_sources(
const assets::shader_source_store& shader_sources, const assets::shader_source_store& shader_sources,

View File

@@ -25,7 +25,7 @@ public:
static constexpr std::size_t min_garbage_collection_count = 4; 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<entry_type> get_handle(store_id_type id); std::optional<entry_type> get_handle(store_id_type id);

View File

@@ -7,10 +7,11 @@
namespace zgl namespace zgl
{ {
struct material_handle // TODO implement
struct material_handle : resource_handle
{ {
std::optional<texture_handle> texture{ std::nullopt }; inline void bind() const;
std::optional<surface_properties_handle> surface_properties{ std::nullopt }; inline static void unbind();
std::optional<alpha_handle> alpha{ std::nullopt };
}; };
} }

View File

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

View File

@@ -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;
};
}

View File

@@ -0,0 +1,17 @@
#pragma once
#include <cinttypes>
#include <array>
namespace zgl
{
template<std::size_t Count>
struct uniform_buffer_alignment_metadata
{
std::array<std::size_t, Count> byte_offsets{};
std::size_t byte_size{};
};
}

View File

@@ -10,14 +10,14 @@ class shader_program_lookup
public: public:
void add( void add(
const shader_program_handle& shader_program_handle, const shader_program_handle& shader_program_handle,
std::span<const shader_program_variable> all_attributes, std::span<const shader_uniform> all_attributes,
std::span<const shader_program_variable> all_uniforms std::span<const shader_uniform> all_uniforms
); );
[[nodiscard]] std::optional<shader_program_handle> find( [[nodiscard]] std::optional<shader_program_handle> find(
shader_program_handle::attribute_support_type attributes, shader_program_handle::attribute_support_type attributes,
shader_program_handle::uniform_support_type uniforms, shader_program_handle::uniform_support_type uniforms,
std::span<const shader_program_variable> all_attributes std::span<const shader_uniform> all_attributes
) const; ) const;
void print(); void print();
@@ -27,7 +27,7 @@ private:
[[nodiscard]] static attribute_locations_type attribute_location_flags( [[nodiscard]] static attribute_locations_type attribute_location_flags(
shader_program_handle::attribute_support_type attributes, shader_program_handle::attribute_support_type attributes,
std::span<const shader_program_variable> all_attributes std::span<const shader_uniform> all_attributes
); );
struct attribute_entry_type struct attribute_entry_type

View File

@@ -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;
};
}

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "opengl/shader_program_variable.hpp" #include "opengl/shader_uniform.hpp"
#include "util/enum_bitfield_operators.hpp" #include "util/enum_bitfield_operators.hpp"
#include <array> #include <array>
@@ -20,12 +20,12 @@ enum class flags : std::uint8_t
tex_coord = 1 << 5 tex_coord = 1 << 5
}; };
constexpr inline auto position = shader_program_variable({ GL_FLOAT_VEC3, 0 }, "model_vertex_position"); constexpr inline auto position = shader_uniform({ GL_FLOAT_VEC3, 0 }, "model_vertex_position");
constexpr inline auto normal = shader_program_variable({ GL_FLOAT_VEC3, 1 }, "model_vertex_normal"); constexpr inline auto normal = shader_uniform({ GL_FLOAT_VEC3, 1 }, "model_vertex_normal");
constexpr inline auto luminance = shader_program_variable({ GL_FLOAT, 2 }, "model_vertex_l"); constexpr inline auto luminance = shader_uniform({ GL_FLOAT, 2 }, "model_vertex_l");
constexpr inline auto color = shader_program_variable({ GL_FLOAT_VEC3, 2 }, "model_vertex_rgb"); constexpr inline auto color = shader_uniform({ GL_FLOAT_VEC3, 2 }, "model_vertex_rgb");
constexpr inline auto alpha = shader_program_variable({ GL_FLOAT, 3 }, "model_vertex_a"); constexpr inline auto alpha = shader_uniform({ 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 tex_coord = shader_uniform({ GL_FLOAT_VEC2, 2 }, "model_vertex_tex_coord");
constexpr inline auto all = std::array{ constexpr inline auto all = std::array{
position, normal, luminance, color, alpha, tex_coord position, normal, luminance, color, alpha, tex_coord

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "opengl/shader_program_variable.hpp" #include "opengl/shader_uniform.hpp"
#include <array> #include <array>
#include "util/enum_bitfield_operators.hpp" #include "util/enum_bitfield_operators.hpp"
#include <string_view> #include <string_view>
@@ -18,11 +18,11 @@ enum class flags : std::uint8_t
alpha = 1 << 3 alpha = 1 << 3
}; };
constexpr inline auto position = shader_program_variable({ GL_FLOAT_VEC3, 0 }, "model_vertex_position"); constexpr inline auto position = shader_uniform({ GL_FLOAT_VEC3, 0 }, "model_vertex_position");
constexpr inline auto normal = shader_program_variable({ GL_FLOAT_VEC3, 1 }, "model_vertex_normal"); constexpr inline auto normal = shader_uniform({ GL_FLOAT_VEC3, 1 }, "model_vertex_normal");
constexpr inline auto luminance = shader_program_variable({ GL_FLOAT_VEC3, 1 }, "model_vertex_l"); constexpr inline auto luminance = shader_uniform({ GL_FLOAT_VEC3, 1 }, "model_vertex_l");
constexpr inline auto color = shader_program_variable({ GL_FLOAT_VEC3, 1 }, "model_vertex_rgb"); constexpr inline auto color = shader_uniform({ GL_FLOAT_VEC3, 1 }, "model_vertex_rgb");
constexpr inline auto alpha = shader_program_variable({ GL_FLOAT_VEC3, 1 }, "model_vertex_a"); constexpr inline auto alpha = shader_uniform({ GL_FLOAT_VEC3, 1 }, "model_vertex_a");
constexpr inline auto all = std::array{ constexpr inline auto all = std::array{
position, normal, luminance, color, alpha position, normal, luminance, color, alpha

View File

@@ -0,0 +1,13 @@
#pragma once
#include "GL/glew.h"
namespace zgl::shading
{
struct sampler_uniform
{
GLenum binding_location;
};
}

View File

@@ -0,0 +1,48 @@
#pragma once
#include "opengl/shading/sampler_uniform.hpp"
#include <array>
#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)

View File

@@ -0,0 +1,14 @@
#pragma once
#include "GL/glew.h"
namespace zgl::shading
{
struct uniform
{
GLenum type;
GLint location;
};
}

View File

@@ -0,0 +1,13 @@
#pragma once
#include "GL/glew.h"
namespace zgl::shading
{
struct uniform_block
{
GLenum binding_location;
};
}

View File

@@ -0,0 +1,33 @@
#pragma once
#include "opengl/shading/uniform_block.hpp"
#include <array>
#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)

View File

@@ -0,0 +1,32 @@
#pragma once
#include "opengl/shading/uniform_block.hpp"
#include <array>
#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)

View File

@@ -1,10 +1,10 @@
#pragma once #pragma once
#include "opengl/shader_program_variable.hpp" #include "opengl/shading/uniform_types/uniform.hpp"
#include <array> #include <array>
#include "util/enum_bitfield_operators.hpp" #include "util/enum_bitfield_operators.hpp"
namespace zgl::shading::uniforms::mesh namespace zgl::shading::mesh_uniforms
{ {
enum class flags : std::uint16_t enum class flags : std::uint16_t
@@ -25,19 +25,19 @@ enum class flags : std::uint16_t
shininess = 1 << 12 shininess = 1 << 12
}; };
constexpr inline auto mvp_matrix = shader_program_variable({ GL_FLOAT_MAT4, 0 }, "mvp_matrix"); constexpr inline auto mvp_matrix = uniform{ GL_FLOAT_MAT4, 0 };
constexpr inline auto model_matrix = shader_program_variable({ GL_FLOAT_MAT4, 1 }, "model_matrix"); constexpr inline auto model_matrix = uniform{ GL_FLOAT_MAT4, 1 };
constexpr inline auto point_size = shader_program_variable({ GL_FLOAT, 2 }, "point_size"); constexpr inline auto point_size = uniform{ GL_FLOAT, 2 };
constexpr inline auto tex = shader_program_variable({ GL_SAMPLER_2D, 3 }, "tex"); constexpr inline auto tex = uniform{ GL_SAMPLER_2D, 3 };
constexpr inline auto color = shader_program_variable({ GL_FLOAT_VEC4, 4 }, "color"); constexpr inline auto color = uniform{ GL_FLOAT_VEC4, 4 };
constexpr inline auto view_pos = shader_program_variable({ GL_FLOAT_VEC3, 5 }, "view_pos"); constexpr inline auto view_pos = uniform{ GL_FLOAT_VEC3, 5 };
constexpr inline auto point_light_direction = shader_program_variable({ GL_FLOAT_VEC3, 6 }, "point_light_direction"); constexpr inline auto point_light_direction = uniform{ GL_FLOAT_VEC3, 6 };
constexpr inline auto point_light_color = shader_program_variable({ GL_FLOAT_VEC3, 7 }, "point_light_color"); constexpr inline auto point_light_color = uniform{ GL_FLOAT_VEC3, 7 };
constexpr inline auto ambient_light_color = shader_program_variable({ GL_FLOAT_VEC3, 8 }, "ambient_light_color"); constexpr inline auto ambient_light_color = uniform{ GL_FLOAT_VEC3, 8 };
constexpr inline auto ambient_filter = shader_program_variable({ GL_FLOAT_VEC3, 9 }, "ambient_filter"); constexpr inline auto ambient_filter = uniform{ GL_FLOAT_VEC3, 9 };
constexpr inline auto diffuse_filter = shader_program_variable({ GL_FLOAT_VEC3, 10 }, "diffuse_filter"); constexpr inline auto diffuse_filter = uniform{ GL_FLOAT_VEC3, 10 };
constexpr inline auto specular_filter = shader_program_variable({ GL_FLOAT_VEC3, 11 }, "specular_filter"); constexpr inline auto specular_filter = uniform{ GL_FLOAT_VEC3, 11 };
constexpr inline auto shininess = shader_program_variable({ GL_FLOAT, 12 }, "shininess"); constexpr inline auto shininess = uniform{ GL_FLOAT, 12 };
constexpr inline auto all = std::array{ constexpr inline auto all = std::array{
mvp_matrix, 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)

View File

@@ -1,10 +1,10 @@
#pragma once #pragma once
#include "opengl/shader_program_variable.hpp" #include "opengl/shading/uniform_types/uniform.hpp"
#include "util/enum_bitfield_operators.hpp" #include "util/enum_bitfield_operators.hpp"
#include <array> #include <array>
namespace zgl::shading::uniforms::point_cloud namespace zgl::shading::point_cloud_uniforms
{ {
enum class flags : std::uint8_t enum class flags : std::uint8_t
@@ -19,13 +19,13 @@ enum class flags : std::uint8_t
rainbow_scale_y = 1 << 6 rainbow_scale_y = 1 << 6
}; };
constexpr inline auto mvp_matrix = shader_program_variable({ GL_FLOAT_MAT4, 0 }, "mvp_matrix"); constexpr inline auto mvp_matrix = uniform{ GL_FLOAT_MAT4, 0 };
constexpr inline auto point_size = shader_program_variable({ GL_FLOAT, 1 }, "point_size"); constexpr inline auto point_size = uniform{ GL_FLOAT, 1 };
constexpr inline auto color = shader_program_variable({ GL_FLOAT_VEC4, 2 }, "color"); constexpr inline auto color = uniform{ GL_FLOAT_VEC4, 2 };
constexpr inline auto model_matrix = shader_program_variable({ GL_FLOAT_MAT4, 3 }, "model_matrix"); constexpr inline auto model_matrix = uniform{ GL_FLOAT_MAT4, 3 };
constexpr inline auto camera_position = shader_program_variable({ GL_FLOAT_VEC3, 4 }, "camera_position"); constexpr inline auto camera_position = uniform{ GL_FLOAT_VEC3, 4 };
constexpr inline auto rainbow_offset_y = shader_program_variable({ GL_FLOAT, 5 }, "rainbow_offset_y"); constexpr inline auto rainbow_offset_y = uniform{ GL_FLOAT, 5 };
constexpr inline auto rainbow_scale_y = shader_program_variable({ GL_FLOAT, 6 }, "rainbow_scale_y"); constexpr inline auto rainbow_scale_y = uniform{ GL_FLOAT, 6 };
constexpr inline auto all = std::array{ constexpr inline auto all = std::array{
mvp_matrix, 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)

View File

@@ -1,8 +1,16 @@
#pragma once #pragma once
#include <utility>
#include "GL/glew.h" #include "GL/glew.h"
#include "util/uix.hpp" #include "util/uix.hpp"
#include "types.hpp"
#include <utility>
#include <span>
#include <tuple>
#include <vector>
#include <cstring>
#include <ranges>
#include <bits/ranges_algo.h>
namespace zgl::type_utils namespace zgl::type_utils
{ {
@@ -68,4 +76,365 @@ constexpr GLsizei size_of(GLenum type) {
return 0; return 0;
} }
} }
template<typename C, typename... Ts>
void interlace_vertex_buffer(
std::vector<ztu::u8>& vertex_buffer,
const C components,
const std::size_t element_count,
std::tuple<std::span<Ts>...> vertex_component_arrays
) {
const auto for_enabled_components = [&](auto&& f)
{
std::apply(
[&](const auto&... vertex_component_array)
{
[&]<auto... Is>(std::index_sequence<Is...>) {
(
[&] {
if ((components & (C{ 1 } << Is)) != C{})
{
f(vertex_component_array, Is);
}
},
...
);
}(std::index_sequence_for<Ts...>{});
},
vertex_component_arrays
);
};
std::array<std::size_t, sizeof...(Ts)> byte_offsets;
auto stride = std::size_t{};
for_enabled_components(
[&]<class Component>(
const std::span<Component>&,
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(
[&]<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, 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<std::size_t C, std::ranges::range R>
constexpr auto to_array(R&& r)
{
std::array<std::ranges::range_value_t<R>, 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<typename, typename... Ts>
struct last
{
using type = typename last<Ts...>::type;
};
template<typename T>
struct last<T>
{
using type = T;
};
template<typename>
class std140_info {};
template<scalar T>
class std140_info<T>
{
// 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<ztu::u8> buffer, const type& s)
{
assert(size == buffer.size());
std::memcpy(
buffer.data(),
&s,
sizeof(type)
);
}
};
template<int L, scalar T>
class std140_info<vec<L, T>>
{
// 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<T>;
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<L, T>;
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<ztu::u8> 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<scalar T, std::size_t C>
class std140_info<array<T, C>>
{
// 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<T>;
static constexpr auto element_alignment = round_up_to(
std140_info<T>::base_alignment,
std140_info<vec<4, float>>::base_alignment
);
public:
using type = array<T, C>;
static constexpr std::size_t base_alignment = element_alignment;
static constexpr std::size_t size = C * element_alignment;
static void write(std::span<ztu::u8> 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<scalar T, int L, std::size_t C>
class std140_info<array<vec<L, T>, 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<T>;
static constexpr auto element_alignment = round_up_to(
element_info::base_alignment,
std140_info<vec<4, float>>::base_alignment
);
public:
using type = array<vec<L, T>, C>;
static constexpr std::size_t base_alignment = element_alignment;
static constexpr std::size_t size = C * element_alignment;
static void write(std::span<ztu::u8> 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<int Dim, scalar T>
class std140_info<mat<Dim, Dim, T>>
{
// 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<Dim, T>;
using array_info = std140_info<array<column_info, Dim>>;
static constexpr std::size_t element_alignment = array_info::element_alignment;
public:
using type = mat<Dim, Dim, T>;
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<ztu::u8> 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<typename... Ts>
class std140_info<structure<Ts...>>
{
// 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<Ts>::base_alignment... }),
std140_info<vec<4, float>>::base_alignment
);
static constexpr auto offsets = to_array<C>(
std::array{ std::pair{ std140_info<Ts>::base_alignment, std140_info<Ts>::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<Ts...>;
static constexpr std::size_t base_alignment = N;
static constexpr std::size_t size = round_up_to(
offsets.back() + std140_info<typename last<Ts...>::type>::size,
base_alignment
);
static void write(std::span<ztu::u8> buffer, const type& s)
{
assert(size == buffer.size());
std::apply(
[&](const Ts&... elements)
{
[&]<auto... Is>(std::index_sequence<Is...>) {
(
std140_info<Ts>::write(
buffer.subspan(offsets[Is], std140_info<Ts>::size),
elements
),
...
);
}(std::index_sequence_for<Ts...>{});
},
s
);
}
};
template<std::size_t C, typename... Ts>
class std140_info<array<structure<Ts...>, 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<structure<Ts...>>;
static constexpr auto N = round_up_to(
element_info::base_alignment,
std140_info<vec<4, float>>::base_alignment
);
static constexpr std::size_t element_alignment = element_info::base_alignment;
public:
using type = array<structure<Ts...>, 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<ztu::u8> 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<typename T>
constexpr auto generate_std140_buffer(const T& value)
{
using info = detail::std140_info<T>;
std::array<ztu::u8, info::size> buffer{};
info::write(buffer, value);
return buffer;
}
} // namespace zgl::type_utils } // namespace zgl::type_utils

30
include/opengl/types.hpp Normal file
View File

@@ -0,0 +1,30 @@
#pragma once
#include <tuple>
#include <array>
#include "glm/gtc/type_aligned.hpp"
namespace zgl
{
template <typename T>
concept scalar = (
std::is_same_v<T, float> or
std::is_same_v<T, int> or
std::is_same_v<T, unsigned int> or
std::is_same_v<T, bool>
);
template<glm::length_t L, typename T>
using vec = glm::vec<L, T, glm::packed_highp>;
template<glm::length_t C, glm::length_t R, typename T>
using mat = glm::mat<C, R, T, glm::packed_highp>;
template<typename T, std::size_t Count>
using array = std::array<T, Count>;
template<typename... Ts>
using structure = std::tuple<Ts...>;
}

View File

@@ -1,88 +0,0 @@
#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>
void interlace(
std::vector<ztu::u8>& vertex_buffer,
const C components,
const std::size_t element_count,
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 buffer_size = stride * element_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, element_count))
{
std::memcpy(
&vertex_buffer[byte_offset],
&value,
sizeof(value)
);
byte_offset += stride;
}
},
buffers...
);
};
}

View File

@@ -7,19 +7,45 @@
//------------[ Uniforms ]------------// //------------[ Uniforms ]------------//
#ifdef TEXTURE #ifdef TEXTURE
layout (location = 3) uniform sampler2D tex; layout (binding = 0) uniform sampler2D tex;
#endif #endif
#ifdef LIGHTING #ifdef LIGHTING
layout (location = 5) uniform vec3 view_pos; // layout (location = 5) uniform vec3 view_pos;
layout (location = 6) uniform vec3 point_light_direction; // layout (location = 6) uniform vec3 point_light_direction;
layout (location = 7) uniform vec3 point_light_color; // layout (location = 7) uniform vec3 point_light_color;
layout (location = 8) uniform vec3 ambient_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 = 9) uniform vec3 ambient_filter;
layout (location = 11) uniform vec3 specular_filter; // layout (location = 10) uniform vec3 diffuse_filter;
layout (location = 12) uniform float shininess; // layout (location = 11) uniform vec3 specular_filter;
// layout (location = 12) uniform float shininess;
#endif #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 ]------------// //------------[ Inputs ]------------//
layout (location = 0) in vec4 frag_color; layout (location = 0) in vec4 frag_color;

View File

@@ -13,9 +13,11 @@
//------------[ Uniforms ]------------// //------------[ Uniforms ]------------//
layout (location = 0) uniform mat4 mvp_matrix; layout (location = 0) uniform mat4 mvp_matrix;
#ifdef LIGHTING #ifdef LIGHTING
layout (location = 1) uniform mat4 model_matrix; //layout (location = 1) uniform mat4 model_matrix;
#endif #endif
// Can be replaced by material ambient filter, right?!?
#ifdef U_RGBA #ifdef U_RGBA
layout (location = 4) uniform vec4 color; layout (location = 4) uniform vec4 color;
#endif #endif

View File

@@ -16,15 +16,20 @@ layout (location = 0) uniform mat4 mvp_matrix;
#ifdef LIGHTING #ifdef LIGHTING
layout (location = 1) uniform mat4 model_matrix; layout (location = 1) uniform mat4 model_matrix;
#endif #endif
layout (location = 2) uniform float point_size; layout (location = 2) uniform float point_size;
#ifdef U_RGBA #ifdef U_RGBA
layout (location = 4) uniform vec4 color; layout (location = 4) uniform vec4 color;
#endif #endif
#ifdef LIGHTING #ifdef LIGHTING
layout (location = 5) uniform vec3 view_pos; layout (location = 5) uniform vec3 view_pos;
layout (location = 6) uniform vec3 point_light_direction; layout (location = 6) uniform vec3 point_light_direction;
layout (location = 7) uniform vec3 point_light_color; layout (location = 7) uniform vec3 point_light_color;
layout (location = 8) uniform vec3 ambient_light_color; layout (location = 8) uniform vec3 ambient_light_color;
layout (location = 9) uniform vec3 ambient_filter; layout (location = 9) uniform vec3 ambient_filter;
layout (location = 10) uniform vec3 diffuse_filter; layout (location = 10) uniform vec3 diffuse_filter;
layout (location = 11) uniform vec3 specular_filter; layout (location = 11) uniform vec3 specular_filter;

View File

@@ -14,13 +14,17 @@
//------------[ Uniforms ]------------// //------------[ Uniforms ]------------//
layout (location = 0) uniform mat4 mvp_matrix; layout (location = 0) uniform mat4 mvp_matrix;
layout (location = 1) uniform float point_size; layout (location = 1) uniform float point_size;
#ifdef U_RGBA #ifdef U_RGBA
layout (location = 2) uniform vec4 color; layout (location = 2) uniform vec4 color;
#endif #endif
#ifdef LIGHTING #ifdef LIGHTING
layout (location = 3) uniform mat4 model_matrix; layout (location = 3) uniform mat4 model_matrix;
layout (location = 4) uniform vec3 camera_position; layout (location = 4) uniform vec3 camera_position;
#endif #endif
#ifdef RAINBOW #ifdef RAINBOW
layout (location = 5) uniform float rainbow_offset_y; layout (location = 5) uniform float rainbow_offset_y;
layout (location = 6) uniform float rainbow_scale_y; layout (location = 6) uniform float rainbow_scale_y;

View File

@@ -4,9 +4,9 @@
#include "opengl/error.hpp" #include "opengl/error.hpp"
#include "opengl/type_utils.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)) if (not m_resource_manager.has_resource(id))
{ {

View File

@@ -2,12 +2,12 @@
#include "util/logger.hpp" #include "util/logger.hpp"
#include "opengl/error.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)) 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(); m_byte_buffer.clear();
std::apply( type_utils::interlace_vertex_buffer(
[&](const auto&... component_buffers) m_byte_buffer,
{ mesh.component_flags,
vertex_buffer_utils::interlace( mesh.vertex_count,
m_byte_buffer,
mesh.component_flags,
mesh.vertex_count,
component_buffers...
);
},
mesh.vertex_component_arrays mesh.vertex_component_arrays
); );

View File

@@ -2,12 +2,12 @@
#include "util/logger.hpp" #include "util/logger.hpp"
#include "opengl/error.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)) 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(); m_byte_buffer.clear();
std::apply( type_utils::interlace_vertex_buffer(
[&](const auto&... component_buffers) m_byte_buffer,
{ point_cloud.vertex_component_flags,
vertex_buffer_utils::interlace( point_cloud.point_count,
m_byte_buffer,
point_cloud.vertex_component_flags,
point_cloud.point_count,
component_buffers...
);
},
point_cloud.vertex_component_arrays point_cloud.vertex_component_arrays
); );

View File

@@ -79,6 +79,11 @@ std::optional<std::pair<zgl::shader_metadata, zgl::shader_handle>> zgl::shader_m
return std::nullopt; return std::nullopt;
} }
void zgl::shader_manager::process(const store_type& shader_sources)
{
m_preprocessor.process(shader_sources);
}
void zgl::shader_manager::get_handles( void zgl::shader_manager::get_handles(
const assets::shader_source_store& shader_sources, const assets::shader_source_store& shader_sources,
std::span<const shading::shader_set_requirements> requirements, std::span<const shading::shader_set_requirements> requirements,
@@ -256,9 +261,3 @@ bool zgl::shader_manager::compile_shader(
return true; return true;
} }
void zgl::shader_manager::process(
const assets::data_stores& stores
) {
m_preprocessor.process(stores);
}

View File

@@ -24,10 +24,9 @@ struct prioritized_metadata_comparator
} }
}; };
void zgl::shader_program_manager::process( void zgl::shader_program_manager::process(const store_type& shader_sources)
const assets::data_stores& stores {
) { m_shader_manager.process(shader_sources);
m_shader_manager.preprocess(stores);
} }
void zgl::shader_program_manager::get_handles( void zgl::shader_program_manager::get_handles(

View File

@@ -76,12 +76,11 @@ private:
void zgl::shader_source_manager::process( void zgl::shader_source_manager::process(const store_type& shader_sources)
const assets::data_stores& stores {
) {
namespace language = shading::shader_metadata_language; 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_value_token_buffer.clear();
m_declaration_token_count_buffer.clear(); m_declaration_token_count_buffer.clear();

View File

@@ -5,12 +5,11 @@
#include "opengl/error.hpp" #include "opengl/error.hpp"
void zgl::texture_manager::process( void zgl::texture_manager::process(const store_type& textures)
const assets::data_stores& stores {
) {
m_texture_buffer.clear(); 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)) if (not m_resource_manager.has_resource(id))
{ {

View File

@@ -9,7 +9,7 @@ namespace zgl
{ {
shader_program_handle::attribute_support_type shader_program_handle::check_attribute_support( shader_program_handle::attribute_support_type shader_program_handle::check_attribute_support(
const std::span<const shader_program_variable> attributes const std::span<const shader_uniform> attributes
) const { ) const {
auto attribute_candidates = attribute_support_type{}; 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( shader_program_handle::uniform_support_type shader_program_handle::check_uniform_support(
const std::span<const shader_program_variable> uniforms const std::span<const shader_uniform> uniforms
) const { ) const {
auto uniform_candidates = uniform_support_type{}; auto uniform_candidates = uniform_support_type{};

View File

@@ -17,7 +17,7 @@ inline void shader_program_handle::unbind()
glUseProgram(0); glUseProgram(0);
} }
template<shader_program_variable::info_type VariableInfo, typename T> template<shader_uniform::info_type VariableInfo, typename T>
void shader_program_handle::set_uniform(const T& value) const void shader_program_handle::set_uniform(const T& value) const
{ {
if constexpr (std::same_as<T, glm::mat4x4>) if constexpr (std::same_as<T, glm::mat4x4>)

View File

@@ -11,8 +11,8 @@ namespace zgl
void shader_program_lookup::add( void shader_program_lookup::add(
const shader_program_handle& shader_program_handle, const shader_program_handle& shader_program_handle,
const std::span<const shader_program_variable> all_attributes, const std::span<const shader_uniform> all_attributes,
const std::span<const shader_program_variable> all_uniforms const std::span<const shader_uniform> all_uniforms
) { ) {
const auto attributes = shader_program_handle.check_attribute_support(all_attributes); const auto attributes = shader_program_handle.check_attribute_support(all_attributes);
const auto uniforms = shader_program_handle.check_uniform_support(all_uniforms); const auto uniforms = shader_program_handle.check_uniform_support(all_uniforms);
@@ -72,7 +72,7 @@ void shader_program_lookup::add(
std::optional<shader_program_handle> shader_program_lookup::find( std::optional<shader_program_handle> shader_program_lookup::find(
shader_program_handle::attribute_support_type attributes, shader_program_handle::attribute_support_type attributes,
shader_program_handle::uniform_support_type uniforms, shader_program_handle::uniform_support_type uniforms,
const std::span<const shader_program_variable> all_attributes const std::span<const shader_uniform> all_attributes
) const { ) const {
const auto lower_uniform = std::ranges::lower_bound( const auto lower_uniform = std::ranges::lower_bound(
@@ -158,7 +158,7 @@ std::optional<shader_program_handle> shader_program_lookup::find(
shader_program_lookup::attribute_locations_type shader_program_lookup::attribute_location_flags( shader_program_lookup::attribute_locations_type shader_program_lookup::attribute_location_flags(
shader_program_handle::attribute_support_type attributes, shader_program_handle::attribute_support_type attributes,
std::span<const shader_program_variable> all_attributes std::span<const shader_uniform> all_attributes
) { ) {
auto location_flags = ztu::u32{ 0 }; auto location_flags = ztu::u32{ 0 };