summaryrefslogtreecommitdiffstats
path: root/wgpu/src/layer.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--wgpu/src/layer.rs (renamed from graphics/src/layer.rs)180
1 files changed, 97 insertions, 83 deletions
diff --git a/graphics/src/layer.rs b/wgpu/src/layer.rs
index 1d453caa..b8f32db1 100644
--- a/graphics/src/layer.rs
+++ b/wgpu/src/layer.rs
@@ -1,19 +1,21 @@
//! Organize rendering primitives into a flattened list of layers.
mod image;
-mod quad;
mod text;
pub mod mesh;
pub use image::Image;
pub use mesh::Mesh;
-pub use quad::Quad;
pub use text::Text;
-use crate::alignment;
-use crate::{
- Background, Font, Point, Primitive, Rectangle, Size, Vector, Viewport,
-};
+use crate::core;
+use crate::core::alignment;
+use crate::core::{Color, Font, Point, Rectangle, Size, Vector};
+use crate::graphics;
+use crate::graphics::color;
+use crate::graphics::Viewport;
+use crate::primitive::{self, Primitive};
+use crate::quad::{self, Quad};
/// A group of primitives that should be clipped together.
#[derive(Debug)]
@@ -22,7 +24,7 @@ pub struct Layer<'a> {
pub bounds: Rectangle,
/// The quads of the [`Layer`].
- pub quads: Vec<Quad>,
+ pub quads: quad::Batch,
/// The triangle meshes of the [`Layer`].
pub meshes: Vec<Mesh<'a>>,
@@ -39,7 +41,7 @@ impl<'a> Layer<'a> {
pub fn new(bounds: Rectangle) -> Self {
Self {
bounds,
- quads: Vec::new(),
+ quads: quad::Batch::default(),
meshes: Vec::new(),
text: Vec::new(),
images: Vec::new(),
@@ -60,18 +62,20 @@ impl<'a> Layer<'a> {
Point::new(11.0, 11.0 + 25.0 * i as f32),
Size::INFINITY,
),
- color: [0.9, 0.9, 0.9, 1.0],
+ color: Color::new(0.9, 0.9, 0.9, 1.0),
size: 20.0,
- font: Font::Default,
+ line_height: core::text::LineHeight::default(),
+ font: Font::MONOSPACE,
horizontal_alignment: alignment::Horizontal::Left,
vertical_alignment: alignment::Vertical::Top,
+ shaping: core::text::Shaping::Basic,
};
overlay.text.push(text);
overlay.text.push(Text {
bounds: text.bounds + Vector::new(-1.0, -1.0),
- color: [0.0, 0.0, 0.0, 1.0],
+ color: Color::BLACK,
..text
});
}
@@ -109,26 +113,16 @@ impl<'a> Layer<'a> {
current_layer: usize,
) {
match primitive {
- Primitive::None => {}
- Primitive::Group { primitives } => {
- // TODO: Inspect a bit and regroup (?)
- for primitive in primitives {
- Self::process_primitive(
- layers,
- translation,
- primitive,
- current_layer,
- )
- }
- }
Primitive::Text {
content,
bounds,
size,
+ line_height,
color,
font,
horizontal_alignment,
vertical_alignment,
+ shaping,
} => {
let layer = &mut layers[current_layer];
@@ -136,10 +130,12 @@ impl<'a> Layer<'a> {
content,
bounds: *bounds + translation,
size: *size,
- color: color.into_linear(),
+ line_height: *line_height,
+ color: *color,
font: *font,
horizontal_alignment: *horizontal_alignment,
vertical_alignment: *vertical_alignment,
+ shaping: *shaping,
});
}
Primitive::Quad {
@@ -151,58 +147,49 @@ impl<'a> Layer<'a> {
} => {
let layer = &mut layers[current_layer];
- // TODO: Move some of these computations to the GPU (?)
- layer.quads.push(Quad {
+ let quad = Quad {
position: [
bounds.x + translation.x,
bounds.y + translation.y,
],
size: [bounds.width, bounds.height],
- color: match background {
- Background::Color(color) => color.into_linear(),
- },
+ border_color: color::pack(*border_color),
border_radius: *border_radius,
border_width: *border_width,
- border_color: border_color.into_linear(),
- });
+ };
+
+ layer.quads.add(quad, background);
}
- Primitive::SolidMesh { buffers, size } => {
+ Primitive::Image { handle, bounds } => {
let layer = &mut layers[current_layer];
- let bounds = Rectangle::new(
- Point::new(translation.x, translation.y),
- *size,
- );
-
- // Only draw visible content
- if let Some(clip_bounds) = layer.bounds.intersection(&bounds) {
- layer.meshes.push(Mesh::Solid {
- origin: Point::new(translation.x, translation.y),
- buffers,
- clip_bounds,
- });
- }
+ layer.images.push(Image::Raster {
+ handle: handle.clone(),
+ bounds: *bounds + translation,
+ });
}
- Primitive::GradientMesh {
- buffers,
- size,
- gradient,
+ Primitive::Svg {
+ handle,
+ color,
+ bounds,
} => {
let layer = &mut layers[current_layer];
- let bounds = Rectangle::new(
- Point::new(translation.x, translation.y),
- *size,
- );
-
- // Only draw visible content
- if let Some(clip_bounds) = layer.bounds.intersection(&bounds) {
- layer.meshes.push(Mesh::Gradient {
- origin: Point::new(translation.x, translation.y),
- buffers,
- clip_bounds,
- gradient,
- });
+ layer.images.push(Image::Vector {
+ handle: handle.clone(),
+ color: *color,
+ bounds: *bounds + translation,
+ });
+ }
+ Primitive::Group { primitives } => {
+ // TODO: Inspect a bit and regroup (?)
+ for primitive in primitives {
+ Self::process_primitive(
+ layers,
+ translation,
+ primitive,
+ current_layer,
+ )
}
}
Primitive::Clip { bounds, content } => {
@@ -235,35 +222,62 @@ impl<'a> Layer<'a> {
current_layer,
);
}
- Primitive::Cached { cache } => {
+ Primitive::Cache { content } => {
Self::process_primitive(
layers,
translation,
- cache,
+ content,
current_layer,
);
}
- Primitive::Image { handle, bounds } => {
- let layer = &mut layers[current_layer];
+ Primitive::Custom(custom) => match custom {
+ primitive::Custom::Mesh(mesh) => match mesh {
+ graphics::Mesh::Solid { buffers, size } => {
+ let layer = &mut layers[current_layer];
- layer.images.push(Image::Raster {
- handle: handle.clone(),
- bounds: *bounds + translation,
- });
- }
- Primitive::Svg {
- handle,
- color,
- bounds,
- } => {
- let layer = &mut layers[current_layer];
+ let bounds = Rectangle::new(
+ Point::new(translation.x, translation.y),
+ *size,
+ );
- layer.images.push(Image::Vector {
- handle: handle.clone(),
- color: *color,
- bounds: *bounds + translation,
- });
- }
+ // Only draw visible content
+ if let Some(clip_bounds) =
+ layer.bounds.intersection(&bounds)
+ {
+ layer.meshes.push(Mesh::Solid {
+ origin: Point::new(
+ translation.x,
+ translation.y,
+ ),
+ buffers,
+ clip_bounds,
+ });
+ }
+ }
+ graphics::Mesh::Gradient { buffers, size } => {
+ let layer = &mut layers[current_layer];
+
+ let bounds = Rectangle::new(
+ Point::new(translation.x, translation.y),
+ *size,
+ );
+
+ // Only draw visible content
+ if let Some(clip_bounds) =
+ layer.bounds.intersection(&bounds)
+ {
+ layer.meshes.push(Mesh::Gradient {
+ origin: Point::new(
+ translation.x,
+ translation.y,
+ ),
+ buffers,
+ clip_bounds,
+ });
+ }
+ }
+ },
+ },
}
}
}