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/platform/vulkan/vulkan_renderer.h | 77 ++++++++++++----------------------- 1 file changed, 27 insertions(+), 50 deletions(-) (limited to 'src/platform/vulkan/vulkan_renderer.h') diff --git a/src/platform/vulkan/vulkan_renderer.h b/src/platform/vulkan/vulkan_renderer.h index a760cb4..d583f07 100644 --- a/src/platform/vulkan/vulkan_renderer.h +++ b/src/platform/vulkan/vulkan_renderer.h @@ -1,14 +1,12 @@ #pragma once -#include -#include -#include -#include +#include "rendering/renderer_backend.h" // Live-window Vulkan backend: owns the instance, surface, device, swapchain, // render pass, framebuffers and per-frame synchronization, and drives the -// acquire -> record -> submit -> present loop. Pure-C++ header (no vulkan.h / -// glfw leak); the GLFW window is passed as an opaque handle. +// acquire -> record -> submit -> present loop. Implements the shared +// RendererBackend interface (SceneObject / BlackHoleParams live there). Pure-C++ +// header (no vulkan.h / glfw leak); the GLFW window is passed as an opaque handle. namespace Donut { // Must be called BEFORE glfwInit() when the Vulkan API is selected: points @@ -16,55 +14,34 @@ namespace Donut // macOS/Homebrew) and configures the MoltenVK ICD / layer paths. auto vulkan_prepare_glfw() -> void; - // A placeable/editable sphere in the world-builder scene view. - struct SceneObject - { - glm::vec3 position = { 0.0f, 2.0f, 0.0f }; - float radius = 2.0f; - glm::vec3 color = { 0.85f, 0.35f, 0.2f }; - }; - - class VulkanRenderer + class VulkanRenderer : public RendererBackend { public: VulkanRenderer(); - ~VulkanRenderer(); + ~VulkanRenderer() override; // glfwWindow must be a GLFW window created with GLFW_NO_API. - auto init(void* glfwWindow, int width, int height) -> bool; - auto shutdown() -> void; - - // Creates the ImGui context + Vulkan/GLFW backends. Call after init(). - auto init_im_gui() -> bool; - - // Renders + presents one frame: clears to clearColor, then (if init_im_gui - // ran) opens an ImGui frame, invokes buildUI to populate it, and draws it. - auto draw_frame(const glm::vec4& clearColor, const std::function& buildUI = {}) -> void; - - auto on_resize(int width, int height) -> void; - - // Rebuilds the starfield environment cubemap from another equirect .hdr - // at runtime (device-idle teardown + rebuild + descriptor rewrite). - // No-op if path is already the active HDRI. - auto set_hdri(const std::string& path) -> void; - - // Filesystem path of the HDRI currently backing the cubemap. - auto current_hdri() const -> const std::string&; - - // Free-fly (WASD + mouse-look) camera vs the default orbital camera. - // Enabling seeds the fly pose from the current orbital framing (no jump). - auto set_free_fly(bool enabled) -> void; - auto is_free_fly() const -> bool; - - // Switch between the black-hole geodesic view and the world-builder scene - // view (grid/sphere/skybox drawn with real Vulkan geometry pipelines). - auto set_scene_mode(bool enabled) -> void; - auto is_scene_mode() const -> bool; - - // Runtime scene objects (spheres) drawn in scene view; the UI mutates this - // list directly. set_selected_object marks one for a rim highlight (-1 = none). - auto scene_objects() -> std::vector&; - auto set_selected_object(int index) -> void; + auto init(void* glfwWindow, int width, int height) -> bool override; + auto init_ui() -> bool override; + auto shutdown() -> void override; + auto resize(int width, int height) -> void override; + + auto draw_frame(const glm::vec4& clear_color, + const std::function& build_ui) -> void override; + + auto set_scene_mode(bool enabled) -> void override; + auto is_scene_mode() const -> bool override; + auto set_free_fly(bool enabled) -> void override; // seeds the fly pose from the orbital framing + auto is_free_fly() const -> bool override; + auto reset_camera() -> void override; + + auto set_hdri(const std::string& path) -> void override; // rebuilds the cubemap (device-idle) + auto current_hdri() const -> const std::string& override; + auto scene_objects() -> std::vector& override; + auto set_selected_object(int index) -> void override; + auto black_hole_params() -> BlackHoleParams& override; + + auto device_name() const -> const std::string& override; private: struct Impl; -- cgit v1.3