glReadPixels 太慢而无法使用
我正在使用 glReadPixels
在 GLSurfaceView.Renderer
的 drawFrame
方法中定期拍摄快照。我需要定期拍摄此快照,以便根据我的应用程序要求保存数据。
然而,glReadPixels
性能确实很慢并且显示出滞后。以下是我如何使用该方法:
gl.glReadPixels(0, 0, 1280, 752, GL10.GL_RGBA,GL10.GL_UNSIGNED_BYTE, bb);
是否有使用 glReadPixels
的替代方法?如何保存图像而不造成延迟?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道这在 Android 上是否可用,但也许 PBO(像素缓冲区对象)会带来性能提升。请参阅此 OpenGL.org 主题。
但是,不要指望奇迹!对于 1280*752 RGBA 图像,每帧传输 3.67 MB 的数据。我不知道 Android 的数据,但我敢打赌您正面临内存带宽或硬盘写入瓶颈。如果您减小 readPixel 的大小并获得更好的性能,您就知道这就是问题所在。
另外,您需要“A”组件吗?也许读回 RGB 更快。尝试以不同的格式回读。有些比其他快得多,因为它们更好地映射到 OpenGL 内存表示。例如,BGRA 可能比 RGBA 更快。当您请求的格式与 OpenGL 所具有的格式不匹配时,必须在操作过程中转换每个像素。
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.