如何在D3D窗口化应用中启用VSYNC? [英] How to enable VSYNC in D3D windowed app?

查看:455
本文介绍了如何在D3D窗口化应用中启用VSYNC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So, Im using D3D in a windowed application.

我使用以下参数初始化了D3D:

I inited D3D with the following parameters:

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

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

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

据我所知(MSDN也说),一旦我设置了D3DPRESENT_INTERVAL_ONE,vsync就可以工作.

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.)

某些网站说D3DPRESENT_INTERVAL_ONE在窗口应用程序中将无法使用.

Some sites say D3DPRESENT_INTERVAL_ONE will not work in windowed applications.

我该如何启用vsync?

How can I enable vsync anyway?

p.s.我终于发现启用了D3D vsync,而某些窗口设置不正确,可能是窗口本身未同步.但是,我还没有偷看设置.

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.

推荐答案

我假设您正在使用D3D9?应该添加该标签.在您的D3DPRESENT_PARAMS变量上:

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;
}

如果您已完成此操作,并且使用的是旧版GDI,则错误的不是vsync设置,而是窗口设置.您必须启用双重缓冲,否则仍然会撕裂.

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.

这篇关于如何在D3D窗口化应用中启用VSYNC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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