2
\$\begingroup\$

So I'm reading up on GLSL 4.0 standard and I see things like "layout (location = 0) in vec3...."

I understand they dictate where certain values are placed but...

  1. Do particular locations hold special meaning (as in the index #s)?

  2. Since I'm sending data by getting that attribute/uniform location by name, what advantage does it provide me?

  3. What are some use cases / tricks done by using it?

On a side note: I see gl_FragColor is depricated, is gl_position deprecated too? Is there a particular name for the frag. shader output or is any vec4 output considered the final result?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$
  1. For the vertex shader the in are the vertex attributes. The number will be the location The net effect is the same as calling glBindAttribLocation with matching name/location before linking but instead it's now encoded inside the shader.

  2. it lets you reuse the location numbers for different programs so you don't have to keep a mapping per program.

  3. see #2

No gl_Position is still the required output from the vertex shader. The fragment shader outputs can be bound to specific color attachments in the framebuffer. If you only have a single output then you don't really have to worry about it.

\$\endgroup\$
4
  • \$\begingroup\$ For question #1 I was asking about the index # and not the term 'in'. If I set something to index 1 vs index 0, is there any reserved index I can't touch or is reserved for VBO. Also with regards to "bound to specific color attachments in the framebuffer" is there an article(link) I can read about. Also for VBO, how does it know which 'in' is the vertex. \$\endgroup\$
    – Mr.UNOwen
    Aug 28, 2017 at 18:30
  • \$\begingroup\$ @Mr.UNOwen there is no reserved index for vertex attributes, just up to 16 of them. Then in the vertex shader itself you are responsible for setting gl_Position to the correct value. \$\endgroup\$ Aug 28, 2017 at 18:46
  • \$\begingroup\$ so in terms of vertex input, they are now just attributes, there's no reserved name for vertex being fed into the vertex shader? Also can you point me to some cases where there's multiple outputs for the fragment shader? \$\endgroup\$
    – Mr.UNOwen
    Aug 28, 2017 at 19:05
  • \$\begingroup\$ @Mr.UNOwen That is correct. I don't have an example offhand but perhaps look at how deferred rendering works, for multiple fragment shader outputs. \$\endgroup\$
    – user253751
    Nov 22, 2017 at 4:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .