QT5.13.1 中设置 OpenGL shader GLSL版本问题

背景

Opengl ES code 移植到QT平台, QT 版本是5.13.1, GLSL代码直接移植,但是必须说明版本,否则编译shader不过。

shader中添加GLSL版本信息:

const char *sVertexShader =
"#version 100\n"
"precision mediump float;\n"
...

添加:
“#version 100\n”
或者
“#version 330 core\n”

都可以,原因待查。

调研资料

OpenGL ES对应的GLSL版本

GLSL versions have evolved alongside specific versions of the OpenGL API. It is only with OpenGL versions 3.3 and above that the GLSL and OpenGL major and minor version numbers match. These versions for GLSL and OpenGL are related in the following table:

GLSL Version OpenGL Version Date Shader Preprocessor
1.10.59 2.0 30 April 2004 #version 110
1.20.8 2.1 07 September 2006 #version 120
1.30.10 3.0 22 November 2009 #version 130
1.40.08 3.1 22 November 2009 #version 140
1.50.11 3.2 04 December 2009 #version 150
3.30.6 3.3 11 March 2010 #version 330
4.00.9 4.0 24 July 2010 #version 400
4.10.6 4.1 24 July 2010 #version 410
4.20.11 4.2 12 December 2011 #version 420
4.30.8 4.3 7 February 2013 #version 430
4.40.9 4.4 16 June 2014 #version 440
4.50.7 4.5 09 May 2017 #version 450
4.60.5 4.6 14 June 2018 #version 460

OpenGL ES and WebGL use OpenGL ES Shading Language (abbreviated: GLSL ES).

GLSL ES version OpenGL ES version WebGL version Based on GLSL version Date Shader Preprocessor
1.00.17 2.0 1.0 1.20 12 May 2009 #version 100
3.00.6 3.0 2.0 3.30 29 January 2016 #version 300 es

This list is incomplete; you can help by expanding it.

OpenGL and GLSL versions

Every OpenGL version since 2.0 has been released with a corresponding GLSL version. However, the GLSL version numbers were not always in sync with the GL version. Here is a table:

OpenGL Version GLSL Version
2.0 1.10
2.1 1.20
3.0 1.30
3.1 1.40
3.2 1.50

For all versions of OpenGL 3.3 and above, the corresponding GLSL version matches the OpenGL version. So GL 4.1 uses GLSL 4.10.

What are the differences between #version 330 and #version 330 core ?

Those two version declarations are equivalent. core is the default. From the GLSL 3.30 spec:

If no profile argument is provided, the default is core.

Which means that:

#version 330

is the same as:

#version 330 core

If you want to use the compatibility profile, you need to specify that explicitly with:

#version 330 compatibility

具体参考: https://stackoverflow.com/questions/31508693/what-are-the-differences-between-version-330-and-version-330-core

查询GLSL版本方法

Shading language version
The primary version of GLSL supported by the implementation can be queried:

glGetString(GL_SHADING_LANGUAGE_VERSION​);

This Wiki page will note the differences between GLSL and C.

https://www.khronos.org/opengl/wiki/Core_Language_(GLSL)

参考资料

https://en.wikipedia.org/wiki/OpenGL_Shading_Language


文章作者: YUV420.COM
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 YUV420.COM !
评论
 上一篇
使用Potplayer播放网络共享直播源提供txt格式转换为dpl格式工具 使用Potplayer播放网络共享直播源提供txt格式转换为dpl格式工具
背景偶然机会发现网络上有很多提供电影电视直播源的,下载下来发现是txt格式。如下所示: = 未分组 = 黑帮电影,http://101.72.196.41/r/baiducdnct.inter.iqiyi.com/tslive/c16_lb
2020-01-08
下一篇 
OpenGL ES shader 编译错误打印方法 OpenGL ES shader 编译错误打印方法
音视频开发中,经常用OpenGL最为显示模块,OpenGL shader的编译错误有时需要打印辅助分析。下面记录一下调试打印OpenGL 或者 OpenGL ES shader 编译错误信息的方法。 直接上代码: glCompile
2020-01-08
  目录