是否需要双缓冲 [英] Is double buffering needed any more

查看:75
本文介绍了是否需要双缓冲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于当今的卡似乎保留了渲染命令列表,并且仅在调用glFlushglFinish时才刷新,因此真的需要双缓冲吗?我在Linux上开发的带有SDL/OpenGL的OpenGL游戏(ATI Mobility radeon卡)在将SDL_GL_swapbuffers()替换为glFinish()并将init代码替换为SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,0)时,实际上闪烁较少.这是我的卡的特殊情况还是所有卡上都有这种情况?

As today's cards seem to keep a list of render commands and flush only on a call to glFlush or glFinish, is double buffering really needed any more? An OpenGL game I am developing on Linux (ATI Mobility radeon card) with SDL/OpenGL actually flickers less when SDL_GL_swapbuffers() is replaced by glFinish() and with SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,0) in the init code. Is this a particular case of my card or are such things likely on all cards?

我发现这是KWin的原因.如datenwolf所说,似乎是没有同步的合成.当我关闭KWin合成时,该游戏可以正常运行,而无需任何源代码补丁

I've discovered that the cause for this is KWin. It appears that as datenwolf said, compositing without sync was the cause. When I switched off KWin compositing, the game works fine without ANY source code patches

推荐答案

双缓冲和glFinish是两个非常不同的东西.

Double buffering and glFinish are two very different things.

glFinish阻止程序,直到完成所有绘制操作.

glFinish blocks the program, until all drawing operations are completed.

双重缓冲用于向用户隐藏渲染过程.如果没有双重缓冲,则假定显示刷新频率无限高,每个绘制操作都会立即可见.在实践中,您将获得一些显示伪像,例如,场景的一部分在一种状态下可见,其余部分不可见或在其他某种状态下,图片可能不完整,等等.双重缓冲可以通过首先渲染到后缓冲区来避免这种情况,并且仅在渲染完成后再将其与前缓冲区交换回去,然后才将其发送到显示设备.

Double buffering is used to hide the rendering process from the user. Without double buffering, each and every single drawing operation would become visible immediately, assuming that the display refresh frequency is infinitely high. In practice you will get some display artifacts, like parts of the scene visible in one state, the rest not visible or in some other state, the picture could be incomplete, etc. Double buffering avoids this by first rendering into a back buffer, and only after the rendering has been finished swapping this back with the front buffer, that gets sent to the display device.

如今,合成窗口管理变得越来越普遍:Windows具有Aero,MacOS X Quartz Extreme,在Linux上,至少Unity和GNOME3 shell使用合成(如果有).关键是:从技术上讲,合成会创建双缓冲:Windows绘制屏幕外缓冲区,并在其中合并最终屏幕.因此,如果您在具有合成功能的计算机上运行,​​则双缓冲在程序中执行时是多余的,而它所需要的只是某种同步机制,以告知合成器下一帧何时准备就绪. MacOS X具有此功能. X11仍然缺乏适当的同步方案,请参阅邮件列表上的这篇文章: http: //lists.freedesktop.org/archives/xorg/2004-May/000607.html

Now today compositing window management becomes prevalent: Windows has Aero, MacOS X Quartz Extreme and on Linux at least Unity and the GNOME3 shell use compositing if available. The point is: Compositing technically creates doublebuffering: Windows draw to offscreen buffers and of these the final screen is composited. So if you're running on a machine with compositing, then double buffering is kind of redundant if performed in your program, and all it'd take was some kind of synchronization mechanism, to tell the compositor when the next frame is ready. MacOS X has this. X11 still lacks a proper synchronization scheme, see this post on the maillist: http://lists.freedesktop.org/archives/xorg/2004-May/000607.html

TL; DR:双重缓冲和glFinish是不同的东西,您需要双重缓冲(某种形式)才能使外观看起来更好.

TL;DR: Double buffering and glFinish are different things, and you need double buffering (of some sort) to make things look good.

这篇关于是否需要双缓冲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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