diff options
author | 2023-05-26 10:07:52 -0700 | |
---|---|---|
committer | 2023-05-26 10:13:18 -0700 | |
commit | 902e333148a1ceed85aba36262a849aaed8d3ac9 (patch) | |
tree | d1b0db241d1f693798ca4dce4d19728d413454fb /wgpu | |
parent | 413526ad09d006853eb9659efabee168f4a0e0a4 (diff) | |
download | iced-902e333148a1ceed85aba36262a849aaed8d3ac9.tar.gz iced-902e333148a1ceed85aba36262a849aaed8d3ac9.tar.bz2 iced-902e333148a1ceed85aba36262a849aaed8d3ac9.zip |
Changed gradient::Packed to be `repr(C)` for direct gpu upload.
Diffstat (limited to 'wgpu')
-rw-r--r-- | wgpu/src/geometry.rs | 4 | ||||
-rw-r--r-- | wgpu/src/layer.rs | 28 | ||||
-rw-r--r-- | wgpu/src/layer/quad.rs | 4 |
3 files changed, 20 insertions, 16 deletions
diff --git a/wgpu/src/geometry.rs b/wgpu/src/geometry.rs index f3fed7ae..740ec20c 100644 --- a/wgpu/src/geometry.rs +++ b/wgpu/src/geometry.rs @@ -505,7 +505,7 @@ impl tessellation::FillVertexConstructor<primitive::GradientVertex2D> primitive::GradientVertex2D { position: [position.x, position.y], - gradient: self.gradient.data, + gradient: self.gradient, } } } @@ -521,7 +521,7 @@ impl tessellation::StrokeVertexConstructor<primitive::GradientVertex2D> primitive::GradientVertex2D { position: [position.x, position.y], - gradient: self.gradient.data, + gradient: self.gradient, } } } diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs index 980d807b..9d7f9f2a 100644 --- a/wgpu/src/layer.rs +++ b/wgpu/src/layer.rs @@ -13,6 +13,7 @@ pub use text::Text; use crate::core; use crate::core::alignment; use crate::core::{Background, Color, Font, Point, Rectangle, Size, Vector}; +use crate::graphics::gradient; use crate::graphics::{Primitive, Viewport}; /// A group of primitives that should be clipped together. @@ -312,30 +313,33 @@ impl<'a> Layer<'a> { } /// Packs the [`Gradient`] for use in shader code. -fn pack_gradient(gradient: &core::Gradient, bounds: Rectangle) -> [f32; 44] { +fn pack_gradient( + gradient: &core::Gradient, + bounds: Rectangle, +) -> gradient::Packed { match gradient { core::Gradient::Linear(linear) => { - let mut pack: [f32; 44] = [0.0; 44]; + let mut data: [f32; 44] = [0.0; 44]; for (index, stop) in linear.stops.iter().enumerate() { let [r, g, b, a] = stop.map_or(Color::default(), |s| s.color).into_linear(); - pack[index * 4] = r; - pack[(index * 4) + 1] = g; - pack[(index * 4) + 2] = b; - pack[(index * 4) + 3] = a; - pack[32 + index] = stop.map_or(2.0, |s| s.offset); + data[index * 4] = r; + data[(index * 4) + 1] = g; + data[(index * 4) + 2] = b; + data[(index * 4) + 3] = a; + data[32 + index] = stop.map_or(2.0, |s| s.offset); } let (start, end) = linear.angle.to_distance(&bounds); - pack[40] = start.x; - pack[41] = start.y; - pack[42] = end.x; - pack[43] = end.y; + data[40] = start.x; + data[41] = start.y; + data[42] = end.x; + data[43] = end.y; - pack + data.into() } } } 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, |