Fabian Orue
Fabian Orue

Reputation: 193

switch between vbo binded to one vao

Currently in my render function i use a VAO (Vertex Array Object) and four VBO (Vertex Buffer Object) binded with this VAO.

for each VBO, I bind to the 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

Then in my render function (pseudocode), for each frame:

glBindVertexArray (vaoID [0]);

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

glBindVertexArray (0);

I know I can put all the geometry in a single VBO, but there are cases where its size exceeds 5Mb and this cause (possibly) that it is not placed on the GPU.

How I can switch all the binded VBO to draw them?

Upvotes: 0

Views: 1533

Answers (1)

ratchet freak
ratchet freak

Reputation: 48176

3 points:

  1. you can gen all buffers at once outside the loop:

    glGenBuffers (4,&vboID[0]); 
    
  2. you don't initialize the data in the vbos (that I can see)

  3. you will need to loop over the vbos again and set the 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);
    

Upvotes: 1

Related Questions