I'm making a 2d game involving drawing huge numbers of overlapping quads to the screen. What goes in front of what doesn't really matter.
If I draw each of my quads with z values from 0 upwards and have glDepthFunc(GL_LESS) set I get quite a nice speed boost as you would expect. This is to avoid having to draw quads which are either totally hidden or partially hidden behind other quads. So I draw the quads using something like:
float small = (float(1)/1000000);
for (int iii = 0; iii < 100000; iii++) {
freeSpace = bullets[iii]->draw(opengl, freeSpace, iii*small);
}
However as I don't use the z value for actual depth it seems like I should be able to just go:
for (int iii = 0; iii < 100000; iii++) {
freeSpace = bullets[iii]->draw(opengl, freeSpace, 0.0f);
}
Or just code the z value of 0.0f into the shader. (the 3rd argument is the z value and ends up being set to gl_position in the shader unchanged.)
The strange thing is that the second method (where I set the z value to 0.0f everytime), ends up getting almost less than half the framerate of the former.
Why is this? They both use glDepthFunc(GL_LESS) and
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 100000*(2*3));
Just the same. I would think that if any setting the z to 0.0f each time would be faster. Why is it not?