summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Tilmann Meyer <me@atiltedtree.dev>2021-08-01 20:38:34 +0200
committerLibravatar Tilmann Meyer <me@atiltedtree.dev>2021-08-03 11:30:45 +0200
commitd7975a9de591a57b265c2d62078a65ffb9209696 (patch)
tree1dc26f557bc84f059de82f436895858642f635e8 /wgpu
parenta08e4ebccbb72f9cf6fca01047e0b46a482ca9ea (diff)
downloadiced-d7975a9de591a57b265c2d62078a65ffb9209696.tar.gz
iced-d7975a9de591a57b265c2d62078a65ffb9209696.tar.bz2
iced-d7975a9de591a57b265c2d62078a65ffb9209696.zip
wgpu: Use the preferred texture format of the surface
Signed-off-by: Tilmann Meyer <me@atiltedtree.dev>
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/backend.rs19
-rw-r--r--wgpu/src/settings.rs6
-rw-r--r--wgpu/src/window/compositor.rs10
3 files changed, 18 insertions, 17 deletions
diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs
index 783079f3..4f34045b 100644
--- a/wgpu/src/backend.rs
+++ b/wgpu/src/backend.rs
@@ -30,23 +30,24 @@ pub struct Backend {
impl Backend {
/// Creates a new [`Backend`].
- pub fn new(device: &wgpu::Device, settings: Settings) -> Self {
+ pub fn new(
+ device: &wgpu::Device,
+ settings: Settings,
+ format: wgpu::TextureFormat,
+ ) -> Self {
let text_pipeline = text::Pipeline::new(
device,
- settings.format,
+ format,
settings.default_font,
settings.text_multithreading,
);
- let quad_pipeline = quad::Pipeline::new(device, settings.format);
- let triangle_pipeline = triangle::Pipeline::new(
- device,
- settings.format,
- settings.antialiasing,
- );
+ let quad_pipeline = quad::Pipeline::new(device, format);
+ let triangle_pipeline =
+ triangle::Pipeline::new(device, format, settings.antialiasing);
#[cfg(any(feature = "image_rs", feature = "svg"))]
- let image_pipeline = image::Pipeline::new(device, settings.format);
+ let image_pipeline = image::Pipeline::new(device, format);
Self {
quad_pipeline,
diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs
index 9a7eed34..dc06b82d 100644
--- a/wgpu/src/settings.rs
+++ b/wgpu/src/settings.rs
@@ -6,11 +6,6 @@ pub use crate::Antialiasing;
/// [`Backend`]: crate::Backend
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Settings {
- /// The output format of the [`Backend`].
- ///
- /// [`Backend`]: crate::Backend
- pub format: wgpu::TextureFormat,
-
/// The present mode of the [`Backend`].
///
/// [`Backend`]: crate::Backend
@@ -68,7 +63,6 @@ impl Settings {
impl Default for Settings {
fn default() -> Settings {
Settings {
- format: wgpu::TextureFormat::Bgra8UnormSrgb,
present_mode: wgpu::PresentMode::Mailbox,
internal_backend: wgpu::BackendBit::PRIMARY,
default_font: None,
diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs
index 9b65596f..68ebf234 100644
--- a/wgpu/src/window/compositor.rs
+++ b/wgpu/src/window/compositor.rs
@@ -13,6 +13,7 @@ pub struct Compositor {
queue: wgpu::Queue,
staging_belt: wgpu::util::StagingBelt,
local_pool: futures::executor::LocalPool,
+ format: wgpu::TextureFormat,
}
impl Compositor {
@@ -42,6 +43,10 @@ impl Compositor {
})
.await?;
+ let format = compatible_surface
+ .as_ref()
+ .and_then(|surf| adapter.get_swap_chain_preferred_format(surf))?;
+
let (device, queue) = adapter
.request_device(
&wgpu::DeviceDescriptor {
@@ -69,12 +74,13 @@ impl Compositor {
queue,
staging_belt,
local_pool,
+ format,
})
}
/// Creates a new rendering [`Backend`] for this [`Compositor`].
pub fn create_backend(&self) -> Backend {
- Backend::new(&self.device, self.settings)
+ Backend::new(&self.device, self.settings, self.format)
}
}
@@ -119,7 +125,7 @@ impl iced_graphics::window::Compositor for Compositor {
surface,
&wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
- format: self.settings.format,
+ format: self.format,
present_mode: self.settings.present_mode,
width,
height,