简体   繁体   English

OpenGL如何知道应基于GL_ARRAY_BUFFER将顶点绘制到什么位置?

[英]How does OpenGL know to what position it should draw the vertices based on the GL_ARRAY_BUFFER?

For example, I have the following piece of code: 例如,我有以下代码:

//Create a vbo and bind it to the GL_ARRAY_BUFFER
glGenBuffers(1, &positionBufferObject);    
glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);

//vertexPosition is an array of floats that stores the position of 3 vertices (x, y, z, w)
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW);

//Enable the vbo at index 0 of the vao (assuming I have stored it previously at index 0)
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);

//Finally draw the triangle
glDrawArrays(GL_TRIANGLES, 0, 3);

My question is, how does glDrawArrays() know that whatever is bound to the GL_ARRAY_BUFFER refers to information about position, and not about colors for example? 我的问题是,glDrawArrays()如何知道绑定到GL_ARRAY_BUFFER的内容是指位置信息,而不是颜色信息?

Where gl_Vertex is available (ie not a core profile), the specification calls out that position and vertex attribute 0 alias. 如果gl_Vertex可用(即没有核心配置文件),则规范会调用该位置和顶点属性0别名。

From the gl 4.5 compatibility profile specification (page 401/1005): gl 4.5兼容性配置文件规范 (第401/1005页):

Setting generic vertex attribute zero specifies a vertex, as described in section 10.7.2. 将通用顶点属性设置为零会指定一个顶点,如10.7.2节所述。 Setting any other generic vertex attribute updates the current values of the attribute. 设置任何其他通用顶点属性将更新该属性的当前值。 There are no current values for vertex attribute zero 顶点属性零没有当前值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM