yourgpu is an easy-to-use modern graphics API for Rust. It dramatically simplifies going from code to screen, taking influence from ModernGL, whilst using wgpu as the rendering backend.
use yourgpu::Context;
fn main() {
let mut ctx = Context::new();
let buf = ctx.storage_buffer(
b"Hello world!",
);
println!("Data from GPU: {}", String::from_utf8_lossy(&ctx.read_buffer(&buf)))
}- Simple and easy to learn
- Headless system by default (no render target required)
- First-class winit support
- Built around the WebGPU Shading Language
- Compute program and shader support
- Exposed wgpu types for easy integration with WGPU-dependent libraries
Everything starts at a Context object.
use yourgpu::Context;
fn main() {
let mut ctx = Context::new();
}Context objects give you access to GPU functions, acting as a baseline for all operations. To create a shader program to run on the GPU, we create a Program.
// ...
let prog = ctx.program("// vertex shader", Some("// fragment shader"), &[]);Program objects allow us to also describe shader binding groups, via a BindGroupBuilder object. To create data for the GPU, we create a Buffer.
// ...
// A `Buffer` with the vertex type
let vbo = ctx.vertex_buffer(&[
0.0, 0.6, 0.0,
-0.6, -0.6, 0.0,
0.6, -0.6, 0.0,
]);Buffer objects store a variety of data on the GPU, from color to position data. To describe how the vertex buffer is used, we create a VertexArray.
// ...
let vao = ctx.vertex_array(
&vbo,
None,
VertexLayoutBuilder::new()
.attr(0, VertexAttributeFormat::Float32x3) // position
);VertexArray objects describe how to data of a vertex buffer should be used, where VertexLayoutBuilder allows a set of attributes and locations describing types. To render the data to a target, like a window, or texture, we create a RenderPass.
// ...
// Example: render to a texture
// Where `tex` is a `Texture` object
ctx.render_texture(&prog, &tex, None, |r| {
r.clear(0.0, 0.0, 0.0, 1.0); // black background
r.draw(&vao); // draw the data
});For the full example, see the file in the examples folder.
yourgpu is 100% free with no drawbacks or limitations. There is no "premium" version; you get the latest and greatest, all licensed under the GPL-3.0.
All source code is public, to anyone. There is no "hidden mechanism" included in this repository; every reference and used factor exists completely and fully.