summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D12
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-03-30 16:52:13 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-03-30 16:52:13 +0000
commit5677bdafc48e6231a67c01e5d894ed657aa0ecf6 (patch)
treea847157bc1d7f8811bcae2d37e9ebe1f8f9b4c6b /Graphics/GraphicsEngineD3D12
parentImplemented option to specify hardware adapter when initializing the engine i... (diff)
downloadDiligentCore-5677bdafc48e6231a67c01e5d894ed657aa0ecf6.tar.gz
DiligentCore-5677bdafc48e6231a67c01e5d894ed657aa0ecf6.zip
Implemented initialization in fullscreen mode on Win32
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
-rw-r--r--Graphics/GraphicsEngineD3D12/include/SwapChainD3D12Impl.h1
-rw-r--r--Graphics/GraphicsEngineD3D12/interface/RenderDeviceFactoryD3D12.h1
-rw-r--r--Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp5
-rw-r--r--Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp35
4 files changed, 37 insertions, 5 deletions
diff --git a/Graphics/GraphicsEngineD3D12/include/SwapChainD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/SwapChainD3D12Impl.h
index 0e73a6b8..3b75be44 100644
--- a/Graphics/GraphicsEngineD3D12/include/SwapChainD3D12Impl.h
+++ b/Graphics/GraphicsEngineD3D12/include/SwapChainD3D12Impl.h
@@ -42,6 +42,7 @@ public:
typedef SwapChainBase<ISwapChainD3D12> TSwapChainBase;
SwapChainD3D12Impl(IReferenceCounters *pRefCounters,
const SwapChainDesc& SwapChainDesc,
+ const FullScreenModeDesc& FSDesc,
class RenderDeviceD3D12Impl* pRenderDeviceD3D12,
class DeviceContextD3D12Impl* pDeviceContextD3D12,
void* pNativeWndHandle);
diff --git a/Graphics/GraphicsEngineD3D12/interface/RenderDeviceFactoryD3D12.h b/Graphics/GraphicsEngineD3D12/interface/RenderDeviceFactoryD3D12.h
index 6a8c7e6e..e8b7cdb4 100644
--- a/Graphics/GraphicsEngineD3D12/interface/RenderDeviceFactoryD3D12.h
+++ b/Graphics/GraphicsEngineD3D12/interface/RenderDeviceFactoryD3D12.h
@@ -57,6 +57,7 @@ public:
virtual void CreateSwapChainD3D12( IRenderDevice *pDevice,
IDeviceContext *pImmediateContext,
const SwapChainDesc& SwapChainDesc,
+ const FullScreenModeDesc& FSDesc,
void* pNativeWndHandle,
ISwapChain **ppSwapChain ) = 0;
diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp
index fb7cb83b..2fdbe59b 100644
--- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp
@@ -65,6 +65,7 @@ public:
void CreateSwapChainD3D12( IRenderDevice *pDevice,
IDeviceContext *pImmediateContext,
const SwapChainDesc& SwapChainDesc,
+ const FullScreenModeDesc& FSDesc,
void* pNativeWndHandle,
ISwapChain **ppSwapChain )override final;
};
@@ -343,6 +344,7 @@ void EngineFactoryD3D12Impl::AttachToD3D12Device(void *pd3d12NativeDevice,
/// \param [in] pDevice - Pointer to the render device
/// \param [in] pImmediateContext - Pointer to the immediate device context
/// \param [in] SCDesc - Swap chain description
+/// \param [in] FSDesc - Fullscreen mode description
/// \param [in] pNativeWndHandle - Platform-specific native handle of the window
/// the swap chain will be associated with:
/// * On Win32 platform, this should be window handle (HWND)
@@ -354,6 +356,7 @@ void EngineFactoryD3D12Impl::AttachToD3D12Device(void *pd3d12NativeDevice,
void EngineFactoryD3D12Impl::CreateSwapChainD3D12( IRenderDevice *pDevice,
IDeviceContext *pImmediateContext,
const SwapChainDesc& SCDesc,
+ const FullScreenModeDesc& FSDesc,
void* pNativeWndHandle,
ISwapChain **ppSwapChain )
{
@@ -368,7 +371,7 @@ void EngineFactoryD3D12Impl::CreateSwapChainD3D12( IRenderDevice *pDevice,
auto *pDeviceD3D12 = ValidatedCast<RenderDeviceD3D12Impl>( pDevice );
auto *pDeviceContextD3D12 = ValidatedCast<DeviceContextD3D12Impl>(pImmediateContext);
auto &RawMemAllocator = GetRawAllocator();
- auto *pSwapChainD3D12 = NEW_RC_OBJ(RawMemAllocator, "SwapChainD3D12Impl instance", SwapChainD3D12Impl)(SCDesc, pDeviceD3D12, pDeviceContextD3D12, pNativeWndHandle);
+ auto *pSwapChainD3D12 = NEW_RC_OBJ(RawMemAllocator, "SwapChainD3D12Impl instance", SwapChainD3D12Impl)(SCDesc, FSDesc, pDeviceD3D12, pDeviceContextD3D12, pNativeWndHandle);
pSwapChainD3D12->QueryInterface( IID_SwapChain, reinterpret_cast<IObject**>(ppSwapChain) );
pDeviceContextD3D12->SetSwapChain(pSwapChainD3D12);
diff --git a/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp
index f45a7c09..6add53b8 100644
--- a/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp
@@ -34,6 +34,7 @@ namespace Diligent
SwapChainD3D12Impl::SwapChainD3D12Impl(IReferenceCounters *pRefCounters,
const SwapChainDesc& SCDesc,
+ const FullScreenModeDesc& FSDesc,
RenderDeviceD3D12Impl* pRenderDeviceD3D12,
DeviceContextD3D12Impl* pDeviceContextD3D12,
void* pNativeWndHandle) :
@@ -47,7 +48,15 @@ SwapChainD3D12Impl::SwapChainD3D12Impl(IReferenceCounters *pRefCounters,
if( m_SwapChainDesc.Width == 0 || m_SwapChainDesc.Height == 0 )
{
RECT rc;
- GetClientRect( hWnd, &rc );
+ if (FSDesc.Fullscreen)
+ {
+ const HWND hDesktop = GetDesktopWindow();
+ GetWindowRect(hDesktop, &rc);
+ }
+ else
+ {
+ GetClientRect(hWnd, &rc);
+ }
m_SwapChainDesc.Width = rc.right - rc.left;
m_SwapChainDesc.Height = rc.bottom - rc.top;
}
@@ -72,9 +81,10 @@ SwapChainD3D12Impl::SwapChainD3D12Impl(IReferenceCounters *pRefCounters,
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferCount = m_SwapChainDesc.BufferCount;
swapChainDesc.Scaling = DXGI_SCALING_NONE;
+ // Windows Store apps must use DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL or DXGI_SWAP_EFFECT_FLIP_DISCARD.
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED; // Not used
- swapChainDesc.Flags = 0;
+ swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
CComPtr<IDXGISwapChain1> pSwapChain1;
CComPtr<IDXGIFactory4> factory;
@@ -82,8 +92,16 @@ SwapChainD3D12Impl::SwapChainD3D12Impl(IReferenceCounters *pRefCounters,
CHECK_D3D_RESULT_THROW(hr, "Failed to create DXGI factory")
auto *pd3d12CmdQueue = pRenderDeviceD3D12->GetCmdQueue()->GetD3D12CommandQueue();
+
#if PLATFORM_WIN32
- hr = factory->CreateSwapChainForHwnd(pd3d12CmdQueue, hWnd, &swapChainDesc, nullptr, nullptr, &pSwapChain1);
+
+ DXGI_SWAP_CHAIN_FULLSCREEN_DESC FullScreenDesc = {};
+ FullScreenDesc.Windowed = FSDesc.Fullscreen ? FALSE : TRUE;
+ FullScreenDesc.RefreshRate.Numerator = FSDesc.RefreshRateNumerator;
+ FullScreenDesc.RefreshRate.Denominator = FSDesc.RefreshRateDenominator;
+ FullScreenDesc.Scaling = static_cast<DXGI_MODE_SCALING>(FSDesc.Scaling);
+ FullScreenDesc.ScanlineOrdering = static_cast<DXGI_MODE_SCANLINE_ORDER>(FSDesc.ScanlineOrder);
+ hr = factory->CreateSwapChainForHwnd(pd3d12CmdQueue, hWnd, &swapChainDesc, &FullScreenDesc, nullptr, &pSwapChain1);
CHECK_D3D_RESULT_THROW( hr, "Failed to create Swap Chain" );
// This sample does not support fullscreen transitions.
@@ -91,6 +109,9 @@ SwapChainD3D12Impl::SwapChainD3D12Impl(IReferenceCounters *pRefCounters,
#elif PLATFORM_UNIVERSAL_WINDOWS
+ if (FSDesc.Fullscreen)
+ LOG_WARNING_MESSAGE("UWP applications do not support fullscreen mode");
+
hr = factory->CreateSwapChainForCoreWindow(
pd3d12CmdQueue,
reinterpret_cast<IUnknown*>(pNativeWndHandle),
@@ -112,7 +133,13 @@ SwapChainD3D12Impl::SwapChainD3D12Impl(IReferenceCounters *pRefCounters,
SwapChainD3D12Impl::~SwapChainD3D12Impl()
{
-
+ if (m_pSwapChain)
+ {
+ BOOL IsFullScreen = FALSE;
+ m_pSwapChain->GetFullscreenState(&IsFullScreen, nullptr);
+ if (IsFullScreen)
+ m_pSwapChain->SetFullscreenState(FALSE, nullptr);
+ }
}
void SwapChainD3D12Impl::InitBuffersAndViews()