views:

45

answers:

1

using '#version 330 core' on NVIDIA,

By using glBindAttribLocation(program, 0, "in_Vertex"); the input vertex works with an "in vec4 in_Vertex;". However, I noticed without the OGL function call in the client app, it still works. It appears to be 'the default first input variable'. Why? Should it be omitted or be explicitly connected to it via glBindAttribLocation? [What's the ideal according to the standard?] Also "in vec4 gl_Vertex;" works while the spec calls it deprecated and the compiler of shaders does not give any warning. Why? I would have expected for it to at least warn. I guess the last one may be a bug in the compiler (GLSL compiler) but the first issue is especially puzzling.

+2  A: 
  1. if you don't bind attributes to a location, the GL will do it for you. Which locations it uses is unspecified but you happened to have the same value.

    • You can ask the GL which location it's chosen with glGetAttribLocation
    • Even though it's not specified, I've seen implementations choose to bind locations in order of the shader. First is 0, second is 1, ...
  2. The standard leaves those 2 options open because there are valid use cases for each.

  3. As for deprecation, nvidia clearly stated that they thing deprecation was the wrong decision. In the end somebody has to write the code to emit the warning... So it's not that surprising they would not warn, even if they ought to.

Bahbar
I can add that if gl_Vertex works on 3.3 core on NVIDIA, doesn't mean it will work on other vendors, or in future hardware. Follow the spec if you want cross compatibility.
Matias Valdenegro
@Matias: true. As a matter of fact, it should error, not warn.
Bahbar
I don't see how leaving it to the implementation is even an option. If it's not universal in what order the input vertices are given to a var then one would definitely have to explicitly use glBindAttribLocation to make sure it is applicable across vendors.
Lela Dax
@Lela Dax: The point is, If you don't care where it was per say, you can ask where it was set, and use that in your code. A bit like texture handles: `glGenTextures` does not return the same handles on every implementation. You still use its result to test texture objects.
Bahbar