1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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;
};
}
|