This commit is contained in:
ZY4N
2024-12-22 16:58:40 +01:00
parent 2704814de2
commit db8db8f9d7
161 changed files with 17102 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
#pragma once
#include "opengl/handles/shader_program_handle.hpp"
#include "rendering/batches/mesh_batch.hpp"
#include "assets/components/mesh_vertex_components.hpp"
#include "assets/components/material_components.hpp"
#include "opengl/handles/material_handle.hpp"
#include <span>
#include "geometry/aabb.hpp"
#include "rendering/modes/mesh_modes.hpp"
#include "rendering/shader_program_lookups/mesh_lookup.hpp"
#include "scene/lighting_setup.hpp"
namespace rendering
{
class mesh_batch_renderer
{
public:
using batch_components_type = std::pair<
components::mesh_vertex::flags,
material_component::flags
>;
using batch_type = mesh_batch;
using batch_index_type = ztu::u32;
using batch_id_type = batch_index_type;
using id_type = std::pair<batch_id_type, batch_type::id_type>;
explicit mesh_batch_renderer(int render_mode_count);
std::optional<id_type> add(
const batch_components_type& batch_component,
const zgl::mesh_handle& mesh,
const aabb& bounding_box,
const zgl::model_matrix_handle& transform,
const zgl::material_handle& material,
const shader_program_lookups::mesh_lookup& shader_program_lookup
);
std::optional<aabb> bounding_box(id_type);
bool remove(id_type mesh_id);
void render(
modes::mesh render_mode,
const glm::mat4& vp_matrix,
const glm::mat4& view_matrix,
const glm::vec3& view_pos,
const lighting_setup& lights
);
protected:
[[nodiscard]] std::pair<std::size_t, bool> lookup_batch(const batch_components_type& batch_components) const;
private:
int m_render_mode_count;
std::vector<std::pair<batch_components_type, batch_index_type>> m_component_lookup{};
std::vector<batch_id_type> m_id_lookup{};
std::vector<std::pair<batch_type, batch_components_type>> m_batches{};
std::vector<zgl::shader_program_handle> m_shader_programs{};
batch_id_type m_next_batch_id{ 0 };
};
}

View File

@@ -0,0 +1,59 @@
#pragma once
#include "opengl/handles/shader_program_handle.hpp"
#include "rendering/batches/point_cloud_batch.hpp"
#include "assets/components/point_cloud_vertex_components.hpp"
#include "rendering/modes/point_cloud_modes.hpp"
#include <optional>
#include "scene/lighting_setup.hpp"
#include "rendering/shader_program_lookups/point_cloud_lookup.hpp"
namespace rendering
{
class point_cloud_batch_renderer
{
public:
using batch_components_type = components::point_cloud_vertex::flags;
using batch_type = point_cloud_batch;
using batch_index_type = ztu::u32;
using batch_id_type = batch_index_type;
using id_type = std::pair<batch_id_type, batch_type::id_type>;
explicit point_cloud_batch_renderer(int render_mode_count);
std::optional<id_type> add(
batch_components_type batch_components,
const zgl::point_cloud_handle& point_cloud,
const aabb& bounding_box,
const zgl::model_matrix_handle& transform,
const shader_program_lookups::point_cloud_lookup& shader_program_lookup
);
std::optional<aabb> bounding_box(id_type id);
bool remove(id_type id);
void render(
modes::point_cloud render_mode,
const glm::mat4& vp_matrix,
const glm::vec3& camera_position,
const lighting_setup&
);
protected:
[[nodiscard]] std::pair<std::size_t, bool> lookup_batch(const batch_components_type& batch_component) const;
private:
int m_render_mode_count;
std::vector<std::pair<batch_components_type, batch_index_type>> m_component_lookup;
std::vector<batch_id_type> m_id_lookup;
std::vector<std::pair<batch_type, batch_components_type>> m_batches;
std::vector<zgl::shader_program_handle> m_shader_programs;
batch_id_type m_next_batch_id{ 0 };
};
}

View File

@@ -0,0 +1,55 @@
#pragma once
#include <vector>
#include <span>
#include "opengl/handles/mesh_handle.hpp"
#include "opengl/handles/matrix_handles.hpp"
#include "opengl/handles/texture_handle.hpp"
#include "opengl/handles/mesh_handle.hpp"
#include "opengl/handles/material_handle.hpp"
#include "geometry/aabb.hpp"
class mesh_batch
{
public:
using id_type = ztu::u32;
inline id_type add(
const zgl::mesh_handle& mesh,
const aabb& bounding_box,
const zgl::model_matrix_handle& transform,
const zgl::material_handle& material
);
inline std::optional<aabb> bounding_box(id_type id);
inline bool remove(id_type id);
[[nodiscard]] inline std::span<const zgl::mesh_handle> meshes() const;
[[nodiscard]] inline std::span<const aabb> bounding_boxes() const;
[[nodiscard]] inline std::span<const zgl::model_matrix_handle> transforms() const;
[[nodiscard]] inline std::span<const zgl::texture_handle> textures() const;
[[nodiscard]] inline std::span<const zgl::surface_properties_handle> surface_properties() const;
[[nodiscard]] inline std::span<const zgl::alpha_handle> alphas() const;
private:
std::vector<zgl::mesh_handle> m_meshes{};
std::vector<aabb> m_bounding_boxes{};
std::vector<zgl::model_matrix_handle> m_transforms{};
std::vector<zgl::texture_handle> m_textures{};
std::vector<zgl::surface_properties_handle> m_surface_properties{};
std::vector<zgl::alpha_handle> m_alphas{};
std::vector<id_type> m_id_lookup{};
id_type m_next_mesh_id{ 0 };
};
#define INCLUDE_MESH_BATCH_IMPLEMENTATION
#include "rendering/batches/mesh_batch.ipp"
#undef INCLUDE_MESH_BATCH_IMPLEMENTATION

View File

@@ -0,0 +1,46 @@
#pragma once
#include <vector>
#include "opengl/handles/point_cloud_handle.hpp"
#include "opengl/handles/matrix_handles.hpp"
#include <span>
#include "geometry/aabb.hpp"
#include <optional>
class point_cloud_batch
{
public:
using id_type = ztu::u32;
point_cloud_batch() = default;
inline id_type add(
const zgl::point_cloud_handle& point_cloud,
const aabb& bounding_box,
const zgl::model_matrix_handle& transform
);
inline std::optional<aabb> bounding_box(id_type id);
inline bool remove(id_type id);
[[nodiscard]] inline std::span<const zgl::point_cloud_handle> point_clouds() const;
[[nodiscard]] inline std::span<const zgl::model_matrix_handle> transforms() const;
[[nodiscard]] inline std::span<const aabb> bounding_boxes() const;
private:
std::vector<zgl::point_cloud_handle> m_point_clouds{};
std::vector<zgl::model_matrix_handle> m_transforms{};
std::vector<aabb> m_bounding_boxes{};
std::vector<id_type> m_id_lookup{};
id_type m_next_id{ 0 };
};
#define INCLUDE_POINT_CLOUD_BATCH_IMPLEMENTATION
#include "rendering/batches/point_cloud_batch.ipp"
#undef INCLUDE_POINT_CLOUD_BATCH_IMPLEMENTATION

View File

@@ -0,0 +1,13 @@
#pragma once
namespace rendering::modes
{
enum class mesh
{
wire_frame,
points,
faces,
lit_faces,
count
};
};

View File

@@ -0,0 +1,11 @@
#pragma once
namespace rendering::modes
{
enum class point_cloud
{
uniform_color,
rainbow,
count
};
}

View File

@@ -0,0 +1,127 @@
#pragma once
#include "assets/components/material_components.hpp"
#include "assets/components/mesh_vertex_components.hpp"
#include "shader_program/capabilities/mesh_capabilities.hpp"
#include <array>
namespace rendering::requirements::mesh
{
struct type
{
shader_program::capabilities::mesh::indices::type shader_program_requirement_index{};
components::mesh_vertex::flags vertex_requirements{
components::mesh_vertex::flags::none
};
material_component::flags material_requirements{
material_component::flags::none
};
};
enum class flags : int
{
none = 0,
position = 1 << 0,
lit = 1 << 1,
textured = 1 << 2,
uniform_color = 1 << 3,
uniform_alpha = 1 << 4,
point = 1 << 5
};
constexpr inline auto position = type{
.shader_program_requirement_index = shader_program::capabilities::mesh::indices::position,
.vertex_requirements = components::mesh_vertex::flags::position
};
constexpr inline auto lit = type{
.shader_program_requirement_index = shader_program::capabilities::mesh::indices::lit,
.vertex_requirements = components::mesh_vertex::flags::normal,
.material_requirements = material_component::flags::surface_properties
};
constexpr inline auto point = type{
.shader_program_requirement_index = shader_program::capabilities::mesh::indices::point
};
constexpr inline auto textured = type{
.shader_program_requirement_index = shader_program::capabilities::mesh::indices::textured,
.vertex_requirements = components::mesh_vertex::flags::tex_coord,
.material_requirements = material_component::flags::texture,
};
constexpr inline auto uniform_color = type{
.shader_program_requirement_index = shader_program::capabilities::mesh::indices::uniform_color
};
constexpr inline auto uniform_alpha = type{
.shader_program_requirement_index = shader_program::capabilities::mesh::indices::uniform_alpha,
.material_requirements = material_component::flags::transparency
};
constexpr inline auto all = std::array{
position, lit, textured, uniform_color, uniform_alpha, point
};
}
[[nodiscard]] constexpr rendering::requirements::mesh::flags operator|(
const rendering::requirements::mesh::flags& a, const rendering::requirements::mesh::flags& b
) {
return static_cast<rendering::requirements::mesh::flags>(static_cast<int>(a) | static_cast<int>(b));
}
[[nodiscard]] constexpr rendering::requirements::mesh::flags operator&(
const rendering::requirements::mesh::flags& a, const rendering::requirements::mesh::flags& b
) {
return static_cast<rendering::requirements::mesh::flags>(static_cast<int>(a) & static_cast<int>(b));
}
[[nodiscard]] constexpr rendering::requirements::mesh::flags operator^(
const rendering::requirements::mesh::flags& a, const rendering::requirements::mesh::flags& b
) {
return static_cast<rendering::requirements::mesh::flags>(static_cast<int>(a) ^ static_cast<int>(b));
}
[[nodiscard]] constexpr rendering::requirements::mesh::flags operator~(const rendering::requirements::mesh::flags& a) {
return static_cast<rendering::requirements::mesh::flags>(~static_cast<int>(a));
}
constexpr rendering::requirements::mesh::flags& operator|=(rendering::requirements::mesh::flags& a, const rendering::requirements::mesh::flags& b) {
return a = a | b;
}
constexpr rendering::requirements::mesh::flags& operator&=(rendering::requirements::mesh::flags& a, const rendering::requirements::mesh::flags& b) {
return a = a & b;
}
constexpr rendering::requirements::mesh::flags& operator^=(rendering::requirements::mesh::flags& a, const rendering::requirements::mesh::flags& b) {
return a = a ^ b;
}
[[nodiscard]] constexpr bool operator<(
rendering::requirements::mesh::flags lhs, rendering::requirements::mesh::flags rhs
) {
return static_cast<int>(lhs) < static_cast<int>(rhs);
}
[[nodiscard]] constexpr bool operator<=(
rendering::requirements::mesh::flags lhs, rendering::requirements::mesh::flags rhs
) {
return static_cast<int>(lhs) <= static_cast<int>(rhs);
}
[[nodiscard]] constexpr bool operator>(
rendering::requirements::mesh::flags lhs, rendering::requirements::mesh::flags rhs
) {
return static_cast<int>(lhs) > static_cast<int>(rhs);
}
[[nodiscard]] constexpr bool operator>=(
rendering::requirements::mesh::flags lhs, rendering::requirements::mesh::flags rhs
) {
return static_cast<int>(lhs) >= static_cast<int>(rhs);
}

View File

@@ -0,0 +1,122 @@
#pragma once
#include "assets/components/point_cloud_vertex_components.hpp"
#include "shader_program/capabilities/point_cloud_capabilities.hpp"
#include <array>
namespace rendering::requirements::point_cloud
{
struct type
{
shader_program::capabilities::point_cloud::indices::type shader_program_requirement_index{};
components::point_cloud_vertex::flags vertex_requirements{
components::point_cloud_vertex::flags::none
};
};
enum class flags : int
{
none = 0,
position = 1 << 0,
vertex_color = 1 << 1,
uniform_color = 1 << 2,
normal = 1 << 3,
reflectance = 1 << 4,
rainbow = 1 << 5
};
constexpr inline auto position = type{
.shader_program_requirement_index = shader_program::capabilities::point_cloud::indices::position,
.vertex_requirements = components::point_cloud_vertex::flags::position
};
constexpr inline auto rainbow = type{
.shader_program_requirement_index = shader_program::capabilities::point_cloud::indices::rainbow
};
constexpr inline auto vertex_color = type{
.shader_program_requirement_index = shader_program::capabilities::point_cloud::indices::vertex_color,
.vertex_requirements = components::point_cloud_vertex::flags::color
};
constexpr inline auto uniform_color = type{
.shader_program_requirement_index = shader_program::capabilities::point_cloud::indices::uniform_color
};
constexpr inline auto normal = type{
.shader_program_requirement_index = shader_program::capabilities::point_cloud::indices::normal,
.vertex_requirements = components::point_cloud_vertex::flags::normal
};
constexpr inline auto reflectance = type{
.shader_program_requirement_index = shader_program::capabilities::point_cloud::indices::reflectance,
.vertex_requirements = components::point_cloud_vertex::flags::reflectance
};
constexpr inline auto all = std::array{
position, vertex_color, uniform_color, normal, reflectance, rainbow
};
}
[[nodiscard]] constexpr rendering::requirements::point_cloud::flags operator|(
const rendering::requirements::point_cloud::flags& a, const rendering::requirements::point_cloud::flags& b
) {
return static_cast<rendering::requirements::point_cloud::flags>(static_cast<int>(a) | static_cast<int>(b));
}
[[nodiscard]] constexpr rendering::requirements::point_cloud::flags operator&(
const rendering::requirements::point_cloud::flags& a, const rendering::requirements::point_cloud::flags& b
) {
return static_cast<rendering::requirements::point_cloud::flags>(static_cast<int>(a) & static_cast<int>(b));
}
[[nodiscard]] constexpr rendering::requirements::point_cloud::flags operator^(
const rendering::requirements::point_cloud::flags& a, const rendering::requirements::point_cloud::flags& b
) {
return static_cast<rendering::requirements::point_cloud::flags>(static_cast<int>(a) ^ static_cast<int>(b));
}
[[nodiscard]] constexpr rendering::requirements::point_cloud::flags operator~(const rendering::requirements::point_cloud::flags& a) {
return static_cast<rendering::requirements::point_cloud::flags>(~static_cast<int>(a));
}
constexpr rendering::requirements::point_cloud::flags& operator|=(rendering::requirements::point_cloud::flags& a, const rendering::requirements::point_cloud::flags& b) {
return a = a | b;
}
constexpr rendering::requirements::point_cloud::flags& operator&=(rendering::requirements::point_cloud::flags& a, const rendering::requirements::point_cloud::flags& b) {
return a = a & b;
}
constexpr rendering::requirements::point_cloud::flags& operator^=(rendering::requirements::point_cloud::flags& a, const rendering::requirements::point_cloud::flags& b) {
return a = a ^ b;
}
[[nodiscard]] constexpr bool operator<(
rendering::requirements::point_cloud::flags lhs, rendering::requirements::point_cloud::flags rhs
) {
return static_cast<int>(lhs) < static_cast<int>(rhs);
}
[[nodiscard]] constexpr bool operator<=(
rendering::requirements::point_cloud::flags lhs, rendering::requirements::point_cloud::flags rhs
) {
return static_cast<int>(lhs) <= static_cast<int>(rhs);
}
[[nodiscard]] constexpr bool operator>(
rendering::requirements::point_cloud::flags lhs, rendering::requirements::point_cloud::flags rhs
) {
return static_cast<int>(lhs) > static_cast<int>(rhs);
}
[[nodiscard]] constexpr bool operator>=(
rendering::requirements::point_cloud::flags lhs, rendering::requirements::point_cloud::flags rhs
) {
return static_cast<int>(lhs) >= static_cast<int>(rhs);
}

View File

@@ -0,0 +1,27 @@
#pragma once
#include "opengl/shader_program_lookup.hpp"
#include "opengl/handles/shader_program_handle.hpp"
#include "rendering/requirements/mesh_requirements.hpp"
namespace rendering::shader_program_lookups
{
class mesh_lookup
{
public:
void add(
const zgl::shader_program_handle& shader_program_handle
);
[[nodiscard]] std::optional<zgl::shader_program_handle> find(
requirements::mesh::flags requirements
) const;
void print();
private:
zgl::shader_program_lookup m_shader_program_lookup;
};
}

View File

@@ -0,0 +1,25 @@
#pragma once
#include "opengl/shader_program_lookup.hpp"
#include "opengl/handles/shader_program_handle.hpp"
#include "rendering/requirements/point_cloud_requirements.hpp"
namespace rendering::shader_program_lookups
{
class point_cloud_lookup
{
public:
void add(
const zgl::shader_program_handle& shader_program_handle
);
[[nodiscard]] std::optional<zgl::shader_program_handle> find(
requirements::point_cloud::flags requirements
) const;
private:
zgl::shader_program_lookup m_program_lookup;
};
}