MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
GlfwWindow.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <GLFW/glfw3.h>
7
8namespace MayaFlux::Core {
9/**
10 * @class GlfwWindow
11 * @brief Platform-agnostic window wrapper
12 *
13 * Wraps a GLFW window and provides a unified interface
14 * for window management, event handling, and state tracking.
15 */
16class MAYAFLUX_API GlfwWindow : public Window {
17public:
18 /**
19 * @brief Creates a window with the given configuration
20 * @param create_info Window creation parameters
21 * @param surface_info Graphics surface parameters
22 * @param api Requested graphics API
23 * @param pre_init_config Optional pre-initialization configuration
24 */
25 GlfwWindow(const WindowCreateInfo& create_info,
26 const GraphicsSurfaceInfo& surface_info, GlobalGraphicsConfig::GraphicsApi api, GlfwPreInitConfig pre_init_config = {});
27
28 ~GlfwWindow() override;
29
30 GlfwWindow(const GlfwWindow&) = delete;
31 GlfwWindow& operator=(const GlfwWindow&) = delete;
32 GlfwWindow(GlfwWindow&&) noexcept;
33 GlfwWindow& operator=(GlfwWindow&&) noexcept;
34
35 void show() override;
36
37 void hide() override;
38
39 void destroy() override;
40
41 [[nodiscard]] bool should_close() const override;
42
43 [[nodiscard]] inline const WindowState& get_state() const override
44 {
45 return m_state;
46 }
47
48 [[nodiscard]] inline const WindowCreateInfo& get_create_info() const override
49 {
50 return m_create_info;
51 }
52
53 inline void set_input_config(const InputConfig& config) override
54 {
55 m_input_config = config;
56 }
57
58 [[nodiscard]] inline const InputConfig& get_input_config() const override
59 {
60 return m_input_config;
61 }
62
63 void set_event_callback(WindowEventCallback callback) override;
64
65 [[nodiscard]] void* get_native_handle() const override;
66
67 [[nodiscard]] void* get_native_display() const override;
68
69 [[nodiscard]] inline GLFWwindow* get_glfw_handle() const { return m_window; }
70
71 void set_title(const std::string& title) override;
72
73 void set_size(uint32_t width, uint32_t height) override;
74
75 void set_position(uint32_t x, uint32_t y) override;
76
77 Vruta::EventSource& get_event_source() override { return m_event_source; }
78 [[nodiscard]] const Vruta::EventSource& get_event_source() const override { return m_event_source; }
79
80 /**
81 * @brief Check if window is registered with graphics subsystem
82 */
83 [[nodiscard]] bool is_graphics_registered() const override { return m_graphics_registered.load(); }
84
85 /**
86 * @brief Mark window as registered/unregistered with graphics
87 * Called by GraphicsSubsystem during register/unregister
88 */
89 void set_graphics_registered(bool registered) override;
90
91 /**
92 * @brief Register a VKBuffer as rendering to this window
93 * @param buffer Buffer that will render to this window
94 *
95 * Used for tracking and queries. Does not affect rendering directly.
96 */
97 void register_rendering_buffer(std::shared_ptr<Buffers::VKBuffer> buffer) override;
98
99 /**
100 * @brief Unregister a VKBuffer from this window
101 * @param buffer Buffer to unregister
102 */
103 void unregister_rendering_buffer(std::shared_ptr<Buffers::VKBuffer> buffer) override;
104
105 /**
106 * @brief Track a secondary command buffer for this frame
107 * @param cmd_id Command buffer ID that contains draw commands for this window
108 *
109 * Called by RenderProcessor after recording. PresentProcessor queries these
110 * to know which secondary buffers to execute.
111 */
112 void track_frame_command(uint64_t cmd_id) override;
113
114 /**
115 * @brief Get all command buffers recorded for this frame
116 * @return Vector of command buffer IDs
117 *
118 * Called by PresentProcessor to collect secondary buffers for execution.
119 */
120 [[nodiscard]] const std::vector<uint64_t>& get_frame_commands() const override;
121
122 /**
123 * @brief Clear tracked commands for this frame
124 *
125 * Called after presenting to reset for next frame.
126 */
127 void clear_frame_commands() override;
128
129 /**
130 * @brief Get all VKBuffers currently rendering to this window
131 * @return Vector of buffers (weak_ptr to avoid ownership issues)
132 */
133 [[nodiscard]] std::vector<std::shared_ptr<Buffers::VKBuffer>> get_rendering_buffers() const override;
134
135private:
136 GLFWwindow* m_window = nullptr;
141
142 std::atomic<bool> m_graphics_registered { false };
143
145
146 std::vector<std::weak_ptr<Buffers::VKBuffer>> m_rendering_buffers;
147 std::vector<uint64_t> m_frame_commands;
148 mutable std::mutex m_render_tracking_mutex;
149
150 void configure_window_hints(const GraphicsSurfaceInfo& surface_info, GlobalGraphicsConfig::GraphicsApi api) const;
151 void setup_callbacks();
152
153 static void glfw_window_size_callback(GLFWwindow* window, int width, int height);
154 static void glfw_window_close_callback(GLFWwindow* window);
155 static void glfw_window_focus_callback(GLFWwindow* window, int focused);
156 static void glfw_framebuffer_size_callback(GLFWwindow* window, int width, int height);
157 static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
158 static void glfw_cursor_pos_callback(GLFWwindow* window, double xpos, double ypos);
159 static void glfw_mouse_button_callback(GLFWwindow* window, int button, int action, int mods);
160 static void glfw_scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
161};
162}
std::vector< std::weak_ptr< Buffers::VKBuffer > > m_rendering_buffers
bool is_graphics_registered() const override
Check if window is registered with graphics subsystem.
Vruta::EventSource m_event_source
const InputConfig & get_input_config() const override
Get current input configuration.
GlfwWindow(const GlfwWindow &)=delete
WindowCreateInfo m_create_info
void set_input_config(const InputConfig &config) override
Set input configuration (keyboard, mouse, cursor)
const Vruta::EventSource & get_event_source() const override
const WindowCreateInfo & get_create_info() const override
GlfwWindow & operator=(const GlfwWindow &)=delete
GLFWwindow * get_glfw_handle() const
Vruta::EventSource & get_event_source() override
Gets the event source for awaiting events.
std::vector< uint64_t > m_frame_commands
WindowEventCallback m_event_callback
Platform-agnostic window wrapper.
Platform-agnostic window wrapper.
Definition Window.hpp:22
Awaitable event stream for window events.
std::function< void(const WindowEvent &)> WindowEventCallback
Configuration hints for GLFW initialization.
System-wide configuration for visual stream processing.
Input configuration for a window.
Configuration for creating a single window instance.
Runtime state of a window (mutable by system, read by user)