nedb
nedb

Reputation: 666

Why did GLSL change varying to in/out?

I know how to use both in/out variables, and varying variables. I am fully aware that using the in/out variables is better because it is not deprecated.

It is a very small thing, but I don't really understand why they changed this. Previously I could have the code in one shader, copy and paste it into the other, and it would be fine. Now I have to paste it into the other and change everything to "out" (instead of "in").

It is not that I mind doing this, I am just very curious about whether there is an advantage to the in/out variables, and if there isn't, why did the Khronos group change it.

Upvotes: 28

Views: 17837

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473192

This was changed because there were no longer two shader stages. OpenGL 3.2 introduced Geometry Shaders, which are an optional stage between Vertex and Fragment shaders. It takes input from VS's and provides output to FS's.

So... how would you do that when you only have one keyword? You can't copy-and-paste the interface variables from the VS and FS into the same GS. You need some way to designate that a named variable is input from the VS or an output to the FS. And no, you can't just say that a variable is both.

Also, pay attention to the nature of the input variables in the GS. They are arrayed. So you couldn't just copy the VS varying definitions into the GS; you have to change them anyway.

It should also be noted that along with geometry shaders, they added input/output interface blocks, which group multiple interface variables under one heading. With these, you don't have to change several in/out pairs; you just change one.

Upvotes: 44

Related Questions