如何在 D3D 窗口应用程序中启用 VSYNC?

发布于 2024-09-27 06:50:49 字数 522 浏览 12 评论 0原文

因此,我在窗口应用程序中使用 D3D。

我使用以下参数启动了 D3D:

windowed: true;
backbufferformat: D3DFMT_X8R8G8B8;
presentinterval: D3DPRESENT_INTERVAL_ONE;
swapeffect: DISCARD

每次调用 OnPaint 时,我都会将图像渲染到后缓冲区并将其呈现到前面。

据我所知(MSDN也是这么说的),一旦我设置了D3DPRESENT_INTERVAL_ONE,垂直同步就会起作用。

但在这种情况下,水平拖动时图像会撕裂。

(图像上似乎有一条线,线下方的图像显示在显示器上,上面的部分如下。)

一些网站说 D3DPRESENT_INTERVAL_ONE 在窗口应用程序中不起作用。

我怎样才能启用垂直同步?

ps我终于发现D3D垂直同步是启用的,而有些窗口设置不正确,也许窗口本身没有同步。不过,我还没有看过设置。

So, Im using D3D in a windowed application.

I inited D3D with the following parameters:

windowed: true;
backbufferformat: D3DFMT_X8R8G8B8;
presentinterval: D3DPRESENT_INTERVAL_ONE;
swapeffect: DISCARD

Each time OnPaint is called, I render the image to the backbuffer and present it to front.

As far as I know (and so does MSDN say), once I set D3DPRESENT_INTERVAL_ONE, vsync will work.

But in this case, the image is teared when dragging horizontally.

(It seems there's a line across the image, image below the line shows on the monitor and the above part follows.)

Some sites say D3DPRESENT_INTERVAL_ONE will not work in windowed applications.

How can I enable vsync anyway?

p.s. I finally found D3D vsync is enabled, while some window settings are not right that perhaps the window itself is not sync ed. though, I haven't peek the settings out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

夜深人未静 2024-10-04 06:50:49

我猜你用的是D3D9?应该添加该标签。在您的 D3DPRESENT_PARAMS 变量上:

if (bVysncEnabled)
{
    presentParams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
    presentParams.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
}
else
{
    presentParams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
    presentParams.FullScreen_RefreshRateInHz = 0;
}

如果您已完成此操作并且正在使用旧的 GDI 内容,那么问题不是您的垂直同步设置,而是窗口设置。您必须启用双缓冲,否则仍然会出现撕裂现象。

I assume you're using D3D9? Should add that tag. On your D3DPRESENT_PARAMS variable:

if (bVysncEnabled)
{
    presentParams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
    presentParams.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
}
else
{
    presentParams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
    presentParams.FullScreen_RefreshRateInHz = 0;
}

If you've done this and you're using the old GDI stuff, it's not your vsync setting that's wrong, but the window settings. You must enable double buffering or you'll still get tearing.

最丧也最甜 2024-10-04 06:50:49

在窗口模式下无法进行垂直同步,只能在全屏模式下进行。但是,您可能会通过从默认显示器获取信息并找到刷新率,然后削弱渲染器以仅以该速率渲染来限制它......尽管我不建议采用该路线。

You cannot vsync while in windowed, only in fullscreen. However, you could potentially ghetto it by getting info from the default display and finding the refresh rate, and then nerfing your renderer to only render at that rate...although I wouldn't suggest that route.

在你怀里撒娇 2024-10-04 06:50:49

您多久调用一次 ::OnPaint ?我问的原因是,您调用 ::OnPaint 的频率必须高于所连接显示器的刷新率。

对我来说,每当消息循环空闲且使窗口无效时,我都会通过强制执行 ::OnPaint 来解决刷新问题。如果您这样做,将会发生的情况是,D3D 的 RenderPresent 命令将等待,直到显卡完成渲染,这为您提供了与实际显示器刷新率同步的 ::OnPaint 的非常精确的计时!

我在这方面取得了很好的成功,上面关于窗口模式不能垂直同步的说法绝对是不正确的。即使在 DirectX 9 Win XP 中,这也能正常工作。

哦,最后但并非最不重要的一点是,如果您连接了多个显示器,请确保与呈现窗口的实际显示器垂直同步。这似乎有点棘手。

How often do you call ::OnPaint ? The reason I am asking is, that you must be calling ::OnPaint more often than the refresh rate of your attached monitor.

For me, I solved the refresh issue by forcing an ::OnPaint whenever the message loop is idle with invalidating the window. What will happen if you do that, is, that the RenderPresent command for D3D will WAIT until the graphic card finished rendering, which gives you a very precise timing of the ::OnPaint in sync with the actual monitor refresh rate !

I am having good success with this, and the statements above that windowed mode cannot vsync is definitely not true. Even in DirectX 9 Win XP, this just works.

Oh and last but not least, if you have more than one display attached, make sure to vsync with the actual display which presents your window. This seems a bit more tricky.

残龙傲雪 2024-10-04 06:50:49

不完全是 D3D,而是 AntiTearing.html 描述了 MPC-HC 如何使用窗口 EVR 等来尝试避免窗口显示的撕裂。此处的链接: http://betterlogic.com/roger/2012/05/gdi-vsync-to-avoid-tearing/ 也可能对同步有用(尽管需要解决一些问题)。

not exactly D3D, but AntiTearing.html describes how MPC-HC uses windowed EVR et al to try and avoid tearing of a windowed display. The links here: http://betterlogic.com/roger/2012/05/gdi-vsync-to-avoid-tearing/ may be useful for synchronizing, too (albeit something of a work around).

情绪操控生活 2024-10-04 06:50:49

历史上,Windowed 无法针对 d3d 进行垂直同步,直到最近,当在 WinVista 或 Win7 中启用 aero 并且应用程序未立即在演示模式下运行时,这才成为可能。

Windowed historically haven't been able to be vsynced for d3d, and only recently has this been possible, when aero is enabled in WinVista or Win7 and the app isn't running in presentation mode immidiate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文