Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get supported GLSL versions

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 ?

like image 299
Joao Pincho Avatar asked Dec 10 '14 17:12

Joao Pincho


People also ask

What version of GLSL should I use?

You pick the GLSL version for the version of OpenGL that is your minimum supported version. If your minimum supported GL version is 2.1, then your GLSL version should be 1.10. If your minimum supported version is GL 4.1, then your GLSL version should be 4.10.

What version of GLSL does WebGL use?

It is based on OpenGL ES 2.0, and according to the spec, it must support GLSL ES version 1.00. In fact that is all it supports. Another good reference for WebGL is the official Khronos WebGL Cheat Sheet.

What is GLSL support?

GLSL supports function overloading (for both built-in functions and operators, and user-defined functions), so there might be multiple function definitions with the same name, having different number of parameters or parameter types. Each of them can have own independent return type.

Which shading model is not supported by OpenGL?

OpenGL does not follow the Direct3D Shader Model format; it has its own way to expose specific sets of functionality to the user.


1 Answers

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:

  • GL_ARB_ES2_compatibility, in core since GL 4.1
  • GL_ARB_ES3_compatibility, in core since GL 4.3
  • GL_ARB_ES3_1_compatibility, in core since GL 4.5

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).

like image 131
derhass Avatar answered Oct 18 '22 21:10

derhass