Libgdx使用ScreenUtils异步和不停止游戏循环

人气:1,051 发布:2022-09-11 标签: java android multithreading libgdx

问题描述

我要捕捉的屏幕。 Libgdx提供了在ScreenUtils类。

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

例如最后像素图像素图= ScreenUtils.getFrameBufferPixmap(X,Y,W,H);

我的问题是,它需要大约1-3秒,以获取该信息。在这段时间内游戏循环被阻塞,用户将其定义为滞后。

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.

在内部, ScreenUtils 类,使用 Gdx.gl.glReadPixels 。如果我在一个线程中运行 ScreenUtils.getFrameBufferPixmap 方法,没有滞后,但它在错误的方法,这是因为游戏循环运行和变化的逻辑捕获屏幕的东西。

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.

是它在某种程度上可以复制的GL上下文或保存并生成像素图在一次与线程的帮助稍后?当然,复制/保存操作,应立即做,否则我不会放过任何东西。

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.

我用 ShapeRenderer 渲染我的东西到屏幕上。

I use ShapeRenderer to render my stuff onto the screen.

推荐答案

一些研究之后,我发现更快的替代glReadPixels - 像素缓冲区对象这是由于Android 4.3可用 - 的https://vec.io/posts/faster-alternatives-to-glreadpixels-and-glteximage2d-in-opengl-es

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

这是不可能调用glReadPixels其他线程不是渲染线程 - http://stackoverflow.com/a/19975386/2158970

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

138

上一篇:拖动图像?

下一篇:BrowserSync 非常慢