WebGL State Machine in Rust
An opinionated wrapper for low-level WebGL API with intention to provide a bit of explicit state management with reasonable defaults.
Primary goals for this library is to support WebGL 1.0 so it is built on top of raw bindings from web-sys
crate.
Key concepts
- Program - GL program description including vertex shader, fragment shader, attributes and uniforms. Program takes care of compiling shaders, getting attributes / uniforms locations and finally disposing resources once it goes out of scope.
- Mesh - structure that holds references to data uploaded to GPU, takes care of disposing array / element buffers once it goes out of scope.
- Framebuffer - render target, has depth and color slot, can also be initialized as empty then rendering would go to the screen.
- Pipeline - a primitive for drawing stuff to screen, sole purpose of which is to set GL context configuration and provide
shade
method for drawing.
Usage example
Get it from crates.io
[]
# ...
= "0.2.0"
Import crate
use glsmrs as gl;
Create context, Ctx
is a wrapper that is using Rc
internally so you can clone it and pass around without worrying too much about lifetimes.
let ctx = get_ctx?;
Create some mesh, like an RGB triangle
let vertices = vec!;
let colors = vec!;
let indices = ;
let triangle = new?
.?
.?;
Define render target
let viewport = new;
let displayfb = new;
Create a program description
let program = new?;
Run program on state supplying necessary inputs
let uniforms: = vec!.into_iter.collect;
let pipeline = new;
pipeline.shade?;
For example project using this library check out [ https://github.com/wg-romank/wasm-game-of-life ] a tweaked version of original WASM tutorial that runs entierly on GPU.