From 38e6779e12630d6c179ca3b3990e2c42023875d1 Mon Sep 17 00:00:00 2001 From: Danilo Date: Tue, 30 Jul 2024 10:43:39 -0300 Subject: [PATCH] Implementa segunda sobrecarga GraphicsDeviceManager::AddDevices --- framework/platform-dx/device.cpp | 2 +- framework/platform-dx/gdevicemanager.cpp | 63 +++++++++++++++++++++--- framework/platform-dx/swapchain.cpp | 2 +- inc/xna/game/gdeviceinfo.hpp | 4 +- inc/xna/game/gdevicemanager.hpp | 24 +++++++-- inc/xna/graphics/presentparams.hpp | 5 +- 6 files changed, 85 insertions(+), 15 deletions(-) diff --git a/framework/platform-dx/device.cpp b/framework/platform-dx/device.cpp index 2427add..879c03b 100644 --- a/framework/platform-dx/device.cpp +++ b/framework/platform-dx/device.cpp @@ -101,7 +101,7 @@ namespace xna { impl->_adapter = info.Adapter; impl->_gameWindow = info.Window; - impl->_presentationParameters = info.Parameters; + impl->_presentationParameters = info.PresentParameters; } bool GraphicsDevice::Initialize() { diff --git a/framework/platform-dx/gdevicemanager.cpp b/framework/platform-dx/gdevicemanager.cpp index dbc7204..949447b 100644 --- a/framework/platform-dx/gdevicemanager.cpp +++ b/framework/platform-dx/gdevicemanager.cpp @@ -13,8 +13,8 @@ namespace xna { parameters->BackBufferWidth = backBufferWidth; parameters->BackBufferHeight = backBufferHeight; parameters->BackBufferFormat = SurfaceFormat::Color; - parameters->Fullscreen = false; - _information.Parameters = parameters; + parameters->IsFullscreen = false; + _information.PresentParameters = parameters; if (game) _information.Window = game->Window(); @@ -72,7 +72,7 @@ namespace xna { return false; } - info.Parameters->DeviceWindowHandle = reinterpret_cast(window->impl->WindowHandle()); + info.PresentParameters->DeviceWindowHandle = reinterpret_cast(window->impl->WindowHandle()); return true; } @@ -95,8 +95,8 @@ namespace xna { void GraphicsDeviceManager::CreateDevice() { if (isDeviceDirty) { - _information.Parameters->BackBufferWidth = backBufferWidth; - _information.Parameters->BackBufferHeight = backBufferHeight; + _information.PresentParameters->BackBufferWidth = backBufferWidth; + _information.PresentParameters->BackBufferHeight = backBufferHeight; } auto result = initWindow(_information, *game, backBufferWidth, backBufferHeight); @@ -109,7 +109,7 @@ namespace xna { void GraphicsDeviceManager::ChangeDevice() { } - void GraphicsDeviceManager::AddDevice(bool anySuitableDevice, std::vector>& foundDevices) { + void GraphicsDeviceManager::AddDevices(bool anySuitableDevice, std::vector>& foundDevices) { const auto handle = game->Window()->Handle(); std::vector> adapters; @@ -122,9 +122,60 @@ namespace xna { if (!IsWindowOnAdapter(handle, *adapter)) continue; } + + if (adapter->IsProfileSupported(graphicsProfile)) { + auto baseDeviceInfo = snew(); + baseDeviceInfo->Adapter = std::move(adapter); + baseDeviceInfo->Profile = graphicsProfile; + baseDeviceInfo->PresentParameters = snew(); + baseDeviceInfo->PresentParameters->DeviceWindowHandle = handle; + baseDeviceInfo->PresentParameters->MultiSampleCount = 0; + baseDeviceInfo->PresentParameters->IsFullscreen = isFullScreen; + baseDeviceInfo->PresentParameters->PresentationInterval = synchronizeWithVerticalRetrace ? PresentInterval::One : PresentInterval::Immediate; + + const auto& currentDisplayMode = baseDeviceInfo->Adapter->CurrentDisplayMode(); + AddDevices(*baseDeviceInfo->Adapter, *currentDisplayMode, baseDeviceInfo, foundDevices); + + if (isFullScreen) { + //TODO + } + } } } + void GraphicsDeviceManager::AddDevices(GraphicsAdapter const& adapter, DisplayMode const& mode, sptr& baseDeviceInfo, std::vector>& foundDevices) { + auto deviceInformation = snew(*baseDeviceInfo); + + if (isFullScreen) + { + deviceInformation->PresentParameters->BackBufferWidth = mode.Width(); + deviceInformation->PresentParameters->BackBufferHeight = mode.Height(); + } + else if (useResizedBackBuffer) { + deviceInformation->PresentParameters->BackBufferWidth = resizedBackBufferWidth; + deviceInformation->PresentParameters->BackBufferHeight = resizedBackBufferHeight; + } + else { + deviceInformation->PresentParameters->BackBufferWidth = backBufferWidth; + deviceInformation->PresentParameters->BackBufferHeight = backBufferHeight; + } + + SurfaceFormat selectedFormat; + DepthFormat selectedDepthFormat; + int selectedMultiSampleCount; + + adapter.QueryBackBufferFormat(deviceInformation->Profile, mode.Format(), depthStencilFormat, allowMultiSampling ? 16 : 0, selectedFormat, selectedDepthFormat, selectedMultiSampleCount); + + deviceInformation->PresentParameters->BackBufferFormat = selectedFormat; + deviceInformation->PresentParameters->DepthStencilFormat = selectedDepthFormat; + deviceInformation->PresentParameters->MultiSampleCount = selectedMultiSampleCount; + + if (std::find(foundDevices.begin(), foundDevices.end(), deviceInformation) != foundDevices.end()) + return; + + foundDevices.push_back(deviceInformation); + } + bool IsWindowOnAdapter(intptr_t windowHandle, GraphicsAdapter const& adapter) { return GameWindow::ScreenFromAdapter(adapter) == GameWindow::ScreenFromHandle(windowHandle); } diff --git a/framework/platform-dx/swapchain.cpp b/framework/platform-dx/swapchain.cpp index c440bb4..6ac7818 100644 --- a/framework/platform-dx/swapchain.cpp +++ b/framework/platform-dx/swapchain.cpp @@ -64,7 +64,7 @@ namespace xna { impl->dxFullScreenDescription.RefreshRate.Denominator = 1; impl->dxFullScreenDescription.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; impl->dxFullScreenDescription.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; - impl->dxFullScreenDescription.Windowed = !parameters->Fullscreen; + impl->dxFullScreenDescription.Windowed = !parameters->IsFullscreen; HWND hwnd = reinterpret_cast(parameters->DeviceWindowHandle); return internalInit(*m_device, hwnd, impl->dxSwapChain, impl->dxDescription, impl->dxFullScreenDescription); diff --git a/inc/xna/game/gdeviceinfo.hpp b/inc/xna/game/gdeviceinfo.hpp index f815e5f..00e6b2e 100644 --- a/inc/xna/game/gdeviceinfo.hpp +++ b/inc/xna/game/gdeviceinfo.hpp @@ -8,8 +8,8 @@ namespace xna { public: sptr Adapter = nullptr; xna::GraphicsProfile Profile{ xna::GraphicsProfile::Reach }; - sptr Parameters = nullptr; - sptr Window = nullptr; + sptr PresentParameters = nullptr; + sptr Window = nullptr; }; } diff --git a/inc/xna/game/gdevicemanager.hpp b/inc/xna/game/gdevicemanager.hpp index ab0779b..3d123ec 100644 --- a/inc/xna/game/gdevicemanager.hpp +++ b/inc/xna/game/gdevicemanager.hpp @@ -104,6 +104,15 @@ namespace xna { isDeviceDirty = true; } + constexpr bool PreferMultiSampling() const { + return allowMultiSampling; + } + + constexpr void PreferMultiSampling(bool value) { + allowMultiSampling = value; + isDeviceDirty = true; + } + //Gets or sets the display orientations that are available if automatic rotation and scaling is enabled. constexpr DisplayOrientation SupportedOrientations() const { return supportedOrientations; @@ -134,7 +143,8 @@ namespace xna { private: void ChangeDevice(bool forceCreate){} - void AddDevice(bool anySuitableDevice, std::vector>& foundDevices); + void AddDevices(bool anySuitableDevice, std::vector>& foundDevices); + void AddDevices(GraphicsAdapter const& adapter, DisplayMode const& mode, sptr& baseDeviceInfo, std::vector>& foundDevices); protected: void CreateDevice(); @@ -153,11 +163,17 @@ namespace xna { bool isFullScreen{ false }; Int backBufferWidth{ DefaultBackBufferWidth }; Int backBufferHeight{ DefaultBackBufferHeight }; - GraphicsProfile graphicsProfile; + GraphicsProfile graphicsProfile{GraphicsProfile::HiDef}; DepthFormat depthStencilFormat{ DepthFormat::Depth24 }; - SurfaceFormat backBufferFormat; - DisplayOrientation supportedOrientations; + SurfaceFormat backBufferFormat{SurfaceFormat::Color}; + DisplayOrientation supportedOrientations{DisplayOrientation::Default}; bool synchronizeWithVerticalRetrace{ true }; + bool useResizedBackBuffer{ false }; + Int resizedBackBufferWidth{ 0 }; + Int resizedBackBufferHeight{ 0 }; + bool allowMultiSampling{ false }; + + std::vector> foundDevices; }; } diff --git a/inc/xna/graphics/presentparams.hpp b/inc/xna/graphics/presentparams.hpp index 774fd97..3782c28 100644 --- a/inc/xna/graphics/presentparams.hpp +++ b/inc/xna/graphics/presentparams.hpp @@ -12,7 +12,10 @@ namespace xna { SurfaceFormat BackBufferFormat{ SurfaceFormat::Color }; SwapEffect PresentationSwapEffect{ SwapEffect::FlipDiscard }; intptr_t DeviceWindowHandle{ 0 }; - bool Fullscreen{ false }; + bool IsFullscreen{ false }; + Int MultiSampleCount{ 0 }; + PresentInterval PresentationInterval{ PresentInterval::Default }; + DepthFormat DepthStencilFormat{ DepthFormat::None }; }; }