I wrote a sample application that reads the pixels from a small box in the center of the screen. Dimensions are typically 32x32.
I am working with a GEForce3
The time it takes is about .08 ms.
This is fine.
If I run the same code subroutine, (actually, I have timed it down to the glReadPixels call), in a far more complex app, then it takes about .4ms, a factor of five times bigger.
The first program was very simple, it just had a model rotating in the scene, whereas the second program has all sorts of crud in it.
I don’t understand why this makes a difference though, since it should be reading the framebuffer, and not doing depth-testing or anything like that.
Anybody have any ideas?
BTW I also ran program #1, while #2 was running, to see if the card was simply getting maxxed out, but the speeds remained the same for both programs.
Try setting up opengl to render to a texture, there are some demo code sets in the Opengl.org news that have popped up to do just that. That doesn’t break the opengl pipeline, as I understand it (which I may not), and therefore is a little safer than using the glReadPixels().
Thanks for the quick replies. I should have included an additional piece of information.
I render straight to texture for other parts of this app, which is MUCH faster than the glReadPixels, then draw it.
This time, I don’t actually want to draw anything, I only want to see what is underneath, and do some simple math. If I render to texture, with glCopyTexSubImage or something similiar, then I still need to do something so I can actually look at the data it has fed the texture.
glTexImage2D sets up the texture, with the data, but how do you read it back once you have the handle?
reading back means waiting till the gpu actually has processed all your fancy commands. you think the gpu is yet finished after calling glCopyTexSubImage? it DIDNT EVEN BEGAN YET!. it’ll do as soon as it has finished all the other jobs. every readback is slow if you don’t tell the gpu before that you want something back, and there are only very few features wich you can request something and get it later.
to view your stuff on the texture, just plot it on screen
every glGet in any form WILL STALL THE PIPELINE if you need to get data that is NOT YET GENERATED. so copy to tex, do something else and then glGet could be faster yeah. dunno