I’m trying to render as many points as I can and am having trouble with optimising…
I’m currently trying to render 30000 points although this is variable according to platform I will run on, the values for each point (color and position ) change every frame so there is unfortunately no chance to use display lists.
The original implementation (at the start of the code) is by far the fastest, even though looking at the OpenGL documentation it should be the slowest…
The simple for->glColor->glVertex->next loop takes 9.5ms, using the glColor4fv and glVertex3fv calls slows the render down to
11ms.
I’ve also tried vertex arrays, two types, the OpenGL version and OpenGL_EXT version (see code segment below) which I also though should be faster, but rendering speed drops now to 13.5ms for both implementations (is there any performance differences between these two implementations?).
So I’m I missing something very obvious? or am I getting the performance people expect…
Platforms this has been tested on include:
NVidia Quadro
NVidia GeForce 440 Go
SGI Onyx IR3
SGI Onyx IR4
Any ideas would be very welcome!
/* Draw Points */
glEnable( GL_POINT_SMOOTH );
glPointSize( sh->pntSize );
if( sh->useVertexArray == 0 )
{
/* traditional immediate mode */
glBegin( GL_POINTS );
for( i = 0 ; i < sh->numStars ; i++ )
{
/* this is faster than... */
glColor3f( sh->col[i][0], sh->col[i][1], sh->col[i][2] /*, sh->col[i][4] */ );
glVertex3f( sh->pos[i][0], sh->pos[i][1], sh->pos[i][2] );
/* than this ... */
// glColor4fv( sh->col[i] );
// glVertex3fv( sh->pos[i] );
}
glEnd();
} else {
int loop = 0;
int numLoops;
int loopVerts;
/*--- vertex arrays version 1 ---*/
/*
glGetIntegerv( GL_MAX_ELEMENTS_VERTICES, &loopVerts );
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_COLOR_ARRAY );
glColorPointer( 4, GL_FLOAT, 0, sh->col );
glVertexPointer( 3, GL_FLOAT, 0, sh->pos );
numLoops = sh->numStars / loopVerts;
for( i = 0 ; i < numLoops ; i++ )
{
glDrawArrays( GL_POINTS, loop, loopVerts );
loop += loopVerts;
}
glDrawArrays( GL_POINTS, loop, (sh->numStars - loop) );
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_COLOR_ARRAY ); */
/*--- vertex arrays version 2 ---*/
glEnable( GL_VERTEX_ARRAY_EXT );
glEnable( GL_COLOR_ARRAY_EXT );
glVertexPointerEXT( 3, GL_FLOAT, 0, sh->numStars, sh->pos );
glColorPointerEXT( 4, GL_FLOAT, 0, sh->numStars, sh->col );
glDrawArraysEXT( GL_POINTS, 0, sh->numStars );
glDisable( GL_VERTEX_ARRAY_EXT );
glDisable( GL_COLOR_ARRAY_EXT );
}