From 5fd5d1cdf8e5354788dc40729c4565ef377d3bba Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 1 Mar 2023 21:34:26 +0100 Subject: Implement `Canvas` support for `iced_tiny_skia` --- wgpu/src/layer/image.rs | 27 ++++++++++++++ wgpu/src/layer/mesh.rs | 93 +++++++++++++++++++++++++++++++++++++++++++++++++ wgpu/src/layer/quad.rs | 30 ++++++++++++++++ wgpu/src/layer/text.rs | 26 ++++++++++++++ 4 files changed, 176 insertions(+) create mode 100644 wgpu/src/layer/image.rs create mode 100644 wgpu/src/layer/mesh.rs create mode 100644 wgpu/src/layer/quad.rs create mode 100644 wgpu/src/layer/text.rs (limited to 'wgpu/src/layer') diff --git a/wgpu/src/layer/image.rs b/wgpu/src/layer/image.rs new file mode 100644 index 00000000..3eff2397 --- /dev/null +++ b/wgpu/src/layer/image.rs @@ -0,0 +1,27 @@ +use crate::{Color, Rectangle}; + +use iced_native::{image, svg}; + +/// A raster or vector image. +#[derive(Debug, Clone)] +pub enum Image { + /// A raster image. + Raster { + /// The handle of a raster image. + handle: image::Handle, + + /// The bounds of the image. + bounds: Rectangle, + }, + /// A vector image. + Vector { + /// The handle of a vector image. + handle: svg::Handle, + + /// The [`Color`] filter + color: Option, + + /// The bounds of the image. + bounds: Rectangle, + }, +} diff --git a/wgpu/src/layer/mesh.rs b/wgpu/src/layer/mesh.rs new file mode 100644 index 00000000..5c1e41ad --- /dev/null +++ b/wgpu/src/layer/mesh.rs @@ -0,0 +1,93 @@ +//! A collection of triangle primitives. +use crate::primitive; +use crate::{Gradient, Point, Rectangle}; + +/// A mesh of triangles. +#[derive(Debug, Clone, Copy)] +pub enum Mesh<'a> { + /// A mesh of triangles with a solid color. + Solid { + /// The origin of the vertices of the [`Mesh`]. + origin: Point, + + /// The vertex and index buffers of the [`Mesh`]. + buffers: &'a primitive::Mesh2D, + + /// The clipping bounds of the [`Mesh`]. + clip_bounds: Rectangle, + }, + /// A mesh of triangles with a gradient color. + Gradient { + /// The origin of the vertices of the [`Mesh`]. + origin: Point, + + /// The vertex and index buffers of the [`Mesh`]. + buffers: &'a primitive::Mesh2D, + + /// The clipping bounds of the [`Mesh`]. + clip_bounds: Rectangle, + + /// The gradient to apply to the [`Mesh`]. + gradient: &'a Gradient, + }, +} + +impl Mesh<'_> { + /// Returns the origin of the [`Mesh`]. + pub fn origin(&self) -> Point { + match self { + Self::Solid { origin, .. } | Self::Gradient { origin, .. } => { + *origin + } + } + } + + /// Returns the indices of the [`Mesh`]. + pub fn indices(&self) -> &[u32] { + match self { + Self::Solid { buffers, .. } => &buffers.indices, + Self::Gradient { buffers, .. } => &buffers.indices, + } + } + + /// Returns the clip bounds of the [`Mesh`]. + pub fn clip_bounds(&self) -> Rectangle { + match self { + Self::Solid { clip_bounds, .. } + | Self::Gradient { clip_bounds, .. } => *clip_bounds, + } + } +} + +/// The result of counting the attributes of a set of meshes. +#[derive(Debug, Clone, Copy, Default)] +pub struct AttributeCount { + /// The total amount of solid vertices. + pub solid_vertices: usize, + + /// The total amount of gradient vertices. + pub gradient_vertices: usize, + + /// The total amount of indices. + pub indices: usize, +} + +/// Returns the number of total vertices & total indices of all [`Mesh`]es. +pub fn attribute_count_of<'a>(meshes: &'a [Mesh<'a>]) -> AttributeCount { + meshes + .iter() + .fold(AttributeCount::default(), |mut count, mesh| { + match mesh { + Mesh::Solid { buffers, .. } => { + count.solid_vertices += buffers.vertices.len(); + count.indices += buffers.indices.len(); + } + Mesh::Gradient { buffers, .. } => { + count.gradient_vertices += buffers.vertices.len(); + count.indices += buffers.indices.len(); + } + } + + count + }) +} diff --git a/wgpu/src/layer/quad.rs b/wgpu/src/layer/quad.rs new file mode 100644 index 00000000..0d8bde9d --- /dev/null +++ b/wgpu/src/layer/quad.rs @@ -0,0 +1,30 @@ +/// A colored rectangle with a border. +/// +/// This type can be directly uploaded to GPU memory. +#[derive(Debug, Clone, Copy)] +#[repr(C)] +pub struct Quad { + /// The position of the [`Quad`]. + pub position: [f32; 2], + + /// The size of the [`Quad`]. + pub size: [f32; 2], + + /// The color of the [`Quad`], in __linear RGB__. + pub color: [f32; 4], + + /// The border color of the [`Quad`], in __linear RGB__. + pub border_color: [f32; 4], + + /// The border radius of the [`Quad`]. + pub border_radius: [f32; 4], + + /// The border width of the [`Quad`]. + pub border_width: f32, +} + +#[allow(unsafe_code)] +unsafe impl bytemuck::Zeroable for Quad {} + +#[allow(unsafe_code)] +unsafe impl bytemuck::Pod for Quad {} diff --git a/wgpu/src/layer/text.rs b/wgpu/src/layer/text.rs new file mode 100644 index 00000000..38d62616 --- /dev/null +++ b/wgpu/src/layer/text.rs @@ -0,0 +1,26 @@ +use crate::{alignment, Color, Font, Rectangle}; + +/// A paragraph of text. +#[derive(Debug, Clone, Copy)] +pub struct Text<'a> { + /// The content of the [`Text`]. + pub content: &'a str, + + /// The layout bounds of the [`Text`]. + pub bounds: Rectangle, + + /// The color of the [`Text`], in __linear RGB_. + pub color: Color, + + /// The size of the [`Text`]. + pub size: f32, + + /// The font of the [`Text`]. + pub font: Font, + + /// The horizontal alignment of the [`Text`]. + pub horizontal_alignment: alignment::Horizontal, + + /// The vertical alignment of the [`Text`]. + pub vertical_alignment: alignment::Vertical, +} -- cgit From 3a0d34c0240f4421737a6a08761f99d6f8140d02 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 4 Mar 2023 05:37:11 +0100 Subject: Create `iced_widget` subcrate and re-organize the whole codebase --- wgpu/src/layer/image.rs | 6 +++--- wgpu/src/layer/mesh.rs | 4 ++-- wgpu/src/layer/text.rs | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'wgpu/src/layer') diff --git a/wgpu/src/layer/image.rs b/wgpu/src/layer/image.rs index 3eff2397..0de589f8 100644 --- a/wgpu/src/layer/image.rs +++ b/wgpu/src/layer/image.rs @@ -1,6 +1,6 @@ -use crate::{Color, Rectangle}; - -use iced_native::{image, svg}; +use crate::core::image; +use crate::core::svg; +use crate::core::{Color, Rectangle}; /// A raster or vector image. #[derive(Debug, Clone)] diff --git a/wgpu/src/layer/mesh.rs b/wgpu/src/layer/mesh.rs index 5c1e41ad..9dd14391 100644 --- a/wgpu/src/layer/mesh.rs +++ b/wgpu/src/layer/mesh.rs @@ -1,6 +1,6 @@ //! A collection of triangle primitives. -use crate::primitive; -use crate::{Gradient, Point, Rectangle}; +use crate::core::{Gradient, Point, Rectangle}; +use crate::graphics::primitive; /// A mesh of triangles. #[derive(Debug, Clone, Copy)] diff --git a/wgpu/src/layer/text.rs b/wgpu/src/layer/text.rs index 38d62616..fdbdaafb 100644 --- a/wgpu/src/layer/text.rs +++ b/wgpu/src/layer/text.rs @@ -1,4 +1,5 @@ -use crate::{alignment, Color, Font, Rectangle}; +use crate::core::alignment; +use crate::core::{Color, Font, Rectangle}; /// A paragraph of text. #[derive(Debug, Clone, Copy)] -- cgit From 33b5a900197e2798a393d6d9a0834039666eddbb Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 19 Apr 2023 01:19:56 +0200 Subject: Make basic text shaping the default shaping strategy --- wgpu/src/layer/text.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'wgpu/src/layer') diff --git a/wgpu/src/layer/text.rs b/wgpu/src/layer/text.rs index fdbdaafb..d36ff273 100644 --- a/wgpu/src/layer/text.rs +++ b/wgpu/src/layer/text.rs @@ -24,4 +24,14 @@ pub struct Text<'a> { /// The vertical alignment of the [`Text`]. pub vertical_alignment: alignment::Vertical, + + /// Whether the text needs advanced shaping and font fallback. + /// + /// You will need to enable this flag if the text contains a complex + /// script, the font used needs it, and/or multiple fonts in your system + /// may be needed to display all of the glyphs. + /// + /// Advanced shaping is expensive! You should only enable it when + /// necessary. + pub advanced_shape: bool, } -- cgit From 4bd290afe7d81d9aaf7467b3ce91491f6600261a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 19 Apr 2023 02:00:45 +0200 Subject: Introduce `text::Shaping` enum and replace magic boolean --- wgpu/src/layer/text.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'wgpu/src/layer') diff --git a/wgpu/src/layer/text.rs b/wgpu/src/layer/text.rs index d36ff273..665f7188 100644 --- a/wgpu/src/layer/text.rs +++ b/wgpu/src/layer/text.rs @@ -1,4 +1,5 @@ use crate::core::alignment; +use crate::core::text; use crate::core::{Color, Font, Rectangle}; /// A paragraph of text. @@ -25,13 +26,6 @@ pub struct Text<'a> { /// The vertical alignment of the [`Text`]. pub vertical_alignment: alignment::Vertical, - /// Whether the text needs advanced shaping and font fallback. - /// - /// You will need to enable this flag if the text contains a complex - /// script, the font used needs it, and/or multiple fonts in your system - /// may be needed to display all of the glyphs. - /// - /// Advanced shaping is expensive! You should only enable it when - /// necessary. - pub advanced_shape: bool, + /// The shaping strategy of the text. + pub shaping: text::Shaping, } -- cgit From 9499a8f9e6f9971dedfae563cb133232aa3cebc2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 4 May 2023 13:00:16 +0200 Subject: Support configurable `LineHeight` in text widgets --- wgpu/src/layer/text.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'wgpu/src/layer') diff --git a/wgpu/src/layer/text.rs b/wgpu/src/layer/text.rs index 665f7188..ba1bdca8 100644 --- a/wgpu/src/layer/text.rs +++ b/wgpu/src/layer/text.rs @@ -14,9 +14,12 @@ pub struct Text<'a> { /// The color of the [`Text`], in __linear RGB_. pub color: Color, - /// The size of the [`Text`]. + /// The size of the [`Text`] in logical pixels. pub size: f32, + /// The line height of the [`Text`]. + pub line_height: text::LineHeight, + /// The font of the [`Text`]. pub font: Font, -- cgit From 6551a0b2ab6c831dd1d3646ecf55180339275e22 Mon Sep 17 00:00:00 2001 From: Bingus Date: Thu, 11 May 2023 09:12:06 -0700 Subject: Added support for gradients as background variants + other optimizations. --- wgpu/src/layer/mesh.rs | 15 ++++++++++----- wgpu/src/layer/quad.rs | 41 +++++++++++++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 15 deletions(-) (limited to 'wgpu/src/layer') diff --git a/wgpu/src/layer/mesh.rs b/wgpu/src/layer/mesh.rs index 9dd14391..b7dd9a0b 100644 --- a/wgpu/src/layer/mesh.rs +++ b/wgpu/src/layer/mesh.rs @@ -1,5 +1,5 @@ //! A collection of triangle primitives. -use crate::core::{Gradient, Point, Rectangle}; +use crate::core::{Point, Rectangle}; use crate::graphics::primitive; /// A mesh of triangles. @@ -22,13 +22,10 @@ pub enum Mesh<'a> { origin: Point, /// The vertex and index buffers of the [`Mesh`]. - buffers: &'a primitive::Mesh2D, + buffers: &'a primitive::Mesh2D, /// The clipping bounds of the [`Mesh`]. clip_bounds: Rectangle, - - /// The gradient to apply to the [`Mesh`]. - gradient: &'a Gradient, }, } @@ -65,9 +62,15 @@ pub struct AttributeCount { /// The total amount of solid vertices. pub solid_vertices: usize, + /// The total amount of solid meshes. + pub solids: usize, + /// The total amount of gradient vertices. pub gradient_vertices: usize, + /// The total amount of gradient meshes. + pub gradients: usize, + /// The total amount of indices. pub indices: usize, } @@ -79,10 +82,12 @@ pub fn attribute_count_of<'a>(meshes: &'a [Mesh<'a>]) -> AttributeCount { .fold(AttributeCount::default(), |mut count, mesh| { match mesh { Mesh::Solid { buffers, .. } => { + count.solids += 1; count.solid_vertices += buffers.vertices.len(); count.indices += buffers.indices.len(); } Mesh::Gradient { buffers, .. } => { + count.gradients += 1; count.gradient_vertices += buffers.vertices.len(); count.indices += buffers.indices.len(); } diff --git a/wgpu/src/layer/quad.rs b/wgpu/src/layer/quad.rs index 0d8bde9d..9913cfe0 100644 --- a/wgpu/src/layer/quad.rs +++ b/wgpu/src/layer/quad.rs @@ -1,7 +1,9 @@ -/// A colored rectangle with a border. -/// -/// This type can be directly uploaded to GPU memory. -#[derive(Debug, Clone, Copy)] +//! A rectangle with certain styled properties. + +use bytemuck::{Pod, Zeroable}; + +/// The properties of a quad. +#[derive(Clone, Copy, Debug, Pod, Zeroable)] #[repr(C)] pub struct Quad { /// The position of the [`Quad`]. @@ -10,21 +12,40 @@ pub struct Quad { /// The size of the [`Quad`]. pub size: [f32; 2], - /// The color of the [`Quad`], in __linear RGB__. - pub color: [f32; 4], - /// The border color of the [`Quad`], in __linear RGB__. pub border_color: [f32; 4], - /// The border radius of the [`Quad`]. + /// The border radii of the [`Quad`]. pub border_radius: [f32; 4], /// The border width of the [`Quad`]. pub border_width: f32, } +/// A quad filled with a solid color. +#[derive(Clone, Copy, Debug, Pod, Zeroable)] +#[repr(C)] +pub struct Solid { + /// The background color data of the quad. + pub color: [f32; 4], + + /// The [`Quad`] data of the [`Solid`]. + pub quad: Quad, +} + +/// A quad filled with interpolated colors. +#[derive(Clone, Copy, Debug)] +#[repr(C)] +pub struct Gradient { + /// The background gradient data of the quad. + pub gradient: [f32; 44], + + /// The [`Quad`] data of the [`Gradient`]. + pub quad: Quad, +} + #[allow(unsafe_code)] -unsafe impl bytemuck::Zeroable for Quad {} +unsafe impl Pod for Gradient {} #[allow(unsafe_code)] -unsafe impl bytemuck::Pod for Quad {} +unsafe impl Zeroable for Gradient {} -- cgit From 902e333148a1ceed85aba36262a849aaed8d3ac9 Mon Sep 17 00:00:00 2001 From: Bingus Date: Fri, 26 May 2023 10:07:52 -0700 Subject: Changed gradient::Packed to be `repr(C)` for direct gpu upload. --- wgpu/src/layer/quad.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wgpu/src/layer') diff --git a/wgpu/src/layer/quad.rs b/wgpu/src/layer/quad.rs index 9913cfe0..0bf7837a 100644 --- a/wgpu/src/layer/quad.rs +++ b/wgpu/src/layer/quad.rs @@ -1,5 +1,5 @@ //! A rectangle with certain styled properties. - +use crate::graphics::gradient; use bytemuck::{Pod, Zeroable}; /// The properties of a quad. @@ -38,7 +38,7 @@ pub struct Solid { #[repr(C)] pub struct Gradient { /// The background gradient data of the quad. - pub gradient: [f32; 44], + pub gradient: gradient::Packed, /// The [`Quad`] data of the [`Gradient`]. pub quad: Quad, -- cgit From 3f141459a66fe66e6dc25d579d0cda80662f0895 Mon Sep 17 00:00:00 2001 From: Bingus Date: Thu, 25 May 2023 10:27:27 -0700 Subject: Fixed issue where quads of different types were not ordered. --- wgpu/src/layer/quad.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'wgpu/src/layer') diff --git a/wgpu/src/layer/quad.rs b/wgpu/src/layer/quad.rs index 0bf7837a..aaaebd5b 100644 --- a/wgpu/src/layer/quad.rs +++ b/wgpu/src/layer/quad.rs @@ -49,3 +49,12 @@ unsafe impl Pod for Gradient {} #[allow(unsafe_code)] unsafe impl Zeroable for Gradient {} + +#[derive(Debug, Copy, Clone)] +/// The identifier of a quad, used for ordering. +pub enum Order { + /// A solid quad + Solid, + /// A gradient quad + Gradient, +} -- cgit From eb6c663420a28e087c91c39e376db3c294b5aea1 Mon Sep 17 00:00:00 2001 From: Bingus Date: Fri, 26 May 2023 09:55:49 -0700 Subject: Adjusted `Quads` struct to be opaque `quad::Layer`. --- wgpu/src/layer/quad.rs | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) (limited to 'wgpu/src/layer') diff --git a/wgpu/src/layer/quad.rs b/wgpu/src/layer/quad.rs index aaaebd5b..284a7618 100644 --- a/wgpu/src/layer/quad.rs +++ b/wgpu/src/layer/quad.rs @@ -1,4 +1,5 @@ //! A rectangle with certain styled properties. +use crate::core::{Background, Rectangle}; use crate::graphics::gradient; use bytemuck::{Pod, Zeroable}; @@ -58,3 +59,91 @@ pub enum Order { /// A gradient quad Gradient, } + +/// A group of [`Quad`]s rendered together. +#[derive(Default, Debug)] +pub struct Layer { + /// The solid quads of the [`Layer`]. + solids: Vec, + + /// The gradient quads of the [`Layer`]. + gradients: Vec, + + /// The quad order of the [`Layer`]; stored as a tuple of the quad type & its count. + order: Vec<(Order, usize)>, + + /// The last index of quad ordering. + index: usize, +} + +impl Layer { + /// Returns true if there are no quads of any type in [`Quads`]. + pub fn is_empty(&self) -> bool { + self.solids.is_empty() && self.gradients.is_empty() + } + + /// The [`Solid`] quads of the [`Layer`]. + pub fn solids(&self) -> &[Solid] { + &self.solids + } + + /// The [`Gradient`] quads of the [`Layer`]. + pub fn gradients(&self) -> &[Gradient] { + &self.gradients + } + + /// The order of quads within the [`Layer`], grouped by (type, count) for rendering in batches. + pub fn ordering(&self) -> &[(Order, usize)] { + &self.order + } + + /// Adds a [`Quad`] with the provided `Background` type to the quad [`Layer`]. + pub fn add(&mut self, quad: Quad, background: &Background) { + let quad_order = match background { + Background::Color(color) => { + self.solids.push(Solid { + color: color.into_linear(), + quad, + }); + + Order::Solid + } + Background::Gradient(gradient) => { + let quad = Gradient { + gradient: gradient::pack( + gradient, + Rectangle::new(quad.position.into(), quad.size.into()), + ), + quad, + }; + + self.gradients.push(quad); + Order::Gradient + } + }; + + match (self.order.get_mut(self.index), quad_order) { + (Some((quad_order, count)), Order::Solid) => match quad_order { + Order::Solid => { + *count += 1; + } + Order::Gradient => { + self.order.push((Order::Solid, 1)); + self.index += 1; + } + }, + (Some((quad_order, count)), Order::Gradient) => match quad_order { + Order::Solid => { + self.order.push((Order::Gradient, 1)); + self.index += 1; + } + Order::Gradient => { + *count += 1; + } + }, + (None, _) => { + self.order.push((quad_order, 1)); + } + } + } +} -- cgit From fe9da174cafffbd77eb351c51ba017cf039a4cf4 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 30 May 2023 00:56:52 +0200 Subject: Move `layer::quad` types to `quad` module Not sure why I split these to begin with! --- wgpu/src/layer/quad.rs | 149 ------------------------------------------------- 1 file changed, 149 deletions(-) delete mode 100644 wgpu/src/layer/quad.rs (limited to 'wgpu/src/layer') diff --git a/wgpu/src/layer/quad.rs b/wgpu/src/layer/quad.rs deleted file mode 100644 index 284a7618..00000000 --- a/wgpu/src/layer/quad.rs +++ /dev/null @@ -1,149 +0,0 @@ -//! A rectangle with certain styled properties. -use crate::core::{Background, Rectangle}; -use crate::graphics::gradient; -use bytemuck::{Pod, Zeroable}; - -/// The properties of a quad. -#[derive(Clone, Copy, Debug, Pod, Zeroable)] -#[repr(C)] -pub struct Quad { - /// The position of the [`Quad`]. - pub position: [f32; 2], - - /// The size of the [`Quad`]. - pub size: [f32; 2], - - /// The border color of the [`Quad`], in __linear RGB__. - pub border_color: [f32; 4], - - /// The border radii of the [`Quad`]. - pub border_radius: [f32; 4], - - /// The border width of the [`Quad`]. - pub border_width: f32, -} - -/// A quad filled with a solid color. -#[derive(Clone, Copy, Debug, Pod, Zeroable)] -#[repr(C)] -pub struct Solid { - /// The background color data of the quad. - pub color: [f32; 4], - - /// The [`Quad`] data of the [`Solid`]. - pub quad: Quad, -} - -/// A quad filled with interpolated colors. -#[derive(Clone, Copy, Debug)] -#[repr(C)] -pub struct Gradient { - /// The background gradient data of the quad. - pub gradient: gradient::Packed, - - /// The [`Quad`] data of the [`Gradient`]. - pub quad: Quad, -} - -#[allow(unsafe_code)] -unsafe impl Pod for Gradient {} - -#[allow(unsafe_code)] -unsafe impl Zeroable for Gradient {} - -#[derive(Debug, Copy, Clone)] -/// The identifier of a quad, used for ordering. -pub enum Order { - /// A solid quad - Solid, - /// A gradient quad - Gradient, -} - -/// A group of [`Quad`]s rendered together. -#[derive(Default, Debug)] -pub struct Layer { - /// The solid quads of the [`Layer`]. - solids: Vec, - - /// The gradient quads of the [`Layer`]. - gradients: Vec, - - /// The quad order of the [`Layer`]; stored as a tuple of the quad type & its count. - order: Vec<(Order, usize)>, - - /// The last index of quad ordering. - index: usize, -} - -impl Layer { - /// Returns true if there are no quads of any type in [`Quads`]. - pub fn is_empty(&self) -> bool { - self.solids.is_empty() && self.gradients.is_empty() - } - - /// The [`Solid`] quads of the [`Layer`]. - pub fn solids(&self) -> &[Solid] { - &self.solids - } - - /// The [`Gradient`] quads of the [`Layer`]. - pub fn gradients(&self) -> &[Gradient] { - &self.gradients - } - - /// The order of quads within the [`Layer`], grouped by (type, count) for rendering in batches. - pub fn ordering(&self) -> &[(Order, usize)] { - &self.order - } - - /// Adds a [`Quad`] with the provided `Background` type to the quad [`Layer`]. - pub fn add(&mut self, quad: Quad, background: &Background) { - let quad_order = match background { - Background::Color(color) => { - self.solids.push(Solid { - color: color.into_linear(), - quad, - }); - - Order::Solid - } - Background::Gradient(gradient) => { - let quad = Gradient { - gradient: gradient::pack( - gradient, - Rectangle::new(quad.position.into(), quad.size.into()), - ), - quad, - }; - - self.gradients.push(quad); - Order::Gradient - } - }; - - match (self.order.get_mut(self.index), quad_order) { - (Some((quad_order, count)), Order::Solid) => match quad_order { - Order::Solid => { - *count += 1; - } - Order::Gradient => { - self.order.push((Order::Solid, 1)); - self.index += 1; - } - }, - (Some((quad_order, count)), Order::Gradient) => match quad_order { - Order::Solid => { - self.order.push((Order::Gradient, 1)); - self.index += 1; - } - Order::Gradient => { - *count += 1; - } - }, - (None, _) => { - self.order.push((quad_order, 1)); - } - } - } -} -- cgit From fa5650cfd1115e6ccec2ad795cf58fd970d5b43c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 29 Jun 2023 07:48:03 +0200 Subject: Decouple `Mesh` primitives from main `Primitive` type --- wgpu/src/layer/mesh.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'wgpu/src/layer') diff --git a/wgpu/src/layer/mesh.rs b/wgpu/src/layer/mesh.rs index b7dd9a0b..7c6206cd 100644 --- a/wgpu/src/layer/mesh.rs +++ b/wgpu/src/layer/mesh.rs @@ -1,6 +1,6 @@ //! A collection of triangle primitives. use crate::core::{Point, Rectangle}; -use crate::graphics::primitive; +use crate::graphics::mesh; /// A mesh of triangles. #[derive(Debug, Clone, Copy)] @@ -11,7 +11,7 @@ pub enum Mesh<'a> { origin: Point, /// The vertex and index buffers of the [`Mesh`]. - buffers: &'a primitive::Mesh2D, + buffers: &'a mesh::Indexed, /// The clipping bounds of the [`Mesh`]. clip_bounds: Rectangle, @@ -22,7 +22,7 @@ pub enum Mesh<'a> { origin: Point, /// The vertex and index buffers of the [`Mesh`]. - buffers: &'a primitive::Mesh2D, + buffers: &'a mesh::Indexed, /// The clipping bounds of the [`Mesh`]. clip_bounds: Rectangle, -- cgit