From f1e20a61f16388ed4d2dac734bab30d67bbd84b3 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 9 Feb 2020 03:25:13 +0100 Subject: Allow `iced_wgpu` to render to any `TextureView` --- wgpu/src/window/swap_chain.rs | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 wgpu/src/window/swap_chain.rs (limited to 'wgpu/src/window/swap_chain.rs') diff --git a/wgpu/src/window/swap_chain.rs b/wgpu/src/window/swap_chain.rs new file mode 100644 index 00000000..46aaa869 --- /dev/null +++ b/wgpu/src/window/swap_chain.rs @@ -0,0 +1,49 @@ +use crate::Viewport; + +/// The rendering target of a window. +/// +/// It represents a series of virtual framebuffers with a scale factor. +#[derive(Debug)] +pub struct SwapChain { + raw: wgpu::SwapChain, + viewport: Viewport, +} + +impl SwapChain {} + +impl SwapChain { + pub fn new( + device: &wgpu::Device, + surface: &wgpu::Surface, + width: u32, + height: u32, + scale_factor: f64, + ) -> SwapChain { + SwapChain { + raw: new_swap_chain(surface, width, height, device), + viewport: Viewport::new(width, height, scale_factor), + } + } + + pub fn next_frame(&mut self) -> (wgpu::SwapChainOutput<'_>, &Viewport) { + (self.raw.get_next_texture(), &self.viewport) + } +} + +fn new_swap_chain( + surface: &wgpu::Surface, + width: u32, + height: u32, + device: &wgpu::Device, +) -> wgpu::SwapChain { + device.create_swap_chain( + &surface, + &wgpu::SwapChainDescriptor { + usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, + format: wgpu::TextureFormat::Bgra8UnormSrgb, + width, + height, + present_mode: wgpu::PresentMode::Vsync, + }, + ) +} -- cgit From 8f0b59a4b28bee028a879b0705eeeaa0b2e82df6 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 9 Feb 2020 03:36:59 +0100 Subject: Remove `scale_factor` from `iced_wgpu::Viewport` --- wgpu/src/window/swap_chain.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'wgpu/src/window/swap_chain.rs') diff --git a/wgpu/src/window/swap_chain.rs b/wgpu/src/window/swap_chain.rs index 46aaa869..3760e8a2 100644 --- a/wgpu/src/window/swap_chain.rs +++ b/wgpu/src/window/swap_chain.rs @@ -17,11 +17,10 @@ impl SwapChain { surface: &wgpu::Surface, width: u32, height: u32, - scale_factor: f64, ) -> SwapChain { SwapChain { raw: new_swap_chain(surface, width, height, device), - viewport: Viewport::new(width, height, scale_factor), + viewport: Viewport::new(width, height), } } -- cgit From 9a73c3a88d92262b4e59c1f061b1c56e533e2b0b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 9 Feb 2020 03:44:16 +0100 Subject: Write documentation for new `iced_wgpu` types --- wgpu/src/window/swap_chain.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'wgpu/src/window/swap_chain.rs') diff --git a/wgpu/src/window/swap_chain.rs b/wgpu/src/window/swap_chain.rs index 3760e8a2..6f545fce 100644 --- a/wgpu/src/window/swap_chain.rs +++ b/wgpu/src/window/swap_chain.rs @@ -12,6 +12,9 @@ pub struct SwapChain { impl SwapChain {} impl SwapChain { + /// Creates a new [`SwapChain`] for the given surface. + /// + /// [`SwapChain`]: struct.SwapChain.html pub fn new( device: &wgpu::Device, surface: &wgpu::Surface, @@ -24,6 +27,10 @@ impl SwapChain { } } + /// Returns the next frame of the [`SwapChain`] alongside its [`Viewport`]. + /// + /// [`SwapChain`]: struct.SwapChain.html + /// [`Viewport`]: ../struct.Viewport.html pub fn next_frame(&mut self) -> (wgpu::SwapChainOutput<'_>, &Viewport) { (self.raw.get_next_texture(), &self.viewport) } -- cgit