C++ 在directx11代码中更改全屏模式下的刷新率无效

C++ 在directx11代码中更改全屏模式下的刷新率无效,c++,directx-11,C++,Directx 11,我希望能够在代码中首次初始化后更改刷新率。 我用的是DX11.0 据我目前所知,基本上有两种方法可以做到这一点。 第一个是使用IDXGIFactory::CreateSwapChain以所需的刷新率重新创建swapchain。 第二个是使用IDXGISwapChain::ResizeTarget。用所需的刷新率填充说明 下面是第一种方法的代码: DXGI_SWAP_CHAIN_DESC swapchain_desc; ZeroMemory(&swapchain_desc,sizeof(s

我希望能够在代码中首次初始化后更改刷新率。 我用的是DX11.0 据我目前所知,基本上有两种方法可以做到这一点。 第一个是使用IDXGIFactory::CreateSwapChain以所需的刷新率重新创建swapchain。 第二个是使用IDXGISwapChain::ResizeTarget。用所需的刷新率填充说明

下面是第一种方法的代码:

DXGI_SWAP_CHAIN_DESC swapchain_desc;
ZeroMemory(&swapchain_desc,sizeof(swapchain_desc));
sSwapChain->GetDesc(&swapchain_desc);//get the description from the original swapchain

//release the backbuffer
sContext->ClearState();
sContext->Flush();

sBackBufferRenderTargetView.Release();
sBackBufferTexture.Release();

//release the current swapchain
sSwapChain.Release();

//create the new swapchain with my desired refreshrate
swapchain_desc.BufferDesc.Width = sDeviceMode.dmPelsWidth;//sDeviceMode is a device mode specified by user
swapchain_desc.BufferDesc.Height = sDeviceMode.dmPelsHeight;
swapchain_desc.BufferDesc.RefreshRate.Numerator= sDeviceMode.dmDisplayFrequency;
swapchain_desc.Windowed = false;

COMPtr<IDXGISwapChain> pSwapChain;
HRESULT hr = sDXGIFactory->CreateSwapChain(sD3D11Device,&swapchain_desc,&pSwapChain);
gAssert(SUCCEEDED(hr));
hr = pSwapChain->QueryInterface(&sSwapChain);
gAssert(SUCCEEDED(hr));

sSwapChain->SetFullscreenState(true,nullptr);
sSwapchain->ResizeTarget的返回结果也是S_OK,但是我想要的刷新率没有设置到监视器


如果有人能指出我的错误,我们将不胜感激。

文档中说,您必须在
DXGI\u SWAP\u CHAIN\u FLAG\u ALLOW\u MODE\u SWITCH\u DESC::Flags
字段中设置
DXGI\u SWAP\u CHAIN\u DESC::Flags
标志才能切换视频模式。

ohhhhhhh!!!这就解决了问题!非常感谢你!!
DXGI_MODE_DESC mode_desc;
ZeroMemory(&mode_desc,sizeof(mode_desc));

mode_desc.Width = sDeviceMode.dmPelsWidth;
mode_desc.Width = sDeviceMode.dmPelsHeight;
mode_desc.RefreshRate.Numerator= sDeviceMode.dmDisplayFrequency;
mode_desc.RefreshRate.Denominator= 1;
mode_desc.Format = swapchain_desc.BufferDesc.Format;
mode_desc.Scaling= swapchain_desc.BufferDesc.Scaling;

hr = sSwapchain->ResizeTarget(&mode_desc);
gAssert(SUCCEEDED(hr));

sSwapChain->SetFullscreenState(true,nullptr);