双缓冲和 libgdx

2022-01-12 00:00:00 buffer java libgdx

我在 libgdx 中有一个非常简单的应用程序.它目前应该用粉红色的纹理覆盖一半的屏幕.它确实做到了,但是纹理在闪烁.基于我自己对主题的理解,以及这个线程:LibGDX 闪烁我需要启用双缓冲.或者,写入我的缓冲区.问题是,要么我对 google 无能,要么很难找到任何关于如何在 libgdx 中操作缓冲区的信息.如果有人可以为我提供资源,解释如何操作缓冲区,以及如何创建缓冲区,如何将它们与当前显示交换等.我将非常感激.

I have a very simple application in libgdx. It currently is supposed to cover half of the screen with pink texture. And it does that, the texture however is blinking. Basing on my own understanding of subject, as well as this thread: LibGDX blinking I need to enable double buffering. Or alternatively, write to my buffer. The thing is, either I am inept with google or it's very difficult to find any information how to manipulate buffers in libgdx. If someone could provide me with resources, explaining how to manipulate buffers, and how to create one, how to swap them with current display etc. I would be very grateful.

在网上搜索了一些之后,我在 badlogic 论坛上找到了帖子,声称 libgdx 默认设置了双缓冲.问题是,它是如何工作的?缓冲区何时交换?

After searching the web some more, I found post on badlogic forum, claiming that libgdx has double buffering set by default. The question is, how does it work? When are the buffers swapped?

推荐答案

Libgdx 默认启用双缓冲(它实际上是底层 OpenGL 基础架构的一部分,而不是 Libgdx).我不认为 Libgdx 公开了对双缓冲的任何控制.有一些控件可以禁用垂直同步,这可能会造成一些撕裂,但不太可能相关.

Libgdx has double buffering enabled by default (its really part of the underlying OpenGL infrastructure, not Libgdx). I don't think Libgdx exposes any controls over double buffering. There are some controls to disable vsync which might create some tearing, but are unlikely to be related.

获得这种行为的更可能的方法是,如果您的 render 方法仅被调用一次.这将绘制到一个缓冲区中.然后,假设 render 已成为无操作,没有任何内容被绘制到另一个缓冲区中,它们被切换,没有任何内容被绘制到原始缓冲区中,它们被切换等等.这可能导致您看到的闪烁行为.

The more likely way to get this behavior is if, somehow, your render method is only invoked once. This will draw into one buffer. Then, assuming render has become a no-op, nothing is drawn into the other buffer, they're switched, nothing is drawn into the original buffer, they're switched, etc. This can lead to the blinking behavior you're seeing.

如果该猜测没有涵盖它,您将不得不提供更多详细信息.你在哪个平台上运行?您是在运行稳定版本的 Libgdx 还是每晚构建的版本之一?您如何设置 libgdx 应用程序配置?您的 render 方法实际上是什么样的?

If that guess doesn't cover it you'll have to provide more details. Which platform are you running on? Are you running a stable version of Libgdx or one of the nightly builds? How are you setting up the libgdx app configuration? What does your render method actually look like?

相关文章