Bläddra i källkod

Overhauled OpenGL context handling
Made sure all render systems create window on creation

Marko Pintera 12 år sedan
förälder
incheckning
aa46b8b57a

+ 1 - 1
BansheeEngine/Include/BsApplication.h

@@ -13,7 +13,7 @@ namespace BansheeEngine
 			 * @brief	Starts the application using the specified options. 
 			 * 			This is how you start the engine.
 			 */
-			void startUp(const CM::String& renderSystem, const CM::String& renderer, const CM::String& resourceCacheDir);
+			void startUp(CM::RENDER_WINDOW_DESC& primaryWindowDesc, const CM::String& renderSystem, const CM::String& renderer, const CM::String& resourceCacheDir);
 
 			/**
 			 * @brief	Executes the main loop. This will cause actually rendering to be performed

+ 2 - 1
BansheeEngine/Source/BsApplication.cpp

@@ -17,12 +17,13 @@ namespace BansheeEngine
 
 	}
 
-	void Application::startUp(const String& renderSystem, const String& renderer, const String& resourceCacheDir)
+	void Application::startUp(RENDER_WINDOW_DESC& primaryWindowDesc, const String& renderSystem, const String& renderer, const String& resourceCacheDir)
 	{
 		CM::START_UP_DESC desc;
 		desc.renderSystem = renderSystem;
 		desc.renderer= renderer;
 		desc.resourceCacheDirectory = resourceCacheDir;
+		desc.primaryWindowDesc = primaryWindowDesc;
 
 		desc.input = "CamelotOISInput";
 		desc.sceneManager = "BansheeOctreeSM";

+ 14 - 8
CamelotClient/CamelotClient.cpp

@@ -29,8 +29,8 @@
 #include "CmEditorWindow.h"
 
 //#define DX11
-//#define DX9
-#define GL
+#define DX9
+//#define GL
 
 using namespace CamelotFramework;
 using namespace CamelotEditor;
@@ -43,12 +43,18 @@ int CALLBACK WinMain(
 	_In_  int nCmdShow
 	)
 {
+	RENDER_WINDOW_DESC renderWindowDesc;
+	renderWindowDesc.width = 1280;
+	renderWindowDesc.height = 720;
+	renderWindowDesc.title = "Banshee";
+	renderWindowDesc.fullscreen = false;
+
 #ifdef DX11
-	gBansheeApp().startUp("CamelotD3D11RenderSystem", "BansheeForwardRenderer", "D:\\CamelotResourceMetas");
+	gBansheeApp().startUp(renderWindowDesc, "CamelotD3D11RenderSystem", "BansheeForwardRenderer", "D:\\CamelotResourceMetas");
 #elif defined DX9
-	gBansheeApp().startUp("CamelotD3D9RenderSystem", "BansheeForwardRenderer", "D:\\CamelotResourceMetas");
+	gBansheeApp().startUp(renderWindowDesc, "CamelotD3D9RenderSystem", "BansheeForwardRenderer", "D:\\CamelotResourceMetas");
 #else
-	gBansheeApp().startUp("CamelotGLRenderSystem", "BansheeForwardRenderer", "D:\\CamelotResourceMetas");
+	gBansheeApp().startUp(renderWindowDesc, "CamelotGLRenderSystem", "BansheeForwardRenderer", "D:\\CamelotResourceMetas");
 #endif
 
 	//CommandQueue::addBreakpoint(0, 19);
@@ -72,8 +78,8 @@ int CALLBACK WinMain(
 	HSceneObject testModelGO = SceneObject::create("TestMesh");
 	HRenderable testRenderable = testModelGO->addComponent<Renderable>();
 
-	//HSceneObject testTextGO = SceneObject::create("TestText");
-	//GameObjectHandle<TestTextSprite> textSprite = testTextGO->addComponent<TestTextSprite>();
+	HSceneObject testTextGO = SceneObject::create("TestText");
+	GameObjectHandle<TestTextSprite> textSprite = testTextGO->addComponent<TestTextSprite>();
 
 	HFont font;
 	
@@ -96,7 +102,7 @@ int CALLBACK WinMain(
 
 	windowFrameTex.waitUntilLoaded();
 
-	//textSprite->init(camera, "Testing in a new row, does this work?", font, 12, windowFrameTex);
+	textSprite->init(camera, "Testing in a new row, does this work?", font, 12, windowFrameTex);
 
 #if defined DX9
 	///////////////// HLSL 9 SHADERS //////////////////////////

+ 4 - 1
CamelotCore/Include/CmApplication.h

@@ -2,6 +2,7 @@
 
 #include "CmPrerequisites.h"
 #include "CmHighLevelGpuProgram.h"
+#include "CmRenderWindow.h"
 
 namespace CamelotFramework
 {
@@ -20,6 +21,8 @@ namespace CamelotFramework
 		String input;
 		String sceneManager;
 
+		RENDER_WINDOW_DESC primaryWindowDesc;
+
 		std::vector<String> importers;
 
 		String resourceCacheDirectory;
@@ -34,7 +37,7 @@ namespace CamelotFramework
 			 * @brief	Starts the application using the specified options. 
 			 * 			This is how you start the engine.
 			 */
-			void startUp(const START_UP_DESC& desc);
+			void startUp(START_UP_DESC& desc);
 
 			/**
 			 * @brief	Executes the main loop. This will cause actually rendering to be performed

+ 1 - 0
CamelotCore/Include/CmPrerequisites.h

@@ -173,6 +173,7 @@ namespace CamelotFramework {
 	struct BLEND_STATE_DESC;
 	struct RENDER_TARGET_BLEND_STATE_DESC;
 	struct RENDER_TEXTURE_DESC;
+	struct RENDER_WINDOW_DESC;
 	struct FONT_DESC;
 }
 

+ 10 - 3
CamelotCore/Include/CmRenderSystem.h

@@ -42,6 +42,7 @@ THE SOFTWARE.
 #include "CmRenderSystemCapabilities.h"
 #include "CmRenderTarget.h"
 #include "CmRenderTexture.h"
+#include "CmRenderWindow.h"
 #include "CmGpuProgram.h"
 #include "CmPlane.h"
 #include "CmModule.h"
@@ -370,11 +371,17 @@ namespace CamelotFramework
 		/// Used to store the capabilities of the graphics card
 		RenderSystemCapabilities* mCurrentCapabilities;
 
+		// TODO - Only used between initialize and initialize_internal. Handle it better?
+		RENDER_WINDOW_DESC mPrimaryWindowDesc;
+
 		/**
-		 * @brief	Call right after creation to properly initialize the RenderSystem;
+		 * @brief	Initializes the render system and creates a primary render window.
+		 * 			
+		 * @note	Although I'd like otherwise, due to the nature of some render system implementations, 
+		 * 			you cannot initialize the render system without a window.
 		 */
-		void initialize();
-		virtual void initialize_internal();
+		RenderWindowPtr initialize(const RENDER_WINDOW_DESC& primaryWindowDesc);
+		virtual void initialize_internal(AsyncOp& asyncOp);
 		virtual void destroy_internal();
 
 		/// Internal method used to set the underlying clip planes when needed

+ 1 - 1
CamelotCore/Include/CmRenderSystemManager.h

@@ -11,7 +11,7 @@ namespace CamelotFramework
 	class CM_EXPORT RenderSystemManager : public Module<RenderSystemManager>
 	{
 	public:
-		void setActive(const String& name);
+		RenderWindowPtr initialize(const String& name, RENDER_WINDOW_DESC& primaryWindowDesc);
 
 		void registerRenderSystemFactory(RenderSystemFactoryPtr factory);
 	private:

+ 2 - 14
CamelotCore/Source/CmApplication.cpp

@@ -40,7 +40,7 @@ namespace CamelotFramework
 		:mPrimaryRenderWindow(nullptr), mIsFrameRenderingFinished(true), mRunMainLoop(false)
 	{ }
 
-	void Application::startUp(const START_UP_DESC& desc)
+	void Application::startUp(START_UP_DESC& desc)
 	{
 		Time::startUp(CM_NEW(Time, GenAlloc) Time());
 		Input::startUp(CM_NEW(Input, GenAlloc) Input());
@@ -50,7 +50,7 @@ namespace CamelotFramework
 		HighLevelGpuProgramManager::startUp(CM_NEW(HighLevelGpuProgramManager, GenAlloc) HighLevelGpuProgramManager());
 
 		RenderSystemManager::startUp(CM_NEW(RenderSystemManager, GenAlloc) RenderSystemManager());
-		RenderSystemManager::instance().setActive(desc.renderSystem);
+		mPrimaryRenderWindow = RenderSystemManager::instance().initialize(desc.renderSystem, desc.primaryWindowDesc);
 
 		RendererManager::startUp(CM_NEW(RendererManager, GenAlloc) RendererManager());
 
@@ -59,18 +59,6 @@ namespace CamelotFramework
 
 		RenderSystem* renderSystem = RenderSystem::instancePtr();
 
-		RENDER_WINDOW_DESC renderWindowDesc;
-		renderWindowDesc.width = 1280;
-		renderWindowDesc.height = 720;
-		renderWindowDesc.title = "Camelot Renderer";
-		renderWindowDesc.fullscreen = false;
-
-		mPrimaryRenderWindow = RenderWindow::create(renderWindowDesc);
-		mPrimaryRenderWindow->waitUntilInitialized(); // TODO: Created window is required for proper initialization of the render system so I need to wait.
-		                                              // I plan on handling this differently. Either by somehow allowing the RS to be initialized without a window,
-		                                              // or forcing a window to be created with RenderSystemManager::startUp. Initializing OpenGL context without a window
-		                                              // is especially troublesome (apparently possible just poorly documented)
-
 		mPrimaryRenderContext = renderSystem->createDeferredContext();
 
 		SceneManager::startUp((SceneManager*)loadPlugin(desc.sceneManager));

+ 5 - 3
CamelotCore/Source/CmRenderSystem.cpp

@@ -89,17 +89,19 @@ namespace CamelotFramework {
 		mCurrentCapabilities = nullptr;
     }
 	//-----------------------------------------------------------------------
-	void RenderSystem::initialize()
+	RenderWindowPtr RenderSystem::initialize(const RENDER_WINDOW_DESC& primaryWindowDesc)
 	{
 		mRenderThreadId = CM_THREAD_CURRENT_ID;
 		mCommandQueue = CM_NEW(CommandQueue, GenAlloc) CommandQueue(CM_THREAD_CURRENT_ID, true);
+		mPrimaryWindowDesc = primaryWindowDesc;
 
 		initRenderThread();
 
-		queueCommand(boost::bind(&RenderSystem::initialize_internal, this), true);
+		AsyncOp op = queueReturnCommand(boost::bind(&RenderSystem::initialize_internal, this, _1), true);
+		return op.getReturnValue<RenderWindowPtr>();
 	}
 	//-----------------------------------------------------------------------
-	void RenderSystem::initialize_internal()
+	void RenderSystem::initialize_internal(AsyncOp& asyncOp)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 

+ 4 - 2
CamelotCore/Source/CmRenderSystemManager.cpp

@@ -6,7 +6,7 @@
 
 namespace CamelotFramework
 {
-	void RenderSystemManager::setActive(const String& pluginFilename)
+	RenderWindowPtr RenderSystemManager::initialize(const String& pluginFilename, RENDER_WINDOW_DESC& primaryWindowDesc)
 	{
 		DynLib* loadedLibrary = gDynLibManager().load(pluginFilename);
 		String name = "";
@@ -24,9 +24,11 @@ namespace CamelotFramework
 			if((*iter)->name() == name)
 			{
 				(*iter)->create();		
-				RenderSystem::instance().initialize();
+				return RenderSystem::instance().initialize(primaryWindowDesc);
 			}
 		}
+
+		return nullptr;
 	}
 
 	void RenderSystemManager::registerRenderSystemFactory(RenderSystemFactoryPtr factory)

+ 1 - 1
CamelotD3D11RenderSystem/Include/CmD3D11RenderSystem.h

@@ -90,7 +90,7 @@ namespace CamelotFramework
 		/**
 		 * @copydoc	RenderSystem::initialize_internal().
 		 */
-		void initialize_internal();
+		void initialize_internal(AsyncOp& asyncOp);
 
 		/**
 		 * @copydoc	RenderSystem::destroy_internal().

+ 6 - 2
CamelotD3D11RenderSystem/Source/CmD3D11RenderSystem.cpp

@@ -59,7 +59,7 @@ namespace CamelotFramework
 		return strName;
 	}
 
-	void D3D11RenderSystem::initialize_internal()
+	void D3D11RenderSystem::initialize_internal(AsyncOp& asyncOp)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
@@ -132,7 +132,11 @@ namespace CamelotFramework
 
 		mIAManager = CM_NEW(D3D11InputLayoutManager, GenAlloc) D3D11InputLayoutManager();
 
-		RenderSystem::initialize_internal();
+		RenderWindowPtr primaryWindow = RenderWindow::create(mPrimaryWindowDesc);
+
+		RenderSystem::initialize_internal(asyncOp);
+
+		asyncOp.completeOperation(primaryWindow);
 	}
 
     void D3D11RenderSystem::destroy_internal()

+ 0 - 4
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -256,10 +256,6 @@ namespace CamelotFramework
 		mDXGIFactory->MakeWindowAssociation(mHWnd, NULL);
 		setHidden(mHidden);
 
-		RenderSystem* rs = RenderSystem::instancePtr();
-		D3D11RenderSystem* d3d11rs = static_cast<D3D11RenderSystem*>(rs);
-		d3d11rs->_notifyWindowCreated(*this);
-
 		RenderWindow::initialize_internal();
 	}
 

+ 1 - 1
CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h

@@ -260,7 +260,7 @@ namespace CamelotFramework
 		friend class D3D9DeviceManager;		
 		friend class D3D9RenderWindowManager;
 
-		void initialize_internal();
+		void initialize_internal(AsyncOp& asyncOp);
 		void destroy_internal();
 
 		void setClipPlanesImpl(const PlaneList& clipPlanes);	

+ 2 - 2
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -133,7 +133,7 @@ namespace CamelotFramework
 		return strName;
 	}
 
-	void D3D9RenderSystem::initialize_internal()
+	void D3D9RenderSystem::initialize_internal(AsyncOp& asyncOp)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
@@ -183,7 +183,7 @@ namespace CamelotFramework
 		RenderStateManager::startUp(CM_NEW(RenderStateManager, GenAlloc) RenderStateManager());
 
 		// call superclass method
-		RenderSystem::initialize_internal();
+		RenderSystem::initialize_internal(asyncOp);
 	}
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::destroy_internal()

+ 0 - 5
CamelotGLRenderer/Include/CmGLContext.h

@@ -54,15 +54,10 @@ namespace CamelotFramework {
          */
         virtual void endCurrent() = 0;
         
-        bool getInitialized() { return initialized; };
-        void setInitialized() { initialized = true; };
-
 		/**
 		* Release the render context.
 		*/
 		virtual void releaseContext() {}
-    protected:
-        bool initialized;
     };
 }
 

+ 4 - 10
CamelotGLRenderer/Include/CmGLRenderSystem.h

@@ -193,9 +193,9 @@ namespace CamelotFramework {
 		/* 				Internal use by OpenGL RenderSystem only                */
 		/************************************************************************/
 
-        void unregisterContext(GLContext *context);
-		void registerContext(GLContext* context);
+		bool isContextInitialized() const { return mGLInitialised; }
 
+		GLContext* getMainContext() const { return mMainContext; } 
 		GLSupport* getGLSupport() const { return mGLSupport; }
 
     private:
@@ -227,7 +227,7 @@ namespace CamelotFramework {
  
         GLint getBlendMode(BlendFactor ogreBlend) const;
 		GLint getTextureAddressingMode(TextureAddressingMode tam) const;
-		void initialiseContext(GLContext* primary);
+		void initializeContext(GLContext* primary);
 
 		/** See
           RenderSystem
@@ -285,11 +285,8 @@ namespace CamelotFramework {
 		IndexBufferPtr mBoundIndexBuffer;
 		DrawOperationType mCurrentDrawOperation;
 
-		/* The main GL context - main thread only */
         GLContext *mMainContext;
-        /* The current GL context  - main thread only */
         GLContext *mCurrentContext;
-		typedef list<GLContext*>::type GLContextList;
 
 		vector<GLuint>::type mBoundAttributes; // Only full between begin/endDraw calls
 		bool mDrawCallInProgress;
@@ -300,7 +297,7 @@ namespace CamelotFramework {
 		/**
 		 * @copydoc	RenderSystem::initialize_internal().
 		 */
-		void initialize_internal();
+		void initialize_internal(AsyncOp& asyncOp);
 
 		/**
 		 * @copydoc	RenderSystem::destroy_internal().
@@ -583,9 +580,6 @@ namespace CamelotFramework {
 
 		void setActiveProgram(GpuProgramType gptype, GLSLGpuProgramPtr program);
 		GLSLGpuProgramPtr getActiveProgram(GpuProgramType gptype) const;
-
-		/** Returns the main context */
-		GLContext* _getMainContext() {return mMainContext;} 
     };
 }
 #endif

+ 6 - 8
CamelotGLRenderer/Source/CmGLContext.cpp

@@ -30,16 +30,14 @@ THE SOFTWARE.
 
 namespace CamelotFramework {
     // Empty base class
-    GLContext::GLContext():
-        initialized(false) {
-    }
+    GLContext::GLContext()
+	{ }
     
-    GLContext::~GLContext() {        
-    }
-    
-    void GLContext::endCurrent() {
-    }
+    GLContext::~GLContext() 
+	{ }
     
+    void GLContext::endCurrent() 
+	{ } 
 }
 
 #if CM_THREAD_SUPPORT == 1

+ 40 - 69
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -136,7 +136,7 @@ namespace CamelotFramework
 		return strName;
 	}
 
-	void GLRenderSystem::initialize_internal()
+	void GLRenderSystem::initialize_internal(AsyncOp& asyncOp)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
@@ -145,7 +145,44 @@ namespace CamelotFramework
 
 		RenderStateManager::startUp(CM_NEW(RenderStateManager, GenAlloc) RenderStateManager());
 
-		RenderSystem::initialize_internal();
+		// Initialize a window so we have something to create a GL context with
+		RenderWindowPtr primaryWindow = RenderWindow::create(mPrimaryWindowDesc);
+		             
+		// Get the context from the window and finish initialization
+		GLContext *context = nullptr;
+		primaryWindow->getCustomAttribute("GLCONTEXT", &context);
+		initializeContext(context);
+
+		checkForErrors();
+
+		std::vector<CamelotFramework::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();
+		checkForErrors();
+
+		initialiseFromRenderSystemCapabilities(mCurrentCapabilities);
+		checkForErrors();
+
+		// Initialise the main context
+		oneTimeContextInitialization();
+		checkForErrors();
+
+		mGLInitialised = true;
+
+		RenderSystem::initialize_internal(asyncOp);
+
+		asyncOp.completeOperation(primaryWindow);
 	}
 
 	void GLRenderSystem::destroy_internal()
@@ -1331,13 +1368,6 @@ namespace CamelotFramework
 		mCurrentContext = context;
 		mCurrentContext->setCurrent();
 
-		// Check if the context has already done one-time initialisation
-		if(!mCurrentContext->getInitialized()) 
-		{
-			oneTimeContextInitialization();
-			mCurrentContext->setInitialized();
-		}
-
 		// Must reset depth/colour write mask to according with user desired, otherwise,
 		// clearFrameBuffer would be wrong because the value we are recorded may be
 		// difference with the really state stored in GL context.
@@ -1347,63 +1377,6 @@ namespace CamelotFramework
 
 	}
 	//---------------------------------------------------------------------
-	void GLRenderSystem::registerContext(GLContext* context)
-	{
-		if (!mGLInitialised) 
-		{                
-			// set up glew and GLSupport
-			initialiseContext(context);
-
-			checkForErrors();
-
-			std::vector<CamelotFramework::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();
-			checkForErrors();
-
-			initialiseFromRenderSystemCapabilities(mCurrentCapabilities);
-			checkForErrors();
-
-			// Initialise the main context
-			oneTimeContextInitialization();
-			checkForErrors();
-
-			if(mCurrentContext)
-			{
-				mCurrentContext->setInitialized();
-				checkForErrors();
-			}
-		}
-	}
-	//---------------------------------------------------------------------
-	void GLRenderSystem::unregisterContext(GLContext *context)
-	{
-		if(mCurrentContext == context) {
-			// Change the context to something else so that a valid context
-			// remains active. When this is the main context being unregistered,
-			// we set the main context to 0.
-			if(mCurrentContext != mMainContext) {
-				switchContext(mMainContext);
-			} else {
-				/// No contexts remain
-				mCurrentContext->endCurrent();
-				mCurrentContext = 0;
-				mMainContext = 0;
-			}
-		}
-	}
-	//---------------------------------------------------------------------
 	bool GLRenderSystem::activateGLTextureUnit(UINT16 unit)
 	{
 		if (mActiveTextureUnit != unit)
@@ -1763,7 +1736,7 @@ namespace CamelotFramework
 		return primType;
 	}
 	//-----------------------------------------------------------------------
-	void GLRenderSystem::initialiseContext(GLContext* primary)
+	void GLRenderSystem::initializeContext(GLContext* primary)
 	{
 		// Set main and current context
 		mMainContext = primary;
@@ -1907,8 +1880,6 @@ namespace CamelotFramework
 		/// Create the texture manager        
 		TextureManager::startUp(CM_NEW(GLTextureManager, GenAlloc) GLTextureManager(*mGLSupport)); 
 		checkForErrors();
-
-		mGLInitialised = true;
 	}
 
 	RenderSystemCapabilities* GLRenderSystem::createRenderSystemCapabilities() const

+ 18 - 38
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -288,9 +288,6 @@ namespace CamelotFramework {
 			WindowEventUtilities::_addRenderWindow(this);			
 		}
 
-		HDC old_hdc = wglGetCurrentDC();
-		HGLRC old_context = wglGetCurrentContext();
-
 		RECT rc;
 		// top and left represent outer window position
 		GetWindowRect(mHWnd, &rc);
@@ -342,51 +339,34 @@ namespace CamelotFramework {
 			mHwGamma = testHwGamma;
 			mFSAA = testFsaa;
 		}
-		if (!mIsExternalGLContext)
-		{
-			mGlrc = wglCreateContext(mHDC);
-			if (!mGlrc)
-			{
-				CM_EXCEPT(RenderingAPIException, 
-					"wglCreateContext failed: " + translateWGLError());
-			}
-		}
+		
+		mActive = true;
+
+		GLRenderSystem* rs = static_cast<GLRenderSystem*>(RenderSystem::instancePtr());
 
-		if (!wglMakeCurrent(mHDC, mGlrc))
+		// If RenderSystem has initialized a context use that, otherwise we create our own
+		if(!rs->isContextInitialized())
 		{
-			CM_EXCEPT(RenderingAPIException, "wglMakeCurrent");
-		}
+			if (!mIsExternalGLContext)
+			{
+				mGlrc = wglCreateContext(mHDC);
 
-		// Do not change vsync if the external window has the OpenGL control
-		if (!mIsExternalGLControl) {
-			// Don't use wglew as if this is the first window, we won't have initialised yet
-			PFNWGLSWAPINTERVALEXTPROC _wglSwapIntervalEXT = 
-				(PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
-			if (_wglSwapIntervalEXT)
-				_wglSwapIntervalEXT(mDesc.vsync ? mDesc.vsyncInterval : 0);
+				if (!mGlrc)
+				{
+					CM_EXCEPT(RenderingAPIException, 
+						"wglCreateContext failed: " + translateWGLError());
+				}
+			}
 		}
-
-		if (old_context && old_context != mGlrc)
+		else
 		{
-			// Restore old context
-			if (!wglMakeCurrent(old_hdc, old_context))
-				CM_EXCEPT(RenderingAPIException, "wglMakeCurrent() failed");
-
-			// Share lists with old context
-			if (!wglShareLists(old_context, mGlrc))
-				CM_EXCEPT(RenderingAPIException, "wglShareLists() failed");
+			rs->getMainContext()->setCurrent();
+			mGlrc = wglGetCurrentContext();
 		}
 
 		// Create RenderSystem context
 		mContext = CM_NEW(Win32Context, GenAlloc) Win32Context(mHDC, mGlrc);
 
-		mActive = true;
-
-		GLRenderSystem* rs = static_cast<GLRenderSystem*>(RenderSystem::instancePtr());
-
-		rs->_notifyWindowCreated(*this);
-		rs->registerContext(mContext);
-
 		RenderWindow::initialize_internal();
 	}
 

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

@@ -31,7 +31,6 @@ THE SOFTWARE.
 #endif
 #include "CmWin32Context.h"
 #include "CmException.h"
-#include "CmGLRenderSystem.h"
 
 namespace CamelotFramework {
 
@@ -44,10 +43,7 @@ namespace CamelotFramework {
     
     Win32Context::~Win32Context()
     {
-		// 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*>(CamelotFramework::RenderSystem::instancePtr());
-		rs->unregisterContext(this);
+
     }
         
     void Win32Context::setCurrent()

+ 3 - 7
TODO.txt

@@ -3,8 +3,6 @@
 ----------------------------------------------------------------------------------------------
 <<<<<<OpenGL issues>>>>>>>
 Camera in new window in OpenGL doesn't render anything
-Destroying OpenGL window doesn't work
-OpenGL camera/rendering is acting really jerky and weird
 
 -------------
 
@@ -14,10 +12,6 @@ When I'm canceling command queue commands I might be canceling important user co
  - maybe I should someone block sim thread if its running too fast?
    - input lag?
 
-Shared GPU buffers
- - wouldn't work atm due to the way I update the buffers (and the way I mark them dirty)
- - Material::setParamBlock is commented out
-
 <<<<<<<Resource update/read>>>>>>>>
 All data classes (MeshData, PixelData, etc) derive from GpuBufferData class. 
  - It contains basically just raw bytes.
@@ -196,7 +190,9 @@ Low priority TODO
   - Resources::unload will deadlock if the resource isn't being loaded!
     - Maybe re-think how I handle ResourceHandle.isCreated?
   - Check D3D9/D3D11/GL resource usages. DX11 reports many unreleased objects. I'm guessing DX9 will as well. Not sure how to check OpenGL.
-
+ - Shared GPU buffers
+   - wouldn't work atm due to the way I update the buffers (and the way I mark them dirty)
+   - Material::setParamBlock is commented out
 ----------------------------------------------------------------------------------------------
 Optional:
  - Need better handling for shader techniques. Some Materials are able to run on all renderers yet I can only specify one. This is problematic