Hi to all, I'm developing a plugin that allows you to render a set of vertices randomly distributed in space. I’d like to draw a huge amount of vertices at the same time: to do this I tried to use OpenGL Vertex Buffer Object (VBO), because I read that it allows vertex array data to be stored in high-performance graphics memory on the server side and promotes efficient data transfer.
This is my approach:
* Generate a new buffer object with glGenBuffersARB().
* Bind the buffer object with glBindBufferARB().
* Copy vertex data to the buffer object with glBufferDataARB().
so in my startExecution plugin function I wrote:
- (BOOL) startExecution:(id<QCPlugInContext>)context
{
CGLContextObj cgl_ctx = [context CGLContextObj];
glGenBuffersARB(1, &VBUFFERNAME);
glBindBufferARB(GL_ARRAY_BUFFER, VBUFFERNAME);
//vcArray is defined as float vcArray[numV*3]
glBufferDataARB
(GL_ARRAY_BUFFER,
sizeof(vcArray
), vcArray, GL_DYNAMIC_DRAW_ARB
);
glVertexPointer(3, GL_FLOAT, 0, 0);
return YES;
}
and in my execute plugin function I do this:
* Update vertices in vcArray using glBufferSubDataARB()
* Draw them using glDrawArrays()
- (BOOL) execute
:(id<QCPlugInContext>
)context atTime
:(NSTimeInterval
)time withArguments
:(NSDictionary*)arguments
{
CGLContextObj cgl_ctx = [context CGLContextObj];
//update vcArray vertices
updateVertices();
glEnableClientState(GL_VERTEX_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER, VBUFFERNAME);
{
glDrawArrays(GL_LINE_STRIP, 0, numV*3);
[self calcVertices];
glBufferSubDataARB
(GL_ARRAY_BUFFER,
0,
sizeof(vcArray
), vcArray
);
}
glDisableClientState(GL_VERTEX_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
return YES;
}
..the problem is that I can’t get noticeably performance improvements than the immediate mode rendering: they are the same!
For example, using VBO I got 60 FPS with 2.500 vetices, 40 FPS with 5000 verices, and 10 FPS with 20.000 vertices.. and that are the same performance I got in immediate mode, using simple code like these:
glBegin(GL_LINE_STRIP);
for(x = 0; x<numV; x++){
glVertex3f(v[x][0], v[x][1], v[x][2]);
}
glEnd();
..am I missing something in the VBO approach?
Why I can’t get performance improvements?
Thank you,
Luke