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

大城市里の小女人 提交于 2019-12-10 14:15:38

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/24717228/libgdx-use-screenutils-asynchronously-and-dont-stop-the-game-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!