maplibre/render/
settings.rs1use std::borrow::Cow;
4
5use wgpu::PresentMode;
6pub use wgpu::{Backends, Features, Limits, PowerPreference, TextureFormat};
7
8#[derive(Clone)]
12pub struct WgpuSettings {
13 pub device_label: Option<Cow<'static, str>>,
14 pub backends: Option<Backends>,
15 pub power_preference: PowerPreference,
16 pub features: Features,
19 pub disabled_features: Option<Features>,
21 pub limits: Limits,
23 pub constrained_limits: Option<Limits>,
25
26 pub record_trace: bool,
28}
29
30impl Default for WgpuSettings {
31 fn default() -> Self {
32 let backends = Some(wgpu::util::backend_bits_from_env().unwrap_or(Backends::all()));
33
34 let limits = if cfg!(feature = "web-webgl") {
35 Limits {
36 max_texture_dimension_2d: 4096,
37 ..Limits::downlevel_webgl2_defaults()
38 }
39 } else if cfg!(target_os = "android") {
40 Limits {
41 max_storage_textures_per_shader_stage: 4,
42 max_compute_workgroups_per_dimension: 0,
43 max_compute_workgroup_size_z: 0,
44 max_compute_workgroup_size_y: 0,
45 max_compute_workgroup_size_x: 0,
46 max_compute_workgroup_storage_size: 0,
47 max_compute_invocations_per_workgroup: 0,
48 ..Limits::downlevel_defaults()
49 }
50 } else {
51 Limits {
52 ..Limits::default()
53 }
54 };
55
56 let features = Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES;
57
58 Self {
59 device_label: Default::default(),
60 backends,
61 power_preference: PowerPreference::HighPerformance,
62 features,
63 disabled_features: None,
64 limits,
65 constrained_limits: None,
66 record_trace: false,
67 }
68 }
69}
70
71#[derive(Clone)]
72pub enum SurfaceType {
73 Headless,
74 Headed,
75}
76
77#[derive(Copy, Clone)]
78pub struct Msaa {
81 pub samples: u32,
89}
90
91impl Msaa {
92 pub fn is_multisampling(&self) -> bool {
93 self.samples > 1
94 }
95}
96
97impl Default for Msaa {
98 fn default() -> Self {
99 Self { samples: 4 }
101 }
102}
103
104#[derive(Clone, Copy)]
105pub struct RendererSettings {
106 pub msaa: Msaa,
107 pub texture_format: Option<TextureFormat>,
109 pub depth_texture_format: TextureFormat,
110 pub present_mode: PresentMode,
112}
113
114impl Default for RendererSettings {
115 fn default() -> Self {
116 Self {
117 msaa: Msaa::default(),
118 texture_format: None,
119
120 depth_texture_format: TextureFormat::Depth24PlusStencil8,
121 present_mode: PresentMode::AutoVsync,
122 }
123 }
124}