Rust WebGL2 wrapper with a focus on making high-performance WebAssembly graphics code easier to write and maintain

Overview

Limelight

GitHub Repo stars crates.io docs.rs Rust

Limelight is a WebGL2 wrapper with a focus on making high-performance WebAssembly graphics code easier to write and maintain.

demo.mov

live demo (code)

Specifically, limelight:

  • Provides a functional interface that abstracts away the statefulness of WebGL. It accomplishes this by using a shadow GPU that tracks the GPU's state, diffs it with the desired state, and sends only the necessary instructions to WebGL.
  • Provides abstractions for buffers and uniforms that defer GPU data transfer until the next draw cycle.
  • Provides a typed interface to uniforms and buffers, and automatically generates bindings between shader attributes and Rust structs through a derive macro.
  • Provides an interface for transforms like zoom and pan through limelight-transform.
  • Provides 2D shape primitives like circles and lines through limelight-primitives.

Getting started

Abstract art made from circles and rectangles.

(full code, demo)

This example uses limelight-primitives and limelight-yew to construct a basic, static image made from circles and rectangles.

use anyhow::Result;
use limelight::{renderer::Drawable, Renderer};
use limelight_primitives::{Circle, CircleLayer, Rect, RectLayer};
use limelight_yew::{LimelightComponent, LimelightController};

struct Primitives {
    rects: RectLayer,
    circles: CircleLayer,
}

impl LimelightController for Primitives {
    fn draw(
        &mut self,
        renderer: &mut Renderer,
        _ts: f64,
    ) -> Result
    {
        
   self.rects.
   draw(renderer)?;
        
   self.circles.
   draw(renderer)?;

        
   Ok(
   false)
    }
}


   impl 
   Default 
   for 
   Primitives {
    
   fn 
   default() -> 
   Self {
        
   let rects 
   = RectLayer
   ::
   new();
        
   let circles 
   = CircleLayer
   ::
   new();

        rects.
   buffer().
   set_data(
   vec![
            Rect {
                lower_right: [
   0.4, 
   0.1],
                upper_left: [
   -
   0.8, 
   0.2],
                color: palette
   ::named
   ::TOMATO.
   into(),
            },
            Rect {
                lower_right: [
   0.4, 
   0.25],
                upper_left: [
   -
   0.6, 
   0.5],
                color: palette
   ::named
   ::SLATEBLUE.
   into(),
            },
        ]);

        circles.
   buffer().
   set_data(
   vec![
            Circle {
                position: [
   0., 
   0.25],
                radius: 
   0.2,
                color: palette
   ::named
   ::WHITE.
   into(),
            },
            Circle {
                position: [
   0., 
   0.25],
                radius: 
   0.1,
                color: palette
   ::named
   ::ORANGERED.
   into(),
            },
        ]);

        Primitives { rects, circles }
    }
}


   fn 
   main() {
    console_error_panic_hook
   ::
   set_once();
    wasm_logger
   ::
   init(wasm_logger
   ::Config
   ::
   default());
    yew
   ::
   start_app
   ::
   
    
     >();
}
    
   
  

More Examples

You might also like...
Zaplib is an open-source library for speeding up web applications using Rust and WebAssembly.

⚡ Zaplib Zaplib is an open-source library for speeding up web applications using Rust and WebAssembly. It lets you write high-performance code in Rust

A template for kick starting a Rust and WebAssembly project using wasm-pack.

A template for kick starting a Rust and WebAssembly project using wasm-pack.

A simple Rust and WebAssembly real-time implementation of the Vigénere Cipher utilizing the Sycamore reactive library.
A simple Rust and WebAssembly real-time implementation of the Vigénere Cipher utilizing the Sycamore reactive library.

WebAssembly Vigenère Cipher A simple Rust and WebAssembly real-time implementation of the Vigenère Cipher utilizing the Sycamore reactive library, Tru

🚀Wasmer is a fast and secure WebAssembly runtime that enables super lightweight containers to run anywhere
🚀Wasmer is a fast and secure WebAssembly runtime that enables super lightweight containers to run anywhere

Wasmer is a fast and secure WebAssembly runtime that enables super lightweight containers to run anywhere: from Desktop to the Cloud, Edge and IoT devices.

Compiler infrastructure and toolchain library for WebAssembly

Binaryen Binaryen is a compiler and toolchain infrastructure library for WebAssembly, written in C++. It aims to make compiling to WebAssembly easy, f

Sealed boxes implementation for Rust/WebAssembly.

Sealed boxes for Rust/WebAssembly This Rust crate provides libsodium sealed boxes for WebAssembly. Usage: // Recipient: create a new key pair let reci

A Rust ESP stack trace decoder that can also runs in your browser thanks to WebAssembly
A Rust ESP stack trace decoder that can also runs in your browser thanks to WebAssembly

ESP Stack Trace Decoder A Rust ESP stack trace decoder that can also runs in your browser thanks to WebAssembly. It is composed of a ⌨️ Rust library,

bn.js bindings for Rust & WebAssembly with primitive-types support

bn.rs bn.js bindings for Rust & WebAssembly with primitive-types support Write Rust code that uses BN use std::str::FromStr; use primitive_types::{H1

A simple compile-to-WebAssembly language rewritten in Rust

chasm A very simple compile-to-WebAssembly language You can play with chasm online. This is a rewrite in Rust of the compiler for the language chasm.

Owner
drifting in space
Server infrastructure to supercharge browser-based tools.
drifting in space
Rust-based WebAssembly bindings to read and write Apache Parquet files

parquet-wasm WebAssembly bindings to read and write the Parquet format to Apache Arrow. This is designed to be used alongside a JavaScript Arrow imple

Kyle Barron 103 Dec 25, 2022
WebAssembly wrapper for JohnnyMorganz's StyLua

WebAssembly wrapper for JohnnyMorganz's StyLua

null 1 Dec 15, 2022
A high-performance, secure, extensible, and OCI-complaint JavaScript runtime for WasmEdge.

Run JavaScript in WebAssembly Now supporting wasmedge socket for HTTP requests and Tensorflow in JavaScript programs! Prerequisites Install Rust and w

Second State 219 Jan 3, 2023
This is a webpack loader that loads Rust code as a WebAssembly module

rust-native-wasm-loader This is a webpack loader that loads Rust code as a WebAssembly module. It uses the native Rust support for compiling to wasm32

David Flemström 162 Nov 21, 2022
Contains the source code to compile the drop'in language into WebAssembly files

drop'in compiler This repository contains the source code to compile the drop'in language into WebAssembly files. This source code is in an experiment

Blue Forest 2 Dec 17, 2022
Client for integrating private analytics in fast and reliable libraries and apps using Rust and WebAssembly

TelemetryDeck Client Client for integrating private analytics in fast and reliable libraries and apps using Rust and WebAssembly The library provides

Konstantin 2 Apr 20, 2022
A console and web-based Gomoku written in Rust and WebAssembly

?? rust-gomoku A console and web-based Gomoku written in Rust and WebAssembly Getting started with cargo & npm Install required program, run # install

namkyu1999 2 Jan 4, 2022
darkforest is a console and web-based Roguelike written in Rust and WebAssembly.

darkforest darkforest is a console and web-based Roguelike written in Rust and WebAssembly. Key Features TBA Quick Start TBA How To Contribute Contrib

Chris Ohk 5 Oct 5, 2021
Simple file sharing with client-side encryption, powered by Rust and WebAssembly

Hako Simple file sharing with client-side encryption, powered by Rust and WebAssembly Not feature-packed, but basic functionalities are just working.

Jaehyeon Park 30 Nov 25, 2022
A handy calculator, based on Rust and WebAssembly.

qubit ?? Visit Website To Use Calculator Example ?? Visit Website To Use Calculator 2 + 2

Abhimanyu Sharma 55 Dec 26, 2022