Skip to content
/ lyon Public
forked from nical/lyon

2D graphics rendering experiments in rust.

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

pizzaiter/lyon

 
 

Repository files navigation

Lyon

GPU-based 2D graphics rendering in rust.

Project logo

crates.io Travis Build Status documentation Gitter Chat

Motivation

For now the goal is to provide efficient SVG-compliant path tessellation tools to help with rendering vector graphics on the GPU. 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_flattened_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()
    );

Structure

The project is split into several crates:

  • crate doc - lyon - A meta-crate that reexports the crates below for convenience.
  • crate doc - lyon_tessellation - Path tessellation routines.
  • crate doc - lyon_path_builder - Tools to facilitate building paths.
  • crate doc - lyon_path_iterator - Tools to facilitate iteratring over paths.
  • crate doc - lyon_path - A simple optional path data structure, provided for convenience.
  • crate doc - lyon_bezier - Cubic and quadratic 2d bézier math.
  • crate doc - lyon_svg - Create paths using SVG's path syntax.
  • crate doc - lyon_extra - Additional testing and debugging tools.
  • crate doc - lyon_core - Common types to most lyon crates (mostly for internal use, reexported by the other crates).

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

Have a look at the basic and advanced gfx-rs examples to see how integrating the tessellators in a renderer can look like.

FAQ

In a nutshell, what is a tessellator?

Tessellators such as the ones provided by lyon take complex shapes as input and generate geometry made of triangles that can be easily consumed by graphics APIs such as OpenGL, Vulkan or D3D.

How do I render an SVG file with lyon?

Lyon is not an SVG renderer. For now lyon mainly provides primitives to tessellate complex path fills and strokes in a way that is convenient to use with GPU APIs such as gfx-rs, glium, OpenGL, D3D, etc. How the tessellated geometry is rendered is completely up to the user of this crate.

How do I render the output of the tessellators?

Although the format of the output of the tessellators is customizable, the algorithms are designed to generate a vertex and an index buffer. See the lyon::tessellation documentaton for more details.

Is anti-aliasing supported?

There is currently no built-in support for anti-aliasing in the tessellators. Anti-aliasing can still be achieved by users of this crate using techniques commonly employed in video games (msaa, taa, fxaa, etc.).

What is left to do before lyon 1.0?

See the 1.0 milestone on the github repository.

I need help!

Don't hesitate to file an issue, ask questions on gitter, or contact @nical by e-mail.

How can I help?

See CONTRIBUTING.md.

License

Licensed under either of

at your option.

Contribution

There is useful information for contributors in the contribution guidelines.

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.

About

2D graphics rendering experiments in rust.

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%