Răsfoiți Sursa

Refactored DX11 windows as well

Marko Pintera 12 ani în urmă
părinte
comite
aaa7d3e3d6

+ 2 - 2
CamelotClient/CamelotClient.cpp

@@ -30,9 +30,9 @@
 #include "CmRTTIType.h"
 #include "CmCursor.h"
 
-//#define DX11
+#define DX11
 //#define DX9
-#define GL
+//#define GL
 
 using namespace CamelotFramework;
 using namespace BansheeEditor;

+ 3 - 3
CamelotCore/Include/CmRenderWindow.h

@@ -110,7 +110,7 @@ namespace CamelotFramework
 		/** 
 			@brief Core method. Alter fullscreen mode options.
 		*/
-		virtual void setFullscreen(bool fullScreen, unsigned int width, unsigned int height)
+		virtual void setFullscreen(bool fullScreen, UINT32 width, UINT32 height)
                 { (void)fullScreen; (void)width; (void)height; }
 
         /**
@@ -162,8 +162,8 @@ namespace CamelotFramework
         * @brief	Overloaded version of getMetrics from RenderTarget, including extra details
 		*			specific to windowing systems.
         */
-        virtual void getMetrics(unsigned int& width, unsigned int& height, unsigned int& colourDepth, 
-			int& left, int& top);
+        virtual void getMetrics(UINT32& width, UINT32& height, UINT32& colourDepth, 
+			INT32& left, INT32& top);
 
 		/**
          * @brief	Internal method. Core method. Called when window is moved or resized.

+ 2 - 2
CamelotCore/Source/CmRenderWindow.cpp

@@ -46,8 +46,8 @@ namespace CamelotFramework
 		
 	}
 
-    void RenderWindow::getMetrics(unsigned int& width, unsigned int& height, unsigned int& colourDepth,
-		int& left, int& top)
+    void RenderWindow::getMetrics(UINT32& width, UINT32& height, UINT32& colourDepth,
+		INT32& left, INT32& top)
     {
         width = mWidth;
         height = mHeight;

+ 63 - 18
CamelotD3D11RenderSystem/Include/CmD3D11RenderWindow.h

@@ -10,45 +10,90 @@ namespace CamelotFramework
 	public:
 		~D3D11RenderWindow();
 
-		void reposition(int left, int top);
-		void resize(unsigned int width, unsigned int height);
+		/**
+		 * @copydoc RenderWindow::reposition
+		 */
+		void reposition(INT32 left, INT32 top);
+
+		/**
+		 * @copydoc RenderWindow::resize
+		 */
+		void resize(UINT32 width, UINT32 height);
 
+		/**
+		 * @copydoc RenderWindow::setHidden
+		 */
 		void setHidden(bool hidden);
+
+		/**
+		 * @copydoc RenderWindow::setActive
+		 */
 		void setActive(bool state);
-		void setFullscreen(bool fullScreen, unsigned int width, unsigned int height);
 
+		/**
+		 * @copydoc RenderWindow::setFullscreen
+		 */
+		void setFullscreen(bool fullScreen, UINT32 width, UINT32 height);
+
+		/**
+		 * @copydoc RenderWindow::copyContentsToMemory
+		 */
 		void copyContentsToMemory(const PixelData &dst, FrameBuffer buffer);
+
+		/**
+		 * @copydoc RenderWindow::swapBuffers
+		 */
 		void swapBuffers();
 
-		void _windowMovedOrResized();
+		/**
+		 * @copydoc RenderWindow::isClosed
+		 */
+		bool isClosed() const { return mClosed; }
 
-		bool isClosed() const									{ return mClosed; }
-		bool isHidden() const									{ return mHidden; }
+		/**
+		 * @copydoc RenderWindow::isHidden
+		 */
+		bool isHidden() const { return mHidden; }
 
+		/**
+		 * @copydoc RenderWindow::screenToWindowPos
+		 */
 		Int2 screenToWindowPos(const Int2& screenPos) const;
 
-		void getCustomAttribute( const String& name, void* pData ) const;
-		DXGI_SWAP_CHAIN_DESC* getPresentationParameters(void)	{ return &mSwapChainDesc; }
-		HWND getWindowHandle() const							{ return mHWnd; }
+		/**
+		 * @copydoc RenderWindow::getCustomAttribute
+		 */
+		void getCustomAttribute(const String& name, void* pData) const;
+
+		/**
+		 * @copydoc RenderWindow::requiresTextureFlipping
+		 */
+		bool requiresTextureFlipping() const { return false; }
+
+		/**
+		 * @copydoc RenderWindow::reposition
+		 */
+		void _windowMovedOrResized();
 
-		bool requiresTextureFlipping() const					{ return false; }
+		DXGI_SWAP_CHAIN_DESC* _getPresentationParameters(void) { return &mSwapChainDesc; }
+		HWND _getWindowHandle() const { return mHWnd; }
 
 	protected:
 		friend class D3D11RenderWindowManager;
 		D3D11RenderWindow(const RENDER_WINDOW_DESC& desc, D3D11Device& device, IDXGIFactory* DXGIFactory);
 
-		void _createSizeDependedD3DResources();
-		void _destroySizeDependedD3DResources();
+		void createSizeDependedD3DResources();
+		void destroySizeDependedD3DResources();
 
-		IDXGIDevice* _queryDxgiDevice(); 
+		IDXGIDevice* queryDxgiDevice(); 
 
-		bool _checkMultiSampleQuality(UINT SampleCount, UINT *outQuality, DXGI_FORMAT format);
+		bool checkMultiSampleQuality(UINT32 SampleCount, UINT32 *outQuality, DXGI_FORMAT format);
 
-		void _createSwapChain();
-		void _resizeSwapChainBuffers(unsigned width, unsigned height);
+		void createSwapChain();
+		void resizeSwapChainBuffers(unsigned width, unsigned height);
 
-		bool _getSwitchingFullscreen() const					{ return mSwitchingFullscreen; }
-		void _finishSwitchingFullscreen();
+		bool getSwitchingFullscreen() const	{ return mSwitchingFullscreen; }
+		void finishSwitchingFullscreen();
 		
 		/**
 		 * @copydoc RenderWindow::initialize_internal().

+ 58 - 41
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -1,4 +1,5 @@
 #include "CmD3D11RenderWindow.h"
+#include "CmCoreThread.h"
 #include "CmWindowEventUtilities.h"
 #include "CmD3D11RenderSystem.h"
 #include "CmD3D11Device.h"
@@ -251,8 +252,8 @@ namespace CamelotFramework
 		mWidth = rc.right;
 		mHeight = rc.bottom;
 
-		_createSwapChain();
-		_createSizeDependedD3DResources();
+		createSwapChain();
+		createSizeDependedD3DResources();
 		mDXGIFactory->MakeWindowAssociation(mHWnd, NULL);
 		setHidden(mHidden);
 
@@ -280,13 +281,15 @@ namespace CamelotFramework
 
 		mHWnd = nullptr;
 
-		_destroySizeDependedD3DResources();
+		destroySizeDependedD3DResources();
 
 		RenderWindow::destroy_internal();
 	}
 
 	void D3D11RenderWindow::swapBuffers()
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
 		if(mDevice.getD3D11Device() != nullptr)
 		{
 			HRESULT hr = mSwapChain->Present(mVSync ? mVSyncInterval : 0, 0);
@@ -298,6 +301,8 @@ namespace CamelotFramework
 
 	void D3D11RenderWindow::reposition(int top, int left)
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
 		if (mHWnd && !mIsFullScreen)
 		{
 			SetWindowPos(mHWnd, 0, top, left, 0, 0,
@@ -307,6 +312,8 @@ namespace CamelotFramework
 
 	void D3D11RenderWindow::resize(unsigned int width, unsigned int height)
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
 		if (mHWnd && !mIsFullScreen)
 		{
 			RECT rc = { 0, 0, width, height };
@@ -318,36 +325,10 @@ namespace CamelotFramework
 		}
 	}
 
-	void D3D11RenderWindow::_windowMovedOrResized()
-	{
-		if (!mHWnd || IsIconic(mHWnd))
-			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;
-
-		if (mWidth == width && mHeight == height)
-			return;
-
-		_resizeSwapChainBuffers(width, height);
-
-		RenderWindow::_windowMovedOrResized();
-	}
-
 	void D3D11RenderWindow::setActive(bool state)
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
 		if (mHWnd && mSwapChain)
 		{
 			if (state)
@@ -367,6 +348,8 @@ namespace CamelotFramework
 
 	void D3D11RenderWindow::setHidden(bool hidden)
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
 		mHidden = hidden;
 		if (!mIsExternal)
 		{
@@ -379,6 +362,8 @@ namespace CamelotFramework
 
 	void D3D11RenderWindow::setFullscreen(bool fullScreen, unsigned int width, unsigned int height)
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
 		if (fullScreen != mIsFullScreen || width != mWidth || height != mHeight)
 		{
 			if (fullScreen != mIsFullScreen)
@@ -462,6 +447,8 @@ namespace CamelotFramework
 
 	void D3D11RenderWindow::copyContentsToMemory(const PixelData &dst, FrameBuffer buffer)
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
 		if(mBackBuffer == nullptr)
 			return;
 
@@ -548,12 +535,42 @@ namespace CamelotFramework
 		return Int2(pos.x, pos.y);
 	}
 
-	void D3D11RenderWindow::_createSwapChain()
+	void D3D11RenderWindow::_windowMovedOrResized()
+	{
+		THROW_IF_NOT_CORE_THREAD;
+
+		if (!mHWnd || IsIconic(mHWnd))
+			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;
+
+		if (mWidth == width && mHeight == height)
+			return;
+
+		resizeSwapChainBuffers(width, height);
+
+		RenderWindow::_windowMovedOrResized();
+	}
+
+	void D3D11RenderWindow::createSwapChain()
 	{
 		ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
 
 		// get the dxgi device
-		IDXGIDevice* pDXGIDevice = _queryDxgiDevice();
+		IDXGIDevice* pDXGIDevice = queryDxgiDevice();
 
 		ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
 		DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
@@ -599,7 +616,7 @@ namespace CamelotFramework
 			CM_EXCEPT(RenderingAPIException, "Unable to create swap chain");
 	}
 
-	void D3D11RenderWindow::_createSizeDependedD3DResources()
+	void D3D11RenderWindow::createSizeDependedD3DResources()
 	{
 		// obtain back buffer
 		SAFE_RELEASE(mBackBuffer);
@@ -642,7 +659,7 @@ namespace CamelotFramework
 		mDepthStencilView = Texture::requestView(mDepthStencilBuffer, 0, 1, 0, 1, GVU_DEPTHSTENCIL);
 	}
 
-	void D3D11RenderWindow::_destroySizeDependedD3DResources()
+	void D3D11RenderWindow::destroySizeDependedD3DResources()
 	{
 		SAFE_RELEASE(mBackBuffer);
 		SAFE_RELEASE(mRenderTargetView);
@@ -650,9 +667,9 @@ namespace CamelotFramework
 		mDepthStencilBuffer = nullptr;
 	}
 
-	void D3D11RenderWindow::_resizeSwapChainBuffers(unsigned width, unsigned height)
+	void D3D11RenderWindow::resizeSwapChainBuffers(unsigned width, unsigned height)
 	{
-		_destroySizeDependedD3DResources();
+		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;
@@ -662,7 +679,7 @@ namespace CamelotFramework
 		mHeight = mSwapChainDesc.BufferDesc.Height;
 		mIsFullScreen = (0 == mSwapChainDesc.Windowed); // Alt-Enter together with SetWindowAssociation() can change this state
 
-		_createSizeDependedD3DResources();
+		createSizeDependedD3DResources();
 
 		mDevice.getImmediateContext()->OMSetRenderTargets(0, 0, 0);
 		// Additional swap chains need their own depth buffer
@@ -696,7 +713,7 @@ namespace CamelotFramework
 		}
 	}
 
-	IDXGIDevice* D3D11RenderWindow::_queryDxgiDevice()
+	IDXGIDevice* D3D11RenderWindow::queryDxgiDevice()
 	{
 		if (mDevice.getD3D11Device() == nullptr)
 		{
@@ -711,7 +728,7 @@ namespace CamelotFramework
 		return pDXGIDevice;
 	}
 
-	void D3D11RenderWindow::_finishSwitchingFullscreen()
+	void D3D11RenderWindow::finishSwitchingFullscreen()
 	{
 		if(mIsFullScreen)
 		{
@@ -741,7 +758,7 @@ namespace CamelotFramework
 		mSwitchingFullscreen = false;
 	}
 
-	bool D3D11RenderWindow::_checkMultiSampleQuality(UINT SampleCount, UINT *outQuality, DXGI_FORMAT format)
+	bool D3D11RenderWindow::checkMultiSampleQuality(UINT32 SampleCount, UINT32 *outQuality, DXGI_FORMAT format)
 	{
 		if (SUCCEEDED(mDevice.getD3D11Device()->CheckMultisampleQualityLevels(format, SampleCount, outQuality)))
 			return true;

+ 3 - 3
CamelotD3D9Renderer/Include/CmD3D9RenderWindow.h

@@ -41,7 +41,7 @@ namespace CamelotFramework
 		/**
 		 * @copydoc RenderWindow::setFullscreen
 		 */
-		void setFullscreen(bool fullScreen, unsigned int width, unsigned int height);
+		void setFullscreen(bool fullScreen, UINT32 width, UINT32 height);
 
 		/**
 		 * @copydoc RenderWindow::isActive
@@ -66,12 +66,12 @@ namespace CamelotFramework
 		/**
 		 * @copydoc RenderWindow::reposition
 		 */
-		void reposition(int left, int top);
+		void reposition(INT32 left, INT32 top);
 
 		/**
 		 * @copydoc RenderWindow::resize
 		 */
-		void resize(unsigned int width, unsigned int height);
+		void resize(UINT32 width, UINT32 height);
 
 		/**
 		 * @copydoc RenderWindow::getCustomAttribute

+ 3 - 3
CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp

@@ -279,7 +279,7 @@ namespace CamelotFramework
 		RenderWindow::destroy_internal();
 	}
 
-	void D3D9RenderWindow::setFullscreen(bool fullScreen, unsigned int width, unsigned int height)
+	void D3D9RenderWindow::setFullscreen(bool fullScreen, UINT32 width, UINT32 height)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
@@ -364,7 +364,7 @@ namespace CamelotFramework
 		return (mHWnd && !IsIconic(mHWnd));
 	}
 
-	void D3D9RenderWindow::reposition(int top, int left)
+	void D3D9RenderWindow::reposition(INT32 top, INT32 left)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
@@ -375,7 +375,7 @@ namespace CamelotFramework
 		}
 	}
 
-	void D3D9RenderWindow::resize(unsigned int width, unsigned int height)
+	void D3D9RenderWindow::resize(UINT32 width, UINT32 height)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 

+ 11 - 11
CamelotGLRenderer/Include/CmWin32Window.h

@@ -41,7 +41,7 @@ namespace CamelotFramework
 		/**
 		 * @copydoc RenderWindow::setFullscreen
 		 */
-		void setFullscreen(bool fullScreen, unsigned int width, unsigned int height);
+		void setFullscreen(bool fullScreen, UINT32 width, UINT32 height);
 
 		/**
 		 * @copydoc RenderWindow::isActive
@@ -61,12 +61,12 @@ namespace CamelotFramework
 		/**
 		 * @copydoc RenderWindow::reposition
 		 */
-		void reposition(int left, int top);
+		void reposition(INT32 left, INT32 top);
 
 		/**
 		 * @copydoc RenderWindow::resize
 		 */
-		void resize(unsigned int width, unsigned int height);
+		void resize(UINT32 width, UINT32 height);
 
 		/**
 		 * @copydoc RenderWindow::copyContentsToMemory
@@ -83,11 +83,6 @@ namespace CamelotFramework
 		 */
 		bool requiresTextureFlipping() const { return false; }
 
-		/**
-		 * @copydoc RenderWindow::_windowMovedOrResized
-		 */
-		void _windowMovedOrResized(void);
-
 		/**
 		 * @copydoc RenderWindow::screenToWindowPos
 		 */
@@ -103,10 +98,15 @@ namespace CamelotFramework
 		 */
 		virtual void setActive( bool state );
 
-		HWND getWindowHandle() const { return mHWnd; }
-		HDC getHDC() const { return mHDC; }
+		/**
+		 * @copydoc RenderWindow::_windowMovedOrResized
+		 */
+		void _windowMovedOrResized(void);
+
+		HWND _getWindowHandle() const { return mHWnd; }
+		HDC _getHDC() const { return mHDC; }
 		
-		void adjustWindow(unsigned int clientWidth, unsigned int clientHeight, 
+		void _adjustWindow(unsigned int clientWidth, unsigned int clientHeight, 
 			unsigned int* winWidth, unsigned int* winHeight);
 
 	protected:

+ 1 - 1
CamelotGLRenderer/Source/CmWin32GLSupport.cpp

@@ -132,7 +132,7 @@ namespace CamelotFramework
 			(PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsString");
 		if(!_wglGetExtensionsString)
 			return;
-		const char *wgl_extensions = _wglGetExtensionsString(mInitialWindow->getHDC());
+		const char *wgl_extensions = _wglGetExtensionsString(mInitialWindow->_getHDC());
 
 		// Parse them, and add them to the main list
 		StringStream ext;

+ 7 - 7
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -165,7 +165,7 @@ namespace CamelotFramework {
 				int screenh = monitorInfoEx.rcWork.bottom - monitorInfoEx.rcWork.top;
 
 				unsigned int winWidth, winHeight;
-				adjustWindow(mDesc.width, mDesc.height, &winWidth, &winHeight);
+				_adjustWindow(mDesc.width, mDesc.height, &winWidth, &winHeight);
 
 				// clamp window dimensions to screen size
 				int outerw = (int(winWidth) < screenw)? int(winWidth) : screenw;
@@ -412,7 +412,7 @@ namespace CamelotFramework {
 		RenderWindow::destroy_internal();
 	}
 
-	void Win32Window::setFullscreen(bool fullScreen, unsigned int width, unsigned int height)
+	void Win32Window::setFullscreen(bool fullScreen, UINT32 width, UINT32 height)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
@@ -500,7 +500,7 @@ namespace CamelotFramework {
 
 				// calculate overall dimensions for requested client area
 				unsigned int winWidth, winHeight;
-				adjustWindow(width, height, &winWidth, &winHeight);
+				_adjustWindow(width, height, &winWidth, &winHeight);
 
 				// deal with centreing when switching down to smaller resolution
 
@@ -546,7 +546,7 @@ namespace CamelotFramework {
 		return mClosed;
 	}
 
-	void Win32Window::reposition(int left, int top)
+	void Win32Window::reposition(INT32 left, INT32 top)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
@@ -557,7 +557,7 @@ namespace CamelotFramework {
 		}
 	}
 
-	void Win32Window::resize(unsigned int width, unsigned int height)
+	void Win32Window::resize(UINT32 width, UINT32 height)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
@@ -655,7 +655,7 @@ namespace CamelotFramework {
 		} else if( name == "WINDOW" )
 		{
 			HWND *pHwnd = (HWND*)pData;
-			*pHwnd = getWindowHandle();
+			*pHwnd = _getWindowHandle();
 			return;
 		} 
 	}
@@ -732,7 +732,7 @@ namespace CamelotFramework {
 		RenderWindow::_windowMovedOrResized();
 	}
 
-	void Win32Window::adjustWindow(unsigned int clientWidth, unsigned int clientHeight, 
+	void Win32Window::_adjustWindow(unsigned int clientWidth, unsigned int clientHeight, 
 		unsigned int* winWidth, unsigned int* winHeight)
 	{
 		// NB only call this for non full screen