GLSLX is a type checker, code formatter, and minifier/obfuscator for WebGL GLSL code. Straight-forward type checking makes it possible to catch GLSL errors using continuous integration. Because it actually parses and understands the code, the minification should be much more robust than other minifiers based on regular expressions. It doesn't include a preprocessor because it's meant to be used after the preprocessing step. It also includes automatic insertion of "#extension" statements so their absence can't mess stuff up.
The compiler is published on npm and is also available as an independent download. That one file works in the browser, as a command-line node script, and as a node module that can be required by other code. The source code lives at https://github.com/evanw/glslx.
Flags:
Rename:
Format:
I call this language GLSLX because it extends GLSL with some additional syntax. The main feature is the "export" modifier, which allows multiple shaders to be specified from the same file that all reuse the same code. Each export function becomes the "main" function in a separate shader.
// Simple modifier syntax export void vertexShader() {} // Modifier block syntax export { void vertexShader() {} void fragmentShader() {} }
API declarations can be done with the "import" modifier. See the compiler's API declarations for more examples.
// Simple modifier syntax import float sin(float x); // Modifier block syntax import { float cos(float x); vec2 cos(vec2 x); vec3 cos(vec3 x); vec4 cos(vec4 x); }
Extensions can be declared with an "#extension" block.
#extension GL_EXT_frag_depth { float gl_FragDepthEXT; }