openglopengl-esopengl-es-2.0

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

So I adapted 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?


Solution

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