10

How would one best do to find the version of GLSL that an OpenGL implementation supports, in a way that can be reliably used programmatically?

Is the best way to get the GL_SHADING_LANGUAGE_VERSION string and try to parse it? Can it be relied upon to be returned in a well-defined format? My Intel driver returns 1.20 which is simple enough to parse, but my nVidia card returns 4.20 NVIDIA via Cg compiler. Can it be trusted to be matched by the (\d+)\.(\d+)( .*)? regex? This answer seems to indicate otherwise, returning OpenGL ES GLSL ES 1.0.

Is any of this correct, and/or is there some other way? Specifically, I want to check so that at least GLSL 1.20 is supported.

Community
  • 1
  • 1
Dolda2000
  • 25,216
  • 4
  • 51
  • 92

3 Answers3

18

There's a specific mapping between OpenGL version and supported GLSL version:

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

There's a well defined API for querying the OpenGL version. Use the table above for mapping to GLSL versions (after OpenGL-3.3 it's very logical).

Furthermore the specification defines the format of the GL_VERSION and GL_SHADING_LANGUAGE_VERSION to

begin with a version number. The version number uses one of these forms:

major_number.minor_number | major_number.minor_number.release_number
SilverTiger
  • 3
  • 1
  • 4
datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • As for the mapping between OpenGL versions and GLSL versions, is it really true not only that a certain OpenGL version supports the corresponding GLSL version, but also that a certain GLSL version is *only* supported by the corresponding OpenGL version, and never by a previous version (as an extension)? – Dolda2000 Sep 26 '13 at 14:33
  • And as for the format of the `GL_SHADING_LANGUAGE_VERSION` string, does that mean that the answer I linked to in the question is either reporting inaccurately, or that Apple is being non-conformant; or is GLES different? – Dolda2000 Sep 26 '13 at 14:35
  • @Dolda2000: Ever since OpenGL-3.3 core all developments regarding core elements (like GLSL) will yield a new OpenGL version. There will be no more GLSL extensions (except for vendor specific extensions of course). OpenGL-ES is a different beast with different rules than OpenGL. – datenwolf Sep 26 '13 at 15:17
  • I'm not really interested in versions that late anyway, however; they already include all features I need and use. I'm more interested in supporting older or less functional OpenGL implmentations in a more optimal way, like OpenGL 2.0/2.1 and the various Intel GPUs that exist. – Dolda2000 Sep 26 '13 at 15:20
  • If it just is that GLES is different in this regard, however, then I'm guessing I'll be fine with parsing the version string. Thanks! – Dolda2000 Sep 26 '13 at 15:24
  • @datenwolf, Do you got this mapping by writing special program? right? Or there is official documentation that contains such kind of mapping? – CAMOBAP Oct 21 '14 at 15:05
  • 1
    @CAMOBAP: While in theory you could get this information by query-polling OpenGL contexts and GLSL compiler supported versions, the canonical way is to simply read the documentation. At http://opengl.org/registry you can download the specifications of each OpenGL standard and associated specification standards (like GLSL) and each standard defines which version of OpenGL it has been written against. For example the GLSL-4.50 specification states on **page 1**: *"All OpenGL Graphics System Specification references in this specification are to version 4.5"*. – datenwolf Oct 21 '14 at 15:35
0

If you expect to get it from code, try using glGetString with GL_SHADING_LANGUAGE_VERSION

http://www.opengl.org/sdk/docs/man/xhtml/glGetString.xml

Oragon Efreet
  • 1,114
  • 1
  • 8
  • 25
0

After initializing the OpenGL context (I use SDL2), call glGetString() to query for graphic the card, the renderer, plus OpenGL and GLSL versions. I copy under the code the info I get.

printf("MESSAGE InceptionGlobals: Creating OpenGL context...\n");
m_contextOpenGL = SDL_GL_CreateContext(m_window);

if (!m_contextOpenGL) {
    printf("ERROR InceptionGlobals: Couldn't create OpenGL context, exiting... %s\n", SDL_GetError());
    SDL_Delay(5000);
    exit(1);
}

printf("Vendor graphic card: %s\n", glGetString(GL_VENDOR));
printf("Renderer: %s\n", glGetString(GL_RENDERER));
printf("Version GL: %s\n", glGetString(GL_VERSION));
printf("Version GLSL: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));

Vendor graphic card: NVIDIA Corporation

Renderer: GeForce GT 635/PCIe/SSE2

Version GL: 4.6.0 NVIDIA 388.13

Version GLSL: 4.60 NVIDIA

LastBlow
  • 617
  • 9
  • 16