PDA

View Full Version : Trouble moving from one VBO to multiple VBOs



Aaron
07-19-2007, 10:32 AM
I had one VBO with two objects in it working. For additional flexibility in design, I changed the code to have two VBO, one for each object. Now when I call glDrawArrays on the second VBO (order of setup) the resultant image is wrong, it looks like some data was lost. The first VBO works.

When I setup the VBOs, I fetched the identifier, bind it, enable the GL_*_ARRAY, define the offsets, transfer the data, and unbind it. Before I call glDrawArrays I bind the VBO, enable the GL_*_ARRAY, define the offsets, call DrawArrays, and then unbind it.

This should be straight forward, however it seems vertex data is getting corrupt. My VBOs are--


id=1 3,148,544 bytes facets=14056 vertices=56224
id=2 83,849,472 bytes facets = 374328 vertices = 1497312I have the GeForce 8800 GTX with 768MB of GPU memory. Has anybody else have difficulty using multiple VBOs? I wondering if I should go back to one VBO and create a management class for it.

Thanks,

Aaron

Komat
07-19-2007, 11:08 AM
Check that you uploaded correct data to the second VBO and that you uploaded them to the correct position within the buffer (e.g. at the beginning of the buffer) and that you use correct starting index in the glDrawArrays for the second object (e.g. 0).

yalmar
07-21-2007, 06:09 AM
Exactly, you must be check if your data was correctly updated.

void Polyhedron::updateVBO(){
vtx_memory_size = sizeof(pos[0])*srf_pos.size();
glBindBuffer(GL_ARRAY_BUFFER, vbo_vtx_id);
glBufferData(GL_ARRAY_BUFFER, vtx_memory_size, 0, GL_STREAM_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, vtx_memory_size, &pos[0][0]);
// check data size in VBO is same as input array, if not return 0 and delete VBO
glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &bufferSize);
assert(vtx_memory_size == bufferSize);

glBindBuffer(GL_ARRAY_BUFFER, vbo_normal_id);
glBufferData(GL_ARRAY_BUFFER, vtx_memory_size, 0, GL_STREAM_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, vtx_memory_size, &normals[0][0]);

// aditionally
// create VBO for index array
// Target of this VBO is GL_ELEMENT_ARRAY_BUFFER and usage is GL_STATIC_DRAW
fdx_memory_size = sizeof(tris[0])*tris.size();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_fdx_id); // activate vbo id to use
glBufferData(GL_ELEMENT_ARRAY_BUFFER, fdx_memory_size, &tris[0][0], GL_STATIC_DRAW); // upload data to video card

// check data size in VBO is same as input array, if not return 0 and delete VBO
glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &bufferSize);
assert(fdx_memory_size == bufferSize);

}
...
void Polyhedron::draw(){
glBindBuffer(GL_ARRAY_BUFFER, vbo_vtx_id);
glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));

// before draw, specify vertex and index arrays with their offsets
glBindBuffer(GL_ARRAY_BUFFER, vbo_normal_id);
glNormalPointer(GL_FLOAT, 0, BUFFER_OFFSET(0));

// Warning! make sure wich buffer is in use
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_fdx_id);
glIndexPointer(GL_UNSIGNED_INT, 0, 0);

// enable vertex arrays
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);

glDrawElements(GL_TRIANGLES, 3*tris.size(), GL_UNSIGNED_INT, (GLuint*)0 + 0);

glDisableClientState(GL_VERTEX_ARRAY); // disable vertex arrays
glDisableClientState(GL_NORMAL_ARRAY);

glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}Currently i'm using VBOs fine.

Aaron
07-24-2007, 04:56 AM
Thanks. I found my problem since I am using all 8 texture units I had to individual enable each TexCoord offset by using--

glClientActiveTextureAR(GL_TEXTURE1-8) and
glEnableClientState(GL_TEXTURE_COORD_ARRAY)

Thanks again for your help.

Aaron