initial commit
This commit is contained in:
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
|
||||
Reference in New Issue
Block a user