summaryrefslogtreecommitdiffstats
path: root/wgpu/src/window/swap_chain.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-09 03:25:13 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-09 03:25:13 +0100
commitf1e20a61f16388ed4d2dac734bab30d67bbd84b3 (patch)
treee4112411df1b0493ecb34aa75ecd04e92e9a82af /wgpu/src/window/swap_chain.rs
parent95880ca74bddb6a23774621ef766b91956d40a61 (diff)
downloadiced-f1e20a61f16388ed4d2dac734bab30d67bbd84b3.tar.gz
iced-f1e20a61f16388ed4d2dac734bab30d67bbd84b3.tar.bz2
iced-f1e20a61f16388ed4d2dac734bab30d67bbd84b3.zip
Allow `iced_wgpu` to render to any `TextureView`
Diffstat (limited to 'wgpu/src/window/swap_chain.rs')
-rw-r--r--wgpu/src/window/swap_chain.rs49
1 files changed, 49 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..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,
+ },
+ )
+}