VBObjects rebuild bringing about random framerate...

Started by
0 comments, last by Enrico 17 years ago
Hi everyone. I've just added vertex buffer object support to my terrain engine, and I'm allowing me to modify the terrain in real time, and so, I've allowed another option to rebuild the VBOs in order to see the changes made to the terrain (alternatively, I could've added the rebuild method to the end of each terrain modification method). However, each time I rebuild, my program seems to 'set itself' a new framerate. It's not that the framerate drops each time I rebuild; the last test I just did had the program running at a considerably lower framerate (150fps) than when I rebuilt a few times (jumping from values in between up to a more reasonable 300fps). Note that this framerate doesn't really change *during* the rebuilds, that's why I said 'set itself a new framerate'. I've added my code below. I don't know if there's anything else I should be doing before I rebuild VBOs, but, either way, can anyone help me out with the fluctuating FPS thing? Thanks. void CTerrain::BuildVBOs() { glGenBuffersARB( 1, &m_unVBOVerticesID ); glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_unVBOVerticesID ); glBufferDataARB( GL_ARRAY_BUFFER_ARB, m_nTotalVertices*3*sizeof(float), m_pcVertices, GL_STATIC_DRAW_ARB ); glGenBuffersARB( 1, &m_unVBOTexCoordsID ); glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_unVBOTexCoordsID ); glBufferDataARB( GL_ARRAY_BUFFER_ARB, m_nTotalVertices*2*sizeof(float), m_pcTexCoords, GL_STATIC_DRAW_ARB ); glGenBuffersARB( 1, &m_unVBOColoursID ); glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_unVBOColoursID ); glBufferDataARB( GL_ARRAY_BUFFER_ARB, m_nTotalVertices*3*sizeof(float), m_pcColours, GL_STATIC_DRAW_ARB ); glGenBuffersARB( 1, &m_unVBONormalsID ); glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_unVBONormalsID ); glBufferDataARB( GL_ARRAY_BUFFER_ARB, m_nTotalVertices*3*sizeof(float), m_pcNormals, GL_STATIC_DRAW_ARB ); }
Advertisement
You are generating new buffers each time without deleting the old buffers first. Somewhen you will run out of memory! Fortunately, you don't need to generate new buffers:
1) Bind desired VBO
2) Replace data with glBufferSubData()

This will be considerably faster and you will not run out of memory :)
--

This topic is closed to new replies.

Advertisement