Syntaxerror 'varying' in GLSL

馋奶兔 提交于 2021-02-07 19:02:55

问题


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

The shader code:

#version 410

varying vec3 vertex;

void main() {
}

Why am I not allowed to use varying variables?


回答1:


Why am I not allowed to use varying variables?

Because they have been replaced by the more generic in/out variable concept since GLSL 1.30.

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).



来源:https://stackoverflow.com/questions/23456739/syntaxerror-varying-in-glsl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!