【发布时间】:2017-09-23 22:07:33
【问题描述】:
我在从一个顶点缓冲区渲染多个对象时遇到问题。 我有一个包含所有顶点和多个 IBO 的 VBO。 我的想法是为 n 个 IBO 创建 n 个 VAO,并为每个 VAO 绑定 VBO 和其中一个 IBO。真的不知道如何解决这个问题。
// all indices
std::vector<std::vector<unsigned int>> allIndices;
// gen buffers for ibos
glGenBuffers(allIndices.size(),ibos);
// gen vaos
glGenVertexArray(allIndices.size(),vaos);
// vbo for vertices
glGenBuffers(1,&vbo);
glBindBuffer(GL_ARRAY_BUFFER,vbo);
glBufferData(GL_ARRAY_BUFFER,...);
// bind VAOn + IBOn + VBO
for(unsigned int x = 0; x < allIndices.size(); x++) {
glBindVertexArray(vao[x]);
// bind current ibo
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,ibo[x]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,...);
//
glBindBuffer(GL_ARRAY_BUFFER,vbo);
// how to bind this buffer to the vao without uploading the data once more?
glBindVertexArray(0);
}
我的第二个想法是连接所有索引并使用 glDrawRangeElements() 调用它们
【问题讨论】:
-
"如何在不再次上传数据的情况下将此缓冲区绑定到 vao?" 您从一开始就没有将此缓冲区附加到 VAO。将数据上传到缓冲区与将该缓冲区用于顶点数据没有任何关系(除了将顶点数据传递给它之外)。