summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-05-07 21:05:29 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-05-07 21:05:29 +0200
commit8a0701a0d95989769341846b05ffcc705ae4ee5f (patch)
treeaaf616f28d82666e6816502f3b9ef2884b049fde /wgpu
parentdb07b9ba9ef20c5995076992bf5592af12698000 (diff)
downloadiced-8a0701a0d95989769341846b05ffcc705ae4ee5f.tar.gz
iced-8a0701a0d95989769341846b05ffcc705ae4ee5f.tar.bz2
iced-8a0701a0d95989769341846b05ffcc705ae4ee5f.zip
Introduce `ICED_PRESENT_MODE` env var to pick a `wgpu::PresentMode`
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/settings.rs14
-rw-r--r--wgpu/src/window/compositor.rs25
2 files changed, 29 insertions, 10 deletions
diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs
index a6aea0a5..5e2603ee 100644
--- a/wgpu/src/settings.rs
+++ b/wgpu/src/settings.rs
@@ -51,3 +51,17 @@ impl From<graphics::Settings> for Settings {
}
}
}
+
+pub fn present_mode_from_env() -> Option<wgpu::PresentMode> {
+ let present_mode = std::env::var("ICED_PRESENT_MODE").ok()?;
+
+ match present_mode.to_lowercase().as_str() {
+ "vsync" => Some(wgpu::PresentMode::AutoVsync),
+ "no_vsync" => Some(wgpu::PresentMode::AutoNoVsync),
+ "immediate" => Some(wgpu::PresentMode::Immediate),
+ "fifo" => Some(wgpu::PresentMode::Fifo),
+ "fifo_relaxed" => Some(wgpu::PresentMode::FifoRelaxed),
+ "mailbox" => Some(wgpu::PresentMode::Mailbox),
+ _ => None,
+ }
+}
diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs
index baf9f315..2e938c77 100644
--- a/wgpu/src/window/compositor.rs
+++ b/wgpu/src/window/compositor.rs
@@ -4,7 +4,8 @@ use crate::graphics::color;
use crate::graphics::compositor;
use crate::graphics::error;
use crate::graphics::{self, Viewport};
-use crate::{Engine, Renderer, Settings};
+use crate::settings::{self, Settings};
+use crate::{Engine, Renderer};
/// A window graphics backend for iced powered by `wgpu`.
#[allow(missing_debug_implementations)]
@@ -270,15 +271,19 @@ impl graphics::Compositor for Compositor {
backend: Option<&str>,
) -> Result<Self, graphics::Error> {
match backend {
- None | Some("wgpu") => Ok(new(
- Settings {
- backends: wgpu::util::backend_bits_from_env()
- .unwrap_or(wgpu::Backends::all()),
- ..settings.into()
- },
- compatible_window,
- )
- .await?),
+ None | Some("wgpu") => {
+ let mut settings = Settings::from(settings);
+
+ if let Some(backends) = wgpu::util::backend_bits_from_env() {
+ settings.backends = backends;
+ }
+
+ if let Some(present_mode) = settings::present_mode_from_env() {
+ settings.present_mode = present_mode;
+ }
+
+ Ok(new(settings, compatible_window).await?)
+ }
Some(backend) => Err(graphics::Error::GraphicsAdapterNotFound {
backend: "wgpu",
reason: error::Reason::DidNotMatch {