1 unstable release

0.1.0 Apr 9, 2020

#8 in #em


Used in emu_core

MIT license

7KB
79 lines

This crate enables GLSL-Rust interop. You can use emu_glsl with emu_core for GLSL-based GPU compute.


lib.rs:

emu_glsl is a crate for GLSL-Rust interop. Currently, it only provides a single derive macro - glsl_struct. This macro derives a trait that is defined in the emu_core crate - GlslStruct. This is what the trait looks like.

pub trait GlslStruct {
    fn as_glsl() -> String; // return the GLSL struct definition of Self
}

emu_glsl lets you derive this trait for simple structures where each field is one of the following.

  • bool
  • i32
  • u32
  • f32
  • f64
  • [i32 | u32 | f32 | f64 | bool; 2 | 3 | 4]

These get straightforwardly translated to their GLSL equivalents with the arrays being translated to GLSL "vector data types". An example usage is the following. (It doesn't compile as is because it's missing imports for the GlslStruct trait and glsl_struct derive macro.)

#[derive(GlslStruct)]
struct Polygon {
    num_edges: u32,
    radius: f64,
    conv: bool, // make sure polygons in same thread block have same convexity
}

Dependencies

~1.5MB
~33K SLoC