Usually the DirectX11 initialization starts from creating a DirectX11 device:
D3D_DRIVER_TYPE driverTypes[] =
{
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE,
};
UINT nNumDriverTypes = ARRAYSIZE(driverTypes);
// Feature levels supported
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_1
};
UINT nNumFeatureLevels = ARRAYSIZE(featureLevels);
D3D_FEATURE_LEVEL featureLevel;
// Create device
for (UINT n = 0; n < nNumDriverTypes; ++n)
{
hr = D3D11CreateDevice(nullptr,driverTypes[n],nullptr, D3D11_CREATE_DEVICE_BGRA_SUPPORT,featureLevels,nNumFeatureLevels,
D3D11_SDK_VERSION,&m_pDevice,&featureLevel,&m_pDeviceContext);
Then you create a swap chain for your window:
IDXGIDevice* pDXGIDevice = nullptr;
HRESULT hr = m_pDevice->QueryInterface(__uuidof(IDXGIDevice),
reinterpret_cast<void**>(&pDXGIDevice));
if (SUCCEEDED(hr))
{
IDXGIAdapter* pDXGIAdapter = nullptr;
hr = pDXGIDevice->GetParent(__uuidof(IDXGIAdapter),
reinterpret_cast<void**>(&pDXGIAdapter));
if (SUCCEEDED(hr))
{
IDXGIFactory2* pDXGIFactory = nullptr;
hr = pDXGIAdapter->GetParent(__uuidof(IDXGIFactory2),
reinterpret_cast<void**>(&pDXGIFactory));
if (SUCCEEDED(hr))
{
DXGI_SWAP_CHAIN_DESC1 desc = {};
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
desc.BufferCount = 2;
desc.Width = nWindowWidth;
desc.Height = nWindowHeight;
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
hr = pDXGIFactory->CreateSwapChainForHwnd(m_pDevice,hWnd,
&desc,nullptr,nullptr,&m_pSwapChain);
My PC has two video adapters connected to two monitors. Adapter1 is connected to Monitor1. Adapter2 is connected to Monitor2. I know i can enumerate DXGI adapters and use a specific adapter for D3D11CreateDevice to create a DirectX11 device but this does not help me because i do not know which monitor shows my window.
- How can i find which monitor shows my window? Do I have to use that monitor video adapter or can I use any adapter?
- What happens if a user moves the window from Monitor1 to Monitor2? Does another adapter start showing the window?
- Overall, how does DirectX11 handle such an issue?