I have implemented a lense flare for my game, and it looks great. The first draft used individual sprites each with its own draw call. This was very slow, so I reengineered it to use a single draw call, expecting it to be much faster. It's not.
I realise now that it is the call to glReadPixels that is the culprit. I have read that the function is slow, especially for reading the depth buffer, but I am reading only a single pixel. And my drawing goes from about 2ms to 15ms (although I'm not sure I trust my timings).
I know that glReadPixels stalls, because it has to wait for all previous operations to finish. Another point is that I would like to port my game to mobile devices at some point, and it's even worse there, perhaps impossible using the depth reading technique.
So my question is, is there a way to speed it up. For example, can I refactor things so that I only do the test at the very end, or perhaps use last frame's data. This is tricky because I have a splitscreen game and use offscreen buffers. Or should I just bite the bullet and implement raytracing. I can do this and my geomentry is simple and static, so fairly easy to use a kdtree or something, but I'd rather not if I don't need to. Thanks