GPU-based 2D graphics rendering tools in Rust using path tessellation.
Crates
This meta-crate (lyon
) reexports the following sub-crates for convenience:
- lyon_tessellation - Path tessellation routines.
- lyon_path - Tools to build and iterate over paths.
- lyon_algorithms - Various 2d path related algorithms.
- lyon_geom - 2d utilities for cubic and quadratic bézier curves, arcs and more.
- lyon_svg - Create paths using SVG's path syntax.
- lyon_extra - Additional testing and debugging tools.
- lyon_tess2 - Alternative fill tessellation implementation using libtess2.
Each lyon_<name>
crate is reexported as a <name>
module in lyon
. For example:
extern crate lyon_tessellation;
use lyon_tessellation::FillTessellator;
Is equivalent to:
extern crate lyon;
use lyon::tessellation::FillTessellator;
Feature flags
serialization using serde can be enabled on each crate using the
serialization
feature flag (disabled by default).
When using the main crate lyon
, the lyon_svg
, lyon_tess2
and
lyon_extra
dependencies are disabled by default. They can be added
with the feature flags svg
, tess2
and extra
.
Additional documentation and links
- wgpu example.
- wgpu_svg example similar to the first example, can render a very small subset of SVG.
- There is some useful documentation on the project's wiki.
- The source code is available on the project's git repository.
- Interested in contributing? Pull requests are welcome. If you would like to help but don't know what to do specifically, have a look at the github issues, some of which are tagged as easy.
Examples
Tessellating a rounded rectangle
The lyon_tessellation
crate provides a collection of tessellation routines
for common shapes such as rectangles and circles. Let's have a look at how
to obtain the fill tessellation a rectangle with rounded corners:
use ;
use ;
use ;
use simple_builder;
Building and tessellating an arbitrary path
extern crate lyon;
use ;
use Path;
use *;
use *;
What is the tolerance variable in these examples?
The tessellator operates on flattened paths (that only contains line segments) so we have to approximate the curves segments with sequences of line segments. To do so we pick a tolerance threshold which is the maximum distance allowed between the curve and its approximation. The documentation of the lyon_geom crate provides more detailed explanations about this tolerance parameter.
Rendering the tessellated geometry
Lyon does not provide with any GPU abstraction or rendering backend (for now). It is up to the user of this crate to decide whether to use OpenGL, vulkan, gfx-rs, wgpu, glium, or any low level graphics API and how to render it. The wgpu example can be used to get an idea of how to render the geometry (in this case using wgpu).