瀏覽代碼

Removing createRenderWindow from RenderSystem

Marko Pintera 13 年之前
父節點
當前提交
8b3a2497ae
共有 37 個文件被更改,包括 473 次插入465 次删除
  1. 1 1
      CamelotClient/CamelotClient.cpp
  2. 2 2
      CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h
  3. 1 1
      CamelotD3D9Renderer/Include/CmD3D9RenderWindow.h
  4. 7 7
      CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp
  5. 1 1
      CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp
  6. 2 0
      CamelotGLRenderer/CamelotGLRenderer.vcxproj
  7. 6 0
      CamelotGLRenderer/CamelotGLRenderer.vcxproj.filters
  8. 78 60
      CamelotGLRenderer/Include/CmGLRenderSystem.h
  9. 23 0
      CamelotGLRenderer/Include/CmGLRenderWindowManager.h
  10. 0 3
      CamelotGLRenderer/Include/CmGLSupport.h
  11. 0 2
      CamelotGLRenderer/Include/CmWin32GLSupport.h
  12. 1 1
      CamelotGLRenderer/Include/CmWin32Window.h
  13. 0 11
      CamelotGLRenderer/Source/CmGLHardwarePixelBuffer.cpp
  14. 40 51
      CamelotGLRenderer/Source/CmGLRenderSystem.cpp
  15. 30 0
      CamelotGLRenderer/Source/CmGLRenderWindowManager.cpp
  16. 1 78
      CamelotGLRenderer/Source/CmWin32GLSupport.cpp
  17. 1 1
      CamelotGLRenderer/Source/CmWin32Window.cpp
  18. 1 1
      CamelotGLRenderer/Source/win32/CmWin32Context.cpp
  19. 2 0
      CamelotRenderer/CamelotRenderer.vcxproj
  20. 6 0
      CamelotRenderer/CamelotRenderer.vcxproj.filters
  21. 2 2
      CamelotRenderer/Include/CmApplication.h
  22. 1 1
      CamelotRenderer/Include/CmCamera.h
  23. 4 2
      CamelotRenderer/Include/CmPrerequisites.h
  24. 3 206
      CamelotRenderer/Include/CmRenderSystem.h
  25. 0 6
      CamelotRenderer/Include/CmRenderTexture.h
  26. 3 1
      CamelotRenderer/Include/CmRenderWindow.h
  27. 213 0
      CamelotRenderer/Include/CmRenderWindowManager.h
  28. 3 3
      CamelotRenderer/Include/CmViewport.h
  29. 1 1
      CamelotRenderer/Source/CmApplication.cpp
  30. 1 1
      CamelotRenderer/Source/CmCamera.cpp
  31. 1 1
      CamelotRenderer/Source/CmDeferredRenderContext.cpp
  32. 1 14
      CamelotRenderer/Source/CmRenderSystem.cpp
  33. 6 1
      CamelotRenderer/Source/CmRenderWindow.cpp
  34. 22 0
      CamelotRenderer/Source/CmRenderWindowManager.cpp
  35. 2 2
      CamelotRenderer/Source/CmViewport.cpp
  36. 3 3
      CamelotRenderer/Source/Win32/CmOSCursorImpl.cpp
  37. 4 1
      CamelotRenderer/TODO.txt

+ 1 - 1
CamelotClient/CamelotClient.cpp

@@ -31,7 +31,7 @@ int _tmain(int argc, _TCHAR* argv[])
 	//gApplication().startUp("CamelotD3D9RenderSystem", "CamelotForwardRenderer");
 
 	RenderSystem* renderSystem = RenderSystemManager::getActive();
-	RenderWindow* renderWindow = gApplication().getPrimaryRenderWindow();
+	RenderWindowPtr renderWindow = gApplication().getPrimaryRenderWindow();
 
 	GameObjectPtr cameraGO = GameObject::create("MainCamera");
 	CameraPtr camera = cameraGO->addComponent<Camera>();

+ 2 - 2
CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h

@@ -54,7 +54,7 @@ namespace CamelotEngine
 		void createRenderWindow_internal(const String &name, unsigned int width, unsigned int height, 
 			bool fullScreen, const NameValuePairList& miscParams, AsyncOp& asyncOp);
 		void destroyRenderTarget(RenderTarget* renderTarget);
-		void setRenderTarget(RenderTarget *target);
+		void setRenderTarget(RenderTarget* target);
 
 		void bindGpuProgram(GpuProgramHandle prg);
 		void unbindGpuProgram(GpuProgramType gptype);
@@ -189,7 +189,7 @@ namespace CamelotEngine
 		RenderSystemCapabilities* updateRenderSystemCapabilities(D3D9RenderWindow* renderWindow);
 
 		/** See RenderSystem definition */
-		virtual void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary);
+		virtual void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps);
 
 
         void convertVertexShaderCaps(RenderSystemCapabilities* rsc) const;

+ 1 - 1
CamelotD3D9Renderer/Include/CmD3D9RenderWindow.h

@@ -47,7 +47,7 @@ namespace CamelotEngine
 		~D3D9RenderWindow					();
 		
 		
-		void				create				(const String& name, unsigned int width, unsigned int height,
+		void				initialize				(const String& name, unsigned int width, unsigned int height,
 												 bool fullScreen, const NameValuePairList *miscParams);
 		void				setFullscreen		(bool fullScreen, unsigned int width, unsigned int height);
 		void				destroy				(void);

+ 7 - 7
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -238,7 +238,7 @@ namespace CamelotEngine
 
 		D3D9RenderWindow* renderWindow = new D3D9RenderWindow(mhInstance);
 
-		renderWindow->create(name, width, height, fullScreen, &miscParams);
+		renderWindow->initialize(name, width, height, fullScreen, &miscParams);
 
 		mResourceManager->lockDeviceAccess();
 
@@ -1053,7 +1053,7 @@ namespace CamelotEngine
 			__SetSamplerState( static_cast<DWORD>(unit), D3DSAMP_MAXANISOTROPY, maxAnisotropy );
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setRenderTarget(RenderTarget *target)
+	void D3D9RenderSystem::setRenderTarget(RenderTarget* target)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
@@ -1066,7 +1066,7 @@ namespace CamelotEngine
 		// implementation ensures nothing happens if the same device is set twice
 		if (std::find(mRenderWindows.begin(), mRenderWindows.end(), target) != mRenderWindows.end())
 		{
-			D3D9RenderWindow *window = static_cast<D3D9RenderWindow*>(target);
+			D3D9RenderWindow* window = static_cast<D3D9RenderWindow*>(target);
 			mDeviceManager->setActiveRenderTargetDevice(window->getDevice());
 			// also make sure we validate the device; if this never went 
 			// through update() it won't be set
@@ -1131,8 +1131,8 @@ namespace CamelotEngine
 		HRESULT hr;
 
 		// Set render target
-		RenderTarget* target = vp.getTarget();
-		setRenderTarget(target);
+		RenderTargetPtr target = vp.getTarget();
+		setRenderTarget(target.get());
 
 		setCullingMode( mCullingMode );
 
@@ -2134,7 +2134,7 @@ namespace CamelotEngine
 			mCurrentCapabilities->addShaderProfile("hlsl");
 			mCurrentCapabilities->addShaderProfile("cg");
 
-			initialiseFromRenderSystemCapabilities(mCurrentCapabilities, renderWindow);
+			initialiseFromRenderSystemCapabilities(mCurrentCapabilities);
 		}
 
 		return rsc;
@@ -2427,7 +2427,7 @@ namespace CamelotEngine
 
 	}
 	//-----------------------------------------------------------------------
-	void D3D9RenderSystem::initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary)
+	void D3D9RenderSystem::initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps)
 	{
 		if (caps->getRenderSystemName() != getName())
 		{

+ 1 - 1
CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp

@@ -57,7 +57,7 @@ namespace CamelotEngine
 		destroy();
 	}
 
-	void D3D9RenderWindow::create(const String& name, unsigned int width, unsigned int height,
+	void D3D9RenderWindow::initialize(const String& name, unsigned int width, unsigned int height,
 		bool fullScreen, const NameValuePairList *miscParams)
 	{
 		HINSTANCE hInst = mInstance;

+ 2 - 0
CamelotGLRenderer/CamelotGLRenderer.vcxproj

@@ -164,6 +164,7 @@
     <ClInclude Include="Include\CmGLRenderSystem.h" />
     <ClInclude Include="Include\CmGLRenderSystemFactory.h" />
     <ClInclude Include="Include\CmGLRenderTexture.h" />
+    <ClInclude Include="Include\CmGLRenderWindowManager.h" />
     <ClInclude Include="Include\CmGLSLProgramRTTI.h" />
     <ClInclude Include="Include\CmGLSupport.h" />
     <ClInclude Include="Include\CmGLTexture.h" />
@@ -205,6 +206,7 @@
     <ClCompile Include="Source\CmGLRenderSystem.cpp" />
     <ClCompile Include="Source\CmGLRenderSystemFactory.cpp" />
     <ClCompile Include="Source\CmGLRenderTexture.cpp" />
+    <ClCompile Include="Source\CmGLRenderWindowManager.cpp" />
     <ClCompile Include="Source\CmGLSupport.cpp" />
     <ClCompile Include="Source\CmGLTexture.cpp" />
     <ClCompile Include="Source\CmGLTextureManager.cpp" />

+ 6 - 0
CamelotGLRenderer/CamelotGLRenderer.vcxproj.filters

@@ -135,6 +135,9 @@
     <ClInclude Include="Include\CmGLMultiRenderTarget.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\CmGLRenderWindowManager.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\atifs\src\ATI_FS_GLGpuProgram.cpp">
@@ -239,5 +242,8 @@
     <ClCompile Include="Source\CmGLMultiRenderTarget.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Source\CmGLRenderWindowManager.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 78 - 60
CamelotGLRenderer/Include/CmGLRenderSystem.h

@@ -44,45 +44,37 @@ namespace CamelotEngine {
     class CM_RSGL_EXPORT GLRenderSystem : public RenderSystem
     {
     public:
-        // Default constructor / destructor
         GLRenderSystem();
         ~GLRenderSystem();
 
-        // ----------------------------------
-        // Overridden RenderSystem functions
-        // ----------------------------------
-        /** See
-          RenderSystem
-         */
+		/**
+		 * @copydoc RenderSystem::getName()
+		 */
         const String& getName(void) const;
 
-        // -----------------------------
-        // Low-level overridden members
-        // -----------------------------
-		/** See
-          RenderSystem
-         */
-		void createRenderWindow_internal(const String &name, unsigned int width, unsigned int height, 
-			bool fullScreen, const NameValuePairList& miscParams, AsyncOp& asyncOp);
-        /**
-         * Set current render target to target, enabling its GL context if needed
-         */
+		/**
+		 * @copydoc RenderSystem::setRenderTarget()
+		 */
         void setRenderTarget(RenderTarget *target);
-		/** See
-          RenderSystem
-         */
+
+		/**
+		 * @copydoc RenderSystem::bindGpuProgram()
+		 */
 		void bindGpuProgram(GpuProgramHandle prg);
-        /** See
-          RenderSystem
-         */
+
+		/**
+		 * @copydoc RenderSystem::unbindGpuProgram()
+		 */
 		void unbindGpuProgram(GpuProgramType gptype);
-		/** See
-          RenderSystem
-         */
+
+		/**
+		 * @copydoc RenderSystem::bindGpuProgramParameters()
+		 */
 		void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, UINT16 mask);
-		/** See
-          RenderSystem
-         */
+
+		/**
+		 * @copydoc RenderSystem::setTexture()
+		 */
         void setTexture(UINT16 unit, bool enabled, const TexturePtr &tex);
         
 		/**
@@ -110,54 +102,80 @@ namespace CamelotEngine {
 		 */
 		void setStencilRefValue(UINT32 refValue);
 
-        /** See
-          RenderSystem
-         */
+		/**
+		 * @copydoc RenderSystem::setViewport()
+		 */
         void setViewport(const Viewport& vp);
-        /** See
-          RenderSystem
-         */
+
+		/**
+		 * @copydoc RenderSystem::beginFrame()
+		 */
         void beginFrame(void);
-        /** See
-          RenderSystem
-         */
+
+		/**
+		 * @copydoc RenderSystem::endFrame()
+		 */
         void endFrame(void);
-        /** See
-          RenderSystem
-         */
+
+        /**
+		 * @copydoc RenderSystem::convertProjectionMatrix()
+		 */
         void convertProjectionMatrix(const Matrix4& matrix,
             Matrix4& dest, bool forGpuProgram = false);
-        /** See
-          RenderSystem
-         */
+        /**
+		 * @copydoc RenderSystem::setVertexDeclaration()
+		 */
 		void setVertexDeclaration(VertexDeclarationPtr decl);
-        /** See
-          RenderSystem
-         */
+        /**
+		 * @copydoc RenderSystem::setVertexBufferBinding()
+		 */
 		void setVertexBufferBinding(VertexBufferBinding* binding);
-        /** See
-          RenderSystem
-         */
+        /**
+		 * @copydoc RenderSystem::render()
+		 */
         void render(const RenderOperation& op);
 
-        /** See
-          RenderSystem
-         */
+        /**
+		 * @copydoc RenderSystem::setScissorRect()
+		 */
         void setScissorRect(UINT32 left = 0, UINT32 top = 0, UINT32 right = 800, UINT32 bottom = 600) ;
+
+		/**
+		 * @copydoc RenderSystem::clearFrameBuffer()
+		 */
         void clearFrameBuffer(unsigned int buffers, 
             const Color& colour = Color::Black, 
             float depth = 1.0f, unsigned short stencil = 0);
 
-		/** See
-          RenderSystem
-         */
+        /**
+		 * @copydoc RenderSystem::getColorVertexElementType()
+		 */
         VertexElementType getColorVertexElementType(void) const;
+
+		/**
+		 * @copydoc RenderSystem::getHorizontalTexelOffset()
+		 */
         float getHorizontalTexelOffset(void);
+
+		/**
+		 * @copydoc RenderSystem::getVerticalTexelOffset()
+		 */
         float getVerticalTexelOffset(void);
+
+		/**
+		 * @copydoc RenderSystem::getMinimumDepthInputValue()
+		 */
         float getMinimumDepthInputValue(void);
+
+		 /**
+		 * @copydoc RenderSystem::getMaximumDepthInputValue()
+		 */
         float getMaximumDepthInputValue(void);
 
-        void _unregisterContext(GLContext *context);
+        void unregisterContext(GLContext *context);
+		void registerContext(GLContext* context);
+
+		GLSupport* getGLSupport() const { return mGLSupport; }
 
     private:
         /// Rendering loop control
@@ -198,7 +216,7 @@ namespace CamelotEngine {
  
         GLint getBlendMode(SceneBlendFactor ogreBlend) const;
 		GLint getTextureAddressingMode(TextureAddressingMode tam) const;
-		void initialiseContext(RenderWindow* primary);
+		void initialiseContext(GLContext* primary);
 
 		/** See
           RenderSystem
@@ -207,7 +225,7 @@ namespace CamelotEngine {
         /** See
           RenderSystem
          */
-		void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary);
+		void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps);
 
         /// Store last depth write state
         bool mDepthWrite;

+ 23 - 0
CamelotGLRenderer/Include/CmGLRenderWindowManager.h

@@ -0,0 +1,23 @@
+#pragma once
+
+#include "CmGLPrerequisites.h"
+#include "CmRenderWindowManager.h"
+
+namespace CamelotEngine
+{
+	class CM_RSGL_EXPORT GLRenderWindowManager : public RenderWindowManager
+	{
+	public:
+		GLRenderWindowManager(GLRenderSystem* renderSystem);
+
+	protected:
+		/**
+		 * @copydoc RenderWindowManager::create()
+		 */
+		void createImpl(const String& name, UINT32 width, UINT32 height, 
+			bool fullScreen, const map<String, String>::type& miscParams, AsyncOp& asyncOp);
+
+	private:
+		GLRenderSystem* mRenderSystem;
+	};
+}

+ 0 - 3
CamelotGLRenderer/Include/CmGLSupport.h

@@ -60,9 +60,6 @@ public:
 
 	virtual ConfigOptionMap& getConfigOptions(void);
 
-	virtual RenderWindow* createWindow(bool autoCreateWindow, GLRenderSystem* renderSystem, const String& windowTitle) = 0;
-
-	/// @copydoc RenderSystem::_createRenderWindow
 	virtual RenderWindow* newWindow(const String &name, unsigned int width, unsigned int height, 
 		bool fullScreen, const NameValuePairList *miscParams = 0) = 0;
 

+ 0 - 2
CamelotGLRenderer/Include/CmWin32GLSupport.h

@@ -26,8 +26,6 @@ namespace CamelotEngine
 		*/
 		String validateConfig();
 
-		virtual RenderWindow* createWindow(bool autoCreateWindow, GLRenderSystem* renderSystem, const String& windowTitle = "OGRE Render Window");
-		
 		/// @copydoc RenderSystem::_createRenderWindow
 		virtual RenderWindow* newWindow(const String &name, unsigned int width, unsigned int height, 
 			bool fullScreen, const NameValuePairList *miscParams = 0);

+ 1 - 1
CamelotGLRenderer/Include/CmWin32Window.h

@@ -39,7 +39,7 @@ namespace CamelotEngine {
         Win32Window(Win32GLSupport &glsupport);
         ~Win32Window();
 
-       void create(const String& name, unsigned int width, unsigned int height,
+       void initialize(const String& name, unsigned int width, unsigned int height,
 	            bool fullScreen, const NameValuePairList *miscParams);
 	   void setFullscreen(bool fullScreen, unsigned int width, unsigned int height);
         void destroy(void);

+ 0 - 11
CamelotGLRenderer/Source/CmGLHardwarePixelBuffer.cpp

@@ -232,17 +232,6 @@ GLTextureBuffer::GLTextureBuffer(const String &baseName, GLenum target, GLuint i
 	mSlicePitch = mHeight*mWidth;
 	mSizeInBytes = PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat);
 	
-	// Log a message
-	/*
-	std::stringstream str;
-	str << "GLHardwarePixelBuffer constructed for texture " << mTextureID 
-		<< " face " << mFace << " level " << mLevel << ": "
-		<< "width=" << mWidth << " height="<< mHeight << " depth=" << mDepth
-		<< "format=" << PixelUtil::getFormatName(mFormat) << "(internal 0x"
-		<< std::hex << value << ")";
-	LogManager::getSingleton().logMessage( 
-                LML_NORMAL, str.str());
-	*/
 	// Set up pixel box
 	mBuffer = PixelData(mWidth, mHeight, mDepth, mFormat);
 	

+ 40 - 51
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -47,6 +47,7 @@ THE SOFTWARE.s
 #include "CmRasterizerState.h"
 #include "CmDepthStencilState.h"
 #include "CmGLRenderTexture.h"
+#include "CmGLRenderWindowManager.h"
 
 #if CM_DEBUG_MODE
 #define THROW_IF_NOT_RENDER_THREAD throwIfNotRenderThread();
@@ -97,7 +98,7 @@ namespace CamelotEngine {
 		size_t i;
 
 		// Get our GLSupport
-		mGLSupport = getGLSupport();
+		mGLSupport = CamelotEngine::getGLSupport();
 
 		mWorldMatrix = Matrix4::IDENTITY;
 		mViewMatrix = Matrix4::IDENTITY;
@@ -155,6 +156,7 @@ namespace CamelotEngine {
 		THROW_IF_NOT_RENDER_THREAD;
 
 		mGLSupport->start();
+		RenderWindowManager::startUp(new GLRenderWindowManager(this));
 
 		RenderSystem::startUp_internal();
 	}
@@ -209,49 +211,6 @@ namespace CamelotEngine {
 		mGLInitialised = 0;
 	}
 
-	void GLRenderSystem::createRenderWindow_internal(const String &name, 
-		unsigned int width, unsigned int height, bool fullScreen,
-		const NameValuePairList& miscParams, AsyncOp& asyncOp)
-	{
-		THROW_IF_NOT_RENDER_THREAD;
-
-		// Create the window
-		RenderWindow* win = mGLSupport->newWindow(name, width, height, 
-			fullScreen, &miscParams);
-
-		attachRenderTarget( *win );
-
-		if (!mGLInitialised) 
-		{                
-			// set up glew and GLSupport
-			initialiseContext(win);
-
-			std::vector<CamelotEngine::String> tokens = StringUtil::split(mGLSupport->getGLVersion(), ".");
-
-			if (!tokens.empty())
-			{
-				mDriverVersion.major = parseInt(tokens[0]);
-				if (tokens.size() > 1)
-					mDriverVersion.minor = parseInt(tokens[1]);
-				if (tokens.size() > 2)
-					mDriverVersion.release = parseInt(tokens[2]); 
-			}
-			mDriverVersion.build = 0;
-			// Initialise GL after the first window has been created
-			// TODO: fire this from emulation options, and don't duplicate float and Current capabilities
-			mCurrentCapabilities = createRenderSystemCapabilities();
-
-			initialiseFromRenderSystemCapabilities(mCurrentCapabilities, win);
-
-			// Initialise the main context
-			oneTimeContextInitialization();
-			if(mCurrentContext)
-				mCurrentContext->setInitialized();
-		}
-
-		asyncOp.completeOperation(win);
-	}
-
 	//---------------------------------------------------------------------
 	void GLRenderSystem::bindGpuProgram(GpuProgramHandle prg)
 	{
@@ -538,9 +497,9 @@ namespace CamelotEngine {
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
-		RenderTarget* target;
+		RenderTargetPtr target;
 		target = vp.getTarget();
-		setRenderTarget(target);
+		setRenderTarget(target.get());
 		mActiveViewport = vp;
 		
 		GLsizei x, y, w, h;
@@ -1572,7 +1531,38 @@ namespace CamelotEngine {
 
 	}
 	//---------------------------------------------------------------------
-	void GLRenderSystem::_unregisterContext(GLContext *context)
+	void GLRenderSystem::registerContext(GLContext* context)
+	{
+		if (!mGLInitialised) 
+		{                
+			// set up glew and GLSupport
+			initialiseContext(context);
+
+			std::vector<CamelotEngine::String> tokens = StringUtil::split(mGLSupport->getGLVersion(), ".");
+
+			if (!tokens.empty())
+			{
+				mDriverVersion.major = parseInt(tokens[0]);
+				if (tokens.size() > 1)
+					mDriverVersion.minor = parseInt(tokens[1]);
+				if (tokens.size() > 2)
+					mDriverVersion.release = parseInt(tokens[2]); 
+			}
+			mDriverVersion.build = 0;
+			// Initialise GL after the first window has been created
+			// TODO: fire this from emulation options, and don't duplicate float and Current capabilities
+			mCurrentCapabilities = createRenderSystemCapabilities();
+
+			initialiseFromRenderSystemCapabilities(mCurrentCapabilities);
+
+			// Initialise the main context
+			oneTimeContextInitialization();
+			if(mCurrentContext)
+				mCurrentContext->setInitialized();
+		}
+	}
+	//---------------------------------------------------------------------
+	void GLRenderSystem::unregisterContext(GLContext *context)
 	{
 		if(mCurrentContext == context) {
 			// Change the context to something else so that a valid context
@@ -1794,11 +1784,10 @@ namespace CamelotEngine {
 		return retval;
 	}
 	//-----------------------------------------------------------------------
-	void GLRenderSystem::initialiseContext(RenderWindow* primary)
+	void GLRenderSystem::initialiseContext(GLContext* primary)
 	{
 		// Set main and current context
-		mMainContext = 0;
-		primary->getCustomAttribute_internal("GLCONTEXT", &mMainContext);
+		mMainContext = primary;
 		mCurrentContext = mMainContext;
 
 		// Set primary context as active
@@ -1813,7 +1802,7 @@ namespace CamelotEngine {
 		glewContextInit(mGLSupport);
 #endif
 	}
-	void GLRenderSystem::initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary)
+	void GLRenderSystem::initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps)
 	{
 		if(caps->getRenderSystemName() != getName())
 		{

+ 30 - 0
CamelotGLRenderer/Source/CmGLRenderWindowManager.cpp

@@ -0,0 +1,30 @@
+#include "CmGLRenderWindowManager.h"
+#include "CmGLRenderSystem.h"
+#include "CmGLSupport.h"
+#include "CmAsyncOp.h"
+
+namespace CamelotEngine
+{
+	GLRenderWindowManager::GLRenderWindowManager(GLRenderSystem* renderSystem)
+		:mRenderSystem(renderSystem)
+	{
+		assert(mRenderSystem != nullptr);
+	}
+
+	void GLRenderWindowManager::createImpl(const String& name, UINT32 width, UINT32 height, 
+		bool fullScreen, const map<String, String>::type& miscParams, AsyncOp& asyncOp)
+	{
+		GLSupport* glSupport = mRenderSystem->getGLSupport();
+
+		// Create the window
+		RenderWindow* win = glSupport->newWindow(name, width, height, fullScreen, &miscParams);
+
+		mRenderSystem->attachRenderTarget(*win);
+		GLContext* context;
+		win->getCustomAttribute_internal("GLCONTEXT", &context);
+		mRenderSystem->registerContext(context);
+
+		RenderWindowPtr winPtr(win);
+		asyncOp.completeOperation(winPtr);
+	}
+}

+ 1 - 78
CamelotGLRenderer/Source/CmWin32GLSupport.cpp

@@ -218,83 +218,6 @@ namespace CamelotEngine {
 		return StringUtil::BLANK;
 	}
 
-	RenderWindow* Win32GLSupport::createWindow(bool autoCreateWindow, GLRenderSystem* renderSystem, const String& windowTitle)
-	{
-		if (autoCreateWindow)
-        {
-            ConfigOptionMap::iterator opt = mOptions.find("Full Screen");
-            if (opt == mOptions.end())
-                CM_EXCEPT(InvalidParametersException, "Can't find full screen options!");
-            bool fullscreen = (opt->second.currentValue == "Yes");
-
-            opt = mOptions.find("Video Mode");
-            if (opt == mOptions.end())
-                CM_EXCEPT(InvalidParametersException, "Can't find video mode options!");
-            String val = opt->second.currentValue;
-            String::size_type pos = val.find('x');
-            if (pos == String::npos)
-                CM_EXCEPT(InvalidParametersException, "Invalid Video Mode provided");
-
-			unsigned int w = parseUnsignedInt(val.substr(0, pos));
-            unsigned int h = parseUnsignedInt(val.substr(pos + 1));
-
-			// Parse optional parameters
-			NameValuePairList winOptions;
-			opt = mOptions.find("Colour Depth");
-			if (opt == mOptions.end())
-				CM_EXCEPT(InvalidParametersException, "Can't find Colour Depth options!");
-			unsigned int colourDepth =
-				parseUnsignedInt(opt->second.currentValue);
-			winOptions["colourDepth"] = toString(colourDepth);
-
-			opt = mOptions.find("VSync");
-			if (opt == mOptions.end())
-				CM_EXCEPT(InvalidParametersException, "Can't find VSync options!");
-			bool vsync = (opt->second.currentValue == "Yes");
-			winOptions["vsync"] = toString(vsync);
-			renderSystem->setWaitForVerticalBlank(vsync);
-
-			opt = mOptions.find("VSync Interval");
-			if (opt == mOptions.end())
-				CM_EXCEPT(InvalidParametersException, "Can't find VSync Interval options!");
-			winOptions["vsyncInterval"] = opt->second.currentValue;
-
-
-			opt = mOptions.find("Display Frequency");
-			if (opt != mOptions.end())
-			{
-				unsigned int displayFrequency =
-					parseUnsignedInt(opt->second.currentValue);
-				winOptions["displayFrequency"] = toString(displayFrequency);
-			}
-
-			opt = mOptions.find("FSAA");
-			if (opt == mOptions.end())
-				CM_EXCEPT(InvalidParametersException, "Can't find FSAA options!");
-			std::vector<CamelotEngine::String> aavalues = StringUtil::split(opt->second.currentValue, " ", 1);
-			unsigned int multisample = parseUnsignedInt(aavalues[0]);
-			String multisample_hint;
-			if (aavalues.size() > 1)
-				multisample_hint = aavalues[1];
-
-			winOptions["FSAA"] = toString(multisample);
-			winOptions["FSAAHint"] = multisample_hint;
-
-			opt = mOptions.find("sRGB Gamma Conversion");
-			if (opt == mOptions.end())
-				CM_EXCEPT(InvalidParametersException, "Can't find sRGB options!");
-			bool hwGamma = (opt->second.currentValue == "Yes");
-			winOptions["gamma"] = toString(hwGamma);
-
-            return renderSystem->createRenderWindow(windowTitle, w, h, fullscreen, &winOptions);
-        }
-        else
-        {
-            // XXX What is the else?
-			return NULL;
-        }
-	}
-
 	BOOL CALLBACK Win32GLSupport::sCreateMonitorsInfoEnumProc(
 		HMONITOR hMonitor,  // handle to display monitor
 		HDC hdcMonitor,     // handle to monitor DC
@@ -373,7 +296,7 @@ namespace CamelotEngine {
 			newParams["monitorHandle"] = toString((size_t)hMonitor);																
 		}
 
-		window->create(name, width, height, fullScreen, miscParams);
+		window->initialize(name, width, height, fullScreen, miscParams);
 
 		if(!mInitialWindow)
 			mInitialWindow = window;

+ 1 - 1
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -64,7 +64,7 @@ namespace CamelotEngine {
 		destroy();
 	}
 
-	void Win32Window::create(const String& name, unsigned int width, unsigned int height,
+	void Win32Window::initialize(const String& name, unsigned int width, unsigned int height,
 							bool fullScreen, const NameValuePairList *miscParams)
 	{
 		// destroy current window, if any

+ 1 - 1
CamelotGLRenderer/Source/win32/CmWin32Context.cpp

@@ -48,7 +48,7 @@ namespace CamelotEngine {
 		// NB have to do this is subclass to ensure any methods called back
 		// are on this subclass and not half-destructed superclass
 		GLRenderSystem *rs = static_cast<GLRenderSystem*>(CamelotEngine::RenderSystemManager::getActive());
-		rs->_unregisterContext(this);
+		rs->unregisterContext(this);
     }
         
     void Win32Context::setCurrent()

+ 2 - 0
CamelotRenderer/CamelotRenderer.vcxproj

@@ -232,6 +232,7 @@
     <ClInclude Include="Include\CmRenderTarget.h" />
     <ClInclude Include="Include\CmRenderTexture.h" />
     <ClInclude Include="Include\CmRenderWindow.h" />
+    <ClInclude Include="Include\CmRenderWindowManager.h" />
     <ClInclude Include="Include\CmResource.h" />
     <ClInclude Include="Include\CmResourceHandle.h" />
     <ClInclude Include="Include\CmResourceHandleRTTI.h" />
@@ -299,6 +300,7 @@
     <ClCompile Include="Source\CmRenderTarget.cpp" />
     <ClCompile Include="Source\CmRenderTexture.cpp" />
     <ClCompile Include="Source\CmRenderWindow.cpp" />
+    <ClCompile Include="Source\CmRenderWindowManager.cpp" />
     <ClCompile Include="Source\CmResource.cpp" />
     <ClCompile Include="Source\CmResourceHandle.cpp" />
     <ClCompile Include="Source\CmResources.cpp" />

+ 6 - 0
CamelotRenderer/CamelotRenderer.vcxproj.filters

@@ -341,6 +341,9 @@
     <ClInclude Include="Include\CmDepthStencilStateRTTI.h">
       <Filter>Header Files\RTTI</Filter>
     </ClInclude>
+    <ClInclude Include="Include\CmRenderWindowManager.h">
+      <Filter>Header Files\RenderSystem</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CamelotRenderer.cpp">
@@ -508,5 +511,8 @@
     <ClCompile Include="Source\CmBlendState.cpp">
       <Filter>Source Files\RenderSystem</Filter>
     </ClCompile>
+    <ClCompile Include="Source\CmRenderWindowManager.cpp">
+      <Filter>Source Files\RenderSystem</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 2 - 2
CamelotRenderer/Include/CmApplication.h

@@ -24,7 +24,7 @@ namespace CamelotEngine
 
 			UINT64 getAppWindowId();
 
-			RenderWindow* getPrimaryRenderWindow() const { return mPrimaryRenderWindow; }
+			RenderWindowPtr getPrimaryRenderWindow() const { return mPrimaryRenderWindow; }
 
 			// TODO: This is just for debug purposes. Normally I'd want to have one render context per scene view, not one global one
 			DeferredRenderContextPtr getPrimaryRenderContext() const { return mPrimaryRenderContext; }
@@ -37,7 +37,7 @@ namespace CamelotEngine
 			void loadPlugin(const String& pluginName);
 
 	private:
-		RenderWindow* mPrimaryRenderWindow;
+		RenderWindowPtr mPrimaryRenderWindow;
 		DeferredRenderContextPtr mPrimaryRenderContext;
 
 		/**

+ 1 - 1
CamelotRenderer/Include/CmCamera.h

@@ -541,7 +541,7 @@ namespace CamelotEngine {
         */
         virtual ~Camera();
 
-		void init(RenderTarget* target = nullptr,
+		void init(RenderTargetPtr target = nullptr,
 			float left = 0.0f, float top = 0.0f,
 			float width = 1.0f, float height = 1.0f,
 			int ZOrder = 0);

+ 4 - 2
CamelotRenderer/Include/CmPrerequisites.h

@@ -165,9 +165,11 @@ namespace CamelotEngine
 	typedef std::shared_ptr<DepthStencilState> DepthStencilStatePtr;
 	typedef std::shared_ptr<RasterizerState> RasterizerStatePtr;
 	typedef std::shared_ptr<BlendState> BlendStatePtr;
+	typedef std::shared_ptr<RenderWindow> RenderWindowPtr;
+	typedef std::shared_ptr<RenderTarget> RenderTargetPtr;
 }
 
-// All type IDs
+// All type IDs used for RTTI
 namespace CamelotEngine
 {
 	enum TypeID_Core
@@ -216,6 +218,6 @@ namespace CamelotEngine
 	typedef ResourceHandle<Material> MaterialHandle;
 }
 
-#endif // __OgrePrerequisites_H__
+#endif
 
 

+ 3 - 206
CamelotRenderer/Include/CmRenderSystem.h

@@ -108,213 +108,10 @@ namespace CamelotEngine
 		 */
 		void startUp();
 
-		// TODO - Classes below (shutdown to getErrorDescription) are not yet thread safe
-
-
 		/** Shutdown the renderer and cleanup resources.
 		*/
 		void shutdown(void);
 
-		/** Creates a new rendering window.
-		@remarks
-		This method creates a new rendering window as specified
-		by the paramteters. The rendering system could be
-		responible for only a single window (e.g. in the case
-		of a game), or could be in charge of multiple ones (in the
-		case of a level editor). The option to create the window
-		as a child of another is therefore given.
-		This method will create an appropriate subclass of
-		RenderWindow depending on the API and platform implementation.
-		@par
-		After creation, this window can be retrieved using getRenderTarget().
-		@param
-		name The name of the window. Used in other methods
-		later like setRenderTarget and getRenderTarget.
-		@param
-		width The width of the new window.
-		@param
-		height The height of the new window.
-		@param
-		fullScreen Specify true to make the window full screen
-		without borders, title bar or menu bar.
-		@param
-		miscParams A NameValuePairList describing the other parameters for the new rendering window. 
-		Options are case sensitive. Unrecognised parameters will be ignored silently.
-		These values might be platform dependent, but these are present for all platforms unless
-		indicated otherwise:
-		<table>
-		<tr>
-			<td><b>Key</b></td>
-			<td><b>Type/Values</b></td>
-			<td><b>Default</b></td>
-			<td><b>Description</b></td>
-			<td><b>Notes</b></td>
-		</tr>
-		<tr>
-			<td>title</td>
-			<td>Any string</td>
-			<td>RenderTarget name</td>
-			<td>The title of the window that will appear in the title bar</td>
-			<td>&nbsp;</td>
-		</tr>
-		<tr>
-			<td>colourDepth</td>
-			<td>16, 32</td>
-			<td>Desktop depth</td>
-			<td>Colour depth of the resulting rendering window; only applies if fullScreen</td>
-			<td>Win32 Specific</td>
-		</tr>
-		<tr>
-			<td>left</td>
-			<td>Positive integers</td>
-			<td>Centred</td>
-			<td>Screen x coordinate from left</td>
-			<td>&nbsp;</td>
-		</tr>
-		<tr>
-			<td>top</td>
-			<td>Positive integers</td>
-			<td>Centred</td>
-			<td>Screen y coordinate from left</td>
-			<td>&nbsp;</td>
-		</tr>
-		<tr>
-			<td>depthBuffer</td>
-			<td>true, false</td>
-			<td>true</td>
-			<td>Use depth buffer</td>
-			<td>DirectX9 specific</td>
-		</tr>
-		<tr>
-			<td>externalWindowHandle</td>
-			<td>Win32: HWND as integer<br/>
-			    GLX: poslong:posint:poslong (display*:screen:windowHandle) or poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*)</td>
-			<td>0 (none)</td>
-			<td>External window handle, for embedding the OGRE render in an existing window</td>
-			<td>&nbsp;</td>
-		</tr>
-		<tr>
-			<td>externalGLControl</td>
-			<td>true, false</td>
-			<td>false</td>
-			<td>Let the external window control OpenGL i.e. don't select a pixel format for the window,
-			do not change v-sync and do not swap buffer. When set to true, the calling application
-			is responsible of OpenGL initialization and buffer swapping. It should also create an
-			OpenGL context for its own rendering, Ogre will create one for its use. Then the calling
-			application must also enable Ogre OpenGL context before calling any Ogre function and
-			restore its OpenGL context after these calls.</td>
-			<td>OpenGL specific</td>
-		</tr>
-		<tr>
-			<td>externalGLContext</td>
-			<td>Context as Unsigned Long</td>
-			<td>0 (create own context)</td>
-			<td>Use an externally created GL context</td>
-			<td>OpenGL Specific</td>
-		</tr>
-		<tr>
-			<td>parentWindowHandle</td>
-			<td>Win32: HWND as integer<br/>
-			    GLX: poslong:posint:poslong (display*:screen:windowHandle) or poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*)</td>
-			<td>0 (none)</td>
-			<td>Parent window handle, for embedding the engine in a child of an external window</td>
-			<td>&nbsp;</td>
-		</tr>
-		<tr>
-			<td>macAPI</td>
-			<td>String: "cocoa" or "carbon"</td>
-			<td>"carbon"</td>
-			<td>Specifies the type of rendering window on the Mac Platform.</td>
-			<td>&nbsp;</td>
-		 </tr>
-		 <tr>
-			<td>macAPICocoaUseNSView</td>
-			<td>bool "true" or "false"</td>
-			<td>"false"</td>
-			<td>On the Mac platform the most diffused method to embed engine in a custom application is to use Interface Builder
-				and add to the interface an instance of OgreView.
-				The pointer to this instance is then used as "externalWindowHandle".
-				However, there are cases where you are NOT using Interface Builder and you get the Cocoa NSView* of an existing interface.
-				For example, this is happens when you want to render into a Java/AWT interface.
-				In short, by setting this flag to "true" the Ogre::Root::createRenderWindow interprets the "externalWindowHandle" as a NSView*
-				instead of an OgreView*. See OgreOSXCocoaView.h/mm.
-			</td>
-			<td>&nbsp;</td>
-		 </tr>
-         <tr>
-			<td>FSAA</td>
-			<td>Positive integer (usually 0, 2, 4, 8, 16)</td>
-			<td>0</td>
-			<td>Full screen antialiasing factor</td>
-			<td>&nbsp;</td>
-		</tr>
-		<tr>
-			<td>FSAAHint</td>
-			<td>Depends on RenderSystem and hardware. Currently supports:<br/>
-			"Quality": on systems that have an option to prefer higher AA quality over speed, use it</td>
-			<td>Blank</td>
-			<td>Full screen antialiasing hint</td>
-			<td>&nbsp;</td>
-		</tr>
-		<tr>
-			<td>displayFrequency</td>
-			<td>Refresh rate in Hertz (e.g. 60, 75, 100)</td>
-			<td>Desktop vsync rate</td>
-			<td>Display frequency rate, for fullscreen mode</td>
-			<td>&nbsp;</td>
-		</tr>
-		<tr>
-			<td>vsync</td>
-			<td>true, false</td>
-			<td>false</td>
-			<td>Synchronize buffer swaps to monitor vsync, eliminating tearing at the expense of a fixed frame rate</td>
-			<td>&nbsp;</td>
-		</tr>
-		<tr>
-			<td>vsyncInterval</td>
-			<td>1, 2, 3, 4</td>
-			<td>1</td>
-			<td>If vsync is enabled, the minimum number of vertical blanks that should occur between renders. 
-			For example if vsync is enabled, the refresh rate is 60 and this is set to 2, then the
-			frame rate will be locked at 30.</td>
-			<td>&nbsp;</td>
-		</tr>
-		<tr>
-			<td>border</td>
-			<td>none, fixed, resize</td>
-			<td>resize</td>
-			<td>The type of window border (in windowed mode)</td>
-			<td>&nbsp;</td>
-		</tr>
-		<tr>
-			<td>outerDimensions</td>
-			<td>true, false</td>
-			<td>false</td>
-			<td>Whether the width/height is expressed as the size of the 
-			outer window, rather than the content area</td>
-			<td>&nbsp;</td>
-		</tr>
-		<tr>
-			<td>useNVPerfHUD</td>
-			<td>true, false</td>
-			<td>false</td>
-			<td>Enable the use of nVidia NVPerfHUD</td>
-			<td>&nbsp;</td>
-		</tr>
-		<tr>
-			<td>gamma</td>
-			<td>true, false</td>
-			<td>false</td>
-			<td>Enable hardware conversion from linear colour space to gamma
-			colour space on rendering to the window.</td>
-			<td>&nbsp;</td>
-		</tr>
-		*/
-		RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height, 
-			bool fullScreen, const NameValuePairList *miscParams = 0);
-		virtual void createRenderWindow_internal(const String &name, unsigned int width, unsigned int height, 
-			bool fullScreen, const NameValuePairList& miscParams, AsyncOp& asyncOp) = 0;
-
 		/** Attaches the passed render target to the render system.
 		*/
 		virtual void attachRenderTarget(RenderTarget &target);
@@ -523,7 +320,7 @@ namespace CamelotEngine
 		/**
          * Set current render target to target, enabling its device context if needed
          */
-        virtual void setRenderTarget(RenderTarget *target) = 0;
+        virtual void setRenderTarget(RenderTarget* target) = 0;
 
 		/************************************************************************/
 		/* 								UTILITY METHODS                    		*/
@@ -594,7 +391,7 @@ namespace CamelotEngine
 		/** The render targets, ordered by priority. */
 		RenderTargetPriorityMap mPrioritisedRenderTargets;
 		/** The Active render target. */
-		RenderTarget * mActiveRenderTarget;
+		RenderTarget* mActiveRenderTarget;
 		/** The Active GPU programs and gpu program parameters*/
 		GpuProgramParametersSharedPtr mActiveVertexGpuProgramParameters;
 		GpuProgramParametersSharedPtr mActiveGeometryGpuProgramParameters;
@@ -635,7 +432,7 @@ namespace CamelotEngine
 		virtual RenderSystemCapabilities* createRenderSystemCapabilities() const = 0;
 
 		/** Initialize the render system from the capabilities*/
-		virtual void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary) = 0;
+		virtual void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps) = 0;
 
 		/**	Create a MultiRenderTarget, which is a render target that renders to multiple RenderTextures
 		at once. Surfaces can be bound and unbound at will.

+ 0 - 6
CamelotRenderer/Include/CmRenderTexture.h

@@ -91,11 +91,8 @@ namespace CamelotEngine
 			bindSurfaceImpl(attachment, target);
 		}
 
-
-
 		/** Unbind attachment.
 		*/
-
 		virtual void unbindSurface(UINT32 attachment)
 		{
 			if (attachment < (UINT32)mBoundSurfaces.size())
@@ -122,7 +119,6 @@ namespace CamelotEngine
 			return mBoundSurfaces[index];
 		}
 
-
 	protected:
 		BoundSufaceList mBoundSurfaces;
 
@@ -130,8 +126,6 @@ namespace CamelotEngine
 		virtual void bindSurfaceImpl(UINT32 attachment, RenderTexture *target) = 0;
 		/// implementation of unbindSurface, must be provided
 		virtual void unbindSurfaceImpl(UINT32 attachment) = 0;
-
-
 	};
 	/** @} */
 	/** @} */

+ 3 - 1
CamelotRenderer/Include/CmRenderWindow.h

@@ -90,7 +90,7 @@ namespace CamelotEngine
                 miscParam A variable number of pointers to platform-specific arguments. The
                 actual requirements must be defined by the implementing subclasses.
         */
-		virtual void create(const String& name, unsigned int width, unsigned int height,
+		virtual void initialize(const String& name, unsigned int width, unsigned int height,
 	            bool fullScreen, const NameValuePairList *miscParams) = 0;
 
 		/** Alter fullscreen mode options. 
@@ -169,6 +169,8 @@ namespace CamelotEngine
           */
         void setDeactivateOnFocusChange(bool deactivate);
 
+		static RenderWindowPtr create(const String& name, unsigned int width, unsigned int height, bool fullScreen, const NameValuePairList *miscParams = nullptr);
+
     protected:
         bool mIsFullScreen;
         bool mIsPrimary;

+ 213 - 0
CamelotRenderer/Include/CmRenderWindowManager.h

@@ -0,0 +1,213 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmModule.h"
+
+namespace CamelotEngine
+{
+	class CM_EXPORT RenderWindowManager : public Module<RenderWindowManager>
+	{
+	public:
+		/** Creates a new rendering window.
+		@remarks
+		This method creates a new rendering window as specified
+		by the paramteters. The rendering system could be
+		responible for only a single window (e.g. in the case
+		of a game), or could be in charge of multiple ones (in the
+		case of a level editor). The option to create the window
+		as a child of another is therefore given.
+		This method will create an appropriate subclass of
+		RenderWindow depending on the API and platform implementation.
+		@par
+		After creation, this window can be retrieved using getRenderTarget().
+		@param
+		name The name of the window. Used in other methods
+		later like setRenderTarget and getRenderTarget.
+		@param
+		width The width of the new window.
+		@param
+		height The height of the new window.
+		@param
+		fullScreen Specify true to make the window full screen
+		without borders, title bar or menu bar.
+		@param
+		miscParams A NameValuePairList describing the other parameters for the new rendering window. 
+		Options are case sensitive. Unrecognised parameters will be ignored silently.
+		These values might be platform dependent, but these are present for all platforms unless
+		indicated otherwise:
+		<table>
+		<tr>
+			<td><b>Key</b></td>
+			<td><b>Type/Values</b></td>
+			<td><b>Default</b></td>
+			<td><b>Description</b></td>
+			<td><b>Notes</b></td>
+		</tr>
+		<tr>
+			<td>title</td>
+			<td>Any string</td>
+			<td>RenderTarget name</td>
+			<td>The title of the window that will appear in the title bar</td>
+			<td>&nbsp;</td>
+		</tr>
+		<tr>
+			<td>colourDepth</td>
+			<td>16, 32</td>
+			<td>Desktop depth</td>
+			<td>Colour depth of the resulting rendering window; only applies if fullScreen</td>
+			<td>Win32 Specific</td>
+		</tr>
+		<tr>
+			<td>left</td>
+			<td>Positive integers</td>
+			<td>Centred</td>
+			<td>Screen x coordinate from left</td>
+			<td>&nbsp;</td>
+		</tr>
+		<tr>
+			<td>top</td>
+			<td>Positive integers</td>
+			<td>Centred</td>
+			<td>Screen y coordinate from left</td>
+			<td>&nbsp;</td>
+		</tr>
+		<tr>
+			<td>depthBuffer</td>
+			<td>true, false</td>
+			<td>true</td>
+			<td>Use depth buffer</td>
+			<td>DirectX9 specific</td>
+		</tr>
+		<tr>
+			<td>externalWindowHandle</td>
+			<td>Win32: HWND as integer<br/>
+			    GLX: poslong:posint:poslong (display*:screen:windowHandle) or poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*)</td>
+			<td>0 (none)</td>
+			<td>External window handle, for embedding the OGRE render in an existing window</td>
+			<td>&nbsp;</td>
+		</tr>
+		<tr>
+			<td>externalGLControl</td>
+			<td>true, false</td>
+			<td>false</td>
+			<td>Let the external window control OpenGL i.e. don't select a pixel format for the window,
+			do not change v-sync and do not swap buffer. When set to true, the calling application
+			is responsible of OpenGL initialization and buffer swapping. It should also create an
+			OpenGL context for its own rendering, Ogre will create one for its use. Then the calling
+			application must also enable Ogre OpenGL context before calling any Ogre function and
+			restore its OpenGL context after these calls.</td>
+			<td>OpenGL specific</td>
+		</tr>
+		<tr>
+			<td>externalGLContext</td>
+			<td>Context as Unsigned Long</td>
+			<td>0 (create own context)</td>
+			<td>Use an externally created GL context</td>
+			<td>OpenGL Specific</td>
+		</tr>
+		<tr>
+			<td>parentWindowHandle</td>
+			<td>Win32: HWND as integer<br/>
+			    GLX: poslong:posint:poslong (display*:screen:windowHandle) or poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*)</td>
+			<td>0 (none)</td>
+			<td>Parent window handle, for embedding the engine in a child of an external window</td>
+			<td>&nbsp;</td>
+		</tr>
+		<tr>
+			<td>macAPI</td>
+			<td>String: "cocoa" or "carbon"</td>
+			<td>"carbon"</td>
+			<td>Specifies the type of rendering window on the Mac Platform.</td>
+			<td>&nbsp;</td>
+		 </tr>
+		 <tr>
+			<td>macAPICocoaUseNSView</td>
+			<td>bool "true" or "false"</td>
+			<td>"false"</td>
+			<td>On the Mac platform the most diffused method to embed engine in a custom application is to use Interface Builder
+				and add to the interface an instance of OgreView.
+				The pointer to this instance is then used as "externalWindowHandle".
+				However, there are cases where you are NOT using Interface Builder and you get the Cocoa NSView* of an existing interface.
+				For example, this is happens when you want to render into a Java/AWT interface.
+				In short, by setting this flag to "true" the Ogre::Root::createRenderWindow interprets the "externalWindowHandle" as a NSView*
+				instead of an OgreView*. See OgreOSXCocoaView.h/mm.
+			</td>
+			<td>&nbsp;</td>
+		 </tr>
+         <tr>
+			<td>FSAA</td>
+			<td>Positive integer (usually 0, 2, 4, 8, 16)</td>
+			<td>0</td>
+			<td>Full screen antialiasing factor</td>
+			<td>&nbsp;</td>
+		</tr>
+		<tr>
+			<td>FSAAHint</td>
+			<td>Depends on RenderSystem and hardware. Currently supports:<br/>
+			"Quality": on systems that have an option to prefer higher AA quality over speed, use it</td>
+			<td>Blank</td>
+			<td>Full screen antialiasing hint</td>
+			<td>&nbsp;</td>
+		</tr>
+		<tr>
+			<td>displayFrequency</td>
+			<td>Refresh rate in Hertz (e.g. 60, 75, 100)</td>
+			<td>Desktop vsync rate</td>
+			<td>Display frequency rate, for fullscreen mode</td>
+			<td>&nbsp;</td>
+		</tr>
+		<tr>
+			<td>vsync</td>
+			<td>true, false</td>
+			<td>false</td>
+			<td>Synchronize buffer swaps to monitor vsync, eliminating tearing at the expense of a fixed frame rate</td>
+			<td>&nbsp;</td>
+		</tr>
+		<tr>
+			<td>vsyncInterval</td>
+			<td>1, 2, 3, 4</td>
+			<td>1</td>
+			<td>If vsync is enabled, the minimum number of vertical blanks that should occur between renders. 
+			For example if vsync is enabled, the refresh rate is 60 and this is set to 2, then the
+			frame rate will be locked at 30.</td>
+			<td>&nbsp;</td>
+		</tr>
+		<tr>
+			<td>border</td>
+			<td>none, fixed, resize</td>
+			<td>resize</td>
+			<td>The type of window border (in windowed mode)</td>
+			<td>&nbsp;</td>
+		</tr>
+		<tr>
+			<td>outerDimensions</td>
+			<td>true, false</td>
+			<td>false</td>
+			<td>Whether the width/height is expressed as the size of the 
+			outer window, rather than the content area</td>
+			<td>&nbsp;</td>
+		</tr>
+		<tr>
+			<td>useNVPerfHUD</td>
+			<td>true, false</td>
+			<td>false</td>
+			<td>Enable the use of nVidia NVPerfHUD</td>
+			<td>&nbsp;</td>
+		</tr>
+		<tr>
+			<td>gamma</td>
+			<td>true, false</td>
+			<td>false</td>
+			<td>Enable hardware conversion from linear colour space to gamma
+			colour space on rendering to the window.</td>
+			<td>&nbsp;</td>
+		</tr>
+		*/
+		RenderWindowPtr create(const String& name, UINT32 width, UINT32 height, 
+			bool fullScreen, const map<String, String>::type* miscParams = nullptr);
+
+	protected:
+		virtual void createImpl(const String& name, UINT32 width, UINT32 height, 
+			bool fullScreen, const map<String, String>::type& miscParams, AsyncOp& asyncOp) = 0;
+	};
+}

+ 3 - 3
CamelotRenderer/Include/CmViewport.h

@@ -79,7 +79,7 @@ namespace CamelotEngine {
                 the front.
         */
         Viewport(
-            RenderTarget* target,
+            RenderTargetPtr target,
             float left = 0.0f, float top = 0.0f,
             float width = 1.0f, float height = 1.0f,
             int ZOrder = 0);
@@ -106,7 +106,7 @@ namespace CamelotEngine {
 
         /** Retrieves a pointer to the render target for this viewport.
         */
-        RenderTarget* getTarget(void) const;
+        RenderTargetPtr getTarget(void) const;
 
         /** Gets the Z-Order of this viewport. */
 		int getZOrder(void) const;
@@ -197,7 +197,7 @@ namespace CamelotEngine {
             int &left, int &top, int &width, int &height ) const;
 
     protected:
-        RenderTarget* mTarget;
+        RenderTargetPtr mTarget;
         // Relative dimensions, irrespective of target dimensions (0..1)
         float mRelLeft, mRelTop, mRelWidth, mRelHeight;
         // Actual dimensions, based on target dimensions

+ 1 - 1
CamelotRenderer/Source/CmApplication.cpp

@@ -52,7 +52,7 @@ namespace CamelotEngine
 		RenderSystem* renderSystem = RenderSystemManager::getActive();
 		renderSystem->startUp();
 
-		mPrimaryRenderWindow = renderSystem->createRenderWindow("Camelot Renderer", 1280, 720, false);
+		mPrimaryRenderWindow = RenderWindow::create("Camelot Renderer", 1280, 720, false);
 		mPrimaryRenderContext = renderSystem->createDeferredContext();
 
 		SceneManager::startUp(new SceneManager());

+ 1 - 1
CamelotRenderer/Source/CmCamera.cpp

@@ -92,7 +92,7 @@ namespace CamelotEngine {
 		if(mViewport != nullptr)
 			delete mViewport;
     }
-	void Camera::init(RenderTarget* target, float left, float top, float width, float height, int ZOrder)
+	void Camera::init(RenderTargetPtr target, float left, float top, float width, float height, int ZOrder)
 	{
 		mViewport = new Viewport(target, left, top, width, height, ZOrder);
 	}

+ 1 - 1
CamelotRenderer/Source/CmDeferredRenderContext.cpp

@@ -124,7 +124,7 @@ namespace CamelotEngine
 		mCommandQueue->queue(boost::bind(&RenderSystem::bindGpuProgramParameters, mRenderSystem, gptype, paramCopy, variabilityMask));
 	}
 
-	void DeferredRenderContext::setRenderTarget(RenderTarget *target)
+	void DeferredRenderContext::setRenderTarget(RenderTarget* target)
 	{
 		mCommandQueue->queue(boost::bind(&RenderSystem::setRenderTarget, mRenderSystem, target));
 	}

+ 1 - 14
CamelotRenderer/Source/CmRenderSystem.cpp

@@ -89,7 +89,7 @@ namespace CamelotEngine {
 
 		initRenderThread();
 
-		queueCommand(boost::bind(&RenderSystem::startUp_internal, this));
+		queueCommand(boost::bind(&RenderSystem::startUp_internal, this), true);
 	}
 	//-----------------------------------------------------------------------
 	void RenderSystem::startUp_internal()
@@ -148,19 +148,6 @@ namespace CamelotEngine {
 				itarg->second->swapBuffers(waitForVSync);
 		}
     }
-	//---------------------------------------------------------------------------------------------
-	RenderWindow* RenderSystem::createRenderWindow(const String &name, unsigned int width, unsigned int height, 
-		bool fullScreen, const NameValuePairList *miscParams)
-	{
-		AsyncOp op;
-
-		if(miscParams != nullptr)
-			op = queueReturnCommand(boost::bind(&RenderSystem::createRenderWindow_internal, this, name, width, height, fullScreen, *miscParams, _1), true);
-		else
-			op = queueReturnCommand(boost::bind(&RenderSystem::createRenderWindow_internal, this, name, width, height, fullScreen, NameValuePairList(), _1), true);
-
-		return op.getReturnValue<RenderWindow*>();
-	}
     //---------------------------------------------------------------------------------------------
     void RenderSystem::destroyRenderWindow(RenderWindow* renderWindow)
     {

+ 6 - 1
CamelotRenderer/Source/CmRenderWindow.cpp

@@ -26,7 +26,7 @@ THE SOFTWARE.
 -----------------------------------------------------------------------------
 */
 #include "CmRenderWindow.h"
-
+#include "CmRenderWindowManager.h"
 #include "CmViewport.h"
 
 namespace CamelotEngine {
@@ -67,4 +67,9 @@ namespace CamelotEngine {
     {
         mAutoDeactivatedOnFocusChange = deactivate;
     }
+
+	RenderWindowPtr RenderWindow::create(const String& name, unsigned int width, unsigned int height, bool fullScreen, const NameValuePairList *miscParams)
+	{
+		return RenderWindowManager::instance().create(name, width, height, fullScreen, miscParams);
+	}
 }

+ 22 - 0
CamelotRenderer/Source/CmRenderWindowManager.cpp

@@ -0,0 +1,22 @@
+#include "CmRenderWindowManager.h"
+#include "CmRenderSystemManager.h"
+#include "CmRenderSystem.h"
+#include "CmAsyncOp.h"
+
+namespace CamelotEngine
+{
+	RenderWindowPtr RenderWindowManager::create(const String& name, UINT32 width, UINT32 height, 
+		bool fullScreen, const map<String, String>::type* miscParams)
+	{
+		RenderSystem* renderSystem = RenderSystemManager::getActive();
+
+		AsyncOp op;
+
+		if(miscParams != nullptr)
+			op = renderSystem->queueReturnCommand(boost::bind(&RenderWindowManager::createImpl, this, name, width, height, fullScreen, *miscParams, _1), true);
+		else
+			op = renderSystem->queueReturnCommand(boost::bind(&RenderWindowManager::createImpl, this, name, width, height, fullScreen, NameValuePairList(), _1), true);
+
+		return op.getReturnValue<RenderWindowPtr>();
+	}
+}

+ 2 - 2
CamelotRenderer/Source/CmViewport.cpp

@@ -52,7 +52,7 @@ namespace CamelotEngine {
 		updateDimensions();
 	}
     //---------------------------------------------------------------------
-    Viewport::Viewport(RenderTarget* target, float left, float top, float width, float height, int ZOrder)
+    Viewport::Viewport(RenderTargetPtr target, float left, float top, float width, float height, int ZOrder)
          :mTarget(target)
         , mRelLeft(left)
         , mRelTop(top)
@@ -92,7 +92,7 @@ namespace CamelotEngine {
 		return mZOrder;
 	}
 	//---------------------------------------------------------------------
-    RenderTarget* Viewport::getTarget(void) const
+    RenderTargetPtr Viewport::getTarget(void) const
     {
         return mTarget;
     }

+ 3 - 3
CamelotRenderer/Source/Win32/CmOSCursorImpl.cpp

@@ -9,7 +9,7 @@ namespace CamelotEngine
 		POINT screenPos;
 		GetCursorPos(&screenPos);
 
-		RenderWindow* primaryWindow = gApplication().getPrimaryRenderWindow();
+		RenderWindowPtr primaryWindow = gApplication().getPrimaryRenderWindow();
 		HWND hwnd;
 		primaryWindow->getCustomAttribute_internal("WINDOW", &hwnd);
 
@@ -26,7 +26,7 @@ namespace CamelotEngine
 		screenPos.x = pos.x;
 		screenPos.y = pos.y;
 
-		RenderWindow* primaryWindow = gApplication().getPrimaryRenderWindow();
+		RenderWindowPtr primaryWindow = gApplication().getPrimaryRenderWindow();
 		HWND hwnd;
 		primaryWindow->getCustomAttribute_internal("WINDOW", &hwnd);
 
@@ -41,7 +41,7 @@ namespace CamelotEngine
 
 		ShowCursor( FALSE );
 
-		RenderWindow* primaryWindow = gApplication().getPrimaryRenderWindow();
+		RenderWindowPtr primaryWindow = gApplication().getPrimaryRenderWindow();
 		HWND hwnd;
 		primaryWindow->getCustomAttribute_internal("WINDOW", &hwnd);
 

+ 4 - 1
CamelotRenderer/TODO.txt

@@ -20,6 +20,10 @@
 Check out how to deal with clip planes so that both DX9, DX11 and GL support them
 waitForVsync can probably be moved somewhere other than being directly in RenderSystem? (where is it in DX11?)
 
+Move createRenderTexture to TextureManager? (also createMultiRenderTexture)
+ - Right now its created with a special texture usage flag, which I don't like
+Drop OpenGL support for low level shaders? (See if cg can translate to GLSL)
+
 Rasterizer state:
  D3DRS_MULTISAMPLEANTIALIAS
  - but first check if available using D3DPRASTERCAPS_MULTISAMPLE_TOGGLE
@@ -27,7 +31,6 @@ Rasterizer state:
  - see if either dx9 or opengl have something similar to DX11 antialias line
 
 Move createRenderWindow outside of RenderSystem
-RenderSystem::setRenderTarget needs to accept multiple targets
 
 Make CommandQueue not use mutexes and use atomics instead??
 Make sure that the simulation can't run faster then the render thread! (Block the main thread until previous render finishes)