Deal with GLSL versions. Need some of experiences

Hi OpenGL community. :slight_smile:

I’m working on an open source project and we have some problem with OpenGL version (actually, mainly GLSL).

So: We’re trying to use OpenGL 3 function and avoid OpenGL 2.1 functions.

The surprising thing is that most of OpenGL 2.1 only drivers can make run our program because they provide OpenGL 3 extensions we use.

But there remains a problem: The GLSL version.

Even if OpenGL 3 functions are supported (thanks to the extensions!), GLSL version is fixed.

I think this page well explain the problem.

The problem is on Mac but also on most open source drivers which are in OpenGL 2.1 (Mesa…).

From what I understand, the problem is “only” with GLSL. So we can do two version of the shader and, following what OpenGL GLEW return, use one or the other.

This is something I’ve seen in OpenGL video game. You have files like this: toto.120.vtx, toto.130.vtx, toto.140.vtx, etc… This are shaders vertex files with version and the system will launch the one they want…

As I’m not very experienced with such problem, I ask you guys what do you think it’s the better idea to deal with that?

Big thanks in advance all! :slight_smile:



PS: There is some move in the Open source drivers for OpenGL 3.0 drivers but it will not be soon…

Have you considered checking the GL version with glGetString?

and just give a message about “your system is not supported”.

Also, IMO it is a good idea to tell the driver which version your shader is with the “#version” number.

Hi and thanks!

Actually, every OpenGL 3 functions I use are supported by most OpemGL 2.1 driver (using extensions).

It’s a “pragmatic” decision: If Every function I use are not OpenGL 2.1 but are supported by almost every OpenGL 2.1 driver, why should I prevent user to use this software?

That’s why I won’t prevent user to use this software if he is OpenGL 2.1.

The problem is only GLSL and I would like to have your professionnal point of view on how deal with that…

About “#version”, if I tell “#version 130”, it just doesn’t compile on GLSL 1.2. That’s why I was thinking to do as in video game and have many shader file to load only if the hardware support it.

No one as never deal with that? :frowning:

Couple of options:

  1. Provide two sets of shaders, for example for GLSL versions 1.20 and 1.50. Detect supported GLSL version at runtime and choose which version to use. Simple, effective and flexible, but high cost to maintain.

  2. Provide a single set of shaders, and patch them to match supported GLSL version. Again, detect supported GLSL version at runtime, then apply patching as needed. Simple string replacements is often enough.

  3. Use GLSL preprocessor to deal with GLSL version differences. For example

#if __VERSION__ >= 140
in vec3 _normal;
varying vec3 _normal;

I currently prefer the first option.

Thank a lot!

Ok so I suppose the first option (one shader by version: 1.2 and 1.3) is a good choice. :slight_smile:

I will do that. Thanks! :slight_smile:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.