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

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

本文关键字:BUFFER ARRAY 绘制 位置 什么 顶点 GL 何知道 OpenGL      更新时间:2023-10-16

例如,我有以下代码:

//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);

我的问题是,glDrawArrays()如何知道绑定到GL_ARRAY_BUFFER的是关于位置的信息,而不是关于颜色的信息?

如果gl_Vertex可用(即不是核心配置文件),则规范会调用该位置和顶点属性0别名。

来自gl 4.5兼容性配置文件规范(第401/1005页):

将通用顶点属性设置为零将指定一个顶点,如下所示如第10.7.2节所述。设置任何其他常规顶点属性更新属性的当前值。没有顶点属性零的当前值