style: 格式化代码及注释
parent
d598b26845
commit
c039b83c57
|
|
@ -3,16 +3,16 @@
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/// @brief Maximum number of lights in scene
|
// Maximum number of lights in scene
|
||||||
constexpr int MAX_LIGHTS = 16;
|
constexpr int MAX_LIGHTS = 16;
|
||||||
|
|
||||||
/// @brief Maximum ray tracing depth
|
// Maximum ray tracing depth
|
||||||
constexpr int MAX_RAY_DEPTH = 8;
|
constexpr int MAX_RAY_DEPTH = 8;
|
||||||
|
|
||||||
/// @brief Default samples per pixel for ray tracing
|
// Default samples per pixel for ray tracing
|
||||||
constexpr int DEFAULT_SPP = 1;
|
constexpr int DEFAULT_SPP = 1;
|
||||||
|
|
||||||
/// @brief G-Buffer attachment indices
|
// G-Buffer attachment indices
|
||||||
constexpr int GBUFFER_POSITION = 0;
|
constexpr int GBUFFER_POSITION = 0;
|
||||||
constexpr int GBUFFER_NORMAL = 1;
|
constexpr int GBUFFER_NORMAL = 1;
|
||||||
constexpr int GBUFFER_ALBEDO = 2;
|
constexpr int GBUFFER_ALBEDO = 2;
|
||||||
|
|
@ -20,11 +20,11 @@ constexpr int GBUFFER_MATERIAL = 3;
|
||||||
constexpr int GBUFFER_MATERIAL_ID = 4;
|
constexpr int GBUFFER_MATERIAL_ID = 4;
|
||||||
constexpr int GBUFFER_COUNT = 5;
|
constexpr int GBUFFER_COUNT = 5;
|
||||||
|
|
||||||
/// @brief Compute shader work group size
|
// Compute shader work group size
|
||||||
constexpr int COMPUTE_GROUP_SIZE_X = 16;
|
constexpr int COMPUTE_GROUP_SIZE_X = 16;
|
||||||
constexpr int COMPUTE_GROUP_SIZE_Y = 16;
|
constexpr int COMPUTE_GROUP_SIZE_Y = 16;
|
||||||
|
|
||||||
/// @brief Mathematical constants
|
// Mathematical constants
|
||||||
constexpr float PI = 3.14159265359f;
|
constexpr float PI = 3.14159265359f;
|
||||||
constexpr float INV_PI = 0.31830988618f;
|
constexpr float INV_PI = 0.31830988618f;
|
||||||
constexpr float EPSILON = 1e-4f;
|
constexpr float EPSILON = 1e-4f;
|
||||||
|
|
|
||||||
|
|
@ -7,51 +7,65 @@
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/// @brief Math utility functions wrapping GLM
|
// Math utility functions wrapping GLM
|
||||||
class MathUtils {
|
class MathUtils {
|
||||||
public:
|
public:
|
||||||
/// @brief Create perspective projection matrix
|
/*
|
||||||
/// @param fov Field of view in radians
|
* @brief Create perspective projection matrix
|
||||||
/// @param aspect Aspect ratio
|
* @param fov Field of view in radians
|
||||||
/// @param near Near plane distance
|
* @param aspect Aspect ratio
|
||||||
/// @param far Far plane distance
|
* @param near Near plane distance
|
||||||
/// @return Projection matrix
|
* @param far Far plane distance
|
||||||
|
* @return Projection matrix
|
||||||
|
*/
|
||||||
static Mat4 perspective(float fov, float aspect, float near, float far);
|
static Mat4 perspective(float fov, float aspect, float near, float far);
|
||||||
|
|
||||||
/// @brief Create look-at view matrix
|
/*
|
||||||
/// @param eye Camera position
|
* @brief Create look-at view matrix
|
||||||
/// @param center Look-at target
|
* @param eye Camera position
|
||||||
/// @param up Up vector
|
* @param center Look-at target
|
||||||
/// @return View matrix
|
* @param up Up vector
|
||||||
static Mat4 look_at(const Vec3& eye, const Vec3& center, const Vec3& up);
|
* @return View matrix
|
||||||
|
*/
|
||||||
|
static Mat4 look_at(const Vec3 &eye, const Vec3 ¢er, const Vec3 &up);
|
||||||
|
|
||||||
/// @brief Normalize a vector
|
/*
|
||||||
/// @param v Input vector
|
* @brief Normalize a vector
|
||||||
/// @return Normalized vector
|
* @param v Input vector
|
||||||
static Vec3 normalize(const Vec3& v);
|
* @return Normalized vector
|
||||||
|
*/
|
||||||
|
static Vec3 normalize(const Vec3 &v);
|
||||||
|
|
||||||
/// @brief Calculate dot product
|
/*
|
||||||
/// @param a First vector
|
* @brief Calculate dot product
|
||||||
/// @param b Second vector
|
* @param a First vector
|
||||||
/// @return Dot product
|
* @param b Second vector
|
||||||
static float dot(const Vec3& a, const Vec3& b);
|
* @return Dot product
|
||||||
|
*/
|
||||||
|
static float dot(const Vec3 &a, const Vec3 &b);
|
||||||
|
|
||||||
/// @brief Calculate cross product
|
/*
|
||||||
/// @param a First vector
|
* @brief Calculate cross product
|
||||||
/// @param b Second vector
|
* @param a First vector
|
||||||
/// @return Cross product
|
* @param b Second vector
|
||||||
static Vec3 cross(const Vec3& a, const Vec3& b);
|
* @return Cross product
|
||||||
|
*/
|
||||||
|
static Vec3 cross(const Vec3 &a, const Vec3 &b);
|
||||||
|
|
||||||
/// @brief Reflect vector around normal
|
/*
|
||||||
/// @param incident Incident vector
|
* @brief Reflect vector around normal
|
||||||
/// @param normal Surface normal
|
* @param incident Incident vector
|
||||||
/// @return Reflected vector
|
* @param normal Surface normal
|
||||||
static Vec3 reflect(const Vec3& incident, const Vec3& normal);
|
* @return Reflected vector
|
||||||
|
*/
|
||||||
|
static Vec3 reflect(const Vec3 &incident, const Vec3 &normal);
|
||||||
|
|
||||||
/// @brief Get pointer to matrix data (for OpenGL)
|
/*
|
||||||
/// @param mat Input matrix
|
* @brief Get pointer to matrix data (for OpenGL)
|
||||||
/// @return Pointer to matrix data
|
* @param mat Input matrix
|
||||||
static const float* value_ptr(const Mat4& mat);
|
* @return Pointer to matrix data
|
||||||
|
*/
|
||||||
|
static const float *value_ptr(const Mat4 &mat);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace are
|
} // namespace are
|
||||||
|
|
|
||||||
|
|
@ -2,36 +2,36 @@
|
||||||
#define ARE_INCLUDE_BASIC_TYPES_H
|
#define ARE_INCLUDE_BASIC_TYPES_H
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/// @brief Basic vector types using GLM
|
// Basic vector types using GLM
|
||||||
using Vec2 = glm::vec2;
|
using Vec2 = glm::vec2;
|
||||||
using Vec3 = glm::vec3;
|
using Vec3 = glm::vec3;
|
||||||
using Vec4 = glm::vec4;
|
using Vec4 = glm::vec4;
|
||||||
|
|
||||||
/// @brief Basic matrix types using GLM
|
// Basic matrix types using GLM
|
||||||
using Mat3 = glm::mat3;
|
using Mat3 = glm::mat3;
|
||||||
using Mat4 = glm::mat4;
|
using Mat4 = glm::mat4;
|
||||||
|
|
||||||
/// @brief Basic integer types
|
// Basic integer types
|
||||||
using uint = uint32_t;
|
using uint = uint32_t;
|
||||||
using uchar = uint8_t;
|
using uchar = uint8_t;
|
||||||
|
|
||||||
/// @brief Handle types for GPU resources
|
// Handle types for GPU resources
|
||||||
using TextureHandle = uint;
|
using TextureHandle = uint;
|
||||||
using BufferHandle = uint;
|
using BufferHandle = uint;
|
||||||
using ShaderHandle = uint;
|
using ShaderHandle = uint;
|
||||||
using FramebufferHandle = uint;
|
using FramebufferHandle = uint;
|
||||||
|
|
||||||
/// @brief Invalid handle constant
|
// Invalid handle constant
|
||||||
constexpr uint INVALID_HANDLE = 0;
|
constexpr uint INVALID_HANDLE = 0;
|
||||||
|
|
||||||
/// @brief Vertex structure for mesh data
|
// Vertex structure for mesh data
|
||||||
struct Vertex {
|
struct Vertex {
|
||||||
Vec3 position_;
|
Vec3 position_;
|
||||||
Vec3 normal_;
|
Vec3 normal_;
|
||||||
|
|
@ -39,7 +39,7 @@ struct Vertex {
|
||||||
Vec3 tangent_;
|
Vec3 tangent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Ray structure for ray tracing
|
// Ray structure for ray tracing
|
||||||
struct Ray {
|
struct Ray {
|
||||||
Vec3 origin_;
|
Vec3 origin_;
|
||||||
Vec3 direction_;
|
Vec3 direction_;
|
||||||
|
|
@ -47,7 +47,7 @@ struct Ray {
|
||||||
float t_max_;
|
float t_max_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Hit information for ray-surface intersection
|
// Hit information for ray-surface intersection
|
||||||
struct HitInfo {
|
struct HitInfo {
|
||||||
bool hit_;
|
bool hit_;
|
||||||
float t_;
|
float t_;
|
||||||
|
|
@ -57,7 +57,7 @@ struct HitInfo {
|
||||||
uint material_id_;
|
uint material_id_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Rendering statistics
|
// Rendering statistics
|
||||||
struct RenderStats {
|
struct RenderStats {
|
||||||
float frame_time_ms_;
|
float frame_time_ms_;
|
||||||
uint triangle_count_;
|
uint triangle_count_;
|
||||||
|
|
|
||||||
|
|
@ -2,53 +2,56 @@
|
||||||
#define ARE_INCLUDE_CORE_BVH_H
|
#define ARE_INCLUDE_CORE_BVH_H
|
||||||
|
|
||||||
#include "basic/types.h"
|
#include "basic/types.h"
|
||||||
#include "scene/mesh.h"
|
|
||||||
#include "resource/buffer.h"
|
#include "resource/buffer.h"
|
||||||
#include <vector>
|
#include "scene/mesh.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/// @brief Axis-aligned bounding box
|
// Axis-aligned bounding box
|
||||||
struct AABB {
|
struct AABB {
|
||||||
Vec3 min_;
|
Vec3 min_;
|
||||||
Vec3 max_;
|
Vec3 max_;
|
||||||
|
|
||||||
/// @brief Construct AABB from min and max points
|
// Construct AABB from min and max points
|
||||||
AABB(const Vec3& min = Vec3(0.0f), const Vec3& max = Vec3(0.0f))
|
AABB(const Vec3 &min = Vec3(0.0f), const Vec3 &max = Vec3(0.0f))
|
||||||
: min_(min), max_(max) {}
|
: min_(min), max_(max) {
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Expand AABB to include point
|
// Expand AABB to include point
|
||||||
void expand(const Vec3& point);
|
void expand(const Vec3 &point);
|
||||||
|
|
||||||
/// @brief Expand AABB to include another AABB
|
// Expand AABB to include another AABB
|
||||||
void expand(const AABB& other);
|
void expand(const AABB &other);
|
||||||
|
|
||||||
/// @brief Get center of AABB
|
// Get center of AABB
|
||||||
Vec3 center() const { return (min_ + max_) * 0.5f; }
|
Vec3 center() const {
|
||||||
|
return (min_ + max_) * 0.5f;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get surface area of AABB
|
// Get surface area of AABB
|
||||||
float surface_area() const;
|
float surface_area() const;
|
||||||
|
|
||||||
/// @brief Check if AABB is valid
|
// Check if AABB is valid
|
||||||
bool is_valid() const;
|
bool is_valid() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Triangle primitive for BVH
|
// Triangle primitive for BVH
|
||||||
struct Triangle {
|
struct Triangle {
|
||||||
Vec3 v0_, v1_, v2_;
|
Vec3 v0_, v1_, v2_;
|
||||||
Vec3 n0_, n1_, n2_;
|
Vec3 n0_, n1_, n2_;
|
||||||
Vec2 uv0_, uv1_, uv2_;
|
Vec2 uv0_, uv1_, uv2_;
|
||||||
uint material_id_;
|
uint material_id_;
|
||||||
|
|
||||||
/// @brief Get bounding box of triangle
|
// Get bounding box of triangle
|
||||||
AABB get_bounds() const;
|
AABB get_bounds() const;
|
||||||
|
|
||||||
/// @brief Get centroid of triangle
|
// Get centroid of triangle
|
||||||
Vec3 get_centroid() const;
|
Vec3 get_centroid() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief BVH node for GPU
|
// BVH node for GPU
|
||||||
struct BVHNode {
|
struct BVHNode {
|
||||||
Vec3 aabb_min_;
|
Vec3 aabb_min_;
|
||||||
uint left_first_; // Left child index or first primitive index
|
uint left_first_; // Left child index or first primitive index
|
||||||
|
|
@ -56,13 +59,13 @@ struct BVHNode {
|
||||||
uint count_; // 0 for interior node, >0 for leaf node
|
uint count_; // 0 for interior node, >0 for leaf node
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief GPU-friendly BVH node layout (std430 aligned)
|
// GPU-friendly BVH node layout (std430 aligned)
|
||||||
struct BVHNodeGpu {
|
struct BVHNodeGpu {
|
||||||
Vec4 aabb_min_left_first_; ///< xyz = aabb min, w = left_first (uint)
|
Vec4 aabb_min_left_first_; ///< xyz = aabb min, w = left_first (uint)
|
||||||
Vec4 aabb_max_count_; ///< xyz = aabb max, w = count (uint, 0 for interior)
|
Vec4 aabb_max_count_; ///< xyz = aabb max, w = count (uint, 0 for interior)
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief GPU-friendly triangle layout (std430 aligned)
|
// GPU-friendly triangle layout (std430 aligned)
|
||||||
struct TriangleGpu {
|
struct TriangleGpu {
|
||||||
Vec4 v0_material_; ///< xyz = v0, w = material_id (uint)
|
Vec4 v0_material_; ///< xyz = v0, w = material_id (uint)
|
||||||
Vec4 v1_; ///< xyz = v1, w = reserved
|
Vec4 v1_; ///< xyz = v1, w = reserved
|
||||||
|
|
@ -74,35 +77,47 @@ struct TriangleGpu {
|
||||||
Vec4 uv2_; ///< xy = uv2, zw = reserved
|
Vec4 uv2_; ///< xy = uv2, zw = reserved
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Bounding Volume Hierarchy for ray tracing acceleration
|
// Bounding Volume Hierarchy for ray tracing acceleration
|
||||||
class BVH {
|
class BVH {
|
||||||
public:
|
public:
|
||||||
/// @brief Constructor
|
// Constructor
|
||||||
BVH();
|
BVH();
|
||||||
|
|
||||||
/// @brief Destructor
|
// Destructor
|
||||||
~BVH();
|
~BVH();
|
||||||
|
|
||||||
/// @brief Build BVH from meshes
|
/*
|
||||||
/// @param meshes Mesh list
|
* @brief Build BVH from meshes
|
||||||
/// @return True if build succeeded
|
* @param meshes Mesh list
|
||||||
bool build(const std::vector<std::shared_ptr<Mesh>>& meshes);
|
* @return True if build succeeded
|
||||||
|
*/
|
||||||
|
bool build(const std::vector<std::shared_ptr<Mesh>> &meshes);
|
||||||
|
|
||||||
/// @brief Upload BVH to GPU
|
/*
|
||||||
/// @param node_buffer Buffer for BVH nodes
|
* @brief Upload BVH to GPU
|
||||||
/// @param triangle_buffer Buffer for triangles
|
* @param node_buffer Buffer for BVH nodes
|
||||||
/// @return True if upload succeeded
|
* @param triangle_buffer Buffer for triangles
|
||||||
bool upload_to_gpu(Buffer& node_buffer, Buffer& triangle_buffer);
|
* @return True if upload succeeded
|
||||||
|
*/
|
||||||
|
bool upload_to_gpu(Buffer &node_buffer, Buffer &triangle_buffer);
|
||||||
|
|
||||||
/// @brief Get total node count
|
/*
|
||||||
/// @return Node count
|
* @brief Get total node count
|
||||||
uint get_node_count() const { return static_cast<uint>(nodes_.size()); }
|
* @return Node count
|
||||||
|
*/
|
||||||
|
uint get_node_count() const {
|
||||||
|
return static_cast<uint>(nodes_.size());
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get total triangle count
|
/*
|
||||||
/// @return Triangle count
|
* @brief Get total triangle count
|
||||||
uint get_triangle_count() const { return static_cast<uint>(triangles_.size()); }
|
* @return Triangle count
|
||||||
|
*/
|
||||||
|
uint get_triangle_count() const {
|
||||||
|
return static_cast<uint>(triangles_.size());
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Clear BVH data
|
// Clear BVH data
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -110,30 +125,38 @@ private:
|
||||||
std::vector<Triangle> triangles_;
|
std::vector<Triangle> triangles_;
|
||||||
std::vector<uint> triangle_indices_;
|
std::vector<uint> triangle_indices_;
|
||||||
|
|
||||||
/// @brief Recursively build BVH
|
/*
|
||||||
/// @param node_idx Current node index
|
* @brief Recursively build BVH
|
||||||
/// @param first_prim First primitive index
|
* @param node_idx Current node index
|
||||||
/// @param prim_count Primitive count
|
* @param first_prim First primitive index
|
||||||
|
* @param prim_count Primitive count
|
||||||
|
*/
|
||||||
void build_recursive_(uint node_idx, uint first_prim, uint prim_count);
|
void build_recursive_(uint node_idx, uint first_prim, uint prim_count);
|
||||||
|
|
||||||
/// @brief Find best split using SAH
|
/*
|
||||||
/// @param first_prim First primitive index
|
* @brief Find best split using SAH
|
||||||
/// @param prim_count Primitive count
|
* @param first_prim First primitive index
|
||||||
/// @param axis Split axis (output)
|
* @param prim_count Primitive count
|
||||||
/// @param split_pos Split position (output)
|
* @param axis Split axis (output)
|
||||||
/// @return Split cost
|
* @param split_pos Split position (output)
|
||||||
float find_best_split_(uint first_prim, uint prim_count, int& axis, float& split_pos);
|
* @return Split cost
|
||||||
|
*/
|
||||||
|
float find_best_split_(uint first_prim, uint prim_count, int &axis, float &split_pos);
|
||||||
|
|
||||||
/// @brief Calculate node bounds
|
/*
|
||||||
/// @param first_prim First primitive index
|
* @brief Calculate node bounds
|
||||||
/// @param prim_count Primitive count
|
* @param first_prim First primitive index
|
||||||
/// @return Bounding box
|
* @param prim_count Primitive count
|
||||||
|
* @return Bounding box
|
||||||
|
*/
|
||||||
AABB calculate_bounds_(uint first_prim, uint prim_count);
|
AABB calculate_bounds_(uint first_prim, uint prim_count);
|
||||||
|
|
||||||
/// @brief Calculate centroid bounds
|
/*
|
||||||
/// @param first_prim First primitive index
|
* @brief Calculate centroid bounds
|
||||||
/// @param prim_count Primitive count
|
* @param first_prim First primitive index
|
||||||
/// @return Centroid bounding box
|
* @param prim_count Primitive count
|
||||||
|
* @return Centroid bounding box
|
||||||
|
*/
|
||||||
AABB calculate_centroid_bounds_(uint first_prim, uint prim_count);
|
AABB calculate_centroid_bounds_(uint first_prim, uint prim_count);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,7 @@
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/**
|
// Mean filter denoiser using compute shader
|
||||||
* @brief Mean filter denoiser using compute shader
|
|
||||||
*/
|
|
||||||
class Denoiser {
|
class Denoiser {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
|
@ -29,7 +27,7 @@ public:
|
||||||
* @param shader Denoise compute shader (managed by ShaderManager)
|
* @param shader Denoise compute shader (managed by ShaderManager)
|
||||||
* @return True on success
|
* @return True on success
|
||||||
*/
|
*/
|
||||||
bool initialize(const std::shared_ptr<Shader>& shader);
|
bool initialize(const std::shared_ptr<Shader> &shader);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Release GPU resources
|
* @brief Release GPU resources
|
||||||
|
|
@ -58,9 +56,7 @@ private:
|
||||||
TextureHandle output_texture_;
|
TextureHandle output_texture_;
|
||||||
bool initialized_;
|
bool initialized_;
|
||||||
|
|
||||||
/**
|
// Create output texture
|
||||||
* @brief Create output texture
|
|
||||||
*/
|
|
||||||
void create_output_texture_();
|
void create_output_texture_();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,54 +1,70 @@
|
||||||
#ifndef ARE_INCLUDE_CORE_GBUFFER_H
|
#ifndef ARE_INCLUDE_CORE_GBUFFER_H
|
||||||
#define ARE_INCLUDE_CORE_GBUFFER_H
|
#define ARE_INCLUDE_CORE_GBUFFER_H
|
||||||
|
|
||||||
#include "basic/types.h"
|
|
||||||
#include "basic/constants.h"
|
#include "basic/constants.h"
|
||||||
#include "scene/scene.h"
|
#include "basic/types.h"
|
||||||
#include "resource/shader.h"
|
#include "resource/shader.h"
|
||||||
|
#include "scene/scene.h"
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/// @brief G-Buffer manager for deferred rendering
|
// G-Buffer manager for deferred rendering
|
||||||
class GBuffer {
|
class GBuffer {
|
||||||
public:
|
public:
|
||||||
/// @brief Constructor
|
/*
|
||||||
/// @param width Buffer width
|
* @brief Constructor
|
||||||
/// @param height Buffer height
|
* @param width Buffer width
|
||||||
|
* @param height Buffer height
|
||||||
|
*/
|
||||||
GBuffer(uint width, uint height);
|
GBuffer(uint width, uint height);
|
||||||
|
|
||||||
/// @brief Destructor
|
// Destructor
|
||||||
~GBuffer();
|
~GBuffer();
|
||||||
|
|
||||||
/// @brief Initialize G-Buffer (create framebuffer and textures)
|
/*
|
||||||
/// @return True if initialization succeeded
|
* @brief Initialize G-Buffer (create framebuffer and textures)
|
||||||
|
* @return True if initialization succeeded
|
||||||
|
*/
|
||||||
bool initialize();
|
bool initialize();
|
||||||
|
|
||||||
/// @brief Release G-Buffer resources
|
// Release G-Buffer resources
|
||||||
void release();
|
void release();
|
||||||
|
|
||||||
/// @brief Render scene to G-Buffer
|
/*
|
||||||
/// @param scene Scene to render
|
* @brief Render scene to G-Buffer
|
||||||
/// @param shader Shader program for G-Buffer pass
|
* @param scene Scene to render
|
||||||
void render(const Scene& scene, const Shader& shader);
|
* @param shader Shader program for G-Buffer pass
|
||||||
|
*/
|
||||||
|
void render(const Scene &scene, const Shader &shader);
|
||||||
|
|
||||||
/// @brief Resize G-Buffer
|
/*
|
||||||
/// @param width New width
|
* @brief Resize G-Buffer
|
||||||
/// @param height New height
|
* @param width New width
|
||||||
|
* @param height New height
|
||||||
|
*/
|
||||||
void resize(uint width, uint height);
|
void resize(uint width, uint height);
|
||||||
|
|
||||||
/// @brief Get texture handle for specific buffer
|
/*
|
||||||
/// @param index Buffer index (GBUFFER_POSITION, GBUFFER_NORMAL, etc.)
|
* @brief Get texture handle for specific buffer
|
||||||
/// @return Texture handle
|
* @param index Buffer index (GBUFFER_POSITION, GBUFFER_NORMAL, etc.)
|
||||||
|
* @return Texture handle
|
||||||
|
*/
|
||||||
TextureHandle get_texture(int index) const;
|
TextureHandle get_texture(int index) const;
|
||||||
|
|
||||||
/// @brief Get framebuffer handle
|
/*
|
||||||
/// @return Framebuffer handle
|
* @brief Get framebuffer handle
|
||||||
FramebufferHandle get_framebuffer() const { return fbo_; }
|
* @return Framebuffer handle
|
||||||
|
*/
|
||||||
|
FramebufferHandle get_framebuffer() const {
|
||||||
|
return fbo_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get buffer dimensions
|
/*
|
||||||
/// @param width Output width
|
* @brief Get buffer dimensions
|
||||||
/// @param height Output height
|
* @param width Output width
|
||||||
void get_dimensions(uint& width, uint& height) const;
|
* @param height Output height
|
||||||
|
*/
|
||||||
|
void get_dimensions(uint &width, uint &height) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint width_;
|
uint width_;
|
||||||
|
|
@ -59,11 +75,13 @@ private:
|
||||||
|
|
||||||
bool initialized_;
|
bool initialized_;
|
||||||
|
|
||||||
/// @brief Create texture for G-Buffer attachment
|
/*
|
||||||
/// @param internal_format OpenGL internal format
|
* @brief Create texture for G-Buffer attachment
|
||||||
/// @param format OpenGL format
|
* @param internal_format OpenGL internal format
|
||||||
/// @param type OpenGL type
|
* @param format OpenGL format
|
||||||
/// @return Texture handle
|
* @param type OpenGL type
|
||||||
|
* @return Texture handle
|
||||||
|
*/
|
||||||
TextureHandle create_texture_(uint internal_format, uint format, uint type);
|
TextureHandle create_texture_(uint internal_format, uint format, uint type);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#define ARE_INCLUDE_CORE_RAYTRACER_H
|
#define ARE_INCLUDE_CORE_RAYTRACER_H
|
||||||
|
|
||||||
#include "basic/types.h"
|
#include "basic/types.h"
|
||||||
#include "core/bvh.h" // 添加
|
#include "core/bvh.h"
|
||||||
#include "core/gbuffer.h"
|
#include "core/gbuffer.h"
|
||||||
#include "resource/buffer.h"
|
#include "resource/buffer.h"
|
||||||
#include "resource/shader.h"
|
#include "resource/shader.h"
|
||||||
|
|
@ -11,62 +11,76 @@
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/// @brief Ray tracing configuration
|
// Ray tracing configuration
|
||||||
struct RayTracerConfig {
|
struct RayTracerConfig {
|
||||||
uint samples_per_pixel_;
|
uint samples_per_pixel_;
|
||||||
uint max_depth_;
|
uint max_depth_;
|
||||||
bool enable_shadows_;
|
bool enable_shadows_;
|
||||||
bool enable_reflections_;
|
bool enable_reflections_;
|
||||||
bool enable_accumulation_;
|
bool enable_accumulation_;
|
||||||
bool use_bvh_; // 添加BVH开关
|
bool use_bvh_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Compute shader based ray tracer
|
// Compute shader based ray tracer
|
||||||
class RayTracer {
|
class RayTracer {
|
||||||
public:
|
public:
|
||||||
/// @brief Constructor
|
/*
|
||||||
/// @param width Output width
|
* @brief Constructor
|
||||||
/// @param height Output height
|
* @param width Output width
|
||||||
/// @param config Ray tracer configuration
|
* @param height Output height
|
||||||
|
* @param config Ray tracer configuration
|
||||||
|
*/
|
||||||
RayTracer(uint width, uint height, const RayTracerConfig &config);
|
RayTracer(uint width, uint height, const RayTracerConfig &config);
|
||||||
|
|
||||||
/// @brief Destructor
|
// Destructor
|
||||||
~RayTracer();
|
~RayTracer();
|
||||||
|
|
||||||
/// @brief Initialize ray tracer
|
/*
|
||||||
/// @return True if initialization succeeded
|
* @brief Initialize ray tracer
|
||||||
|
* @return True if initialization succeeded
|
||||||
|
*/
|
||||||
bool initialize(const std::shared_ptr<Shader> &shader);
|
bool initialize(const std::shared_ptr<Shader> &shader);
|
||||||
|
|
||||||
/// @brief Release resources
|
// Release resources
|
||||||
void release();
|
void release();
|
||||||
|
|
||||||
/// @brief Trace rays using G-Buffer as input
|
/*
|
||||||
/// @param scene Scene data
|
* @brief Trace rays using G-Buffer as input
|
||||||
/// @param gbuffer G-Buffer containing geometry information
|
* @param scene Scene data
|
||||||
/// @param output_texture Output texture for ray traced result
|
* @param gbuffer G-Buffer containing geometry information
|
||||||
|
* @param output_texture Output texture for ray traced result
|
||||||
|
*/
|
||||||
void trace(const Scene &scene, const GBuffer &gbuffer, TextureHandle output_texture);
|
void trace(const Scene &scene, const GBuffer &gbuffer, TextureHandle output_texture);
|
||||||
|
|
||||||
/// @brief Resize output
|
/*
|
||||||
/// @param width New width
|
* @brief Resize output
|
||||||
/// @param height New height
|
* @param width New width
|
||||||
|
* @param height New height
|
||||||
|
*/
|
||||||
void resize(uint width, uint height);
|
void resize(uint width, uint height);
|
||||||
|
|
||||||
/// @brief Reset accumulation buffer
|
// Reset accumulation buffer
|
||||||
void reset_accumulation();
|
void reset_accumulation();
|
||||||
|
|
||||||
/// @brief Get current configuration
|
/*
|
||||||
/// @return Current configuration
|
* @brief Get current configuration
|
||||||
|
* @return Current configuration
|
||||||
|
*/
|
||||||
const RayTracerConfig &get_config() const {
|
const RayTracerConfig &get_config() const {
|
||||||
return config_;
|
return config_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Update configuration
|
/*
|
||||||
/// @param config New configuration
|
* @brief Update configuration
|
||||||
|
* @param config New configuration
|
||||||
|
*/
|
||||||
void set_config(const RayTracerConfig &config);
|
void set_config(const RayTracerConfig &config);
|
||||||
|
|
||||||
/// @brief Rebuild BVH from scene
|
/*
|
||||||
/// @param scene Scene to build BVH from
|
* @brief Rebuild BVH from scene
|
||||||
/// @return True if build succeeded
|
* @param scene Scene to build BVH from
|
||||||
|
* @return True if build succeeded
|
||||||
|
*/
|
||||||
bool rebuild_bvh(const Scene &scene);
|
bool rebuild_bvh(const Scene &scene);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -81,10 +95,10 @@ private:
|
||||||
BufferHandle light_buffer_;
|
BufferHandle light_buffer_;
|
||||||
|
|
||||||
// BVH related
|
// BVH related
|
||||||
std::unique_ptr<BVH> bvh_; // 添加
|
std::unique_ptr<BVH> bvh_;
|
||||||
Buffer bvh_node_buffer_; // 添加
|
Buffer bvh_node_buffer_;
|
||||||
Buffer bvh_triangle_buffer_; // 添加
|
Buffer bvh_triangle_buffer_;
|
||||||
bool bvh_built_; // 添加
|
bool bvh_built_;
|
||||||
|
|
||||||
uint materials_hash_;
|
uint materials_hash_;
|
||||||
uint lights_hash_;
|
uint lights_hash_;
|
||||||
|
|
@ -92,12 +106,16 @@ private:
|
||||||
uint frame_count_;
|
uint frame_count_;
|
||||||
bool initialized_;
|
bool initialized_;
|
||||||
|
|
||||||
/// @brief Upload scene data to GPU buffers
|
/*
|
||||||
/// @param scene Scene to upload
|
* @brief Upload scene data to GPU buffers
|
||||||
|
* @param scene Scene to upload
|
||||||
|
*/
|
||||||
void upload_scene_data_(const Scene &scene);
|
void upload_scene_data_(const Scene &scene);
|
||||||
|
|
||||||
/// @brief Bind G-Buffer textures to compute shader
|
/*
|
||||||
/// @param gbuffer G-Buffer to bind
|
* @brief Bind G-Buffer textures to compute shader
|
||||||
|
* @param gbuffer G-Buffer to bind
|
||||||
|
*/
|
||||||
void bind_gbuffer_(const GBuffer &gbuffer);
|
void bind_gbuffer_(const GBuffer &gbuffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,17 @@
|
||||||
#define ARE_INCLUDE_CORE_RENDERER_H
|
#define ARE_INCLUDE_CORE_RENDERER_H
|
||||||
|
|
||||||
#include "basic/types.h"
|
#include "basic/types.h"
|
||||||
#include "scene/scene.h"
|
#include "core/denoiser.h"
|
||||||
#include "core/gbuffer.h"
|
#include "core/gbuffer.h"
|
||||||
#include "core/raytracer.h"
|
#include "core/raytracer.h"
|
||||||
#include "core/screen_blit.h"
|
#include "core/screen_blit.h"
|
||||||
#include "core/denoiser.h"
|
|
||||||
#include "core/shader_manager.h"
|
#include "core/shader_manager.h"
|
||||||
|
#include "scene/scene.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/// @brief Main renderer configuration
|
// Main renderer configuration
|
||||||
struct RendererConfig {
|
struct RendererConfig {
|
||||||
uint width_;
|
uint width_;
|
||||||
uint height_;
|
uint height_;
|
||||||
|
|
@ -22,43 +22,57 @@ struct RendererConfig {
|
||||||
bool enable_accumulation_;
|
bool enable_accumulation_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Main rendering engine interface
|
// Main rendering engine interface
|
||||||
class Renderer {
|
class Renderer {
|
||||||
public:
|
public:
|
||||||
/// @brief Constructor
|
/*
|
||||||
/// @param config Renderer configuration
|
* @brief Constructor
|
||||||
Renderer(const RendererConfig& config);
|
* @param config Renderer configuration
|
||||||
|
*/
|
||||||
|
Renderer(const RendererConfig &config);
|
||||||
|
|
||||||
/// @brief Destructor
|
// Destructor
|
||||||
~Renderer();
|
~Renderer();
|
||||||
|
|
||||||
/// @brief Initialize renderer (OpenGL context must be current)
|
/*
|
||||||
/// @return True if initialization succeeded
|
* @brief Initialize renderer (OpenGL context must be current)
|
||||||
|
* @return True if initialization succeeded
|
||||||
|
*/
|
||||||
bool initialize();
|
bool initialize();
|
||||||
|
|
||||||
/// @brief Shutdown renderer and release resources
|
// Shutdown renderer and release resources
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
|
||||||
/// @brief Render a frame
|
/*
|
||||||
/// @param scene Scene to render
|
* @brief Render a frame
|
||||||
/// @param output_texture Output texture handle (0 for default framebuffer)
|
* @param scene Scene to render
|
||||||
/// @return Rendering statistics
|
* @param output_texture Output texture handle (0 for default framebuffer)
|
||||||
RenderStats render(const Scene& scene, TextureHandle output_texture = 0);
|
* @return Rendering statistics
|
||||||
|
*/
|
||||||
|
RenderStats render(const Scene &scene, TextureHandle output_texture = 0);
|
||||||
|
|
||||||
/// @brief Resize render targets
|
/*
|
||||||
/// @param width New width
|
* @brief Resize render targets
|
||||||
/// @param height New height
|
* @param width New width
|
||||||
|
* @param height New height
|
||||||
|
*/
|
||||||
void resize(uint width, uint height);
|
void resize(uint width, uint height);
|
||||||
|
|
||||||
/// @brief Get current configuration
|
/*
|
||||||
/// @return Current configuration
|
* @brief Get current configuration
|
||||||
const RendererConfig& get_config() const { return config_; }
|
* @return Current configuration
|
||||||
|
*/
|
||||||
|
const RendererConfig &get_config() const {
|
||||||
|
return config_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Update configuration
|
/*
|
||||||
/// @param config New configuration
|
* @brief Update configuration
|
||||||
void set_config(const RendererConfig& config);
|
* @param config New configuration
|
||||||
|
*/
|
||||||
|
void set_config(const RendererConfig &config);
|
||||||
|
|
||||||
/// @brief Notify scene changed to rebuild acceleration
|
// Notify scene changed to rebuild acceleration
|
||||||
void notify_scene_changed(const Scene &scene);
|
void notify_scene_changed(const Scene &scene);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -7,32 +7,38 @@
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/// @brief Screen blit utility for rendering texture to screen
|
// Screen blit utility for rendering texture to screen
|
||||||
class ScreenBlit {
|
class ScreenBlit {
|
||||||
public:
|
public:
|
||||||
/// @brief Constructor
|
// Constructor
|
||||||
ScreenBlit();
|
ScreenBlit();
|
||||||
|
|
||||||
/// @brief Destructor
|
// Destructor
|
||||||
~ScreenBlit();
|
~ScreenBlit();
|
||||||
|
|
||||||
/// @brief Initialize screen blit
|
/*
|
||||||
/// @return True if initialization succeeded
|
* @brief Initialize screen blit
|
||||||
|
* @return True if initialization succeeded
|
||||||
|
*/
|
||||||
bool initialize(const std::shared_ptr<Shader> &screen_blit_shader);
|
bool initialize(const std::shared_ptr<Shader> &screen_blit_shader);
|
||||||
|
|
||||||
/// @brief Release resources
|
// Release resources
|
||||||
void release();
|
void release();
|
||||||
|
|
||||||
/// @brief Blit texture to screen
|
/*
|
||||||
/// @param texture Texture to blit
|
* @brief Blit texture to screen
|
||||||
/// @param x Screen X position
|
* @param texture Texture to blit
|
||||||
/// @param y Screen Y position
|
* @param x Screen X position
|
||||||
/// @param width Blit width
|
* @param y Screen Y position
|
||||||
/// @param height Blit height
|
* @param width Blit width
|
||||||
|
* @param height Blit height
|
||||||
|
*/
|
||||||
void blit(TextureHandle texture, int x, int y, uint width, uint height);
|
void blit(TextureHandle texture, int x, int y, uint width, uint height);
|
||||||
|
|
||||||
/// @brief Blit texture to full screen
|
/*
|
||||||
/// @param texture Texture to blit
|
* @brief Blit texture to full screen
|
||||||
|
* @param texture Texture to blit
|
||||||
|
*/
|
||||||
void blit_fullscreen(TextureHandle texture);
|
void blit_fullscreen(TextureHandle texture);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -41,7 +47,7 @@ private:
|
||||||
uint vbo_;
|
uint vbo_;
|
||||||
bool initialized_;
|
bool initialized_;
|
||||||
|
|
||||||
/// @brief Create fullscreen quad
|
// Create fullscreen quad
|
||||||
void create_quad_();
|
void create_quad_();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,64 +3,88 @@
|
||||||
|
|
||||||
#include "basic/types.h"
|
#include "basic/types.h"
|
||||||
#include "resource/shader.h"
|
#include "resource/shader.h"
|
||||||
#include <unordered_map>
|
|
||||||
#include <string>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/// @brief Shader manager for loading and caching shaders
|
// Shader manager for loading and caching shaders
|
||||||
class ShaderManager {
|
class ShaderManager {
|
||||||
public:
|
public:
|
||||||
/// @brief Constructor
|
// Constructor
|
||||||
ShaderManager();
|
ShaderManager();
|
||||||
|
|
||||||
/// @brief Destructor
|
// Destructor
|
||||||
~ShaderManager();
|
~ShaderManager();
|
||||||
|
|
||||||
/// @brief Initialize shader manager and load built-in shaders
|
/*
|
||||||
/// @return True if initialization succeeded
|
* @brief Initialize shader manager and load built-in shaders
|
||||||
|
* @return True if initialization succeeded
|
||||||
|
*/
|
||||||
bool initialize();
|
bool initialize();
|
||||||
|
|
||||||
/// @brief Release all shaders
|
// Release all shaders
|
||||||
void release();
|
void release();
|
||||||
|
|
||||||
/// @brief Load shader from files
|
/*
|
||||||
/// @param name Shader name for caching
|
* @brief Load shader from files
|
||||||
/// @param vertex_path Vertex shader file path
|
* @param name Shader name for caching
|
||||||
/// @param fragment_path Fragment shader file path
|
* @param vertex_path Vertex shader file path
|
||||||
/// @return Shader object
|
* @param fragment_path Fragment shader file path
|
||||||
std::shared_ptr<Shader> load_shader(const std::string& name,
|
* @return Shader object
|
||||||
const std::string& vertex_path,
|
*/
|
||||||
const std::string& fragment_path);
|
std::shared_ptr<Shader> load_shader(const std::string &name,
|
||||||
|
const std::string &vertex_path,
|
||||||
|
const std::string &fragment_path);
|
||||||
|
|
||||||
/// @brief Load compute shader from file
|
/*
|
||||||
/// @param name Shader name for caching
|
* @brief Load compute shader from file
|
||||||
/// @param compute_path Compute shader file path
|
* @param name Shader name for caching
|
||||||
/// @return Shader object
|
* @param compute_path Compute shader file path
|
||||||
std::shared_ptr<Shader> load_compute_shader(const std::string& name,
|
* @return Shader object
|
||||||
const std::string& compute_path);
|
*/
|
||||||
|
std::shared_ptr<Shader> load_compute_shader(const std::string &name,
|
||||||
|
const std::string &compute_path);
|
||||||
|
|
||||||
/// @brief Get cached shader by name
|
/*
|
||||||
/// @param name Shader name
|
* @brief Get cached shader by name
|
||||||
/// @return Shader object (invalid if not found)
|
* @param name Shader name
|
||||||
std::shared_ptr<Shader> get_shader(const std::string& name) const;
|
* @return Shader object (invalid if not found)
|
||||||
|
*/
|
||||||
|
std::shared_ptr<Shader> get_shader(const std::string &name) const;
|
||||||
|
|
||||||
/// @brief Get G-Buffer shader
|
/*
|
||||||
/// @return G-Buffer shader
|
* @brief Get G-Buffer shader
|
||||||
const std::shared_ptr<Shader>& get_gbuffer_shader() const { return gbuffer_shader_; }
|
* @return G-Buffer shader
|
||||||
|
*/
|
||||||
|
const std::shared_ptr<Shader> &get_gbuffer_shader() const {
|
||||||
|
return gbuffer_shader_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get ray tracing compute shader
|
/*
|
||||||
/// @return Ray tracing shader
|
* @brief Get ray tracing compute shader
|
||||||
const std::shared_ptr<Shader>& get_raytracing_shader() const { return raytracing_shader_; }
|
* @return Ray tracing shader
|
||||||
|
*/
|
||||||
|
const std::shared_ptr<Shader> &get_raytracing_shader() const {
|
||||||
|
return raytracing_shader_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get mean denoise compute shader
|
/*
|
||||||
/// @return Denoise shader (nullptr if not loaded)
|
* @brief Get mean denoise compute shader
|
||||||
const std::shared_ptr<Shader>& get_denoise_shader() const { return denoise_shader_; }
|
* @return Denoise shader (nullptr if not loaded)
|
||||||
|
*/
|
||||||
|
const std::shared_ptr<Shader> &get_denoise_shader() const {
|
||||||
|
return denoise_shader_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get screen bliting shader
|
/*
|
||||||
/// @return Screen bliting shader (nullptr if not loaded)
|
* @brief Get screen bliting shader
|
||||||
const std::shared_ptr<Shader>& get_screen_blit_shader() const { return screen_blit_shader_; }
|
* @return Screen bliting shader (nullptr if not loaded)
|
||||||
|
*/
|
||||||
|
const std::shared_ptr<Shader> &get_screen_blit_shader() const {
|
||||||
|
return screen_blit_shader_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, std::shared_ptr<Shader>> shader_cache_;
|
std::unordered_map<std::string, std::shared_ptr<Shader>> shader_cache_;
|
||||||
|
|
@ -71,8 +95,10 @@ private:
|
||||||
|
|
||||||
bool initialized_;
|
bool initialized_;
|
||||||
|
|
||||||
/// @brief Load built-in shaders
|
/*
|
||||||
/// @return True if loading succeeded
|
* @brief Load built-in shaders
|
||||||
|
* @return True if loading succeeded
|
||||||
|
*/
|
||||||
bool load_builtin_shaders_();
|
bool load_builtin_shaders_();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,14 @@
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/// @brief Buffer usage hint
|
// Buffer usage hint
|
||||||
enum class BufferUsage {
|
enum class BufferUsage {
|
||||||
STATIC_DRAW,
|
STATIC_DRAW,
|
||||||
DYNAMIC_DRAW,
|
DYNAMIC_DRAW,
|
||||||
STREAM_DRAW
|
STREAM_DRAW
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Buffer type
|
// Buffer type
|
||||||
enum class BufferType {
|
enum class BufferType {
|
||||||
VERTEX_BUFFER,
|
VERTEX_BUFFER,
|
||||||
INDEX_BUFFER,
|
INDEX_BUFFER,
|
||||||
|
|
@ -20,63 +20,85 @@ enum class BufferType {
|
||||||
SHADER_STORAGE_BUFFER
|
SHADER_STORAGE_BUFFER
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief GPU buffer resource
|
// GPU buffer resource
|
||||||
class Buffer {
|
class Buffer {
|
||||||
public:
|
public:
|
||||||
/// @brief Constructor
|
// Constructor
|
||||||
Buffer();
|
Buffer();
|
||||||
|
|
||||||
Buffer(const Buffer&) = delete;
|
Buffer(const Buffer &) = delete;
|
||||||
Buffer& operator=(const Buffer&) = delete;
|
Buffer &operator=(const Buffer &) = delete;
|
||||||
|
|
||||||
Buffer(Buffer&& other) noexcept;
|
Buffer(Buffer &&other) noexcept;
|
||||||
Buffer& operator=(Buffer&& other) noexcept;
|
Buffer &operator=(Buffer &&other) noexcept;
|
||||||
|
|
||||||
/// @brief Destructor
|
// Destructor
|
||||||
~Buffer();
|
~Buffer();
|
||||||
|
|
||||||
/// @brief Create buffer
|
/*
|
||||||
/// @param type Buffer type
|
* @brief Create buffer
|
||||||
/// @param size Buffer size in bytes
|
* @param type Buffer type
|
||||||
/// @param data Initial data (nullptr for empty buffer)
|
* @param size Buffer size in bytes
|
||||||
/// @param usage Usage hint
|
* @param data Initial data (nullptr for empty buffer)
|
||||||
/// @return True if creation succeeded
|
* @param usage Usage hint
|
||||||
bool create(BufferType type, size_t size, const void* data, BufferUsage usage);
|
* @return True if creation succeeded
|
||||||
|
*/
|
||||||
|
bool create(BufferType type, size_t size, const void *data, BufferUsage usage);
|
||||||
|
|
||||||
/// @brief Update buffer data
|
/*
|
||||||
/// @param offset Offset in bytes
|
* @brief Update buffer data
|
||||||
/// @param size Size in bytes
|
* @param offset Offset in bytes
|
||||||
/// @param data Data to upload
|
* @param size Size in bytes
|
||||||
void update(size_t offset, size_t size, const void* data);
|
* @param data Data to upload
|
||||||
|
*/
|
||||||
|
void update(size_t offset, size_t size, const void *data);
|
||||||
|
|
||||||
/// @brief Bind buffer
|
// Bind buffer
|
||||||
void bind() const;
|
void bind() const;
|
||||||
|
|
||||||
/// @brief Bind buffer to binding point (for UBO/SSBO)
|
/*
|
||||||
/// @param binding_point Binding point index
|
* @brief Bind buffer to binding point (for UBO/SSBO)
|
||||||
|
* @param binding_point Binding point index
|
||||||
|
*/
|
||||||
void bind_base(uint binding_point) const;
|
void bind_base(uint binding_point) const;
|
||||||
|
|
||||||
/// @brief Unbind buffer
|
// Unbind buffer
|
||||||
void unbind() const;
|
void unbind() const;
|
||||||
|
|
||||||
/// @brief Release buffer resources
|
// Release buffer resources
|
||||||
void release();
|
void release();
|
||||||
|
|
||||||
/// @brief Get buffer handle
|
/*
|
||||||
/// @return Buffer handle
|
* @brief Get buffer handle
|
||||||
BufferHandle get_handle() const { return handle_; }
|
* @return Buffer handle
|
||||||
|
*/
|
||||||
|
BufferHandle get_handle() const {
|
||||||
|
return handle_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get buffer size
|
/*
|
||||||
/// @return Size in bytes
|
* @brief Get buffer size
|
||||||
size_t get_size() const { return size_; }
|
* @return Size in bytes
|
||||||
|
*/
|
||||||
|
size_t get_size() const {
|
||||||
|
return size_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get buffer type
|
/*
|
||||||
/// @return Buffer type
|
* @brief Get buffer type
|
||||||
BufferType get_type() const { return type_; }
|
* @return Buffer type
|
||||||
|
*/
|
||||||
|
BufferType get_type() const {
|
||||||
|
return type_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Check if buffer is valid
|
/*
|
||||||
/// @return True if valid
|
* @brief Check if buffer is valid
|
||||||
bool is_valid() const { return handle_ != INVALID_HANDLE; }
|
* @return True if valid
|
||||||
|
*/
|
||||||
|
bool is_valid() const {
|
||||||
|
return handle_ != INVALID_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BufferHandle handle_;
|
BufferHandle handle_;
|
||||||
|
|
|
||||||
|
|
@ -7,127 +7,169 @@
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/// @brief Shader program resource
|
// Shader program resource
|
||||||
class Shader {
|
class Shader {
|
||||||
public:
|
public:
|
||||||
/// @brief Constructor
|
// Constructor
|
||||||
Shader();
|
Shader();
|
||||||
|
|
||||||
Shader(const Shader&) = delete;
|
Shader(const Shader &) = delete;
|
||||||
Shader& operator=(const Shader&) = delete;
|
Shader &operator=(const Shader &) = delete;
|
||||||
|
|
||||||
Shader(Shader&& other) noexcept;
|
Shader(Shader &&other) noexcept;
|
||||||
Shader& operator=(Shader&& other) noexcept;
|
Shader &operator=(Shader &&other) noexcept;
|
||||||
|
|
||||||
/// @brief Destructor
|
// Destructor
|
||||||
~Shader();
|
~Shader();
|
||||||
|
|
||||||
/// @brief Load and compile shader from files
|
/*
|
||||||
/// @param vertex_path Vertex shader path
|
* @brief Load and compile shader from files
|
||||||
/// @param fragment_path Fragment shader path
|
* @param vertex_path Vertex shader path
|
||||||
/// @return True if compilation succeeded
|
* @param fragment_path Fragment shader path
|
||||||
bool load(const std::string& vertex_path, const std::string& fragment_path);
|
* @return True if compilation succeeded
|
||||||
|
*/
|
||||||
|
bool load(const std::string &vertex_path, const std::string &fragment_path);
|
||||||
|
|
||||||
/// @brief Load and compile compute shader
|
/*
|
||||||
/// @param compute_path Compute shader path
|
* @brief Load and compile compute shader
|
||||||
/// @return True if compilation succeeded
|
* @param compute_path Compute shader path
|
||||||
bool load_compute(const std::string& compute_path);
|
* @return True if compilation succeeded
|
||||||
|
*/
|
||||||
|
bool load_compute(const std::string &compute_path);
|
||||||
|
|
||||||
/// @brief Compile shader from source strings
|
/*
|
||||||
/// @param vertex_source Vertex shader source
|
* @brief Compile shader from source strings
|
||||||
/// @param fragment_source Fragment shader source
|
* @param vertex_source Vertex shader source
|
||||||
/// @return True if compilation succeeded
|
* @param fragment_source Fragment shader source
|
||||||
bool compile(const std::string& vertex_source, const std::string& fragment_source);
|
* @return True if compilation succeeded
|
||||||
|
*/
|
||||||
|
bool compile(const std::string &vertex_source, const std::string &fragment_source);
|
||||||
|
|
||||||
/// @brief Compile compute shader from source
|
/*
|
||||||
/// @param compute_source Compute shader source
|
* @brief Compile compute shader from source
|
||||||
/// @return True if compilation succeeded
|
* @param compute_source Compute shader source
|
||||||
bool compile_compute(const std::string& compute_source);
|
* @return True if compilation succeeded
|
||||||
|
*/
|
||||||
|
bool compile_compute(const std::string &compute_source);
|
||||||
|
|
||||||
/// @brief Use/activate shader program
|
// Use/activate shader program
|
||||||
void use() const; // 改为const
|
void use() const; // 改为const
|
||||||
|
|
||||||
/// @brief Release shader resources
|
// Release shader resources
|
||||||
void release();
|
void release();
|
||||||
|
|
||||||
/// @brief Set uniform boolean
|
/*
|
||||||
/// @param name Uniform name
|
* @brief Set uniform boolean
|
||||||
/// @param value Value
|
* @param name Uniform name
|
||||||
void set_bool(const std::string& name, bool value) const; // 新增,const
|
* @param value Value
|
||||||
|
*/
|
||||||
|
void set_bool(const std::string &name, bool value) const; // 新增,const
|
||||||
|
|
||||||
/// @brief Set uniform integer
|
/*
|
||||||
/// @param name Uniform name
|
* @brief Set uniform integer
|
||||||
/// @param value Value
|
* @param name Uniform name
|
||||||
void set_int(const std::string& name, int value) const; // 改为const
|
* @param value Value
|
||||||
|
*/
|
||||||
|
void set_int(const std::string &name, int value) const; // 改为const
|
||||||
|
|
||||||
/// @brief Set uniform unsigned integer
|
/*
|
||||||
/// @param name Uniform name
|
* @brief Set uniform unsigned integer
|
||||||
/// @param value Value
|
* @param name Uniform name
|
||||||
void set_uint(const std::string& name, uint value) const; // 改为const
|
* @param value Value
|
||||||
|
*/
|
||||||
|
void set_uint(const std::string &name, uint value) const; // 改为const
|
||||||
|
|
||||||
/// @brief Set uniform float
|
/*
|
||||||
/// @param name Uniform name
|
* @brief Set uniform float
|
||||||
/// @param value Value
|
* @param name Uniform name
|
||||||
void set_float(const std::string& name, float value) const; // 改为const
|
* @param value Value
|
||||||
|
*/
|
||||||
|
void set_float(const std::string &name, float value) const; // 改为const
|
||||||
|
|
||||||
/// @brief Set uniform vec2
|
/*
|
||||||
/// @param name Uniform name
|
* @brief Set uniform vec2
|
||||||
/// @param value Value
|
* @param name Uniform name
|
||||||
void set_vec2(const std::string& name, const Vec2& value) const; // 改为const
|
* @param value Value
|
||||||
|
*/
|
||||||
|
void set_vec2(const std::string &name, const Vec2 &value) const; // 改为const
|
||||||
|
|
||||||
/// @brief Set uniform vec3
|
/*
|
||||||
/// @param name Uniform name
|
* @brief Set uniform vec3
|
||||||
/// @param value Value
|
* @param name Uniform name
|
||||||
void set_vec3(const std::string& name, const Vec3& value) const; // 改为const
|
* @param value Value
|
||||||
|
*/
|
||||||
|
void set_vec3(const std::string &name, const Vec3 &value) const; // 改为const
|
||||||
|
|
||||||
/// @brief Set uniform vec4
|
/*
|
||||||
/// @param name Uniform name
|
* @brief Set uniform vec4
|
||||||
/// @param value Value
|
* @param name Uniform name
|
||||||
void set_vec4(const std::string& name, const Vec4& value) const; // 改为const
|
* @param value Value
|
||||||
|
*/
|
||||||
|
void set_vec4(const std::string &name, const Vec4 &value) const; // 改为const
|
||||||
|
|
||||||
/// @brief Set uniform mat3
|
/*
|
||||||
/// @param name Uniform name
|
* @brief Set uniform mat3
|
||||||
/// @param value Value
|
* @param name Uniform name
|
||||||
void set_mat3(const std::string& name, const Mat3& value) const; // 改为const
|
* @param value Value
|
||||||
|
*/
|
||||||
|
void set_mat3(const std::string &name, const Mat3 &value) const; // 改为const
|
||||||
|
|
||||||
/// @brief Set uniform mat4
|
/*
|
||||||
/// @param name Uniform name
|
* @brief Set uniform mat4
|
||||||
/// @param value Value
|
* @param name Uniform name
|
||||||
void set_mat4(const std::string& name, const Mat4& value) const; // 改为const
|
* @param value Value
|
||||||
|
*/
|
||||||
|
void set_mat4(const std::string &name, const Mat4 &value) const; // 改为const
|
||||||
|
|
||||||
/// @brief Get shader program handle
|
/*
|
||||||
/// @return Shader handle
|
* @brief Get shader program handle
|
||||||
ShaderHandle get_handle() const { return handle_; }
|
* @return Shader handle
|
||||||
|
*/
|
||||||
|
ShaderHandle get_handle() const {
|
||||||
|
return handle_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Check if shader is valid
|
/*
|
||||||
/// @return True if valid
|
* @brief Check if shader is valid
|
||||||
bool is_valid() const { return handle_ != INVALID_HANDLE; }
|
* @return True if valid
|
||||||
|
*/
|
||||||
|
bool is_valid() const {
|
||||||
|
return handle_ != INVALID_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ShaderHandle handle_;
|
ShaderHandle handle_;
|
||||||
mutable std::unordered_map<std::string, int> uniform_cache_; // 改为mutable
|
mutable std::unordered_map<std::string, int> uniform_cache_; // 改为mutable
|
||||||
|
|
||||||
/// @brief Get uniform location (with caching)
|
/*
|
||||||
/// @param name Uniform name
|
* @brief Get uniform location (with caching)
|
||||||
/// @return Uniform location
|
* @param name Uniform name
|
||||||
int get_uniform_location_(const std::string& name) const; // 改为const
|
* @return Uniform location
|
||||||
|
*/
|
||||||
|
int get_uniform_location_(const std::string &name) const; // 改为const
|
||||||
|
|
||||||
/// @brief Compile shader stage
|
/*
|
||||||
/// @param source Shader source code
|
* @brief Compile shader stage
|
||||||
/// @param type Shader type (GL_VERTEX_SHADER, etc.)
|
* @param source Shader source code
|
||||||
/// @return Shader object handle (0 on failure)
|
* @param type Shader type (GL_VERTEX_SHADER, etc.)
|
||||||
uint compile_shader_(const std::string& source, uint type);
|
* @return Shader object handle (0 on failure)
|
||||||
|
*/
|
||||||
|
uint compile_shader_(const std::string &source, uint type);
|
||||||
|
|
||||||
/// @brief Link shader program
|
/*
|
||||||
/// @param shaders Array of shader object handles
|
* @brief Link shader program
|
||||||
/// @param count Number of shaders
|
* @param shaders Array of shader object handles
|
||||||
/// @return True if linking succeeded
|
* @param count Number of shaders
|
||||||
bool link_program_(const uint* shaders, uint count);
|
* @return True if linking succeeded
|
||||||
|
*/
|
||||||
|
bool link_program_(const uint *shaders, uint count);
|
||||||
|
|
||||||
/// @brief Read file content
|
/*
|
||||||
/// @param path File path
|
* @brief Read file content
|
||||||
/// @return File content
|
* @param path File path
|
||||||
std::string read_file_(const std::string& path);
|
* @return File content
|
||||||
|
*/
|
||||||
|
std::string read_file_(const std::string &path);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace are
|
} // namespace are
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/// @brief Texture format enumeration
|
// Texture format enumeration
|
||||||
enum class TextureFormat {
|
enum class TextureFormat {
|
||||||
R8,
|
R8,
|
||||||
RG8,
|
RG8,
|
||||||
|
|
@ -23,7 +23,7 @@ enum class TextureFormat {
|
||||||
DEPTH24_STENCIL8
|
DEPTH24_STENCIL8
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Texture filter mode
|
// Texture filter mode
|
||||||
enum class TextureFilter {
|
enum class TextureFilter {
|
||||||
NEAREST,
|
NEAREST,
|
||||||
LINEAR,
|
LINEAR,
|
||||||
|
|
@ -33,7 +33,7 @@ enum class TextureFilter {
|
||||||
LINEAR_MIPMAP_LINEAR
|
LINEAR_MIPMAP_LINEAR
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Texture wrap mode
|
// Texture wrap mode
|
||||||
enum class TextureWrap {
|
enum class TextureWrap {
|
||||||
REPEAT,
|
REPEAT,
|
||||||
MIRRORED_REPEAT,
|
MIRRORED_REPEAT,
|
||||||
|
|
@ -41,84 +41,116 @@ enum class TextureWrap {
|
||||||
CLAMP_TO_BORDER
|
CLAMP_TO_BORDER
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Texture resource
|
// Texture resource
|
||||||
class Texture {
|
class Texture {
|
||||||
public:
|
public:
|
||||||
/// @brief Constructor
|
// Constructor
|
||||||
Texture();
|
Texture();
|
||||||
|
|
||||||
Texture(const Texture&) = delete;
|
Texture(const Texture &) = delete;
|
||||||
Texture& operator=(const Texture&) = delete;
|
Texture &operator=(const Texture &) = delete;
|
||||||
|
|
||||||
Texture(Texture&& other) noexcept;
|
Texture(Texture &&other) noexcept;
|
||||||
Texture& operator=(Texture&& other) noexcept;
|
Texture &operator=(Texture &&other) noexcept;
|
||||||
|
|
||||||
/// @brief Destructor
|
// Destructor
|
||||||
~Texture();
|
~Texture();
|
||||||
|
|
||||||
/// @brief Load texture from file
|
/*
|
||||||
/// @param path File path
|
* @brief Load texture from file
|
||||||
/// @param generate_mipmaps Generate mipmaps
|
* @param path File path
|
||||||
/// @return True if loading succeeded
|
* @param generate_mipmaps Generate mipmaps
|
||||||
bool load_from_file(const std::string& path, bool generate_mipmaps = true);
|
* @return True if loading succeeded
|
||||||
|
*/
|
||||||
|
bool load_from_file(const std::string &path, bool generate_mipmaps = true);
|
||||||
|
|
||||||
/// @brief Create empty texture
|
/*
|
||||||
/// @param width Texture width
|
* @brief Create empty texture
|
||||||
/// @param height Texture height
|
* @param width Texture width
|
||||||
/// @param format Texture format
|
* @param height Texture height
|
||||||
/// @return True if creation succeeded
|
* @param format Texture format
|
||||||
|
* @return True if creation succeeded
|
||||||
|
*/
|
||||||
bool create(uint width, uint height, TextureFormat format);
|
bool create(uint width, uint height, TextureFormat format);
|
||||||
|
|
||||||
/// @brief Upload data to texture
|
/*
|
||||||
/// @param data Pixel data
|
* @brief Upload data to texture
|
||||||
/// @param width Data width
|
* @param data Pixel data
|
||||||
/// @param height Data height
|
* @param width Data width
|
||||||
/// @param format Data format
|
* @param height Data height
|
||||||
/// @return True if upload succeeded
|
* @param format Data format
|
||||||
bool upload(const void* data, uint width, uint height, TextureFormat format);
|
* @return True if upload succeeded
|
||||||
|
*/
|
||||||
|
bool upload(const void *data, uint width, uint height, TextureFormat format);
|
||||||
|
|
||||||
/// @brief Set texture filter mode
|
/*
|
||||||
/// @param min_filter Minification filter
|
* @brief Set texture filter mode
|
||||||
/// @param mag_filter Magnification filter
|
* @param min_filter Minification filter
|
||||||
|
* @param mag_filter Magnification filter
|
||||||
|
*/
|
||||||
void set_filter(TextureFilter min_filter, TextureFilter mag_filter);
|
void set_filter(TextureFilter min_filter, TextureFilter mag_filter);
|
||||||
|
|
||||||
/// @brief Set texture wrap mode
|
/*
|
||||||
/// @param wrap_s Wrap mode for S coordinate
|
* @brief Set texture wrap mode
|
||||||
/// @param wrap_t Wrap mode for T coordinate
|
* @param wrap_s Wrap mode for S coordinate
|
||||||
|
* @param wrap_t Wrap mode for T coordinate
|
||||||
|
*/
|
||||||
void set_wrap(TextureWrap wrap_s, TextureWrap wrap_t);
|
void set_wrap(TextureWrap wrap_s, TextureWrap wrap_t);
|
||||||
|
|
||||||
/// @brief Generate mipmaps
|
// Generate mipmaps
|
||||||
void generate_mipmaps();
|
void generate_mipmaps();
|
||||||
|
|
||||||
/// @brief Bind texture to texture unit
|
/*
|
||||||
/// @param unit Texture unit
|
* @brief Bind texture to texture unit
|
||||||
|
* @param unit Texture unit
|
||||||
|
*/
|
||||||
void bind(uint unit) const;
|
void bind(uint unit) const;
|
||||||
|
|
||||||
/// @brief Unbind texture
|
// Unbind texture
|
||||||
void unbind() const;
|
void unbind() const;
|
||||||
|
|
||||||
/// @brief Release texture resources
|
// Release texture resources
|
||||||
void release();
|
void release();
|
||||||
|
|
||||||
/// @brief Get texture handle
|
/*
|
||||||
/// @return Texture handle
|
* @brief Get texture handle
|
||||||
TextureHandle get_handle() const { return handle_; }
|
* @return Texture handle
|
||||||
|
*/
|
||||||
|
TextureHandle get_handle() const {
|
||||||
|
return handle_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get texture width
|
/*
|
||||||
/// @return Width
|
* @brief Get texture width
|
||||||
uint get_width() const { return width_; }
|
* @return Width
|
||||||
|
*/
|
||||||
|
uint get_width() const {
|
||||||
|
return width_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get texture height
|
/*
|
||||||
/// @return Height
|
* @brief Get texture height
|
||||||
uint get_height() const { return height_; }
|
* @return Height
|
||||||
|
*/
|
||||||
|
uint get_height() const {
|
||||||
|
return height_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get texture format
|
/*
|
||||||
/// @return Format
|
* @brief Get texture format
|
||||||
TextureFormat get_format() const { return format_; }
|
* @return Format
|
||||||
|
*/
|
||||||
|
TextureFormat get_format() const {
|
||||||
|
return format_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Check if texture is valid
|
/*
|
||||||
/// @return True if valid
|
* @brief Check if texture is valid
|
||||||
bool is_valid() const { return handle_ != INVALID_HANDLE; }
|
* @return True if valid
|
||||||
|
*/
|
||||||
|
bool is_valid() const {
|
||||||
|
return handle_ != INVALID_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TextureHandle handle_;
|
TextureHandle handle_;
|
||||||
|
|
|
||||||
|
|
@ -5,75 +5,101 @@
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/// @brief Camera projection type
|
// Camera projection type
|
||||||
enum class ProjectionType {
|
enum class ProjectionType {
|
||||||
PERSPECTIVE,
|
PERSPECTIVE,
|
||||||
ORTHOGRAPHIC
|
ORTHOGRAPHIC
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Camera for rendering
|
// Camera for rendering
|
||||||
class Camera {
|
class Camera {
|
||||||
public:
|
public:
|
||||||
/// @brief Constructor
|
// Constructor
|
||||||
Camera();
|
Camera();
|
||||||
|
|
||||||
/// @brief Destructor
|
// Destructor
|
||||||
~Camera();
|
~Camera();
|
||||||
|
|
||||||
/// @brief Set perspective projection
|
/*
|
||||||
/// @param fov Field of view in degrees
|
* @brief Set perspective projection
|
||||||
/// @param aspect Aspect ratio
|
* @param fov Field of view in degrees
|
||||||
/// @param near Near plane
|
* @param aspect Aspect ratio
|
||||||
/// @param far Far plane
|
* @param near Near plane
|
||||||
|
* @param far Far plane
|
||||||
|
*/
|
||||||
void set_perspective(float fov, float aspect, float near, float far);
|
void set_perspective(float fov, float aspect, float near, float far);
|
||||||
|
|
||||||
/// @brief Set orthographic projection
|
/*
|
||||||
/// @param left Left plane
|
* @brief Set orthographic projection
|
||||||
/// @param right Right plane
|
* @param left Left plane
|
||||||
/// @param bottom Bottom plane
|
* @param right Right plane
|
||||||
/// @param top Top plane
|
* @param bottom Bottom plane
|
||||||
/// @param near Near plane
|
* @param top Top plane
|
||||||
/// @param far Far plane
|
* @param near Near plane
|
||||||
|
* @param far Far plane
|
||||||
|
*/
|
||||||
void set_orthographic(float left, float right, float bottom, float top, float near, float far);
|
void set_orthographic(float left, float right, float bottom, float top, float near, float far);
|
||||||
|
|
||||||
/// @brief Set camera position
|
/*
|
||||||
/// @param position Position
|
* @brief Set camera position
|
||||||
void set_position(const Vec3& position);
|
* @param position Position
|
||||||
|
*/
|
||||||
|
void set_position(const Vec3 &position);
|
||||||
|
|
||||||
/// @brief Set camera target
|
/*
|
||||||
/// @param target Target position
|
* @brief Set camera target
|
||||||
void set_target(const Vec3& target);
|
* @param target Target position
|
||||||
|
*/
|
||||||
|
void set_target(const Vec3 &target);
|
||||||
|
|
||||||
/// @brief Set camera up vector
|
/*
|
||||||
/// @param up Up vector
|
* @brief Set camera up vector
|
||||||
void set_up(const Vec3& up);
|
* @param up Up vector
|
||||||
|
*/
|
||||||
|
void set_up(const Vec3 &up);
|
||||||
|
|
||||||
/// @brief Get view matrix
|
/*
|
||||||
/// @return View matrix
|
* @brief Get view matrix
|
||||||
|
* @return View matrix
|
||||||
|
*/
|
||||||
Mat4 get_view_matrix() const;
|
Mat4 get_view_matrix() const;
|
||||||
|
|
||||||
/// @brief Get projection matrix
|
/*
|
||||||
/// @return Projection matrix
|
* @brief Get projection matrix
|
||||||
|
* @return Projection matrix
|
||||||
|
*/
|
||||||
Mat4 get_projection_matrix() const;
|
Mat4 get_projection_matrix() const;
|
||||||
|
|
||||||
/// @brief Get view-projection matrix
|
/*
|
||||||
/// @return View-projection matrix
|
* @brief Get view-projection matrix
|
||||||
|
* @return View-projection matrix
|
||||||
|
*/
|
||||||
Mat4 get_view_projection_matrix() const;
|
Mat4 get_view_projection_matrix() const;
|
||||||
|
|
||||||
/// @brief Get camera position
|
/*
|
||||||
/// @return Position
|
* @brief Get camera position
|
||||||
const Vec3& get_position() const { return position_; }
|
* @return Position
|
||||||
|
*/
|
||||||
|
const Vec3 &get_position() const {
|
||||||
|
return position_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get camera forward direction
|
/*
|
||||||
/// @return Forward direction
|
* @brief Get camera forward direction
|
||||||
|
* @return Forward direction
|
||||||
|
*/
|
||||||
Vec3 get_forward() const;
|
Vec3 get_forward() const;
|
||||||
|
|
||||||
/// @brief Get camera right direction
|
/*
|
||||||
/// @return Right direction
|
* @brief Get camera right direction
|
||||||
|
* @return Right direction
|
||||||
|
*/
|
||||||
Vec3 get_right() const;
|
Vec3 get_right() const;
|
||||||
|
|
||||||
/// @brief Get camera up direction
|
/*
|
||||||
/// @return Up direction
|
* @brief Get camera up direction
|
||||||
|
* @return Up direction
|
||||||
|
*/
|
||||||
Vec3 get_up() const;
|
Vec3 get_up() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -5,95 +5,125 @@
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/// @brief Light type enumeration
|
// Light type enumeration
|
||||||
enum class LightType {
|
enum class LightType {
|
||||||
DIRECTIONAL = 0,
|
DIRECTIONAL = 0,
|
||||||
POINT = 1,
|
POINT = 1,
|
||||||
SPOT = 2
|
SPOT = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Light source
|
// Light source
|
||||||
class Light {
|
class Light {
|
||||||
public:
|
public:
|
||||||
/// @brief Constructor
|
// Constructor
|
||||||
Light();
|
Light();
|
||||||
|
|
||||||
/// @brief Destructor
|
// Destructor
|
||||||
~Light();
|
~Light();
|
||||||
|
|
||||||
/// @brief Set light type
|
/*
|
||||||
/// @param type Light type
|
* @brief Set light type
|
||||||
|
* @param type Light type
|
||||||
|
*/
|
||||||
void set_type(LightType type);
|
void set_type(LightType type);
|
||||||
|
|
||||||
/// @brief Set light position (for point and spot lights)
|
/*
|
||||||
/// @param position Light position
|
* @brief Set light position (for point and spot lights)
|
||||||
|
* @param position Light position
|
||||||
|
*/
|
||||||
void set_position(const Vec3 &position);
|
void set_position(const Vec3 &position);
|
||||||
|
|
||||||
/// @brief Set light direction (for directional and spot lights)
|
/*
|
||||||
/// @param direction Light direction
|
* @brief Set light direction (for directional and spot lights)
|
||||||
|
* @param direction Light direction
|
||||||
|
*/
|
||||||
void set_direction(const Vec3 &direction);
|
void set_direction(const Vec3 &direction);
|
||||||
|
|
||||||
/// @brief Set light color
|
/*
|
||||||
/// @param color Light color
|
* @brief Set light color
|
||||||
|
* @param color Light color
|
||||||
|
*/
|
||||||
void set_color(const Vec3 &color);
|
void set_color(const Vec3 &color);
|
||||||
|
|
||||||
/// @brief Set light intensity
|
/*
|
||||||
/// @param intensity Light intensity
|
* @brief Set light intensity
|
||||||
|
* @param intensity Light intensity
|
||||||
|
*/
|
||||||
void set_intensity(float intensity);
|
void set_intensity(float intensity);
|
||||||
|
|
||||||
/// @brief Set light range (for point and spot lights)
|
/*
|
||||||
/// @param range Light range
|
* @brief Set light range (for point and spot lights)
|
||||||
|
* @param range Light range
|
||||||
|
*/
|
||||||
void set_range(float range);
|
void set_range(float range);
|
||||||
|
|
||||||
/// @brief Set spot light angles
|
/*
|
||||||
/// @param inner_angle Inner cone angle in degrees
|
* @brief Set spot light angles
|
||||||
/// @param outer_angle Outer cone angle in degrees
|
* @param inner_angle Inner cone angle in degrees
|
||||||
|
* @param outer_angle Outer cone angle in degrees
|
||||||
|
*/
|
||||||
void set_spot_angles(float inner_angle, float outer_angle);
|
void set_spot_angles(float inner_angle, float outer_angle);
|
||||||
|
|
||||||
/// @brief Get light type
|
/*
|
||||||
/// @return Light type
|
* @brief Get light type
|
||||||
|
* @return Light type
|
||||||
|
*/
|
||||||
LightType get_type() const {
|
LightType get_type() const {
|
||||||
return type_;
|
return type_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Get light position
|
/*
|
||||||
/// @return Light position
|
* @brief Get light position
|
||||||
|
* @return Light position
|
||||||
|
*/
|
||||||
const Vec3 &get_position() const {
|
const Vec3 &get_position() const {
|
||||||
return position_;
|
return position_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Get light direction
|
/*
|
||||||
/// @return Light direction
|
* @brief Get light direction
|
||||||
|
* @return Light direction
|
||||||
|
*/
|
||||||
const Vec3 &get_direction() const {
|
const Vec3 &get_direction() const {
|
||||||
return direction_;
|
return direction_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Get light color
|
/*
|
||||||
/// @return Light color
|
* @brief Get light color
|
||||||
|
* @return Light color
|
||||||
|
*/
|
||||||
const Vec3 &get_color() const {
|
const Vec3 &get_color() const {
|
||||||
return color_;
|
return color_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Get light intensity
|
/*
|
||||||
/// @return Light intensity
|
* @brief Get light intensity
|
||||||
|
* @return Light intensity
|
||||||
|
*/
|
||||||
float get_intensity() const {
|
float get_intensity() const {
|
||||||
return intensity_;
|
return intensity_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Get light range
|
/*
|
||||||
/// @return Light range
|
* @brief Get light range
|
||||||
|
* @return Light range
|
||||||
|
*/
|
||||||
float get_range() const {
|
float get_range() const {
|
||||||
return range_;
|
return range_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Get spot light inner angle
|
/*
|
||||||
/// @return Inner angle in radians
|
* @brief Get spot light inner angle
|
||||||
|
* @return Inner angle in radians
|
||||||
|
*/
|
||||||
float get_inner_angle() const {
|
float get_inner_angle() const {
|
||||||
return inner_angle_;
|
return inner_angle_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Get spot light outer angle
|
/*
|
||||||
/// @return Outer angle in radians
|
* @brief Get spot light outer angle
|
||||||
|
* @return Outer angle in radians
|
||||||
|
*/
|
||||||
float get_outer_angle() const {
|
float get_outer_angle() const {
|
||||||
return outer_angle_;
|
return outer_angle_;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/// @brief Material type enumeration
|
// Material type enumeration
|
||||||
enum class MaterialType {
|
enum class MaterialType {
|
||||||
DIFFUSE = 0,
|
DIFFUSE = 0,
|
||||||
METAL = 1,
|
METAL = 1,
|
||||||
|
|
@ -15,78 +15,126 @@ enum class MaterialType {
|
||||||
EMISSIVE = 3
|
EMISSIVE = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Material properties
|
// Material properties
|
||||||
class Material {
|
class Material {
|
||||||
public:
|
public:
|
||||||
/// @brief Constructor
|
// Constructor
|
||||||
Material();
|
Material();
|
||||||
|
|
||||||
/// @brief Destructor
|
// Destructor
|
||||||
~Material();
|
~Material();
|
||||||
|
|
||||||
/// @brief Set albedo color
|
/*
|
||||||
/// @param albedo Albedo color
|
* @brief Set albedo color
|
||||||
void set_albedo(const Vec3& albedo);
|
* @param albedo Albedo color
|
||||||
|
*/
|
||||||
|
void set_albedo(const Vec3 &albedo);
|
||||||
|
|
||||||
/// @brief Set emission color
|
/*
|
||||||
/// @param emission Emission color
|
* @brief Set emission color
|
||||||
void set_emission(const Vec3& emission);
|
* @param emission Emission color
|
||||||
|
*/
|
||||||
|
void set_emission(const Vec3 &emission);
|
||||||
|
|
||||||
/// @brief Set metallic value
|
/*
|
||||||
/// @param metallic Metallic (0-1)
|
* @brief Set metallic value
|
||||||
|
* @param metallic Metallic (0-1)
|
||||||
|
*/
|
||||||
void set_metallic(float metallic);
|
void set_metallic(float metallic);
|
||||||
|
|
||||||
/// @brief Set roughness value
|
/*
|
||||||
/// @param roughness Roughness (0-1)
|
* @brief Set roughness value
|
||||||
|
* @param roughness Roughness (0-1)
|
||||||
|
*/
|
||||||
void set_roughness(float roughness);
|
void set_roughness(float roughness);
|
||||||
|
|
||||||
/// @brief Set index of refraction
|
/*
|
||||||
/// @param ior Index of refraction
|
* @brief Set index of refraction
|
||||||
|
* @param ior Index of refraction
|
||||||
|
*/
|
||||||
void set_ior(float ior);
|
void set_ior(float ior);
|
||||||
|
|
||||||
/// @brief Set material type
|
/*
|
||||||
/// @param type Material type
|
* @brief Set material type
|
||||||
|
* @param type Material type
|
||||||
|
*/
|
||||||
void set_type(MaterialType type);
|
void set_type(MaterialType type);
|
||||||
|
|
||||||
/// @brief Set albedo texture
|
/*
|
||||||
/// @param texture Albedo texture
|
* @brief Set albedo texture
|
||||||
|
* @param texture Albedo texture
|
||||||
|
*/
|
||||||
void set_albedo_texture(std::shared_ptr<Texture> texture);
|
void set_albedo_texture(std::shared_ptr<Texture> texture);
|
||||||
|
|
||||||
/// @brief Set normal map
|
/*
|
||||||
/// @param texture Normal map texture
|
* @brief Set normal map
|
||||||
|
* @param texture Normal map texture
|
||||||
|
*/
|
||||||
void set_normal_texture(std::shared_ptr<Texture> texture);
|
void set_normal_texture(std::shared_ptr<Texture> texture);
|
||||||
|
|
||||||
/// @brief Get albedo color
|
/*
|
||||||
/// @return Albedo color
|
* @brief Get albedo color
|
||||||
const Vec3& get_albedo() const { return albedo_; }
|
* @return Albedo color
|
||||||
|
*/
|
||||||
|
const Vec3 &get_albedo() const {
|
||||||
|
return albedo_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get emission color
|
/*
|
||||||
/// @return Emission color
|
* @brief Get emission color
|
||||||
const Vec3& get_emission() const { return emission_; }
|
* @return Emission color
|
||||||
|
*/
|
||||||
|
const Vec3 &get_emission() const {
|
||||||
|
return emission_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get metallic value
|
/*
|
||||||
/// @return Metallic
|
* @brief Get metallic value
|
||||||
float get_metallic() const { return metallic_; }
|
* @return Metallic
|
||||||
|
*/
|
||||||
|
float get_metallic() const {
|
||||||
|
return metallic_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get roughness value
|
/*
|
||||||
/// @return Roughness
|
* @brief Get roughness value
|
||||||
float get_roughness() const { return roughness_; }
|
* @return Roughness
|
||||||
|
*/
|
||||||
|
float get_roughness() const {
|
||||||
|
return roughness_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get index of refraction
|
/*
|
||||||
/// @return IOR
|
* @brief Get index of refraction
|
||||||
float get_ior() const { return ior_; }
|
* @return IOR
|
||||||
|
*/
|
||||||
|
float get_ior() const {
|
||||||
|
return ior_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get material type
|
/*
|
||||||
/// @return Material type
|
* @brief Get material type
|
||||||
MaterialType get_type() const { return type_; }
|
* @return Material type
|
||||||
|
*/
|
||||||
|
MaterialType get_type() const {
|
||||||
|
return type_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get albedo texture
|
/*
|
||||||
/// @return Albedo texture (nullptr if none)
|
* @brief Get albedo texture
|
||||||
std::shared_ptr<Texture> get_albedo_texture() const { return albedo_texture_; }
|
* @return Albedo texture (nullptr if none)
|
||||||
|
*/
|
||||||
|
std::shared_ptr<Texture> get_albedo_texture() const {
|
||||||
|
return albedo_texture_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get normal texture
|
/*
|
||||||
/// @return Normal texture (nullptr if none)
|
* @brief Get normal texture
|
||||||
std::shared_ptr<Texture> get_normal_texture() const { return normal_texture_; }
|
* @return Normal texture (nullptr if none)
|
||||||
|
*/
|
||||||
|
std::shared_ptr<Texture> get_normal_texture() const {
|
||||||
|
return normal_texture_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vec3 albedo_;
|
Vec3 albedo_;
|
||||||
|
|
|
||||||
|
|
@ -6,61 +6,95 @@
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/// @brief Mesh data container
|
// Mesh data container
|
||||||
class Mesh {
|
class Mesh {
|
||||||
public:
|
public:
|
||||||
/// @brief Constructor
|
// Constructor
|
||||||
Mesh();
|
Mesh();
|
||||||
|
|
||||||
/// @brief Destructor
|
// Destructor
|
||||||
~Mesh();
|
~Mesh();
|
||||||
|
|
||||||
/// @brief Set vertex data
|
/*
|
||||||
/// @param vertices Vertex array
|
* @brief Set vertex data
|
||||||
void set_vertices(const std::vector<Vertex>& vertices);
|
* @param vertices Vertex array
|
||||||
|
*/
|
||||||
|
void set_vertices(const std::vector<Vertex> &vertices);
|
||||||
|
|
||||||
/// @brief Set index data
|
/*
|
||||||
/// @param indices Index array
|
* @brief Set index data
|
||||||
void set_indices(const std::vector<uint>& indices);
|
* @param indices Index array
|
||||||
|
*/
|
||||||
|
void set_indices(const std::vector<uint> &indices);
|
||||||
|
|
||||||
/// @brief Set material index
|
/*
|
||||||
/// @param material_id Material index
|
* @brief Set material index
|
||||||
|
* @param material_id Material index
|
||||||
|
*/
|
||||||
void set_material(uint material_id);
|
void set_material(uint material_id);
|
||||||
|
|
||||||
/// @brief Set transform matrix
|
/*
|
||||||
/// @param transform Transform matrix
|
* @brief Set transform matrix
|
||||||
void set_transform(const Mat4& transform);
|
* @param transform Transform matrix
|
||||||
|
*/
|
||||||
|
void set_transform(const Mat4 &transform);
|
||||||
|
|
||||||
/// @brief Get vertices
|
/*
|
||||||
/// @return Vertex array
|
* @brief Get vertices
|
||||||
const std::vector<Vertex>& get_vertices() const { return vertices_; }
|
* @return Vertex array
|
||||||
|
*/
|
||||||
|
const std::vector<Vertex> &get_vertices() const {
|
||||||
|
return vertices_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get indices
|
/*
|
||||||
/// @return Index array
|
* @brief Get indices
|
||||||
const std::vector<uint>& get_indices() const { return indices_; }
|
* @return Index array
|
||||||
|
*/
|
||||||
|
const std::vector<uint> &get_indices() const {
|
||||||
|
return indices_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get material index
|
/*
|
||||||
/// @return Material index
|
* @brief Get material index
|
||||||
uint get_material() const { return material_id_; }
|
* @return Material index
|
||||||
|
*/
|
||||||
|
uint get_material() const {
|
||||||
|
return material_id_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get transform matrix
|
/*
|
||||||
/// @return Transform matrix
|
* @brief Get transform matrix
|
||||||
const Mat4& get_transform() const { return transform_; }
|
* @return Transform matrix
|
||||||
|
*/
|
||||||
|
const Mat4 &get_transform() const {
|
||||||
|
return transform_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Upload mesh data to GPU
|
/*
|
||||||
/// @return True if upload succeeded
|
* @brief Upload mesh data to GPU
|
||||||
|
* @return True if upload succeeded
|
||||||
|
*/
|
||||||
bool upload_to_gpu();
|
bool upload_to_gpu();
|
||||||
|
|
||||||
/// @brief Release GPU resources
|
// Release GPU resources
|
||||||
void release_gpu_resources();
|
void release_gpu_resources();
|
||||||
|
|
||||||
/// @brief Get VAO handle
|
/*
|
||||||
/// @return VAO handle
|
* @brief Get VAO handle
|
||||||
uint get_vao() const { return vao_; }
|
* @return VAO handle
|
||||||
|
*/
|
||||||
|
uint get_vao() const {
|
||||||
|
return vao_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Check if mesh is uploaded to GPU
|
/*
|
||||||
/// @return True if uploaded
|
* @brief Check if mesh is uploaded to GPU
|
||||||
bool is_uploaded() const { return uploaded_; }
|
* @return True if uploaded
|
||||||
|
*/
|
||||||
|
bool is_uploaded() const {
|
||||||
|
return uploaded_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Vertex> vertices_;
|
std::vector<Vertex> vertices_;
|
||||||
|
|
|
||||||
|
|
@ -3,63 +3,89 @@
|
||||||
|
|
||||||
#include "basic/types.h"
|
#include "basic/types.h"
|
||||||
#include "scene/camera.h"
|
#include "scene/camera.h"
|
||||||
#include "scene/mesh.h"
|
|
||||||
#include "scene/material.h"
|
|
||||||
#include "scene/light.h"
|
#include "scene/light.h"
|
||||||
#include <vector>
|
#include "scene/material.h"
|
||||||
|
#include "scene/mesh.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/// @brief Scene container holding all scene objects
|
// Scene container holding all scene objects
|
||||||
class Scene {
|
class Scene {
|
||||||
public:
|
public:
|
||||||
/// @brief Constructor
|
// Constructor
|
||||||
Scene();
|
Scene();
|
||||||
|
|
||||||
/// @brief Destructor
|
// Destructor
|
||||||
~Scene();
|
~Scene();
|
||||||
|
|
||||||
/// @brief Add mesh to scene
|
/*
|
||||||
/// @param mesh Mesh to add
|
* @brief Add mesh to scene
|
||||||
/// @return Mesh index
|
* @param mesh Mesh to add
|
||||||
|
* @return Mesh index
|
||||||
|
*/
|
||||||
uint add_mesh(std::shared_ptr<Mesh> mesh);
|
uint add_mesh(std::shared_ptr<Mesh> mesh);
|
||||||
|
|
||||||
/// @brief Add material to scene
|
/*
|
||||||
/// @param material Material to add
|
* @brief Add material to scene
|
||||||
/// @return Material index
|
* @param material Material to add
|
||||||
|
* @return Material index
|
||||||
|
*/
|
||||||
uint add_material(std::shared_ptr<Material> material);
|
uint add_material(std::shared_ptr<Material> material);
|
||||||
|
|
||||||
/// @brief Add light to scene
|
/*
|
||||||
/// @param light Light to add
|
* @brief Add light to scene
|
||||||
/// @return Light index
|
* @param light Light to add
|
||||||
|
* @return Light index
|
||||||
|
*/
|
||||||
uint add_light(std::shared_ptr<Light> light);
|
uint add_light(std::shared_ptr<Light> light);
|
||||||
|
|
||||||
/// @brief Set active camera
|
/*
|
||||||
/// @param camera Camera to set
|
* @brief Set active camera
|
||||||
|
* @param camera Camera to set
|
||||||
|
*/
|
||||||
void set_camera(std::shared_ptr<Camera> camera);
|
void set_camera(std::shared_ptr<Camera> camera);
|
||||||
|
|
||||||
/// @brief Get active camera
|
/*
|
||||||
/// @return Active camera
|
* @brief Get active camera
|
||||||
const Camera& get_camera() const { return *camera_; }
|
* @return Active camera
|
||||||
|
*/
|
||||||
|
const Camera &get_camera() const {
|
||||||
|
return *camera_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get all meshes
|
/*
|
||||||
/// @return Mesh list
|
* @brief Get all meshes
|
||||||
const std::vector<std::shared_ptr<Mesh>>& get_meshes() const { return meshes_; }
|
* @return Mesh list
|
||||||
|
*/
|
||||||
|
const std::vector<std::shared_ptr<Mesh>> &get_meshes() const {
|
||||||
|
return meshes_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get all materials
|
/*
|
||||||
/// @return Material list
|
* @brief Get all materials
|
||||||
const std::vector<std::shared_ptr<Material>>& get_materials() const { return materials_; }
|
* @return Material list
|
||||||
|
*/
|
||||||
|
const std::vector<std::shared_ptr<Material>> &get_materials() const {
|
||||||
|
return materials_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Get all lights
|
/*
|
||||||
/// @return Light list
|
* @brief Get all lights
|
||||||
const std::vector<std::shared_ptr<Light>>& get_lights() const { return lights_; }
|
* @return Light list
|
||||||
|
*/
|
||||||
|
const std::vector<std::shared_ptr<Light>> &get_lights() const {
|
||||||
|
return lights_;
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Clear all scene objects
|
// Clear all scene objects
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
/// @brief Update scene (animations, transforms, etc.)
|
/*
|
||||||
/// @param delta_time Time since last update
|
* @brief Update scene (animations, transforms, etc.)
|
||||||
|
* @param delta_time Time since last update
|
||||||
|
*/
|
||||||
void update(float delta_time);
|
void update(float delta_time);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -6,63 +6,85 @@
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/// @brief Configuration manager for loading engine settings
|
/*
|
||||||
/// @note This module should be implemented by the user
|
* @brief Configuration manager for loading engine settings
|
||||||
|
* @note This module should be implemented by the user
|
||||||
|
*/
|
||||||
class Config {
|
class Config {
|
||||||
public:
|
public:
|
||||||
/// @brief Load configuration from file
|
/*
|
||||||
/// @param path Configuration file path
|
* @brief Load configuration from file
|
||||||
/// @return True if loading succeeded
|
* @param path Configuration file path
|
||||||
static bool load(const std::string& path);
|
* @return True if loading succeeded
|
||||||
|
*/
|
||||||
|
static bool load(const std::string &path);
|
||||||
|
|
||||||
/// @brief Save configuration to file
|
/*
|
||||||
/// @param path Configuration file path
|
* @brief Save configuration to file
|
||||||
/// @return True if saving succeeded
|
* @param path Configuration file path
|
||||||
static bool save(const std::string& path);
|
* @return True if saving succeeded
|
||||||
|
*/
|
||||||
|
static bool save(const std::string &path);
|
||||||
|
|
||||||
/// @brief Get string value
|
/*
|
||||||
/// @param key Configuration key
|
* @brief Get string value
|
||||||
/// @param default_value Default value if key not found
|
* @param key Configuration key
|
||||||
/// @return Configuration value
|
* @param default_value Default value if key not found
|
||||||
static std::string get_string(const std::string& key, const std::string& default_value = "");
|
* @return Configuration value
|
||||||
|
*/
|
||||||
|
static std::string get_string(const std::string &key, const std::string &default_value = "");
|
||||||
|
|
||||||
/// @brief Get integer value
|
/*
|
||||||
/// @param key Configuration key
|
* @brief Get integer value
|
||||||
/// @param default_value Default value if key not found
|
* @param key Configuration key
|
||||||
/// @return Configuration value
|
* @param default_value Default value if key not found
|
||||||
static int get_int(const std::string& key, int default_value = 0);
|
* @return Configuration value
|
||||||
|
*/
|
||||||
|
static int get_int(const std::string &key, int default_value = 0);
|
||||||
|
|
||||||
/// @brief Get float value
|
/*
|
||||||
/// @param key Configuration key
|
* @brief Get float value
|
||||||
/// @param default_value Default value if key not found
|
* @param key Configuration key
|
||||||
/// @return Configuration value
|
* @param default_value Default value if key not found
|
||||||
static float get_float(const std::string& key, float default_value = 0.0f);
|
* @return Configuration value
|
||||||
|
*/
|
||||||
|
static float get_float(const std::string &key, float default_value = 0.0f);
|
||||||
|
|
||||||
/// @brief Get boolean value
|
/*
|
||||||
/// @param key Configuration key
|
* @brief Get boolean value
|
||||||
/// @param default_value Default value if key not found
|
* @param key Configuration key
|
||||||
/// @return Configuration value
|
* @param default_value Default value if key not found
|
||||||
static bool get_bool(const std::string& key, bool default_value = false);
|
* @return Configuration value
|
||||||
|
*/
|
||||||
|
static bool get_bool(const std::string &key, bool default_value = false);
|
||||||
|
|
||||||
/// @brief Set string value
|
/*
|
||||||
/// @param key Configuration key
|
* @brief Set string value
|
||||||
/// @param value Configuration value
|
* @param key Configuration key
|
||||||
static void set_string(const std::string& key, const std::string& value);
|
* @param value Configuration value
|
||||||
|
*/
|
||||||
|
static void set_string(const std::string &key, const std::string &value);
|
||||||
|
|
||||||
/// @brief Set integer value
|
/*
|
||||||
/// @param key Configuration key
|
* @brief Set integer value
|
||||||
/// @param value Configuration value
|
* @param key Configuration key
|
||||||
static void set_int(const std::string& key, int value);
|
* @param value Configuration value
|
||||||
|
*/
|
||||||
|
static void set_int(const std::string &key, int value);
|
||||||
|
|
||||||
/// @brief Set float value
|
/*
|
||||||
/// @param key Configuration key
|
* @brief Set float value
|
||||||
/// @param value Configuration value
|
* @param key Configuration key
|
||||||
static void set_float(const std::string& key, float value);
|
* @param value Configuration value
|
||||||
|
*/
|
||||||
|
static void set_float(const std::string &key, float value);
|
||||||
|
|
||||||
/// @brief Set boolean value
|
/*
|
||||||
/// @param key Configuration key
|
* @brief Set boolean value
|
||||||
/// @param value Configuration value
|
* @param key Configuration key
|
||||||
static void set_bool(const std::string& key, bool value);
|
* @param value Configuration value
|
||||||
|
*/
|
||||||
|
static void set_bool(const std::string &key, bool value);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace are
|
} // namespace are
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,12 @@
|
||||||
#ifndef ARE_INCLUDE_CORE_LOGGER_H
|
#ifndef ARE_INCLUDE_CORE_LOGGER_H
|
||||||
#define ARE_INCLUDE_CORE_LOGGER_H
|
#define ARE_INCLUDE_CORE_LOGGER_H
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace are {
|
namespace are {
|
||||||
|
|
||||||
/**
|
// Logging severity levels
|
||||||
* @enum LogLevel
|
|
||||||
* @brief Logging severity levels
|
|
||||||
*/
|
|
||||||
enum class LogLevel {
|
enum class LogLevel {
|
||||||
ARE_LOG_TRACE,
|
ARE_LOG_TRACE,
|
||||||
ARE_LOG_DEBUG,
|
ARE_LOG_DEBUG,
|
||||||
|
|
@ -19,13 +16,7 @@ enum class LogLevel {
|
||||||
ARE_LOG_CRITICAL
|
ARE_LOG_CRITICAL
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// Thread-safe logging system
|
||||||
* @class Logger
|
|
||||||
* @brief Thread-safe logging system
|
|
||||||
*
|
|
||||||
* This class provides a simple interface for logging messages with different
|
|
||||||
* severity levels. It wraps spdlog for actual logging functionality.
|
|
||||||
*/
|
|
||||||
class Logger {
|
class Logger {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
|
@ -47,8 +38,8 @@ public:
|
||||||
* @param line Line number
|
* @param line Line number
|
||||||
* @param message Log message
|
* @param message Log message
|
||||||
*/
|
*/
|
||||||
static void log(LogLevel level, const char* file, const char* func,
|
static void log(LogLevel level, const char *file, const char *func,
|
||||||
int line, const std::string& message);
|
int line, const std::string &message);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set minimum log level
|
* @brief Set minimum log level
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue