From e3aa33fc9a99d8b817bda42a567a4c347e18ab32 Mon Sep 17 00:00:00 2001 From: hachem Date: Sun, 23 Aug 2026 05:53:33 +0200 Subject: [add]: unified interface --- src/rendering/renderer_backend.h | 73 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/rendering/renderer_backend.h (limited to 'src/rendering/renderer_backend.h') 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 +#include +#include +#include + +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& 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& = 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; + }; +} -- cgit v1.3