diff options
Diffstat (limited to '')
-rw-r--r-- | wgpu/src/image.rs | 74 | ||||
-rw-r--r-- | wgpu/src/image/atlas.rs (renamed from wgpu/src/texture/atlas.rs) | 0 | ||||
-rw-r--r-- | wgpu/src/image/atlas/allocation.rs (renamed from wgpu/src/texture/atlas/allocation.rs) | 2 | ||||
-rw-r--r-- | wgpu/src/image/atlas/allocator.rs (renamed from wgpu/src/texture/atlas/allocator.rs) | 0 | ||||
-rw-r--r-- | wgpu/src/image/atlas/entry.rs (renamed from wgpu/src/texture/atlas/entry.rs) | 3 | ||||
-rw-r--r-- | wgpu/src/image/atlas/layer.rs (renamed from wgpu/src/texture/atlas/layer.rs) | 2 | ||||
-rw-r--r-- | wgpu/src/image/raster.rs | 2 | ||||
-rw-r--r-- | wgpu/src/image/vector.rs | 2 | ||||
-rw-r--r-- | wgpu/src/lib.rs | 9 | ||||
-rw-r--r-- | wgpu/src/renderer.rs | 103 | ||||
-rw-r--r-- | wgpu/src/texture.rs | 3 |
11 files changed, 114 insertions, 86 deletions
diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index dc19cfbf..d3603676 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -1,18 +1,23 @@ +mod atlas; + #[cfg(feature = "image")] mod raster; + #[cfg(feature = "svg")] mod vector; -use crate::{texture, Transformation}; +use crate::Transformation; +use atlas::Atlas; -use iced_native::{image, svg, Rectangle}; +use iced_native::Rectangle; +use std::cell::RefCell; use std::mem; -#[cfg(any(feature = "image", feature = "svg"))] -use std::cell::RefCell; +#[cfg(feature = "image")] +use iced_native::image; -#[cfg(any(feature = "image", feature = "svg"))] -use crate::texture::atlas; +#[cfg(feature = "svg")] +use iced_native::svg; #[derive(Debug)] pub struct Pipeline { @@ -30,7 +35,7 @@ pub struct Pipeline { texture: wgpu::BindGroup, texture_version: usize, texture_layout: wgpu::BindGroupLayout, - texture_atlas: texture::Atlas, + texture_atlas: Atlas, } impl Pipeline { @@ -216,7 +221,7 @@ impl Pipeline { usage: wgpu::BufferUsage::VERTEX | wgpu::BufferUsage::COPY_DST, }); - let texture_atlas = texture::Atlas::new(device); + let texture_atlas = Atlas::new(device); let texture = device.create_bind_group(&wgpu::BindGroupDescriptor { layout: &texture_layout, @@ -284,33 +289,29 @@ impl Pipeline { for image in images { match &image.handle { - Handle::Raster(_handle) => { - #[cfg(feature = "image")] - { - if let Some(atlas_entry) = raster_cache.upload( - _handle, - device, - encoder, - &mut self.texture_atlas, - ) { - add_instances(image, atlas_entry, instances); - } - }; + #[cfg(feature = "image")] + Handle::Raster(handle) => { + if let Some(atlas_entry) = raster_cache.upload( + handle, + device, + encoder, + &mut self.texture_atlas, + ) { + add_instances(image, atlas_entry, instances); + } } - Handle::Vector(_handle) => { - #[cfg(feature = "svg")] - { - if let Some(atlas_entry) = vector_cache.upload( - _handle, - image.size, - _scale, - device, - encoder, - &mut self.texture_atlas, - ) { - add_instances(image, atlas_entry, instances); - } - }; + #[cfg(feature = "svg")] + Handle::Vector(handle) => { + if let Some(atlas_entry) = vector_cache.upload( + handle, + image.size, + _scale, + device, + encoder, + &mut self.texture_atlas, + ) { + add_instances(image, atlas_entry, instances); + } } } } @@ -432,7 +433,10 @@ pub struct Image { } pub enum Handle { + #[cfg(feature = "image")] Raster(image::Handle), + + #[cfg(feature = "svg")] Vector(svg::Handle), } @@ -479,7 +483,6 @@ struct Uniforms { transform: [f32; 16], } -#[cfg(any(feature = "image", feature = "svg"))] fn add_instances( image: &Image, entry: &atlas::Entry, @@ -516,7 +519,6 @@ fn add_instances( } } -#[cfg(any(feature = "image", feature = "svg"))] #[inline] fn add_instance( position: [f32; 2], diff --git a/wgpu/src/texture/atlas.rs b/wgpu/src/image/atlas.rs index 86a5ff49..86a5ff49 100644 --- a/wgpu/src/texture/atlas.rs +++ b/wgpu/src/image/atlas.rs diff --git a/wgpu/src/texture/atlas/allocation.rs b/wgpu/src/image/atlas/allocation.rs index e17b3f8c..59b7239f 100644 --- a/wgpu/src/texture/atlas/allocation.rs +++ b/wgpu/src/image/atlas/allocation.rs @@ -1,4 +1,4 @@ -use crate::texture::atlas::{self, allocator}; +use crate::image::atlas::{self, allocator}; #[derive(Debug)] pub enum Allocation { diff --git a/wgpu/src/texture/atlas/allocator.rs b/wgpu/src/image/atlas/allocator.rs index 7a4ff5b1..7a4ff5b1 100644 --- a/wgpu/src/texture/atlas/allocator.rs +++ b/wgpu/src/image/atlas/allocator.rs diff --git a/wgpu/src/texture/atlas/entry.rs b/wgpu/src/image/atlas/entry.rs index 2c064665..0310fc54 100644 --- a/wgpu/src/texture/atlas/entry.rs +++ b/wgpu/src/image/atlas/entry.rs @@ -1,4 +1,4 @@ -use crate::texture::atlas; +use crate::image::atlas; #[derive(Debug)] pub enum Entry { @@ -10,6 +10,7 @@ pub enum Entry { } impl Entry { + #[cfg(feature = "image")] pub fn size(&self) -> (u32, u32) { match self { Entry::Contiguous(allocation) => allocation.size(), diff --git a/wgpu/src/texture/atlas/layer.rs b/wgpu/src/image/atlas/layer.rs index b025d8a1..b1084ed9 100644 --- a/wgpu/src/texture/atlas/layer.rs +++ b/wgpu/src/image/atlas/layer.rs @@ -1,4 +1,4 @@ -use crate::texture::atlas::Allocator; +use crate::image::atlas::Allocator; #[derive(Debug)] pub enum Layer { diff --git a/wgpu/src/image/raster.rs b/wgpu/src/image/raster.rs index 883c32f7..3edec57e 100644 --- a/wgpu/src/image/raster.rs +++ b/wgpu/src/image/raster.rs @@ -1,4 +1,4 @@ -use crate::texture::atlas::{self, Atlas}; +use crate::image::atlas::{self, Atlas}; use iced_native::image; use std::collections::{HashMap, HashSet}; diff --git a/wgpu/src/image/vector.rs b/wgpu/src/image/vector.rs index 6b12df54..bae0f82f 100644 --- a/wgpu/src/image/vector.rs +++ b/wgpu/src/image/vector.rs @@ -1,4 +1,4 @@ -use crate::texture::atlas::{self, Atlas}; +use crate::image::atlas::{self, Atlas}; use iced_native::svg; use std::collections::{HashMap, HashSet}; diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index a807b44d..1d63abbf 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -30,13 +30,11 @@ pub mod triangle; pub mod widget; pub mod window; -mod image; mod primitive; mod quad; mod renderer; mod target; mod text; -mod texture; mod transformation; mod viewport; @@ -52,6 +50,11 @@ pub use viewport::Viewport; #[doc(no_inline)] pub use widget::*; -pub(crate) use self::image::Image; pub(crate) use quad::Quad; pub(crate) use transformation::Transformation; + +#[cfg(any(feature = "image", feature = "svg"))] +mod image; + +#[cfg(any(feature = "image", feature = "svg"))] +pub(crate) use self::image::Image; diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs index b5dce480..d9ef9fc4 100644 --- a/wgpu/src/renderer.rs +++ b/wgpu/src/renderer.rs @@ -1,7 +1,11 @@ use crate::{ - image, quad, text, triangle, Defaults, Image, Primitive, Quad, Settings, - Target, Transformation, + quad, text, triangle, Defaults, Primitive, Quad, Settings, Target, + Transformation, }; + +#[cfg(any(feature = "image", feature = "svg"))] +use crate::{image, Image}; + use iced_native::{ layout, Background, Color, Layout, MouseCursor, Point, Rectangle, Vector, Widget, @@ -16,18 +20,22 @@ mod widget; #[derive(Debug)] pub struct Renderer { quad_pipeline: quad::Pipeline, - image_pipeline: image::Pipeline, text_pipeline: text::Pipeline, - triangle_pipeline: crate::triangle::Pipeline, + triangle_pipeline: triangle::Pipeline, + + #[cfg(any(feature = "image", feature = "svg"))] + image_pipeline: image::Pipeline, } struct Layer<'a> { bounds: Rectangle<u32>, offset: Vector<u32>, quads: Vec<Quad>, - images: Vec<Image>, meshes: Vec<(Point, Arc<triangle::Mesh2D>)>, text: Vec<wgpu_glyph::Section<'a>>, + + #[cfg(any(feature = "image", feature = "svg"))] + images: Vec<Image>, } impl<'a> Layer<'a> { @@ -36,9 +44,11 @@ impl<'a> Layer<'a> { bounds, offset, quads: Vec::new(), - images: Vec::new(), text: Vec::new(), meshes: Vec::new(), + + #[cfg(any(feature = "image", feature = "svg"))] + images: Vec::new(), } } } @@ -51,19 +61,22 @@ impl Renderer { let text_pipeline = text::Pipeline::new(device, settings.format, settings.default_font); let quad_pipeline = quad::Pipeline::new(device, settings.format); - let image_pipeline = - crate::image::Pipeline::new(device, settings.format); let triangle_pipeline = triangle::Pipeline::new( device, settings.format, settings.antialiasing, ); + #[cfg(any(feature = "image", feature = "svg"))] + let image_pipeline = image::Pipeline::new(device, settings.format); + Self { quad_pipeline, - image_pipeline, text_pipeline, triangle_pipeline, + + #[cfg(any(feature = "image", feature = "svg"))] + image_pipeline, } } @@ -116,6 +129,7 @@ impl Renderer { ); } + #[cfg(any(feature = "image", feature = "svg"))] self.image_pipeline.trim_cache(); *mouse_cursor @@ -223,20 +237,6 @@ impl Renderer { border_color: border_color.into_linear(), }); } - Primitive::Image { handle, bounds } => { - layer.images.push(Image { - handle: image::Handle::Raster(handle.clone()), - position: [bounds.x, bounds.y], - size: [bounds.width, bounds.height], - }); - } - Primitive::Svg { handle, bounds } => { - layer.images.push(Image { - handle: image::Handle::Vector(handle.clone()), - position: [bounds.x, bounds.y], - size: [bounds.width, bounds.height], - }); - } Primitive::Mesh2D { origin, buffers } => { layer.meshes.push((*origin, buffers.clone())); } @@ -264,6 +264,28 @@ impl Renderer { layers.push(new_layer); } } + + #[cfg(feature = "image")] + Primitive::Image { handle, bounds } => { + layer.images.push(Image { + handle: image::Handle::Raster(handle.clone()), + position: [bounds.x, bounds.y], + size: [bounds.width, bounds.height], + }); + } + #[cfg(not(feature = "image"))] + Primitive::Image { .. } => {} + + #[cfg(feature = "svg")] + Primitive::Svg { handle, bounds } => { + layer.images.push(Image { + handle: image::Handle::Vector(handle.clone()), + position: [bounds.x, bounds.y], + size: [bounds.width, bounds.height], + }); + } + #[cfg(not(feature = "svg"))] + Primitive::Svg { .. } => {} } } @@ -346,23 +368,26 @@ impl Renderer { ); } - if layer.images.len() > 0 { - let translated_and_scaled = transformation - * Transformation::scale(scale_factor, scale_factor) - * Transformation::translate( - -(layer.offset.x as f32), - -(layer.offset.y as f32), + #[cfg(any(feature = "image", feature = "svg"))] + { + if layer.images.len() > 0 { + let translated_and_scaled = transformation + * Transformation::scale(scale_factor, scale_factor) + * Transformation::translate( + -(layer.offset.x as f32), + -(layer.offset.y as f32), + ); + + self.image_pipeline.draw( + device, + encoder, + &layer.images, + translated_and_scaled, + bounds, + target, + scale_factor, ); - - self.image_pipeline.draw( - device, - encoder, - &layer.images, - translated_and_scaled, - bounds, - target, - scale_factor, - ); + } } if layer.text.len() > 0 { diff --git a/wgpu/src/texture.rs b/wgpu/src/texture.rs deleted file mode 100644 index 00b60bfa..00000000 --- a/wgpu/src/texture.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod atlas; - -pub use atlas::Atlas; |