Detecting the Shader Model
OpenGL does not follow the Direct3D Shader Model format; it has its own way to expose specific sets of functionality to the user. The OpenGL version number and the presence of extensions is a better test for what features are available on the hardware.
However, if you must equate GL functionality with Direct3D Shader Model versions, here is how to do so. It differs for different shading languages.
OpenGL Shading Language
Query the version of with
glGetString(GL_SHADING_LANGUAGE_VERSION). The version is formatted as
<version number><space><vendor-specific information>, where
<version number> is a
MAJOR.MINOR format, with an optional release number.
GLSL versions went through some interesting number changes.
Until version 3.30, the GLSL version number and the corresponding OpenGL version number were different. Here's a table:
For all versions of OpenGL 3.3 and above, the corresponding GLSL version matches the OpenGL version. So GL 4.1 uses GLSL 4.10.
Direct3D Shader Model 4.0 is equivalent to GLSL version 3.3. Earlier GLSL versions for OpenGL 3.x provide subsets of this functionality, based on the available functionality in the OpenGL version, though 1.50 is almost feature-identical to SM4.
Direct3D Shader Model 5.0 is equivalent to GLSL version 4.10.
For earlier shader models, GLSL versions less than 1.30 are used. Because GLSL is a high-level language, many of the differences between SM 2 and 3 are not exposed to the user.
ARB Assembly Language
These are done through testing the presence of extensions. You should test them in this order:
- GL_NV_gpu_program4: SM 4.0 or better.
- GL_NV_vertex_program3: SM 3.0 or better.
- GL_ARB_fragment_program: SM 2.0 or better.
ATI does not support higher than SM 2.0 functionality in assembly shaders.