如何避免在Linux / X11上使用pygame进行撕裂

时间:2021-07-29 02:18:53

I've been playing with pygame (on Debian/Lenny). It seems to work nicely, except for annoying tearing of blits (fullscreen or windowed mode).

我一直在玩pygame(在Debian / Lenny上)。它似乎工作得很好,除了烦人的blits撕裂(全屏或窗口模式)。

I'm using the default SDL X11 driver. Googling suggests that it's a known issue with SDL that X11 provides no vsync facility (even with a display created with FULLSCREEN|DOUBLEBUF|HWSURFACE flags), and I should use the "dga" driver instead.

我正在使用默认的SDL X11驱动程序。谷歌搜索表明SDL的一个已知问题是X11没有提供vsync功能(即使使用FULLSCREEN | DOUBLEBUF | HWSURFACE标志创建显示),我应该使用“dga”驱动程序。

However, running

SDL_VIDEODRIVER=dga ./mygame.py

throws in pygame initialisation with

抛出pygame初始化

pygame.error: No available video device

(despite xdpyinfo showing an XFree86-DGA extension present).

(尽管xdpyinfo显示了XFree86-DGA扩展)。

So: what's the trick to getting tear-free vsynced flips ? Either by getting this dga thing working or some other mechanism ?

所以:获得无泪vsynced翻转的诀窍是什么?通过让这个dga工作或其他机制?

2 个解决方案

#1


The best way to keep tearing to a minimum is to keep your frame rate as close to the screen's frequency as possible. The SDL library doesn't have a vsync unless you're running OpenGL through it, so the only way is to approximate the frame rate yourself. The SDL hardware double buffer isn't guaranteed, although nice when it works. I've seldomly seen it in action.

将撕裂率降至最低的最佳方法是尽可能使帧速率尽可能接近屏幕频率。除非您通过它运行OpenGL,否则SDL库没有vsync,因此唯一的方法是自己估算帧速率。 SDL硬件双缓冲区不能保证,但它很好用。我很少看到它在行动。

In my experience with SDL you have to use OpenGL to completely eliminate tearing. It's a bit of an adjustment, but drawing simple 2D textures isn't all that complicated and you get a few other added bonuses that you're able to implement like rotation, scaling, blending and so on.

根据我使用SDL的经验,您必须使用OpenGL来彻底消除撕裂。这是一个调整,但绘制简单的2D纹理并不是那么复杂,你可以获得一些其他额外的奖励,你可以实现旋转,缩放,混合等。

However, if you still want to use the software rendering, I'd recommend using dirty rectangle updating. It's also a bit difficult to get used to, but it saves loads of processing which may make it easier to keep the updates up to pace and it avoids the whole screen being teared (unless you're scrolling the whole play area or something). As well as the time it takes to draw to the buffer is at a minimum which may avoid the blitting taking place while the screen is updating, which is the cause of the tearing.

但是,如果您仍想使用软件渲染,我建议使用脏矩形更新。它也有点难以习惯,但它节省了大量的处理,这可以使更容易保持更新的速度,并避免整个屏幕被撕裂(除非你滚动整个游戏区域或其他东西)。除了绘制到缓冲区所花费的时间至少可以避免在屏幕更新时发生blitting,这是撕裂的原因。

#2


Well my eventual solution was to switch to Pyglet, which seems to support OpenGL much better than Pygame, and doesn't have any flicker problems.

我最终的解决方案是切换到Pyglet,它似乎比Pygame更好地支持OpenGL,并且没有任何闪烁问题。

#1


The best way to keep tearing to a minimum is to keep your frame rate as close to the screen's frequency as possible. The SDL library doesn't have a vsync unless you're running OpenGL through it, so the only way is to approximate the frame rate yourself. The SDL hardware double buffer isn't guaranteed, although nice when it works. I've seldomly seen it in action.

将撕裂率降至最低的最佳方法是尽可能使帧速率尽可能接近屏幕频率。除非您通过它运行OpenGL,否则SDL库没有vsync,因此唯一的方法是自己估算帧速率。 SDL硬件双缓冲区不能保证,但它很好用。我很少看到它在行动。

In my experience with SDL you have to use OpenGL to completely eliminate tearing. It's a bit of an adjustment, but drawing simple 2D textures isn't all that complicated and you get a few other added bonuses that you're able to implement like rotation, scaling, blending and so on.

根据我使用SDL的经验,您必须使用OpenGL来彻底消除撕裂。这是一个调整,但绘制简单的2D纹理并不是那么复杂,你可以获得一些其他额外的奖励,你可以实现旋转,缩放,混合等。

However, if you still want to use the software rendering, I'd recommend using dirty rectangle updating. It's also a bit difficult to get used to, but it saves loads of processing which may make it easier to keep the updates up to pace and it avoids the whole screen being teared (unless you're scrolling the whole play area or something). As well as the time it takes to draw to the buffer is at a minimum which may avoid the blitting taking place while the screen is updating, which is the cause of the tearing.

但是,如果您仍想使用软件渲染,我建议使用脏矩形更新。它也有点难以习惯,但它节省了大量的处理,这可以使更容易保持更新的速度,并避免整个屏幕被撕裂(除非你滚动整个游戏区域或其他东西)。除了绘制到缓冲区所花费的时间至少可以避免在屏幕更新时发生blitting,这是撕裂的原因。

#2


Well my eventual solution was to switch to Pyglet, which seems to support OpenGL much better than Pygame, and doesn't have any flicker problems.

我最终的解决方案是切换到Pyglet,它似乎比Pygame更好地支持OpenGL,并且没有任何闪烁问题。