OGL

Rendering huge amount of vertices (VBO)

LukeNeo's picture

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:

  1. - (BOOL) startExecution:(id<QCPlugInContext>)context
  2. {
  3. CGLContextObj cgl_ctx = [context CGLContextObj];
  4.  
  5. glGenBuffersARB(1, &VBUFFERNAME);
  6. glBindBufferARB(GL_ARRAY_BUFFER, VBUFFERNAME);
  7. //vcArray is defined as float vcArray[numV*3]
  8. glBufferDataARB(GL_ARRAY_BUFFER, sizeof(vcArray), vcArray, GL_DYNAMIC_DRAW_ARB);
  9. glVertexPointer(3, GL_FLOAT, 0, 0);
  10.  
  11. return YES;
  12. }

and in my execute plugin function I do this:
* Update vertices in vcArray using glBufferSubDataARB()
* Draw them using glDrawArrays()

  1. - (BOOL) execute:(id<QCPlugInContext>)context atTime:(NSTimeInterval)time withArguments:(NSDictionary*)arguments
  2. {
  3. CGLContextObj cgl_ctx = [context CGLContextObj];
  4.  
  5. //update vcArray vertices
  6. updateVertices();
  7.  
  8. glEnableClientState(GL_VERTEX_ARRAY);
  9. glBindBufferARB(GL_ARRAY_BUFFER, VBUFFERNAME);
  10. {
  11. glDrawArrays(GL_LINE_STRIP, 0, numV*3);
  12. [self calcVertices];
  13. glBufferSubDataARB(GL_ARRAY_BUFFER, 0, sizeof(vcArray), vcArray);
  14. }
  15. glDisableClientState(GL_VERTEX_ARRAY);
  16. glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
  17.  
  18. return YES;
  19. }

..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:

  1. glBegin(GL_LINE_STRIP);
  2. for(x = 0; x<numV; x++){
  3. glVertex3f(v[x][0], v[x][1], v[x][2]);
  4. }
  5. glEnd();

..am I missing something in the VBO approach? Why I can’t get performance improvements?

Thank you, Luke