0

I need to read the pixel data from the frame buffer in OpenGL ES 2.0. I know that can be done easily with glReadPixels but since iOS 5 we can use the TextureCached objects for faster reading.

I have implemented the solution proposed by Brad Larson ( I will be always thankful to him, I think he is doing a great job for the community sharing so much knowledge...) in Faster alternative to glReadPixels in iPhone OpenGL ES 2.0

Everything seems to work, I get the proper data and if I compare it with glReadPixels, the data is identical. My problem came when I measure the performance of this 2 possible solutions (consumed time while retrieving the data).

Here my results :

(framebuffer and texture size 320x480 pixels)

GPUImageProcessingDemo[1252:707] glReadPixels 2750 us

GPUImageProcessingDemo[1252:707] Texture reading 1276 us

GPUImageProcessingDemo[1252:707] glReadPixels 2443 us

GPUImageProcessingDemo[1252:707] Texture reading 1263 us

GPUImageProcessingDemo[1252:707] glReadPixels 2494 us

GPUImageProcessingDemo[1252:707] Texture reading 1375 us

Which seems very interesting since it is almost half of the time needed when using glReadPixels. The problem is when I change the texture size to something a little bit bigger I get this results:

(framebuffer and texture size 480x620 pixels)

GPUImageProcessingDemo[1077:707] glReadPixels 2407 us

GPUImageProcessingDemo[1077:707] Texture reading 2842 us

GPUImageProcessingDemo[1077:707] glReadPixels 2392 us

GPUImageProcessingDemo[1077:707] Texture reading 3040 us

GPUImageProcessingDemo[1077:707] glReadPixels 2224 us

Does this make sense? Or should I expect to get better results always?

Community
  • 1
  • 1
tetuje
  • 279
  • 3
  • 9
  • Are you using `glFinish()` right before reading from the texture cache? You need to make sure that rendering is completed before reading from a texture, because of the deferred nature of these GPUs. This can lead to a lot of variability in timing otherwise. – Brad Larson Oct 09 '12 at 17:18
  • What do the numbers look like for much larger images? We're talking sub-millisecond differences here, so there might be some scatter in the results for smaller images like this. – Brad Larson Oct 10 '12 at 16:18
  • I did try with 1280x720 and still glReadPixel was faster, I am trying to get the times back but I dont know where I did save them. Any suggestion or idea? – tetuje Oct 16 '12 at 07:42
  • Are you using a pixel buffer pool, or re-using the same pixel buffer and texture? You need to do either to avoid the overhead of creating a new pixel buffer for each frame you're rendering, which can slow things down. – Brad Larson Oct 16 '12 at 14:21
  • I am re-using the same pixel buffer and texture for every scene, I just configure the pixel buffer and texture once during OpenGL set up and after that just read from the base address from the pixel buffer after every render. – tetuje Oct 18 '12 at 07:41

0 Answers0