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()函数进行加载即可.但是由于老是出错,所以自己实现了一下,也 ...
随机推荐
- 【bzoj3505】[Cqoi2014]数三角形 容斥原理
题目描述 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个.下图为4x4的网格上的一个三角形. 注意三角形的三点不能共线. 输入 输入一行,包含两个空格分隔的正整数m和n. 输出 输出一个 ...
- BZOJ3990 [SDOI2015]排序 【搜索】
题目 小A有一个1-2^N的排列A[1..2^N],他希望将A数组从小到大排序,小A可以执行的操作有N种,每种操作最多可以执行一次,对于所有的i(1<=i<=N),第i中操作为将序列从左到 ...
- 刷题总结——xor(ssoj)
题目: 题目背景 OURCE:NOIP2015-SHY-7 题目描述 求一棵带边权的树的一条最大 Xor 路径的值.这里的“路径”不一定从根到叶子结点,中间一段路径只要满足条件也可以. 输入格式 第一 ...
- jenkins使用xvfb插件构建虚拟化显示屏自动化测试
1.linux服务器安装xvfb,并启动 参考我的博客:http://www.cnblogs.com/lincj/p/5468505.html 或者网上搜索一下进行安装 2.jenkins安装xvfb ...
- 关于vue-router路径配置的问题
"/" 表示路由根目录 "/AdminPage" 表示一级路由 如果在一级路由下面配置子路由 "User",表示的意思是 "/Ad ...
- google jib容器打包工具
简介 Jib 是 Google 开发的可以直接构建 Java 应用的 Docker 和 OCI 镜像的类库,以 Maven 和 Gradle 插件形式提供. 通过 Jib,Java 开发者可以使用他们 ...
- docker的通俗理解
自己买了个服务器,前不久搭建好的一个网站,想要再搞一个站点,无奈只能修改端口后,再部署另外一个站点.繁琐的配置运行环境,迁移网站,是否让你感觉到很繁琐?服务器不想用了,想搬迁到另外一台服务器去部署,先 ...
- TYVJ 1305 最大子序和 ++ 烽火传递
描述 输入一个长度为n的整数序列,从中找出一段不超过M的连续子序列,使得整个序列的和最大. 例如 1,-3,5,1,-2,3 当m=4时,S=5+1-2+3=7当m=2或m=3时,S=5+1=6 输入 ...
- AT&T汇编语言及其寻址方式
汇编语言论风格来分主要是两类,一类是Intel汇编,一类是AT&T汇编,分别被Windows和Linux作为主流风格.因为我博客以推荐Linux系统为主,所以以后多以Linux汇编为主要描述语 ...
- Day 20 迭代器、生成器
一. 迭代器 1.迭代器协议是指:对象必须提供一个next方法,执行该方法要么返回迭代中的下一项,要么就引起一个StopIteration异常,以终止迭代 (只能往后走不能往前退) 2.可迭代对象:实 ...