OpenGL读取像素的速度比glReadPixels快 [英] OpenGL read pixels faster than glReadPixels

查看:320
本文介绍了OpenGL读取像素的速度比glReadPixels快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以提高glReadPixels的速度?目前我正在这样做:

Is there a way to increase the speed of glReadPixels? Currently I do:

Gdx.gl.glReadPixels(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixels);

问题是它阻止了渲染并且速度很慢.

The problem is that it blocks the rendering and is slow.

我听说过像素缓冲区对象,但是我不确定如何连接它以及它是否更快.

I have heard of Pixel Buffer Objects, but I am quite unsure on how to wire it up and whether it is faster or not.

还有除了glReadPixels以外的其他稀释液吗?

Also is there any other solutation than glReadPixels?

基本上,我想尽可能快地截取屏幕截图,而又不影响下一个场景的绘制.

Basically, I want to take a screenshot as fast as possible, without blocking the drawing of the next scene.

推荐答案

有没有办法提高glReadPixels的速度?

Is there a way to increase the speed of glReadPixels?

嗯,该操作的速度实际上不是主要问题.它必须将一定数量的字节从帧缓冲区传输到系统内存.在典型的带有离散GPU的台式机系统中,这涉及通过PCI-Express发送数据,而这没有办法解决.

Well, the speed of that operation is actually not the main issue. It has to transfer a certain amount of bytes from the framebuffer to your system memory. In your typical desktop system with a discrete GPU, that involvs sending the data over PCI-Express, and there is no way around that.

但是正如您Aready所说,隐式同步是一个大问题.如果您尽快需要该像素数据,那么您真的无法比同步回读做得更好.但是,如果您以后可以继续获取这些数据,则可以通过像素缓冲区对象(PBO)进行异步回读.

But as you aready stated, the implicit synchronization is a big issue. If you need that pixel data as soon as possible, you can't really do much better than that synchronous readback. But if you can live with getting that data later, asynchronous readback via pixel buffer objects (PBOs) is the way to go.

其伪代码为:

  1. 创建PBO
  2. 将PBO绑定为GL_PIXEL_PACK_BUFFER
  3. 执行glReadPixels
  4. 做其他事情.两者都可以在CPU上工作,并为GPU发出新命令.
  5. 使用glGetBufferSubData或映射PBO进行读取以从PBO读取数据.
  1. create PBO
  2. bind PBO as GL_PIXEL_PACK_BUFFER
  3. do the glReadPixels
  4. do something else. Both work on the CPU and issuing new commands for the GPU is ideal.
  5. Read back the data from PBO by either using glGetBufferSubData or by mapping the PBO for reading.

关键点是第5步的时间安排.我要尽早这样做,但仍会阻止客户端,因为它将等待数据可用.对于某些屏幕截图,不难将这一步延迟一两帧.这样,它只会对整体渲染性能产生很小的影响,并且不会使GPU和CPU停顿.

The crucial point is the timing of step 5. I you do that to early, you still blocking the client side, as it will wait for the data to become available. For some screenshots, It should not be hard to delay that step for even one or two frames. That way, it will have only a slight impact on the overall render performance, and it will neither stall the GPU nor the CPU.

这篇关于OpenGL读取像素的速度比glReadPixels快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆