initial commit
This commit is contained in:
58
include/assets/data_loaders/generic/generic_3dtk_loader.hpp
Normal file
58
include/assets/data_loaders/generic/generic_3dtk_loader.hpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <charconv>
|
||||
#include <string_view>
|
||||
|
||||
#include "glm/mat4x4.hpp"
|
||||
#include "util/result.hpp"
|
||||
#include "util/string_list.hpp"
|
||||
#include "assets/prefetch_queue.hpp"
|
||||
|
||||
#include "assets/dynamic_read_buffers/dynamic_point_cloud_buffer.hpp"
|
||||
#include "assets/dynamic_data_stores/dynamic_point_cloud_store.hpp"
|
||||
#include "assets/prefetch_lookup.hpp"
|
||||
|
||||
|
||||
|
||||
template<bool Normal, bool Color, bool Reflectance>
|
||||
struct generic_3dtk_loader
|
||||
{
|
||||
[[nodiscard]] static std::error_code prefetch(
|
||||
const ztu::string_list& filenames,
|
||||
prefetch_queue& queue
|
||||
);
|
||||
|
||||
[[nodiscard]] static std::error_code load(
|
||||
dynamic_point_cloud_buffer& buffer,
|
||||
const file_dir_list& paths,
|
||||
prefetch_lookup& asset_lookup,
|
||||
dynamic_point_cloud_store& store,
|
||||
bool pedantic = false
|
||||
);
|
||||
|
||||
protected:
|
||||
|
||||
[[nodiscard]] static ztu::result<pose_prefetch_lookup::index_type> parse_index(
|
||||
std::string_view filename
|
||||
);
|
||||
|
||||
ztu::result<std::pair<ztu::u32, std::chars_format>> analyze_component_format(
|
||||
std::string_view line
|
||||
);
|
||||
|
||||
void transform_point_cloud(
|
||||
std::span<components::point_cloud_vertex::position::value_type> points,
|
||||
const glm::mat4& pose
|
||||
);
|
||||
|
||||
private:
|
||||
std::error_code read_point_file(
|
||||
const std::filesystem::path& filename,
|
||||
dynamic_point_cloud_buffer& point_cloud
|
||||
);
|
||||
};
|
||||
|
||||
#define INCLUDE_GENERIC_3DTK_LOADER_IMPLEMENTATION
|
||||
#include "assets/data_loaders/generic/generic_3dtk_loader.ipp"
|
||||
#undef INCLUDE_GENERIC_3DTK_LOADER_IMPLEMENTATION
|
||||
91
include/geometry/aabb.hpp
Executable file
91
include/geometry/aabb.hpp
Executable file
@@ -0,0 +1,91 @@
|
||||
#pragma once
|
||||
|
||||
#include "glm/glm.hpp"
|
||||
|
||||
#include <limits>
|
||||
#include <algorithm>
|
||||
#include <span>
|
||||
#include <array>
|
||||
|
||||
struct aabb
|
||||
{
|
||||
using vector_type = glm::vec3;
|
||||
using scalar_type = vector_type::value_type;
|
||||
using index_type = vector_type::length_type;
|
||||
|
||||
static constexpr auto default_min = std::numeric_limits<scalar_type>::max();
|
||||
static constexpr auto default_max =-std::numeric_limits<scalar_type>::max();
|
||||
|
||||
vector_type min { default_min, default_min, default_min };
|
||||
vector_type max { default_max, default_max, default_max };
|
||||
|
||||
[[nodiscard]] vector_type size() const
|
||||
{
|
||||
return max - min;
|
||||
}
|
||||
|
||||
[[nodiscard]] vector_type center() const
|
||||
{
|
||||
return min + 0.5f * size();
|
||||
}
|
||||
|
||||
[[nodiscard]] vector_type closest_point_inside(const vector_type& point) const {
|
||||
return {
|
||||
std::clamp(point.x, min.x, max.x),
|
||||
std::clamp(point.y, min.y, max.y),
|
||||
std::clamp(point.z, min.z, max.z)
|
||||
};
|
||||
}
|
||||
|
||||
aabb& add_aabb(const aabb& other)
|
||||
{
|
||||
for (index_type i{}; i != min.length(); ++i)
|
||||
{
|
||||
min[i] = std::min(min[i], other.min[i]);
|
||||
max[i] = std::max(max[i], other.max[i]);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
aabb& add_point(const auto& point)
|
||||
{
|
||||
for (index_type i{}; i != min.length(); ++i)
|
||||
{
|
||||
min[i] = std::min(min[i], point[i]);
|
||||
max[i] = std::max(max[i], point[i]);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
aabb& add_points(std::span<const T> points)
|
||||
{
|
||||
for (const auto& point : points)
|
||||
{
|
||||
add_point(point);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
aabb& join(const aabb& other)
|
||||
{
|
||||
min = glm::min(min, other.min);
|
||||
max = glm::max(max, other.max);
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] aabb transformed(const glm::mat4x4& matrix) const
|
||||
{
|
||||
const auto vertices = std::array{
|
||||
vector_type{ matrix * glm::vec4{ min.x, min.y, min.z, 1 } },
|
||||
vector_type{ matrix * glm::vec4{ min.x, min.y, max.z, 1 } },
|
||||
vector_type{ matrix * glm::vec4{ min.x, max.y, min.z, 1 } },
|
||||
vector_type{ matrix * glm::vec4{ min.x, max.y, max.z, 1 } },
|
||||
vector_type{ matrix * glm::vec4{ max.x, min.y, min.z, 1 } },
|
||||
vector_type{ matrix * glm::vec4{ max.x, min.y, max.z, 1 } },
|
||||
vector_type{ matrix * glm::vec4{ max.x, max.y, min.z, 1 } },
|
||||
vector_type{ matrix * glm::vec4{ max.x, max.y, max.z, 1 } }
|
||||
};
|
||||
return aabb{}.add_points<vector_type>(vertices);
|
||||
}
|
||||
};
|
||||
14
include/geometry/normal_estimation.hpp
Normal file
14
include/geometry/normal_estimation.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <span>
|
||||
|
||||
#include "util/uix.hpp"
|
||||
#include "assets/components/mesh_vertex_components.hpp"
|
||||
|
||||
void estimate_normals(
|
||||
std::span<const components::mesh_vertex::position::value_type> vertices,
|
||||
std::span<const std::array<ztu::u32, 3>> triangles,
|
||||
std::vector<components::mesh_vertex::normal::value_type>& normals
|
||||
);
|
||||
45
include/opengl/data/shader_program_data.hpp
Executable file
45
include/opengl/data/shader_program_data.hpp
Executable file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "GL/glew.h"
|
||||
#include <system_error>
|
||||
|
||||
#include "opengl/handles/shader_handle.hpp"
|
||||
#include "opengl/handles/shader_program_handle.hpp"
|
||||
|
||||
namespace zgl
|
||||
{
|
||||
class shader_program_data
|
||||
{
|
||||
private:
|
||||
explicit shader_program_data(GLuint program_id);
|
||||
|
||||
public:
|
||||
|
||||
shader_program_data() = default;
|
||||
|
||||
[[nodiscard]] static std::error_code build_from(
|
||||
const shader_handle& vertex_shader,
|
||||
const shader_handle& geometry_shader,
|
||||
const shader_handle& fragment_shader,
|
||||
shader_program_data& data
|
||||
);
|
||||
|
||||
shader_program_data(const shader_program_data& other) = delete;
|
||||
shader_program_data& operator=(const shader_program_data& other) = delete;
|
||||
|
||||
shader_program_data(shader_program_data&& other) noexcept ;
|
||||
shader_program_data& operator=(shader_program_data&& other) noexcept;
|
||||
|
||||
[[nodiscard]] shader_program_handle handle() const;
|
||||
|
||||
~shader_program_data();
|
||||
|
||||
private:
|
||||
shader_program_handle m_handle{};
|
||||
};
|
||||
}
|
||||
|
||||
#define INCLUDE_SHADER_PROGRAM_DATA_IMPLEMENTATION
|
||||
#include "opengl/data/shader_program_data.ipp"
|
||||
#undef INCLUDE_SHADER_PROGRAM_DATA_IMPLEMENTATION
|
||||
74
include/opengl/error.hpp
Normal file
74
include/opengl/error.hpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
|
||||
#include <system_error>
|
||||
#include "GL/glew.h"
|
||||
|
||||
namespace zgl
|
||||
{
|
||||
namespace error
|
||||
{
|
||||
|
||||
enum class codes : GLenum {
|
||||
ok = GL_NO_ERROR,
|
||||
invalid_enum = GL_INVALID_ENUM,
|
||||
invalid_value = GL_INVALID_VALUE,
|
||||
invalid_operation = GL_INVALID_OPERATION,
|
||||
invalid_framebuffer_operation = GL_INVALID_FRAMEBUFFER_OPERATION,
|
||||
out_of_memory = GL_OUT_OF_MEMORY,
|
||||
stack_overflow = GL_STACK_OVERFLOW,
|
||||
stack_underflow = GL_STACK_UNDERFLOW,
|
||||
context_lost = GL_CONTEXT_LOST
|
||||
};
|
||||
|
||||
struct category : std::error_category
|
||||
{
|
||||
[[nodiscard]] const char* name() const noexcept override
|
||||
{
|
||||
return "opengl";
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string message(int ev) const override
|
||||
{
|
||||
switch (static_cast<codes>(ev)) {
|
||||
using enum codes;
|
||||
case ok:
|
||||
return "No error has been recorded.";
|
||||
case invalid_enum:
|
||||
return "An unacceptable value is specified for an enumerated argument.";
|
||||
case invalid_value:
|
||||
return "A numeric argument is out of range.";
|
||||
case invalid_operation:
|
||||
return "The specified operation is not allowed in the current state.";
|
||||
case invalid_framebuffer_operation:
|
||||
return "The framebuffer object is not complete.";
|
||||
case out_of_memory:
|
||||
return "There is not enough memory left to execute the command.";
|
||||
case stack_overflow:
|
||||
return "An attempt has been made to perform an operation that would cause an internal stack to underflow.";
|
||||
case stack_underflow:
|
||||
return "An attempt has been made to perform an operation that would cause an internal stack to overflow.";
|
||||
case context_lost:
|
||||
return "The OpenGL context has been lost.";
|
||||
default:
|
||||
return "<unknown>";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace error
|
||||
|
||||
[[nodiscard]] inline std::error_category& error_category() noexcept
|
||||
{
|
||||
static error::category category;
|
||||
return category;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline std::error_code make_error_code(const GLenum e) noexcept
|
||||
{
|
||||
return { static_cast<int>(e), error_category() };
|
||||
}
|
||||
|
||||
} // namespace zgl
|
||||
|
||||
template<>
|
||||
struct std::is_error_code_enum<zgl::error::codes> : std::true_type {};
|
||||
8
include/opengl/handles/alpha_handle.hpp
Normal file
8
include/opengl/handles/alpha_handle.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
namespace zgl
|
||||
{
|
||||
|
||||
using alpha_handle = float;
|
||||
|
||||
} // namespace zgl
|
||||
16
include/opengl/handles/material_handle.hpp
Normal file
16
include/opengl/handles/material_handle.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include "opengl/handles/texture_handle.hpp"
|
||||
#include "opengl/handles/surface_properties_handle.hpp"
|
||||
#include "opengl/handles/alpha_handle.hpp"
|
||||
|
||||
namespace zgl
|
||||
{
|
||||
struct material_handle
|
||||
{
|
||||
std::optional<texture_handle> texture{ std::nullopt };
|
||||
std::optional<surface_properties_handle> surface_properties{ std::nullopt };
|
||||
std::optional<alpha_handle> alpha{ std::nullopt };
|
||||
};
|
||||
}
|
||||
12
include/opengl/handles/matrix_handles.hpp
Normal file
12
include/opengl/handles/matrix_handles.hpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "glm/glm.hpp"
|
||||
|
||||
namespace zgl
|
||||
{
|
||||
using model_matrix_handle = glm::mat4x4;
|
||||
|
||||
using view_matrix_handle = glm::mat4x4;
|
||||
|
||||
using projection_matrix_handle = glm::mat4x4;
|
||||
}
|
||||
20
include/opengl/handles/mesh_handle.hpp
Executable file
20
include/opengl/handles/mesh_handle.hpp
Executable file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "GL/glew.h"
|
||||
#include "util/uix.hpp"
|
||||
|
||||
namespace zgl
|
||||
{
|
||||
struct mesh_handle
|
||||
{
|
||||
inline void bind() const;
|
||||
inline static void unbind();
|
||||
|
||||
GLuint vao_id{ 0 };
|
||||
GLsizei index_count{ 0 };
|
||||
};
|
||||
}
|
||||
|
||||
#define INCLUDE_MESH_INSTANCE_IMPLEMENTATION
|
||||
#include "opengl/handles/mesh_handle.ipp"
|
||||
#undef INCLUDE_MESH_INSTANCE_IMPLEMENTATION
|
||||
20
include/opengl/handles/point_cloud_handle.hpp
Executable file
20
include/opengl/handles/point_cloud_handle.hpp
Executable file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "GL/glew.h"
|
||||
#include "util/uix.hpp"
|
||||
|
||||
namespace zgl
|
||||
{
|
||||
struct point_cloud_handle
|
||||
{
|
||||
inline void bind() const;
|
||||
inline static void unbind();
|
||||
|
||||
GLuint vao_id{ 0 };
|
||||
GLsizei point_count{ 0 };
|
||||
};
|
||||
}
|
||||
|
||||
#define INCLUDE_POINT_CLOUD_INSTANCE_IMPLEMENTATION
|
||||
#include "opengl/handles/point_cloud_handle.ipp"
|
||||
#undef INCLUDE_POINT_CLOUD_INSTANCE_IMPLEMENTATION
|
||||
33
include/opengl/handles/shader_program_handle.hpp
Normal file
33
include/opengl/handles/shader_program_handle.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "GL/glew.h"
|
||||
#include "opengl/shader_program_variable.hpp"
|
||||
|
||||
#include "opengl/shader_program_variable.hpp"
|
||||
#include "util/uix.hpp"
|
||||
#include <span>
|
||||
|
||||
namespace zgl
|
||||
{
|
||||
struct shader_program_handle
|
||||
{
|
||||
using attribute_support_type = ztu::u32;
|
||||
using uniform_support_type = ztu::u32;
|
||||
|
||||
inline void bind() const;
|
||||
static void unbind();
|
||||
|
||||
template<shader_program_variable::info_type VariableInfo, typename T>
|
||||
void set_uniform(const T& value) const;
|
||||
|
||||
[[nodiscard]] attribute_support_type check_attribute_support(std::span<const shader_program_variable> attributes) const;
|
||||
|
||||
[[nodiscard]] uniform_support_type check_uniform_support(std::span<const shader_program_variable> uniforms) const;
|
||||
|
||||
GLuint program_id{ 0 };
|
||||
};
|
||||
}
|
||||
|
||||
#define INCLUDE_GL_SHADER_PROGRAM_INSTANCE_IMPLEMENTATION
|
||||
#include "opengl/handles/shader_program_handle.ipp"
|
||||
#undef INCLUDE_GL_SHADER_PROGRAM_INSTANCE_IMPLEMENTATION
|
||||
16
include/opengl/handles/surface_properties_handle.hpp
Normal file
16
include/opengl/handles/surface_properties_handle.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "glm/glm.hpp"
|
||||
|
||||
namespace zgl
|
||||
{
|
||||
struct surface_properties_handle
|
||||
{
|
||||
glm::mat3 filters{
|
||||
0.1986f, 0.0000f, 0.0000f,
|
||||
0.5922f, 0.0166f, 0.0000f,
|
||||
0.5974f, 0.2084f, 0.2084f
|
||||
};
|
||||
float shininess{ 100.2237f };
|
||||
};
|
||||
}
|
||||
17
include/opengl/handles/texture_handle.hpp
Normal file
17
include/opengl/handles/texture_handle.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "GL/glew.h"
|
||||
|
||||
namespace zgl {
|
||||
struct texture_handle
|
||||
{
|
||||
inline void bind() const;
|
||||
inline static void unbind();
|
||||
|
||||
GLuint texture_id{ 0 };
|
||||
};
|
||||
}
|
||||
|
||||
#define INCLUDE_TEXTURE_INSTANCE_IMPLEMENTATION
|
||||
#include "opengl/handles/texture_handle.ipp"
|
||||
#undef INCLUDE_TEXTURE_INSTANCE_IMPLEMENTATION
|
||||
16
include/opengl/shader_program_variable.hpp
Normal file
16
include/opengl/shader_program_variable.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "GL/glew.h"
|
||||
|
||||
namespace zgl
|
||||
{
|
||||
struct shader_program_variable
|
||||
{
|
||||
struct info_type
|
||||
{
|
||||
GLenum type;
|
||||
GLint location;
|
||||
} info;
|
||||
const char* name;
|
||||
};
|
||||
}
|
||||
71
include/opengl/type_utils.hpp
Executable file
71
include/opengl/type_utils.hpp
Executable file
@@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
|
||||
#include <utility>
|
||||
#include "GL/glew.h"
|
||||
#include "util/uix.hpp"
|
||||
|
||||
namespace zgl::type_utils
|
||||
{
|
||||
constexpr bool is_valid_type(GLenum type) {
|
||||
switch (type) {
|
||||
case GL_BYTE:
|
||||
case GL_UNSIGNED_BYTE:
|
||||
case GL_SHORT:
|
||||
case GL_UNSIGNED_SHORT:
|
||||
case GL_INT:
|
||||
case GL_UNSIGNED_INT:
|
||||
case GL_FLOAT:
|
||||
case GL_DOUBLE:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
consteval GLenum to_gl_type() {
|
||||
if constexpr (std::same_as<T, ztu::i8>) {
|
||||
return GL_BYTE;
|
||||
} else if constexpr (std::same_as<T, ztu::u8>) {
|
||||
return GL_UNSIGNED_BYTE;
|
||||
} else if constexpr (std::same_as<T, ztu::i16>) {
|
||||
return GL_SHORT;
|
||||
} else if constexpr (std::same_as<T, ztu::u16>) {
|
||||
return GL_UNSIGNED_SHORT;
|
||||
} else if constexpr (std::same_as<T, ztu::i32>) {
|
||||
return GL_INT;
|
||||
} else if constexpr (std::same_as<T, ztu::u32>) {
|
||||
return GL_UNSIGNED_INT;
|
||||
} else if constexpr (std::same_as<T, float>) {
|
||||
return GL_FLOAT;
|
||||
} else if constexpr (std::same_as<T, double>) {
|
||||
return GL_DOUBLE;
|
||||
} else {
|
||||
T::___unknown_type;
|
||||
return GL_INVALID_ENUM;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr GLsizei size_of(GLenum type) {
|
||||
switch (type) {
|
||||
case GL_BYTE:
|
||||
return sizeof(ztu::i8);
|
||||
case GL_UNSIGNED_BYTE:
|
||||
return sizeof(ztu::u8);
|
||||
case GL_SHORT:
|
||||
return sizeof(ztu::i16);
|
||||
case GL_UNSIGNED_SHORT:
|
||||
return sizeof(ztu::u16);
|
||||
case GL_INT:
|
||||
return sizeof(ztu::i32);
|
||||
case GL_UNSIGNED_INT:
|
||||
return sizeof(ztu::u32);
|
||||
case GL_FLOAT:
|
||||
return sizeof(float);
|
||||
case GL_DOUBLE:
|
||||
return sizeof(double);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} // namespace zgl::type_utils
|
||||
27
include/scene/camera_view.hpp
Normal file
27
include/scene/camera_view.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "glm/glm.hpp"
|
||||
#include "glm/gtc/matrix_transform.hpp"
|
||||
#include <numbers>
|
||||
|
||||
struct camera_view
|
||||
{
|
||||
glm::vec3 position;
|
||||
glm::vec3 front;
|
||||
glm::vec3 right;
|
||||
glm::vec3 up;
|
||||
float aspect_ratio;
|
||||
float fov;
|
||||
|
||||
[[nodiscard]] glm::mat4 create_view_matrix() const {
|
||||
return glm::lookAt(position, position + front, up);
|
||||
}
|
||||
|
||||
[[nodiscard]] glm::mat4 create_projection_matrix() const {
|
||||
return glm::perspective(
|
||||
fov,
|
||||
aspect_ratio,
|
||||
0.1f, 1000.0f
|
||||
);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user