GLSL中的语法错误“变化" [英] Syntaxerror 'varying' in GLSL
问题描述
我在MacBook Pro上使用GLFW 3和OpenGL 4 + GLSL 4.启动程序时出现以下语法错误:
I'm using GLFW 3 and OpenGL 4 + GLSL 4 on a MacBook Pro. I get the following syntax error, when starting my program:
ERROR: 0:5: 'varying' : syntax error syntax error
着色器代码:
#version 410
varying vec3 vertex;
void main() {
}
为什么不允许使用变量?
Why am I not allowed to use varying variables?
推荐答案
为什么不允许使用变量?
Why am I not allowed to use varying variables?
因为自GLSL 1.30起,它们已由更通用的 in
/ out
变量概念代替.
Because they have been replaced by the more generic in
/out
variable concept since GLSL 1.30.
这是必要的,因为在GL3中引入了几何着色器,因此需要在着色器阶段之间使用更通用的通信方法.现在,您只需要在一个着色器阶段声明 out
变量,并在下一个着色器阶段使用与 in
相同的声明即可.变化的概念仍然相同-光栅化器之前的最后一个着色器阶段(您使用的)的输出应与片段着色器(或光栅化器之后的第一个着色器阶段的输入)匹配,但目前没有其他输出,且默认情况下,数据将在基元上插值(如果您未将其声明为 flat
或使用无法插值的类型).
That became necessary because with GL3, the geometry shader was introduced, so a more generic communication method between shader stages was needed. Nowadays you just declare out
variables in one shader stage and have the same declarations as in
in the next shader stage you are using. The concept of varying is still the same - the outputs of the last shader stage (you use) before the rasterizer should match the inputs of the fragment shader (or the first shader stage after the rasterizer, but currently, there is no other), and the data will be interpolated across the primitive per default (if you don't declare it as flat
, or use types which can't be interpolated).
这篇关于GLSL中的语法错误“变化"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!