OpenGL 如何知道应该根据 GL_ARRAY_BUFFER 将顶点绘制到什么位置?
How does OpenGL know to what position it should draw the vertices based on the GL_ARRAY_BUFFER?
比如我有下面一段代码:
//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 compatibility profile specification(第 401/1005 页):
Setting generic vertex attribute zero specifies a vertex, as
described in section 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
比如我有下面一段代码:
//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 compatibility profile specification(第 401/1005 页):
Setting generic vertex attribute zero specifies a vertex, as described in section 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