Why is there the need for the index argument in glEnableVertexAttribArray? [duplicate]

断了今生、忘了曾经 提交于 2019-12-14 03:27:43

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/39815782/why-is-there-the-need-for-the-index-argument-in-glenablevertexattribarray

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