Libgdx使用ScreenUtils异步和不停止游戏循环 [英] Libgdx use ScreenUtils asynchronously and don't stop the game loop

查看:364
本文介绍了Libgdx使用ScreenUtils异步和不停止游戏循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要捕捉的屏幕。 Libgdx提供了在<定义的某些功能href=\"https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/utils/ScreenUtils.java\">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其他线程不是渲染线程 - <一个href=\"http://stackoverflow.com/a/19975386/2158970\">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

这篇关于Libgdx使用ScreenUtils异步和不停止游戏循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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