2020-05-28 01:46:17 +02:00
|
|
|
//! Configure a renderer.
|
2020-05-29 23:09:15 +02:00
|
|
|
pub use crate::Antialiasing;
|
2020-02-18 08:48:54 +01:00
|
|
|
|
2020-11-25 07:11:27 +01:00
|
|
|
/// The settings of a [`Backend`].
|
2020-01-09 18:31:07 +01:00
|
|
|
///
|
2020-11-25 07:11:27 +01:00
|
|
|
/// [`Backend`]: crate::Backend
|
2020-06-01 22:07:29 +02:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
2020-01-01 17:49:48 +01:00
|
|
|
pub struct Settings {
|
2020-11-25 07:11:27 +01:00
|
|
|
/// The present mode of the [`Backend`].
|
2020-11-23 00:00:13 +01:00
|
|
|
///
|
2020-11-25 07:11:27 +01:00
|
|
|
/// [`Backend`]: crate::Backend
|
2020-11-23 00:00:13 +01:00
|
|
|
pub present_mode: wgpu::PresentMode,
|
|
|
|
|
|
2021-03-25 11:27:31 +01:00
|
|
|
/// The internal graphics backend to use.
|
2021-08-19 03:06:35 +02:00
|
|
|
pub internal_backend: wgpu::Backends,
|
2021-03-25 11:27:31 +01:00
|
|
|
|
2020-01-09 18:31:07 +01:00
|
|
|
/// The bytes of the font that will be used by default.
|
|
|
|
|
///
|
|
|
|
|
/// If `None` is provided, a default system font will be chosen.
|
2020-01-01 17:49:48 +01:00
|
|
|
pub default_font: Option<&'static [u8]>,
|
2020-02-15 10:08:27 +01:00
|
|
|
|
2020-06-19 00:08:28 +02:00
|
|
|
/// The default size of text.
|
|
|
|
|
///
|
|
|
|
|
/// By default, it will be set to 20.
|
|
|
|
|
pub default_text_size: u16,
|
|
|
|
|
|
2021-07-22 18:21:50 +07:00
|
|
|
/// If enabled, spread text workload in multiple threads when multiple cores
|
|
|
|
|
/// are available.
|
2021-07-22 18:27:33 +07:00
|
|
|
///
|
|
|
|
|
/// By default, it is disabled.
|
2021-07-22 18:21:50 +07:00
|
|
|
pub text_multithreading: bool,
|
|
|
|
|
|
2020-02-15 10:08:27 +01:00
|
|
|
/// The antialiasing strategy that will be used for triangle primitives.
|
2021-07-22 18:27:33 +07:00
|
|
|
///
|
|
|
|
|
/// By default, it is `None`.
|
2020-02-18 08:48:54 +01:00
|
|
|
pub antialiasing: Option<Antialiasing>,
|
2020-02-15 10:08:27 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-25 11:27:31 +01:00
|
|
|
impl Settings {
|
|
|
|
|
/// Creates new [`Settings`] using environment configuration.
|
|
|
|
|
///
|
|
|
|
|
/// Specifically:
|
|
|
|
|
///
|
|
|
|
|
/// - The `internal_backend` can be configured using the `WGPU_BACKEND`
|
|
|
|
|
/// environment variable. If the variable is not set, the primary backend
|
|
|
|
|
/// will be used. The following values are allowed:
|
|
|
|
|
/// - `vulkan`
|
|
|
|
|
/// - `metal`
|
|
|
|
|
/// - `dx12`
|
|
|
|
|
/// - `dx11`
|
|
|
|
|
/// - `gl`
|
|
|
|
|
/// - `webgpu`
|
2021-05-14 21:21:25 +08:00
|
|
|
/// - `primary`
|
2021-03-25 11:27:31 +01:00
|
|
|
pub fn from_env() -> Self {
|
|
|
|
|
Settings {
|
|
|
|
|
internal_backend: backend_from_env()
|
2021-08-19 03:06:35 +02:00
|
|
|
.unwrap_or(wgpu::Backends::all()),
|
2021-03-25 11:27:31 +01:00
|
|
|
..Self::default()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-24 20:08:40 +01:00
|
|
|
impl Default for Settings {
|
|
|
|
|
fn default() -> Settings {
|
|
|
|
|
Settings {
|
2022-07-02 15:39:42 +08:00
|
|
|
present_mode: wgpu::PresentMode::AutoVsync,
|
2021-08-19 03:06:35 +02:00
|
|
|
internal_backend: wgpu::Backends::all(),
|
2020-02-24 20:08:40 +01:00
|
|
|
default_font: None,
|
2020-06-19 00:08:28 +02:00
|
|
|
default_text_size: 20,
|
2021-07-22 18:21:50 +07:00
|
|
|
text_multithreading: false,
|
2020-02-24 20:08:40 +01:00
|
|
|
antialiasing: None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-25 11:27:31 +01:00
|
|
|
|
2021-08-19 03:06:35 +02:00
|
|
|
fn backend_from_env() -> Option<wgpu::Backends> {
|
2021-03-25 11:27:31 +01:00
|
|
|
std::env::var("WGPU_BACKEND").ok().map(|backend| {
|
|
|
|
|
match backend.to_lowercase().as_str() {
|
2021-08-19 03:06:35 +02:00
|
|
|
"vulkan" => wgpu::Backends::VULKAN,
|
|
|
|
|
"metal" => wgpu::Backends::METAL,
|
|
|
|
|
"dx12" => wgpu::Backends::DX12,
|
|
|
|
|
"dx11" => wgpu::Backends::DX11,
|
|
|
|
|
"gl" => wgpu::Backends::GL,
|
|
|
|
|
"webgpu" => wgpu::Backends::BROWSER_WEBGPU,
|
|
|
|
|
"primary" => wgpu::Backends::PRIMARY,
|
2023-01-27 13:25:04 -07:00
|
|
|
other => panic!("Unknown backend: {other}"),
|
2021-03-25 11:27:31 +01:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|