-2

Using glVertexAttribPointer the opengl implementation already knows to which attribute location/index in vertex shader Vertex Attribute Object is bound, so why is there the need to provide attribute index in glEnableVertexAttribArray again? I think after using glBindVertexArray(VAO); it could have been enough to use just glEnableVertexAttribArray()? Why there is the need to provide attribute index two times; one in glVertexAttribPointer and one in glEnableVertexAttribArray()? Please bear with me, I am beginner and i don't know all aspects of the OpenGL yet.

[This question is NOT duplicate as some try to mark it as duplicate to redirect to their answers on some irrelevant questions to earn rating, this is selfish act! Please don't ruin the question by marking as duplicate if you don't know how to answer it.]

Shuji
  • 574
  • 6
  • 22

1 Answers1

0

Because it's possible to set a vertex attribute to a value that's constant for all elements using glVertexAttrib. Yes, you could to that to the same effect with a uniform as well, but this kind of per-attribute selection of where a value comes from (sourced from array, or set constant) has been around for ages (ever since OpenGL-1.1, although back then it was not generic attributes, but specific ones, i.e. position, color, normal and so on) and this legacy rubbed of onto generic vertex attributes.

datenwolf
  • 149,702
  • 12
  • 167
  • 273