From 09e6aa3d9a5fa016cc5dfab5cdb236e7182c05ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Fri, 9 Oct 2015 19:21:42 -0700 Subject: [PATCH] Cleanup. --- src/renderer_d3d11.cpp | 176 +++++++++++++++++++++-------------------- src/renderer_d3d11.h | 2 +- 2 files changed, 91 insertions(+), 87 deletions(-) diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index fc8e53bf..a7a383d3 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -9,9 +9,9 @@ # include "renderer_d3d11.h" #if BX_PLATFORM_WINRT -#include -#include -#endif +# include +# include +#endif // BX_PLATFORM_WINRT namespace bgfx { namespace d3d11 { @@ -1017,50 +1017,52 @@ BX_PRAGMA_DIAGNOSTIC_POP(); memset(&m_scd, 0, sizeof(m_scd) ); m_scd.Width = BGFX_DEFAULT_WIDTH; m_scd.Height = BGFX_DEFAULT_HEIGHT; - m_scd.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + m_scd.Format = DXGI_FORMAT_R8G8B8A8_UNORM; m_scd.Stereo = false; m_scd.SampleDesc.Count = 1; m_scd.SampleDesc.Quality = 0; m_scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; m_scd.BufferCount = 2; - m_scd.Scaling = (g_platformData.ndt == 0) ? DXGI_SCALING_NONE : DXGI_SCALING_STRETCH; - m_scd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; - m_scd.AlphaMode = DXGI_ALPHA_MODE_IGNORE; + m_scd.Scaling = 0 == g_platformData.ndt + ? DXGI_SCALING_NONE + : DXGI_SCALING_STRETCH; + m_scd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; + m_scd.AlphaMode = DXGI_ALPHA_MODE_IGNORE; - if (g_platformData.ndt == 0) - { - hr = m_factory->CreateSwapChainForCoreWindow(m_device - , (::IUnknown*)g_platformData.nwh - , &m_scd - , NULL - , &m_swapChain - ); - BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create Direct3D11 swap chain."); - } - else - { - BGFX_FATAL(g_platformData.ndt == reinterpret_cast(1), Fatal::UnableToInitialize, "Unable to set swap chain on panel."); + if (NULL == g_platformData.ndt) + { + hr = m_factory->CreateSwapChainForCoreWindow(m_device + , (::IUnknown*)g_platformData.nwh + , &m_scd + , NULL + , &m_swapChain + ); + BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create Direct3D11 swap chain."); + } + else + { + BGFX_FATAL(g_platformData.ndt == reinterpret_cast(1), Fatal::UnableToInitialize, "Unable to set swap chain on panel."); - hr = m_factory->CreateSwapChainForComposition( - m_device, - &m_scd, - NULL, - &m_swapChain); - BX_WARN(SUCCEEDED(hr), "Unable to create Direct3D11 swap chain."); + hr = m_factory->CreateSwapChainForComposition(m_device + , &m_scd + , NULL + , &m_swapChain + ); + BX_WARN(SUCCEEDED(hr), "Unable to create Direct3D11 swap chain."); - IInspectable *nativeWindow = reinterpret_cast(g_platformData.nwh); - ISwapChainBackgroundPanelNative* panel = nullptr; - hr = nativeWindow->QueryInterface(__uuidof(ISwapChainBackgroundPanelNative), (void **)&panel); - BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to set swap chain on panel."); + IInspectable* nativeWindow = reinterpret_cast(g_platformData.nwh); + ISwapChainBackgroundPanelNative* panel = NULL; + hr = nativeWindow->QueryInterface(__uuidof(ISwapChainBackgroundPanelNative), (void**)&panel); + BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to set swap chain on panel."); - if (panel != nullptr) - { - hr = panel->SetSwapChain(m_swapChain); - BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to set swap chain on panel."); + if (NULL != panel) + { + hr = panel->SetSwapChain(m_swapChain); + BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to set swap chain on panel."); - panel->Release(); - } - } + panel->Release(); + } + } #else hr = adapter->GetParent(IID_IDXGIFactory, (void**)&m_factory); BX_WARN(SUCCEEDED(hr), "Unable to create Direct3D11 device."); @@ -2155,46 +2157,46 @@ BX_PRAGMA_DIAGNOSTIC_POP(); #if BX_PLATFORM_WINRT HRESULT hr; - if (g_platformData.ndt == 0) - { - hr = m_factory->CreateSwapChainForCoreWindow(m_device - , (::IUnknown*)g_platformData.nwh - , scd - , NULL - , &m_swapChain - ); - BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create Direct3D11 swap chain."); - } - else - { - BGFX_FATAL(g_platformData.ndt == reinterpret_cast(1), Fatal::UnableToInitialize, "Invalid native display type."); + if (g_platformData.ndt == 0) + { + hr = m_factory->CreateSwapChainForCoreWindow(m_device + , (::IUnknown*)g_platformData.nwh + , scd + , NULL + , &m_swapChain + ); + BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create Direct3D11 swap chain."); + } + else + { + BGFX_FATAL(g_platformData.ndt == reinterpret_cast(1), Fatal::UnableToInitialize, "Invalid native display type."); - hr = m_factory->CreateSwapChainForComposition( - m_device, - &m_scd, - NULL, - &m_swapChain); - BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create Direct3D11 swap chain."); + hr = m_factory->CreateSwapChainForComposition(m_device + , &m_scd + , NULL + , &m_swapChain + ); + BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create Direct3D11 swap chain."); - IInspectable *nativeWindow = reinterpret_cast(g_platformData.nwh); - ISwapChainBackgroundPanelNative* panel = nullptr; - hr = nativeWindow->QueryInterface(__uuidof(ISwapChainBackgroundPanelNative), (void **)&panel); - BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to set swap chain on panel."); + IInspectable *nativeWindow = reinterpret_cast(g_platformData.nwh); + ISwapChainBackgroundPanelNative* panel = NULL; + hr = nativeWindow->QueryInterface(__uuidof(ISwapChainBackgroundPanelNative), (void **)&panel); + BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to set swap chain on panel."); - if (panel != nullptr) - { - hr = panel->SetSwapChain(m_swapChain); - BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to set swap chain on panel."); + if (NULL != panel) + { + hr = panel->SetSwapChain(m_swapChain); + BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to set swap chain on panel."); - panel->Release(); - } - } + panel->Release(); + } + } #else HRESULT hr; hr = m_factory->CreateSwapChain(m_device - , scd - , &m_swapChain - ); + , scd + , &m_swapChain + ); #endif // BX_PLATFORM_WINRT BGFX_FATAL(SUCCEEDED(hr), bgfx::Fatal::UnableToInitialize, "Failed to create swap chain."); } @@ -3319,22 +3321,24 @@ BX_PRAGMA_DIAGNOSTIC_POP(); s_renderD3D11 = NULL; } - void trim() - { - if (s_renderD3D11) - { - if (s_renderD3D11->m_device) - { - IDXGIDevice3 * pDXGIDevice; - HRESULT hr = s_renderD3D11->m_device->QueryInterface(__uuidof(IDXGIDevice3), (void **)&pDXGIDevice); - if (SUCCEEDED(hr)) - { - pDXGIDevice->Trim(); - pDXGIDevice->Release(); - } - } - } - } + void trim() + { +#if BX_PLATFORM_WINRT + if (NULL != s_renderD3D11) + { + if (s_renderD3D11->m_device) + { + IDXGIDevice3* pDXGIDevice; + HRESULT hr = s_renderD3D11->m_device->QueryInterface(__uuidof(IDXGIDevice3),(void **)&pDXGIDevice); + if (SUCCEEDED(hr) ) + { + pDXGIDevice->Trim(); + pDXGIDevice->Release(); + } + } + } +#endif // BX_PLATFORM_WINRT + } void stubMultiDrawInstancedIndirect(uint32_t _numDrawIndirect, ID3D11Buffer* _ptr, uint32_t _offset, uint32_t _stride) { diff --git a/src/renderer_d3d11.h b/src/renderer_d3d11.h index 34ee041e..d0560957 100644 --- a/src/renderer_d3d11.h +++ b/src/renderer_d3d11.h @@ -20,7 +20,7 @@ BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4005) // warning C4005: '' : macro redefinitio #include #define D3D11_NO_HELPERS #if BX_PLATFORM_WINRT -# include +# include #else # include #endif // BX_PLATFORM_WINRT