Browse Source

Added DX9 render window fullscreen switching (not tested)
Some refactoring of DX9 device management

Marko Pintera 11 years ago
parent
commit
1c131997e7

+ 1 - 0
CamelotCore/Include/CmApplication.h

@@ -1,6 +1,7 @@
 #pragma once
 
 #include "CmPrerequisites.h"
+#include "CmModule.h"
 #include "CmCoreThreadAccessor.h"
 #include "CmRenderWindow.h"
 #include "BsEvent.h"

+ 3 - 2
CamelotCore/Include/CmRenderWindow.h

@@ -83,11 +83,12 @@ 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.
+		* @param	refreshRateIdx	Index of the refresh rate entry in the video mode object.
 		*
 		* @note		Core thread.
 		*/
-		virtual void setFullscreen(const VideoMode& mode) { }
+		virtual void setFullscreen(const VideoMode& mode, UINT32 refreshRateIdx = 0) { }
 
 		/**
 		 * @brief	Switches the window to windowed mode.

+ 1 - 3
CamelotD3D11RenderSystem/Include/CmD3D11RenderWindow.h

@@ -38,7 +38,7 @@ namespace BansheeEngine
 		/**
 		* @copydoc RenderWindow::setFullscreen
 		*/
-		void setFullscreen(const VideoMode& mode);
+		void setFullscreen(const VideoMode& mode, UINT32 refreshRateIdx = 0);
 
 		/**
 		* @copydoc RenderWindow::setWindowed
@@ -122,8 +122,6 @@ namespace BansheeEngine
 		bool mIsChild;
 
 		DXGI_SAMPLE_DESC mFSAAType;
-		UINT32 mRefreshRateNumerator;
-		UINT32 mRefreshRateDenominator;
 		bool mVSync;
 		UINT32 mVSyncInterval;
 

+ 9 - 7
CamelotD3D11RenderSystem/Include/CmD3D11VideoModeInfo.h

@@ -10,25 +10,27 @@ namespace BansheeEngine
 	 */
 	class CM_D3D11_EXPORT D3D11VideoMode : public VideoMode
 	{
-		struct RefreshRate
+		struct DX11Data
 		{
-			UINT32 numerator;
-			UINT32 denominator;
+			UINT32 refreshRateNumerator;
+			UINT32 refreshRateDenominator;
+			DXGI_MODE_DESC mode;
 		};
 
 	public:
-		D3D11VideoMode(UINT32 width, UINT32 height, VideoOutputInfo* outputInfo, DXGI_MODE_DESC dxgiMode);
+		D3D11VideoMode(UINT32 width, UINT32 height, VideoOutputInfo* outputInfo);
 
 		/**
 		 * @brief	Returns an internal DXGI representation of this video mode.
+		 *
+		 * @param	idx		Index referencing which refresh rate to use.
 		 */
-		const DXGI_MODE_DESC& getDXGIModeDesc() const { return mDXGIMode; }
+		const DXGI_MODE_DESC& getDXGIModeDesc(UINT32 idx) const { return mD3D11Modes[idx].mode; }
 
 	private:
 		friend class D3D11VideoOutputInfo;
 
-		Vector<RefreshRate> mD3D11RefreshRates; /**< DXGI stores refresh rates as rational numbers so we need a special storage for them. */
-		DXGI_MODE_DESC mDXGIMode;
+		Vector<DX11Data> mD3D11Modes; 
 	};
 
 	/**

+ 6 - 4
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -21,8 +21,6 @@ namespace BansheeEngine
 		, mIsExternal(false)
 		, mSizing(false)
 		, mClosed(false)
-		, mRefreshRateNumerator(0)
-		, mRefreshRateDenominator(0)
 		, mRenderTargetView(nullptr)
 		, mBackBuffer(nullptr)
 		, mSwapChain(nullptr)
@@ -398,12 +396,14 @@ namespace BansheeEngine
 		outputInfo.getDXGIOutput()->FindClosestMatchingMode(&modeDesc, &nearestMode, nullptr);
 
 		mIsFullScreen = true;
+		mWidth = width;
+		mHeight = height;
 
 		mSwapChain->ResizeTarget(&nearestMode);
 		mSwapChain->SetFullscreenState(true, outputInfo.getDXGIOutput()); 
 	}
 
-	void D3D11RenderWindow::setFullscreen(const VideoMode& mode)
+	void D3D11RenderWindow::setFullscreen(const VideoMode& mode, UINT32 refreshRateIdx)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
@@ -414,8 +414,10 @@ namespace BansheeEngine
 		const D3D11VideoOutputInfo& outputInfo = static_cast<const D3D11VideoOutputInfo&>(mode.getParentOutput());
 
 		mIsFullScreen = true;
+		mWidth = mode.getWidth();
+		mHeight = mode.getHeight();
 
-		mSwapChain->ResizeTarget(&videoMode.getDXGIModeDesc());
+		mSwapChain->ResizeTarget(&videoMode.getDXGIModeDesc(refreshRateIdx));
 		mSwapChain->SetFullscreenState(true, outputInfo.getDXGIOutput());
 	}
 

+ 24 - 22
CamelotD3D11RenderSystem/Source/CmD3D11VideoModeInfo.cpp

@@ -53,10 +53,10 @@ namespace BansheeEngine
 				if (d3d11videoMode->mWidth == displayMode.Width && d3d11videoMode->mHeight == displayMode.Height)
 				{
 					bool foundRefreshRate = false;
-					for (auto refreshRate : d3d11videoMode->mD3D11RefreshRates)
+					for (auto refreshRate : d3d11videoMode->mD3D11Modes)
 					{
-						if (refreshRate.numerator == displayMode.RefreshRate.Numerator &&
-							refreshRate.denominator == displayMode.RefreshRate.Denominator)
+						if (refreshRate.refreshRateNumerator == displayMode.RefreshRate.Numerator &&
+							refreshRate.refreshRateDenominator == displayMode.RefreshRate.Denominator)
 						{
 							foundRefreshRate = true;
 							break;
@@ -65,12 +65,12 @@ namespace BansheeEngine
 
 					if (!foundRefreshRate)
 					{
-						D3D11VideoMode::RefreshRate refreshRate;
-						refreshRate.numerator = displayMode.RefreshRate.Numerator;
-						refreshRate.denominator = displayMode.RefreshRate.Denominator;
+						D3D11VideoMode::DX11Data refreshRate;
+						refreshRate.refreshRateNumerator = displayMode.RefreshRate.Numerator;
+						refreshRate.refreshRateDenominator = displayMode.RefreshRate.Denominator;
 
-						d3d11videoMode->mD3D11RefreshRates.push_back(refreshRate);
-						d3d11videoMode->mRefreshRates.push_back(refreshRate.numerator / (float)refreshRate.denominator);
+						d3d11videoMode->mD3D11Modes.push_back(refreshRate);
+						d3d11videoMode->mRefreshRates.push_back(refreshRate.refreshRateNumerator / (float)refreshRate.refreshRateDenominator);
 					}
 
 					foundVideoMode = true;
@@ -80,14 +80,15 @@ namespace BansheeEngine
 
 			if (!foundVideoMode)
 			{
-				D3D11VideoMode* videoMode = cm_new<D3D11VideoMode>(displayMode.Width, displayMode.Height, this, displayMode);
+				D3D11VideoMode* videoMode = cm_new<D3D11VideoMode>(displayMode.Width, displayMode.Height, this);
 
-				D3D11VideoMode::RefreshRate refreshRate;
-				refreshRate.numerator = displayMode.RefreshRate.Numerator;
-				refreshRate.denominator = displayMode.RefreshRate.Denominator;
+				D3D11VideoMode::DX11Data d3d11data;
+				d3d11data.refreshRateNumerator = displayMode.RefreshRate.Numerator;
+				d3d11data.refreshRateDenominator = displayMode.RefreshRate.Denominator;
+				d3d11data.mode = displayMode;
 
-				videoMode->mD3D11RefreshRates.push_back(refreshRate);
-				videoMode->mRefreshRates.push_back(refreshRate.numerator / (float)refreshRate.denominator);
+				videoMode->mD3D11Modes.push_back(d3d11data);
+				videoMode->mRefreshRates.push_back(d3d11data.refreshRateNumerator / (float)d3d11data.refreshRateDenominator);
 
 				mVideoModes.push_back(videoMode);
 			}
@@ -121,15 +122,16 @@ namespace BansheeEngine
 
 		output->FindClosestMatchingMode(&currentMode, &nearestMode, nullptr);
 
-		D3D11VideoMode* desktopVideoMode = cm_new<D3D11VideoMode>(nearestMode.Width, nearestMode.Height, this, nearestMode);;
+		D3D11VideoMode* desktopVideoMode = cm_new<D3D11VideoMode>(nearestMode.Width, nearestMode.Height, this);;
 		
 		{
-			D3D11VideoMode::RefreshRate refreshRate;
-			refreshRate.numerator = nearestMode.RefreshRate.Numerator;
-			refreshRate.denominator = nearestMode.RefreshRate.Denominator;
+			D3D11VideoMode::DX11Data d3d11data;
+			d3d11data.refreshRateNumerator = nearestMode.RefreshRate.Numerator;
+			d3d11data.refreshRateDenominator = nearestMode.RefreshRate.Denominator;
+			d3d11data.mode = nearestMode;
 
-			desktopVideoMode->mD3D11RefreshRates.push_back(refreshRate);
-			desktopVideoMode->mRefreshRates.push_back(refreshRate.numerator / (float)refreshRate.denominator);
+			desktopVideoMode->mD3D11Modes.push_back(d3d11data);
+			desktopVideoMode->mRefreshRates.push_back(d3d11data.refreshRateNumerator / (float)d3d11data.refreshRateDenominator);
 		}
 
 		mDesktopVideoMode = desktopVideoMode;
@@ -140,7 +142,7 @@ namespace BansheeEngine
 		SAFE_RELEASE(mDXGIOutput);
 	}
 
-	D3D11VideoMode::D3D11VideoMode(UINT32 width, UINT32 height, VideoOutputInfo* outputInfo, DXGI_MODE_DESC dxgiMode)
-		:VideoMode(width, height, outputInfo), mDXGIMode(dxgiMode)
+	D3D11VideoMode::D3D11VideoMode(UINT32 width, UINT32 height, VideoOutputInfo* outputInfo)
+		:VideoMode(width, height, outputInfo)
 	{ }
 }

+ 83 - 120
CamelotD3D9Renderer/Include/CmD3D9Device.h

@@ -1,150 +1,113 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2011 Torus Knot Software Ltd
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __D3D9Device_H__
-#define __D3D9Device_H__
+#pragma once
 
 #include "CmD3D9Prerequisites.h"
 #include "CmRenderTarget.h"
 
-namespace BansheeEngine {
-
-	class D3D9RenderWindow;
-	class D3D9DeviceManager;
-
+namespace BansheeEngine 
+{
 	/** High level interface of Direct3D9 Device.
 	Provide useful methods for device handling.
 	*/
 	class CM_D3D9_EXPORT D3D9Device
 	{
+	protected:
+		struct RenderWindowResources
+		{
+			IDirect3DSwapChain9* swapChain;	// Swap chain interface.
+			UINT32 adapterOrdinalInGroupIndex; // Relative index of the render window in the group.
+			UINT32 presentParametersIndex; // Index of present parameter in the shared array of the device.
+			IDirect3DSurface9* backBuffer; // The back buffer of the render window.
+			IDirect3DSurface9* depthBuffer;	// The depth buffer of the render window.
+			D3DPRESENT_PARAMETERS presentParameters; // Present parameters of the render window.
+			bool acquired; // True if resources acquired.			
+		};
 
-	// Interface.
 	public:
-		void					attachRenderWindow		(const D3D9RenderWindow* renderWindow);
-		void					detachRenderWindow		(const D3D9RenderWindow* renderWindow);
+		D3D9Device(D3D9DeviceManager* deviceManager, UINT adapterNumber, HMONITOR hMonitor,
+			D3DDEVTYPE devType, DWORD behaviorFlags);
+		~D3D9Device();
+
+		void attachRenderWindow(const D3D9RenderWindow* renderWindow);
+		void detachRenderWindow(const D3D9RenderWindow* renderWindow);
 	
-		bool					acquire					();
+		bool acquire();
 		
-		void					release					();		
-		void					destroy					();		
+		void release();		
+		void destroy();		
 		
-		bool					isDeviceLost			();				
-		IDirect3DDevice9*		getD3D9Device			() const;
+		bool isDeviceLost();				
+		IDirect3DDevice9* getD3D9Device() const;
 					
-		UINT					getAdapterNumber		() const;
-		D3DDEVTYPE				getDeviceType			() const;
-		bool					isMultihead				() const;					
-		bool					isAutoDepthStencil		() const;
+		UINT getAdapterNumber() const;
+		D3DDEVTYPE getDeviceType() const;
+		bool isMultihead() const;					
+		bool isAutoDepthStencil() const;
 		
-		const D3DCAPS9&			getD3D9DeviceCaps		() const;
-		D3DFORMAT				getBackBufferFormat		() const;
-		D3DFORMAT				getDepthStencilFormat	() const;
+		const D3DCAPS9& getD3D9DeviceCaps() const;
+		D3DFORMAT getBackBufferFormat() const;
+		D3DFORMAT getDepthStencilFormat() const;
 
-		bool					validate				(D3D9RenderWindow* renderWindow);
-		void					invalidate				(const D3D9RenderWindow* renderWindow);
+		bool validate(D3D9RenderWindow* renderWindow);
+		void invalidate(const D3D9RenderWindow* renderWindow);
 
-		void					present					(const D3D9RenderWindow* renderWindow);
+		void present(const D3D9RenderWindow* renderWindow);
 		
-		IDirect3DSurface9*		getDepthBuffer			(const D3D9RenderWindow* renderWindow);
-		IDirect3DSurface9*		getBackBuffer			(const D3D9RenderWindow* renderWindow);
+		IDirect3DSurface9* getDepthBuffer(const D3D9RenderWindow* renderWindow);
+		IDirect3DSurface9* getBackBuffer(const D3D9RenderWindow* renderWindow);
 
-		UINT32					getLastPresentFrame		() const { return mLastPresentFrame; }
-
-		void					setAdapterOrdinalIndex  (const D3D9RenderWindow* renderWindow, UINT32 adapterOrdinalInGroupIndex);
-		void					copyContentsToMemory(const D3D9RenderWindow* window, const PixelData &dst, RenderTarget::FrameBuffer buffer);
-		void					clearDeviceStreams		();
+		void setAdapterOrdinalIndex(const D3D9RenderWindow* renderWindow, UINT32 adapterOrdinalInGroupIndex);
+		void copyContentsToMemory(const D3D9RenderWindow* window, const PixelData &dst, RenderTarget::FrameBuffer buffer);
+		void clearDeviceStreams();
 	
-	public:
-		D3D9Device	(D3D9DeviceManager* deviceManager,
-					 UINT adapterNumber, 
-					 HMONITOR hMonitor, 
-					 D3DDEVTYPE devType, 
-					 DWORD behaviorFlags);
-		~D3D9Device	();
+	protected:
+		friend class D3D9DeviceManager;
+		friend class D3D9RenderSystem;
 
-	protected:			
-		D3D9DeviceManager*				mpDeviceManager;			// The manager of this device instance.
-		IDirect3DDevice9*				mpDevice;					// Will hold the device interface.				
-		UINT							mAdapterNumber;				// The adapter that this device belongs to.	
-		HMONITOR						mMonitor;					// The monitor that this device belongs to.
-		D3DDEVTYPE						mDeviceType;				// Device type.	
-		static HWND						msSharedFocusWindow;		// The shared focus window in case of multiple full screen render windows.
-		HWND							mFocusWindow;				// The focus window this device attached to.			
-		DWORD							mBehaviorFlags;				// The behavior of this device.		
-		D3DPRESENT_PARAMETERS*			mPresentationParams;		// Presentation parameters which the device was created with. May be
-																	// an array of presentation parameters in case of multi-head device.				
-		UINT							mPresentationParamsCount;	// Number of presentation parameters elements.		
-		D3DCAPS9						mD3D9DeviceCaps;			// Device caps.	
-		bool							mD3D9DeviceCapsValid;		// True if device caps initialized.				
-		D3DDEVICE_CREATION_PARAMETERS	mCreationParams;			// Creation parameters.
-		UINT32							mLastPresentFrame;			// Last frame that this device present method called.
-		bool							mDeviceLost;				// True if device entered lost state.
-	
-		struct RenderWindowResources
-		{
-			IDirect3DSwapChain9* 	swapChain;						// Swap chain interface.
-			UINT32					adapterOrdinalInGroupIndex;		// Relative index of the render window in the group.
-			UINT32					presentParametersIndex;			// Index of present parameter in the shared array of the device.
-			IDirect3DSurface9*	 	backBuffer;						// The back buffer of the render window.
-			IDirect3DSurface9*	 	depthBuffer;					// The depth buffer of the render window.
-			D3DPRESENT_PARAMETERS	presentParameters;				// Present parameters of the render window.
-			bool					acquired;						// True if resources acquired.			
-		};		
 		typedef Map<const D3D9RenderWindow*, RenderWindowResources*> RenderWindowToResorucesMap;
 		typedef RenderWindowToResorucesMap::iterator				 RenderWindowToResorucesIterator;
 
-		RenderWindowToResorucesMap mMapRenderWindowToResoruces;		// Map between render window to resources.
-
+		RenderWindowToResorucesIterator getRenderWindowIterator(const D3D9RenderWindow* renderWindow);
 
-	protected:
-		RenderWindowToResorucesIterator getRenderWindowIterator (const D3D9RenderWindow* renderWindow);
+		bool acquire(const D3D9RenderWindow* renderWindow);
+		bool reset();
+		void updatePresentationParameters();
+		void updateRenderWindowsIndices();
 
-		bool					acquire							(const D3D9RenderWindow* renderWindow);
-		bool					reset							();
-		void					updatePresentationParameters	();
-		void					updateRenderWindowsIndices		();
-		
-		void					createD3D9Device				();
-		void					releaseD3D9Device				();
-		void					releaseRenderWindowResources	(RenderWindowResources* renderWindowResources);
-		void					acquireRenderWindowResources	(RenderWindowToResorucesIterator it);		
-		void					notifyDeviceLost				();
+		void createD3D9Device();
+		void releaseD3D9Device();
+		void releaseRenderWindowResources(RenderWindowResources* renderWindowResources);
+		void acquireRenderWindowResources(RenderWindowToResorucesIterator it);
+		void notifyDeviceLost();
 
-		void					validateFocusWindow				();
-		void					validateBackBufferSize			(const D3D9RenderWindow* renderWindow);
-		bool					validateDisplayMonitor			(D3D9RenderWindow* renderWindow);
-		bool					validateDeviceState				(const D3D9RenderWindow* renderWindow);
-		bool					isSwapChainWindow				(const D3D9RenderWindow* renderWindow);
-		const D3D9RenderWindow*	getPrimaryWindow				();
-		void					setSharedWindowHandle			(HWND hSharedHWND);
+		void validateFocusWindow();
+		void validateBackBufferSize(const D3D9RenderWindow* renderWindow);
+		bool validateDisplayMonitor(D3D9RenderWindow* renderWindow);
+		bool validateDeviceState(const D3D9RenderWindow* renderWindow);
+		bool isSwapChainWindow(const D3D9RenderWindow* renderWindow);
+		const D3D9RenderWindow*	getPrimaryWindow();
+		void setSharedWindowHandle(HWND hSharedHWND);
 
-	private:
-		friend class D3D9DeviceManager;
-		friend class D3D9RenderSystem;
+	protected:			
+		D3D9DeviceManager* mpDeviceManager;	/**< The manager of this device instance. */
+		IDirect3DDevice9* mpDevice;	/**< Will hold the device interface. */
+		UINT mAdapterNumber; /**< The adapter that this device belongs to. */
+		HMONITOR mMonitor; /**< The monitor that this device belongs to. */
+		D3DDEVTYPE mDeviceType; /**< Device type. */
+		static HWND	msSharedFocusWindow; /**< The shared focus window in case of multiple full screen render windows. */
+		HWND mFocusWindow; /**< The focus window this device attached to. */	
+		DWORD mBehaviorFlags; /**< The behavior of this device.	*/
+		
+		/** Presentation parameters which the device was created with. May be
+		 *  an array of presentation parameters in case of multi-head device.
+		 */
+		D3DPRESENT_PARAMETERS* mPresentationParams;
+		UINT mPresentationParamsCount; /**< Number of presentation parameters elements.	 */
+		D3DCAPS9 mD3D9DeviceCaps; /**< Device caps. */
+		bool mD3D9DeviceCapsValid; /**< True if device caps initialized. */
+		D3DDEVICE_CREATION_PARAMETERS mCreationParams; /**< Creation parameters. */
+		bool mDeviceLost; /**< True if device entered lost state. */
+	
+		RenderWindowToResorucesMap mMapRenderWindowToResoruces;		// Map between render window to resources.
+	
 	};
-}
-#endif
+}

+ 67 - 62
CamelotD3D9Renderer/Include/CmD3D9DeviceManager.h

@@ -1,76 +1,81 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
+#pragma once
 
-Copyright (c) 2000-2011 Torus Knot Software Ltd
+#include "CmD3D9Prerequisites.h"
 
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
+namespace BansheeEngine 
+{
+	/**
+	 * @brief	Handles creation of DirectX 9 devices. Also links the devices
+	 *			with created render targets.
+	 */
+	class CM_D3D9_EXPORT D3D9DeviceManager
+	{	
+	public:
+		D3D9DeviceManager();
+		~D3D9DeviceManager();
 
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
+		/**
+		 * @brief	Changes the active device to the provided device. Must be not null.
+		 */
+		void setActiveDevice(D3D9Device* device);
 
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __D3D9DeviceManager_H__
-#define __D3D9DeviceManager_H__
+		/**
+		 * @brief	Retrieves the currently active device.
+		 */
+		D3D9Device*	getActiveDevice();
 
-#include "CmD3D9Prerequisites.h"
+		/**
+		 * @brief	Sets the device used by the currently active render target.
+		 */
+		void setActiveRenderTargetDevice(D3D9Device* device);
 
-namespace BansheeEngine {
+		/**
+		 * @brief	Retrieves the device used by the currently active render target.
+		 */
+		D3D9Device*	getActiveRenderTargetDevice();		
 
-	class D3D9Device;
-	class D3D9RenderWindow;
+		/**
+		 * @brief	Returns the total number of devices available.
+		 */
+		UINT getDeviceCount();
 
-	/** Device manager interface.
-	*/
-	class CM_D3D9_EXPORT D3D9DeviceManager
-	{	
+		/**
+		 * @brief	Returns the device under the specified index.
+		 */
+		D3D9Device*	getDevice(UINT index);
 
-	// Interface.
-	public:		
-		void				setActiveDevice					(D3D9Device* device);
-		D3D9Device*			getActiveDevice					();
-		void				setActiveRenderTargetDevice		(D3D9Device* device);
-		D3D9Device*			getActiveRenderTargetDevice		();		
-		UINT				getDeviceCount					();
-		D3D9Device*			getDevice						(UINT index);			
-		void				linkRenderWindow				(D3D9RenderWindow* renderWindow);
-		void				destroyInactiveRenderDevices	();
-		void				notifyOnDeviceDestroy			(D3D9Device* device);
-		D3D9Device*			getDeviceFromD3D9Device			(IDirect3DDevice9* d3d9Device);
-		
-	public:
-		D3D9DeviceManager	();
-		~D3D9DeviceManager	();
+		/**
+		 * @brief	Links the provided render window with a device. The window will be 
+		 *			assigned an existing device if a match one can be found, otherwise
+		 *			a new device will be created.
+		 */
+		void linkRenderWindow(D3D9RenderWindow* renderWindow);
 
-	protected:		
-		typedef Vector<D3D9Device*>		 DeviceList;
-		typedef DeviceList::iterator			 DeviceIterator;
-		typedef DeviceList::const_iterator		 ConstDeviceIterator;
-		typedef Vector<D3D9RenderWindow*>  D3D9RenderWindowList;
+		/**
+		 * @brief	Called by the devices when they're are being destroyed.
+		 */
+		void notifyOnDeviceDestroy(D3D9Device* device);
+
+		/**
+		 * @brief	Retrieves engine device from DX9 device.
+		 */
+		D3D9Device*	getDeviceFromD3D9Device(IDirect3DDevice9* d3d9Device);
 
 	protected:
-		D3D9Device*			selectDevice		(D3D9RenderWindow* renderWindow, D3D9RenderWindowList& renderWindowsGroup);
-		D3D9Driver*			findDriver			(D3D9RenderWindow* renderWindow);
+		/**
+		 * @brief	Attempts to find a matching device for the provided render window. If one cannot be found a
+		 *			new device is created. Found/created device is returned, as well as a list of all render windows
+		 *			using that device.
+		 */
+		D3D9Device*	selectDevice(D3D9RenderWindow* renderWindow, Vector<D3D9RenderWindow*>& renderWindowsGroup);
+
+		/**
+		 * @brief	Finds the driver the render window belongs to.
+		 */
+		D3D9Driver*	findDriver(D3D9RenderWindow* renderWindow);
 
-		
-		DeviceList								mRenderDevices;		
-		D3D9Device*								mActiveDevice;
-		D3D9Device*								mActiveRenderWindowDevice;		
+		Vector<D3D9Device*> mRenderDevices;
+		D3D9Device*	mActiveDevice;
+		D3D9Device*	mActiveRenderWindowDevice;		
 	};
-}
-#endif
+}

+ 20 - 14
CamelotD3D9Renderer/Include/CmD3D9RenderWindow.h

@@ -12,9 +12,19 @@ namespace BansheeEngine
 		~D3D9RenderWindow();
 		
 		/**
-		 * @copydoc RenderWindow::setFullscreen
-		 */
-		void setFullscreen(bool fullScreen, UINT32 width, UINT32 height);
+		* @copydoc RenderWindow::setFullscreen
+		*/
+		void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0);
+
+		/**
+		* @copydoc RenderWindow::setFullscreen
+		*/
+		void setFullscreen(const VideoMode& mode, UINT32 refreshRateIdx);
+
+		/**
+		* @copydoc RenderWindow::setWindowed
+		*/
+		void setWindowed();
 
 		/**
 		 * @copydoc RenderWindow::setHidden
@@ -84,28 +94,23 @@ namespace BansheeEngine
 		/**
 		 * @copydoc RenderWindow::_windowMovedOrResized
 		 */
-		void				_windowMovedOrResized	();
+		void _windowMovedOrResized();
 
-		HWND 				_getWindowHandle		() const { return mHWnd; }				
-		IDirect3DDevice9*	_getD3D9Device		() const;
-		D3D9Device*			_getDevice			() const;
-		void				_setDevice			(D3D9Device* device);
+		HWND _getWindowHandle() const { return mHWnd; }				
+		IDirect3DDevice9* _getD3D9Device() const;
+		D3D9Device* _getDevice() const;
+		void _setDevice(D3D9Device* device);
 
 		/**
 		 * @brief	Build the presentation parameters used with this window.
 		 */
-		void				_buildPresentParameters	(D3DPRESENT_PARAMETERS* presentParams) const;
+		void _buildPresentParameters(D3DPRESENT_PARAMETERS* presentParams) const;
 
 		/**
 		 * @brief	Accessor for render surface.
 		 */
 		IDirect3DSurface9* _getRenderSurface() const;
 
-		/**
-		 * @brief	Are we in the middle of switching between fullscreen and windowed.
-		 */
-		bool _getSwitchingFullscreen() const;
-
 		/**
 		 * @brief	Indicate that fullscreen / windowed switching has finished.
 		 */
@@ -156,6 +161,7 @@ namespace BansheeEngine
 		unsigned int				mVSyncInterval;		
 		DWORD						mStyle;					// Window style currently used for this window.
 		bool						mIsDepthBuffered;
+		bool						mIsChild;
 		// Desired width / height after resizing
 		unsigned int mDesiredWidth;
 		unsigned int mDesiredHeight;

+ 4 - 37
CamelotD3D9Renderer/Include/CmD3D9Resource.h

@@ -1,32 +1,4 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2011 Torus Knot Software Ltd
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __D3D9Resource_H__
-#define __D3D9Resource_H__
+#pragma once
 
 #include "CmD3D9Prerequisites.h"
 
@@ -38,9 +10,10 @@ namespace BansheeEngine {
 	*/
 	class CM_D3D9_EXPORT D3D9Resource
 	{
-
 	// Interface.
 	public:
+		D3D9Resource();
+		virtual ~D3D9Resource();
 
 		// Called immediately after the Direct3D device has been created.
 		virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device) {}
@@ -64,13 +37,7 @@ namespace BansheeEngine {
 		// Relevant for multi thread application.
 		static void unlockDeviceAccess();
 
-
-	public:
-		D3D9Resource			();
-		virtual ~D3D9Resource	();
-
 	protected:
 		CM_STATIC_MUTEX(msDeviceAccessMutex)		
 	};
-}
-#endif
+}

+ 20 - 61
CamelotD3D9Renderer/Include/CmD3D9ResourceManager.h

@@ -1,37 +1,9 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2011 Torus Knot Software Ltd
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __D3D9ResourceManager_H__
-#define __D3D9ResourceManager_H__
+#pragma once
 
 #include "CmD3D9Prerequisites.h"
 
-namespace BansheeEngine {
-
+namespace BansheeEngine 
+{
 	enum D3D9ResourceCreationPolicy
 	{
 		// Creates the rendering resource on the current active device that needs it.
@@ -52,58 +24,45 @@ namespace BansheeEngine {
 	
 	class CM_D3D9_EXPORT D3D9ResourceManager
 	{
-
-	// Interface.
 	public:
+		D3D9ResourceManager();
+		~D3D9ResourceManager();
 
 		// Called immediately after the Direct3D device has been created.
-		void notifyOnDeviceCreate	(IDirect3DDevice9* d3d9Device);
+		void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
 
 		// Called before the Direct3D device is going to be destroyed.
-		void notifyOnDeviceDestroy	(IDirect3DDevice9* d3d9Device);
+		void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
 
 		// Called immediately after the Direct3D device has entered a lost state.
-		void notifyOnDeviceLost		(IDirect3DDevice9* d3d9Device);
+		void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device);
 
 		// Called immediately after the Direct3D device has been reset.
-		void notifyOnDeviceReset	(IDirect3DDevice9* d3d9Device);
+		void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device);
 
 		// Called when device state is changing. Access to any device should be locked.
 		// Relevant for multi thread application.
-		void lockDeviceAccess		();
+		void lockDeviceAccess();
 
 		// Called when device state change completed. Access to any device is allowed.
 		// Relevant for multi thread application.
-		void unlockDeviceAccess		();
+		void unlockDeviceAccess();
 		
 		// Called when new resource created.
-		void _notifyResourceCreated		(D3D9Resource* pResource);
+		void _notifyResourceCreated(D3D9Resource* pResource);
 
 		// Called when resource is about to be destroyed.
-		void _notifyResourceDestroyed	(D3D9Resource* pResource);
+		void _notifyResourceDestroyed(D3D9Resource* pResource);
 
-		D3D9ResourceManager			();
-		~D3D9ResourceManager		();		
-
-		void						setCreationPolicy	(D3D9ResourceCreationPolicy creationPolicy);
-		D3D9ResourceCreationPolicy	getCreationPolicy	() const;
+		void setCreationPolicy(D3D9ResourceCreationPolicy creationPolicy);
+		D3D9ResourceCreationPolicy getCreationPolicy() const;
 		
-	// Friends.
 	protected:
 		friend class D3D9Resource;
-	
-	// Types.
-	protected:
-		typedef Vector<D3D9Resource*>		ResourceContainer;
-		typedef ResourceContainer::iterator		ResourceContainerIterator;
-
-	// Attributes.
-	protected:		
+		
 		CM_MUTEX(mResourcesMutex)
-		ResourceContainer			mResources;
-		D3D9ResourceCreationPolicy	mResourceCreationPolicy;
-		long						mDeviceAccessLockCount;		
+		Vector<D3D9Resource*> mResources;
+		D3D9ResourceCreationPolicy mResourceCreationPolicy;
+		long mDeviceAccessLockCount;		
 	};
-}
-
-#endif
+}

+ 0 - 3
CamelotD3D9Renderer/Include/CmD3D9Texture.h

@@ -208,9 +208,6 @@ namespace BansheeEngine {
 		/// allocates new texture resources structure attached to the given device.
 		TextureResources* allocateTextureResources(IDirect3DDevice9* d3d9Device);
 
-		/// creates this texture resources according to the current settings.
-		void createTextureResources(IDirect3DDevice9* d3d9Device);
-
 		/// frees the given texture resources.
 		void freeTextureResources(IDirect3DDevice9* d3d9Device, TextureResources* textureResources);
 

+ 52 - 139
CamelotD3D9Renderer/Source/CmD3D9Device.cpp

@@ -1,30 +1,3 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2011 Torus Knot Software Ltd
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
 #include "CmD3D9Device.h"
 #include "CmD3D9DeviceManager.h"
 #include "CmD3D9Driver.h"
@@ -36,65 +9,58 @@ THE SOFTWARE.
 
 namespace BansheeEngine
 {
-	HWND D3D9Device::msSharedFocusWindow = NULL;
-
-	//---------------------------------------------------------------------
-	D3D9Device::D3D9Device(D3D9DeviceManager* deviceManager,
-		UINT adapterNumber, 
-		HMONITOR hMonitor, 
-		D3DDEVTYPE devType, 
-		DWORD behaviorFlags)
+	HWND D3D9Device::msSharedFocusWindow = 0;
+
+	D3D9Device::D3D9Device(D3D9DeviceManager* deviceManager, UINT adapterNumber, HMONITOR hMonitor, 
+		D3DDEVTYPE devType, DWORD behaviorFlags)
 	{
-		mpDeviceManager				= deviceManager;
-		mpDevice					= NULL;		
-		mAdapterNumber				= adapterNumber;
-		mMonitor					= hMonitor;
-		mDeviceType					= devType;
-		mFocusWindow				= NULL;
-		mBehaviorFlags				= behaviorFlags;	
-		mD3D9DeviceCapsValid		= false;
-		mDeviceLost					= false;
-		mPresentationParamsCount 	= 0;
-		mPresentationParams		 	= NULL;
+		mpDeviceManager	= deviceManager;
+		mpDevice = nullptr;		
+		mAdapterNumber = adapterNumber;
+		mMonitor = hMonitor;
+		mDeviceType = devType;
+		mFocusWindow = 0;
+		mBehaviorFlags = behaviorFlags;	
+		mD3D9DeviceCapsValid = false;
+		mDeviceLost = false;
+		mPresentationParamsCount = 0;
+		mPresentationParams	= nullptr;
 		memset(&mD3D9DeviceCaps, 0, sizeof(mD3D9DeviceCaps));
 		memset(&mCreationParams, 0, sizeof(mCreationParams));		
 	}
 
-	//---------------------------------------------------------------------
 	D3D9Device::~D3D9Device()
 	{
 
 	}
 
-	//---------------------------------------------------------------------
 	D3D9Device::RenderWindowToResorucesIterator D3D9Device::getRenderWindowIterator(const D3D9RenderWindow* renderWindow)
 	{
 		RenderWindowToResorucesIterator it = mMapRenderWindowToResoruces.find(renderWindow);
 
 		if (it == mMapRenderWindowToResoruces.end())
-			CM_EXCEPT(RenderingAPIException, "Render window was not attached to this device !!");
+			CM_EXCEPT(RenderingAPIException, "Render window was not attached to this device.");
 
 		return it;
 	}
 
-	//---------------------------------------------------------------------
 	void D3D9Device::attachRenderWindow(const D3D9RenderWindow* renderWindow)
 	{
 		RenderWindowToResorucesIterator it = mMapRenderWindowToResoruces.find(renderWindow);
 
 		if (it == mMapRenderWindowToResoruces.end())
 		{
-			RenderWindowResources* renderWindowResources = cm_new<RenderWindowResources, PoolAlloc>();
+			RenderWindowResources* renderWindowResources = cm_new<RenderWindowResources>();
 
 			memset(renderWindowResources, 0, sizeof(RenderWindowResources));						
 			renderWindowResources->adapterOrdinalInGroupIndex = 0;					
 			renderWindowResources->acquired = false;
 			mMapRenderWindowToResoruces[renderWindow] = renderWindowResources;			
 		}
+
 		updateRenderWindowsIndices();
 	}
 
-	//---------------------------------------------------------------------
 	void D3D9Device::detachRenderWindow(const D3D9RenderWindow* renderWindow)
 	{
 		RenderWindowToResorucesIterator it = mMapRenderWindowToResoruces.find(renderWindow);
@@ -105,26 +71,26 @@ namespace BansheeEngine
 			// resources must be acquired again.
 			if (mFocusWindow == renderWindow->_getWindowHandle())
 			{
-				mFocusWindow = NULL;				
+				mFocusWindow = 0;				
 			}
 
 			// Case this is the shared focus window.
 			if (renderWindow->_getWindowHandle() == msSharedFocusWindow)			
-				setSharedWindowHandle(NULL);		
+				setSharedWindowHandle(0);		
 			
 			RenderWindowResources* renderWindowResources = it->second;
 
 			releaseRenderWindowResources(renderWindowResources);
 
 			if(renderWindowResources != nullptr)
-				cm_delete<PoolAlloc>(renderWindowResources);
+				cm_delete(renderWindowResources);
 			
 			mMapRenderWindowToResoruces.erase(it);		
 		}
+
 		updateRenderWindowsIndices();
 	}
 
-	//---------------------------------------------------------------------
 	bool D3D9Device::acquire()
 	{	
 		updatePresentationParameters();
@@ -132,17 +98,15 @@ namespace BansheeEngine
 		bool resetDevice = false;
 			
 		// Create device if need to.
-		if (mpDevice == NULL)
+		if (mpDevice == nullptr)
 		{			
 			createD3D9Device();
 		}
-
-		// Case device already exists.
 		else
 		{
 			RenderWindowToResorucesIterator itPrimary = getRenderWindowIterator(getPrimaryWindow());
 
-			if (itPrimary->second->swapChain != NULL)
+			if (itPrimary->second->swapChain != nullptr)
 			{
 				D3DPRESENT_PARAMETERS currentPresentParams;
 				HRESULT hr;
@@ -176,9 +140,7 @@ namespace BansheeEngine
 		{
 			reset();
 		}
-
-		// No need to reset -> just acquire resources.
-		else
+		else // No need to reset -> just acquire resources.
 		{
 			// Update resources of each window.
 			RenderWindowToResorucesIterator it = mMapRenderWindowToResoruces.begin();
@@ -193,16 +155,12 @@ namespace BansheeEngine
 		return true;
 	}
 
-	//---------------------------------------------------------------------
 	void D3D9Device::release()
 	{
-		if (mpDevice != NULL)
+		if (mpDevice != nullptr)
 		{
 			D3D9RenderSystem* renderSystem = static_cast<D3D9RenderSystem*>(BansheeEngine::RenderSystem::instancePtr());
 
-			//// Clean up depth stencil surfaces
-			//renderSystem->_cleanupDepthStencils(mpDevice);	
-
 			RenderWindowToResorucesIterator it = mMapRenderWindowToResoruces.begin();
 
 			while (it != mMapRenderWindowToResoruces.end())
@@ -217,7 +175,6 @@ namespace BansheeEngine
 		}				
 	}
 
-	//---------------------------------------------------------------------
 	bool D3D9Device::acquire(const D3D9RenderWindow* renderWindow)
 	{
 		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);
@@ -227,7 +184,6 @@ namespace BansheeEngine
 		return true;
 	}
 
-	//---------------------------------------------------------------------	
 	void D3D9Device::notifyDeviceLost()
 	{
 		// Case this device is already in lost state.
@@ -238,11 +194,9 @@ namespace BansheeEngine
 		mDeviceLost = true;	
 
 		D3D9RenderSystem* renderSystem = static_cast<D3D9RenderSystem*>(BansheeEngine::RenderSystem::instancePtr());
-
 		renderSystem->notifyOnDeviceLost(this);
 	}	
 
-	//---------------------------------------------------------------------
 	IDirect3DSurface9* D3D9Device::getDepthBuffer(const D3D9RenderWindow* renderWindow)
 	{
 		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);		
@@ -250,14 +204,13 @@ namespace BansheeEngine
 		return it->second->depthBuffer;
 	}
 
-	//---------------------------------------------------------------------
 	IDirect3DSurface9* D3D9Device::getBackBuffer(const D3D9RenderWindow* renderWindow)
 	{
 		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);
 	
 		return it->second->backBuffer;		
 	}
-	//---------------------------------------------------------------------
+
 	void D3D9Device::setAdapterOrdinalIndex(const D3D9RenderWindow* renderWindow, UINT32 adapterOrdinalInGroupIndex)
 	{
 		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);
@@ -267,7 +220,6 @@ namespace BansheeEngine
 		updateRenderWindowsIndices();
 	}
 	
-	//---------------------------------------------------------------------
 	void D3D9Device::destroy()
 	{	
 		// Lock access to rendering device.
@@ -280,21 +232,21 @@ namespace BansheeEngine
 		if (it != mMapRenderWindowToResoruces.end())
 		{	
 			if (it->first->_getWindowHandle() == msSharedFocusWindow)
-				setSharedWindowHandle(NULL);
+				setSharedWindowHandle(0);
 
 			if(it->second != nullptr)
-				cm_delete<PoolAlloc>(it->second);
+				cm_delete(it->second);
 
 			++it;
 		}
 		mMapRenderWindowToResoruces.clear();
 		
 		// Reset dynamic attributes.		
-		mFocusWindow			= NULL;		
-		mD3D9DeviceCapsValid	= false;
+		mFocusWindow = 0;		
+		mD3D9DeviceCapsValid = false;
 
 		if(mPresentationParams != nullptr)
-			cm_deleteN<PoolAlloc>(mPresentationParams, mPresentationParamsCount);
+			cm_deleteN(mPresentationParams, mPresentationParamsCount);
 
 		mPresentationParamsCount = 0;
 
@@ -304,8 +256,7 @@ namespace BansheeEngine
 		// UnLock access to rendering device.
 		D3D9RenderSystem::getResourceManager()->unlockDeviceAccess();
 	}	
-	
-	//---------------------------------------------------------------------
+
 	bool D3D9Device::isDeviceLost()
 	{		
 		HRESULT hr;
@@ -321,7 +272,6 @@ namespace BansheeEngine
 		return false;
 	}
 
-	//---------------------------------------------------------------------
 	bool D3D9Device::reset()
 	{
 		HRESULT hr;
@@ -359,7 +309,6 @@ namespace BansheeEngine
 
 		clearDeviceStreams();
 
-
 		// Reset the device using the presentation parameters.
 		hr = mpDevice->Reset(mPresentationParams);
 	
@@ -404,7 +353,6 @@ namespace BansheeEngine
 		return true;
 	}
 
-	//---------------------------------------------------------------------
 	bool D3D9Device::isAutoDepthStencil() const
 	{
 		const D3DPRESENT_PARAMETERS& primaryPresentationParams = mPresentationParams[0];
@@ -427,7 +375,6 @@ namespace BansheeEngine
 		return true;
 	}
 
-	//---------------------------------------------------------------------
 	const D3DCAPS9& D3D9Device::getD3D9DeviceCaps() const
 	{
 		if (mD3D9DeviceCapsValid == false)
@@ -438,7 +385,6 @@ namespace BansheeEngine
 		return mD3D9DeviceCaps;
 	}
 
-	//---------------------------------------------------------------------
 	D3DFORMAT D3D9Device::getBackBufferFormat() const
 	{		
 		if (mPresentationParams == NULL || mPresentationParamsCount == 0)
@@ -449,7 +395,6 @@ namespace BansheeEngine
 		return mPresentationParams[0].BackBufferFormat;
 	}
 
-	//---------------------------------------------------------------------
 	D3DFORMAT D3D9Device::getDepthStencilFormat() const
 	{		
 		if (mPresentationParams == NULL || mPresentationParamsCount == 0)
@@ -460,24 +405,22 @@ namespace BansheeEngine
 		return mPresentationParams[0].AutoDepthStencilFormat;
 	}
 
-	//---------------------------------------------------------------------
 	IDirect3DDevice9* D3D9Device::getD3D9Device() const
 	{
 		return mpDevice;
 	}
 
-	//---------------------------------------------------------------------
 	void D3D9Device::updatePresentationParameters()
 	{		
 		// Clear old presentation parameters.
 		if(mPresentationParams != nullptr)
-			cm_deleteN<PoolAlloc>(mPresentationParams, mPresentationParamsCount);
+			cm_deleteN(mPresentationParams, mPresentationParamsCount);
 
 		mPresentationParamsCount = 0;		
 
 		if (mMapRenderWindowToResoruces.size() > 0)
 		{
-			mPresentationParams = cm_newN<D3DPRESENT_PARAMETERS, PoolAlloc>((UINT32)mMapRenderWindowToResoruces.size());
+			mPresentationParams = cm_newN<D3DPRESENT_PARAMETERS>((UINT32)mMapRenderWindowToResoruces.size());
 
 			RenderWindowToResorucesIterator it = mMapRenderWindowToResoruces.begin();
 
@@ -518,19 +461,16 @@ namespace BansheeEngine
 		}
 	}	
 
-	//---------------------------------------------------------------------
 	UINT D3D9Device::getAdapterNumber() const
 	{
 		return mAdapterNumber;
 	}
 
-	//---------------------------------------------------------------------
 	D3DDEVTYPE D3D9Device::getDeviceType() const
 	{
 		return mDeviceType;
 	}
 
-	//---------------------------------------------------------------------
 	bool D3D9Device::isMultihead() const
 	{
 		RenderWindowToResorucesMap::const_iterator it = mMapRenderWindowToResoruces.begin();
@@ -539,8 +479,7 @@ namespace BansheeEngine
 		{
 			RenderWindowResources* renderWindowResources = it->second;
 			
-			if (renderWindowResources->adapterOrdinalInGroupIndex > 0 &&
-				it->first->isFullScreen())
+			if (renderWindowResources->adapterOrdinalInGroupIndex > 0 && it->first->isFullScreen())
 			{
 				return true;
 			}
@@ -551,7 +490,6 @@ namespace BansheeEngine
 		return false;
 	}
 
-	//---------------------------------------------------------------------
 	void D3D9Device::clearDeviceStreams()
 	{
 		D3D9RenderSystem* renderSystem = static_cast<D3D9RenderSystem*>(BansheeEngine::RenderSystem::instancePtr());
@@ -559,10 +497,10 @@ namespace BansheeEngine
 		// Set all texture units to nothing to release texture surfaces
 		for (DWORD stage = 0; stage < mD3D9DeviceCaps.MaxSimultaneousTextures; ++stage)
 		{
-			DWORD   dwCurValue = D3DTOP_FORCE_DWORD;
+			DWORD dwCurValue = D3DTOP_FORCE_DWORD;
 			HRESULT hr;
 
-			hr = mpDevice->SetTexture(stage, NULL);
+			hr = mpDevice->SetTexture(stage, nullptr);
 			if( hr != S_OK )
 			{
 				String str = "Unable to disable texture '" + toString((unsigned int)stage) + "' in D3D9";
@@ -590,11 +528,10 @@ namespace BansheeEngine
 		// Unbind any vertex streams to avoid memory leaks				
 		for (unsigned int i = 0; i < mD3D9DeviceCaps.MaxStreams; ++i)
 		{
-			mpDevice->SetStreamSource(i, NULL, 0, 0);
+			mpDevice->SetStreamSource(i, nullptr, 0, 0);
 		}
 	}
 
-	//---------------------------------------------------------------------
 	void D3D9Device::createD3D9Device()
 	{		
 		// Update focus window.
@@ -607,8 +544,7 @@ namespace BansheeEngine
 			mFocusWindow = primaryRenderWindow->_getWindowHandle();		
 
 		IDirect3D9* pD3D9 = D3D9RenderSystem::getDirect3D9();
-		HRESULT     hr;
-
+		HRESULT hr;
 
 		if (isMultihead())
 		{
@@ -633,7 +569,7 @@ namespace BansheeEngine
 		}
 
 		// Case hardware vertex processing failed.
-		if( FAILED( hr ) )
+		if (FAILED(hr))
 		{
 			// Try to create the device with mixed vertex processing.
 			mBehaviorFlags &= ~D3DCREATE_HARDWARE_VERTEXPROCESSING;
@@ -643,7 +579,7 @@ namespace BansheeEngine
 				mBehaviorFlags, mPresentationParams, &mpDevice);
 		}
 
-		if( FAILED( hr ) )
+		if (FAILED(hr))
 		{
 			// try to create the device with software vertex processing.
 			mBehaviorFlags &= ~D3DCREATE_MIXED_VERTEXPROCESSING;
@@ -652,14 +588,14 @@ namespace BansheeEngine
 				mBehaviorFlags, mPresentationParams, &mpDevice);
 		}
 
-		if ( FAILED( hr ) )
+		if (FAILED(hr))
 		{
 			// try reference device
 			mDeviceType = D3DDEVTYPE_REF;
 			hr = pD3D9->CreateDevice(mAdapterNumber, mDeviceType, mFocusWindow,
 				mBehaviorFlags, mPresentationParams, &mpDevice);
 
-			if ( FAILED( hr ) )
+			if (FAILED(hr))
 			{
 				CM_EXCEPT(RenderingAPIException, "Cannot create device!");
 			}
@@ -667,14 +603,14 @@ namespace BansheeEngine
 
 		// Get current device caps.
 		hr = mpDevice->GetDeviceCaps(&mD3D9DeviceCaps);
-		if( FAILED( hr ) )
+		if (FAILED(hr))
 		{
 			CM_EXCEPT(RenderingAPIException, "Cannot get device caps!");
 		}
 
 		// Get current creation parameters caps.
 		hr = mpDevice->GetCreationParameters(&mCreationParams);
-		if ( FAILED(hr) )
+		if (FAILED(hr) )
 		{
 			CM_EXCEPT(RenderingAPIException, "Error Get Creation Parameters");
 		}
@@ -697,10 +633,9 @@ namespace BansheeEngine
 		D3D9RenderSystem::getResourceManager()->unlockDeviceAccess();
 	}
 
-	//---------------------------------------------------------------------
 	void D3D9Device::releaseD3D9Device()
 	{
-		if (mpDevice != NULL)
+		if (mpDevice != nullptr)
 		{
 			// Lock access to rendering device.
 			D3D9RenderSystem::getResourceManager()->lockDeviceAccess();
@@ -722,7 +657,6 @@ namespace BansheeEngine
 		}
 	}
 
-	//---------------------------------------------------------------------
 	void D3D9Device::releaseRenderWindowResources(RenderWindowResources* renderWindowResources)
 	{
 		SAFE_RELEASE(renderWindowResources->backBuffer);
@@ -731,7 +665,6 @@ namespace BansheeEngine
 		renderWindowResources->acquired = false;
 	}
 
-	//---------------------------------------------------------------------
 	void D3D9Device::invalidate(const D3D9RenderWindow* renderWindow)
 	{
 		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);
@@ -739,11 +672,10 @@ namespace BansheeEngine
 		it->second->acquired = false;		
 	}
 
-	//---------------------------------------------------------------------
 	bool D3D9Device::validate(D3D9RenderWindow* renderWindow)
 	{
 		// Validate that the render window should run on this device.
-		if (false == validateDisplayMonitor(renderWindow))
+		if (!validateDisplayMonitor(renderWindow))
 			return false;
 		
 		// Validate that this device created on the correct target focus window handle		
@@ -753,13 +685,12 @@ namespace BansheeEngine
 		validateBackBufferSize(renderWindow);
 
 		// Validate that this device is in valid rendering state.
-		if (false == validateDeviceState(renderWindow))
+		if (!validateDeviceState(renderWindow))
 			return false;
 
 		return true;
 	}
 
-	//---------------------------------------------------------------------
 	void D3D9Device::validateFocusWindow()
 	{
 		// Focus window changed -> device should be re-acquired.
@@ -777,7 +708,6 @@ namespace BansheeEngine
 		}
 	}
 
-	//---------------------------------------------------------------------
 	bool D3D9Device::validateDeviceState(const D3D9RenderWindow* renderWindow)
 	{
 		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);		
@@ -839,8 +769,6 @@ namespace BansheeEngine
 		return true;
 	}
 		
-
-	//---------------------------------------------------------------------
 	void D3D9Device::validateBackBufferSize(const D3D9RenderWindow* renderWindow)
 	{
 		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);
@@ -861,7 +789,6 @@ namespace BansheeEngine
 		}				
 	}
 
-	//---------------------------------------------------------------------
 	bool D3D9Device::validateDisplayMonitor(D3D9RenderWindow* renderWindow)
 	{
 		// Ignore full screen since it doesn't really move and it is possible 
@@ -897,13 +824,11 @@ namespace BansheeEngine
 		return true;
 	}
 
-	//---------------------------------------------------------------------
 	void D3D9Device::present(const D3D9RenderWindow* renderWindow)
 	{		
 		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);
 		RenderWindowResources*	renderWindowResources = it->second;				
 
-
 		// Skip present while current device state is invalid.
 		if (mDeviceLost || 
 			renderWindowResources->acquired == false || 
@@ -928,7 +853,7 @@ namespace BansheeEngine
 		}
 
 
-		if( D3DERR_DEVICELOST == hr)
+		if(D3DERR_DEVICELOST == hr)
 		{
 			releaseRenderWindowResources(renderWindowResources);
 			notifyDeviceLost();
@@ -937,15 +862,8 @@ namespace BansheeEngine
 		{
 			CM_EXCEPT(RenderingAPIException, "Error Presenting surfaces");
 		}
-		else
-		{
-			// TODO PORT - What is this used for? In any case I don't have Root so just set it to 0
-			//mLastPresentFrame = Root::getSingleton().getNextFrameNumber();
-			mLastPresentFrame = 0;
-		}
 	}
 
-	//---------------------------------------------------------------------
 	void D3D9Device::acquireRenderWindowResources(RenderWindowToResorucesIterator it)
 	{
 		RenderWindowResources*	renderWindowResources = it->second;
@@ -1034,7 +952,7 @@ namespace BansheeEngine
 
 		renderWindowResources->acquired = true; 
 	}
-	//---------------------------------------------------------------------
+
 	bool D3D9Device::isSwapChainWindow(const D3D9RenderWindow* renderWindow)
 	{
 		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);
@@ -1045,7 +963,6 @@ namespace BansheeEngine
 		return true;
 	}
 
-	//---------------------------------------------------------------------
 	const D3D9RenderWindow* D3D9Device::getPrimaryWindow()
 	{		
 		RenderWindowToResorucesIterator it = mMapRenderWindowToResoruces.begin();
@@ -1058,14 +975,12 @@ namespace BansheeEngine
 		return it->first;
 	}
 
-	//---------------------------------------------------------------------
 	void D3D9Device::setSharedWindowHandle(HWND hSharedHWND)
 	{
 		if (hSharedHWND != msSharedFocusWindow)					
 			msSharedFocusWindow = hSharedHWND;					
 	}
 
-	//---------------------------------------------------------------------
 	void D3D9Device::updateRenderWindowsIndices()
 	{
 		// Update present parameters index attribute per render window.
@@ -1127,7 +1042,7 @@ namespace BansheeEngine
 			}
 		}
 	}
-	//---------------------------------------------------------------------
+
 	void D3D9Device::copyContentsToMemory(const D3D9RenderWindow* renderWindow, 
 		const PixelData &dst, RenderTarget::FrameBuffer buffer)
 	{
@@ -1334,7 +1249,5 @@ namespace BansheeEngine
 
 		SAFE_RELEASE(pTempSurf);
 		SAFE_RELEASE(pSurf);
-
-
 	}
 }

+ 51 - 123
CamelotD3D9Renderer/Source/CmD3D9DeviceManager.cpp

@@ -1,30 +1,3 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2011 Torus Knot Software Ltd
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
 #include "CmD3D9DeviceManager.h"
 #include "CmD3D9Device.h"
 #include "CmD3D9RenderSystem.h"
@@ -35,27 +8,21 @@ THE SOFTWARE.
 
 namespace BansheeEngine
 {
-	//---------------------------------------------------------------------
 	D3D9DeviceManager::D3D9DeviceManager()
+		:mActiveDevice(nullptr), mActiveRenderWindowDevice(nullptr)
 	{
-		mActiveDevice = NULL;		
-		mActiveRenderWindowDevice = NULL;
+
 	}
 
-	//---------------------------------------------------------------------
 	D3D9DeviceManager::~D3D9DeviceManager()
 	{
-		DeviceIterator itDevice = mRenderDevices.begin();
-		while (mRenderDevices.size() > 0)
-		{			
+		while (mRenderDevices.size() > 0)	
 			mRenderDevices[0]->destroy();						
-		}		
 
-		mActiveDevice = NULL;
-		mActiveRenderWindowDevice = NULL;
+		mActiveDevice = nullptr;
+		mActiveRenderWindowDevice = nullptr;
 	}
 
-	//---------------------------------------------------------------------
 	void D3D9DeviceManager::setActiveDevice(D3D9Device* device)
 	{
 		if (mActiveDevice != device)
@@ -63,7 +30,7 @@ namespace BansheeEngine
 			mActiveDevice = device;
 
 			D3D9RenderSystem* renderSystem = static_cast<D3D9RenderSystem*>(BansheeEngine::RenderSystem::instancePtr());
-			D3D9DriverList*		driverList	 = renderSystem->getDirect3DDrivers();
+			D3D9DriverList*	driverList = renderSystem->getDirect3DDrivers();
 
 			// Update the active driver member.
 			for (UINT32 i=0; i < driverList->count(); ++i)
@@ -78,54 +45,46 @@ namespace BansheeEngine
 		}						
 	}
 
-	//---------------------------------------------------------------------
 	D3D9Device* D3D9DeviceManager::getActiveDevice()
 	{	
-		if (mActiveDevice == NULL)
-		{
-			CM_EXCEPT(InvalidParametersException, "Current active device is NULL !!!" );
-		}
+		if (mActiveDevice == nullptr)
+			CM_EXCEPT(InvalidParametersException, "Current active device is null." );
 
 		return mActiveDevice;		
 	}
 
-	//---------------------------------------------------------------------
 	void D3D9DeviceManager::setActiveRenderTargetDevice(D3D9Device* device)
 	{
 		mActiveRenderWindowDevice = device;
-		if (mActiveRenderWindowDevice != NULL)		
+		if (mActiveRenderWindowDevice != nullptr)
 			setActiveDevice(mActiveRenderWindowDevice);			
 	}
 
-	//---------------------------------------------------------------------
 	D3D9Device* D3D9DeviceManager::getActiveRenderTargetDevice()
 	{
 		return mActiveRenderWindowDevice;
 	}
 
-	//---------------------------------------------------------------------
 	UINT D3D9DeviceManager::getDeviceCount()
 	{
 		return static_cast<UINT>(mRenderDevices.size());
 	}
 
-	//---------------------------------------------------------------------
 	D3D9Device* D3D9DeviceManager::getDevice(UINT index)
 	{
 		return mRenderDevices[index];
 	}
 
-	//---------------------------------------------------------------------
 	void D3D9DeviceManager::linkRenderWindow(D3D9RenderWindow* renderWindow)
 	{		
 		D3D9Device* renderDevice;
 
 		// Detach from previous device.
 		renderDevice = renderWindow->_getDevice();		
-		if (renderDevice != NULL)		
+		if (renderDevice != nullptr)
 			renderDevice->detachRenderWindow(renderWindow);						
 
-		D3D9RenderWindowList renderWindowsGroup;
+		Vector<D3D9RenderWindow*> renderWindowsGroup;
 
 		// Select new device for this window.		
 		renderDevice = selectDevice(renderWindow, renderWindowsGroup);
@@ -141,34 +100,31 @@ namespace BansheeEngine
 		}
 				
 		renderDevice->acquire();
-		if (mActiveDevice == NULL)			
+		if (mActiveDevice == nullptr)
 			setActiveDevice(renderDevice);		
 	}
 
-	//---------------------------------------------------------------------
-	D3D9Device* D3D9DeviceManager::selectDevice(D3D9RenderWindow* renderWindow, D3D9RenderWindowList& renderWindowsGroup)
+	D3D9Device* D3D9DeviceManager::selectDevice(D3D9RenderWindow* renderWindow, Vector<D3D9RenderWindow*>& renderWindowsGroup)
 	{
-		D3D9RenderSystem*		renderSystem	 = static_cast<D3D9RenderSystem*>(BansheeEngine::RenderSystem::instancePtr());
-		D3D9Device*				renderDevice	 = NULL;	
-		IDirect3D9*				direct3D9	     = D3D9RenderSystem::getDirect3D9();
-		UINT					nAdapterOrdinal  = D3DADAPTER_DEFAULT;
-		D3DDEVTYPE				devType			 = D3DDEVTYPE_HAL;						
-		DWORD					extraFlags		 = 0;					
-		D3D9DriverList*			driverList = renderSystem->getDirect3DDrivers();
-		bool					nvAdapterFound = false;
-
+		D3D9RenderSystem* renderSystem = static_cast<D3D9RenderSystem*>(BansheeEngine::RenderSystem::instancePtr());
+		D3D9Device*	renderDevice = nullptr;	
+		IDirect3D9*	direct3D9 = D3D9RenderSystem::getDirect3D9();
+		UINT adapterOrdinal = D3DADAPTER_DEFAULT;
+		D3DDEVTYPE devType = D3DDEVTYPE_HAL;						
+		DWORD extraFlags = 0;					
+		D3D9DriverList* driverList = renderSystem->getDirect3DDrivers();
 
 		// Default group includes at least the given render window.
 		renderWindowsGroup.push_back(renderWindow);
 
 		// Try to find a matching device from current device list.
-		if (renderDevice == NULL)
+		if (renderDevice == nullptr)
 		{
 			for (UINT32 i = 0; i < mRenderDevices.size(); ++i)
 			{
 				D3D9Device* currDevice = mRenderDevices[i];
 
-				if (currDevice->getAdapterNumber() == nAdapterOrdinal &&
+				if (currDevice->getAdapterNumber() == adapterOrdinal &&
 					currDevice->getDeviceType() == devType)
 				{
 					renderDevice = currDevice;
@@ -180,13 +136,13 @@ namespace BansheeEngine
 		// No matching device found -> try reference device type (might have been 
 		// previously created as a fallback, but don't change devType because HAL
 		// should be preferred on creation)
-		if (renderDevice == NULL)
+		if (renderDevice == nullptr)
 		{
 			for (UINT32 i = 0; i < mRenderDevices.size(); ++i)
 			{
 				D3D9Device* currDevice = mRenderDevices[i];
 
-				if (currDevice->getAdapterNumber() == nAdapterOrdinal &&
+				if (currDevice->getAdapterNumber() == adapterOrdinal &&
 					currDevice->getDeviceType() == D3DDEVTYPE_REF)
 				{
 					renderDevice = currDevice;
@@ -197,37 +153,35 @@ namespace BansheeEngine
 
 
 		// No matching device found -> create new one.
-		if (renderDevice == NULL)
+		if (renderDevice == nullptr)
 		{
-			renderDevice = cm_new<D3D9Device>(this, nAdapterOrdinal, direct3D9->GetAdapterMonitor(nAdapterOrdinal), devType, extraFlags);
+			renderDevice = cm_new<D3D9Device>(this, adapterOrdinal, direct3D9->GetAdapterMonitor(adapterOrdinal), devType, extraFlags);
 			mRenderDevices.push_back(renderDevice);
-			if (mActiveDevice == NULL)			
+
+			if (mActiveDevice == nullptr)
 				setActiveDevice(renderDevice);											
 		}				
 
 		return renderDevice;	
 	}
 
-	//-----------------------------------------------------------------------
 	D3D9Driver* D3D9DeviceManager::findDriver(D3D9RenderWindow* renderWindow)
 	{
-		D3D9RenderSystem*		renderSystem	 = static_cast<D3D9RenderSystem*>(BansheeEngine::RenderSystem::instancePtr());		
-		IDirect3D9*				direct3D9	     = D3D9RenderSystem::getDirect3D9();
-		UINT					nAdapterOrdinal  = D3DADAPTER_DEFAULT;						
-		HMONITOR				hRenderWindowMonitor = NULL;			
-		D3D9DriverList*			driverList = renderSystem->getDirect3DDrivers();
+		D3D9RenderSystem* renderSystem = static_cast<D3D9RenderSystem*>(BansheeEngine::RenderSystem::instancePtr());		
+		IDirect3D9*	direct3D9 = D3D9RenderSystem::getDirect3D9();				
+		HMONITOR renderWindowMonitor = NULL;			
+		D3D9DriverList* driverList = renderSystem->getDirect3DDrivers();
 
 		// Find the monitor this render window belongs to.
-		hRenderWindowMonitor = MonitorFromWindow(renderWindow->_getWindowHandle(), MONITOR_DEFAULTTONEAREST);
-
+		renderWindowMonitor = MonitorFromWindow(renderWindow->_getWindowHandle(), MONITOR_DEFAULTTONEAREST);
 
 		// Find the matching driver using window monitor handle.
 		for (UINT32 i = 0; i < driverList->count(); ++i)
 		{
-			D3D9Driver* currDriver       = driverList->item(i);
+			D3D9Driver* currDriver = driverList->item(i);
 			HMONITOR hCurrAdpaterMonitor = direct3D9->GetAdapterMonitor(currDriver->getAdapterNumber());
 
-			if (hCurrAdpaterMonitor == hRenderWindowMonitor)
+			if (hCurrAdpaterMonitor == renderWindowMonitor)
 			{
 				return currDriver;				
 			}
@@ -236,70 +190,44 @@ namespace BansheeEngine
 		return nullptr;
 	}
 
-	//-----------------------------------------------------------------------
 	void D3D9DeviceManager::notifyOnDeviceDestroy(D3D9Device* device)
 	{
-		if (device != NULL)
+		if (device != nullptr)
 		{						
 			if (device == mActiveDevice)			
-				mActiveDevice = NULL;			
+				mActiveDevice = nullptr;
 
-			DeviceIterator itDevice = mRenderDevices.begin();
-			while (itDevice != mRenderDevices.end())
+			auto iter = mRenderDevices.begin();
+			while (iter != mRenderDevices.end())
 			{			
-				if (*itDevice == device)
+				if (*iter == device)
 				{					
 					if(device != nullptr)
 						cm_delete(device);
 
-					mRenderDevices.erase(itDevice);
+					mRenderDevices.erase(iter);
 					break;
 				}												
-				++itDevice;
+				++iter;
 			}
 
-			if (mActiveDevice == NULL)
+			if (mActiveDevice == nullptr)
 			{
-				DeviceIterator itDevice = mRenderDevices.begin();
-				if (itDevice != mRenderDevices.end())				
-					mActiveDevice = (*itDevice);
+				auto iter = mRenderDevices.begin();
+				if (iter != mRenderDevices.end())				
+					mActiveDevice = (*iter);
 			}
 		}
 	}
 
-	//---------------------------------------------------------------------
 	D3D9Device*	D3D9DeviceManager::getDeviceFromD3D9Device(IDirect3DDevice9* d3d9Device)
 	{
-		DeviceIterator itDevice = mRenderDevices.begin();
-		while (itDevice != mRenderDevices.end())
-		{			
-			if ((*itDevice)->getD3D9Device() == d3d9Device)
-			{					
-				return *itDevice;
-			}												
-			++itDevice;
+		for (auto& device : mRenderDevices)
+		{
+			if (device->getD3D9Device() == d3d9Device)
+				return device;
 		}
 
-		return NULL;
-	}
-
-	//---------------------------------------------------------------------
-	void D3D9DeviceManager::destroyInactiveRenderDevices()
-	{
-		// TODO PORT - This is supposed to destroy inactive render devices but lastPresentFrame isn't being set properly at the moment, so this wont work properly
-		//DeviceIterator itDevice = mRenderDevices.begin();
-		//while (itDevice != mRenderDevices.end())
-		//{			
-		//	if ((*itDevice)->getRenderWindowCount() == 0 &&
-		//		(*itDevice)->getLastPresentFrame() + 1 < Root::getSingleton().getNextFrameNumber())
-		//	{		
-		//		if (*itDevice == mActiveRenderWindowDevice)
-		//			setActiveRenderTargetDevice(NULL);
-		//		(*itDevice)->destroy();
-		//		break;
-		//	}												
-		//	++itDevice;
-		//}
+		return nullptr;
 	}
-
 }

+ 7 - 4
CamelotD3D9Renderer/Source/CmD3D9IndexBuffer.cpp

@@ -21,7 +21,7 @@ namespace BansheeEngine
 	{
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
-		D3DPOOL eResourcePool = mSystemMemory? D3DPOOL_SYSTEMMEM : D3DPOOL_DEFAULT;
+		D3DPOOL eResourcePool = mSystemMemory ? D3DPOOL_SYSTEMMEM : D3DPOOL_MANAGED;
 
 		// Set the desired memory pool.
 		mBufferDesc.Pool = eResourcePool;
@@ -48,7 +48,7 @@ namespace BansheeEngine
 	{
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
-			DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.begin();
+		DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.begin();
 
 		while (it != mMapDeviceToBufferResources.end())
 		{
@@ -199,8 +199,11 @@ namespace BansheeEngine
 	{		
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
-		if (D3D9RenderSystem::getResourceManager()->getCreationPolicy() == RCP_CREATE_ON_ALL_DEVICES)
-			createBuffer(d3d9Device, mBufferDesc.Pool);		
+		if (mBufferDesc.Pool == D3DPOOL_DEFAULT)
+		{
+			if (D3D9RenderSystem::getResourceManager()->getCreationPolicy() == RCP_CREATE_ON_ALL_DEVICES)
+				createBuffer(d3d9Device, mBufferDesc.Pool);
+		}
 	}
 
 	void D3D9IndexBuffer::createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL ePool)

+ 1 - 1
CamelotD3D9Renderer/Source/CmD3D9PixelBuffer.cpp

@@ -424,7 +424,7 @@ namespace BansheeEngine
 
 		if (bufferResources	== NULL)
 		{
-			mOwnerTexture->createTextureResources(d3d9Device);
+			mOwnerTexture->createInternalResources(d3d9Device);
 			bufferResources = getBufferResources(d3d9Device);
 		}
 

+ 3 - 8
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -1167,26 +1167,21 @@ namespace BansheeEngine
 		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
-		if( FAILED( hr = getActiveD3D9Device()->EndScene() ) )
+		if(FAILED(hr = getActiveD3D9Device()->EndScene()))
 			CM_EXCEPT(RenderingAPIException, "Error ending frame");
-
-		mDeviceManager->destroyInactiveRenderDevices();
 	}
 
 	void D3D9RenderSystem::setVertexDeclaration(VertexDeclarationPtr decl)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		HRESULT hr;
-
-		std::shared_ptr<D3D9VertexDeclaration> d3ddecl = 
-			std::static_pointer_cast<D3D9VertexDeclaration>(decl);
+		std::shared_ptr<D3D9VertexDeclaration> d3ddecl = std::static_pointer_cast<D3D9VertexDeclaration>(decl);
 
+		HRESULT hr;
 		if (FAILED(hr = getActiveD3D9Device()->SetVertexDeclaration(d3ddecl->getD3DVertexDeclaration())))
 		{
 			CM_EXCEPT(RenderingAPIException, "Unable to set D3D9 vertex declaration");
 		}
-
 	}
 
 	void D3D9RenderSystem::setVertexBuffers(UINT32 index, VertexBufferPtr* buffers, UINT32 numBuffers)

+ 81 - 93
CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp

@@ -7,12 +7,13 @@
 #include "CmRenderSystem.h"
 #include "CmBitwise.h"
 #include "Win32/CmPlatformWndProc.h"
+#include "CmD3D9VideoModeInfo.h"
 #include "CmD3D9DeviceManager.h"
 
 namespace BansheeEngine
 {
 	D3D9RenderWindow::D3D9RenderWindow(const RENDER_WINDOW_DESC& desc, HINSTANCE instance)
-        : RenderWindow(desc), mInstance(instance), mIsDepthBuffered(true)  
+		: RenderWindow(desc), mInstance(instance), mIsDepthBuffered(true), mIsChild(false)
 	{
 		mDevice = NULL;
 		mIsFullScreen = false;		
@@ -51,6 +52,8 @@ namespace BansheeEngine
 		if(opt != mDesc.platformSpecific.end())
 			externalHandle = (HWND)parseUnsignedInt(opt->second);
 
+		mIsChild = parentHWnd != 0;
+
 		if (!externalHandle)
 		{
 			DWORD		dwStyle = WS_VISIBLE | WS_CLIPCHILDREN;
@@ -131,7 +134,7 @@ namespace BansheeEngine
 			mTop = top;
 			mLeft = left;
 
-			if (mDesc.fullscreen)
+			if (mDesc.fullscreen && !mIsChild)
 			{
 				dwStyleEx |= WS_EX_TOPMOST;
 				dwStyle |= WS_POPUP;
@@ -218,7 +221,7 @@ namespace BansheeEngine
 
 		mName = mDesc.title;
 		mIsDepthBuffered = mDesc.depthBuffer;
-		mIsFullScreen = mDesc.fullscreen;
+		mIsFullScreen = mDesc.fullscreen && !mIsChild;
 		mColorDepth = mDesc.colorDepth;
 
 		mActive = true;
@@ -250,77 +253,93 @@ namespace BansheeEngine
 		RenderWindow::destroy_internal();
 	}
 
-	void D3D9RenderWindow::setFullscreen(bool fullScreen, UINT32 width, UINT32 height)
+	void D3D9RenderWindow::setFullscreen(UINT32 width, UINT32 height, float refreshRate, UINT32 monitorIdx)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		if (fullScreen != mIsFullScreen || width != mWidth || height != mHeight)
-		{
-			if (fullScreen != mIsFullScreen)
-				mSwitchingFullscreen = true;
+		if (mIsChild)
+			return;
 
-			mStyle = WS_VISIBLE | WS_CLIPCHILDREN;
+		const D3D9VideoModeInfo& videoModeInfo = static_cast<const D3D9VideoModeInfo&>(RenderSystem::instance().getVideoModeInfo());
+		UINT32 numOutputs = videoModeInfo.getNumOutputs();
+		if (numOutputs == 0)
+			return;
 
-			bool oldFullscreen = mIsFullScreen;
-			mIsFullScreen = fullScreen;
-			mWidth = mDesiredWidth = width;
-			mHeight = mDesiredHeight = height;
+		UINT32 actualMonitorIdx = std::min(monitorIdx, numOutputs - 1);
+		const D3D9VideoOutputInfo& outputInfo = static_cast<const D3D9VideoOutputInfo&>(videoModeInfo.getOutputInfo(actualMonitorIdx));
 
-			if (fullScreen)
-			{
-				mStyle |= WS_POPUP;
-				
-				// Get the nearest monitor to this window.
-				HMONITOR hMonitor = MonitorFromWindow(mHWnd, MONITOR_DEFAULTTONEAREST);
+		bool oldFullscreen = mIsFullScreen;
 
-				// Get monitor info	
-				MONITORINFO monitorInfo;
+		mStyle = WS_VISIBLE | WS_CLIPCHILDREN | WS_POPUP;
+		mWidth = width;
+		mHeight = height;
+		mDisplayFrequency = Math::roundToInt(refreshRate);
 
-				memset(&monitorInfo, 0, sizeof(MONITORINFO));
-				monitorInfo.cbSize = sizeof(MONITORINFO);
-				GetMonitorInfo(hMonitor, &monitorInfo);
+		mIsFullScreen = true;
+		mSwitchingFullscreen = true;
 
-				mTop = monitorInfo.rcMonitor.top;
-				mLeft = monitorInfo.rcMonitor.left;				
-				
-				// need different ordering here
+		HMONITOR hMonitor = outputInfo.getMonitorHandle();
+		MONITORINFO monitorInfo;
 
-				if (oldFullscreen)
-				{
-					// was previously fullscreen, just changing the resolution
-					SetWindowPos(mHWnd, HWND_TOPMOST, mLeft, mTop, width, height, SWP_NOACTIVATE);
-				}
-				else
-				{
-					SetWindowPos(mHWnd, HWND_TOPMOST, mLeft, mTop, width, height, SWP_NOACTIVATE);
-					//MoveWindow(mHWnd, mLeft, mTop, mWidth, mHeight, FALSE);
-					SetWindowLong(mHWnd, GWL_STYLE, mStyle);
-					SetWindowPos(mHWnd, 0, 0,0, 0,0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
-				}
-			}
-			else
+		memset(&monitorInfo, 0, sizeof(MONITORINFO));
+		monitorInfo.cbSize = sizeof(MONITORINFO);
+		GetMonitorInfo(hMonitor, &monitorInfo);
+
+		mTop = monitorInfo.rcMonitor.top;
+		mLeft = monitorInfo.rcMonitor.left;
+
+		if (oldFullscreen) // Was previously fullscreen, just changing the resolution
+		{
+			SetWindowPos(mHWnd, HWND_TOPMOST, mLeft, mTop, mWidth, mHeight, SWP_NOACTIVATE);
+		}
+		else
+		{
+			SetWindowPos(mHWnd, HWND_TOPMOST, mLeft, mTop, mWidth, mHeight, SWP_NOACTIVATE);
+			SetWindowLong(mHWnd, GWL_STYLE, mStyle);
+			SetWindowPos(mHWnd, 0, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
+		}
+
+		// Invalidate device, which resets it
+		mDevice->invalidate(this);
+	}
+
+	void D3D9RenderWindow::setFullscreen(const VideoMode& mode, UINT32 refreshRateIdx)
+	{
+		const VideoOutputInfo& outputInfo = mode.getParentOutput();
+		UINT32 monitorIdx = 0;
+		for (UINT32 i = 0; i < outputInfo.getNumVideoModes(); i++)
+		{
+			if (&outputInfo.getVideoMode(i) == &mode)
 			{
-				mStyle |= WS_OVERLAPPEDWINDOW;
-				// Calculate window dimensions required
-				// to get the requested client area
-				unsigned int winWidth, winHeight;
-				_adjustWindow(mWidth, mHeight, mStyle, &winWidth, &winHeight);
-
-				SetWindowLong(mHWnd, GWL_STYLE, mStyle);
-				SetWindowPos(mHWnd, HWND_NOTOPMOST, 0, 0, winWidth, winHeight,
-					SWP_DRAWFRAME | SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOACTIVATE);
-				// Note that we also set the position in the restoreLostDevice method
-				// via _finishSwitchingFullScreen
+				monitorIdx = i;
+				break;
 			}
-						
-			// Have to release & trigger device reset
-			// NB don't use windowMovedOrResized since Win32 doesn't know
-			// about the size change yet				
-			mDevice->invalidate(this);
-
-			// TODO - Notify viewports of resize
 		}
-	} 
+
+		setFullscreen(mode.getWidth(), mode.getHeight(), mode.getRefreshRate(refreshRateIdx), monitorIdx);
+	}
+
+	void D3D9RenderWindow::setWindowed()
+	{
+		THROW_IF_NOT_CORE_THREAD;
+
+		if (!mIsFullScreen)
+			return;
+
+		mIsFullScreen = false;
+		mSwitchingFullscreen = true;
+
+		mStyle = WS_VISIBLE | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW;
+
+		unsigned int winWidth, winHeight;
+		_adjustWindow(mWidth, mHeight, mStyle, &winWidth, &winHeight);
+
+		SetWindowLong(mHWnd, GWL_STYLE, mStyle);
+		SetWindowPos(mHWnd, HWND_NOTOPMOST, 0, 0, winWidth, winHeight,
+			SWP_DRAWFRAME | SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOACTIVATE);
+
+		mDevice->invalidate(this);
+	}
 
 	void D3D9RenderWindow::setHidden(bool hidden)
 	{
@@ -382,7 +401,7 @@ namespace BansheeEngine
 
 	void D3D9RenderWindow::getCustomAttribute( const String& name, void* pData ) const
 	{
-		// Valid attributes and their equvalent native functions:
+		// Valid attributes and their equivalent native functions:
 		// D3DDEVICE			: getD3DDevice
 		// WINDOW				: getWindowHandle
 
@@ -616,17 +635,6 @@ namespace BansheeEngine
 		}
 		else
 		{
-			// NB not using vsync in windowed mode in D3D9 can cause jerking at low 
-			// frame rates no matter what buffering modes are used (odd - perhaps a
-			// timer issue in D3D9 since GL doesn't suffer from this) 
-			// low is < 200fps in this context
-			if (!mIsFullScreen)
-			{
-				// TODO LOG PORT - Enable this warning later?
-				//LogManager::getSingleton().logMessage("D3D9 : WARNING - "
-				//	"disabling VSync in windowed mode can cause timing issues at lower "
-				//	"frame rates, turn VSync on if you observe this problem.");
-			}
 			presentParams->PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
 		}
 
@@ -679,21 +687,6 @@ namespace BansheeEngine
 
 		presentParams->MultiSampleType = fsaaType;
 		presentParams->MultiSampleQuality = (fsaaQuality == 0) ? 0 : fsaaQuality;
-
-		// Check sRGB
-		if (mHwGamma)
-		{
-			/* hmm, this never succeeds even when device does support??
-			if(FAILED(pD3D->CheckDeviceFormat(mDriver->getAdapterNumber(),
-				devType, presentParams->BackBufferFormat, D3DUSAGE_QUERY_SRGBWRITE, 
-				D3DRTYPE_SURFACE, presentParams->BackBufferFormat )))
-			{
-				// disable - not supported
-				mHwGamma = false;
-			}
-			*/
-
-		}
 	}
 
 	IDirect3DDevice9* D3D9RenderWindow::_getD3D9Device() const
@@ -706,11 +699,6 @@ namespace BansheeEngine
 		return mDevice->getBackBuffer(this);
 	}
 
-	bool D3D9RenderWindow::_getSwitchingFullscreen() const
-	{
-		return mSwitchingFullscreen;
-	}
-
 	D3D9Device* D3D9RenderWindow::_getDevice() const
 	{
 		return mDevice;

+ 0 - 27
CamelotD3D9Renderer/Source/CmD3D9Resource.cpp

@@ -1,30 +1,3 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2011 Torus Knot Software Ltd
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
 #include "CmD3D9Resource.h"
 #include "CmD3D9ResourceManager.h"
 #include "CmD3D9RenderSystem.h"

+ 13 - 70
CamelotD3D9Renderer/Source/CmD3D9ResourceManager.cpp

@@ -1,140 +1,84 @@
-/*
------------------------------------------------------------------------------
-This source file is part of OGRE
-(Object-oriented Graphics Rendering Engine)
-For the latest info, see http://www.ogre3d.org/
-
-Copyright (c) 2000-2011 Torus Knot Software Ltd
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
 #include "CmD3D9Resource.h"
 #include "CmD3D9ResourceManager.h"
 #include "CmD3D9PixelBuffer.h"
 
 namespace BansheeEngine
 {
-	
-	//-----------------------------------------------------------------------
 	D3D9ResourceManager::D3D9ResourceManager()
 	{
 		mResourceCreationPolicy = RCP_CREATE_ON_ALL_DEVICES;
 		mDeviceAccessLockCount = 0;
 	}
 
-	//-----------------------------------------------------------------------
 	D3D9ResourceManager::~D3D9ResourceManager()
 	{
 	
 	}
  
-	//-----------------------------------------------------------------------
 	void D3D9ResourceManager::setCreationPolicy(D3D9ResourceCreationPolicy creationPolicy)
 	{
 		mResourceCreationPolicy = creationPolicy;
 	}
 
-	//-----------------------------------------------------------------------
 	D3D9ResourceCreationPolicy D3D9ResourceManager::getCreationPolicy() const
 	{
 		return mResourceCreationPolicy;
 	}
 
-	 //-----------------------------------------------------------------------
 	void D3D9ResourceManager::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
 	{				
 		CM_LOCK_MUTEX(mResourcesMutex)
 
-		ResourceContainerIterator it = mResources.begin();
-		while (it != mResources.end())
-		{
-			(*it)->notifyOnDeviceCreate(d3d9Device);
-			++it;
-		}				
+		for (auto& resource : mResources)
+			resource->notifyOnDeviceCreate(d3d9Device);			
 	}
 
-	 //-----------------------------------------------------------------------
 	void D3D9ResourceManager::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
 	{
 		CM_LOCK_MUTEX(mResourcesMutex)
 
-		ResourceContainerIterator it = mResources.begin();
-		while (it != mResources.end())
-		{
-			(*it)->notifyOnDeviceDestroy(d3d9Device);
-			++it;
-		}	
+		for (auto& resource : mResources)
+			resource->notifyOnDeviceDestroy(d3d9Device);
 	}
 
-	 //-----------------------------------------------------------------------
 	void D3D9ResourceManager::notifyOnDeviceLost(IDirect3DDevice9* d3d9Device)
 	{
 		CM_LOCK_MUTEX(mResourcesMutex)
 
-		ResourceContainerIterator it = mResources.begin();
-		while (it != mResources.end())
-		{
-			(*it)->notifyOnDeviceLost(d3d9Device);
-			++it;
-		}	
+		for (auto& resource : mResources)
+			resource->notifyOnDeviceLost(d3d9Device);
 	}
 
-	 //-----------------------------------------------------------------------
 	void D3D9ResourceManager::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device)
 	{		
 		CM_LOCK_MUTEX(mResourcesMutex)
 
-		ResourceContainerIterator it = mResources.begin();
-		while (it != mResources.end())
-		{
-			(*it)->notifyOnDeviceReset(d3d9Device);
-			++it;			
-		}		
+		for (auto& resource : mResources)
+			resource->notifyOnDeviceReset(d3d9Device);	
 	}
 
-	//-----------------------------------------------------------------------
 	void D3D9ResourceManager::_notifyResourceCreated(D3D9Resource* pResource)
 	{		
 		CM_LOCK_MUTEX(mResourcesMutex)		
 		mResources.push_back(pResource);
 	}
 	
-	//-----------------------------------------------------------------------
 	void D3D9ResourceManager::_notifyResourceDestroyed(D3D9Resource* pResource)
 	{		
 		CM_LOCK_MUTEX(mResourcesMutex)
 
-		ResourceContainerIterator it = mResources.begin();
-
-		while (it != mResources.end())
+		auto iter = mResources.begin();
+		while (iter != mResources.end())
 		{
-			if ((*it) == pResource)
+			if ((*iter) == pResource)
 			{
-				mResources.erase(it);
+				mResources.erase(iter);
 				break;
 			}			
-			++it;
+			++iter;
 		}	
 	}
 	
-	//-----------------------------------------------------------------------
 	void D3D9ResourceManager::lockDeviceAccess()
 	{	
 		assert(mDeviceAccessLockCount >= 0);
@@ -146,7 +90,6 @@ namespace BansheeEngine
 		}
 	}
 
-	//-----------------------------------------------------------------------
 	void D3D9ResourceManager::unlockDeviceAccess()
 	{
 		assert(mDeviceAccessLockCount > 0);		

+ 6 - 27
CamelotD3D9Renderer/Source/CmD3D9Texture.cpp

@@ -300,19 +300,6 @@ namespace BansheeEngine
 
 		return textureResources;
 	}
-
-	
-	void D3D9Texture::createTextureResources(IDirect3DDevice9* d3d9Device)
-	{				
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-			
-			/*		prepareImpl();		
-
-			loadImpl(d3d9Device);
-
-			postLoadImpl();	*/			
-	}
-
 	
 	void D3D9Texture::freeTextureResources(IDirect3DDevice9* d3d9Device, D3D9Texture::TextureResources* textureResources)
 	{		
@@ -352,18 +339,10 @@ namespace BansheeEngine
 		{
 			mD3DPool = D3DPOOL_MANAGED;
 		}
-
 	}
 	
 	void D3D9Texture::createInternalResources(IDirect3DDevice9* d3d9Device)
 	{		
-		TextureResources* textureResources;			
-
-		// Check if resources already exist.
-		textureResources = getTextureResources(d3d9Device);
-		if (textureResources != NULL && textureResources->pBaseTex != NULL)
-			return;
-		
 		// load based on tex.type
 		switch (getTextureType())
 		{
@@ -1128,7 +1107,7 @@ namespace BansheeEngine
 		TextureResources* textureResources = getTextureResources(d3d9Device);
 		if (textureResources == NULL || textureResources->pBaseTex == NULL)
 		{				
-			createTextureResources(d3d9Device);
+			createInternalResources(d3d9Device);
 			textureResources = getTextureResources(d3d9Device);			
 		}
 	
@@ -1152,7 +1131,7 @@ namespace BansheeEngine
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
 		if (D3D9RenderSystem::getResourceManager()->getCreationPolicy() == RCP_CREATE_ON_ALL_DEVICES)
-			createTextureResources(d3d9Device);
+			createInternalResources(d3d9Device);
 	}
 
 	//---------------------------------------------------------------------
@@ -1214,7 +1193,7 @@ namespace BansheeEngine
 
 		if(mD3DPool == D3DPOOL_DEFAULT)
 		{			
-			createTextureResources(d3d9Device);
+			createInternalResources(d3d9Device);
 		}
 	}
 
@@ -1229,7 +1208,7 @@ namespace BansheeEngine
 		textureResources = getTextureResources(d3d9Device);		
 		if (textureResources == NULL || textureResources->pBaseTex == NULL)
 		{			
-			createTextureResources(d3d9Device);
+			createInternalResources(d3d9Device);
 			textureResources = getTextureResources(d3d9Device);			
 		}
 		assert(textureResources); 
@@ -1249,7 +1228,7 @@ namespace BansheeEngine
 		textureResources = getTextureResources(d3d9Device);		
 		if (textureResources == NULL || textureResources->pNormTex == NULL)
 		{
-			createTextureResources(d3d9Device);
+			createInternalResources(d3d9Device);
 			textureResources = getTextureResources(d3d9Device);			
 		}
 		assert(textureResources); 
@@ -1269,7 +1248,7 @@ namespace BansheeEngine
 		textureResources = getTextureResources(d3d9Device);		
 		if (textureResources == NULL || textureResources->pCubeTex)
 		{
-			createTextureResources(d3d9Device);
+			createInternalResources(d3d9Device);
 			textureResources = getTextureResources(d3d9Device);			
 		}
 		assert(textureResources); 

+ 1 - 1
CamelotD3D9Renderer/Source/CmD3D9VertexBuffer.cpp

@@ -308,7 +308,7 @@ namespace BansheeEngine {
 	{
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
-		D3DPOOL eResourcePool = mSystemMemory ? D3DPOOL_SYSTEMMEM : D3DPOOL_DEFAULT;    		
+		D3DPOOL eResourcePool = mSystemMemory ? D3DPOOL_SYSTEMMEM : D3DPOOL_MANAGED;    		
 
 		// Set the desired memory pool.
 		mBufferDesc.Pool = eResourcePool;

+ 8 - 14
Polish.txt

@@ -15,25 +15,19 @@ Finish GPUProfiler:
 
  Fullscreen stuff:
 
-Add VideoModeInfo to OpenGL and DX9. Remove any existing functionality.
- - Don't forget desktop mode
- - Don't forget child window check
+ In DX9 RenderWindow delete _finishSwitchingFullscreen method if possible after I test fullscreen switching
+ Update OpenGL render window set fullscreen methods.
 
 Test if it all works. Especially going fullscreen on another monitor.
 When initializing a render window I don't have an option to use exact refresh rate (i.e. in RENDER_WINDOW_DESC)
 
- EnumDisplayMonitors - Get all available monitors
- - http://msdn.microsoft.com/en-us/library/windows/desktop/dd162617(v=vs.85).aspx
-GetMonitorInfo - Get display name for monitor
- - http://msdn.microsoft.com/en-us/library/windows/desktop/dd144901(v=vs.85).aspx
 ChangeDisplaySettingEx - For actually changing resolution and refresh rate
  - http://msdn.microsoft.com/en-us/library/windows/desktop/dd183413(v=vs.85).aspx
-EnumDisplaySettings  - To query all available resolutions and refresh rates
- - http://msdn.microsoft.com/en-us/library/windows/desktop/dd162611(v=vs.85).aspx
 
-RenderSystem
- - Allow for querying multiple monitors
- - Allow querying for all possible resolutions and refresh rates (for each monitor specifically)
- - Allow querying for desktop resolution and refresh rate
 
-in window setFullscreen add a refresh rate setting, and a monitor index
+
+ -----------------------------
+
+ Refactor:
+ - Make CmApplication a base of BsApplication
+ - If I merge CmApp and BsApp consider refactoring CmApplication::mainLoopCallback