kmcallister / glassful Goto Github PK
View Code? Open in Web Editor NEWRust-like syntax for OpenGL Shading Language
License: Apache License 2.0
Rust-like syntax for OpenGL Shading Language
License: Apache License 2.0
Am I doing something wrong here:
let fragment_shader_src = glassful! {
#![version="140"]
#[varying] static v_coord: vec3 = UNINIT;
fn main() {
if (abs(v_coord.z) == 0.25) {
gl_FragColor = vec4(0., 1., 0., 1.);
} else if (abs(v_coord.x) == 0.25) {
gl_FragColor = vec4(0., 0., 1., 1.);
} else if (abs(v_coord.y) == 0.25) {
gl_FragColor = vec4(1., 0., 0., 1.);
}
}
};
I get:
thread '<main>' panicked at 'called `Result::unwrap()` on an `Err` value: CompilationError("0:5(8): error: syntax error, unexpected IF\n")', ../src/libcore/result.rs:731```
More ambitious version of #5.
We only support a tiny subset of Rust. It could be nice to have a 100 line grammar for shader programs instead of the grammar being the 6,000 line Rust parser + a pile of ad-hoc restrictions.
We could also make small changes to the syntax, e.g. removing the mandatory initializers on statics. As long as the tokens are compatible with Rust, the macro re-parses from source anyway.
Using the actual libsyntax parser was mostly a hack to get the proof of concept done in one day :P
The translation runs in a separate thread from rustc, in order to catch errors. So we may not be able to share libsyntax data structures. If that's the case, maybe we can hack up an acceptable codemap in the new parser context.
Perhaps using a pretty-printing library similar to Haskell's Text.PrettyPrint.
We should indent code properly, and also elide parentheses when possible (especially around assignment).
I presume each driver has its own error format, but it can't be that hard to find a line and column number.
Related to #4.
e.g.
const UNIFORMS: Uniforms;
fn vertex(v: Attributes) -> (vec4, Varyings) { ... }
fn fragment(v: Varyings) -> vec4 { ... }
where those struct definitions are lifted up from glium (c.f. #2)
which is the reference compiler for GLSL.
This will catch type errors, undefined names, as well as syntax problems the frontend won't catch.
glium already has glslang integration of some kind.
We should map errors back to the source code and print them as spans.
Modern GLSL uses in/out instead of attribute/varying, this should be supported.
So that, for example, we only declare uniforms once.
@eddyb suggested
static color: vec3 = varying;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.