Libgdx use ScreenUtils asynchronously and don't stop the game loop

I want to capture the screen. Libgdx provides some functions defined in the ScreenUtils class.

For instance final Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(x, y, w, h);

My problem is that it takes about 1-3 seconds to get that information. During that time the game loop is blocked and the user will define it as a lag.

Internally the ScreenUtils class, uses Gdx.gl.glReadPixels . If I run the ScreenUtils.getFrameBufferPixmap method in a thread, there is no lag, but it captures the screen at the wrong method, which is logical since the game loop runs and changes stuff.

Is it somehow possible to copy the GL context or save it and generate the Pixmap at a later point of time with the help of a Thread? Of course the copy/save operation should be done instantly, otherwise I don't spare anything.

I use ShapeRenderer to render my stuff onto the screen.


After little research I have found faster alternative to glReadPixels - Pixel Buffer Object which is available since Android 4.3 - https://vec.io/posts/faster-alternatives-to-glreadpixels-and-glteximage2d-in-opengl-es

It is not possible to call glReadPixels on other thread than render thread - https://stackoverflow.com/a/19975386/2158970


I have found a solution, which works in my case since I have only minor graphics / shapes. Basically I copy all the objects, which are drawn to the view, as described here. In a background thread I generate a Bitmap programmatically and use the information stored in my objects to draw to the bitmap.

链接地址: http://www.djcxy.com/p/21728.html

上一篇: 中间人攻击和SSL

下一篇: Libgdx异步使用ScreenUtils并且不停止游戏循环