PDA

View Full Version : version acrobatics



ugluk
06-21-2010, 08:37 AM
since __VERSION__ is often set to 120 by default, even if a higher version is available (why so, btw?)? I check for highest shader version available on the CPU and prepend the maximum available GLSL version, say,



#define GLSL_VERSION 150


to all shader code I load. I then do something like,



#if (GLSL_VERSION > __VERSION__)
// here I set the maximum supported GLSL version
#version 150
#endif // GLSL_VERSION

#if (__VERSION__ > 120)
# define IN in
# define OUT out
#else
# define IN attribute
# define OUT varying
#endif // __VERSION __


in my shader. I also check for __VERSION__ in my shader code. This way I can support all possible GLSL shader versions in a certain interval in the same shader code.

My question is, does there exist a better way to do the same task, i.e. support an interval of GLSL versions in the same shader code?

ugluk
06-21-2010, 06:18 PM
Hmm, no answers? Well, as it turns out, the trick does not work on ATI cards but works very well on NVIDIA cards. So now I simply get the maximum version the GPU supports and inject it on top of every shader source I load.

Alfonse Reinheart
06-21-2010, 07:16 PM
My question is, does there exist a better way to do the same task, i.e. support an interval of GLSL versions in the same shader code?

You could just use the compatibility version for GL versions 3.0 or greater. In GLSL, you would set "#version 150 compatibility". It will give you deprecated warnings, but if you're looking for backwards compatibility with GL 2.1, then that's what you use.

frank li
06-21-2010, 08:04 PM
"The #version directive must occur in a shader before anything else, except for comments and white space.", so your shader may cause error. -
#define GLSL_VERSION 150
#if (GLSL_VERSION > __VERSION__)
#version 150
#endif

ugluk
06-22-2010, 04:30 PM
Yeah frenk, I fixed this. Now I check the maximum supported version and do:

#version 400

or sth like that, as the first line of every shader I load.