Should the vertex and fragment shader versions be the same?

Suppose I have a fragment shader that starts with #version 120

and a vertex shader that starts with #version 150 compatibility

. This combination seems to work AFAICT, but does it go against the OpenGL or GLSL specs? I couldn't find any information that discusses this issue. If this is the case, should I consider it "not prohibited" or "not approved"?

+3


source to share


2 answers


No, there are no requirements that match the shader versions. There is a requirement for matching profiles, but this only applies to mixing desktop and embedded GLSL. This is discussed briefly in the GLSL specification, but the consequences of mixing different shader versions of compatible profiles are not fully discussed.

OpenGL Shading Language 4.50 - 3.3 Preprocessor - p. fourteen

Shaders for kernel or compatibility profiles that declare different versions can be linked to each other. However, profiling shaders cannot be linked to non-es profile shaders or other version shaders, or the result will be a connection time error. When linking shaders of the versions allowed by these rules, the remaining link time errors will be corrected according to the linking rules in the GLSL version corresponding to the context version with which the shaders are bound. Shader compilation errors still have to be strictly specified based on the declared version (or default) in each shader.



You will run into syntax differences that can become a cumbersome mess between 1.20 and 1.50. For example, it 150 compatibility

understands the use of declared variables in

and out

for I / O shader stage, where it 120

should declare them as attribute

or varying

. A varying

in 1.20 vertex shader can pass data to a variable in

with the same name in a 1.50 chunk shader despite the different syntax.

There may also be minor changes in the behavior of certain functions when the shader version changes. For example, GLSL 1.30 stops respecting GL_DEPTH_TEXTURE_MODE

and always returns rrrr

... if you select a depth texture from your 1.20 vertex shader and then again from shader 1.50, you can very well get different results for gba

part of the result. This kind of thing is not so common, but it is something to keep in mind.

+4


source


Mixing #version 120

and #version 150 compatibility

in the same program is allowed. Let me quote the GLSL 4.50 spec , section 3.3 The Preprocessor (emphasis):



Shaders for major or compatibility profiles that declare different versions can be linked together . However shader profiles cannot be associated with non-es profile shaders or with es profile shaders different version or connection time error. When binding the shader versions allowed by these rules, the remaining connection time errors will be provided according to the binding rules in the GLSL version of the corresponding context versions bound by the shaders under. Shader compilation errors still need to be strictly defined in the version declared (or default) in each shader.

+3


source







All Articles