I’ve spent the last several hours trying to figure out why after I call glBufferDataARB, if I delete the data I passed it, nothing is displayed. From my understanding I should be able to do this because the data should be safely copied into the card’s video memory. Here’s my code to build the VBOs:
void Hex2DPlot::BuildVBOs()
{
glGenBuffersARB( 1, &m_VBOVertices );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_VBOVertices );
glBufferDataARB( GL_ARRAY_BUFFER_ARB, m_vertices.size()*sizeof(GLdouble), &(m_vertices[0]), GL_STATIC_DRAW_ARB );
glGenBuffersARB( 1, &m_VBOColors );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_VBOColors ); // Bind The Buffer
glBufferDataARB( GL_ARRAY_BUFFER_ARB, m_colors.size()*sizeof(GLubyte), &(m_colors[0]), GL_STATIC_DRAW_ARB );
// PROBLEM: I should be able to uncomment this but for some reason I can't
//m_vertices.clear();
//m_colors.clear();
}
Notice the commented out part there. Uncommenting it makes it so nothing is drawn (thus the problem). Here’s the code I use to draw:
void Hex2DPlot::DrawPlot()
{
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_VBOVertices);
glVertexPointer( 2, GL_DOUBLE, 0, (char *) NULL );
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_VBOColors);
glColorPointer( 3, GL_UNSIGNED_BYTE, 0, (char *) NULL );
glDrawArrays(GL_TRIANGLE_STRIP, 0, m_vertices.size() / 2);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
}
I’ve been tearing my hair out trying to figure out why I can’t uncomment those two lines. I made a really weird discovery though. The call to DrawPlot normally happens inside a display list. When this is the case, the program chokes when glDrawArrays is called – it pauses there for about twenty seconds. But after that the calls to draw the list are very speedy and the scene draws just fine (this is assuming that the lines above are still commented out).
Now, if I don’t use a display list and just call DrawPlot every frame, drawing is terribly slow, but the scene appears instantly instead of choking for 20 seconds. I think this is somehow related, but I can’t figure it out.
Any ideas on why the weird performance load/render tradeoff or why I can’t uncomment those lines?