2020-05-28 01:46:17 +02:00
|
|
|
//! Configure a renderer.
|
2023-03-04 05:37:11 +01:00
|
|
|
use crate::core::Font;
|
|
|
|
|
use crate::graphics::Antialiasing;
|
2023-02-04 07:33:33 +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
|
2023-02-04 07:33:33 +01:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
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
|
|
|
|
2023-02-04 07:33:33 +01:00
|
|
|
/// The default [`Font`] to use.
|
|
|
|
|
pub default_font: Font,
|
2020-02-15 10:08:27 +01:00
|
|
|
|
2020-06-19 00:08:28 +02:00
|
|
|
/// The default size of text.
|
|
|
|
|
///
|
2023-02-04 16:41:18 +01:00
|
|
|
/// By default, it will be set to `16.0`.
|
|
|
|
|
pub default_text_size: f32,
|
2020-06-19 00:08:28 +02:00
|
|
|
|
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(),
|
2023-02-04 07:33:33 +01:00
|
|
|
default_font: Font::SansSerif,
|
|
|
|
|
default_text_size: 16.0,
|
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
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|