0

目前在我的渲染函数中,我使用一个 VAO(顶点数组对象)和四个与这个 VAO 绑定的 VBO(顶点缓冲区对象)。

对于每个 VBO,我绑定到 vao

glGenVertexArrays (1, & vaoID [0]); // Create our Vertex Array Object
glBindVertexArray (vaoID [0]); // Bind our Vertex Array Object so we can use it

int i = 0;
for (i = 0; i <4, ++i)
{
glGenBuffers (1,vboID [i]); // Generate Vertex Buffer Object
glBindBuffer (GL_ARRAY_BUFFER, vboID [i]); // Bind Vertex Buffer Object
glBufferData (GL_ARRAY_BUFFER, 18 * sizeof (GLfloat) vertices, GL_STATIC_DRAW);

glVertexAttribPointer ((GLuint) 0, 3, GL_FLOAT, GL_FALSE, 0, 0);
  }

glEnableVertexAttribArray (0); // Disable Vertex Array Object
glBindVertexArray (0); // Disable Vertex Buffer Object

然后在我的渲染函数(伪代码)中,对于每一帧:

glBindVertexArray (vaoID [0]);

// here, I need to draw the four VBO, but only draws the first

glBindVertexArray (0);

我知道我可以将所有几何图形放在一个 VBO 中,但在某些情况下它的大小超过 5Mb,这导致(可能)它没有放在 GPU 上。

我如何切换所有绑定的 VBO 来绘制它们?

4

1 回答 1

1

3分:

  1. 您可以在循环外一次生成所有缓冲区:

    glGenBuffers (4,&vboID[0]); 
    
  2. 您没有初始化 vbos 中的数据(我可以看到)

  3. 您将需要再次遍历 vbos 并设置glVertexAttribPointer

    glBindVertexArray (vaoID [0]);
    for(int i = 0; i < 4; i++){
        glBindBuffer (GL_ARRAY_BUFFER, vboID [i]);
        glVertexAttribPointer ((GLuint) 0, 3, GL_FLOAT, GL_FALSE, 0, 0);
        //drawArrays
    }
    glBindVertexArray (0);
    
于 2014-11-03T12:39:50.653 回答