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,58 @@
#pragma once
#include "assets/data/texture.hpp"
#include "assets/data/surface_properties.hpp"
#include "assets/components/material_components.hpp"
#include "opengl/handles/material_handle.hpp"
#include "opengl/data/texture_data.hpp"
#include <system_error>
namespace zgl
{
struct material_data
{
private:
material_data(
const std::optional<texture_handle>& texture_handle,
const std::optional<surface_properties_handle>& surface_properties_handle,
const std::optional<alpha_handle>& alpha_handle,
std::optional<texture_data>&& texture_data,
components::material::flags components
);
public:
material_data() = default;
[[nodiscard]] static std::error_code build_from(
const std::optional<components::material::texture>& texture_opt,
const std::optional<components::material::surface_properties>& surface_properties_opt,
const std::optional<components::material::transparency>& transparency_opt,
material_component::flags components,
material_data& data
);
material_data(const material_data& other) = delete;
material_data& operator=(const material_data& other) = delete;
material_data(material_data&& other) noexcept;
material_data& operator=(material_data&& other) noexcept;
[[nodiscard]] material_handle handle() const;
[[nodiscard]] material_component::flags components() const;
private:
material_handle m_handle{};
std::optional<texture_data> m_texture_data{ std::nullopt };
material_component::flags m_component_types{
material_component::flags::none
};
};
}
#define INCLUDE_MATERIAL_DATA_IMPLEMENTATION
#include "opengl/data/material_data.ipp"
#undef INCLUDE_MATERIAL_DATA_IMPLEMENTATION

View File

@@ -0,0 +1,68 @@
#pragma once
#include "opengl/handles/mesh_handle.hpp"
#include "util/uix.hpp"
#include <system_error>
#include <span>
#include "assets/components/mesh_vertex_components.hpp"
#include "GL/glew.h"
namespace zgl
{
struct mesh_data
{
private:
mesh_data(
GLuint vertex_vbo_id,
GLuint index_vbo_id,
GLuint vao_id,
ztu::u32 material_id,
components::mesh_vertex::flags components,
GLsizei index_count
);
public:
mesh_data() = default;
[[nodiscard]] static std::error_code build_from(
std::span<const std::uint8_t> vertex_buffer,
std::span<const GLenum> component_types,
std::span<const GLint> component_lengths,
GLsizei stride,
std::span<const ztu::u32> index_buffer,
ztu::u32 material_id,
components::mesh_vertex::flags components,
mesh_data& data
);
mesh_data(const mesh_data& other) = delete;
mesh_data& operator=(const mesh_data& other) = delete;
mesh_data(mesh_data&& other) noexcept;
mesh_data& operator=(mesh_data&& other) noexcept;
~mesh_data();
[[nodiscard]] mesh_handle handle() const;
[[nodiscard]] components::mesh_vertex::flags components() const;
[[nodiscard]] ztu::u32 material_id() const;
private:
mesh_handle m_handle{};
GLuint m_vertex_vbo_id{ 0 };
GLuint m_index_vbo_id{ 0 };
ztu::u32 m_material_id{ 0 };
components::mesh_vertex::flags m_component_types{
components::mesh_vertex::flags::none
};
};
}
#define INCLUDE_MESH_DATA_IMPLEMENTATION
#include "opengl/data/mesh_data.ipp"
#undef INCLUDE_MESH_DATA_IMPLEMENTATION

View File

@@ -0,0 +1,55 @@
#pragma once
#include "util/uix.hpp"
#include <span>
#include <system_error>
#include "GL/glew.h"
#include "opengl/handles/point_cloud_handle.hpp"
#include "assets/components/point_cloud_vertex_components.hpp"
namespace zgl {
struct point_cloud_data {
private:
point_cloud_data(
GLuint vertex_buffer_id,
GLuint vao_id,
GLsizei point_count
);
public:
point_cloud_data() = default;
[[nodiscard]] static std::error_code build_from(
std::span<const std::uint8_t> point_buffer,
std::span<const GLenum> component_types,
std::span<const GLint> component_lengths,
GLsizei stride,
point_cloud_data& data
);
point_cloud_data(const point_cloud_data& other) = delete;
point_cloud_data& operator=(const point_cloud_data& other) = delete;
point_cloud_data(point_cloud_data&& other) noexcept;
point_cloud_data& operator=(point_cloud_data&& other) noexcept;
~point_cloud_data();
[[nodiscard]] point_cloud_handle handle() const;
[[nodiscard]] components::point_cloud_vertex::flags components() const;
private:
point_cloud_handle m_handle{};
GLuint m_vertex_vbo_id{ 0 };
components::point_cloud_vertex::flags m_component_types{
components::point_cloud_vertex::flags::none
};
};
}
#define INCLUDE_POINT_CLOUD_DATA_IMPLEMENTATION
#include "opengl/data/point_cloud_data.ipp"
#undef INCLUDE_POINT_CLOUD_DATA_IMPLEMENTATION

View File

@@ -0,0 +1,43 @@
#pragma once
#include <string>
#include <system_error>
#include "GL/glew.h"
#include "opengl/handles/shader_handle.hpp"
namespace zgl
{
class shader_data
{
private:
explicit shader_data(GLuint shader_id, GLenum type);
public:
shader_data() = default;
[[nodiscard]] static std::error_code build_from(
GLenum type,
const std::string& source,
shader_data& data
);
shader_data(const shader_data& other) = delete;
shader_data& operator=(const shader_data& other) = delete;
shader_data(shader_data&& other) noexcept;
shader_data& operator=(shader_data&& other) noexcept;
[[nodiscard]] shader_handle handle() const;
~shader_data();
private:
shader_handle m_handle{};
GLenum m_type{ GL_INVALID_ENUM };
};
}
#define INCLUDE_SHADER_DATA_IMPLEMENTATION
#include "opengl/data/shader_data.ipp"
#undef INCLUDE_SHADER_DATA_IMPLEMENTATION

View File

@@ -0,0 +1,45 @@
#pragma once
#include "GL/glew.h"
#include "opengl/handles/texture_handle.hpp"
#include <span>
namespace zgl
{
struct texture_data
{
private:
explicit texture_data(GLuint texture_id);
public:
texture_data() = default;
template<typename T>
[[nodiscard]] static std::error_code build_from(
std::span<const T> buffer,
GLenum format,
GLenum type,
GLsizei width,
GLsizei height,
texture_data& data
);
texture_data(const texture_data&) = delete;
texture_data& operator=(const texture_data&) = delete;
texture_data(texture_data&&) noexcept;
texture_data& operator=(texture_data&&) noexcept;
~texture_data();
[[nodiscard]] texture_handle handle() const;
private:
texture_handle m_handle{};
};
}
#define INCLUDE_TEXTURE_DATA_IMPLEMENTATION
#include "opengl/data/texture_data.ipp"
#undef INCLUDE_TEXTURE_DATA_IMPLEMENTATION

View File

@@ -0,0 +1,84 @@
#pragma once
#include "../../assets/dynamic_read_buffers"
#include "assets/dynamic_data_stores/dynamic_texture_store.hpp"
#include "opengl/data/texture_data.hpp"
#include <vector>
namespace zgl
{
class texture_data_uploader
{
void upload(
std::span<const dynamic_texture_data> dynamic_data,
std::span<const dynamic_texture_store::id_type> dynamic_data_ids
) {
std::vector<GLuint> texture_ids;
std::vector<GLuint> invalid_texture_ids;
texture_ids.resize(dynamic_data.size());
glGenTextures(texture_ids.size(), texture_ids.data());
auto texture_id_it = texture_ids.begin();
for (std::size_t i{}; i != dynamic_data.size(); ++i)
{
const auto& texture_id = *texture_id_it;
const auto& texture = dynamic_data[i];
glBindTexture(GL_TEXTURE_2D, texture_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GLenum format;
switch (texture.components()) {
using enum components::texture::flags;
case luminance:
format = GL_LUMINANCE;
break;
case luminance | alpha:
format = GL_LUMINANCE_ALPHA;
break;
case red | green | blue:
format = GL_RGB;
break;
case red | green | blue | alpha:
format = GL_RGBA;
break;
default:
format = GL_INVALID_ENUM;
break;
}
if (format == GL_INVALID_ENUM)
{
invalid_texture_ids.push_back(texture_id);
}
else
{
glTexImage2D(
GL_TEXTURE_2D, 0,
GL_RGBA8,
texture.width(),
texture.height(),
0,
format,
GL_UNSIGNED_BYTE,
texture.data()
);
glGenerateMipmap(GL_TEXTURE_2D);
}
}
glBindTexture(GL_TEXTURE_2D, 0);
glDeleteTextures(invalid_texture_ids.size(), invalid_texture_ids.data());
}
};
}

View File

@@ -0,0 +1,13 @@
#pragma once
#include "GL/glew.h"
namespace zgl
{
struct shader_handle
{
constexpr bool operator==(const shader_handle&) const = default;
GLuint shader_id{ 0 };
};
}

View File

@@ -0,0 +1,43 @@
#pragma once
#include "opengl/handles/shader_program_handle.hpp"
#include <optional>
#include <vector>
namespace zgl {
class shader_program_lookup
{
public:
void add(
const shader_program_handle& shader_program_handle,
std::span<const shader_program_variable> all_attributes,
std::span<const shader_program_variable> all_uniforms
);
[[nodiscard]] std::optional<shader_program_handle> find(
shader_program_handle::attribute_support_type attributes,
shader_program_handle::uniform_support_type uniforms,
std::span<const shader_program_variable> all_attributes
) const;
void print();
private:
using attribute_locations_type = ztu::u32;
[[nodiscard]] static attribute_locations_type attribute_location_flags(
shader_program_handle::attribute_support_type attributes,
std::span<const shader_program_variable> all_attributes
);
struct attribute_entry_type
{
shader_program_handle::attribute_support_type attributes;
attribute_locations_type locations; // Do not go past location 31!!!
};
std::vector<shader_program_handle::uniform_support_type> m_mesh_shader_program_uniforms;
std::vector<attribute_entry_type> m_mesh_shader_program_attributes;
std::vector<shader_program_handle> m_mesh_shader_programs;
};
}