Value of __VERSION__?

I’ve either discovered a bug in Nvidia’s GLSL compiler, or I’m misunderstanding the intention of VERSION. I have a shader that I want to compile differently depending on the supported shading language version. One path uses transpose (introduced in 1.20), and the other path does not. I have the following at the start of my shader:

#if __VERSION__ >= 120
#define USE_TRANSPOSE_PATH
#version 120
#endif

However, even on a compiler that supports 1.20, this path is never activiated. If I move the #version statement before the #if, it gets activated. This seems counter intuitive, and somewhat useless. I looked at the GLSL 1.20 spec, and it seems to indicate that VERSION should be 120 regardless of any #version statement.

What’s the real scoop?

It is the “special” about the nvidia implementation, it is not GLSL-conformant by default. You can read it here: http://developer.download.nvidia.com/opengl/glsl/glsl_release_notes.pdf

From the spec:
The #version directive must occur in a shader before anything else, except for comments and white space.

One thing I would like to know is if the VERSION define is based on what is at the top of the file (the #version) or if it is based on what the compiler supports.

It is the version you define.

Perhaps the spec should be updated to make this clearer. (as both idr and myself were confused about this)

That and it seems pretty much useless. Gosh, if I have to tell it the version, why do I need a variable to tell me what I told it? I don’t see how that helps developers write shaders that support different code paths on different compiler versions. :frowning:

Maybe the idea is to give the developer some control over the compile from the shader itself, analogous to being able to specify the shader model compile target in a D3D effect. I’ve not even used this feature yet, but that’s my guess.

It does seem a bit backwards :wink:

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