Browse Source

Able to specify VideoMode when creating a new render window and it will respect fullscreen/monitor settings

Marko Pintera 11 years ago
parent
commit
96d06586e8

+ 1 - 2
BansheeEditor/Source/BsEditorApplication.cpp

@@ -45,8 +45,7 @@ namespace BansheeEngine
 		:mActiveRSPlugin(renderSystemPlugin)
 	{
 		RENDER_WINDOW_DESC renderWindowDesc;
-		renderWindowDesc.width = 1280;
-		renderWindowDesc.height = 720;
+		renderWindowDesc.videoMode = VideoMode(1280, 720);
 		renderWindowDesc.title = "BansheeEditor";
 		renderWindowDesc.fullscreen = false;
 		renderWindowDesc.border = WindowBorder::None;

+ 1 - 2
BansheeEditor/Source/BsEditorWindowBase.cpp

@@ -15,8 +15,7 @@ namespace BansheeEngine
 		:mOwnsRenderWindow(true)
 	{
 		RENDER_WINDOW_DESC renderWindowDesc;
-		renderWindowDesc.width = 200;
-		renderWindowDesc.height = 200;
+		renderWindowDesc.videoMode = VideoMode(200, 200);
 		renderWindowDesc.title = "EditorWindow";
 		renderWindowDesc.fullscreen = false;
 		renderWindowDesc.border = WindowBorder::None;

+ 2 - 2
CamelotCore/Include/CmCoreThreadAccessor.h

@@ -147,9 +147,9 @@ namespace BansheeEngine
 		void setFullscreen(RenderWindowPtr& renderWindow, UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0);
 
 		/**
-		 * @copydoc RenderWindow::setFullscreen(const VideoMode&, UINT32)
+		 * @copydoc RenderWindow::setFullscreen(const VideoMode&)
 		 */
-		void setFullscreen(RenderWindowPtr& renderWindow, const VideoMode& mode, UINT32 refreshRateIdx = 0);
+		void setFullscreen(RenderWindowPtr& renderWindow, const VideoMode& mode);
 
 		/**
 		 * @copydoc RenderWindow::setWindowed

+ 0 - 6
CamelotCore/Include/CmRenderTarget.h

@@ -57,12 +57,6 @@ namespace BansheeEngine
 		 */
         UINT32 getHeight() const { return mHeight; }
 
-		/**
-		 * @brief	Returns the number of bits a single color value of the 
-		 *			render target format takes.
-		 */
-		UINT32 getColorDepth() const { return mColorDepth; }
-
 		/**
 		 * @brief	Gets the number of samples used for multisampling.
 		 *			(0 if multisampling is not used).

+ 8 - 13
CamelotCore/Include/CmRenderWindow.h

@@ -3,6 +3,7 @@
 #include "CmPrerequisites.h"
 
 #include "CmRenderTarget.h"
+#include "CmVideoModeInfo.h"
 #include "CmVector2I.h"
 
 namespace BansheeEngine
@@ -23,35 +24,29 @@ namespace BansheeEngine
 	struct CM_EXPORT RENDER_WINDOW_DESC
 	{
 		RENDER_WINDOW_DESC()
-			:width(0), height(0), fullscreen(false)
-			, vsync(false), vsyncInterval(1), hidden(false)
-			, displayFrequency(60), colorDepth(32), depthBuffer(true)
+		: vsync(false), vsyncInterval(1), fullscreen(false), hidden(false), depthBuffer(true)
 			, multisampleCount(0), multisampleHint(""), gamma(false), left(-1), top(-1)
 			, title(""), border(WindowBorder::Normal), outerDimensions(false), enableDoubleClick(true)
-			, monitorIndex(-1), toolWindow(false), modal(false)
+			, toolWindow(false), modal(false)
 		{ }
 
-		UINT32 width; /**< Width of the window in pixels. */
-		UINT32 height; /**< Height of the window in pixels. */
-		bool fullscreen; /**< Should the window be created in full-screen mode. */
+		VideoMode videoMode; /**< A set of frame buffer options. */
+		bool fullscreen; /**< Should the window be opened in fullscreen mode. */
 		bool vsync; /**< Should the window wait for vertical sync before swapping buffers. */
 		UINT32 vsyncInterval; /**< Determines how many vsync intervals occur per frame. FPS = refreshRate/interval. Usually 1 when vsync active. */
 		bool hidden; /**< Should the window be hidden. */
-		UINT32 displayFrequency; /**< Display frequency of the screen to use in hertz. */
-		UINT32 colorDepth; /**< Depth of the color buffer in bits. This is the size of a single pixel in color buffer. */
 		bool depthBuffer; /**< Should the window be created with a depth/stencil buffer. */
 		UINT32 multisampleCount; /**< If higher than 1, texture containing multiple samples per pixel is created. */
 		String multisampleHint; /**< Hint about what kind of multisampling to use. Render system specific. */
 		bool gamma; /**< Should the written color pixels be gamma corrected before write. */
-		INT32 left; /**< Window origin on X axis in pixels. -1 == screen center. */
-		INT32 top; /**< Window origin on Y axis in pixels. -1 == screen center. */
+		INT32 left; /**< Window origin on X axis in pixels. -1 == screen center. Relative to monitor provided in videoMode. */
+		INT32 top; /**< Window origin on Y axis in pixels. -1 == screen center. Relative to monitor provided in videoMode. */
 		String title; /**< Title of the window. */
 		WindowBorder border; /**< Type of border to create the window with. */
 		bool outerDimensions; /**< Do our dimensions include space for things like title-bar and border. */
 		bool enableDoubleClick; /**< Does window accept double-clicks. */
 		bool toolWindow; /**< Tool windows don't include standard window controls. */
 		bool modal; /**< When a modal window is open all other windows will be locked until modal window is closed. */
-		INT32 monitorIndex; /**< Index of the monitor to create the window on. -1 == select based on coordinates */
 
 		NameValuePairList platformSpecific; /**< Platform-specific creation options. */
 	};
@@ -83,7 +78,7 @@ namespace BansheeEngine
 		/**
 		* @brief	Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
 		*
-		* @param	videoMode		Mode retrieved from VideoModeInfo in RenderSystem.
+		* @param	videoMode	Mode retrieved from VideoModeInfo in RenderSystem.
 		*
 		* @note		Core thread.
 		*/

+ 2 - 3
CamelotCore/Include/CmVideoModeInfo.h

@@ -11,6 +11,8 @@ namespace BansheeEngine
 	class CM_EXPORT VideoMode
 	{
 	public:
+		VideoMode() {}
+
 		/**
 		 * @brief	Creates a new video mode.
 		 *
@@ -24,9 +26,6 @@ namespace BansheeEngine
 		VideoMode(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 outputIdx = 0);
 		virtual ~VideoMode();
 
-		VideoMode(const VideoMode&) = delete; // Make non-copyable
-		VideoMode& operator=(const VideoMode&) = delete; // Make non-copyable
-
 		/**
 		 * @brief	Width of the front/back buffer in pixels.
 		 */

+ 3 - 4
CamelotCore/Source/CmCoreThreadAccessor.cpp

@@ -264,12 +264,11 @@ namespace BansheeEngine
 		mCommandQueue->queue(std::bind(funcPtr, renderWindow.get(), width, height, refreshRate, monitorIdx));
 	}
 
-	void CoreThreadAccessorBase::setFullscreen(RenderWindowPtr& renderWindow, const VideoMode& mode, 
-		UINT32 refreshRateIdx)
+	void CoreThreadAccessorBase::setFullscreen(RenderWindowPtr& renderWindow, const VideoMode& mode)
 	{
-		void(RenderWindow::*funcPtr)(const VideoMode&, UINT32) = &RenderWindow::setFullscreen;
+		void(RenderWindow::*funcPtr)(const VideoMode&) = &RenderWindow::setFullscreen;
 
-		mCommandQueue->queue(std::bind(funcPtr, renderWindow.get(), std::cref(mode), refreshRateIdx));
+		mCommandQueue->queue(std::bind(funcPtr, renderWindow.get(), std::cref(mode)));
 	}
 
 	void CoreThreadAccessorBase::setWindowed(RenderWindowPtr& renderWindow)

+ 2 - 0
CamelotD3D11RenderSystem/Include/CmD3D11RenderWindow.h

@@ -124,6 +124,8 @@ namespace BansheeEngine
 		DXGI_SAMPLE_DESC mMultisampleType;
 		bool mVSync;
 		UINT32 mVSyncInterval;
+		UINT32 mRefreshRateNumerator;
+		UINT32 mRefreshRateDenominator;
 
 		ID3D11Texture2D* mBackBuffer;
 		ID3D11RenderTargetView*	mRenderTargetView;

+ 12 - 2
CamelotD3D11RenderSystem/Include/CmD3D11VideoModeInfo.h

@@ -19,11 +19,21 @@ namespace BansheeEngine
 		 */
 		const DXGI_MODE_DESC& getDXGIModeDesc() const { return mD3D11Mode; }
 
+		/**
+		 * @brief	Gets internal DX11 refresh rate numerator.
+		 */
+		UINT32 getRefreshRateNumerator() const { return mRefreshRateNumerator; }
+
+		/**
+		 * @brief	Gets internal DX11 refresh rate denominator.
+		 */
+		UINT32 getRefreshRateDenominator() const { return mRefreshRateDenominator; }
+
 	private:
 		friend class D3D11VideoOutputInfo;
 
-		UINT32 refreshRateNumerator;
-		UINT32 refreshRateDenominator;
+		UINT32 mRefreshRateNumerator;
+		UINT32 mRefreshRateDenominator;
 		DXGI_MODE_DESC mD3D11Mode;
 	};
 

+ 94 - 109
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -15,18 +15,9 @@
 namespace BansheeEngine
 {
 	D3D11RenderWindow::D3D11RenderWindow(const RENDER_WINDOW_DESC& desc,D3D11Device& device, IDXGIFactory* DXGIFactory)
-		: RenderWindow(desc)
-		, mDevice(device)
-		, mDXGIFactory(DXGIFactory)
-		, mIsExternal(false)
-		, mSizing(false)
-		, mClosed(false)
-		, mRenderTargetView(nullptr)
-		, mBackBuffer(nullptr)
-		, mSwapChain(nullptr)
-		, mHWnd(0)
-		, mDepthStencilView(nullptr)
-		, mIsChild(false)
+		: RenderWindow(desc), mDevice(device), mDXGIFactory(DXGIFactory), mIsExternal(false), mSizing(false), 
+		mClosed(false), mRenderTargetView(nullptr), mBackBuffer(nullptr), mSwapChain(nullptr), mHWnd(0), 
+		mDepthStencilView(nullptr), mIsChild(false), mRefreshRateNumerator(0), mRefreshRateDenominator(0)
 	{
 		ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
 	}
@@ -45,33 +36,54 @@ namespace BansheeEngine
 		mVSyncInterval = 1;
 		HWND parentHWnd = 0;
 		HWND externalHandle = 0;
-		HMONITOR hMonitor = NULL;
+		
 
-		// Get variable-length params
 		NameValuePairList::const_iterator opt;
-
-		// parentWindowHandle		-> parentHWnd
 		opt = mDesc.platformSpecific.find("parentWindowHandle");
 		if(opt != mDesc.platformSpecific.end())
 			parentHWnd = (HWND)parseUnsignedInt(opt->second);
-		// externalWindowHandle		-> externalHandle
+
 		opt = mDesc.platformSpecific.find("externalWindowHandle");
 		if(opt != mDesc.platformSpecific.end())
 			externalHandle = (HWND)parseUnsignedInt(opt->second);
-		// monitor handle
-		opt = mDesc.platformSpecific.find("monitorHandle");
-		if (opt != mDesc.platformSpecific.end())
-			hMonitor = (HMONITOR)parseInt(opt->second);		
 
 		mName = mDesc.title;
 		mIsChild = parentHWnd != 0;
 		mIsFullScreen = mDesc.fullscreen && !mIsChild;
-		mColorDepth = mDesc.colorDepth;
+		mColorDepth = 32;
 		mWidth = mHeight = mLeft = mTop = 0;
 
 		mActive = true;
 		mClosed = false;
 
+		if (mDesc.videoMode.isCustom())
+		{
+			mRefreshRateNumerator = Math::roundToInt(mDesc.videoMode.getRefreshRate());
+			mRefreshRateDenominator = 1;
+		}
+		else
+		{
+			const D3D11VideoMode& d3d11videoMode = static_cast<const D3D11VideoMode&>(mDesc.videoMode);
+			mRefreshRateNumerator = d3d11videoMode.getRefreshRateNumerator();
+			mRefreshRateDenominator = d3d11videoMode.getRefreshRateDenominator();
+		}
+
+		HMONITOR hMonitor = NULL;
+		const D3D11VideoOutputInfo* outputInfo = nullptr;
+
+		const D3D11VideoModeInfo& videoModeInfo = static_cast<const D3D11VideoModeInfo&>(RenderSystem::instance().getVideoModeInfo());
+		UINT32 numOutputs = videoModeInfo.getNumOutputs();
+		if (numOutputs > 0)
+		{
+			UINT32 actualMonitorIdx = std::min(mDesc.videoMode.getOutputIdx(), numOutputs - 1);
+			outputInfo = static_cast<const D3D11VideoOutputInfo*>(&videoModeInfo.getOutputInfo(actualMonitorIdx));
+
+			DXGI_OUTPUT_DESC desc;
+			outputInfo->getDXGIOutput()->GetDesc(&desc);
+
+			hMonitor = desc.Monitor;
+		}
+
 		if (!externalHandle)
 		{
 			DWORD dwStyle = (mHidden ? 0 : WS_VISIBLE) | WS_CLIPCHILDREN;
@@ -79,36 +91,6 @@ namespace BansheeEngine
 			RECT rc;
 			MONITORINFO monitorInfo;
 
-			// If we specified which adapter we want to use - find it's monitor.
-			if (mDesc.monitorIndex != -1)
-			{
-				RenderSystem* rs = RenderSystem::instancePtr();
-				D3D11RenderSystem* d3d11rs = static_cast<D3D11RenderSystem*>(rs);
-
-				D3D11DriverList* driverList = d3d11rs->getDriverList();
-
-				UINT32 curOutput = 0;
-				for(UINT32 i = 0; i < driverList->count(); i++)
-				{
-					D3D11Driver* driver = driverList->item(i);
-					UINT32 numOutputs = driver->getNumAdapterOutputs();
-
-					for(UINT32 j = 0; j < numOutputs; j++)
-					{
-						if(curOutput == mDesc.monitorIndex)
-						{
-							hMonitor = driver->getOutputDesc(j).Monitor;
-							break;
-						}
-
-						curOutput++;
-					}
-
-					if(curOutput == mDesc.monitorIndex)
-						break;
-				}			
-			}
-
 			// If we didn't specified the adapter index, or if it didn't find it
 			if (hMonitor == NULL)
 			{
@@ -129,8 +111,8 @@ namespace BansheeEngine
 
 
 			unsigned int winWidth, winHeight;
-			winWidth = mDesc.width;
-			winHeight = mDesc.height;
+			winWidth = mDesc.videoMode.getWidth();
+			winHeight = mDesc.videoMode.getHeight();
 
 			UINT32 left = mDesc.left;
 			UINT32 top = mDesc.top;
@@ -147,22 +129,22 @@ namespace BansheeEngine
 
 				if (left == -1)
 					left = monitorInfo.rcWork.left + (screenw - outerw) / 2;
-				else if (mDesc.monitorIndex != -1)
+				else if (hMonitor != NULL)
 					left += monitorInfo.rcWork.left;
 
 				if (top == -1)
 					top = monitorInfo.rcWork.top + (screenh - outerh) / 2;
-				else if (mDesc.monitorIndex != -1)
+				else if (hMonitor != NULL)
 					top += monitorInfo.rcWork.top;
 			}
-			else if (mDesc.monitorIndex != -1)
+			else if (hMonitor != NULL)
 			{
 				left += monitorInfo.rcWork.left;
 				top += monitorInfo.rcWork.top;
 			}
 
-			mWidth = mDesc.width;
-			mHeight = mDesc.height;
+			mWidth = mDesc.videoMode.getWidth();
+			mHeight = mDesc.videoMode.getHeight();
 			mTop = top;
 			mLeft = left;
 
@@ -242,16 +224,24 @@ namespace BansheeEngine
 		}
 
 		RECT rc;
-		// top and left represent outer window coordinates
 		GetWindowRect(mHWnd, &rc);
 		mTop = rc.top;
 		mLeft = rc.left;
-		// width and height represent interior drawable area
+
 		GetClientRect(mHWnd, &rc);
 		mWidth = rc.right;
 		mHeight = rc.bottom;
 
 		createSwapChain();
+
+		if (mIsFullScreen)
+		{
+			if (outputInfo != nullptr)
+				mSwapChain->SetFullscreenState(true, outputInfo->getDXGIOutput());
+			else
+				mSwapChain->SetFullscreenState(true, nullptr);
+		}
+
 		createSizeDependedD3DResources();
 		mDXGIFactory->MakeWindowAssociation(mHWnd, NULL);
 		setHidden(mHidden);
@@ -489,11 +479,11 @@ namespace BansheeEngine
 		if(mBackBuffer == nullptr)
 			return;
 
-		// get the backbuffer desc
+		// Get the backbuffer desc
 		D3D11_TEXTURE2D_DESC BBDesc;
 		mBackBuffer->GetDesc(&BBDesc);
 
-		ID3D11Texture2D *backbuffer = nullptr;
+		ID3D11Texture2D* backbuffer = nullptr;
 
 		if(BBDesc.SampleDesc.Quality > 0)
 		{
@@ -504,59 +494,51 @@ namespace BansheeEngine
 			desc.SampleDesc.Quality = 0;
 			desc.SampleDesc.Count = 1;
 
-			HRESULT hr = mDevice.getD3D11Device()->CreateTexture2D(
-				&desc,
-				NULL,
-				&backbuffer);
+			HRESULT hr = mDevice.getD3D11Device()->CreateTexture2D(&desc, nullptr, &backbuffer);
 
 			if (FAILED(hr) || mDevice.hasError())
 			{
 				String errorDescription = mDevice.getErrorDescription();
-				CM_EXCEPT(RenderingAPIException,
-					"Error creating texture\nError Description:" + errorDescription);
+				CM_EXCEPT(RenderingAPIException, "Error creating texture\nError Description:" + errorDescription);
 			}
 
 			mDevice.getImmediateContext()->ResolveSubresource(backbuffer, D3D11CalcSubresource(0, 0, 1), mBackBuffer, D3D11CalcSubresource(0, 0, 1), desc.Format);
 		}
 
-
-		// change the parameters of the texture so we can read it
+		// Change the parameters of the texture so we can read it
 		BBDesc.Usage = D3D11_USAGE_STAGING;
 		BBDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
 		BBDesc.BindFlags = 0;
 		BBDesc.SampleDesc.Quality = 0;
 		BBDesc.SampleDesc.Count = 1;
 
-		// create a temp buffer to copy to
-		ID3D11Texture2D * pTempTexture2D;
-		HRESULT hr = mDevice.getD3D11Device()->CreateTexture2D(
-			&BBDesc,
-			NULL,
-			&pTempTexture2D);
+		// Create a temp buffer to copy to
+		ID3D11Texture2D* tempTexture;
+		HRESULT hr = mDevice.getD3D11Device()->CreateTexture2D(&BBDesc, nullptr, &tempTexture);
 
 		if (FAILED(hr) || mDevice.hasError())
 		{
 			String errorDescription = mDevice.getErrorDescription();
-			CM_EXCEPT(RenderingAPIException,
-				"Error creating texture\nError Description:" + errorDescription);
+			CM_EXCEPT(RenderingAPIException, "Error creating texture\nError Description:" + errorDescription);
 		}
-		// copy the back buffer
-		mDevice.getImmediateContext()->CopyResource(pTempTexture2D, backbuffer != NULL ? backbuffer : mBackBuffer);
 
-		// map the copied texture
+		// Copy the back buffer
+		mDevice.getImmediateContext()->CopyResource(tempTexture, backbuffer != NULL ? backbuffer : mBackBuffer);
+
+		// Map the copied texture
 		D3D11_MAPPED_SUBRESOURCE mappedTex2D;
-		mDevice.getImmediateContext()->Map(pTempTexture2D, 0,D3D11_MAP_READ, 0, &mappedTex2D);
+		mDevice.getImmediateContext()->Map(tempTexture, 0,D3D11_MAP_READ, 0, &mappedTex2D);
 
-		// copy the the texture to the dest
+		// Copy the the texture to the dest
 		PixelData src(mWidth, mHeight, 1, PF_A8B8G8R8);
 		src.setExternalBuffer((UINT8*)mappedTex2D.pData);
 		PixelUtil::bulkPixelConversion(src, dst);
 
-		// unmap the temp buffer
-		mDevice.getImmediateContext()->Unmap(pTempTexture2D, 0);
+		// Unmap the temp buffer
+		mDevice.getImmediateContext()->Unmap(tempTexture, 0);
 
 		// Release the temp buffer
-		SAFE_RELEASE(pTempTexture2D);
+		SAFE_RELEASE(tempTexture);
 		SAFE_RELEASE(backbuffer);
 	}
 
@@ -588,17 +570,17 @@ namespace BansheeEngine
 			return;
 
 		RECT rc;
-		// top and left represent outer window position
 		GetWindowRect(mHWnd, &rc);
 		mTop = rc.top;
 		mLeft = rc.left;
-		// width and height represent drawable area only
+
 		GetClientRect(mHWnd, &rc);
 		unsigned int width = rc.right - rc.left;
 		unsigned int height = rc.bottom - rc.top;
 
 		if (width == 0) 
 			width = 1;
+
 		if (height == 0)
 			height = 1;
 
@@ -611,34 +593,41 @@ namespace BansheeEngine
 	{
 		ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
 
-		// get the dxgi device
 		IDXGIDevice* pDXGIDevice = queryDxgiDevice();
 
 		ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
 		DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
-		mSwapChainDesc.OutputWindow			= mHWnd;
-		mSwapChainDesc.BufferDesc.Width		= mWidth;
-		mSwapChainDesc.BufferDesc.Height	= mHeight;
-		mSwapChainDesc.BufferDesc.Format	= format;
-		mSwapChainDesc.BufferDesc.RefreshRate.Numerator=0;
-		mSwapChainDesc.BufferDesc.RefreshRate.Denominator = 0;
+		mSwapChainDesc.OutputWindow	= mHWnd;
+		mSwapChainDesc.BufferDesc.Width = mWidth;
+		mSwapChainDesc.BufferDesc.Height = mHeight;
+		mSwapChainDesc.BufferDesc.Format = format;
+
+		if (mIsFullScreen)
+		{
+			mSwapChainDesc.BufferDesc.RefreshRate.Numerator = mRefreshRateNumerator;
+			mSwapChainDesc.BufferDesc.RefreshRate.Denominator = mRefreshRateDenominator;
+		}
+		else
+		{
+			mSwapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
+			mSwapChainDesc.BufferDesc.RefreshRate.Denominator = 0;
+		}
 
 		mSwapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
 		mSwapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
 		mSwapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH ;
 
-		mSwapChainDesc.BufferUsage			= DXGI_USAGE_RENDER_TARGET_OUTPUT;
-		mSwapChainDesc.BufferCount			= 1;
-		mSwapChainDesc.SwapEffect			= DXGI_SWAP_EFFECT_DISCARD ;
+		mSwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
+		mSwapChainDesc.BufferCount = 1;
+		mSwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD ;
 
-		mSwapChainDesc.OutputWindow 		= mHWnd;
-		mSwapChainDesc.Windowed				= !mIsFullScreen;
+		mSwapChainDesc.Windowed	= false;
 
 		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
 		rs->determineMultisampleSettings(mMultisampleCount, mMultisampleHint, format, &mMultisampleType);
 		mSwapChainDesc.SampleDesc.Count = mMultisampleType.Count;
 		mSwapChainDesc.SampleDesc.Quality = mMultisampleType.Quality;
-
+		
 		HRESULT hr;
 
 		// Create swap chain			
@@ -659,21 +648,17 @@ namespace BansheeEngine
 
 	void D3D11RenderWindow::createSizeDependedD3DResources()
 	{
-		// obtain back buffer
 		SAFE_RELEASE(mBackBuffer);
 
 		HRESULT hr = mSwapChain->GetBuffer(0,  __uuidof(ID3D11Texture2D), (LPVOID*)&mBackBuffer);
-		if( FAILED(hr) )
+		if(FAILED(hr))
 			CM_EXCEPT(RenderingAPIException, "Unable to Get Back Buffer for swap chain");
 
-		// create all other size depended resources
 		assert(mBackBuffer && !mRenderTargetView);
 
-		// get the backbuffer desc
 		D3D11_TEXTURE2D_DESC BBDesc;
 		mBackBuffer->GetDesc(&BBDesc);
 
-		// create the render target view
 		D3D11_RENDER_TARGET_VIEW_DESC RTVDesc;
 		ZeroMemory( &RTVDesc, sizeof(RTVDesc) );
 
@@ -682,7 +667,7 @@ namespace BansheeEngine
 		RTVDesc.Texture2D.MipSlice = 0;
 		hr = mDevice.getD3D11Device()->CreateRenderTargetView(mBackBuffer, &RTVDesc, &mRenderTargetView);
 
-		if( FAILED(hr) )
+		if(FAILED(hr))
 		{
 			String errorDescription = mDevice.getErrorDescription();
 			CM_EXCEPT(RenderingAPIException, "Unable to create rendertagert view\nError Description:" + errorDescription);
@@ -712,7 +697,6 @@ namespace BansheeEngine
 	{
 		destroySizeDependedD3DResources();
 
-		// width and height can be zero to autodetect size, therefore do not rely on them
 		UINT Flags = mIsFullScreen ? DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH : 0;
 		HRESULT hr = mSwapChain->ResizeBuffers(mSwapChainDesc.BufferCount, width, height, mSwapChainDesc.BufferDesc.Format, Flags);
 
@@ -738,6 +722,7 @@ namespace BansheeEngine
 
 		IDXGIDevice* pDXGIDevice = nullptr;
 		HRESULT hr = mDevice.getD3D11Device()->QueryInterface(__uuidof(IDXGIDevice), (void**)&pDXGIDevice);
+
 		if(FAILED(hr))
 			CM_EXCEPT(RenderingAPIException, "Unable to query a DXGIDevice");
 

+ 5 - 5
CamelotD3D11RenderSystem/Source/CmD3D11VideoModeInfo.cpp

@@ -51,8 +51,8 @@ namespace BansheeEngine
 				D3D11VideoMode* d3d11videoMode = static_cast<D3D11VideoMode*>(videoMode);
 
 				if (d3d11videoMode->mWidth == displayMode.Width && d3d11videoMode->mHeight == displayMode.Height &&
-					d3d11videoMode->refreshRateNumerator == displayMode.RefreshRate.Numerator &&
-					d3d11videoMode->refreshRateDenominator == displayMode.RefreshRate.Denominator)
+					d3d11videoMode->mRefreshRateNumerator == displayMode.RefreshRate.Numerator &&
+					d3d11videoMode->mRefreshRateDenominator == displayMode.RefreshRate.Denominator)
 				{
 					foundVideoMode = true;
 					break;
@@ -63,7 +63,7 @@ namespace BansheeEngine
 			{
 				float refreshRate = displayMode.RefreshRate.Numerator / (float)displayMode.RefreshRate.Denominator;
 				D3D11VideoMode* videoMode = cm_new<D3D11VideoMode>(displayMode.Width, displayMode.Height, refreshRate,
-					displayMode.RefreshRate.Numerator, displayMode.RefreshRate.Denominator, displayMode, this);
+					outputIdx, displayMode.RefreshRate.Numerator, displayMode.RefreshRate.Denominator, displayMode);
 
 				mVideoModes.push_back(videoMode);
 			}
@@ -109,7 +109,7 @@ namespace BansheeEngine
 
 	D3D11VideoMode::D3D11VideoMode(UINT32 width, UINT32 height, float refreshRate, UINT32 outputIdx, 
 		UINT32 refreshRateNumerator, UINT32 refreshRateDenominator, DXGI_MODE_DESC mode)
-		:VideoMode(width, height, refreshRate, outputIdx), refreshRateNumerator(refreshRateNumerator),
-		refreshRateDenominator(refreshRateDenominator), mD3D11Mode(mode)
+		:VideoMode(width, height, refreshRate, outputIdx), mRefreshRateNumerator(refreshRateNumerator),
+		mRefreshRateDenominator(refreshRateDenominator), mD3D11Mode(mode)
 	{ }
 }

+ 8 - 18
CamelotD3D9Renderer/Source/CmD3D9Device.cpp

@@ -432,16 +432,12 @@ namespace BansheeEngine
 				// Ask the render window to build it's own parameters.
 				renderWindow->_buildPresentParameters(&renderWindowResources->presentParameters);
 				
-
 				// Update shared focus window handle.
-				if (renderWindow->isFullScreen() && 
-					renderWindowResources->presentParametersIndex == 0 &&
-					msSharedFocusWindow == NULL)
+				if (renderWindow->isFullScreen() && renderWindowResources->presentParametersIndex == 0 && msSharedFocusWindow == NULL)
 					setSharedWindowHandle(renderWindow->_getWindowHandle());					
 
 				// This is the primary window or a full screen window that is part of multi head device.
-				if (renderWindowResources->presentParametersIndex == 0 ||
-					renderWindow->isFullScreen())
+				if (renderWindowResources->presentParametersIndex == 0 || renderWindow->isFullScreen())
 				{
 					mPresentationParams[renderWindowResources->presentParametersIndex] = renderWindowResources->presentParameters;
 					mPresentationParamsCount++;
@@ -473,18 +469,12 @@ namespace BansheeEngine
 
 	bool D3D9Device::isMultihead() const
 	{
-		RenderWindowToResorucesMap::const_iterator it = mMapRenderWindowToResoruces.begin();
-
-		while (it != mMapRenderWindowToResoruces.end())				
+		for (auto& resourceData : mMapRenderWindowToResoruces)
 		{
-			RenderWindowResources* renderWindowResources = it->second;
-			
-			if (renderWindowResources->adapterOrdinalInGroupIndex > 0 && it->first->isFullScreen())
-			{
+			RenderWindowResources* renderWindowResources = resourceData.second;
+
+			if (renderWindowResources->adapterOrdinalInGroupIndex > 0 && resourceData.first->isFullScreen())
 				return true;
-			}
-			
-			++it;		
 		}
 
 		return false;
@@ -581,7 +571,7 @@ namespace BansheeEngine
 
 		if (FAILED(hr))
 		{
-			// try to create the device with software vertex processing.
+			// Try to create the device with software vertex processing.
 			mBehaviorFlags &= ~D3DCREATE_MIXED_VERTEXPROCESSING;
 			mBehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
 			hr = pD3D9->CreateDevice(mAdapterNumber, mDeviceType, mFocusWindow,
@@ -590,7 +580,7 @@ namespace BansheeEngine
 
 		if (FAILED(hr))
 		{
-			// try reference device
+			// Try reference device
 			mDeviceType = D3DDEVTYPE_REF;
 			hr = pD3D9->CreateDevice(mAdapterNumber, mDeviceType, mFocusWindow,
 				mBehaviorFlags, mPresentationParams, &mpDevice);

+ 57 - 75
CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp

@@ -37,16 +37,16 @@ namespace BansheeEngine
 		mMultisampleCount = mDesc.multisampleCount;
 		mVSync = mDesc.vsync;
 		mVSyncInterval = mDesc.vsyncInterval;
+		mDisplayFrequency = Math::roundToInt(mDesc.videoMode.getRefreshRate());
 
 		HWND parentHWnd = 0;
 		HWND externalHandle = 0;
 
 		NameValuePairList::const_iterator opt;
-		// parentWindowHandle		-> parentHWnd
 		opt = mDesc.platformSpecific.find("parentWindowHandle");
 		if(opt != mDesc.platformSpecific.end())
 			parentHWnd = (HWND)parseUnsignedInt(opt->second);
-		// externalWindowHandle		-> externalHandle
+
 		opt = mDesc.platformSpecific.find("externalWindowHandle");
 		if(opt != mDesc.platformSpecific.end())
 			externalHandle = (HWND)parseUnsignedInt(opt->second);
@@ -55,25 +55,19 @@ namespace BansheeEngine
 
 		if (!externalHandle)
 		{
-			DWORD		dwStyle = WS_VISIBLE | WS_CLIPCHILDREN;
-			DWORD		dwStyleEx = 0;
-			HMONITOR    hMonitor = NULL;		
+			DWORD dwStyle = WS_VISIBLE | WS_CLIPCHILDREN;
+			DWORD dwStyleEx = 0;	
 			MONITORINFO monitorInfo;
-			RECT		rc;
+			RECT rc;
 
-			// If we specified which adapter we want to use - find it's monitor.
-			if (mDesc.monitorIndex != -1)
+			HMONITOR hMonitor = NULL;
+			const D3D9VideoModeInfo& videoModeInfo = static_cast<const D3D9VideoModeInfo&>(RenderSystem::instance().getVideoModeInfo());
+			UINT32 numOutputs = videoModeInfo.getNumOutputs();
+			if (numOutputs > 0)
 			{
-				IDirect3D9* direct3D9 = D3D9RenderSystem::getDirect3D9();
-
-				for (UINT32 i=0; i < direct3D9->GetAdapterCount(); ++i)
-				{
-					if (i == mDesc.monitorIndex)
-					{
-						hMonitor = direct3D9->GetAdapterMonitor(i);
-						break;
-					}
-				}				
+				UINT32 actualMonitorIdx = std::min(mDesc.videoMode.getOutputIdx(), numOutputs - 1);
+				const D3D9VideoOutputInfo& outputInfo = static_cast<const D3D9VideoOutputInfo&>(videoModeInfo.getOutputInfo(actualMonitorIdx));
+				hMonitor = outputInfo.getMonitorHandle();
 			}
 
 			// If we didn't specified the adapter index, or if it didn't find it
@@ -94,10 +88,9 @@ namespace BansheeEngine
 			monitorInfo.cbSize = sizeof(MONITORINFO);
 			GetMonitorInfo(hMonitor, &monitorInfo);
 
-
 			unsigned int winWidth, winHeight;
-			winWidth = mDesc.width;
-			winHeight = mDesc.height;
+			winWidth = mDesc.videoMode.getWidth();
+			winHeight = mDesc.videoMode.getHeight();
 
 			UINT32 left = mDesc.left;
 			UINT32 top = mDesc.top;
@@ -114,22 +107,22 @@ namespace BansheeEngine
 
 				if (left == -1)
 					left = monitorInfo.rcWork.left + (screenw - outerw) / 2;
-				else if (mDesc.monitorIndex != -1)
+				else if (hMonitor != NULL)
 					left += monitorInfo.rcWork.left;
 
 				if (top == -1)
 					top = monitorInfo.rcWork.top + (screenh - outerh) / 2;
-				else if (mDesc.monitorIndex != -1)
+				else if (hMonitor != NULL)
 					top += monitorInfo.rcWork.top;
 			}
-			else if (mDesc.monitorIndex != -1)
+			else if (hMonitor != NULL)
 			{
 				left += monitorInfo.rcWork.left;
 				top += monitorInfo.rcWork.top;
 			}
 
-			mWidth = mDesiredWidth = mDesc.width;
-			mHeight = mDesiredHeight = mDesc.height;
+			mWidth = mDesiredWidth = mDesc.videoMode.getWidth();
+			mHeight = mDesiredHeight = mDesc.videoMode.getHeight();
 			mTop = top;
 			mLeft = left;
 
@@ -161,7 +154,7 @@ namespace BansheeEngine
 						dwStyle |= WS_OVERLAPPEDWINDOW;
 				}
 
-				_adjustWindow(mDesc.width, mDesc.height, dwStyle, &winWidth, &winHeight);
+				_adjustWindow(mDesc.videoMode.getWidth(), mDesc.videoMode.getHeight(), dwStyle, &winWidth, &winHeight);
 
 				if (!mDesc.outerDimensions)
 				{
@@ -209,11 +202,10 @@ namespace BansheeEngine
 		}
 
 		RECT rc;
-		// top and left represent outer window coordinates
 		GetWindowRect(mHWnd, &rc);
 		mTop = rc.top;
 		mLeft = rc.left;
-		// width and height represent interior drawable area
+
 		GetClientRect(mHWnd, &rc);
 		mWidth = rc.right;
 		mHeight = rc.bottom;
@@ -221,7 +213,7 @@ namespace BansheeEngine
 		mName = mDesc.title;
 		mIsDepthBuffered = mDesc.depthBuffer;
 		mIsFullScreen = mDesc.fullscreen && !mIsChild;
-		mColorDepth = mDesc.colorDepth;
+		mColorDepth = 32;
 
 		mActive = true;
 		mClosed = false;
@@ -516,23 +508,21 @@ namespace BansheeEngine
 	}
 	
 	void D3D9RenderWindow::_buildPresentParameters(D3DPRESENT_PARAMETERS* presentParams) const
-	{		
-		// Set up the presentation parameters		
+	{			
 		IDirect3D9* pD3D = D3D9RenderSystem::getDirect3D9();
 		D3DDEVTYPE devType = D3DDEVTYPE_HAL;
 
 		if (mDevice != NULL)		
 			devType = mDevice->getDeviceType();		
 	
-
 		ZeroMemory( presentParams, sizeof(D3DPRESENT_PARAMETERS) );
-		presentParams->Windowed					= !mIsFullScreen;
-		presentParams->SwapEffect				= D3DSWAPEFFECT_DISCARD;
-		presentParams->BackBufferCount			= 1;
-		presentParams->EnableAutoDepthStencil	= mIsDepthBuffered;
-		presentParams->hDeviceWindow			= mHWnd;
-		presentParams->BackBufferWidth			= mWidth;
-		presentParams->BackBufferHeight			= mHeight;
+		presentParams->Windowed = !mIsFullScreen;
+		presentParams->SwapEffect = D3DSWAPEFFECT_DISCARD;
+		presentParams->BackBufferCount = 1;
+		presentParams->EnableAutoDepthStencil = mIsDepthBuffered;
+		presentParams->hDeviceWindow = mHWnd;
+		presentParams->BackBufferWidth = mWidth;
+		presentParams->BackBufferHeight	= mHeight;
 		presentParams->FullScreen_RefreshRateInHz = mIsFullScreen ? mDisplayFrequency : 0;
 		
 		if (presentParams->BackBufferWidth == 0)		
@@ -541,10 +531,8 @@ namespace BansheeEngine
 		if (presentParams->BackBufferHeight == 0)	
 			presentParams->BackBufferHeight = 1;					
 
-
 		if (mVSync)
 		{
-			// D3D9 only seems to support 2-4 presentation intervals in fullscreen
 			if (mIsFullScreen)
 			{
 				switch(mVSyncInterval)
@@ -563,11 +551,13 @@ namespace BansheeEngine
 					presentParams->PresentationInterval = D3DPRESENT_INTERVAL_FOUR;
 					break;
 				};
-				// check that the interval was supported, revert to 1 to be safe otherwise
+
 				D3DCAPS9 caps;
 				pD3D->GetDeviceCaps(mDevice->getAdapterNumber(), devType, &caps);
 				if (!(caps.PresentationIntervals & presentParams->PresentationInterval))
+				{
 					presentParams->PresentationInterval = D3DPRESENT_INTERVAL_ONE;
+				}
 
 			}
 			else
@@ -580,51 +570,43 @@ namespace BansheeEngine
 			presentParams->PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
 		}
 
-		presentParams->BackBufferFormat	= D3DFMT_R5G6B5;
-		if(mColorDepth > 16)
-			presentParams->BackBufferFormat = D3DFMT_X8R8G8B8;
+		presentParams->BackBufferFormat = D3DFMT_X8R8G8B8;
 
-		if (mColorDepth > 16)
+		if (FAILED(pD3D->CheckDeviceFormat(mDevice->getAdapterNumber(),
+			devType, presentParams->BackBufferFormat, D3DUSAGE_DEPTHSTENCIL,
+			D3DRTYPE_SURFACE, D3DFMT_D24S8)))
 		{
-			if(FAILED( pD3D->CheckDeviceFormat(mDevice->getAdapterNumber(),
-				devType,  presentParams->BackBufferFormat,  D3DUSAGE_DEPTHSTENCIL, 
-				D3DRTYPE_SURFACE, D3DFMT_D24S8)))
+			if (FAILED(pD3D->CheckDeviceFormat(mDevice->getAdapterNumber(),
+				devType, presentParams->BackBufferFormat, D3DUSAGE_DEPTHSTENCIL,
+				D3DRTYPE_SURFACE, D3DFMT_D32)))
 			{
-				if(FAILED( pD3D->CheckDeviceFormat(mDevice->getAdapterNumber(),
-					devType,  presentParams->BackBufferFormat,  D3DUSAGE_DEPTHSTENCIL, 
-					D3DRTYPE_SURFACE, D3DFMT_D32)))
-				{
-					presentParams->AutoDepthStencilFormat = D3DFMT_D16;
-				}
-				else
-				{
-					presentParams->AutoDepthStencilFormat = D3DFMT_D32;
-				}
+				presentParams->AutoDepthStencilFormat = D3DFMT_D16;
 			}
 			else
 			{
-				if(SUCCEEDED( pD3D->CheckDepthStencilMatch( mDevice->getAdapterNumber(), devType,
-				presentParams->BackBufferFormat, presentParams->BackBufferFormat, D3DFMT_D24S8)))
-				{
-					presentParams->AutoDepthStencilFormat = D3DFMT_D24S8; 
-				} 
-				else
-				{
-					presentParams->AutoDepthStencilFormat = D3DFMT_D24X8;
-				}
+				presentParams->AutoDepthStencilFormat = D3DFMT_D32;
 			}
 		}
 		else
-			presentParams->AutoDepthStencilFormat = D3DFMT_D16;
+		{
+			if (SUCCEEDED(pD3D->CheckDepthStencilMatch(mDevice->getAdapterNumber(), devType,
+				presentParams->BackBufferFormat, presentParams->BackBufferFormat, D3DFMT_D24S8)))
+			{
+				presentParams->AutoDepthStencilFormat = D3DFMT_D24S8;
+			}
+			else
+			{
+				presentParams->AutoDepthStencilFormat = D3DFMT_D24X8;
+			}
+		}
 
-		D3D9RenderSystem* rsys = static_cast<D3D9RenderSystem*>(BansheeEngine::RenderSystem::instancePtr());
+		D3D9RenderSystem* rs = static_cast<D3D9RenderSystem*>(BansheeEngine::RenderSystem::instancePtr());
 
 		D3DMULTISAMPLE_TYPE multisampleType;
 		DWORD multisampleQuality;
 
-		rsys->determineMultisampleSettings(mDevice->getD3D9Device(),
-			mMultisampleCount, mMultisampleHint, presentParams->BackBufferFormat, mIsFullScreen, 
-			&multisampleType, &multisampleQuality);
+		rs->determineMultisampleSettings(mDevice->getD3D9Device(), mMultisampleCount, mMultisampleHint, 
+			presentParams->BackBufferFormat, mIsFullScreen, &multisampleType, &multisampleQuality);
 
 		presentParams->MultiSampleType = multisampleType;
 		presentParams->MultiSampleQuality = (multisampleQuality == 0) ? 0 : multisampleQuality;
@@ -675,7 +657,7 @@ namespace BansheeEngine
 		mTop = rc.top;
 		mLeft = rc.left;
 
-		// width and height represent drawable area only
+		// Width and height represent drawable area only
 		result = GetClientRect(mHWnd, &rc);
 		if (result == FALSE)
 		{

+ 43 - 41
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -53,14 +53,10 @@ namespace BansheeEngine
 		mIsFullScreen = mDesc.fullscreen;
 		mClosed = false;
 		mIsChild = false;
-		mDisplayFrequency = mDesc.displayFrequency;
-		mColorDepth = mDesc.colorDepth;
+		mDisplayFrequency = Math::roundToInt(mDesc.videoMode.getRefreshRate());
+		mColorDepth = 32;
 		HWND parent = 0;
-		HMONITOR hMonitor = NULL;
-
-		int monitorIndex = mDesc.monitorIndex;
 
-		// Get variable-length params
 		NameValuePairList::const_iterator opt;
 		NameValuePairList::const_iterator end = mDesc.platformSpecific.end();
 
@@ -70,8 +66,6 @@ namespace BansheeEngine
 			if (mHWnd)
 			{
 				mIsExternal = true;
-				mIsChild = true;
-				mIsFullScreen = false;
 			}
 
 			if ((opt = mDesc.platformSpecific.find("externalGLControl")) != end) {
@@ -85,17 +79,26 @@ namespace BansheeEngine
 			glrc = (HGLRC)parseUnsignedLong(opt->second);
 		}
 
-		// incompatible with fullscreen
 		if ((opt = mDesc.platformSpecific.find("parentWindowHandle")) != end)
+		{
 			parent = (HWND)parseUnsignedInt(opt->second);
+			mIsChild = true;
+			mIsFullScreen = false;
+		}
 
-		// monitor handle
-		if ((opt = mDesc.platformSpecific.find("monitorHandle")) != end)
-			hMonitor = (HMONITOR)parseInt(opt->second);			
+		HMONITOR hMonitor = NULL;
+		const Win32VideoModeInfo& videoModeInfo = static_cast<const Win32VideoModeInfo&>(RenderSystem::instance().getVideoModeInfo());
+		UINT32 numOutputs = videoModeInfo.getNumOutputs();
+		if (numOutputs > 0)
+		{
+			UINT32 actualMonitorIdx = std::min(mDesc.videoMode.getOutputIdx(), numOutputs - 1);
+			const Win32VideoOutputInfo& outputInfo = static_cast<const Win32VideoOutputInfo&>(videoModeInfo.getOutputInfo(actualMonitorIdx));
+			hMonitor = outputInfo.getMonitorHandle();
+		}
 
 		if (!mIsFullScreen)
 		{
-			// make sure we don't exceed desktop colour depth
+			// Make sure we don't exceed desktop color depth
 			if ((int)mColorDepth > GetDeviceCaps(GetDC(0), BITSPIXEL))
 				mColorDepth = GetDeviceCaps(GetDC(0), BITSPIXEL);
 		}
@@ -116,7 +119,6 @@ namespace BansheeEngine
 				windowAnchorPoint.x = mDesc.left;
 				windowAnchorPoint.y = mDesc.top;
 
-
 				// Get the nearest monitor to this window.
 				hMonitor = MonitorFromPoint(windowAnchorPoint, MONITOR_DEFAULTTONEAREST);
 			}
@@ -141,7 +143,7 @@ namespace BansheeEngine
 				int screenh = monitorInfoEx.rcWork.bottom - monitorInfoEx.rcWork.top;
 
 				unsigned int winWidth, winHeight;
-				_adjustWindow(mDesc.width, mDesc.height, &winWidth, &winHeight);
+				_adjustWindow(mDesc.videoMode.getWidth(), mDesc.videoMode.getHeight(), &winWidth, &winHeight);
 
 				// clamp window dimensions to screen size
 				int outerw = (int(winWidth) < screenw)? int(winWidth) : screenw;
@@ -149,22 +151,22 @@ namespace BansheeEngine
 
 				if (left == -1)
 					left = monitorInfoEx.rcWork.left + (screenw - outerw) / 2;
-				else if (mDesc.monitorIndex != -1)
+				else if (hMonitor != NULL)
 					left += monitorInfoEx.rcWork.left;
 
 				if (top == -1)
 					top = monitorInfoEx.rcWork.top + (screenh - outerh) / 2;
-				else if (mDesc.monitorIndex != -1)
+				else if (hMonitor != NULL)
 					top += monitorInfoEx.rcWork.top;
 			}
-			else if (mDesc.monitorIndex != -1)
+			else if (hMonitor != NULL)
 			{
 				left += monitorInfoEx.rcWork.left;
 				top += monitorInfoEx.rcWork.top;
 			}
 
-			mWidth = mDesc.width;
-			mHeight = mDesc.height;
+			mWidth = mDesc.videoMode.getWidth();
+			mHeight = mDesc.videoMode.getHeight();
 			mTop = top;
 			mLeft = left;
 
@@ -244,17 +246,16 @@ namespace BansheeEngine
 				{
 					displayDeviceMode.dmDisplayFrequency = mDisplayFrequency;
 					displayDeviceMode.dmFields |= DM_DISPLAYFREQUENCY;
+
 					if (ChangeDisplaySettingsEx(mDeviceName, &displayDeviceMode, NULL, CDS_FULLSCREEN | CDS_TEST, NULL) != DISP_CHANGE_SUCCESSFUL)
 					{
-						// TODO LOG PORT - Log this somewhere
-						//LogManager::getSingleton().logMessage(LML_NORMAL, "ChangeDisplaySettings with user display frequency failed");
-						//displayDeviceMode.dmFields ^= DM_DISPLAYFREQUENCY;
+						CM_EXCEPT(RenderingAPIException, "ChangeDisplaySettings with user display frequency failed.");
 					}
 				}
+
 				if (ChangeDisplaySettingsEx(mDeviceName, &displayDeviceMode, NULL, CDS_FULLSCREEN, NULL) != DISP_CHANGE_SUCCESSFUL)
 				{
-					// TODO LOG PORT - Log this somewhere
-					//LogManager::getSingleton().logMessage(LML_CRITICAL, "ChangeDisplaySettings failed");
+					CM_EXCEPT(RenderingAPIException, "ChangeDisplaySettings failed.");
 				}
 			}
 
@@ -264,11 +265,11 @@ namespace BansheeEngine
 		}
 
 		RECT rc;
-		// top and left represent outer window position
+
 		GetWindowRect(mHWnd, &rc);
 		mTop = rc.top;
 		mLeft = rc.left;
-		// width and height represent drawable area only
+
 		GetClientRect(mHWnd, &rc);
 		mWidth = rc.right;
 		mHeight = rc.bottom;
@@ -284,14 +285,14 @@ namespace BansheeEngine
 			{
 				if (mMultisampleCount > 0)
 				{
-					// try without multisampling
+					// Try without multisampling
 					testMultisample = 0;
 					formatOk = mGLSupport.selectPixelFormat(mHDC, mColorDepth, testMultisample, testHwGamma);
 				}
 
 				if (!formatOk && mDesc.gamma)
 				{
-					// try without sRGB
+					// Try without sRGB
 					testHwGamma = false;
 					testMultisample = mMultisampleCount;
 					formatOk = mGLSupport.selectPixelFormat(mHDC, mColorDepth, testMultisample, testHwGamma);
@@ -299,17 +300,18 @@ namespace BansheeEngine
 
 				if (!formatOk && mDesc.gamma && (mMultisampleCount > 0))
 				{
-					// try without both
+					// Try without both
 					testHwGamma = false;
 					testMultisample = 0;
 					formatOk = mGLSupport.selectPixelFormat(mHDC, mColorDepth, testMultisample, testHwGamma);
 				}
 
 				if (!formatOk)
-					CM_EXCEPT(RenderingAPIException, "selectPixelFormat failed");
+					CM_EXCEPT(RenderingAPIException, "Failed selecting pixel format.");
 
 			}
-			// record what gamma option we used in the end
+
+			// Record what gamma option we used in the end
 			// this will control enabling of sRGB state flags when used
 			mHwGamma = testHwGamma;
 			mMultisampleCount = testMultisample;
@@ -393,7 +395,7 @@ namespace BansheeEngine
 		monitorInfo.cbSize = sizeof(MONITORINFOEX);
 		GetMonitorInfo(hMonitor, &monitorInfo);
 
-		// Move window to 0,0 before display switch
+		// Move window to 0, 0 before display switch
 		SetWindowPos(mHWnd, HWND_TOPMOST, 0, 0, mWidth, mHeight, SWP_NOACTIVATE);
 
 		if (ChangeDisplaySettingsEx(monitorInfo.szDevice, &displayDeviceMode, NULL, CDS_FULLSCREEN, NULL) != DISP_CHANGE_SUCCESSFUL)
@@ -588,12 +590,14 @@ namespace BansheeEngine
 		return Vector2I(pos.x, pos.y);
 	}	
 
-	void Win32Window::getCustomAttribute( const String& name, void* pData ) const
+	void Win32Window::getCustomAttribute(const String& name, void* pData) const
 	{
-		if( name == "GLCONTEXT" ) {
+		if(name == "GLCONTEXT") 
+		{
 			*static_cast<GLContext**>(pData) = mContext;
 			return;
-		} else if( name == "WINDOW" )
+		} 
+		else if(name == "WINDOW")
 		{
 			HWND *pHwnd = (HWND*)pData;
 			*pHwnd = _getWindowHandle();
@@ -601,7 +605,7 @@ namespace BansheeEngine
 		} 
 	}
 
-	void Win32Window::setActive( bool state )
+	void Win32Window::setActive(bool state)
 	{	
 		THROW_IF_NOT_CORE_THREAD;
 
@@ -671,13 +675,12 @@ namespace BansheeEngine
 			return;
 
 		RECT rc;
-		// top and left represent outer window position
+
 		GetWindowRect(mHWnd, &rc);
 		mTop = rc.top;
 		mLeft = rc.left;
-		// width and height represent drawable area only
-		GetClientRect(mHWnd, &rc);
 
+		GetClientRect(mHWnd, &rc);
 		mWidth = rc.right - rc.left;
 		mHeight = rc.bottom - rc.top;
 
@@ -711,6 +714,5 @@ namespace BansheeEngine
 			*winWidth = maxW;
 		if (*winHeight > (unsigned int)maxH)
 			*winHeight = maxH;
-
 	}
 }