Rendering huge amount of vertices (again)

LukeNeo's picture

Finally I can stress QC performance with a simple plugin that uses OpenGL VertexArray to draw huge amount of vertices. Results are VERY GOOD, and now I can really understand the difference between rendering primitives in the old style glBegin/glEnd and vertex arrays. You can test by your own vertex array performances using this plugin. Also, it results that rendering points is faster than rendering lines (in the plugin inputs, use primitiveType 0 for points, 1 for lines).

PreviewAttachmentSize
drawTest_00.zip23.74 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

monobrau's picture
Re: Rendering huge amount of vertices (again)

Nice! getting a steady 60fps up to 600000 vertices or 100000 lines on a early mbp2008 2.6c2d.

vade's picture
Re: Rendering huge amount of vertices (again)

If you switch to VAO, VBOs, with index buffer arrays on the GPU. VAOs are VBOs that encapsulate all state associated with the VBO (which buffers are bound where, etc) you can get even greater performance. Less draw calls, more encapsulated, pre-verified state means over-all wins.

glBegin/end is very bad for performance, especially if you want to draw lots of geometry.

LukeNeo's picture
Re: Rendering huge amount of vertices (again)

Ok, I try to switch to VBO, but It seems to not work properly. I made VBO setup in this way:

  1. #define VSIZE 500000 //Max vertices num
  2.  
  3. @interface drawTestPlugIn : QCPlugIn
  4. {
  5. ...
  6. float vcArray[VSIZE*3]; //vertices pos
  7. GLubyte pointsIndices[VSIZE]; //indices
  8.  
  9. GLuint VBUFFERNAME; //VERTEX_ARRAY_BUFFER
  10. GLuint IBUFFERNAME; //ELEMENT_ARRAY_BUFFER
  11. }
  12.  
  13. @implementation drawTestPlugIn
  14.  
  15. - (BOOL) startExecution:(id<QCPlugInContext>)context
  16. {
  17. CGLContextObj cgl_ctx = [context CGLContextObj];
  18. //init vertices position
  19. for(int x=0;x<VSIZE*3;x+=3){
  20. vcArray[x] = [self randomBetween:-XRANGE and:XRANGE];
  21. vcArray[x+1] = [self randomBetween:-YRANGE and:YRANGE];
  22. vcArray[x+2] = [self randomBetween:-ZRANGE and:ZRANGE];
  23. }
  24. //init vertices indices
  25. for(int x=0;x<VSIZE;x++){
  26. pointsIndices[x] = x;
  27. }
  28.  
  29. //setup vertexArray buffer
  30. glGenBuffers(1, &VBUFFERNAME);
  31. glBindBuffer(GL_ARRAY_BUFFER, VBUFFERNAME);
  32. glBufferData(GL_ARRAY_BUFFER, VSIZE*3*sizeof(float), vcArray, GL_STATIC_DRAW);
  33. glVertexPointer(3, GL_FLOAT, 0, vcArray);
  34.  
  35. //setup indices buffer
  36. glGenBuffers(1, &IBUFFERNAME);
  37. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBUFFERNAME);
  38. glBufferData(GL_ELEMENT_ARRAY_BUFFER, VSIZE*sizeof(GLubyte), pointsIndices, GL_STATIC_DRAW);
  39.  
  40. return YES;
  41. }
  42.  
  43.  
  44.  
  45. -(void) startRender:(id<QCPlugInContext>)context
  46. {
  47. CGLContextObj cgl_ctx = [context CGLContextObj];
  48.  
  49. glEnableClientState(GL_VERTEX_ARRAY);
  50. glBindBuffer(GL_ARRAY_BUFFER, VBUFFERNAME);
  51. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBUFFERNAME);
  52.  
  53. ...
  54. }
  55.  
  56. -(void) stopRender:(id<QCPlugInContext>)context
  57. {
  58. CGLContextObj cgl_ctx = [context CGLContextObj];
  59.  
  60. ...
  61. glDisableClientState(GL_VERTEX_ARRAY);
  62. glBindBuffer(GL_ARRAY_BUFFER, 0);
  63. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  64. }
  65.  
  66. -(void)drawVertices:(id<QCPlugInContext>)context
  67. {
  68. CGLContextObj cgl_ctx = [context CGLContextObj];
  69.  
  70. glDrawElements(GL_POINTS, numV, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
  71. }
  72.  
  73. - (BOOL) execute:(id<QCPlugInContext>)context atTime:(NSTimeInterval)time withArguments:(NSDictionary*)arguments
  74. {
  75. CGLContextObj cgl_ctx = [context CGLContextObj];
  76.  
  77. ...
  78.  
  79. numV = self.input_numVertices;
  80. if(numV > VSIZE) numV = VSIZE;
  81.  
  82. [self startRender:context];
  83. [self drawVertices:context];
  84. [self stopRender:context];
  85.  
  86. return YES;
  87. }
  88.  
  89. @end

..I follow basic VBO setup from OpenGL Redbook, but maybe I forgot something in VBO setup? :\

LukeNeo's picture
Re: Rendering huge amount of vertices (again)

I realized that this plugin may crash in Lion: the setup for Vertex Arrays I used compile well in Lion but crash in QC under Lion. Now I'm working with this kind of setup:

//variables
#define   VSIZE   2000000   //Max vertices num
float   vcArray[VSIZE*3];
 
//StartExecution()
glGenBuffers(1, &VBUFFERNAME);
   glBindBuffer(GL_ARRAY_BUFFER, VBUFFERNAME);
   glBufferData(GL_ARRAY_BUFFER, sizeof(vcArray), vcArray, GL_STATIC_DRAW);
   glVertexAttribPointer(target, 3, GL_FLOAT, GL_FALSE,0,0);
 
//Execute()
glBindBuffer(GL_ARRAY_BUFFER, VBUFFERNAME);
   glEnableVertexAttribArray(target);
   glVertexAttribPointer(target, 3, GL_FLOAT, GL_FALSE, 0, 0);
 
glDrawArrays(GL_POINTS, 0, numV);
glBindBuffer(GL_ARRAY_BUFFER, 0);
PreviewAttachmentSize
drawTest_1.1.zip19.68 KB

benoitlahoz's picture
Re: Rendering huge amount of vertices (again)

It works for me in Lion 10.7.1