I am using glReadPixels
to take a snapshot at regular intervals in drawFrame
method of GLSurfaceView.Renderer
. I need to take this snapshot at regular intervals to keep saving my data as per my app requirements.
However glReadPixels
performance is really slow and shows a lag. Here's how I use the method:
gl.glReadPixels(0, 0, 1280, 752, GL10.GL_RGBA,GL10.GL_UNSIGNED_BYTE, bb);
Is there a alternative to use glReadPixels
? How can I save the image without causing a lag?
Yes, glReadPixels() is a VERY slow.
In particular, PBOs are a way to improve asynchronous behavior between the application and OpenGL. Therefore, the first thing that you need to do in order to properly take advantage of them is to actually have something to do while you are waiting for the transfer to complete.
I don't know if that is available on android, but maybe PBOs (Pixel buffer objects) will give a performance boost. See this OpenGL.org thread.
However, don't expect miracles! With a 1280*752 RGBA image, you are transfering 3.67 MB of data each frame. I don't know the figures for Android, but I would bet you are facing a memory bandwidth or hard drive write bottleneck. If you reduce the size of your readPixel and get much better performance, you know that's the problem.
Also, do you need the "A" component? Maybe reading back RGB is faster. Try reading back in different formats. Some are way faster than others because they map better to the OpenGL memory representation. For example, BGRA might be faster than RGBA. When the you request a format that doesn't match what OpenGL has, each pixel must be converted during the operation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With