Sign in to follow this  
industrion

VBObjects rebuild bringing about random framerate...

Recommended Posts

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 ); }

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this