development/Common/Render/source/PlatformDisplayModes.cpp
// nativeScale - if true, only select resolutions that are even of multiply of monitor resolution
if true, only select resolutions that are even of multiply of monitor resolution
if true only select resolutions that are even of multiply of monitor resolution
yaget::render::platform::Adapters GetValidResolutions(IDXGIFactory* dxgFactory, DXGI_FORMAT format, bool nativeScale, uint32_t minimumRefreshRate)
    {
        using namespace yaget;
        render::platform::Adapters supportedModes;
        const uint32_t kMinimumRefreshRate = minimumRefreshRate;
        std::vector<ComPtr<IDXGIAdapter>> adapters = EnumerateAdapters(dxgFactory);
        for (auto it : adapters)
        {
            DXGI_ADAPTER_DESC adapterDesc = {};
            HRESULT hr = it->GetDesc(&adapterDesc);
            std::vector<ComPtr<IDXGIOutput>> vOutputs;
            ComPtr<IDXGIOutput> dxgOutput;
            for (UINT i = 0; it->EnumOutputs(i, &dxgOutput) != DXGI_ERROR_NOT_FOUND; ++i)
            {
                vOutputs.push_back(dxgOutput);
            }
            for (auto out : vOutputs)
            {
                DXGI_OUTPUT_DESC outpuDesc = {};
                hr = out->GetDesc(&outpuDesc);
                render::platform::Adapter adapter;
                adapter.mPlatfrormAdapter = it;
                adapter.mMonitor = outpuDesc.Monitor;
                adapter.mColorFormat = format;
                adapter.AdapterName = conv::wide_to_utf8(adapterDesc.Description);
                adapter.MonitorName = conv::wide_to_utf8(outpuDesc.DeviceName);
                adapter.Width = outpuDesc.DesktopCoordinates.right - outpuDesc.DesktopCoordinates.left;
                adapter.Height = outpuDesc.DesktopCoordinates.bottom - outpuDesc.DesktopCoordinates.top;
                UINT numModes = 0;
                hr = out->GetDisplayModeList(format, 0, &numModes, nullptr);
                std::vector<DXGI_MODE_DESC> modes(numModes);
                hr = out->GetDisplayModeList(format, 0, &numModes, modes.data());
                uint32_t width = adapter.Width;
                uint32_t height = adapter.Height;
                modes.erase(std::remove_if(std::begin(modes), std::end(modes), [width, height, kMinimumRefreshRate, nativeScale](const DXGI_MODE_DESC& modeDesc)
                {
                    uint32_t refreshRate = static_cast<uint32_t>(std::ceil(modeDesc.RefreshRate.Numerator / (modeDesc.RefreshRate.Denominator * 1.0f)));
                    if (refreshRate < kMinimumRefreshRate)
                    {
                        return true;
                    }
                    if (modeDesc.Scaling != DXGI_MODE_SCALING_UNSPECIFIED)
                    {
                        return true;
                    }
                    if (!nativeScale || (nativeScale && (width % modeDesc.Width) == 0 && (height % modeDesc.Height) == 0))
                    {
                        return false;
                    }
                    return true;
                }), std::end(modes));
                for (auto mode : modes)
                {
                    uint32_t refreshRate = static_cast<uint32_t>(std::ceil(mode.RefreshRate.Numerator / (mode.RefreshRate.Denominator * 1.0f)));
                    adapter.Modes.push_back({ mode.Width, mode.Height, refreshRate });
                }
                if (!adapter.Modes.empty())
                {
                    supportedModes.push_back(adapter);
                }
            }
        }
        return supportedModes;
    }
yaget :: render :: platform :: Adapters GetValidResolutions ( IDXGIFactory * dxgFactory , DXGI_FORMAT format , bool nativeScale , uint32_t minimumRefreshRate ) { using namespace yaget ; render :: platform :: Adapters supportedModes ; const uint32_t kMinimumRefreshRate = minimumRefreshRate ; std :: vector < ComPtr < IDXGIAdapter > > adapters = EnumerateAdapters ( dxgFactory ) ; for ( auto it : adapters ) { DXGI_ADAPTER_DESC adapterDesc = { } ; HRESULT hr = it -> GetDesc ( & adapterDesc ) ; std :: vector < ComPtr < IDXGIOutput > > vOutputs ; ComPtr < IDXGIOutput > dxgOutput ; for ( UINT i = 0 ; it -> EnumOutputs ( i , & dxgOutput ) != DXGI_ERROR_NOT_FOUND ; ++ i ) { vOutputs . push_back ( dxgOutput ) ; } for ( auto out : vOutputs ) { DXGI_OUTPUT_DESC outpuDesc = { } ; hr = out -> GetDesc ( & outpuDesc ) ; render :: platform :: Adapter adapter ; adapter . mPlatfrormAdapter = it ; adapter . mMonitor = outpuDesc . Monitor ; adapter . mColorFormat = format ; adapter . AdapterName = conv :: wide_to_utf8 ( adapterDesc . Description ) ; adapter . MonitorName = conv :: wide_to_utf8 ( outpuDesc . DeviceName ) ; adapter . Width = outpuDesc . DesktopCoordinates . right - outpuDesc . DesktopCoordinates . left ; adapter . Height = outpuDesc . DesktopCoordinates . bottom - outpuDesc . DesktopCoordinates . top ; UINT numModes = 0 ; hr = out -> GetDisplayModeList ( format , 0 , & numModes , nullptr ) ; std :: vector < DXGI_MODE_DESC > modes ( numModes ) ; hr = out -> GetDisplayModeList ( format , 0 , & numModes , modes . data ( ) ) ; uint32_t width = adapter . Width ; uint32_t height = adapter . Height ; modes . erase ( std :: remove_if ( std :: begin ( modes ) , std :: end ( modes ) , [ width , height , kMinimumRefreshRate , nativeScale ] ( const DXGI_MODE_DESC & modeDesc ) { uint32_t refreshRate = static_cast < uint32_t > ( std :: ceil ( modeDesc . RefreshRate . Numerator / ( modeDesc . RefreshRate . Denominator * 1.0f ) ) ) ; if ( refreshRate < kMinimumRefreshRate ) { return true ; } if ( modeDesc . Scaling != DXGI_MODE_SCALING_UNSPECIFIED ) { return true ; } if ( ! nativeScale || ( nativeScale && ( width % modeDesc . Width ) == 0 && ( height % modeDesc . Height ) == 0 ) ) { return false ; } return true ; } ) , std :: end ( modes ) ) ; for ( auto mode : modes ) { uint32_t refreshRate = static_cast < uint32_t > ( std :: ceil ( mode . RefreshRate . Numerator / ( mode . RefreshRate . Denominator * 1.0f ) ) ) ; adapter . Modes . push_back ( { mode . Width , mode . Height , refreshRate } ) ; } if ( ! adapter . Modes . empty ( ) ) { supportedModes . push_back ( adapter ) ; } } } return supportedModes ; }
nativeScale - if true, only select resolutions that are even of multiply of monitor resolution
nativeScale - if true only select resolutions that are even of multiply of monitor resolution
// Get the number of elements // Get the list /*DXGI_ENUM_MODES_SCALING*/