From 5b361d81dbd2af0d0e99b9eb1adebea76ff05db0 Mon Sep 17 00:00:00 2001 From: hachem Date: Thu, 20 Aug 2026 02:27:02 +0200 Subject: [chore]: MASSIVE refactor + more vulkan bs --- src/Engine/Engine.h | 228 ++++++++++++++++++++++++++-------------------------- 1 file changed, 114 insertions(+), 114 deletions(-) (limited to 'src/Engine/Engine.h') diff --git a/src/Engine/Engine.h b/src/Engine/Engine.h index a4cbdc7..c7d02b5 100644 --- a/src/Engine/Engine.h +++ b/src/Engine/Engine.h @@ -8,15 +8,15 @@ #include #include -#include "Core/Camera.h" -#include "Object.h" +#include "core/camera.h" +#include "object.h" -#include "Rendering/Renderer.h" -#include "Rendering/Shader.h" -#include "Rendering/VertexArray.h" -#include "Rendering/Texture.h" -#include "Rendering/UniformBuffer.h" -#include "Rendering/TextureManager.h" +#include "rendering/renderer.h" +#include "rendering/shader.h" +#include "rendering/vertex_array.h" +#include "rendering/texture.h" +#include "rendering/uniform_buffer.h" +#include "rendering/texture_manager.h" #include #include @@ -30,33 +30,33 @@ namespace Donut struct BlackHole { - glm::vec3 m_Position; - double m_Mass; - double m_Radius; - double m_Rs; + glm::vec3 m_position; + double m_mass; + double m_radius; + double m_rs; BlackHole(glm::vec3 pos, float mass) - : m_Position(pos), m_Mass(mass) + : m_position(pos), m_mass(mass) { - m_Rs = 2.0 * G * m_Mass / (c * c); + m_rs = 2.0 * G * m_mass / (c * c); } - bool Intercept(float px, float py, float pz) const + bool intercept(float px, float py, float pz) const { - double dx = double(px) - double(m_Position.x); - double dy = double(py) - double(m_Position.y); - double dz = double(pz) - double(m_Position.z); + double dx = double(px) - double(m_position.x); + double dy = double(py) - double(m_position.y); + double dz = double(pz) - double(m_position.z); double dist2 = dx * dx + dy * dy + dz * dz; - return dist2 < m_Rs * m_Rs; + return dist2 < m_rs * m_rs; } }; struct ObjectData { - glm::vec4 m_PosRadius; - glm::vec4 m_Color; - float m_Mass; - glm::vec3 m_Velocity = glm::vec3(0.0f, 0.0f, 0.0f); + glm::vec4 m_pos_radius; + glm::vec4 m_color; + float m_mass; + glm::vec3 m_velocity = glm::vec3(0.0f, 0.0f, 0.0f); }; class Engine @@ -65,120 +65,120 @@ namespace Donut Engine(); ~Engine() = default; - void DrawFullScreenQuad(); - void DrawBlurPass(); - void DispatchCompute(const Camera& cam); - void UploadCameraUBO(const Camera& cam); - void UploadObjectsUBO(const std::vector& objs); - void UploadDiskUBO(); - void UploadSimulationUBO(); - void RenderScene(); - void UpdatePhysics(float deltaTime); - void UpdateWindowDimensions(); - void SetWindowDimensions(int width, int height); - - int GetWidth() const { return m_Width; } - int GetHeight() const { return m_Height; } - - std::vector& GetObjects() { return m_Objects; } - BlackHole& GetSagA() { return m_SagA; } - Camera& GetCamera() { return m_Camera; } - bool& GetGravity() { return m_Gravity; } - - void UpdatePerformance(float deltaTime); - void SetTargetFPS(int fps) { m_TargetFPS = fps; } - int GetTargetFPS() const { return m_TargetFPS; } - float GetCurrentFPS() const { return m_CurrentFPS; } - void SetComputeHeight(int height) + auto draw_full_screen_quad() -> void; + auto draw_blur_pass() -> void; + auto dispatch_compute(const Camera& cam) -> void; + auto upload_camera_ubo(const Camera& cam) -> void; + auto upload_objects_ubo(const std::vector& objs) -> void; + auto upload_disk_ubo() -> void; + auto upload_simulation_ubo() -> void; + auto render_scene() -> void; + auto update_physics(float delta_time) -> void; + auto update_window_dimensions() -> void; + auto set_window_dimensions(int width, int height) -> void; + + auto get_width() const -> int { return m_width; } + auto get_height() const -> int { return m_height; } + + auto get_objects() -> std::vector& { return m_objects; } + auto get_sag_a() -> BlackHole& { return m_sag_a; } + auto get_camera() -> Camera& { return m_camera; } + auto get_gravity() -> bool& { return m_gravity; } + + auto update_performance(float delta_time) -> void; + auto set_target_fps(int fps) -> void { m_target_fps = fps; } + auto get_target_fps() const -> int { return m_target_fps; } + auto get_current_fps() const -> float { return m_current_fps; } + void set_compute_height(int height) { #ifdef __APPLE__ // Without compute shaders the geodesic pass runs as a tiled - // fragment shader (see DrawGeodesicPass), so very high working + // fragment shader (see draw_geodesic_pass), so very high working // resolutions make each frame take many seconds. Cap it on macOS. if (height > 256) height = 256; #endif - m_ComputeHeight = height; + m_compute_height = height; } - int GetComputeHeight() const { return m_ComputeHeight; } - int GetComputeWidth() const { return (m_Width * m_ComputeHeight) / m_Height; } - void UpdateComputeDimensions(); + auto get_compute_height() const -> int { return m_compute_height; } + auto get_compute_width() const -> int { return (m_width * m_compute_height) / m_height; } + auto update_compute_dimensions() -> void; - int GetMaxStepsMoving() const { return m_MaxStepsMoving; } - int GetMaxStepsStatic() const { return m_MaxStepsStatic; } - float GetEarlyExitDistance() const { return m_EarlyExitDistance; } - void SetMaxStepsMoving(int steps) { m_MaxStepsMoving = steps; } - void SetMaxStepsStatic(int steps) { m_MaxStepsStatic = steps; } - void SetEarlyExitDistance(float distance) { m_EarlyExitDistance = distance; } + auto get_max_steps_moving() const -> int { return m_max_steps_moving; } + auto get_max_steps_static() const -> int { return m_max_steps_static; } + auto get_early_exit_distance() const -> float { return m_early_exit_distance; } + auto set_max_steps_moving(int steps) -> void { m_max_steps_moving = steps; } + auto set_max_steps_static(int steps) -> void { m_max_steps_static = steps; } + auto set_early_exit_distance(float distance) -> void { m_early_exit_distance = distance; } - float GetDiskThickness() const { return m_DiskThickness; } - void SetDiskThickness(float thickness) { m_DiskThickness = thickness; } + auto get_disk_thickness() const -> float { return m_disk_thickness; } + auto set_disk_thickness(float thickness) -> void { m_disk_thickness = thickness; } - float GetDiskDensity() const { return m_DiskDensity; } - void SetDiskDensity(float density) { m_DiskDensity = density; } + auto get_disk_density() const -> float { return m_disk_density; } + auto set_disk_density(float density) -> void { m_disk_density = density; } - float GetRotationSpeed() const { return m_RotationSpeed; } - void SetRotationSpeed(float speed) { m_RotationSpeed = speed; } + auto get_rotation_speed() const -> float { return m_rotation_speed; } + auto set_rotation_speed(float speed) -> void { m_rotation_speed = speed; } - float GetBlurStrength() const { return m_BlurStrength; } - void SetBlurStrength(float strength) { m_BlurStrength = strength; } + auto get_blur_strength() const -> float { return m_blur_strength; } + auto set_blur_strength(float strength) -> void { m_blur_strength = strength; } - float GetGlowIntensity() const { return m_GlowIntensity; } - void SetGlowIntensity(float intensity) { m_GlowIntensity = intensity; } + auto get_glow_intensity() const -> float { return m_glow_intensity; } + auto set_glow_intensity(float intensity) -> void { m_glow_intensity = intensity; } - void LoadObjectsFromScene(const std::vector& objects); - void ExportHighResFrame(const std::string& filename, int width = 4096, int height = 3072); - void PrintObjectInfo() const; + auto load_objects_from_scene(const std::vector& objects) -> void; + auto export_high_res_frame(const std::string& filename, int width = 4096, int height = 3072) -> void; + auto print_object_info() const -> void; - void SetHDRIEnvironment(Ref hdri) { m_HDRIEnvironment = hdri; } - Ref GetHDRIEnvironment() const { return m_HDRIEnvironment; } + auto set_hdri_environment(Ref hdri) -> void { m_hdri_environment = hdri; } + auto get_hdri_environment() const -> Ref { return m_hdri_environment; } private: - Ref CreateComputeProgram(const char* path); + auto create_compute_program(const char* path) -> Ref; std::pair, Ref> QuadVAO(); // Draws the bound geodesic shader over a cw x ch target. On macOS this // is split into scissored tiles (with a flush each) so no single GPU // submission trips the OS watchdog; elsewhere it is one fast draw. - void DrawGeodesicPass(int cw, int ch); + auto draw_geodesic_pass(int cw, int ch) -> void; private: - Ref m_QuadVAO; - Ref m_Texture; - Ref m_HDRIEnvironment; - Ref m_ShaderProgram; - Ref m_ComputeProgram; - Ref m_BlurShader; - Ref m_CameraUBO; - Ref m_DiskUBO; - Ref m_ObjectsUBO; - Ref m_SimulationUBO; - - // FBO used to render the geodesic pass into m_Texture. The geodesic + Ref m_quad_vao; + Ref m_texture; + Ref m_hdri_environment; + Ref m_shader_program; + Ref m_compute_program; + Ref m_blur_shader; + Ref m_camera_ubo; + Ref m_disk_ubo; + Ref m_objects_ubo; + Ref m_simulation_ubo; + + // FBO used to render the geodesic pass into m_texture. The geodesic // shader is a fragment shader (macOS has no compute), so it draws a // fullscreen quad into this framebuffer instead of dispatching compute. - uint32_t m_GeodesicFBO = 0; - - int m_Width; - int m_Height; - float m_Width_f = 100.0f*1e10f; - float m_Height_f = 75.0f*1e10f; - - int m_TargetFPS = 60; - float m_CurrentFPS = 60.0f; - float m_LastFrameTime = 0.0f; - int m_ComputeHeight = 150; - - std::vector m_Objects; - BlackHole m_SagA; - Camera m_Camera; - bool m_Gravity = false; - - int m_MaxStepsMoving = 60000; - int m_MaxStepsStatic = 30000; - float m_EarlyExitDistance = 5.0e11f; - - float m_DiskThickness = 0.1f; - float m_DiskDensity = 0.1f; - float m_RotationSpeed = 1.0f; - float m_BlurStrength = 2.0f; - float m_GlowIntensity = 0.1f; + uint32_t m_geodesic_fbo = 0; + + int m_width; + int m_height; + float m_width_f = 100.0f*1e10f; + float m_height_f = 75.0f*1e10f; + + int m_target_fps = 60; + float m_current_fps = 60.0f; + float m_last_frame_time = 0.0f; + int m_compute_height = 150; + + std::vector m_objects; + BlackHole m_sag_a; + Camera m_camera; + bool m_gravity = false; + + int m_max_steps_moving = 60000; + int m_max_steps_static = 30000; + float m_early_exit_distance = 5.0e11f; + + float m_disk_thickness = 0.1f; + float m_disk_density = 0.1f; + float m_rotation_speed = 1.0f; + float m_blur_strength = 2.0f; + float m_glow_intensity = 0.1f; }; }; -- cgit v1.3