diff options
author | 2020-07-08 11:44:40 +0200 | |
---|---|---|
committer | 2020-07-08 11:44:40 +0200 | |
commit | f3dfaa2c43bad16fc91660b2b73cb9173549e7ec (patch) | |
tree | 353365f4dd1e3136bc651ac8c1572f62fff1304b /wgpu | |
parent | 072ec69d53d2708d8fd1693151bcec7305efccf8 (diff) | |
parent | 5c4f5ae5ecb36703a95cafb2cd58692529c9466d (diff) | |
download | iced-f3dfaa2c43bad16fc91660b2b73cb9173549e7ec.tar.gz iced-f3dfaa2c43bad16fc91660b2b73cb9173549e7ec.tar.bz2 iced-f3dfaa2c43bad16fc91660b2b73cb9173549e7ec.zip |
Merge branch 'master' into feature/pane-grid-titlebar
Diffstat (limited to 'wgpu')
-rw-r--r-- | wgpu/src/backend.rs | 8 | ||||
-rw-r--r-- | wgpu/src/lib.rs | 2 | ||||
-rw-r--r-- | wgpu/src/settings.rs | 6 | ||||
-rw-r--r-- | wgpu/src/triangle.rs | 38 | ||||
-rw-r--r-- | wgpu/src/widget/slider.rs | 2 | ||||
-rw-r--r-- | wgpu/src/window/compositor.rs | 17 |
6 files changed, 57 insertions, 16 deletions
diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs index 9ed4438b..a25f42f7 100644 --- a/wgpu/src/backend.rs +++ b/wgpu/src/backend.rs @@ -24,6 +24,8 @@ pub struct Backend { #[cfg(any(feature = "image", feature = "svg"))] image_pipeline: image::Pipeline, + + default_text_size: u16, } impl Backend { @@ -50,6 +52,8 @@ impl Backend { #[cfg(any(feature = "image", feature = "svg"))] image_pipeline, + + default_text_size: settings.default_text_size, } } @@ -245,6 +249,10 @@ impl backend::Text for Backend { const ICON_FONT: Font = font::ICONS; const CHECKMARK_ICON: char = font::CHECKMARK_ICON; + fn default_size(&self) -> u16 { + self.default_text_size + } + fn measure( &self, contents: &str, diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index e67221c7..e51a225c 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -36,7 +36,7 @@ mod backend; mod quad; mod text; -pub use iced_graphics::{Antialiasing, Defaults, Primitive, Viewport}; +pub use iced_graphics::{Antialiasing, Color, Defaults, Primitive, Viewport}; pub use wgpu; pub use backend::Backend; diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs index 4655e64f..bc146c4c 100644 --- a/wgpu/src/settings.rs +++ b/wgpu/src/settings.rs @@ -16,6 +16,11 @@ pub struct Settings { /// If `None` is provided, a default system font will be chosen. pub default_font: Option<&'static [u8]>, + /// The default size of text. + /// + /// By default, it will be set to 20. + pub default_text_size: u16, + /// The antialiasing strategy that will be used for triangle primitives. pub antialiasing: Option<Antialiasing>, } @@ -25,6 +30,7 @@ impl Default for Settings { Settings { format: wgpu::TextureFormat::Bgra8UnormSrgb, default_font: None, + default_text_size: 20, antialiasing: None, } } diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index fe2388a3..2744c67a 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -16,6 +16,7 @@ const INDEX_BUFFER_SIZE: usize = 10_000; pub(crate) struct Pipeline { pipeline: wgpu::RenderPipeline, blit: Option<msaa::Blit>, + constants_layout: wgpu::BindGroupLayout, constants: wgpu::BindGroup, uniforms_buffer: Buffer<Uniforms>, vertex_buffer: Buffer<Vertex2D>, @@ -50,8 +51,10 @@ impl<T> Buffer<T> { } } - pub fn ensure_capacity(&mut self, device: &wgpu::Device, size: usize) { - if self.size < size { + pub fn expand(&mut self, device: &wgpu::Device, size: usize) -> bool { + let needs_resize = self.size < size; + + if needs_resize { self.raw = device.create_buffer(&wgpu::BufferDescriptor { label: None, size: (std::mem::size_of::<T>() * size) as u64, @@ -60,6 +63,8 @@ impl<T> Buffer<T> { self.size = size; } + + needs_resize } } @@ -69,7 +74,7 @@ impl Pipeline { format: wgpu::TextureFormat, antialiasing: Option<settings::Antialiasing>, ) -> Pipeline { - let constant_layout = + let constants_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { label: None, bindings: &[wgpu::BindGroupLayoutEntry { @@ -88,7 +93,7 @@ impl Pipeline { let constant_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { label: None, - layout: &constant_layout, + layout: &constants_layout, bindings: &[wgpu::Binding { binding: 0, resource: wgpu::BindingResource::Buffer { @@ -100,7 +105,7 @@ impl Pipeline { let layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - bind_group_layouts: &[&constant_layout], + bind_group_layouts: &[&constants_layout], }); let vs = include_bytes!("shader/triangle.vert.spv"); @@ -180,6 +185,7 @@ impl Pipeline { Pipeline { pipeline, blit: antialiasing.map(|a| msaa::Blit::new(device, format, a)), + constants_layout, constants: constant_bind_group, uniforms_buffer: constants_buffer, vertex_buffer: Buffer::new( @@ -220,9 +226,25 @@ impl Pipeline { // Then we ensure the current buffers are big enough, resizing if // necessary - self.uniforms_buffer.ensure_capacity(device, meshes.len()); - self.vertex_buffer.ensure_capacity(device, total_vertices); - self.index_buffer.ensure_capacity(device, total_indices); + let _ = self.vertex_buffer.expand(device, total_vertices); + let _ = self.index_buffer.expand(device, total_indices); + + // If the uniforms buffer is resized, then we need to recreate its + // bind group. + if self.uniforms_buffer.expand(device, meshes.len()) { + self.constants = + device.create_bind_group(&wgpu::BindGroupDescriptor { + label: None, + layout: &self.constants_layout, + bindings: &[wgpu::Binding { + binding: 0, + resource: wgpu::BindingResource::Buffer { + buffer: &self.uniforms_buffer.raw, + range: 0..std::mem::size_of::<Uniforms>() as u64, + }, + }], + }); + } let mut uniforms: Vec<Uniforms> = Vec::with_capacity(meshes.len()); let mut offsets: Vec<( diff --git a/wgpu/src/widget/slider.rs b/wgpu/src/widget/slider.rs index cf036829..3a8c2595 100644 --- a/wgpu/src/widget/slider.rs +++ b/wgpu/src/widget/slider.rs @@ -13,4 +13,4 @@ pub use iced_native::slider::State; /// values. /// /// This is an alias of an `iced_native` slider with an `iced_wgpu::Renderer`. -pub type Slider<'a, Message> = iced_native::Slider<'a, Message, Renderer>; +pub type Slider<'a, T, Message> = iced_native::Slider<'a, T, Message, Renderer>; diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index 8345679a..5bdd34bc 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -1,4 +1,4 @@ -use crate::{Backend, Renderer, Settings}; +use crate::{Backend, Color, Renderer, Settings}; use iced_graphics::Viewport; use iced_native::{futures, mouse}; @@ -103,6 +103,7 @@ impl iced_graphics::window::Compositor for Compositor { renderer: &mut Self::Renderer, swap_chain: &mut Self::SwapChain, viewport: &Viewport, + background_color: Color, output: &<Self::Renderer as iced_native::Renderer>::Output, overlay: &[T], ) -> mouse::Interaction { @@ -118,11 +119,15 @@ impl iced_graphics::window::Compositor for Compositor { resolve_target: None, load_op: wgpu::LoadOp::Clear, store_op: wgpu::StoreOp::Store, - clear_color: wgpu::Color { - r: 1.0, - g: 1.0, - b: 1.0, - a: 1.0, + clear_color: { + let [r, g, b, a] = background_color.into_linear(); + + wgpu::Color { + r: f64::from(r), + g: f64::from(g), + b: f64::from(b), + a: f64::from(a), + } }, }], depth_stencil_attachment: None, |