• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Shnoutz

Stereoscopic 3D - how to create a swapchain

2 posts in this topic

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?

0

Share this post


Link to post
Share on other sites

Try changing

 

    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";

 

to

 

    HRESULT hr;
    hr = m_dxgiFactory->CreateSwapChainForHwnd(
        m_device,
        p_hWnd,
        &m_swapChainDesc,
        &m_swapChainFullscreenDesc,
        m_dxgiOutput,
        m_swapChain.ptr());

    if (FAILED(hr))
    {
        std::stringstream str;
        str << "Failed to create DXGI swap chain. HR: 0x" << std::hex << std::uppercase << static_cast<unsigned long>(hr) << std::endl;
        OutputDebugStringA(str.str().c_str());
        throw str.str().c_str();
    }

 



Note that you'll need to #include <string> <sstream> <ios> and <ostream>. Also, I'd generally recommend throwing C++ standard library-based exceptions rather than raw ASCII strings and working in Unicode (e.g. L"Something" rather than "Something") along with the corresponding wide character variants of the STL functionality (e.g. std::wstringstream) and Windows API calls (OutputDebugStringW).

Once you have the HRESULT code from the swap chain failure, you'll potentially have much more information than just that the call failed.

At a guess, what's probably going on based on the code you provided you are passing in for the HWND a parameter named "p_hWnd". If that's really a pointer to an HWND, you should be passing in "*p_hWnd" since the API call is expecting an HWND, not a pointer to one.

Also, from the documentation - http://msdn.microsoft.com/en-us/library/hh768891(v=vs.85).aspx , you are calling m_dxgiFactory->IsWindowedStereoEnabled to check for stereo support but this just tells you whether or not you can render a windowed app in stereo. The proper check for a full screen app is to call IDXGIOutput1::GetDisplayModeList1 and see if any of the returned modes supports stereo. You are doing that anyway but your initial call to IsWindowedStereoEnabled is superfluous and might even improperly exclude stereo if the card didn't support windowed stereo with its current settings but would support full screen stereo.

1

Share this post


Link to post
Share on other sites

Thanks Mike for your answer.

I will re-check the return value of the CreateSwapChainForHwnd... Somehow I forgot about it and I was relying on directx's debug output to explain the problem (as most of the time it is quite detailed).

 

From the link you provided, it seems like one needs to register a stereo notification event to enable stereo rendering... I am not sure if CreateSwapChain will fail if no event is registered (like in my case). I havent worked with win api events before and I would like to see an example of its use.

 

Gab.

 

P.S.: the p_ this is to specify that p_hWnd is a paramter of the function and I am throwing ascii strings only for fatal errors, its a choice I made a while ago... Probably not the best idea but it works for me.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0