Implemented uniform buffers. Optimized data upload to GPU

This commit is contained in:
2026-09-27 05:33:36 +02:00
parent 1703ead546
commit a9bda25031
13 changed files with 382 additions and 195 deletions

View File

@@ -3,6 +3,7 @@
#include "scene.hpp"
#include "camera.hpp"
#include "uniformbuffer.hpp"
namespace Fan
{
@@ -23,6 +24,58 @@ public:
int screen_width, int screen_height,
const Rc<Shader>& debug_shader,
const Rc<Mesh>& default_mesh);
private:
static Rc<UniformBuffer> s_camera_ubo;
static Rc<UniformBuffer> s_light_ubo;
static void update_global_data(const Scene& scene, const Camera& camera,
int screen_width, int screen_height);
struct CameraData {
glm::mat4 view;
glm::mat4 projection;
};
// Maps to Fan::DirectionalLight
struct DirectionalLightData {
glm::vec4 direction;
glm::vec4 ambient;
glm::vec4 diffuse;
glm::vec4 specular;
};
// Maps to Fan::PointLight
struct PointLightData {
glm::vec4 position;
glm::vec4 ambient;
glm::vec4 diffuse;
glm::vec4 specular;
glm::vec4 attenuation; // x = constant, y = linear, z = quadratic
};
// Maps to Fan::SpotLight
struct SpotLightData {
glm::vec4 position;
glm::vec4 direction;
glm::vec4 ambient;
glm::vec4 diffuse;
glm::vec4 specular;
glm::vec4 attenuation; // x = constant, y = linear, z = quadratic
glm::vec4 cut_offs; // x = cut_off (cos), y = outer_cut_off (cos)
};
struct LightEnvironmentData {
DirectionalLightData dir_light;
int active_point_lights;
int active_spot_lights;
int _padding[2]; // Pad the 8 bytes of integers to a 16-byte boundary
PointLightData point_lights[MAX_POINT_LIGHTS];
SpotLightData spot_lights[MAX_SPOT_LIGHTS];
};
};
} // namespace Fan