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.

GLSL Versions

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

GLSL ES Versions (Android, iOS, WebGL)

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.

Differences at a Glance

Differences between (desktop) GLSL versions.

Version 100

Vertex shader:

uniform mat4 projTrans;

attribute vec2 Position;
attribute vec2 TexCoord; varying vec2 vTexCoord; void main() {
vTexCoord = TexCoord;
gl_Position = u_projView * vec4(Position, 0.0, 1.0);
}

Fragment shader:

uniform sampler2D tex0;

varying vec2 vTexCoord;

void main() {
vec4 color = texture2D(tex0, vTexCoord);
gl_FragColor = color;
}

Version 330

As of GLSL 130+, in and out are used instead of attribute and varying. GLSL 330+ includes other features like layout qualifiers and changes texture2D to texture.

Vertex shader:

#version 330

uniform mat4 projTrans;

layout(location = 0) in vec2 Position;
layout(location = 1) in vec2 TexCoord; out vec2 vTexCoord; void main() {
vTexCoord = TexCoord;
gl_Position = u_projView * vec4(Position, 0, 1);
}

Fragment shader:

#version 330
uniform sampler2D tex0; in vec2 vTexCoord; //use your own output instead of gl_FragColor
out vec4 fragColor; void main() {
//'texture' instead of 'texture2D'
fragColor = texture(tex0, vTexCoord);
}

Other Significant Changes

GLSL 120 Additions

  • 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 a const 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;

GLSL 130 Additions

  • int and uint 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 and out syntax instead of attribute and varying

GLSL 150 Additions

  • texture() should now be used instead of texture2D()

GLSL 330 Additions

  • 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 with ARB_explicit_attrib_location extension

GLSL Versions和GLSL ES Versions 对比的更多相关文章

  1. MySQL、HBase、ES的对比

    hbase是列数据库,是kv结构的,ES的基于Lucene的搜索引擎的面向文档数据库吧 ES是搜索引擎,主要的优势在于快速搜索,HBase是数据库,优势在于存储数据,侧重点不同 MySQL:关系型数据 ...

  2. OpenGL 与 GLSL 版本号

    来自:https://github.com/mattdesl/lwjgl-basics/wiki/GLSL-Versions You can use the #version command as t ...

  3. 着色器语言 GLSL (opengl-shader-language)入门大全

    基本类型: 类型 说明 void 空类型,即不返回任何值 bool 布尔类型 true,false int 带符号的整数 signed integer float 带符号的浮点数 floating s ...

  4. GLSL in ShaderLab

    [Syntax] However, use of raw GLSL is only recommended for testing, or when you know you will only ta ...

  5. GLSL 着色器程序

    除了使用Cg/HSL 着色器程序以外, OpenGL 着色器语言(GLSL)着色器可以直接书写shader. 然而,使用原生的GLSL只推荐作为测试使用,或者你清晰的知道你的目标平台是 Mac OS ...

  6. OpenGL 4.5 Core Profile管线(GLSL与应用程序接口详解)【未完成】

    之前写过一篇博客,OpenGL管线(用经典管线代说着色器内部),说的主要是OpenGL的经典管线.大家都知道,现代OpenGL已经弃用(从OpenGL 3.0开始)经典管线功能(glBegin,变换矩 ...

  7. 查找EBS中各种文件版本(Finding File Versions in the Oracle Applications EBusiness Suite - Checking the $HEADER)

    Finding File Versions in the Oracle Applications EBusiness Suite - Checking the $HEADER (文档 ID 85895 ...

  8. webgl glsl

    GLSL是什么? GLSL是运行在GPU上的着色器语言 GLSL有自己的语法,跟js有些不同. GLSL是一个强类型的语言,所以在写着器语言时,必须要用强类型,强类型,强类型,强类型 GLSL是着色器 ...

  9. 【OpenGL4.0】GLSL渲染语言入门与VBO、VAO使用:绘制一个三角形 【转】

    http://blog.csdn.net/xiajun07061225/article/details/7628146 以前都是用Cg的,现在改用GLSL,又要重新学,不过两种语言很多都是相通的. 下 ...

随机推荐

  1. Java中的“&”和“&&”的区别

    Java中的"&"和"&&"的区别 1."&"是位运算符,"&&"是逻辑 ...

  2. Java中集合List,Map和Set的区别

    Java中集合List,Map和Set的区别 1.List和Set的父接口是Collection,而Map不是 2.List中的元素是有序的,可以重复的 3.Map是Key-Value映射关系,且Ke ...

  3. Duplicate <http> element detected

    1.错误描述    org.springframework.beans.factory.parsing.BeanDefinitionParsingException:Configuration pro ...

  4. BUAA软工第0次作业

    第一部分:结缘计算机 1.你为什么选择计算机专业?你认为你的条件如何?和这些博主比呢?(必答) 我在大学之前甚至连一个萌新都算不上,根本没有任何一点计算机专业的基础. 因此在进入大学之前,计算机对于我 ...

  5. ASP.NET登录记住用户名

    案例如下: 1:首先在登录的控制器中定义一个全局变量 public const string LonginName = "sessName"; 2:在登陆的方法中 public A ...

  6. Python Web-第三周-Networks and Sockets(Using Python to Access Web Data)

    1.Networked Programs 1.Internet 我们现在学习Internet部分,即平时我们浏览器做的事情,之后再学习客服端这部分 2.TCP 传输控制协议 3.Socket HTTP ...

  7. Spring Boot Actutaur + Telegraf + InFluxDB + Grafana 构建监控平台

    完成一套精准,漂亮图形化监控系统从这里开始第一步 Telegraf是收集和报告指标和数据的代理 它是TICK堆栈的一部分,是一个用于收集和报告指标的插件驱动的服务器代理.Telegraf拥有插件或集成 ...

  8. 【BZOJ1926】粟粟的书架(主席树,前缀和)

    [BZOJ1926]粟粟的书架(主席树,前缀和) 题面 Description 幸福幼儿园 B29 班的粟粟是一个聪明机灵.乖巧可爱的小朋友,她的爱好是画画和读书,尤其喜欢 Thomas H. Co ...

  9. python 时间模块time,datetime详细介绍

    模块(module)是 Python 中非常重要的东西,你可以把它理解为 Python 的扩展工具.换言之,Python 默认情况下提供了一些可用的东西,但是这些默认情况下提供的还远远不能满足编程实践 ...

  10. golang channel的使用以及调度原理

    golang channel的使用以及调度原理 为了并发的goroutines之间的通讯,golang使用了管道channel. 可以通过一个goroutines向channel发送数据,然后从另一个 ...