From f8c881de096d796fd186fdbdcc543663646d8230 Mon Sep 17 00:00:00 2001 From: Danilo Date: Sun, 21 Apr 2024 21:28:07 -0300 Subject: [PATCH] =?UTF-8?q?Implementa=C3=A7=C3=A3o=20em=20SupportedDisplay?= =?UTF-8?q?Modes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/platform/adapter-dx.cpp | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/framework/platform/adapter-dx.cpp b/framework/platform/adapter-dx.cpp index e588fcb..f16dc29 100644 --- a/framework/platform/adapter-dx.cpp +++ b/framework/platform/adapter-dx.cpp @@ -152,13 +152,37 @@ namespace xna { return static_cast(desc.VendorId); } + static UINT getDisplayModesCount(IDXGIAdapter* adapter) { + IDXGIOutput* pOutput = nullptr; + UINT numModes = 0; + + if (adapter->EnumOutputs(0, &pOutput) != DXGI_ERROR_NOT_FOUND) { + for (size_t f = 0; f < SURFACE_FORMAT_COUNT; ++f) { + const auto currentSurface = static_cast(f); + DXGI_FORMAT format = GraphicsAdapter::ToDXGI(currentSurface); + + UINT num = 0; + pOutput->GetDisplayModeList(format, 0, &num, nullptr); + + numModes += num; + } + + pOutput->Release(); + pOutput = nullptr; + } + + return numModes; + } + UDisplayModeCollection GraphicsAdapter::SupportedDisplayModes() const { if (!_adapter) return nullptr; IDXGIOutput* pOutput = nullptr; UINT numModes = 0; UINT totalModes = 0; - std::vector buffer(500); + + const auto totalDisplay = getDisplayModesCount(_adapter); + std::vector buffer(totalDisplay); if (_adapter->EnumOutputs(0, &pOutput) != DXGI_ERROR_NOT_FOUND) { for (size_t f = 0; f < SURFACE_FORMAT_COUNT; ++f) { @@ -168,10 +192,7 @@ namespace xna { pOutput->GetDisplayModeList(format, 0, &numModes, nullptr); if (numModes == 0) - continue; - - if (buffer.size() < static_cast(totalModes) + numModes) - buffer.resize(static_cast(totalModes * 2)); + continue; pOutput->GetDisplayModeList(format, 0, &numModes, buffer.data() + totalModes);