From 6e10a3a6699bc2bc3469d7a7d92506ab80283a12 Mon Sep 17 00:00:00 2001 From: Danilo Date: Fri, 19 Jul 2024 22:11:57 -0300 Subject: [PATCH] =?UTF-8?q?Corre=C3=A7=C3=B5es=20em=20Adapter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/platform-dx/adapter.cpp | 223 ++++++++++++++++-------------- framework/platform-dx/device.cpp | 12 +- inc/xna/graphics/adapter.hpp | 103 ++++++++++---- inc/xna/xna-dx.hpp | 9 +- 4 files changed, 200 insertions(+), 147 deletions(-) diff --git a/framework/platform-dx/adapter.cpp b/framework/platform-dx/adapter.cpp index 9a38799..fe0e00c 100644 --- a/framework/platform-dx/adapter.cpp +++ b/framework/platform-dx/adapter.cpp @@ -4,8 +4,17 @@ #include "xna/xna-dx.hpp" namespace xna { + static String getDescription(comptr const& adapter); + static Uint getDeviceId(comptr const& adapter); + static String getDeviceName(comptr const& adapter); + static intptr_t getMonitorHandle(comptr const& adapter); + static Uint getRevision(comptr const& adapter); + static Uint getRevision(comptr const& adapter); + static Uint getSubSystemId(comptr const& adapter); + static Uint getVendorId(comptr const& adapter); static size_t getDisplayModesCount(IDXGIAdapter* adapter); - static uptr createDisplayModeCollection(std::vector const& source); + static uptr createDisplayModeCollection(std::vector const& source); + static void setCurrentDisplayMode(GraphicsAdapter& adapter, SurfaceFormat surfaceFormat, Uint width, Uint height, sptr& currentDisplayMode); GraphicsAdapter::GraphicsAdapter() { impl = unew(); @@ -21,10 +30,18 @@ namespace xna { if (pFactory->EnumAdapters1(0, pAdapter.GetAddressOf()) != DXGI_ERROR_NOT_FOUND) { auto adp = unew(); - - adp->impl->_index = 0; + adp->impl->dxAdapter = pAdapter; - adp->impl->dxFactory = pFactory; + adp->impl->dxFactory = pFactory; + + adp->description = getDescription(pAdapter); + adp->deviceId = getDeviceId(pAdapter); + adp->deviceName = getDeviceName(pAdapter); + adp->isDefault = true; + adp->monitorHandle = getMonitorHandle(pAdapter); + adp->revision = getRevision(pAdapter); + adp->subSystemId = getSubSystemId(pAdapter); + adp->vendorId = getVendorId(pAdapter); return adp; } @@ -43,90 +60,21 @@ namespace xna { for (UINT count = 0; pFactory->EnumAdapters1(count, pAdapter.GetAddressOf()) != DXGI_ERROR_NOT_FOUND; ++count) { auto adp = unew(); - adp->impl->_index = count; adp->impl->dxAdapter = pAdapter; adp->impl->dxFactory = pFactory; + adp->description = getDescription(pAdapter); + adp->deviceId = getDeviceId(pAdapter); + adp->deviceName = getDeviceName(pAdapter); + adp->isDefault = count == 0; + adp->monitorHandle = getMonitorHandle(pAdapter); + adp->revision = getRevision(pAdapter); + adp->subSystemId = getSubSystemId(pAdapter); + adp->vendorId = getVendorId(pAdapter); + adapters.push_back(std::move(adp)); } - } - - String GraphicsAdapter::Description() const { - if (!impl->dxAdapter) return String(); - - DXGI_ADAPTER_DESC1 desc; - impl->dxAdapter->GetDesc1(&desc); - String description = XnaHelper::ToString(desc.Description); - return description; - } - - Uint GraphicsAdapter::DeviceId() const { - if (!impl->dxAdapter) return 0; - - DXGI_ADAPTER_DESC1 desc; - impl->dxAdapter->GetDesc1(&desc); - - return static_cast(desc.DeviceId); - } - - String GraphicsAdapter::DeviceName() const { - if (!impl->dxAdapter) return String(); - - comptr pOutput = nullptr; - - if (impl->dxAdapter->EnumOutputs(0, pOutput.GetAddressOf()) != DXGI_ERROR_NOT_FOUND) { - DXGI_OUTPUT_DESC outputDesc{}; - pOutput->GetDesc(&outputDesc); - - String deviceName = XnaHelper::ToString(outputDesc.DeviceName); - - return deviceName; - } - - return String(); - } - - intptr_t GraphicsAdapter::MonitorHandle() const { - if (!impl->dxAdapter) return 0; - - comptr pOutput = nullptr; - - if (impl->dxAdapter->EnumOutputs(0, pOutput.GetAddressOf()) != DXGI_ERROR_NOT_FOUND) { - DXGI_OUTPUT_DESC outputDesc; - pOutput->GetDesc(&outputDesc); - - return reinterpret_cast(outputDesc.Monitor); - } - - return 0; - } - - Uint GraphicsAdapter::Revision() const { - if (!impl->dxAdapter) return 0; - - DXGI_ADAPTER_DESC1 desc; - impl->dxAdapter->GetDesc1(&desc); - - return static_cast(desc.Revision); - } - - Uint GraphicsAdapter::SubSystemId() const { - if (!impl->dxAdapter) return 0; - - DXGI_ADAPTER_DESC1 desc; - impl->dxAdapter->GetDesc1(&desc); - - return static_cast(desc.SubSysId); - } - - Uint GraphicsAdapter::VendorId() const { - if (!impl->dxAdapter) return 0; - - DXGI_ADAPTER_DESC1 desc; - impl->dxAdapter->GetDesc1(&desc); - - return static_cast(desc.VendorId); - } + } uptr GraphicsAdapter::SupportedDisplayModes() const { if (!impl->dxAdapter) return nullptr; @@ -191,27 +139,16 @@ namespace xna { } sptr GraphicsAdapter::CurrentDisplayMode() { - if (!impl->_currentDisplayMode) { - CurrentDisplayMode(SurfaceFormat::Color, GraphicsDeviceManager::DefaultBackBufferWidth, GraphicsDeviceManager::DefaultBackBufferHeight); + if (!currentDisplayMode) { + setCurrentDisplayMode(*this, + SurfaceFormat::Color, + GraphicsDeviceManager::DefaultBackBufferWidth, + GraphicsDeviceManager::DefaultBackBufferHeight, + currentDisplayMode); } - return impl->_currentDisplayMode; - } - - void GraphicsAdapter::CurrentDisplayMode(SurfaceFormat surfaceFormat, Uint width, Uint height) { - const auto modes = SupportedDisplayModes(surfaceFormat); - - for (size_t i = 0; i < modes->DisplayModes.size(); ++i) { - auto& m = modes->DisplayModes[i]; - - if (m->Format == surfaceFormat && m->Width == width && m->Height == height) { - impl->_currentDisplayMode = m; - } - else if(i + 1 == modes->DisplayModes.size()) { - impl->_currentDisplayMode = m; - } - } - } + return currentDisplayMode; + } bool GraphicsAdapter::PlatformImplementation::GetOutput(UINT slot, IDXGIOutput*& output) const { if (!dxAdapter) return false; @@ -224,7 +161,22 @@ namespace xna { //INTERNAL FUNCTIONS - static size_t getDisplayModesCount(IDXGIAdapter* adapter) { + void setCurrentDisplayMode(GraphicsAdapter& adapter, SurfaceFormat surfaceFormat, Uint width, Uint height, sptr& currentDisplayMode) { + const auto modes = adapter.SupportedDisplayModes(surfaceFormat); + + for (size_t i = 0; i < modes->DisplayModes.size(); ++i) { + auto& m = modes->DisplayModes[i]; + + if (m->Format == surfaceFormat && m->Width == width && m->Height == height) { + currentDisplayMode = m; + } + else if (i + 1 == modes->DisplayModes.size()) { + currentDisplayMode = m; + } + } + } + + size_t getDisplayModesCount(IDXGIAdapter* adapter) { comptr pOutput = nullptr; size_t numModes = 0; @@ -243,7 +195,7 @@ namespace xna { return numModes; } - static uptr createDisplayModeCollection(std::vector const& source) { + uptr createDisplayModeCollection(std::vector const& source) { auto collection = unew(); DisplayMode currentDisplayMode; std::vector> displayList; @@ -274,4 +226,67 @@ namespace xna { return collection; } + + String getDescription(comptr const& adapter) { + DXGI_ADAPTER_DESC1 desc; + adapter->GetDesc1(&desc); + const auto description = XnaHelper::ToString(desc.Description); + return description; + } + + Uint getDeviceId(comptr const& adapter) { + DXGI_ADAPTER_DESC1 desc; + adapter->GetDesc1(&desc); + + return static_cast(desc.DeviceId); + } + + String getDeviceName(comptr const& adapter) { + comptr pOutput = nullptr; + + if (adapter->EnumOutputs(0, pOutput.GetAddressOf()) != DXGI_ERROR_NOT_FOUND) { + DXGI_OUTPUT_DESC outputDesc{}; + pOutput->GetDesc(&outputDesc); + + String deviceName = XnaHelper::ToString(outputDesc.DeviceName); + + return deviceName; + } + + return String(); + } + + intptr_t getMonitorHandle(comptr const& adapter) { + comptr pOutput = nullptr; + + if (adapter->EnumOutputs(0, pOutput.GetAddressOf()) != DXGI_ERROR_NOT_FOUND) { + DXGI_OUTPUT_DESC outputDesc; + pOutput->GetDesc(&outputDesc); + + return reinterpret_cast(outputDesc.Monitor); + } + + return 0; + } + + Uint getRevision(comptr const& adapter) { + DXGI_ADAPTER_DESC1 desc; + adapter->GetDesc1(&desc); + + return static_cast(desc.Revision); + } + + Uint getSubSystemId(comptr const& adapter) { + DXGI_ADAPTER_DESC1 desc; + adapter->GetDesc1(&desc); + + return static_cast(desc.SubSysId); + } + + Uint getVendorId(comptr const& adapter) { + DXGI_ADAPTER_DESC1 desc; + adapter->GetDesc1(&desc); + + return static_cast(desc.VendorId); + } } \ No newline at end of file diff --git a/framework/platform-dx/device.cpp b/framework/platform-dx/device.cpp index 50d839e..dfa1e50 100644 --- a/framework/platform-dx/device.cpp +++ b/framework/platform-dx/device.cpp @@ -77,11 +77,7 @@ namespace xna { GraphicsDevice::GraphicsDevice() { impl = unew(); - impl->_adapter = GraphicsAdapter::DefaultAdapter(); - impl->_adapter->CurrentDisplayMode( - SurfaceFormat::Color, - GraphicsDeviceManager::DefaultBackBufferWidth, - GraphicsDeviceManager::DefaultBackBufferHeight); + impl->_adapter = GraphicsAdapter::DefaultAdapter(); } GraphicsDevice::GraphicsDevice(GraphicsDeviceInformation const& info) { @@ -89,11 +85,7 @@ namespace xna { impl->_adapter = info.Adapter; impl->_gameWindow = info.Window; - impl->_presentationParameters = info.Parameters; - impl->_adapter->CurrentDisplayMode( - impl->_presentationParameters->BackBufferFormat, - impl->_presentationParameters->BackBufferWidth, - impl->_presentationParameters->BackBufferHeight); + impl->_presentationParameters = info.Parameters; } bool GraphicsDevice::Initialize() { diff --git a/inc/xna/graphics/adapter.hpp b/inc/xna/graphics/adapter.hpp index c0dad93..ae04431 100644 --- a/inc/xna/graphics/adapter.hpp +++ b/inc/xna/graphics/adapter.hpp @@ -2,6 +2,7 @@ #define XNA_GRAPHICS_ADAPTER_HPP #include "../default.hpp" +#include "displaymode.hpp" namespace xna { //Provides methods to retrieve and manipulate graphics adapters. @@ -9,38 +10,88 @@ namespace xna { public: GraphicsAdapter(); - //Retrieves a string used for presentation to the user. - String Description() const; - //Retrieves a value that is used to help identify a particular chip set. - Uint DeviceId() const; - //Retrieves a string that contains the device name. - String DeviceName() const; - //Determines if this instance of GraphicsAdapter is the default adapter. - bool IsDefaultAdapter() const; - //Retrieves the handle of the monitor - intptr_t MonitorHandle() const; - //Retrieves a value used to help identify the revision level of a particular chip set. - Uint Revision() const; - //Retrieves a value used to identify the subsystem. - Uint SubSystemId() const; - //Retrieves a value used to identify the manufacturer. - Uint VendorId() const; + //Collection of available adapters on the system. + static void Adapters(std::vector>& adapters); + //Gets the current display mode. + sptr CurrentDisplayMode(); + + //Gets the default adapter. + static uptr DefaultAdapter(); + + //Retrieves a string used for presentation to the user. + constexpr String Description() const { return description; } + + //Retrieves a value that is used to help identify a particular chip set. + constexpr Uint DeviceId() const { return deviceId; } + + //Retrieves a string that contains the device name. + constexpr String DeviceName() const { return deviceName; } + + //Determines if this instance of GraphicsAdapter is the default adapter. + constexpr bool IsDefaultAdapter() const { return isDefault; } + + //Determines if the graphics adapter is in widescreen mode. + constexpr bool IsWideScreen() const { return false; } + + //Retrieves the handle of the monitor + constexpr intptr_t MonitorHandle() const { return monitorHandle; } + + //Retrieves a value used to help identify the revision level of a particular chip set. + constexpr Uint Revision() const { return revision; } + + //Retrieves a value used to identify the subsystem. + constexpr Uint SubSystemId() const { return subSystemId; } + //Returns a collection of supported display modes for the current adapter. uptr SupportedDisplayModes() const; //Returns a collection of supported display modes for the current adapter. uptr SupportedDisplayModes(SurfaceFormat surfaceFormat) const; - - //Gets the current display mode. - sptr CurrentDisplayMode(); - //Gets the current display mode. - void CurrentDisplayMode(SurfaceFormat surfaceFormat, Uint width, Uint height); - //Gets the default adapter. - static uptr DefaultAdapter(); - - //Collection of available adapters on the system. - static void Adapters(std::vector>& adapters); + //Retrieves a value used to identify the manufacturer. + constexpr Uint VendorId() const { return vendorId; } + + //Tests to see if the adapter supports the requested profile. + bool IsProfileSupported(GraphicsProfile graphicsProfile) { + return false; + } + + //Queries the adapter for support for the requested back buffer format. + bool QueryBackBufferFormat( + GraphicsProfile graphicsProfile, + SurfaceFormat format, + DepthFormat depthFormat, + Int multiSampleCount, + SurfaceFormat& selectedFormat, + DepthFormat& selectedDepthFormat, + Int& selectedMultiSampleCount + ) { + return false; + } + + //Queries the adapter for support for the requested render target format. + bool QueryRenderTargetFormat( + GraphicsProfile graphicsProfile, + SurfaceFormat format, + DepthFormat depthFormat, + Int multiSampleCount, + SurfaceFormat& selectedFormat, + DepthFormat& selectedDepthFormat, + int& selectedMultiSampleCount + ) { + return false; + } + + private: + String description; + Uint deviceId{0}; + String deviceName; + bool isDefault{ false }; + intptr_t monitorHandle{ 0 }; + Uint revision{ 0 }; + Uint subSystemId{ 0 }; + Uint vendorId{ 0 }; + sptr currentDisplayMode{ nullptr }; public: struct PlatformImplementation; diff --git a/inc/xna/xna-dx.hpp b/inc/xna/xna-dx.hpp index 685213d..0226b17 100644 --- a/inc/xna/xna-dx.hpp +++ b/inc/xna/xna-dx.hpp @@ -591,15 +591,10 @@ namespace xna { struct GraphicsAdapter::PlatformImplementation { comptr dxAdapter = nullptr; - comptr dxFactory = nullptr; - - private: - friend class GraphicsAdapter; - Uint _index{ 0 }; - sptr _currentDisplayMode = nullptr; + comptr dxFactory = nullptr; public: - bool GetOutput(UINT slot, IDXGIOutput*& output) const; + bool GetOutput(UINT slot, IDXGIOutput*& output) const; }; struct BlendRenderTarget {