OpenGL 与 GLSL 版本号
来自:https://github.com/mattdesl/lwjgl-basics/wiki/GLSL-Versions
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 aconstvalue - 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
fto define a float:float f = 2.5f;
GLSL 130 Additions
intanduintsupport (and bitwise operations with them)switchstatement support- New built-ins:
trunc(),round(),roundEven(),isnan(),isinf(),modf() - Fragment output can be user-defined
- Input and output is declared with
inandoutsyntax instead ofattributeandvarying
GLSL 150 Additions
texture()should now be used instead oftexture2D()
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
OpenGL 与 GLSL 版本号的更多相关文章
- 【OpenGL】glsl、glew、glfw
glsl: OpenGL着色语言(OpenGL Shading Language)是用来在OpenGL中着色编程的语言,也即开发人员写的短小的自定义程序,他们是在图形卡的GPU (Graphic Pr ...
- OpenGL和GLSL版本更迭
前言 最近才发现,自己写的glsl和教程的glsl版本对不上,一直以为是xcode不允许使用太高版本,只能使用OpenGL 2.0的版本,却不知使用glfw可以使用到最新的OpenGL版本.
- OpenGL中GLSL渲染茶壶光照完整程序
顶点着色器VertexShader.txt: uniform vec3 lightposition;//光源位置 uniform vec3 eyeposition;//相机位置 uniform vec ...
- OpenGL的版本号历史和发展
来源请注明.本文永久地址为http://www.cnblogs.com/vertexshader/articles/2917540.html OpenGL®作为业界最为广泛使用的2D和3D图形接口标准 ...
- C#+OpenGL+FreeType显示3D文字(2) - 用GLSL+VBO绘制文字
C#+OpenGL+FreeType显示3D文字(2) - 用GLSL+VBO绘制文字 +BIT祝威+悄悄在此留下版了个权的信息说: 上一篇得到了字形贴图及其位置字典(可导出为XML).本篇就利用此贴 ...
- OpenGL/GLSL数据传递小记(3.x)(转)
OpenGL/GLSL规范在不断演进着,我们渐渐走进可编程管道的时代的同时,崭新的功能接口也让我们有点缭乱的感觉.本文再次从OpenGL和GLSL之间数据的传递这一点,记录和介绍基于OpenGL3.x ...
- OpenGl中使用着色器的基本步骤及GLSL渲染简单示例
OpenGL着色语言(OpenGL Shading Language,GLSL)是用来在OpenGL中着色编程的语言,是一种具有C/C++风格的高级过程语言,同样也以main函数开始,只不过执行过程是 ...
- OpenGL ES SL 3.0规范中以前的attribute改成了in varying改成了out
OpenGL ES和OpenGL的图标 关于“OpenGL ES SL 3.0规范中以前的attribute改成了in varying改成了out”这个问题,做一阐述: 1.关键字的小修 ...
- OpenGL 笔记 <2> Compiling and Linking a shader program
Preface 这一节所有的主要内容都在一个OpenGL库文件中<LoadShaders.h> ,只需要用LoadShader()函数进行加载即可.但是由于老是出错,所以自己实现了一下,也 ...
随机推荐
- iOS学习笔记36-Masonry自动布局
一.Masonry介绍 之前我们在屏幕适配的章节中学习过AutoLayout的使用,但那都是在可视化界面上进行添加约束完成的,我们很多时候都需要在代码中使用AutoLayout约束,苹果也为我们提供了 ...
- Github管理 第一步:在Eclipse中导入既存Github Java Project
1.前提 从官网下载的最新版本的Eclipse已经集成了Github插件,所以忽略了配置说明. 如果在下面的步骤中你找不到Git的设定目录,可能你的Eclipse中还没有Github,请自行解决. 2 ...
- zygote的分裂
1 zygote的分裂 前面已经讲了zygote分裂出了长子system_server,然后SS(system_server)就通过initAndLoop进行消息循环处理了.那么谁会向zygote发送 ...
- [暑假集训--数位dp]LightOJ1140 How Many Zeroes?
Jimmy writes down the decimal representations of all natural numbers between and including m and n, ...
- Java Socket IO(BIO、NIO)
总结下Java socket IO.首先是各种IO的定义,这个定义似乎也是众说纷纭.我按照stackoverflow上面的解释: IO有两种分法:按照阻塞或者按照同步.按照阻塞,有阻塞IO和非阻塞IO ...
- [Codeforces Round #170 Div. 1] 277A Learning Languages
A. Learning Languages time limit per test:2 seconds memory limit per test:256 megabytes input standa ...
- 使用 IntelliJ IDEA 开发 Android 应用程序时配置 Allatori 进行代码混淆
IntelliJ IDEA 提供了非常强大的 Android 开发支持,就连 Google 官方推荐的 Android Studio 其实也是 IntelliJ IDEA 的一个 Android 开发 ...
- 开发使用mysql的一些必备知识点整理(二)查询
简介 查询的基本语法 select * from 表名; from关键字后面写表名,表示数据来源于是这张表 select后面写表中的列名,如果是*表示在结果中显示表中所有列 在select后面的列名部 ...
- hdu 1401(单广各种卡的搜索题||双广秒速)
Solitaire Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- LeetCode OJ--Set Matrix Zeroes **
http://oj.leetcode.com/problems/set-matrix-zeroes/ 因为空间要求原地,所以一些信息就得原地存储.使用第一行第一列来存本行本列中是否有0.另外对于第一个 ...