Hi,
I've read that shaders are just as fast as the fixed pipeline but I decided to do my own tests to be sure.
I found some interesting results. In short, I have found fragment shaders to be just as fast (if not then a little faster) than the fixed function pipeline.
However, vertex shaders seem significantly slower.
I have tested with the following code. I used a display list as this removed download bottlenecks from the equation.
#define ISURFACES 6000
glFinish();
double t1 = getTime();
glslshader->begin();
static int first=1;
glBindTexture ( GL_TEXTURE_2D, basetex );
for (int i=0;i<ISURFACES;i++)
{
float quadwidth = 20.0;
float tx=0.0;
float ty=0.0;
float h = -10.0;
glPushMatrix();
glTranslatef(xg,0.0,0.0);
if (first)
{
glNewList(DL,GL_COMPILE);
glPushMatrix();
glBegin(GL_QUADS);
for (float x = -50.0 ; x < 50.0 ; x+= quadwidth)
{
tx=0.0;
for (float y = -50.0 ; y < 50.0 ; y+= quadwidth)
{
glTexCoord2f(tx,ty);
glVertex3f(x,h,y);
glTexCoord2f(tx,ty+0.2);
glVertex3f(x,h,y+quadwidth);
glTexCoord2f(tx+0.2,ty+0.2);
glVertex3f(x+quadwidth,h,y+quadwidth);
glTexCoord2f(tx+0.2,ty);
glVertex3f(x+quadwidth,h,y);
tx+=0.2;
}
ty+=0.2;
}
glEnd();
glPopMatrix();
glEndList();
first=0;
}else
{
glCallList(DL);
}
glPopMatrix();
xg+=100.0;
}
glslshader->end();
glFinish();
fprintf(stderr,"Time elapsed=%0.2f\n",(getTime() - t1) * 1000.0);
On my GF 6800 Ultra, the above 6000 primatives with the fixed function pipeline took 4 milliseconds to render.
On the other hand, to render with a vertex shader enabled took over 10 milliseconds!
The glsl shader looks like this (pretty simple):
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
I have also tried with CG and ARB assembly shaders. All with the same results.
Is there an optimization I am missong here?