为什么在glEnableVertexAttribArray中需要index参数? [英] Why is there the need for the index argument in glEnableVertexAttribArray?
问题描述
使用glVertexAttribPointer
,opengl实现已经知道顶点着色器中的属性位置/索引绑定了顶点属性对象,那么为什么又需要在glEnableVertexAttribArray
中提供属性索引呢?我认为在使用glBindVertexArray(VAO)之后;仅使用glEnableVertexAttribArray()
就足够了吗?为什么需要两次提供属性索引; glVertexAttribPointer
中的一个和glEnableVertexAttribArray()
中的一个?
请多多包涵,我是初学者,我还不知道OpenGL的所有方面.
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.
[此问题不是重复的,因为有些人试图将其标记为重复,以重定向到他们在一些不相关的问题上的答案,以获得评分,这是自私的行为!如果您不知道如何回答,请不要通过标记为重复来破坏问题.]
推荐答案
因为可以使用glVertexAttrib
.是的,您也可以使用统一的方法达到相同的效果,但是这种从值(从数组获取或设置常量)来的按属性选择已经存在了很长时间(自OpenGL-1.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.
这篇关于为什么在glEnableVertexAttribArray中需要index参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!