Hi,
I would like to know how to setup stereoscopic 3D using DirectX 11 Win32 application.
I got to the point where I need to create a swap chain but my application fails in CreateSwapChainForHwnd...
Here's the code I use to detect a stereo capable output (monitor) and create a swap chain for it:
if(m_dxgiFactory->IsWindowedStereoEnabled())
{
// Enumerate all outputs
DirectX11::Handle < IDXGIOutput > dxgiOutput;
for(UINT outputIt = 0; SUCCEEDED(m_dxgiAdapter->EnumOutputs(outputIt, dxgiOutput.ptr())); ++outputIt)
{
// Get stereo 3D capable output
DirectX11::Handle < IDXGIOutput1 > dxgiOutput1;
if(FAILED(dxgiOutput->QueryInterface(__uuidof(IDXGIOutput1), (void **) dxgiOutput1.ptr())))
throw "Failed to retrieve DXGI stereo 3D output";
// Get display mode list
UINT numModes;
if(FAILED(dxgiOutput1->GetDisplayModeList1(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED|DXGI_ENUM_MODES_STEREO, &numModes, NULL)))
throw "Failed to retrieve DXGI display mode list (count)";
std::vector < DXGI_MODE_DESC1 > displayModes(numModes);
if(FAILED(dxgiOutput1->GetDisplayModeList1(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED|DXGI_ENUM_MODES_STEREO, &numModes, displayModes.data())))
throw "Failed to retrieve DXGI display mode list";
// Output display mode list
double maxRefreshRateInHertz = 0.0;
for(uint i = 0; i < numModes; i++)
{
if(displayModes[i].Stereo)
{
double const refreshRateInHertz =
(double) displayModes[i].RefreshRate.Numerator / (double) displayModes[i].RefreshRate.Denominator;
if(refreshRateInHertz > maxRefreshRateInHertz)
{
maxRefreshRateInHertz = refreshRateInHertz;
m_fullscreenWidth = displayModes[i].Width;
m_fullscreenHeight = displayModes[i].Height;
m_fullscreenRefreshRateNumerator = displayModes[i].RefreshRate.Numerator;
m_fullscreenRefreshRateDenominator = displayModes[i].RefreshRate.Denominator;
m_dxgiOutput = dxgiOutput;
}
}
}
dxgiOutput = nullptr;
}
// Create initial swap chain descriptors
m_swapChainDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
m_swapChainDesc.Stereo = TRUE;
m_swapChainDesc.SampleDesc.Count = 1;
m_swapChainDesc.SampleDesc.Quality = 0;
m_swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
m_swapChainDesc.BufferCount = 2;
m_swapChainDesc.Scaling = DXGI_SCALING_NONE;
m_swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_SEQUENTIAL;
m_swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
m_swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
m_swapChainFullscreenDesc.RefreshRate.Numerator = m_fullscreenRefreshRateNumerator;
m_swapChainFullscreenDesc.RefreshRate.Denominator = m_fullscreenRefreshRateDenominator;
m_swapChainFullscreenDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
m_swapChainFullscreenDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
m_swapChainDesc.Width = m_fullscreenWidth;
m_swapChainDesc.Height = m_fullscreenHeight;
m_swapChainFullscreenDesc.Windowed = FALSE;
// Create swap chain
if(FAILED(m_dxgiFactory->CreateSwapChainForHwnd(
m_device,
p_hWnd,
&m_swapChainDesc,
&m_swapChainFullscreenDesc,
m_dxgiOutput,
m_swapChain.ptr())))
throw "Failed to create DXGI swap chain";
}
The call to CreateSwapChainForHwnd fails without any debug output so I don't really know why it doesn't work.
Anyone tried something similar?