GLSL type checker, formatter, and minifier online demo

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.

Input

Load example:   WebGL 1   WebGL 2   Bugs   Protophore

   

Output

Flags:      
Rename:      
Format:          

Syntax Extensions

I call this language GLSLX because it extends GLSL with some additional syntax. The main feature are the @vertex and @fragment modifiers, which allows multiple shaders to be specified from the same file that all reuse the same code. Each function with one of these modifiers becomes the main function in a separate shader.

@vertex
void vertexShader() {}

@fragment
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;
}