Lyon Tessellation
This crate implements tools to compute the tessellation of 2d paths fill and stroke operations, in order to render them efficiently on the GPU.
Overview
The most interesting types and traits of this crate are:
- FillTessellator - Tessellator for complex path fill operations.
- StrokeTessellator - Tessellator for complex path stroke operations.
GeometryBuilder
- (See the documentation of the geometry_builder module) Which the above two are built on. This trait provides an interface for types that help with building and assembling the vertices and triangles that form the tessellation, usually in the form of arbitrary vertex and index buffers.- The various specialised tessellators in the
basic_shapes
modules.
The tessellation pipeline
The figure above shows each step of the fill tessellation pipeline.
Tessellating strokes works the same way using StrokeVertex
instead of FillVertex
.
The input: iterators
The path tessellators are not tied to a particular data structure. Instead they consume iterators of flattened path events. A Path struct in the crate lyon_path is provided for convenience (but is optional).
The output: geometry builders
The tessellators are parametrized over a type implementing the GeometryBuilder trait. This trait provides some simple methods to add vertices and triangles, without enforcing any particular representation for the resulting geometry. This is important because each application will usually want to work with its own vertex type tailored a certain rendering model.
Each application will implement the GeometryBuilder<Point>
trait in order to
generate vertex buffers and index buffers any type of vertex they want taking a 2d Point
as input for each vertex.
The structs VertexBuffers and
geometry_buider::BuffersBuilder are provided
for convenience. VertexBuffers<T>
is contains a Vec<T>
for the vertices and a Vec<u16>
for the indices.
BuffersBuilder
is generic over a VertexConstructor<InputVertex, OutputVertex>
trait which
creates the application's output vertices from the tessellator input vertices (either FillVertex
or StrokeVertex
).
Flattening and tolerance
Most tessellators in this crate currently operate on flattened paths (paths or shapes represented
by sequences of line segments). when paths contain bézier curves or arcs, the latter need to be
approximated with sequences of line segments. This approximation depends on a tolerance
parameter
which represents the maximum distance between a curve and its flattened approximation.
More explanaion about flattening and tolerance in the lyon_bezier crate.