-
Notifications
You must be signed in to change notification settings - Fork 186
GLSL Versions
mattdesl edited this page Feb 22, 2013
·
15 revisions
You can use the #version
command as the first line of your shader to specify GLSL version:
#version 120
void main() {
gl_FragColor = vec4(1.0);
}
GLSL versions are released alongside GL versions. See the following charts to decide which version you would like to target.
OpenGL Version | GLSL Version |
2.0 | 110 |
2.1 | 120 |
3.0 | 130 |
3.1 | 140 |
3.2 | 150 |
3.3 | 330 |
4.0 | 400 |
4.1 | 410 |
4.2 | 420 |
4.3 | 430 |
OpenGL ES has its own Shading Language, and the versioning starts fresh. It is based on OpenGL Shading Language version 1.10.
OpenGL ES Version | GLSL ES Version |
2.0 | 100 |
3.0 | 300 |
So, for example, if a feature is available in GLSL 120, it probably won't be available in GLSL ES 100 unless the ES compiler specifically allows it.
Some major additions to GLSL 120. Note that most of these will not work on GLSL ES.
- You can initialize arrays within a shader, like so:
float a[5] = float[5](3.4, 4.2, 5.0, 5.2, 1.1);
float b[5] = float[](3.4, 4.2, 5.0, 5.2, 1.1);
However, the above is not supported on Mac OSX Snow Leopard, even with GLSL 120. (1)
- You can initialize uniforms in a shader, and the value will be set at link time:
uniform float val = 1.0;
- You can use built-ins like
sin()
when setting aconst
value - Integers are implicitly converted to floats when necessary, for example:
float f = 1.0; <-- valid
float g = 1; <-- only supported in GLSL 120
vec2 v = vec2(1, 2.0); <-- only supported in GLSL 120
- You can use
f
to define a float:float f = 2.5f;
-
int
anduint
support (and bitwise operations with them) -
switch
statement support - New built-ins:
trunc()
,round()
,roundEven()
,isnan()
,isinf()
,modf()
- Fragment output can be user-defined
- Input and output is declared with
in
andout
syntax instead ofattribute
andvarying
- Layout qualifiers can declare the location of vertex shader inputs and fragment shader outputs, eg:
layout(location = 2) in vec3 values[4];
Formally this was only possible withARB_explicit_attrib_location
extension