lyon 0.4.0

2D Graphics rendering experiments.
Documentation

Lyon

GPU-based 2D graphics rendering in rust.

Motivation

For now the goal is to provide efficient SVG-compliant path tessellation tools to help with rendering vector graphics on the GPU. If things go well the project could eventually grow into including a (partial) SVG renderer in a separate crate, but for now think of this library as a way to turn complex paths into triangles for use in your own rendering engine.

The intent is for this library to be useful in projects like Servo and games.

Example

    // Build a Path.
    let mut builder = SvgPathBuilder::new(Path::builder());
    builder.move_to(point(0.0, 0.0));
    builder.line_to(point(1.0, 0.0));
    builder.quadratic_bezier_to(point(2.0, 0.0), point(2.0, 1.0));
    builder.cubic_bezier_to(point(1.0, 1.0), point(0.0, 1.0), point(0.0, 0.0));
    builder.close();
    let path = builder.build();

    // Will contain the result of the tessellation.
    let mut geometry_cpu: VertexBuffers<Vec2> = VertexBuffers::new();

    let mut tessellator = FillTessellator::new();

    {
        // The simple builder uses the tessellator's vertex type.
        // You can implement the GeometryBuilder trait to create custom vertices.
        let mut vertex_builder = simple_builder(&mut geometry_cpu);

        // Compute the tessellation.
        tessellator.tessellate_path(
            path.path_iter().flattened(0.1),
            &FillOptions::default(),
            &mut vertex_builder
        ).unwrap();
    }

    // The tessellated geometry is ready to be uploaded to the GPU.
    println!(" -- {} vertices {} indices",
        geometry_cpu.vertices.len(),
        geometry_cpu.indices.len()
    );

Documentation

Structure

The project is split into small crates:

  • lyon (documentation): A meta-crate that imports the other crates.
  • lyon_tessellator (documentation): The tessellation routines (where most of the focus is for now).
  • lyon_path_iterator (documentation): A set of iterator abstractions over vector paths.
  • lyon_path_builder (documentation): Tools to build paths.
  • lyon_path (documentation): A simple vector path data structure provided for convenience, but not required by the other crates.
  • lyon_bezier (documentation): 2d quadratic and cubic bezier curve maths, including an efficient flattening algorithm.
  • lyon_core (documentation): Contains types common to most lyon crates.
  • lyon_extra (documentation): various optional utilities.

There is also a toy command-line tool exposing to tessellate SVG path from your favorite terminal.

Have a look at the gfx-rs example to see how integrating the tessellators in a renderer can look like.

Status

The focus right now is on implementing a SVG compliant path tessellator (rather than an actual SVG render).

  • path
    • bezier curves (through path flattening)
    • SVG 1.1
    • builder API
    • iterator API
  • complex fills
    • fill shape types
      • concave shapes
      • self-intersections
      • holes
    • fill rules
      • even-odd
      • non-zero
    • vertex-aa
    • clip rect
    • stable API
  • complex strokes
    • line caps
      • butt
      • square
      • round
    • line joins
      • miter
      • miter clip
      • round
      • bevel
      • arcs
    • vertex-aa
    • clip rect
    • stable API
  • basic shapes
    • quad
      • fill
      • stroke
    • rectangle
      • fill
      • stroke
    • rounded rectangle
      • fill
      • stroke
    • ellipsis
      • fill
      • stroke
    • convex polygons
      • fill
      • stroke
    • nine-patch
  • path flattening
    • builder
    • iterator
  • testing
    • fill
      • test suite
      • automatic test-case reduction
      • reference testing
      • fuzzing
    • stroke
    • basic shapes

TODO

There are the unticked items above as well as a rough list of things to do. If you are interested in contributing, please let me know on twitter (@nicalsilva) or by e-mail.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.