顶点和片段着色器版本是否应该始终匹配?
Should vertex and fragment shader versions always match?
假设我有一个以 #version 120
开头的片段着色器和一个以 #version 150 compatibility
开头的顶点着色器。这种组合似乎适用于 AFAICT,但它是否违反 OpenGL 或 GLSL 规范?我找不到任何讨论这个问题的信息。如果确实有none,我应该把它当作"not forbidden"还是当作"not approved"?
允许在同一程序中混合使用 #version 120
和 #version 150 compatibility
。让我引用 GLSL 4.50 specification,第 3.3 节 "Preprocessor"(强调我的):
Shaders for the core or compatibility profiles that declare different
versions can be linked together. However, es profile shaders cannot be
linked with non-es profile shaders or with es profile shaders of a
different version, or a link-time error will result. When linking
shaders of versions allowed by these rules, remaining link-time errors
will be given as per the linking rules in the GLSL version
corresponding to the version of the context the shaders are linked
under. Shader compile-time errors must still be given strictly based
on the version declared (or defaulted to) within each shader.
不,不要求着色器版本匹配。要求配置文件匹配,但实际上只涉及混合桌面和嵌入式 GLSL。这在 GLSL 规范中进行了简要讨论,但并未充分讨论混合不同着色器版本的兼容配置文件的含义。
OpenGL Shading Language 4.50 - 3.3 Preprocessor - p. 14
Shaders for the core or compatibility profiles that declare different versions can be linked together. However, es profile shaders cannot be linked with non-es profile shaders or with es profile shaders of a different version, or a link-time error will result. When linking shaders of versions allowed by these rules,
remaining link-time errors will be given as per the linking rules in the GLSL version corresponding to the version of the context the shaders are linked under. Shader compile-time errors must still be given strictly based on the version declared (or defaulted to) within each shader.
您将 运行 了解可能会在 1.20 和 1.50 之间变得笨拙的语法差异。例如,150 compatibility
理解 in
和 out
着色器阶段 I/O 声明变量的使用,其中 120
必须将这些声明为 attribute
或 varying
。尽管语法不同,1.20 顶点着色器中的 varying
可以将数据传递给 1.50 片段着色器中同名的 in
变量。
当您更改着色器版本时,某些函数的行为也可能会发生细微变化。例如,GLSL 1.30 停止遵守 GL_DEPTH_TEXTURE_MODE
并且始终 returns rrrr
... 如果您从 1.20 顶点着色器中采样深度纹理,然后再次从 1.50 片段着色器中采样,您可能结果的 gba
部分很好地得到不同的结果。这种事情并不常见,但要记住。
假设我有一个以 #version 120
开头的片段着色器和一个以 #version 150 compatibility
开头的顶点着色器。这种组合似乎适用于 AFAICT,但它是否违反 OpenGL 或 GLSL 规范?我找不到任何讨论这个问题的信息。如果确实有none,我应该把它当作"not forbidden"还是当作"not approved"?
允许在同一程序中混合使用 #version 120
和 #version 150 compatibility
。让我引用 GLSL 4.50 specification,第 3.3 节 "Preprocessor"(强调我的):
Shaders for the core or compatibility profiles that declare different versions can be linked together. However, es profile shaders cannot be linked with non-es profile shaders or with es profile shaders of a different version, or a link-time error will result. When linking shaders of versions allowed by these rules, remaining link-time errors will be given as per the linking rules in the GLSL version corresponding to the version of the context the shaders are linked under. Shader compile-time errors must still be given strictly based on the version declared (or defaulted to) within each shader.
不,不要求着色器版本匹配。要求配置文件匹配,但实际上只涉及混合桌面和嵌入式 GLSL。这在 GLSL 规范中进行了简要讨论,但并未充分讨论混合不同着色器版本的兼容配置文件的含义。
OpenGL Shading Language 4.50 - 3.3 Preprocessor - p. 14
Shaders for the core or compatibility profiles that declare different versions can be linked together. However, es profile shaders cannot be linked with non-es profile shaders or with es profile shaders of a different version, or a link-time error will result. When linking shaders of versions allowed by these rules, remaining link-time errors will be given as per the linking rules in the GLSL version corresponding to the version of the context the shaders are linked under. Shader compile-time errors must still be given strictly based on the version declared (or defaulted to) within each shader.
您将 运行 了解可能会在 1.20 和 1.50 之间变得笨拙的语法差异。例如,150 compatibility
理解 in
和 out
着色器阶段 I/O 声明变量的使用,其中 120
必须将这些声明为 attribute
或 varying
。尽管语法不同,1.20 顶点着色器中的 varying
可以将数据传递给 1.50 片段着色器中同名的 in
变量。
当您更改着色器版本时,某些函数的行为也可能会发生细微变化。例如,GLSL 1.30 停止遵守 GL_DEPTH_TEXTURE_MODE
并且始终 returns rrrr
... 如果您从 1.20 顶点着色器中采样深度纹理,然后再次从 1.50 片段着色器中采样,您可能结果的 gba
部分很好地得到不同的结果。这种事情并不常见,但要记住。