aboutsummaryrefslogtreecommitdiff
path: root/src/rendering/renderer_backend.h
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-08-23 05:53:33 +0200
committerhachem <im@hachem.wtf>2026-08-23 05:53:33 +0200
commite3aa33fc9a99d8b817bda42a567a4c347e18ab32 (patch)
treeda0e7ba3ce97a3e545d95d49e366be128c6d2112 /src/rendering/renderer_backend.h
parent43cee69e40be3cb8b0341c3fc94171fe01712b8c (diff)
[add]: unified interface
Diffstat (limited to 'src/rendering/renderer_backend.h')
-rw-r--r--src/rendering/renderer_backend.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/rendering/renderer_backend.h b/src/rendering/renderer_backend.h
new file mode 100644
index 0000000..6a4f1af
--- /dev/null
+++ b/src/rendering/renderer_backend.h
@@ -0,0 +1,73 @@
+#pragma once
+
+#include <glm/glm.hpp>
+#include <functional>
+#include <string>
+#include <vector>
+
+namespace Donut
+{
+ // A placeable/editable sphere in the world-builder scene view. Backend-
+ // agnostic: the app owns the list, every backend renders it the same way.
+ struct SceneObject
+ {
+ glm::vec3 position = { 0.0f, 2.0f, 0.0f };
+ float radius = 2.0f;
+ glm::vec3 color = { 0.85f, 0.35f, 0.2f };
+ };
+
+ // Live-tunable black-hole / accretion-disk parameters. Radii are in
+ // Schwarzschild radii; the inner edge is clamped to the ISCO (3 r_s).
+ struct BlackHoleParams
+ {
+ float disk_inner_rs = 3.0f; // inner edge (x r_s)
+ float disk_outer_rs = 12.0f; // outer edge (x r_s)
+ float temperature = 4800.0f; // Kelvin at the flux peak (disk colour)
+ float brightness = 0.9f; // disk exposure
+ float turbulence = 0.4f; // 0 = smooth physical disk
+ int quality_steps = 15000; // geodesic integration steps
+ float fov_degrees = 60.0f; // camera field of view
+ };
+
+ // The swappable high-level renderer. Each graphics backend (OpenGL, Vulkan,
+ // and later Metal / D3D12) implements this one interface; the Application,
+ // states and UI drive it identically, so the app behaves the same no matter
+ // which backend is active. Backends own their own device/swapchain/pipelines
+ // and translate these high-level calls into their native API.
+ class RendererBackend
+ {
+ public:
+ virtual ~RendererBackend() = default;
+
+ // glfwWindow is an opaque GLFW handle (created NO_API for Vulkan/Metal,
+ // with a GL context for OpenGL). Returns false on failure.
+ virtual auto init(void* glfwWindow, int width, int height) -> bool = 0;
+
+ // Creates the ImGui context + this backend's ImGui platform/render impl.
+ virtual auto init_ui() -> bool = 0;
+ virtual auto shutdown() -> void = 0;
+ virtual auto resize(int width, int height) -> void = 0;
+
+ // Renders one frame: draws the current view (black hole or scene) from
+ // the shared state, then invokes build_ui to draw the ImGui panel on top.
+ virtual auto draw_frame(const glm::vec4& clear_color,
+ const std::function<void()>& build_ui) -> void = 0;
+
+ // --- shared view / camera state ------------------------------------
+ virtual auto set_scene_mode(bool enabled) -> void = 0; // black hole vs scene view
+ virtual auto is_scene_mode() const -> bool = 0;
+ virtual auto set_free_fly(bool enabled) -> void = 0; // free-fly vs orbital camera
+ virtual auto is_free_fly() const -> bool = 0;
+ virtual auto reset_camera() -> void = 0;
+
+ // --- shared content ------------------------------------------------
+ virtual auto set_hdri(const std::string& path) -> void = 0;
+ virtual auto current_hdri() const -> const std::string& = 0;
+ virtual auto scene_objects() -> std::vector<SceneObject>& = 0;
+ virtual auto set_selected_object(int index) -> void = 0;
+ virtual auto black_hole_params() -> BlackHoleParams& = 0;
+
+ // --- introspection for the UI --------------------------------------
+ virtual auto device_name() const -> const std::string& = 0;
+ };
+}