Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kmcallister/glassful
Rust-like syntax for OpenGL Shading Language
https://github.com/kmcallister/glassful
Last synced: 1 day ago
JSON representation
Rust-like syntax for OpenGL Shading Language
- Host: GitHub
- URL: https://github.com/kmcallister/glassful
- Owner: kmcallister
- License: apache-2.0
- Created: 2015-02-01T03:13:32.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-01-22T02:32:33.000Z (almost 8 years ago)
- Last Synced: 2024-08-10T19:16:04.436Z (3 months ago)
- Language: Rust
- Size: 53.7 KB
- Stars: 171
- Watchers: 13
- Forks: 14
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# Rust-like syntax for GLSL
[![Build Status](https://travis-ci.org/kmcallister/glassful.svg?branch=master)](https://travis-ci.org/kmcallister/glassful)
glassful translates a small subset of Rust to [OpenGL Shading Language][].
Besides one's personal preferences regarding Rust-like vs. C-like syntax, this
has a few specific advantages for the Rust programmer:* Syntax is checked at Rust compile time, with friendly rustc-style errors
* There's less cognitive overhead switching between CPU and GPU code
* Shaders can use Rust macros!
* Shaders embedded in a Rust program have syntax highlightingThe library is still in a *very* early stage! Many improvements are possible.
See the [issue tracker][] and don't hesitate to send pull requests :)[OpenGL Shading Language]: https://www.opengl.org/documentation/glsl/
[issue tracker]: https://github.com/kmcallister/glassful/issues## Usage
There are three ways to invoke the translator. The language syntax is exactly
the same in all three cases.### As a macro
```rust
#![feature(plugin)]#![plugin(glassful_macros)]
const VERTEX: &'static str = glassful! {
#![version="110"]#[attribute] static position: vec2 = UNINIT;
#[varying] static color: vec3 = UNINIT;fn main() {
gl_Position = vec4(position, 0.0, 1.0);
color = vec3(0.5*(position + vec2(1.0, 1.0)), 0.0);
}
};const FRAGMENT: &'static str = glassful! {
#![version="110"]#[varying] static color: vec3 = UNINIT;
fn main() {
gl_FragColor = vec4(color, 1.0);
}
};let program = glium::Program::from_source(&display, VERTEX, FRAGMENT, None);
```See `examples/gradient/` for a full glium/glutin example.
### As an external program
```
$ ./target/glassful < shader.glassful > shader.glsl
```### As an ordinary library
```rust
extern crate glassful;pub fn main() {
let prog = io::stdin().read_to_end().unwrap();
let prog = String::from_utf8(prog).unwrap();
print!("{}", glassful::translate(prog));
}
```