Changed tesselation functions to take Vertex2D builder instead of using lyon's builtin Point type to avoid extra copies.
This commit is contained in:
parent
cb7c467654
commit
f4878a1a66
1 changed files with 31 additions and 17 deletions
|
|
@ -9,7 +9,6 @@ use crate::Primitive;
|
||||||
use crate::layer::mesh;
|
use crate::layer::mesh;
|
||||||
use crate::triangle::Vertex2D;
|
use crate::triangle::Vertex2D;
|
||||||
use lyon::tessellation;
|
use lyon::tessellation;
|
||||||
use lyon::tessellation::geometry_builder::Positions;
|
|
||||||
|
|
||||||
/// The frame of a [`Canvas`].
|
/// The frame of a [`Canvas`].
|
||||||
///
|
///
|
||||||
|
|
@ -17,10 +16,7 @@ use lyon::tessellation::geometry_builder::Positions;
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct Frame {
|
pub struct Frame {
|
||||||
size: Size,
|
size: Size,
|
||||||
buffers: Vec<(
|
buffers: Vec<(tessellation::VertexBuffers<Vertex2D, u32>, mesh::Style)>,
|
||||||
tessellation::VertexBuffers<lyon::math::Point, u32>,
|
|
||||||
mesh::Style,
|
|
||||||
)>,
|
|
||||||
primitives: Vec<Primitive>,
|
primitives: Vec<Primitive>,
|
||||||
transforms: Transforms,
|
transforms: Transforms,
|
||||||
fill_tessellator: tessellation::FillTessellator,
|
fill_tessellator: tessellation::FillTessellator,
|
||||||
|
|
@ -93,7 +89,7 @@ impl Frame {
|
||||||
let mut buf = tessellation::VertexBuffers::new();
|
let mut buf = tessellation::VertexBuffers::new();
|
||||||
|
|
||||||
let mut buffers =
|
let mut buffers =
|
||||||
tessellation::BuffersBuilder::new(&mut buf, Positions);
|
tessellation::BuffersBuilder::new(&mut buf, Vertex2DBuilder);
|
||||||
|
|
||||||
let options =
|
let options =
|
||||||
tessellation::FillOptions::default().with_fill_rule(rule.into());
|
tessellation::FillOptions::default().with_fill_rule(rule.into());
|
||||||
|
|
@ -131,7 +127,7 @@ impl Frame {
|
||||||
let mut buf = tessellation::VertexBuffers::new();
|
let mut buf = tessellation::VertexBuffers::new();
|
||||||
|
|
||||||
let mut buffers =
|
let mut buffers =
|
||||||
tessellation::BuffersBuilder::new(&mut buf, Positions);
|
tessellation::BuffersBuilder::new(&mut buf, Vertex2DBuilder);
|
||||||
|
|
||||||
let top_left =
|
let top_left =
|
||||||
self.transforms.current.raw.transform_point(
|
self.transforms.current.raw.transform_point(
|
||||||
|
|
@ -165,7 +161,7 @@ impl Frame {
|
||||||
let mut buf = tessellation::VertexBuffers::new();
|
let mut buf = tessellation::VertexBuffers::new();
|
||||||
|
|
||||||
let mut buffers =
|
let mut buffers =
|
||||||
tessellation::BuffersBuilder::new(&mut buf, Positions);
|
tessellation::BuffersBuilder::new(&mut buf, Vertex2DBuilder);
|
||||||
|
|
||||||
let mut options = tessellation::StrokeOptions::default();
|
let mut options = tessellation::StrokeOptions::default();
|
||||||
options.line_width = stroke.width;
|
options.line_width = stroke.width;
|
||||||
|
|
@ -342,7 +338,7 @@ impl Frame {
|
||||||
if !buffer.indices.is_empty() {
|
if !buffer.indices.is_empty() {
|
||||||
self.primitives.push(Primitive::Mesh2D {
|
self.primitives.push(Primitive::Mesh2D {
|
||||||
buffers: triangle::Mesh2D {
|
buffers: triangle::Mesh2D {
|
||||||
vertices: vertices_from(buffer.vertices),
|
vertices: buffer.vertices,
|
||||||
indices: buffer.indices,
|
indices: buffer.indices,
|
||||||
},
|
},
|
||||||
size: self.size,
|
size: self.size,
|
||||||
|
|
@ -355,12 +351,30 @@ impl Frame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts from [`lyon::math::Point`] to [`Vertex2D`]. Used for generating primitives.
|
struct Vertex2DBuilder;
|
||||||
fn vertices_from(points: Vec<lyon::math::Point>) -> Vec<Vertex2D> {
|
|
||||||
points
|
impl tessellation::FillVertexConstructor<Vertex2D> for Vertex2DBuilder {
|
||||||
.iter()
|
fn new_vertex(
|
||||||
.map(|p| Vertex2D {
|
&mut self,
|
||||||
position: [p.x, p.y],
|
vertex: tessellation::FillVertex<'_>,
|
||||||
})
|
) -> Vertex2D {
|
||||||
.collect()
|
let position = vertex.position();
|
||||||
|
|
||||||
|
Vertex2D {
|
||||||
|
position: [position.x, position.y],
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl tessellation::StrokeVertexConstructor<Vertex2D> for Vertex2DBuilder {
|
||||||
|
fn new_vertex(
|
||||||
|
&mut self,
|
||||||
|
vertex: tessellation::StrokeVertex<'_, '_>,
|
||||||
|
) -> Vertex2D {
|
||||||
|
let position = vertex.position();
|
||||||
|
|
||||||
|
Vertex2D {
|
||||||
|
position: [position.x, position.y],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue