euv_core/render/config/impl.rs
1use super::*;
2
3/// Default rendering configuration (`Auto`, `VSync`, `AnalyticalSdf`, dirty rects enabled).
4impl Default for RenderConfig {
5 /// Creates the recommended cross-platform `RenderConfig`.
6 ///
7 /// # Returns
8 ///
9 /// - `Self` - Default `RenderConfig`.
10 fn default() -> Self {
11 Self {
12 mode: RenderMode::Auto,
13 preferred_backend: None,
14 present_mode: PresentMode::VSync,
15 antialiasing: AntialiasingMode::AnalyticalSdf,
16 color_space: ColorSpace::Srgb,
17 dirty_rect_optimization: true,
18 tile_size: DEFAULT_TILE_SIZE,
19 max_fps: DEFAULT_MAX_FPS,
20 hdr: false,
21 }
22 }
23}
24
25/// Fluent builder helpers for `RenderConfig`.
26impl RenderConfig {
27 /// Creates a software-rendering configuration.
28 ///
29 /// # Returns
30 ///
31 /// - `Self` - Software-mode `RenderConfig`.
32 #[must_use]
33 pub fn software() -> Self {
34 let mut cfg: Self = Self::default();
35 cfg.set_mode(RenderMode::Software);
36 cfg.set_preferred_backend(Some(GraphicsBackend::SoftwareCpu));
37 cfg
38 }
39
40 /// Creates a hardware GPU rendering configuration.
41 ///
42 /// # Returns
43 ///
44 /// - `Self` - Hardware-mode `RenderConfig`.
45 #[must_use]
46 pub fn hardware() -> Self {
47 let mut cfg: Self = Self::default();
48 cfg.set_mode(RenderMode::Hardware);
49 cfg
50 }
51
52 /// Creates a hybrid CPU-tile + GPU-compositor rendering configuration.
53 ///
54 /// # Returns
55 ///
56 /// - `Self` - Hybrid-mode `RenderConfig`.
57 #[must_use]
58 pub fn hybrid() -> Self {
59 let mut cfg: Self = Self::default();
60 cfg.set_mode(RenderMode::Hybrid);
61 cfg
62 }
63
64 /// Returns the optional preferred graphics backend.
65 ///
66 /// # Arguments
67 ///
68 /// - `&Self` - Render config.
69 ///
70 /// # Returns
71 ///
72 /// - `Option<GraphicsBackend>` - Explicit backend preference if set.
73 #[must_use]
74 pub fn preferred_backend_value(&self) -> Option<GraphicsBackend> {
75 let Self {
76 preferred_backend, ..
77 } = *self;
78 preferred_backend
79 }
80}