GithubHelp home page GithubHelp logo

ghostofme / lyon Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nical/lyon

0.0 0.0 0.0 4.39 MB

2D graphics rendering on the GPU in rust using path tessellation.

License: Other

Rust 99.95% Shell 0.02% JavaScript 0.03%

lyon's Introduction

Lyon

A path tessellation library written in rust for GPU-based 2D graphics rendering.

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

extern crate lyon;
use lyon::math::point;
use lyon::path::Path;
use lyon::path::builder::*;
use lyon::tessellation::*;

fn main() {
    // Build a Path.
    let mut builder = 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();

    // Let's use our own custom vertex type instead of the default one.
    #[derive(Copy, Clone, Debug)]
    struct MyVertex { position: [f32; 2], normal: [f32; 2] };

    // Will contain the result of the tessellation.
    let mut geometry: VertexBuffers<MyVertex, u16> = VertexBuffers::new();

    let mut tessellator = FillTessellator::new();

    {
        // Compute the tessellation.
        tessellator.tessellate_path(
            &path,
            &FillOptions::default(),
            &mut BuffersBuilder::new(&mut geometry, |vertex : FillVertex| {
                MyVertex {
                    position: vertex.position.to_array(),
                    normal: vertex.normal.to_array(),
                }
            }),
        ).unwrap();
    }

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

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.

Dual MIT/Apache2 is strictly more permissive

Contribution

There is useful information for contributors in the contribution guidelines.

lyon's People

Contributors

nical avatar kleintom avatar whmountains avatar pizzaiter avatar o0ignition0o avatar nivkner avatar kaedroho avatar darnuria avatar dd10-e avatar hadronized avatar silentbyte avatar orhanbalci avatar kuxv avatar padenot avatar jaemk avatar anna-liao avatar eijebong avatar emilio avatar ghostofme avatar bostelk avatar noxivs avatar razrfalcon avatar icefoxen avatar simonsapin avatar gralpli avatar msiglreith avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.