Browse Source

Refactored OpenGL RenderWindow

Marko Pintera 12 years ago
parent
commit
e4a0187267

+ 2 - 2
CamelotClient/CamelotClient.cpp

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

+ 4 - 0
CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp

@@ -435,6 +435,8 @@ namespace CamelotFramework
 
 	void D3D9RenderWindow::swapBuffers()
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
 		if (mDeviceValid)
 			mDevice->present(this);		
 	}
@@ -453,6 +455,8 @@ namespace CamelotFramework
 
 	void D3D9RenderWindow::copyContentsToMemory(const PixelData &dst, FrameBuffer buffer)
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
 		mDevice->copyContentsToMemory(this, dst, buffer);
 	}
 

+ 61 - 23
CamelotGLRenderer/Include/CmWin32Window.h

@@ -26,46 +26,86 @@ THE SOFTWARE.
 -----------------------------------------------------------------------------
 */
 
-#ifndef __Win32Window_H__
-#define __Win32Window_H__
+#pragma once
 
 #include "CmWin32Prerequisites.h"
 #include "CmRenderWindow.h"
 
-namespace CamelotFramework {
+namespace CamelotFramework 
+{
     class CM_RSGL_EXPORT Win32Window : public RenderWindow
     {
     public:
         ~Win32Window();
 
-	   void setFullscreen(bool fullScreen, unsigned int width, unsigned int height);
-		bool isActive(void) const;
-        bool isVisible() const;
-        bool isClosed(void) const;
-        void reposition(int left, int top);
-        void resize(unsigned int width, unsigned int height);
+		/**
+		 * @copydoc RenderWindow::setFullscreen
+		 */
+		void setFullscreen(bool fullScreen, unsigned int width, unsigned int height);
+
+		/**
+		 * @copydoc RenderWindow::isActive
+		 */
+		bool isActive() const;
 
-		/** Overridden - see RenderTarget. */
-		virtual void copyContentsToMemory(const PixelData &dst, FrameBuffer buffer);
+		/**
+		 * @copydoc RenderWindow::isVisible
+		 */
+		bool isVisible() const;
+
+		/**
+		 * @copydoc RenderWindow::isClosed
+		 */
+		bool isClosed() const;
+
+		/**
+		 * @copydoc RenderWindow::reposition
+		 */
+		void reposition(int left, int top);
+
+		/**
+		 * @copydoc RenderWindow::resize
+		 */
+		void resize(unsigned int width, unsigned int height);
+
+		/**
+		 * @copydoc RenderWindow::copyContentsToMemory
+		 */
+		void copyContentsToMemory(const PixelData &dst, FrameBuffer buffer);
 
+		/**
+		 * @copydoc RenderWindow::swapBuffers
+		 */
 		void swapBuffers();
 
+		/**
+		 * @copydoc RenderWindow::requiresTextureFlipping
+		 */
 		bool requiresTextureFlipping() const { return false; }
 
-		HWND getWindowHandle() const { return mHWnd; }
-		HDC getHDC() const { return mHDC; }
-		
-		// Method for dealing with resize / move & 3d library
-		virtual void _windowMovedOrResized(void);
+		/**
+		 * @copydoc RenderWindow::_windowMovedOrResized
+		 */
+		void _windowMovedOrResized(void);
 
+		/**
+		 * @copydoc RenderWindow::screenToWindowPos
+		 */
 		Int2 screenToWindowPos(const Int2& screenPos) const;
 
-		void getCustomAttribute( const String& name, void* pData ) const;
+		/**
+		 * @copydoc RenderWindow::getCustomAttribute
+		 */
+		void getCustomAttribute(const String& name, void* pData) const;
 
-        /** Used to set the active state of the render target.
-        */
-        virtual void setActive( bool state );
+		/**
+		 * @copydoc RenderWindow::setActive
+		 */
+		virtual void setActive( bool state );
 
+		HWND getWindowHandle() const { return mHWnd; }
+		HDC getHDC() const { return mHDC; }
+		
 		void adjustWindow(unsigned int clientWidth, unsigned int clientHeight, 
 			unsigned int* winWidth, unsigned int* winHeight);
 
@@ -98,6 +138,4 @@ namespace CamelotFramework {
 		 */
 		void destroy_internal();
     };
-}
-
-#endif
+}

+ 68 - 55
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -31,6 +31,7 @@ THE SOFTWARE.
 #endif
 #include "CmWin32Window.h"
 #include "CmRenderSystem.h"
+#include "CmCoreThread.h"
 #include "CmException.h"
 #include "CmWin32GLSupport.h"
 #include "CmWin32Context.h"
@@ -411,38 +412,10 @@ namespace CamelotFramework {
 		RenderWindow::destroy_internal();
 	}
 
-	void Win32Window::adjustWindow(unsigned int clientWidth, unsigned int clientHeight, 
-		unsigned int* winWidth, unsigned int* winHeight)
-	{
-		// NB only call this for non full screen
-		RECT rc;
-		SetRect(&rc, 0, 0, clientWidth, clientHeight);
-		AdjustWindowRect(&rc, WS_VISIBLE | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW, false);
-		*winWidth = rc.right - rc.left;
-		*winHeight = rc.bottom - rc.top;
-
-		// adjust to monitor
-		HMONITOR hMonitor = MonitorFromWindow(mHWnd, MONITOR_DEFAULTTONEAREST);
-
-		// Get monitor info	
-		MONITORINFO monitorInfo;
-
-		memset(&monitorInfo, 0, sizeof(MONITORINFO));
-		monitorInfo.cbSize = sizeof(MONITORINFO);
-		GetMonitorInfo(hMonitor, &monitorInfo);
-
-		LONG maxW = monitorInfo.rcWork.right  - monitorInfo.rcWork.left;
-		LONG maxH = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top;
-
-		if (*winWidth > (unsigned int)maxW)
-			*winWidth = maxW;
-		if (*winHeight > (unsigned int)maxH)
-			*winHeight = maxH;
-
-	}
-
 	void Win32Window::setFullscreen(bool fullScreen, unsigned int width, unsigned int height)
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
 		if (mIsFullScreen != fullScreen || width != mWidth || height != mHeight)
 		{
 			mIsFullScreen = fullScreen;
@@ -575,6 +548,8 @@ namespace CamelotFramework {
 
 	void Win32Window::reposition(int left, int top)
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
 		if (mHWnd && !mIsFullScreen)
 		{
 			SetWindowPos(mHWnd, 0, left, top, 0, 0,
@@ -584,6 +559,8 @@ namespace CamelotFramework {
 
 	void Win32Window::resize(unsigned int width, unsigned int height)
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
 		if (mHWnd && !mIsFullScreen)
 		{
 			RECT rc = { 0, 0, width, height };
@@ -595,37 +572,19 @@ namespace CamelotFramework {
 		}
 	}
 
-	void Win32Window::_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);
-
-		if (mWidth == rc.right && mHeight == rc.bottom)
-			return;
-
-		mWidth = rc.right - rc.left;
-		mHeight = rc.bottom - rc.top;
-
-		RenderWindow::_windowMovedOrResized();
-	}
-
 	void Win32Window::swapBuffers()
 	{
-	  if (!mIsExternalGLControl) {
-	  	SwapBuffers(mHDC);
-	  }
+		THROW_IF_NOT_CORE_THREAD;
+
+		if (!mIsExternalGLControl) {
+			SwapBuffers(mHDC);
+		}
 	}
 
 	void Win32Window::copyContentsToMemory(const PixelData &dst, FrameBuffer buffer)
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
 		if ((dst.getLeft() < 0) || (dst.getRight() > mWidth) ||
 			(dst.getTop() < 0) || (dst.getBottom() > mHeight) ||
 			(dst.getFront() != 0) || (dst.getBack() != 1))
@@ -703,6 +662,8 @@ namespace CamelotFramework {
 
 	void Win32Window::setActive( bool state )
 	{	
+		THROW_IF_NOT_CORE_THREAD;
+
 		if (mDeviceName != NULL && state == false)
 		{
 			HWND hActiveWindow = GetActiveWindow();
@@ -748,4 +709,56 @@ namespace CamelotFramework {
 			}
 		}
 	}
+
+	void Win32Window::_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);
+
+		if (mWidth == rc.right && mHeight == rc.bottom)
+			return;
+
+		mWidth = rc.right - rc.left;
+		mHeight = rc.bottom - rc.top;
+
+		RenderWindow::_windowMovedOrResized();
+	}
+
+	void Win32Window::adjustWindow(unsigned int clientWidth, unsigned int clientHeight, 
+		unsigned int* winWidth, unsigned int* winHeight)
+	{
+		// NB only call this for non full screen
+		RECT rc;
+		SetRect(&rc, 0, 0, clientWidth, clientHeight);
+		AdjustWindowRect(&rc, WS_VISIBLE | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW, false);
+		*winWidth = rc.right - rc.left;
+		*winHeight = rc.bottom - rc.top;
+
+		// adjust to monitor
+		HMONITOR hMonitor = MonitorFromWindow(mHWnd, MONITOR_DEFAULTTONEAREST);
+
+		// Get monitor info	
+		MONITORINFO monitorInfo;
+
+		memset(&monitorInfo, 0, sizeof(MONITORINFO));
+		monitorInfo.cbSize = sizeof(MONITORINFO);
+		GetMonitorInfo(hMonitor, &monitorInfo);
+
+		LONG maxW = monitorInfo.rcWork.right  - monitorInfo.rcWork.left;
+		LONG maxH = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top;
+
+		if (*winWidth > (unsigned int)maxW)
+			*winWidth = maxW;
+		if (*winHeight > (unsigned int)maxH)
+			*winHeight = maxH;
+
+	}
 }