MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
GlobalGraphicsInfo.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Core {
6
7//==============================================================================
8// GRAPHICS BACKEND CONFIGURATION (Vulkan/OpenGL/etc.)
9//==============================================================================
10
11/**
12 * @struct GraphicsBackendInfo
13 * @brief Configuration for graphics API backend (Vulkan/OpenGL/etc.)
14 *
15 * Separate from windowing - this is GPU/rendering configuration.
16 * GraphicsSurfaceInfo handles windows, this handles the graphics API.
17 */
18struct MAYAFLUX_API GraphicsBackendInfo {
19 /** @brief Enable validation layers (debug builds) */
20 bool enable_validation = true;
21
22 /** @brief Enable GPU debug markers (for profiling tools) */
23 bool enable_debug_markers = false;
24
25 /** @brief Required device features (Vulkan-specific) */
26 struct {
27 bool compute_shaders = true;
28 bool geometry_shaders = false;
29 bool tessellation_shaders = false;
30 bool multi_viewport = false;
31 bool sampler_anisotropy = true;
32 bool fill_mode_non_solid = false;
33 } required_features;
34
35 /** @brief Memory allocation strategy */
36 enum class MemoryStrategy : uint8_t {
37 CONSERVATIVE, ///< Minimize allocations
38 BALANCED, ///< Balance speed and memory
39 AGGRESSIVE ///< Maximize performance
40 } memory_strategy = MemoryStrategy::BALANCED;
41
42 /** @brief Command buffer pooling strategy */
43 enum class CommandPooling : uint8_t {
44 PER_THREAD, ///< One pool per thread
45 SHARED, ///< Shared pool
46 PER_QUEUE ///< One pool per queue family
47 } command_pooling = CommandPooling::PER_THREAD;
48
49 /** @brief Maximum number of frames in flight (GPU pipelining) */
50 uint32_t max_frames_in_flight = 2;
51
52 /** @brief Enable compute queue (separate from graphics) */
53 bool enable_compute_queue = true;
54
55 /** @brief Enable transfer queue (separate from graphics) */
56 bool enable_transfer_queue = false;
57
58 /** @brief Shader compilation strategy */
59 enum class ShaderCompilation : uint8_t {
60 RUNTIME, ///< Compile at runtime
61 PRECOMPILED, ///< Use pre-compiled SPIR-V
62 CACHED ///< Cache compiled shaders
63 } shader_compilation = ShaderCompilation::CACHED;
64
65 /** @brief Shader cache directory (if caching enabled) */
66 std::filesystem::path shader_cache_dir = "cache/shaders";
67
68 /** @brief Backend-specific extensions to request */
69 std::vector<std::string> required_extensions;
70 std::vector<std::string> optional_extensions;
71
72 static constexpr auto describe()
73 {
74 return std::make_tuple(
75 IO::member("enable_validation", &GraphicsBackendInfo::enable_validation),
76 IO::member("enable_debug_markers", &GraphicsBackendInfo::enable_debug_markers),
77 // IO::member("required_features", &GraphicsBackendInfo::required_features),
78 IO::member("memory_strategy", &GraphicsBackendInfo::memory_strategy),
79 IO::member("command_pooling", &GraphicsBackendInfo::command_pooling),
80 IO::member("max_frames_in_flight", &GraphicsBackendInfo::max_frames_in_flight),
81 IO::member("enable_compute_queue", &GraphicsBackendInfo::enable_compute_queue),
82 IO::member("enable_transfer_queue", &GraphicsBackendInfo::enable_transfer_queue),
83 IO::member("shader_compilation", &GraphicsBackendInfo::shader_compilation),
84 IO::member("shader_cache_dir", &GraphicsBackendInfo::shader_cache_dir),
85 IO::member("required_extensions", &GraphicsBackendInfo::required_extensions),
86 IO::member("optional_extensions", &GraphicsBackendInfo::optional_extensions));
87 }
88};
89
90/**
91 * @struct GraphicsResourceLimits
92 * @brief Resource limits and budgets for graphics subsystem
93 *
94 * Prevents runaway resource usage, similar to audio buffer limits.
95 */
96struct MAYAFLUX_API GraphicsResourceLimits {
97 /** @brief Maximum number of concurrent windows */
98 uint32_t max_windows = 16;
99
100 /** @brief Maximum staging buffer size (MB) */
101 uint32_t max_staging_buffer_mb = 256;
102
103 /** @brief Maximum compute buffer size (MB) */
104 uint32_t max_compute_buffer_mb = 1024;
105
106 /** @brief Maximum texture cache size (MB) */
107 uint32_t max_texture_cache_mb = 2048;
108
109 /** @brief Maximum number of descriptor sets */
110 uint32_t max_descriptor_sets = 1024;
111
112 /** @brief Maximum number of pipeline state objects */
113 uint32_t max_pipelines = 256;
114
115 static constexpr auto describe()
116 {
117 return std::make_tuple(
118 IO::member("max_windows", &GraphicsResourceLimits::max_windows),
119 IO::member("max_staging_buffer_mb", &GraphicsResourceLimits::max_staging_buffer_mb),
120 IO::member("max_compute_buffer_mb", &GraphicsResourceLimits::max_compute_buffer_mb),
121 IO::member("max_texture_cache_mb", &GraphicsResourceLimits::max_texture_cache_mb),
122 IO::member("max_descriptor_sets", &GraphicsResourceLimits::max_descriptor_sets),
123 IO::member("max_pipelines", &GraphicsResourceLimits::max_pipelines));
124 }
125};
126
127//==============================================================================
128// GLOBAL VISUAL STREAM INFO (Parallel to GlobalStreamInfo)
129//==============================================================================
130
131/**
132 * @struct GraphicsSurfaceInfo
133 * @brief System-wide configuration for visual stream processing
134 *
135 * Defines technical parameters for ALL windows/visual streams in the system.
136 * This is set once at subsystem initialization, similar to audio sample rate.
137 * Individual windows inherit these defaults but can override specific params.
138 */
139struct MAYAFLUX_API GraphicsSurfaceInfo {
140
141 /**
142 * @enum SurfaceFormat
143 * @brief Default pixel format for window surfaces (Vulkan-compatible)
144 */
145 enum class SurfaceFormat : uint8_t {
146 B8G8R8A8_SRGB, ///< Most common - 8-bit SRGB
147 R8G8B8A8_SRGB, ///< Alternative 8-bit SRGB
148 B8G8R8A8_UNORM, ///< 8-bit linear
149 R8G8B8A8_UNORM, ///< 8-bit linear
150 R16G16B16A16_SFLOAT, ///< 16-bit float HDR
151 A2B10G10R10_UNORM, ///< 10-bit HDR
152 R32G32B32A32_SFLOAT, ///< 32-bit float
153 };
154
155 /** @brief Default surface format for new windows */
156 SurfaceFormat format = SurfaceFormat::B8G8R8A8_SRGB;
157
158 /**
159 * @enum ColorSpace
160 * @brief Default color space for window surfaces
161 */
162 enum class ColorSpace : uint8_t {
163 SRGB_NONLINEAR, ///< Standard sRGB
164 EXTENDED_SRGB, ///< Extended sRGB for HDR
165 HDR10_ST2084, ///< HDR10 PQ
166 DISPLAY_P3, ///< DCI-P3
167 };
168
169 /** @brief Default color space for new windows */
170 ColorSpace color_space = ColorSpace::SRGB_NONLINEAR;
171
172 /**
173 * @enum PresentMode
174 * @brief Frame presentation strategy
175 */
176 enum class PresentMode : uint8_t {
177 IMMEDIATE, ///< No vsync, tear possible
178 MAILBOX, ///< Triple buffering, no tear
179 FIFO, ///< Vsync, no tear
180 FIFO_RELAXED, ///< Vsync, tear if late
181 };
182
183 /** @brief Default presentation mode for new windows */
184 PresentMode present_mode = PresentMode::FIFO;
185
186 /** @brief Default number of swapchain images (double/triple buffering) */
187 uint32_t image_count = 3;
188
189 /** @brief Enable region-based processing by default */
190 bool enable_regions = true;
191
192 /** @brief Maximum regions per window container */
193 uint32_t max_regions_per_window = 256;
194
195 /** @brief Enable HDR output if available */
196 bool enable_hdr {};
197
198 /** @brief Measure and report actual frame times */
199 bool measure_frame_time {};
200
201 /** @brief Backend-specific configuration parameters */
202 std::unordered_map<std::string, std::any> backend_options;
203
204 static constexpr auto describe()
205 {
206 return std::make_tuple(
207 IO::member("format", &GraphicsSurfaceInfo::format),
208 IO::member("color_space", &GraphicsSurfaceInfo::color_space),
209 IO::member("present_mode", &GraphicsSurfaceInfo::present_mode),
210 IO::member("image_count", &GraphicsSurfaceInfo::image_count),
211 IO::member("enable_regions", &GraphicsSurfaceInfo::enable_regions),
212 IO::member("max_regions_per_window", &GraphicsSurfaceInfo::max_regions_per_window),
213 IO::member("enable_hdr", &GraphicsSurfaceInfo::enable_hdr),
214 IO::member("measure_frame_time", &GraphicsSurfaceInfo::measure_frame_time));
215 }
216};
217
218#ifdef MAYAFLUX_PLATFORM_MACOS
219
220/**
221 * @struct GlfwPreInitConfig
222 * @brief Configuration hints for GLFW initialization
223 *
224 * Set before initializing the GLFW library. These affect how GLFW sets up
225 * its internal state and platform integration.
226 */
227struct GlfwPreInitConfig {
228 bool cocoa_chdir_resources = true;
229 bool cocoa_menubar = true;
230
231 /** @brief Request OpenGL debug context (if using OpenGL backend) */
232 bool headless {};
233
234 static constexpr auto describe()
235 {
236 return std::make_tuple(
237 IO::member("cocoa_chdir_resources", &GlfwPreInitConfig::cocoa_chdir_resources),
238 IO::member("cocoa_menubar", &GlfwPreInitConfig::cocoa_menubar),
239 IO::member("headless", &GlfwPreInitConfig::headless));
240 }
241};
242#endif // MAYAFLUX_PLATFORM_MACOS
243
244/**
245 * @struct KeyRepeatConfig
246 * @brief Key repeat timing for native window backends.
247 *
248 * Wayland and Win32 backends implement client-side repeat using these values.
249 * GLFW backend ignores this; OS repeat settings apply there.
250 */
252 /** @brief Delay before repeat starts in milliseconds. */
253 uint32_t initial_delay_ms { 90 };
254
255 /** @brief Interval between repeat events in milliseconds. */
256 uint32_t interval_ms { 16 };
257
258 /** @brief If true, compositor-reported repeat_info overrides these values. */
260
261 static constexpr auto describe()
262 {
263 return std::make_tuple(
264 IO::member("initial_delay_ms", &KeyRepeatConfig::initial_delay_ms),
266 IO::member("allow_compositor_override", &KeyRepeatConfig::allow_compositor_override));
267 }
268};
269
270/**
271 * @struct TextConfig
272 * @brief Default font configuration for Portal::Text.
273 *
274 * When present, GraphicsSubsystem initializes Portal::Text and attempts to
275 * load the specified font as the system default. Users may call
276 * Portal::Text::set_default_font() at any time after initialization to
277 * replace or augment this.
278 *
279 * When absent, Portal::Text is still initialized but no default atlas is
280 * created; any call to InkPress that requires a default atlas will log an
281 * error until the user sets one explicitly.
282 */
284 /** @brief Font family name forwarded to Platform::find_font(). */
285 std::string family;
286
287 /** @brief Optional style hint (e.g. "Regular", "Bold"). */
288 std::string style;
289
290 /** @brief Glyph rasterization height in pixels. */
291 uint32_t pixel_size { 24 };
292
293 /** @brief Atlas texture dimension (power of two). */
294 uint32_t atlas_size { 512 };
295
296 static constexpr auto describe()
297 {
298 return std::make_tuple(
299 IO::member("family", &TextConfig::family),
300 IO::member("style", &TextConfig::style),
301 IO::member("pixel_size", &TextConfig::pixel_size),
302 IO::member("atlas_size", &TextConfig::atlas_size));
303 }
304};
305
306struct MAYAFLUX_API GlobalGraphicsConfig {
307#ifdef MAYAFLUX_PLATFORM_MACOS
308 /** @brief Pre-initialization configuration for GLFW */
309 GlfwPreInitConfig glfw_preinit_config;
310#endif // MAYAFLUX_PLATFORM_MACOS
311
312 /** @brief Key repeat timing for native Wayland and Win32 backends. */
314
315 /** @brief System-wide configuration for visual stream processing */
317
318 /** @brief Graphics backend configuration */
320
321 /** @brief Resource limits */
323
324 /**
325 * @enum WindowingBackend
326 * @brief Windowing library selection
327 */
328 enum class WindowingBackend : uint8_t {
329 GLFW, ///< GLFW3 (default, cross-platform)
330 WINDOWS, ///< Native Win32
331 WAYLAND, ///< Native Wayland
332 NONE ///< No windowing (offscreen rendering only)
333 };
334
335 /**
336 * @enum VisualApi
337 * @brief Supported graphics APIs (backend selection)
338 */
339 enum class GraphicsApi : uint8_t {
340 VULKAN,
341 OPENGL,
342 METAL,
343 DIRECTX12
344 };
345
346 /** @brief Target frame rate for visual processing (Hz) */
347 uint32_t target_frame_rate = 60;
348
349#if defined(MAYAFLUX_PLATFORM_WINDOWS)
350#ifndef WIN32_BACKEND
351#error "Windows builds require WIN32_BACKEND"
352#endif // WIN32_BACKEND
353 /** @brief Selected windowing backend */
354 WindowingBackend windowing_backend = WindowingBackend::WINDOWS;
355#elif defined(WAYLAND_BACKEND)
356 /** @brief Selected windowing backend */
357 WindowingBackend windowing_backend = WindowingBackend::WAYLAND;
358#else
359 /** @brief Selected windowing backend */
360 WindowingBackend windowing_backend = WindowingBackend::GLFW;
361#endif // defined(MAYAFLUX_PLATFORM_WINDOWS) && defined (WIN32_BACKEND)
362
363 /** @brief Selected graphics API for rendering */
364 GraphicsApi requested_api = GraphicsApi::VULKAN;
365
366 /** @brief Default font for Portal::Text. */
367 TextConfig text_config {
368#if defined(MAYAFLUX_PLATFORM_LINUX)
369 "sans-serif", "", 24, 512
370#elif defined(MAYAFLUX_PLATFORM_MACOS)
371 "Helvetica Neue", "", 24, 512
372#elif defined(MAYAFLUX_PLATFORM_WINDOWS)
373 "Segoe UI", "", 24, 512
374#else
375 "sans-serif", "", 24, 512
376#endif
377 };
378
379#ifdef MAYAFLUX_PLATFORM_MACOS
380 static constexpr auto describe()
381 {
382 return std::make_tuple(
383 IO::member("glfw_preinit_config", &GlobalGraphicsConfig::glfw_preinit_config),
384 IO::member("key_repeat_config", &GlobalGraphicsConfig::key_repeat_config),
385 IO::member("surface_info", &GlobalGraphicsConfig::surface_info),
386 IO::member("backend_info", &GlobalGraphicsConfig::backend_info),
387 IO::member("resource_limits", &GlobalGraphicsConfig::resource_limits),
388 IO::member("target_frame_rate", &GlobalGraphicsConfig::target_frame_rate),
389 IO::member("windowing_backend", &GlobalGraphicsConfig::windowing_backend),
390 IO::member("requested_api", &GlobalGraphicsConfig::requested_api),
391 IO::member("text_config", &GlobalGraphicsConfig::text_config));
392 }
393#else
394 static constexpr auto describe()
395 {
396 return std::make_tuple(
397 IO::member("key_repeat_config", &GlobalGraphicsConfig::key_repeat_config),
398 IO::member("surface_info", &GlobalGraphicsConfig::surface_info),
399 IO::member("backend_info", &GlobalGraphicsConfig::backend_info),
400 IO::member("resource_limits", &GlobalGraphicsConfig::resource_limits),
401 IO::member("target_frame_rate", &GlobalGraphicsConfig::target_frame_rate),
402 IO::member("windowing_backend", &GlobalGraphicsConfig::windowing_backend),
403 IO::member("requested_api", &GlobalGraphicsConfig::requested_api),
404 IO::member("text_config", &GlobalGraphicsConfig::text_config));
405 }
406
407#endif // #ifdef MAYAFLUX_PLATFORM_MACOS
408};
409
410//==============================================================================
411// PER-WINDOW CREATION INFO (Parallel to audio ChannelConfig)
412//==============================================================================
413
414/**
415 * @struct WindowCreateInfo
416 * @brief Configuration for creating a single window instance
417 *
418 * Lightweight per-window parameters. Most settings inherited from
419 * GraphicsSurfaceInfo. This is like creating a new audio channel - you specify
420 * only what differs from global defaults.
421 */
422struct MAYAFLUX_API WindowCreateInfo {
423 /** @brief Window title/identifier */
424 std::string title { "MayaFlux Window" };
425
426 /** @brief Initial window dimensions */
427 uint32_t width { 1920 };
428 uint32_t height { 1080 };
429
430 /** @brief Target monitor ID (-1 = primary monitor) */
431 int32_t monitor_id { -1 };
432
433 /** @brief Start in fullscreen mode */
434 bool fullscreen {};
435
436 /** @brief Window can be resized by user */
437 bool resizable { true };
438
439 /** @brief Show OS window decorations (title bar, borders) */
440 bool decorated { true };
441
442 /** @brief Transparent framebuffer (compositing) */
443 bool transparent {};
444
445 /** @brief Window always on top */
446 bool floating {};
447
448 /** @brief Register this window for processing (if false, no grpahics API handles visuals) */
449 bool register_for_processing { true };
450
451 /** @brief Override global surface format (nullopt = use global default) */
452 std::optional<GraphicsSurfaceInfo::SurfaceFormat> surface_format;
453
454 /** @brief Override global present mode (nullopt = use global default) */
455 std::optional<GraphicsSurfaceInfo::PresentMode> present_mode;
456
457 /** @brief Container dimensions (channels) */
458 struct {
459 uint32_t color_channels { 4 };
460 bool has_depth {};
461 bool has_stencil {};
462 } container_format;
463
464 std::array<float, 4> clear_color { { 0.0F, 0.0F, 0.0F, 1.0F } };
465};
466
467//==============================================================================
468// WINDOW RUNTIME STATE (Read-only, updated by subsystem)
469//==============================================================================
470
471/**
472 * @struct WindowState
473 * @brief Runtime state of a window (mutable by system, read by user)
474 *
475 * You don't set these - the windowing subsystem updates them as events occur.
476 */
478 uint32_t current_width = 0;
479 uint32_t current_height = 0;
480
481 bool is_visible = true;
482 bool is_focused = false;
483 bool is_minimized = false;
484 bool is_maximized = false;
485 bool is_hovered = false;
486
487 uint64_t frame_count = 0;
488 double last_present_time = 0.0;
489 double average_frame_time = 0.0;
490};
491
492//==============================================================================
493// INPUT CONFIGURATION (Runtime mutable)
494//==============================================================================
495
496/**
497 * @enum CursorMode
498 * @brief Cursor visibility and behavior
499 */
500enum class CursorMode : uint8_t {
501 NORMAL, ///< Visible and movable
502 HIDDEN, ///< Invisible but movable
503 DISABLED, ///< Invisible and locked (FPS camera)
504 CAPTURED, ///< Invisible, locked, raw motion
505};
506
507/**
508 * @struct InputConfig
509 * @brief Input configuration for a window
510 *
511 * Can be changed at runtime via window->set_input_config()
512 */
522
523//==============================================================================
524// WINDOW EVENTS
525//==============================================================================
526
527/**
528 * @enum WindowEventType
529 * @brief Types of window and input events
530 */
558
559/**
560 * @struct WindowEvent
561 * @brief Event data for window and input events
562 */
565 double timestamp;
566
567 struct ResizeData {
568 uint32_t width, height;
569 };
570 struct KeyData {
571 int16_t key;
572 int32_t scancode, mods;
573 };
575 double x, y;
576 };
578 int8_t button;
579 int32_t mods;
580 };
581 struct ScrollData {
583 };
584
585 using EventData = std::variant<
586 std::monostate,
588 KeyData,
592 std::any>;
593
595
596 WindowEvent() = default;
597 WindowEvent(const WindowEvent&) = default;
598 WindowEvent(WindowEvent&&) noexcept = default;
599 WindowEvent& operator=(const WindowEvent&) = default;
600 WindowEvent& operator=(WindowEvent&&) noexcept = default;
601 ~WindowEvent() = default;
602};
603
604using WindowEventCallback = std::function<void(const WindowEvent&)>;
605
606//==============================================================================
607// MONITOR INFORMATION (System query, not per-window config)
608//==============================================================================
609
610/**
611 * @struct VideoMode
612 * @brief Monitor video mode
613 */
614struct VideoMode {
615 uint32_t width, height;
616 uint32_t refresh_rate;
617 uint8_t red_bits, green_bits, blue_bits;
618
619 bool operator==(const VideoMode& other) const
620 {
621 return width == other.width && height == other.height && refresh_rate == other.refresh_rate;
622 }
623};
624
625/**
626 * @struct MonitorInfo
627 * @brief Information about a physical display
628 */
630 int32_t id;
631 std::string name;
632 int32_t width_mm, height_mm;
634 bool is_primary = false;
635};
636
637} // namespace MayaFlux::Core
uint32_t width
Definition Decoder.cpp:59
CursorMode
Cursor visibility and behavior.
@ DISABLED
Invisible and locked (FPS camera)
@ NORMAL
Visible and movable.
@ CAPTURED
Invisible, locked, raw motion.
@ HIDDEN
Invisible but movable.
WindowEventType
Types of window and input events.
std::function< void(const WindowEvent &)> WindowEventCallback
constexpr auto member(std::string_view key, T Class::*ptr)
GraphicsSurfaceInfo surface_info
System-wide configuration for visual stream processing.
WindowingBackend
Windowing library selection.
GraphicsResourceLimits resource_limits
Resource limits.
GraphicsBackendInfo backend_info
Graphics backend configuration.
KeyRepeatConfig key_repeat_config
Key repeat timing for native Wayland and Win32 backends.
std::vector< std::string > required_extensions
Backend-specific extensions to request.
MemoryStrategy
Memory allocation strategy.
std::vector< std::string > optional_extensions
CommandPooling
Command buffer pooling strategy.
ShaderCompilation
Shader compilation strategy.
Configuration for graphics API backend (Vulkan/OpenGL/etc.)
Resource limits and budgets for graphics subsystem.
ColorSpace
Default color space for window surfaces.
SurfaceFormat
Default pixel format for window surfaces (Vulkan-compatible)
PresentMode
Frame presentation strategy.
std::unordered_map< std::string, std::any > backend_options
Backend-specific configuration parameters.
System-wide configuration for visual stream processing.
Input configuration for a window.
uint32_t interval_ms
Interval between repeat events in milliseconds.
uint32_t initial_delay_ms
Delay before repeat starts in milliseconds.
bool allow_compositor_override
If true, compositor-reported repeat_info overrides these values.
Key repeat timing for native window backends.
Information about a physical display.
std::string style
Optional style hint (e.g.
static constexpr auto describe()
uint32_t atlas_size
Atlas texture dimension (power of two).
uint32_t pixel_size
Glyph rasterization height in pixels.
std::string family
Font family name forwarded to Platform::find_font().
Default font configuration for Portal::Text.
bool operator==(const VideoMode &other) const
std::optional< GraphicsSurfaceInfo::PresentMode > present_mode
Override global present mode (nullopt = use global default)
std::optional< GraphicsSurfaceInfo::SurfaceFormat > surface_format
Override global surface format (nullopt = use global default)
Configuration for creating a single window instance.
std::variant< std::monostate, ResizeData, KeyData, MousePosData, MouseButtonData, ScrollData, std::any > EventData
WindowEvent(const WindowEvent &)=default
WindowEvent(WindowEvent &&) noexcept=default
Event data for window and input events.
Runtime state of a window (mutable by system, read by user)