diff options
author | 2020-02-10 19:49:08 +0100 | |
---|---|---|
committer | 2020-02-10 19:49:08 +0100 | |
commit | 5d16f431b3088189579cf096b3abf89578cc73f6 (patch) | |
tree | c7efea00fabd87133a59760e902548d39822a844 /wgpu/src/window/swap_chain.rs | |
parent | 95880ca74bddb6a23774621ef766b91956d40a61 (diff) | |
parent | 4337daddb2a02a2c60dfc5beb896e3059588312a (diff) | |
download | iced-5d16f431b3088189579cf096b3abf89578cc73f6.tar.gz iced-5d16f431b3088189579cf096b3abf89578cc73f6.tar.bz2 iced-5d16f431b3088189579cf096b3abf89578cc73f6.zip |
Merge pull request #183 from hecrj/feature/wgpu-integration
Integration with existing `wgpu` projects
Diffstat (limited to 'wgpu/src/window/swap_chain.rs')
-rw-r--r-- | wgpu/src/window/swap_chain.rs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/wgpu/src/window/swap_chain.rs b/wgpu/src/window/swap_chain.rs new file mode 100644 index 00000000..6f545fce --- /dev/null +++ b/wgpu/src/window/swap_chain.rs @@ -0,0 +1,55 @@ +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 { + /// Creates a new [`SwapChain`] for the given surface. + /// + /// [`SwapChain`]: struct.SwapChain.html + pub fn new( + device: &wgpu::Device, + surface: &wgpu::Surface, + width: u32, + height: u32, + ) -> SwapChain { + SwapChain { + raw: new_swap_chain(surface, width, height, device), + viewport: Viewport::new(width, height), + } + } + + /// 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) + } +} + +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, + }, + ) +} |