Просмотр исходного кода

Refactored D3D9 RenderWindow a bit

Marko Pintera 12 лет назад
Родитель
Сommit
3856bcb79d

+ 1 - 0
BansheeEngine.sln

@@ -38,6 +38,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CamelotGLRenderSystem", "Ca
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1D081E5A-615A-4C06-B2DF-0D8D9390DE02}"
 	ProjectSection(SolutionItems) = preProject
+		CSharpWrap.txt = CSharpWrap.txt
 		Dependencies.txt = Dependencies.txt
 		Notes.txt = Notes.txt
 		TODO.txt = TODO.txt

+ 47 - 0
CSharpWrap.txt

@@ -0,0 +1,47 @@
+Classes that need C# wrappers:
+Math (Instead of a wrapper create actual C# classes, but which map 1-1 with C++ code so we can move them through C++/C# boundaries):
+ -Vector2
+ -Vector3
+ -Vector4
+ -Matrix3
+ -Matrix4
+ -Quaternion
+ -Rect
+ -Int2
+ -Color
+
+Resources:
+ - Mesh
+ - Texture
+ - Font
+ - Material
+  - GpuProgram
+  - Technique
+  - Shader
+  - DepthStencil/Blend/Rasterizer/Sampler state
+
+Core objects:
+ - RenderTarget
+  - RenderWindow
+  - RenderTexture
+  - MultiRenderTexture
+ - SceneObject
+ - Component
+  - plus specific components Camera, Renderable, maybe others
+  - (later ofc ability to derive custom C# components)
+
+GUI:
+ - EditorWindow
+ - GUIWidget
+ - GUILabel/GUIButton/GUIToggle/GUIInputBox/GUITexture...
+ - GUILayoutX/GUILayoutY/GUILayoutOptions
+ - GUISkin/GUIElementStyle
+
+Systems:
+ - Resources
+ - Importer
+ - Application (startUp/shutDown)
+ - Cursor
+ - Debug
+ - Input
+ - Time

+ 2 - 2
CamelotClient/CamelotClient.cpp

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

+ 1 - 1
CamelotClient/CmEditorWindow.cpp

@@ -95,7 +95,7 @@ namespace BansheeEditor
 		//titleBarBackgroundArea->getLayout().addSpace(1);
 		
 		//mRenderWindow->resize(300, 250);
-		mRenderWindow->setVisible(false);
+		//mRenderWindow->setVisible(false);
 	}
 
 	EditorWindow::~EditorWindow()

+ 55 - 58
CamelotCore/Include/CmRenderWindow.h

@@ -107,80 +107,78 @@ namespace CamelotFramework
     public:
 		virtual ~RenderWindow();
 
-		/**
-		 * @copydoc RenderTarget::isWindow.
-		 */
-		bool isWindow() const { return true; }
-
-		/** Alter fullscreen mode options. 
-		@note Nothing will happen unless the settings here are different from the
-			current settings.
-		@param fullScreen Whether to use fullscreen mode or not. 
-		@param width The new width to use
-		@param height The new height to use
+		/** 
+			@brief Core method. Alter fullscreen mode options.
 		*/
 		virtual void setFullscreen(bool fullScreen, unsigned int width, unsigned int height)
                 { (void)fullScreen; (void)width; (void)height; }
 
-        /** Alter the size of the window.
-        */
-        virtual void resize(unsigned int width, unsigned int height) = 0;
+        /**
+         * @brief	Core method. Set the visibility state.
+         */
+        virtual void setVisible(bool visible);
 
-        /** Notify that the window has been resized
-        @remarks
-            You don't need to call this unless you created the window externally.
-        */
-        virtual void windowMovedOrResized();
+        /**
+         * @brief	Core method. Alter the size of the window.
+         */
+        virtual void resize(UINT32 width, UINT32 height) = 0;
 
-        /** Reposition the window.
-        */
-        virtual void reposition(int left, int top) = 0;
+        /**
+         * @brief	Core method. Reposition the window.
+         */
+        virtual void reposition(INT32 left, INT32 top) = 0;
 
-        /** Indicates whether the window is visible (not minimized or obscured)
-        */
-        virtual bool isVisible(void) const { return true; }
+		/**
+		 * @copydoc RenderTarget::isWindow.
+		 */
+		bool isWindow() const { return true; }
 
-        /** Set the visibility state
-        */
-        virtual void setVisible(bool visible)
-        { (void)visible; }
+        /**
+         * @brief	Indicates whether the window is visible (not minimized or obscured).
+         */
+        virtual bool isVisible(void) const { return true; }
 
-        /** Overridden from RenderTarget, flags invisible windows as inactive
-        */
-        virtual bool isActive(void) const { return mActive && isVisible(); }
+        /** 
+        * @copydoc RenderTarget::isActive
+		*/
+        virtual bool isActive() const { return mActive && isVisible(); }
 
-        /** Indicates whether the window has been closed by the user.
-        */
-        virtual bool isClosed(void) const = 0;
+        /** 
+        * @brief Indicates whether the window has been closed by the user.
+		*/
+        virtual bool isClosed() const = 0;
         
-        /** Returns true if window is running in fullscreen mode.
-        */
-        virtual bool isFullScreen(void) const;
+        /** 
+        * @brief Returns true if window is running in fullscreen mode.
+		*/
+        virtual bool isFullScreen() const;
+
+		/**
+		 * @brief	Indicates whether the window currently has keyboard focus.
+		 */
+		bool hasFocus() const { return mHasFocus; }
 
-        /** Overloaded version of getMetrics from RenderTarget, including extra details
-            specific to windowing systems.
+        /**   
+        * @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);
 
-		/// Override since windows don't usually have alpha
-		PixelFormat suggestPixelFormat() const { return PF_BYTE_RGB; }
-
-        /** Returns true if the window will automatically de-activate itself when it loses focus.
-        */
-        bool isDeactivatedOnFocusChange() const;
+		/**
+         * @brief	Internal method. Core method. Called when window is moved or resized.
+         */
+        virtual void _windowMovedOrResized();
 
-        /** Indicates whether the window will automatically deactivate itself when it loses focus.
-          * \param deactivate a value of 'true' will cause the window to deactivate itself when it loses focus.  'false' will allow it to continue to render even when window focus is lost.
-          * \note 'true' is the default behavior.
-          */
-        void setDeactivateOnFocusChange(bool deactivate);
+		/**
+         * @brief	Internal method. Core method. Called when window has received focus.
+         */
+		virtual void _windowFocusReceived();
 
 		/**
-		 * @brief	Internal method. Called when window gets or loses focus.
-		 */
-		void _setHasFocus(bool focus);
-		bool hasFocus() const { return mHasFocus; }
+         * @brief	Internal method. Core method. Called when window has lost focus.
+         */
+		virtual void _windowFocusLost();
 
 		virtual Int2 screenToWindowPos(const Int2& screenPos) const = 0;
 
@@ -197,9 +195,8 @@ namespace CamelotFramework
         
 	protected:
 		bool mIsFullScreen;
-		bool mAutoDeactivatedOnFocusChange;
-		int mLeft;
-		int mTop;
+		INT32 mLeft;
+		INT32 mTop;
 		bool mHasFocus;
 
 		RENDER_WINDOW_DESC mDesc;

+ 1 - 1
CamelotCore/Include/CmRenderWindowManager.h

@@ -40,7 +40,7 @@ namespace CamelotFramework
 		virtual RenderWindowPtr createImpl(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow) = 0;
 
 		void windowDestroyed(RenderWindow* window);
-		void windowGotFocus(RenderWindow* window);
+		void windowFocusReceived(RenderWindow* window);
 		void windowMovedOrResized(RenderWindow* window);
 	};
 }

+ 22 - 19
CamelotCore/Source/CmRenderWindow.cpp

@@ -26,6 +26,7 @@ THE SOFTWARE.
 -----------------------------------------------------------------------------
 */
 #include "CmRenderWindow.h"
+#include "CmCoreThread.h"
 #include "CmRenderWindowManager.h"
 #include "CmViewport.h"
 
@@ -37,7 +38,7 @@ namespace CamelotFramework
 		, mDesc(desc)
 		, mHasFocus(false)
     {
-        mAutoDeactivatedOnFocusChange = false;
+
     }
 
 	RenderWindow::~RenderWindow() 
@@ -45,7 +46,6 @@ namespace CamelotFramework
 		
 	}
 
-    //-----------------------------------------------------------------------
     void RenderWindow::getMetrics(unsigned int& width, unsigned int& height, unsigned int& colourDepth,
 		int& left, int& top)
     {
@@ -55,38 +55,41 @@ namespace CamelotFramework
         left = mLeft;
         top = mTop;
     }
-    //-----------------------------------------------------------------------
-    bool RenderWindow::isFullScreen(void) const
-    {
-        return mIsFullScreen;
-    }
 
-    bool RenderWindow::isDeactivatedOnFocusChange() const
-    {
-        return mAutoDeactivatedOnFocusChange;
-    }
+	void RenderWindow::setVisible(bool visible)
+	{
+		THROW_IF_NOT_CORE_THREAD;
+	}
 
-    void RenderWindow::setDeactivateOnFocusChange(bool deactivate)
+    bool RenderWindow::isFullScreen(void) const
     {
-        mAutoDeactivatedOnFocusChange = deactivate;
+        return mIsFullScreen;
     }
 
-	void RenderWindow::windowMovedOrResized()
+	void RenderWindow::_windowMovedOrResized()
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
 		if(!onMovedOrResized.empty())
 			onMovedOrResized(this);
 
 		RenderWindowManager::instance().windowMovedOrResized(this);
 	}
 
-	void RenderWindow::_setHasFocus(bool focus)
+	void RenderWindow::_windowFocusReceived()
 	{
-		// TODO: Core thread only
+		THROW_IF_NOT_CORE_THREAD;
 
-		mHasFocus = focus; 
+		mHasFocus = true;
+
+		RenderWindowManager::instance().windowFocusReceived(this);
+	}
+
+	void RenderWindow::_windowFocusLost()
+	{
+		THROW_IF_NOT_CORE_THREAD;
 
-		if(mHasFocus)
-			RenderWindowManager::instance().windowGotFocus(this);
+		mHasFocus = false;
 	}
 
 	void RenderWindow::destroy()

+ 1 - 5
CamelotCore/Source/CmRenderWindowManager.cpp

@@ -37,7 +37,7 @@ namespace CamelotFramework
 		}
 	}
 
-	void RenderWindowManager::windowGotFocus(RenderWindow* window)
+	void RenderWindowManager::windowFocusReceived(RenderWindow* window)
 	{
 		CM_LOCK_MUTEX(mWindowMutex);
 		mNewWindowInFocus = window;
@@ -70,16 +70,12 @@ namespace CamelotFramework
 		{
 			if(mWindowInFocus != nullptr)
 			{
-				mWindowInFocus->_setHasFocus(false);
-
 				if(!onFocusLost.empty())
 					onFocusLost(*mWindowInFocus);
 			}
 
 			if(newWinInFocus != nullptr)
 			{
-				newWinInFocus->_setHasFocus(true);
-
 				if(!onFocusGained.empty())
 					onFocusGained(*newWinInFocus);
 			}

+ 9 - 45
CamelotCore/Source/CmWindowEventUtilities.cpp

@@ -137,20 +137,15 @@ LRESULT CALLBACK WindowEventUtilities::_WndProc(HWND hWnd, UINT uMsg, WPARAM wPa
         bool active = (LOWORD(wParam) != WA_INACTIVE);
         if( active )
         {
-		    win->setActive( true );
+		    win->setActive(true);
 
 			if(!win->hasFocus())
-				win->_setHasFocus(true);
+				win->_windowFocusReceived();
         }
         else
         {
-            if( win->isDeactivatedOnFocusChange() )
-            {
-    		    win->setActive( false );
-            }
-
 			if(win->hasFocus())
-				win->_setHasFocus(false);
+				win->_windowFocusLost();
         }
 
 		break;
@@ -186,13 +181,13 @@ LRESULT CALLBACK WindowEventUtilities::_WndProc(HWND hWnd, UINT uMsg, WPARAM wPa
 	case WM_EXITSIZEMOVE:
 		break;
 	case WM_MOVE:
-		win->windowMovedOrResized();
+		win->_windowMovedOrResized();
 		break;
 	case WM_DISPLAYCHANGE:
-		win->windowMovedOrResized();
+		win->_windowMovedOrResized();
 		break;
 	case WM_SIZE:
-		win->windowMovedOrResized();
+		win->_windowMovedOrResized();
 		break;
 	case WM_SETCURSOR:
 		if(Cursor::isHidden())
@@ -311,7 +306,7 @@ void GLXProc( RenderWindow *win, const XEvent &event )
 		unsigned int oldWidth, oldHeight, oldDepth;
 		int oldLeft, oldTop;
 		win->getMetrics(oldWidth, oldHeight, oldDepth, oldLeft, oldTop);
-		win->windowMovedOrResized();
+		win->_windowMovedOrResized();
 
 		unsigned int newWidth, newHeight, newDepth;
 		int newLeft, newTop;
@@ -361,11 +356,6 @@ OSStatus WindowEventUtilities::_CarbonWindowHandler(EventHandlerCallRef nextHand
     RenderWindow* curWindow = (RenderWindow*)wnd;
     if(!curWindow) return eventNotHandledErr;
     
-    //Iterator of all listeners registered to this RenderWindow
-	WindowEventListeners::iterator index,
-        start = _msListeners.lower_bound(curWindow),
-        end = _msListeners.upper_bound(curWindow);
-    
     // We only get called if a window event happens
     UInt32 eventKind = GetEventKind( event );
 
@@ -373,51 +363,28 @@ OSStatus WindowEventUtilities::_CarbonWindowHandler(EventHandlerCallRef nextHand
     {
         case kEventWindowActivated:
             curWindow->setActive( true );
-            for( ; start != end; ++start )
-                (start->second)->windowFocusChange(curWindow);
             break;
         case kEventWindowDeactivated:
-            if( curWindow->isDeactivatedOnFocusChange() )
-            {
-                curWindow->setActive( false );
-            }
-
-            for( ; start != end; ++start )
-                (start->second)->windowFocusChange(curWindow);
-
             break;
         case kEventWindowShown:
         case kEventWindowExpanded:
             curWindow->setActive( true );
             curWindow->setVisible( true );
-            for( ; start != end; ++start )
-                (start->second)->windowFocusChange(curWindow);
             break;
         case kEventWindowHidden:
         case kEventWindowCollapsed:
             curWindow->setActive( false );
             curWindow->setVisible( false );
-            for( ; start != end; ++start )
-                (start->second)->windowFocusChange(curWindow);
             break;            
         case kEventWindowDragCompleted:
-            curWindow->windowMovedOrResized();
-            for( ; start != end; ++start )
-				(start->second)->windowMoved(curWindow);
+            curWindow->_windowMovedOrResized();
             break;
         case kEventWindowBoundsChanged:
-            curWindow->windowMovedOrResized();
-            for( ; start != end; ++start )
-				(start->second)->windowResized(curWindow);
+            curWindow->_windowMovedOrResized();
             break;
 		case kEventWindowClose:
 		{
 			bool close = true;
-			for( ; start != end; ++start )
-			{
-				if (!(start->second)->windowClosing(curWindow))
-					close = false;
-			}
 			if (close)
 				// This will cause event handling to continue on to the standard handler, which calls
 				// DisposeWindow(), which leads to the 'kEventWindowClosed' event
@@ -425,9 +392,6 @@ OSStatus WindowEventUtilities::_CarbonWindowHandler(EventHandlerCallRef nextHand
 			break;
 		}
         case kEventWindowClosed:
-
-            for( ; start != end; ++start )
-				(start->second)->windowClosed(curWindow);
             break;
         default:
             status = eventNotHandledErr;

+ 1 - 1
CamelotD3D11RenderSystem/Include/CmD3D11RenderWindow.h

@@ -20,7 +20,7 @@ namespace CamelotFramework
 		void copyContentsToMemory(const PixelData &dst, FrameBuffer buffer);
 		void swapBuffers();
 
-		void windowMovedOrResized();
+		void _windowMovedOrResized();
 
 		bool isClosed() const									{ return mClosed; }
 		bool isHidden() const									{ return mHidden; }

+ 2 - 2
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -318,7 +318,7 @@ namespace CamelotFramework
 		}
 	}
 
-	void D3D11RenderWindow::windowMovedOrResized()
+	void D3D11RenderWindow::_windowMovedOrResized()
 	{
 		if (!mHWnd || IsIconic(mHWnd))
 			return;
@@ -343,7 +343,7 @@ namespace CamelotFramework
 
 		_resizeSwapChainBuffers(width, height);
 
-		RenderWindow::windowMovedOrResized();
+		RenderWindow::_windowMovedOrResized();
 	}
 
 	void D3D11RenderWindow::setActive(bool state)

+ 94 - 44
CamelotD3D9Renderer/Include/CmD3D9RenderWindow.h

@@ -25,8 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 -----------------------------------------------------------------------------
 */
-#ifndef __D3D9RENDERWINDOW_H__
-#define __D3D9RENDERWINDOW_H__
+#pragma once
 
 #include "CmD3D9Prerequisites.h"
 #include "CmRenderWindow.h"
@@ -37,56 +36,109 @@ namespace CamelotFramework
 	class CM_D3D9_EXPORT D3D9RenderWindow : public RenderWindow
 	{
 	public:
-		~D3D9RenderWindow					();
+		~D3D9RenderWindow();
 		
-		void				setFullscreen		(bool fullScreen, unsigned int width, unsigned int height);
-		bool				isActive			() const;
-		bool				isVisible			() const;
-		bool 				isClosed			() const { return mClosed; }
-		bool				isVSync				() const { return mVSync; }
-		void 				reposition			(int left, int top);
-		void 				resize				(unsigned int width, unsigned int height);
-		HWND 				getWindowHandle		() const { return mHWnd; }				
-		IDirect3DDevice9*	getD3D9Device		() const;
-		D3D9Device*			getDevice			() const;
-		void				setDevice			(D3D9Device* device);
-
-		void				getCustomAttribute	(const String& name, void* pData) const;
-		
-		/** Overridden - see RenderTarget.
-		*/
-		void				copyContentsToMemory	(const PixelData &dst, FrameBuffer buffer);
-		bool				requiresTextureFlipping	() const { return false; }
+		/**
+		 * @copydoc RenderWindow::setFullscreen
+		 */
+		void setFullscreen(bool fullScreen, unsigned int width, unsigned int height);
 
-		void				swapBuffers();
+		/**
+		 * @copydoc RenderWindow::isActive
+		 */
+		bool isActive() const;
+
+		/**
+		 * @copydoc RenderWindow::isVisible
+		 */
+		bool isVisible() const;
 
-		Int2				screenToWindowPos(const Int2& screenPos) const;
+		/**
+		 * @copydoc RenderWindow::isClosed
+		 */
+		bool isClosed() const { return mClosed; }
 
-		// Method for dealing with resize / move & 3d library
-		void				windowMovedOrResized	();
-	
-		/// Build the presentation parameters used with this window
-		void				buildPresentParameters	(D3DPRESENT_PARAMETERS* presentParams) const;
-		
-		/// Accessor for render surface
-		IDirect3DSurface9* getRenderSurface() const;
+		/**
+		 * @copydoc RenderWindow::isVSync
+		 */
+		bool isVSync() const { return mVSync; }
+
+		/**
+		 * @copydoc RenderWindow::reposition
+		 */
+		void reposition(int left, int top);
+
+		/**
+		 * @copydoc RenderWindow::resize
+		 */
+		void resize(unsigned int width, unsigned int height);
+
+		/**
+		 * @copydoc RenderWindow::getCustomAttribute
+		 */
+		void getCustomAttribute(const String& name, void* pData) const;
+
+		/**
+		 * @copydoc RenderWindow::copyContentsToMemory
+		 */
+		void copyContentsToMemory(const PixelData &dst, FrameBuffer buffer);
+
+		/**
+		 * @copydoc RenderWindow::requiresTextureFlipping
+		 */
+		bool requiresTextureFlipping() const { return false; }
+
+		/**
+		 * @copydoc RenderWindow::swapBuffers
+		 */
+		void swapBuffers();
+
+		/**
+		 * @copydoc RenderWindow::screenToWindowPos
+		 */
+		Int2 screenToWindowPos(const Int2& screenPos) const;
+
+		/**
+		 * @copydoc RenderWindow::_windowMovedOrResized
+		 */
+		void				_windowMovedOrResized	();
+
+		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;
 
-		/// Are we in the middle of switching between fullscreen and windowed
+		/**
+		 * @brief	Accessor for render surface.
+		 */
+		IDirect3DSurface9* _getRenderSurface() const;
+
+		/**
+		 * @brief	Are we in the middle of switching between fullscreen and windowed.
+		 */
 		bool _getSwitchingFullscreen() const;
-		
-		/// Indicate that fullscreen / windowed switching has finished
+
+		/**
+		 * @brief	Indicate that fullscreen / windowed switching has finished.
+		 */
 		void _finishSwitchingFullscreen();
 	
-		/// Returns true if this window use depth buffer.
-		bool isDepthBuffered() const;
-
-		/// Returns true if this window should use NV perf hud adapter.
-		bool isNvPerfHUDEnable() const;
+		/**
+		 * @brief	Returns true if this window use depth buffer.
+		 */
+		bool _isDepthBuffered() const;
 
-		/** Validate the device for this window. */
+		/**
+		 * @brief	Validate the device for this window.
+		 */
 		bool _validateDevice();
 
-		void adjustWindow(unsigned int clientWidth, unsigned int clientHeight, 
+		void _adjustWindow(unsigned int clientWidth, unsigned int clientHeight, 
 			DWORD style, unsigned int* winWidth, unsigned int* winHeight);
 
 	protected:
@@ -119,12 +171,10 @@ namespace CamelotFramework
 		UINT						mDisplayFrequency;		// Display frequency.
 		bool						mVSync;					// Use vertical sync or not.
 		unsigned int				mVSyncInterval;		
-		bool						mUseNVPerfHUD;			// Use NV Perf HUD.
 		DWORD						mStyle;					// Window style currently used for this window.
 		bool						mIsDepthBuffered;
 		// Desired width / height after resizing
 		unsigned int mDesiredWidth;
 		unsigned int mDesiredHeight;
 	};
-}
-#endif
+}

+ 11 - 11
CamelotD3D9Renderer/Source/CmD3D9Device.cpp

@@ -103,13 +103,13 @@ namespace CamelotFramework
 		{		
 			// The focus window in which the d3d9 device created on is detached.
 			// resources must be acquired again.
-			if (mFocusWindow == renderWindow->getWindowHandle())
+			if (mFocusWindow == renderWindow->_getWindowHandle())
 			{
 				mFocusWindow = NULL;				
 			}
 
 			// Case this is the shared focus window.
-			if (renderWindow->getWindowHandle() == msSharedFocusWindow)			
+			if (renderWindow->_getWindowHandle() == msSharedFocusWindow)			
 				setSharedWindowHandle(NULL);		
 			
 			RenderWindowResources* renderWindowResources = it->second;
@@ -279,7 +279,7 @@ namespace CamelotFramework
 
 		if (it != mMapRenderWindowToResoruces.end())
 		{	
-			if (it->first->getWindowHandle() == msSharedFocusWindow)
+			if (it->first->_getWindowHandle() == msSharedFocusWindow)
 				setSharedWindowHandle(NULL);
 
 			if(it->second != nullptr)
@@ -487,14 +487,14 @@ namespace CamelotFramework
 				RenderWindowResources* renderWindowResources = it->second;
 
 				// Ask the render window to build it's own parameters.
-				renderWindow->buildPresentParameters(&renderWindowResources->presentParameters);
+				renderWindow->_buildPresentParameters(&renderWindowResources->presentParameters);
 				
 
 				// Update shared focus window handle.
 				if (renderWindow->isFullScreen() && 
 					renderWindowResources->presentParametersIndex == 0 &&
 					msSharedFocusWindow == NULL)
-					setSharedWindowHandle(renderWindow->getWindowHandle());					
+					setSharedWindowHandle(renderWindow->_getWindowHandle());					
 
 				// This is the primary window or a full screen window that is part of multi head device.
 				if (renderWindowResources->presentParametersIndex == 0 ||
@@ -604,7 +604,7 @@ namespace CamelotFramework
 		if (msSharedFocusWindow != NULL)
 			mFocusWindow = msSharedFocusWindow;
 		else
-			mFocusWindow = primaryRenderWindow->getWindowHandle();		
+			mFocusWindow = primaryRenderWindow->_getWindowHandle();		
 
 		IDirect3D9* pD3D9 = D3D9RenderSystem::getDirect3D9();
 		HRESULT     hr;
@@ -764,7 +764,7 @@ namespace CamelotFramework
 	{
 		// Focus window changed -> device should be re-acquired.
 		if ((msSharedFocusWindow != NULL && mCreationParams.hFocusWindow != msSharedFocusWindow) ||
-			(msSharedFocusWindow == NULL && mCreationParams.hFocusWindow != getPrimaryWindow()->getWindowHandle()))
+			(msSharedFocusWindow == NULL && mCreationParams.hFocusWindow != getPrimaryWindow()->_getWindowHandle()))
 		{
 			// Lock access to rendering device.
 			D3D9RenderSystem::getResourceManager()->lockDeviceAccess();
@@ -873,7 +873,7 @@ namespace CamelotFramework
 		HMONITOR	hRenderWindowMonitor = NULL;
 
 		// Find the monitor this render window belongs to.
-		hRenderWindowMonitor = MonitorFromWindow(renderWindow->getWindowHandle(), MONITOR_DEFAULTTONULL);
+		hRenderWindowMonitor = MonitorFromWindow(renderWindow->_getWindowHandle(), MONITOR_DEFAULTTONULL);
 
 		// This window doesn't intersect with any of the display monitor
 		if (hRenderWindowMonitor == NULL)		
@@ -990,7 +990,7 @@ namespace CamelotFramework
 
 		// Additional swap chains need their own depth buffer
 		// to support resizing them
-		if (renderWindow->isDepthBuffered()) 
+		if (renderWindow->_isDepthBuffered()) 
 		{
 			// if multihead is enabled, depth buffer can be created automatically for 
 			// all the adapters. if multihead is not enabled, depth buffer is just
@@ -1102,7 +1102,7 @@ namespace CamelotFramework
 				it = mMapRenderWindowToResoruces.begin();
 				while (it != mMapRenderWindowToResoruces.end())			
 				{
-					if (it->first->getWindowHandle() == mCreationParams.hFocusWindow)
+					if (it->first->_getWindowHandle() == mCreationParams.hFocusWindow)
 					{
 						deviceFocusWindow = it->first;
 						it->second->presentParametersIndex = nextPresParamIndex;
@@ -1217,7 +1217,7 @@ namespace CamelotFramework
 				POINT point;
 				point.x = srcRect.left;
 				point.y = srcRect.top;
-				ClientToScreen(renderWindow->getWindowHandle(), &point);
+				ClientToScreen(renderWindow->_getWindowHandle(), &point);
 				srcRect.top = point.y;
 				srcRect.left = point.x;
 				srcRect.bottom += point.y;

+ 3 - 26
CamelotD3D9Renderer/Source/CmD3D9DeviceManager.cpp

@@ -121,7 +121,7 @@ namespace CamelotFramework
 		D3D9Device* renderDevice;
 
 		// Detach from previous device.
-		renderDevice = renderWindow->getDevice();		
+		renderDevice = renderWindow->_getDevice();		
 		if (renderDevice != NULL)		
 			renderDevice->detachRenderWindow(renderWindow);						
 
@@ -135,7 +135,7 @@ namespace CamelotFramework
 		{
 			D3D9RenderWindow* currWindow = renderWindowsGroup[i];
 
-			currWindow->setDevice(renderDevice);
+			currWindow->_setDevice(renderDevice);
 			renderDevice->attachRenderWindow(currWindow);
 			renderDevice->setAdapterOrdinalIndex(currWindow, i);
 		}
@@ -161,29 +161,6 @@ namespace CamelotFramework
 		// Default group includes at least the given render window.
 		renderWindowsGroup.push_back(renderWindow);
 
-		// Case we use nvidia performance HUD, override the device settings. 
-		if (renderWindow->isNvPerfHUDEnable())
-		{
-			// Look for 'NVIDIA NVPerfHUD' adapter (<= v4)
-			// or 'NVIDIA PerfHUD' (v5)
-			// If it is present, override default settings
-			for (UINT adapter=0; adapter < direct3D9->GetAdapterCount(); ++adapter)
-			{
-				D3D9Driver* currDriver = driverList->item(adapter);
-				const D3DADAPTER_IDENTIFIER9& currAdapterIdentifier = currDriver->getAdapterIdentifier();
-
-				if(strstr(currAdapterIdentifier.Description, "PerfHUD") != NULL)
-				{
-					renderDevice = NULL;
-					nAdapterOrdinal = adapter;
-					renderSystem->mActiveD3DDriver = currDriver;
-					devType = D3DDEVTYPE_REF;
-					nvAdapterFound = true;
-					break;
-				}
-			}		
-		}
-
 		// Try to find a matching device from current device list.
 		if (renderDevice == NULL)
 		{
@@ -241,7 +218,7 @@ namespace CamelotFramework
 		D3D9DriverList*			driverList = renderSystem->getDirect3DDrivers();
 
 		// Find the monitor this render window belongs to.
-		hRenderWindowMonitor = MonitorFromWindow(renderWindow->getWindowHandle(), MONITOR_DEFAULTTONEAREST);
+		hRenderWindowMonitor = MonitorFromWindow(renderWindow->_getWindowHandle(), MONITOR_DEFAULTTONEAREST);
 
 
 		// Find the matching driver using window monitor handle.

+ 2 - 2
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -1088,7 +1088,7 @@ namespace CamelotFramework
 		if (target->isWindow())
 		{
 			D3D9RenderWindow* window = static_cast<D3D9RenderWindow*>(target.get());
-			mDeviceManager->setActiveRenderTargetDevice(window->getDevice());
+			mDeviceManager->setActiveRenderTargetDevice(window->_getDevice());
 			window->_validateDevice();
 		}
 
@@ -2286,7 +2286,7 @@ namespace CamelotFramework
 		{
 			D3D9Device* currDevice = mDeviceManager->getDevice(i);
 			const D3D9RenderWindow* currDevicePrimaryWindow = currDevice->getPrimaryWindow();
-			IDirect3DSurface9* pSurface = currDevicePrimaryWindow->getRenderSurface();
+			IDirect3DSurface9* pSurface = currDevicePrimaryWindow->_getRenderSurface();
 			D3DSURFACE_DESC srfDesc;
 
 			// Get surface desc

+ 134 - 135
CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp

@@ -26,6 +26,7 @@ THE SOFTWARE.
 -----------------------------------------------------------------------------
 */
 #include "CmD3D9RenderWindow.h"
+#include "CmCoreThread.h"
 #include "CmViewport.h"
 #include "CmException.h"
 #include "CmD3D9RenderSystem.h"
@@ -48,7 +49,6 @@ namespace CamelotFramework
 		mSwitchingFullscreen = false;
 		mDisplayFrequency = 0;
 		mDeviceValid = false;
-		mUseNVPerfHUD = false;
 	}
 
 	D3D9RenderWindow::~D3D9RenderWindow()
@@ -63,7 +63,6 @@ namespace CamelotFramework
 		mFSAA = mDesc.FSAA;
 		mVSync = mDesc.vsync;
 		mVSyncInterval = mDesc.vsyncInterval;
-		mUseNVPerfHUD = false;
 
 		HWND parentHWnd = 0;
 		HWND externalHandle = 0;
@@ -186,7 +185,7 @@ namespace CamelotFramework
 						dwStyle |= WS_OVERLAPPEDWINDOW;
 				}
 
-				adjustWindow(mDesc.width, mDesc.height, dwStyle, &winWidth, &winHeight);
+				_adjustWindow(mDesc.width, mDesc.height, dwStyle, &winWidth, &winHeight);
 
 				if (!mDesc.outerDimensions)
 				{
@@ -282,6 +281,8 @@ namespace CamelotFramework
 
 	void D3D9RenderWindow::setFullscreen(bool fullScreen, unsigned int width, unsigned int height)
 	{
+		THROW_IF_NOT_CORE_THREAD;
+
 		if (fullScreen != mIsFullScreen || width != mWidth || height != mHeight)
 		{
 			if (fullScreen != mIsFullScreen)
@@ -332,7 +333,7 @@ namespace CamelotFramework
 				// Calculate window dimensions required
 				// to get the requested client area
 				unsigned int winWidth, winHeight;
-				adjustWindow(mWidth, mHeight, mStyle, &winWidth, &winHeight);
+				_adjustWindow(mWidth, mHeight, mStyle, &winWidth, &winHeight);
 
 				SetWindowLong(mHWnd, GWL_STYLE, mStyle);
 				SetWindowPos(mHWnd, HWND_NOTOPMOST, 0, 0, winWidth, winHeight,
@@ -350,7 +351,128 @@ namespace CamelotFramework
 		}
 	} 
 
-	void D3D9RenderWindow::adjustWindow(unsigned int clientWidth, unsigned int clientHeight, 
+	bool D3D9RenderWindow::isActive() const
+	{
+		if (isFullScreen())
+			return isVisible();
+
+		return mActive && isVisible();
+	}
+
+	bool D3D9RenderWindow::isVisible() const
+	{
+		return (mHWnd && !IsIconic(mHWnd));
+	}
+
+	void D3D9RenderWindow::reposition(int top, int left)
+	{
+		THROW_IF_NOT_CORE_THREAD;
+
+		if (mHWnd && !mIsFullScreen)
+		{
+			SetWindowPos(mHWnd, 0, top, left, 0, 0,
+				SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
+		}
+	}
+
+	void D3D9RenderWindow::resize(unsigned int width, unsigned int height)
+	{
+		THROW_IF_NOT_CORE_THREAD;
+
+		if (mHWnd && !mIsFullScreen)
+		{
+			unsigned int winWidth, winHeight;
+			_adjustWindow(width, height, mStyle, &winWidth, &winHeight);
+			SetWindowPos(mHWnd, 0, 0, 0, winWidth, winHeight,
+				SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
+		}
+	}
+
+	void D3D9RenderWindow::getCustomAttribute( const String& name, void* pData ) const
+	{
+		// Valid attributes and their equvalent native functions:
+		// D3DDEVICE			: getD3DDevice
+		// WINDOW				: getWindowHandle
+
+		if( name == "D3DDEVICE" )
+		{
+			IDirect3DDevice9* *pDev = (IDirect3DDevice9**)pData;
+			*pDev = _getD3D9Device();
+			return;
+		}		
+		else if( name == "WINDOW" )
+		{
+			HWND *pHwnd = (HWND*)pData;
+			*pHwnd = _getWindowHandle();
+			return;
+		}
+		else if( name == "isTexture" )
+		{
+			bool *b = reinterpret_cast< bool * >( pData );
+			*b = false;
+
+			return;
+		}
+		else if( name == "D3DZBUFFER" )
+		{
+			IDirect3DSurface9* *pSurf = (IDirect3DSurface9**)pData;
+			*pSurf = mDevice->getDepthBuffer(this);
+			return;
+		}
+		else if( name == "DDBACKBUFFER" )
+		{
+			IDirect3DSurface9* *pSurf = (IDirect3DSurface9**)pData;
+			*pSurf = mDevice->getBackBuffer(this);
+			return;
+		}
+		else if( name == "DDFRONTBUFFER" )
+		{
+			IDirect3DSurface9* *pSurf = (IDirect3DSurface9**)pData;
+			*pSurf = mDevice->getBackBuffer(this);
+			return;
+		}
+	}
+
+	void D3D9RenderWindow::swapBuffers()
+	{
+		if (mDeviceValid)
+			mDevice->present(this);		
+	}
+
+	Int2 D3D9RenderWindow::screenToWindowPos(const Int2& screenPos) const
+	{
+		POINT pos;
+
+		// Convert client coordinates to screen coordinates
+		pos.x = screenPos.x;
+		pos.y = screenPos.y;
+
+		ScreenToClient(mHWnd, &pos);
+		return Int2(pos.x, pos.y);
+	}
+
+	void D3D9RenderWindow::copyContentsToMemory(const PixelData &dst, FrameBuffer buffer)
+	{
+		mDevice->copyContentsToMemory(this, dst, buffer);
+	}
+
+	void D3D9RenderWindow::_windowMovedOrResized()
+	{
+		THROW_IF_NOT_CORE_THREAD;
+
+		if (!mHWnd || IsIconic(mHWnd))
+			return;
+	
+		updateWindowRect();
+
+		RenderWindow::_windowMovedOrResized();
+	}
+
+	/************************************************************************/
+	/* 						D3D9 IMPLEMENTATION SPECIFIC                    */
+	/************************************************************************/
+
+	void D3D9RenderWindow::_adjustWindow(unsigned int clientWidth, unsigned int clientHeight, 
 		DWORD style, unsigned int* winWidth, unsigned int* winHeight)
 	{
 		// NB only call this for non full screen
@@ -395,7 +517,7 @@ namespace CamelotFramework
 			// after device has been restored
 			// We may have had a resize event which polluted our desired sizes
 			unsigned int winWidth, winHeight;
-			adjustWindow(mDesiredWidth, mDesiredHeight, mStyle, &winWidth, &winHeight);
+			_adjustWindow(mDesiredWidth, mDesiredHeight, mStyle, &winWidth, &winHeight);
 
 			// deal with centreing when switching down to smaller resolution
 
@@ -426,7 +548,7 @@ namespace CamelotFramework
 		mSwitchingFullscreen = false;
 	}
 	
-	void D3D9RenderWindow::buildPresentParameters(D3DPRESENT_PARAMETERS* presentParams) const
+	void D3D9RenderWindow::_buildPresentParameters(D3DPRESENT_PARAMETERS* presentParams) const
 	{		
 		// Set up the presentation parameters		
 		IDirect3D9* pD3D = D3D9RenderSystem::getDirect3D9();
@@ -570,142 +692,37 @@ namespace CamelotFramework
 		}
 	}
 
-	bool D3D9RenderWindow::isActive() const
-	{
-		if (isFullScreen())
-			return isVisible();
-
-		return mActive && isVisible();
-	}
-
-	bool D3D9RenderWindow::isVisible() const
-	{
-		return (mHWnd && !IsIconic(mHWnd));
-	}
-
-	void D3D9RenderWindow::reposition(int top, int left)
-	{
-		if (mHWnd && !mIsFullScreen)
-		{
-			SetWindowPos(mHWnd, 0, top, left, 0, 0,
-				SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
-		}
-	}
-
-	void D3D9RenderWindow::resize(unsigned int width, unsigned int height)
-	{
-		if (mHWnd && !mIsFullScreen)
-		{
-			unsigned int winWidth, winHeight;
-			adjustWindow(width, height, mStyle, &winWidth, &winHeight);
-			SetWindowPos(mHWnd, 0, 0, 0, winWidth, winHeight,
-				SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
-		}
-	}
-
-	void D3D9RenderWindow::windowMovedOrResized()
-	{
-		if (!mHWnd || IsIconic(mHWnd))
-			return;
-	
-		updateWindowRect();
-
-		RenderWindow::windowMovedOrResized();
-	}
-
-	void D3D9RenderWindow::swapBuffers()
-	{
-		if (mDeviceValid)
-			mDevice->present(this);		
-	}
-
-	void D3D9RenderWindow::getCustomAttribute( const String& name, void* pData ) const
-	{
-		// Valid attributes and their equvalent native functions:
-		// D3DDEVICE			: getD3DDevice
-		// WINDOW				: getWindowHandle
-
-		if( name == "D3DDEVICE" )
-		{
-			IDirect3DDevice9* *pDev = (IDirect3DDevice9**)pData;
-			*pDev = getD3D9Device();
-			return;
-		}		
-		else if( name == "WINDOW" )
-		{
-			HWND *pHwnd = (HWND*)pData;
-			*pHwnd = getWindowHandle();
-			return;
-		}
-		else if( name == "isTexture" )
-		{
-			bool *b = reinterpret_cast< bool * >( pData );
-			*b = false;
-
-			return;
-		}
-		else if( name == "D3DZBUFFER" )
-		{
-			IDirect3DSurface9* *pSurf = (IDirect3DSurface9**)pData;
-			*pSurf = mDevice->getDepthBuffer(this);
-			return;
-		}
-		else if( name == "DDBACKBUFFER" )
-		{
-			IDirect3DSurface9* *pSurf = (IDirect3DSurface9**)pData;
-			*pSurf = mDevice->getBackBuffer(this);
-			return;
-		}
-		else if( name == "DDFRONTBUFFER" )
-		{
-			IDirect3DSurface9* *pSurf = (IDirect3DSurface9**)pData;
-			*pSurf = mDevice->getBackBuffer(this);
-			return;
-		}
-	}
-
-	void D3D9RenderWindow::copyContentsToMemory(const PixelData &dst, FrameBuffer buffer)
-	{
-		mDevice->copyContentsToMemory(this, dst, buffer);
-	}
-	//-----------------------------------------------------------------------------
-	IDirect3DDevice9* D3D9RenderWindow::getD3D9Device() const
+	IDirect3DDevice9* D3D9RenderWindow::_getD3D9Device() const
 	{
 		return mDevice->getD3D9Device();
 	}
 
-	//-----------------------------------------------------------------------------
-	IDirect3DSurface9* D3D9RenderWindow::getRenderSurface() const 
+	IDirect3DSurface9* D3D9RenderWindow::_getRenderSurface() const 
 	{
 		return mDevice->getBackBuffer(this);
 	}
 
-	//-----------------------------------------------------------------------------
 	bool D3D9RenderWindow::_getSwitchingFullscreen() const
 	{
 		return mSwitchingFullscreen;
 	}
 
-	//-----------------------------------------------------------------------------
-	D3D9Device* D3D9RenderWindow::getDevice() const
+	D3D9Device* D3D9RenderWindow::_getDevice() const
 	{
 		return mDevice;
 	}
 
-	//-----------------------------------------------------------------------------
-	void D3D9RenderWindow::setDevice(D3D9Device* device)
+	void D3D9RenderWindow::_setDevice(D3D9Device* device)
 	{
 		mDevice = device;
 		mDeviceValid = false;
 	}
 
-	//-----------------------------------------------------------------------------
-	bool D3D9RenderWindow::isDepthBuffered() const
+	bool D3D9RenderWindow::_isDepthBuffered() const
 	{
 		return mIsDepthBuffered;
 	}
 
-	//-----------------------------------------------------------------------------
 	void D3D9RenderWindow::updateWindowRect()
 	{
 		RECT rc;
@@ -746,24 +763,6 @@ namespace CamelotFramework
 		}	
 	}
 
-	Int2 D3D9RenderWindow::screenToWindowPos(const Int2& screenPos) const
-	{
-		POINT pos;
-
-		// Convert client coordinates to screen coordinates
-		pos.x = screenPos.x;
-		pos.y = screenPos.y;
-
-		ScreenToClient(mHWnd, &pos);
-		return Int2(pos.x, pos.y);
-	}
-
-	//-----------------------------------------------------------------------------
-	bool D3D9RenderWindow::isNvPerfHUDEnable() const
-	{
-		return mUseNVPerfHUD;
-	}
-	//---------------------------------------------------------------------
 	bool D3D9RenderWindow::_validateDevice()
 	{
 		mDeviceValid = mDevice->validate(this);

+ 1 - 1
CamelotGLRenderer/Include/CmWin32Window.h

@@ -56,7 +56,7 @@ namespace CamelotFramework {
 		HDC getHDC() const { return mHDC; }
 		
 		// Method for dealing with resize / move & 3d library
-		virtual void windowMovedOrResized(void);
+		virtual void _windowMovedOrResized(void);
 
 		Int2 screenToWindowPos(const Int2& screenPos) const;
 

+ 3 - 3
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -550,7 +550,7 @@ namespace CamelotFramework {
 				mWidth = width;
 				mHeight = height;
 
-				windowMovedOrResized();
+				_windowMovedOrResized();
 			}
 		}
 	}
@@ -595,7 +595,7 @@ namespace CamelotFramework {
 		}
 	}
 
-	void Win32Window::windowMovedOrResized()
+	void Win32Window::_windowMovedOrResized()
 	{
 		if (!mHWnd || IsIconic(mHWnd))
 			return;
@@ -614,7 +614,7 @@ namespace CamelotFramework {
 		mWidth = rc.right - rc.left;
 		mHeight = rc.bottom - rc.top;
 
-		RenderWindow::windowMovedOrResized();
+		RenderWindow::_windowMovedOrResized();
 	}
 
 	void Win32Window::swapBuffers()

+ 2 - 5
TODO.txt

@@ -24,13 +24,9 @@ GUIWidget::updateMeshes leaks. If I leave the game running I can see memory cont
 /************** INPUT REFACTOR *********************/
 
 DO LATER:
+ - Rename DeferredRenderContext and everything that references it
  - onMovedOrResized is still used by Viewport
  - Replace list of windows in WIndowEventUtilities with WindowManagers list. No need to keep two lists I think
- - Remagine render thread:
-   - Its main loop is in CmApplication
-   - Rename it to CoreThread
-   - Renamed DeferredRenderContext to DeferredCoreThreadAccessor
- - Maybe: Attempt to add a global throwIfNotCore thread method
 
 /*******************************************************/
 
@@ -56,6 +52,7 @@ TextBox needed elements:
  - Text selection - Shift + arrow keys select text. Mouse drag selects text, and scrolls the text if needed. Text selection is drawn using another single color image sprite. Selection height is determined by line height.
  - Text operations - Select all, copy, paste (using shorcuts, possibly also context menu?)
  - Make sure multi-line text boxes work fine as well.
+ - (Selecting something and then typing anything needs to replace selection with typed character)
 
 Window needed systems:
 EditorWindowContainer

+ 8 - 2
TODODoc.txt

@@ -16,5 +16,11 @@
    very weird issues.
  - If you're creating a hierarchy of classes with RTTI support, ALL classes in the hierarchy must have RTTI implementations. You cannot just leave
    some out, even if they contain no data. This would create incomplete RTTI class hierarchy which can cause various issues.
- - Methods prefixed with "_" are methods you should not normally call. They are used internally by some subset of classes that form a system and are not meant
-   to be called by the user, unless you are working internally with that system. The only reason they are part of the public interface is to avoid friend classes.
+ - Notation rules:
+    - Method prefixed with _ (i.e. _getDevice()) are internal methods used by the engine systems and normal user should not need to call them unless 
+	  he really knows what is he doing. Those methods might also be marked with "Internal method" notation in their documentation.
+	  Only methods that are part of the public interface have this syntax, as private methods are not visible to the user anyway, so there's no need for special notation.
+	    - When communicating between system I will use "prefix _" notation interchangeably with friend class approach. Sometimes I prefer to extend to public interface and 
+		add a _ prefixed method, and in other cases I prefer not to modify the public interface and make a class a friend and use a private method.
+	- "Core method" notation in method documentation. This means the method is only meant to be called from the core thread. Calling it from another thread
+	  will cause an exception at best, or cause unpredictable behaviour at worst.