10
votes

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.

3

3 Answers

17
votes

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
0
votes

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

0
votes

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