如何获得在DXGI显示器/输出的当前显示模式(分辨率,刷新率)?(How to get curren

2019-08-17 22:36发布

我创建一个多显示器全屏DXGI / D3D应用程序。 我通过可用的输出和适配器,准备创建自己的交换链的枚举。

当创建使用DXGI是我的交换链IDXGIFactory :: CreateSwapChain方法,我需要提供一个交换链的描述,其中包括类型的缓冲器描述DXGI_MODE_DESC ,详细的宽度,高度,刷新速率等方面我怎样才能找出输出是什么目前设定为(或者我怎么能找出输出的显示模式目前是)? 我不想当我去到全屏这个交换链,以改变用户的分辨率或刷新率。

Answer 1:

环顾四周后,多一些我偶然发现了EnumDisplaySettings传统GDI函数,这让我访问当前的分辨率和刷新率。 与此相结合IDXGIOutput::FindClosestMatchingMode功能,我可以得到相当接近当前显示模式:

void getClosestDisplayModeToCurrent(IDXGIOutput* output, DXGI_MODE_DESC* outCurrentDisplayMode)
{
  DXGI_OUTPUT_DESC outputDesc;
  output->GetDesc(&outputDesc);
  HMONITOR hMonitor = outputDesc.Monitor;
  MONITORINFOEX monitorInfo;
  monitorInfo.cbSize = sizeof(MONITORINFOEX);
  GetMonitorInfo(hMonitor, &monitorInfo);
  DEVMODE devMode;
  devMode.dmSize = sizeof(DEVMODE);
  devMode.dmDriverExtra = 0;
  EnumDisplaySettings(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &devMode);

  DXGI_MODE_DESC current;
  current.Width = devMode.dmPelsWidth;
  current.Height = devMode.dmPelsHeight;
  bool useDefaultRefreshRate = 1 == devMode.dmDisplayFrequency || 0 == devMode.dmDisplayFrequency;
  current.RefreshRate.Numerator = useDefaultRefreshRate ? 0 : devMode.dmDisplayFrequency;
  current.RefreshRate.Denominator = useDefaultRefreshRate ? 0 : 1;
  current.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
  current.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
  current.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

  output->FindClosestMatchingMode(&current, outCurrentDisplayMode, NULL);
}

......但我不认为这是真正正确的答案,因为我需要使用传统功能。 有没有办法做到这一点与DXGI得到确切的当前显示模式,而不是使用这种方法吗?



Answer 2:

我看到这里的解决方案: http://www.rastertek.com/dx11tut03.html

在便接踵而来部分:

   // Now go through all the display modes and find the one that matches the screen width and height.
    // When a match is found store the numerator and denominator of the refresh rate for that monitor.
    for(i=0; i<numModes; i++)
    {
        if(displayModeList[i].Width == (unsigned int)screenWidth)
        {
            if(displayModeList[i].Height == (unsigned int)screenHeight)
            {
                numerator = displayModeList[i].RefreshRate.Numerator;
                denominator = displayModeList[i].RefreshRate.Denominator;
            }
        }
    }

我的理解是正确的,可用的分辨率是在displayModeList。



Answer 3:

This might be what you are looking for:


            // Get display mode list
            std::vector<DXGI_MODE_DESC*> modeList = GetDisplayModeList(*outputItor);
            for(std::vector<DXGI_MODE_DESC*>::iterator modeItor = modeList.begin(); modeItor != modeList.end(); ++modeItor)
            {
            //  PrintDisplayModeInfo(*modeItor);
            }
        }




std::vector<DXGI_MODE_DESC*> GetDisplayModeList(IDXGIOutput* output)
{
    UINT num = 0;
    DXGI_FORMAT format = DXGI_FORMAT_R32G32B32A32_TYPELESS;
    UINT flags = DXGI_ENUM_MODES_INTERLACED | DXGI_ENUM_MODES_SCALING;

    // Get number of display modes
    output->GetDisplayModeList(format, flags, &num, 0);

    // Get display mode list
    DXGI_MODE_DESC * pDescs = new DXGI_MODE_DESC[num];
    output->GetDisplayModeList(format, flags, &num, pDescs);

    std::vector<DXGI_MODE_DESC*> displayList;
    for(int i = 0; i < num; ++i)
    {
        displayList.push_back(&pDescs[i]);
    }

    return displayList;
}


文章来源: How to get current display mode (resolution, refresh rate) of a monitor/output in DXGI?