ajaxorg/ace — Issue #606: Please add GLSL syntax highlighting (for WebGL)
Author: emackey
Created: 2012-01-06 04:23:16+00:00
State: open

Hi, can you add syntax highlighting for WebGL's shading language (OpenGL ES 2.0's GLSL)? The MIME types are "x-shader/x-vertex" and "x-shader/x-fragment". The syntax is the same as the C language, but with a different set of keywords and built-ins, as follows:

```javascript
var keywords = lang.arrayToMap(
("attribute|const|uniform|varying|break|continue|do|for|while|" +
"if|else|in|out|inout|float|int|void|bool|true|false|" +
"lowp|mediump|highp|precision|invariant|discard|return|mat2|mat3|" +
"mat4|vec2|vec3|vec4|ivec2|ivec3|ivec4|bvec2|bvec3|bvec4|sampler2D|" +
"samplerCube|struct").split("|")
);

var buildinConstants = lang.arrayToMap(
("radians|degrees|sin|cos|tan|asin|acos|atan|pow|" +
"exp|log|exp2|log2|sqrt|inversesqrt|abs|sign|floor|ceil|fract|mod|" +
"min|max|clamp|mix|step|smoothstep|length|distance|dot|cross|" +
"normalize|faceforward|reflect|refract|matrixCompMult|lessThan|" +
"lessThanEqual|greaterThan|greaterThanEqual|equal|notEqual|any|all|" +
"not|dFdx|dFdy|fwidth|texture2D|texture2DProj|texture2DLod|" +
"texture2DProjLod|textureCube|textureCubeLod|" +
"gl_MaxVertexAttribs|gl_MaxVertexUniformVectors|gl_MaxVaryingVectors|" +
"gl_MaxVertexTextureImageUnits|gl_MaxCombinedTextureImageUnits|" +
"gl_MaxTextureImageUnits|gl_MaxFragmentUniformVectors|gl_MaxDrawBuffers|" +
"gl_DepthRangeParameters|gl_DepthRange|" +
// The following two are only for MIME x-shader/x-vertex.
"gl_Position|gl_PointSize|" +
// The following five are only for MIME x-shader/x-fragment.
"gl_FragCoord|gl_FrontFacing|gl_PointCoord|gl_FragColor|gl_FragData").split("|")
);
```

For reference, see pages 3 and 4 of the quick ref card here: http://www.khronos.org/files/webgl/webgl-reference-card-1_0.pdf

I've put comments in the above that a few builtins are specific to only vertex or only fragment shaders, but in practice you can use a single set of highlighting for both types, because those builtins are reserved words in both.

Thanks!