获取支持的 GLSL 版本 [英] Get supported GLSL versions

查看:19
本文介绍了获取支持的 GLSL 版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用英特尔显卡的笔记本电脑上开发时,在编译顶点着色器时,我得到了这个:

0:1(10):错误:不支持 GLSL 3.30.支持的版本有:1.10、1.20、1.30、1.00 ES 和 3.00 ES

好的,所以我调整着色器以使用版本 300 ES.同时,我想检查当前驱动程序/卡支持的 GLSL 版本,所以我使用这个:

glGetString (GL_SHADING_LANGUAGE_VERSION)

令我沮丧的是,它只返回1.30".

如何获取完整列表?或者即使它不是完整列表,我如何获得标准 GL 支持版本和 GLES 支持版本?

解决方案

在桌面GL中,GL版本与GLSL版本的对应关系如下:

GL 版本 GLSL 版本2.0 1.102.1 1.203.0 1.303.1 1.403.2 1.503.3 3.304.0 4.004.1 4.104.2 4.204.3 4.304.4 4.404.5 4.50...

因此,从 GL 3.3 开始,版本号会同步"以使生活更轻松.另请注意,没有明确的 1.00 版本.当着色器被开发为 GL 1.x 的扩展时,这是可用的.然而,这从来都不是 OpenGL 的核心特性,所以这里的版本从 1.10 开始(如果你的着色器中没有 #version 指令,这也是默认的).如果您请求 #version 100,您将获得 GLSL 1.00 ES.

请注意,除了需要支持列出的 GLSL 版本外,还需要 GL 实现来支持旧版本.例如,在 OpenGL 4.5 核心配置文件规范中,声明如下(强调我的):

<块引用>

OpenGL 4.5 实现保证支持 4.50 版OpenGL 着色语言.对该部分的所有引用规格参考该版本.支持的最新版本可以按照第 22.2 节中的说明查询着色语言.该OpenGL 4.5 的核心配置文件也保证支持所有以前的OpenGL 着色语言版本回到 1.40 版. 在某些核心配置文件的实现也可能支持早期版本的着色语言,并且可能支持兼容性配置文件版本版本的着色语言1.40 及更早版本.在这种情况下,使用诸如兼容性配置文件内置的语言功能时会产生错误,而不是由核心配置文件 API 支持.

对于 OpenGL ES,同样适用:

GLES 版本 GLSL 版本2.0 1.00 ES3.0 3.00 ES3.1 3.10 ES

GLES 3.1 规范声明p><块引用>

OpenGL ES 3.1 实现保证支持 3.10 版本,OpenGL ES Shading Language 3.00 和 1.00.

现在您可能仍想知道您可以在桌面 GL 中使用哪些 GLSL ES 版本.因此,对于现代 GL,这非常简单.再次引用 GL 4.5 规范:

<块引用>

OpenGL 4.5 实现保证支持 1.00 版本,OpenGL ES 着色语言的 3.00 和 3.10.

对桌面 GL 中特定于 GLES 的功能(如 GLSL 的 ES 变体)的支持通常通过兼容性"扩展来处理:

现在您的实现可能只提供 GL 3.0 并且仍然支持 ES 兼容性扩展.

从 GL 4.3 开始,您可以通过 glGetStringi(GL_SHADING_LANGUAGE_VERSION,...).对于之前的版本,您必须检查 GL 版本号和扩展字符串,以推断保证支持哪些版本(但实现可能仍支持更多).

While developing on a laptop with an intel graphics card, while compiling a vertex shader, i got this:

0:1(10): error: GLSL 3.30 is not supported. Supported versions are: 1.10, 1.20, 1.30, 1.00 ES, and 3.00 ES

ok, so i adapt the shader to use version 300 ES. Meanwhile, i want to check what GLSL versions the current driver/card supports, so i use this:

glGetString ( GL_SHADING_LANGUAGE_VERSION )

Which, to my dismay, returns only "1.30".

How can i get the full list? Or even if it's not the full list, how can i get standard GL supported versions, and GLES supported versions ?

解决方案

In desktop GL, the mapping between the GL version and the GLSL version is as follows:

GL version                     GLSL version
2.0                            1.10
2.1                            1.20
3.0                            1.30
3.1                            1.40
3.2                            1.50
3.3                            3.30
4.0                            4.00
4.1                            4.10
4.2                            4.20
4.3                            4.30
4.4                            4.40
4.5                            4.50
...

So, beginning with GL 3.3, the version numbers are "synced" to make life easier. Also note that there is no explicit version 1.00. That was available when shaders were developed as an extension to GL 1.x. However, that was never a core feature of OpenGL, so the version starts at 1.10 here (which is also the default if you don't have a #version directive in your shader). If you request #version 100, you'll get GLSL 1.00 ES.

Note that besides being required to support the listed GLSL versions, GL implementations are also required to support older versions. For example, in the OpenGL 4.5 core profile specification, the following is stated (emphasis mine):

OpenGL 4.5 implementations are guaranteed to support version 4.50 of the OpenGL Shading Language. All references to sections of that specification refer to that version. The latest supported version of the shading language may be queried as described in section 22.2. The core profile of OpenGL 4.5 is also guaranteed to support all previous versions of the OpenGL Shading Language back to version 1.40. In some implementations the core profile may also support earlier versions of the Shading Language, and may support compatibility profile versions of the Shading Language for versions 1.40 and earlier. In this case, errors will be generated when using language features such as compatibility profile built-ins not supported by the core profile API.

For OpenGL ES, similiar things apply:

GLES version                  GLSL version
2.0                            1.00 ES
3.0                            3.00 ES
3.1                            3.10 ES

with the GLES 3.1 spec stating

OpenGL ES 3.1 implementations are guaranteed to support versions 3.10, 3.00 and 1.00 of the OpenGL ES Shading Language.

Now you might still want to know which GLSL ES versions you can use in desktop GL. So, for modern GL, this is quite simple. To quote the GL 4.5 spec again:

OpenGL 4.5 implementations are guaranteed to support versions 1.00, 3.00, and 3.10 of the OpenGL ES Shading Language.

Support for features which are specific to GLES in desktop GL (like the ES variants of GLSL) are generally handled via "compatibility" extensions:

Now your implementation might only provide GL 3.0 and still support the ES compatibility extensions.

Since GL 4.3, you can simply query the list of all of the supported GLSL versions via glGetStringi(GL_SHADING_LANGUAGE_VERSION,...). For versions prior to that, you have to check the GL version number and the extension string(s) to deduce which versions are guaranteed to be supported (but the implementation might still support more).

这篇关于获取支持的 GLSL 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆