Ver Fonte

RenderSystem is now a module

Marko Pintera há 13 anos atrás
pai
commit
e94ca6b9d6

+ 2 - 2
CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h

@@ -244,8 +244,8 @@ namespace CamelotEngine
 		friend class D3D9DeviceManager;		
 		friend class D3D9DeviceManager;		
 		friend class D3D9RenderWindowManager;
 		friend class D3D9RenderWindowManager;
 
 
-		void startUp_internal();
-		void shutdown_internal();
+		void initialize_internal();
+		void destroy_internal();
 
 
 		void setClipPlanesImpl(const PlaneList& clipPlanes);	
 		void setClipPlanesImpl(const PlaneList& clipPlanes);	
 
 

+ 1 - 1
CamelotD3D9Renderer/Include/CmD3D9RenderSystemFactory.h

@@ -12,7 +12,7 @@ namespace CamelotEngine
 	class D3D9RenderSystemFactory : public RenderSystemFactory
 	class D3D9RenderSystemFactory : public RenderSystemFactory
 	{
 	{
 		public:
 		public:
-			virtual RenderSystemPtr create();
+			virtual void create();
 			virtual const std::string& name() const { return SystemName; }
 			virtual const std::string& name() const { return SystemName; }
 
 
 		private:
 		private:

+ 5 - 5
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -111,7 +111,7 @@ namespace CamelotEngine
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
 	D3D9RenderSystem::~D3D9RenderSystem()
 	D3D9RenderSystem::~D3D9RenderSystem()
 	{		
 	{		
-		shutdown_internal();
+		destroy_internal();
 
 
 		// Deleting the HLSL program factory
 		// Deleting the HLSL program factory
 		if (mHLSLProgramFactory)
 		if (mHLSLProgramFactory)
@@ -139,7 +139,7 @@ namespace CamelotEngine
 		static String strName( "D3D9RenderSystem");
 		static String strName( "D3D9RenderSystem");
 		return strName;
 		return strName;
 	}
 	}
-	void D3D9RenderSystem::startUp_internal()
+	void D3D9RenderSystem::initialize_internal()
 	{
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 		THROW_IF_NOT_RENDER_THREAD;
 
 
@@ -215,12 +215,12 @@ namespace CamelotEngine
 		RenderWindowManager::startUp(new D3D9RenderWindowManager(this));
 		RenderWindowManager::startUp(new D3D9RenderWindowManager(this));
 
 
 		// call superclass method
 		// call superclass method
-		RenderSystem::startUp_internal();
+		RenderSystem::initialize_internal();
 	}
 	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::shutdown_internal()
+	void D3D9RenderSystem::destroy_internal()
 	{
 	{
-		RenderSystem::shutdown_internal();
+		RenderSystem::destroy_internal();
 
 
 		SAFE_DELETE( mDeviceManager );
 		SAFE_DELETE( mDeviceManager );
 
 

+ 3 - 2
CamelotD3D9Renderer/Source/CmD3D9RenderSystemFactory.cpp

@@ -1,8 +1,9 @@
 #include "CmD3D9RenderSystemFactory.h"
 #include "CmD3D9RenderSystemFactory.h"
+#include "CmRenderSystem.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
-	RenderSystemPtr D3D9RenderSystemFactory::create()
+	void D3D9RenderSystemFactory::create()
 	{
 	{
 	#ifdef CM_STATIC_LIB
 	#ifdef CM_STATIC_LIB
 		HINSTANCE hInst = GetModuleHandle( NULL );
 		HINSTANCE hInst = GetModuleHandle( NULL );
@@ -10,7 +11,7 @@ namespace CamelotEngine
 		HINSTANCE hInst = GetModuleHandle( "CamelotD3D9RenderSystem.dll" );
 		HINSTANCE hInst = GetModuleHandle( "CamelotD3D9RenderSystem.dll" );
 	#endif
 	#endif
 
 
-		return RenderSystemPtr(new D3D9RenderSystem(hInst));
+		RenderSystem::startUp(new D3D9RenderSystem(hInst));
 	}
 	}
 
 
 	D3D9RenderSystemFactory::InitOnStart D3D9RenderSystemFactory::initOnStart;
 	D3D9RenderSystemFactory::InitOnStart D3D9RenderSystemFactory::initOnStart;

+ 2 - 2
CamelotGLRenderer/Include/CmGLRenderSystem.h

@@ -272,11 +272,11 @@ namespace CamelotEngine {
 		/** See
 		/** See
           RenderSystem
           RenderSystem
          */
          */
-		void startUp_internal();
+		void initialize_internal();
 		/** See
 		/** See
           RenderSystem
           RenderSystem
          */
          */
-        void shutdown_internal(void);
+        void destroy_internal(void);
 
 
 		void setClipPlanesImpl(const PlaneList& clipPlanes);
 		void setClipPlanesImpl(const PlaneList& clipPlanes);
 		bool activateGLTextureUnit(UINT16 unit);
 		bool activateGLTextureUnit(UINT16 unit);

+ 1 - 1
CamelotGLRenderer/Include/CmGLRenderSystemFactory.h

@@ -12,7 +12,7 @@ namespace CamelotEngine
 	class GLRenderSystemFactory : public RenderSystemFactory
 	class GLRenderSystemFactory : public RenderSystemFactory
 	{
 	{
 	public:
 	public:
-		virtual RenderSystemPtr create();
+		virtual void create();
 		virtual const std::string& name() const { return SystemName; }
 		virtual const std::string& name() const { return SystemName; }
 
 
 	private:
 	private:

+ 5 - 5
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -131,7 +131,7 @@ namespace CamelotEngine {
 
 
 	GLRenderSystem::~GLRenderSystem()
 	GLRenderSystem::~GLRenderSystem()
 	{
 	{
-		shutdown_internal();
+		destroy_internal();
 
 
 		// Destroy render windows
 		// Destroy render windows
 		for (auto i = mRenderTargets.begin(); i != mRenderTargets.end(); ++i)
 		for (auto i = mRenderTargets.begin(); i != mRenderTargets.end(); ++i)
@@ -151,19 +151,19 @@ namespace CamelotEngine {
 		return strName;
 		return strName;
 	}
 	}
 
 
-	void GLRenderSystem::startUp_internal()
+	void GLRenderSystem::initialize_internal()
 	{
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 		THROW_IF_NOT_RENDER_THREAD;
 
 
 		mGLSupport->start();
 		mGLSupport->start();
 		RenderWindowManager::startUp(new GLRenderWindowManager(this));
 		RenderWindowManager::startUp(new GLRenderWindowManager(this));
 
 
-		RenderSystem::startUp_internal();
+		RenderSystem::initialize_internal();
 	}
 	}
 
 
-	void GLRenderSystem::shutdown_internal(void)
+	void GLRenderSystem::destroy_internal(void)
 	{
 	{
-		RenderSystem::shutdown_internal();
+		RenderSystem::destroy_internal();
 
 
 		// Deleting the GLSL program factory
 		// Deleting the GLSL program factory
 		if (mGLSLProgramFactory)
 		if (mGLSLProgramFactory)

+ 3 - 2
CamelotGLRenderer/Source/CmGLRenderSystemFactory.cpp

@@ -1,10 +1,11 @@
 #include "CmGLRenderSystemFactory.h"
 #include "CmGLRenderSystemFactory.h"
+#include "CmGLRenderSystem.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
-	RenderSystemPtr GLRenderSystemFactory::create()
+	void GLRenderSystemFactory::create()
 	{
 	{
-		return RenderSystemPtr(new GLRenderSystem());
+		RenderSystem::startUp(new GLRenderSystem());
 	}
 	}
 
 
 	GLRenderSystemFactory::InitOnStart GLRenderSystemFactory::initOnStart;
 	GLRenderSystemFactory::InitOnStart GLRenderSystemFactory::initOnStart;

+ 10 - 26
CamelotRenderer/Include/CmRenderSystem.h

@@ -44,6 +44,7 @@ THE SOFTWARE.
 #include "CmRenderTexture.h"
 #include "CmRenderTexture.h"
 #include "CmGpuProgram.h"
 #include "CmGpuProgram.h"
 #include "CmPlane.h"
 #include "CmPlane.h"
+#include "CmModule.h"
 
 
 #include "boost/function.hpp"
 #include "boost/function.hpp"
 #include "boost/signal.hpp"
 #include "boost/signal.hpp"
@@ -69,22 +70,12 @@ namespace CamelotEngine
 	methods have implementations, most of this class is
 	methods have implementations, most of this class is
 	abstract, requiring a subclass based on a specific API
 	abstract, requiring a subclass based on a specific API
 	to be constructed to provide the full functionality.
 	to be constructed to provide the full functionality.
-	Note there are 2 levels to the interface - one which
-	will be used often by the caller of the Ogre library,
-	and one which is at a lower level and will be used by the
-	other classes provided by Ogre. These lower level
-	methods are prefixed with '_' to differentiate them.
-	The advanced user of the library may use these lower
-	level methods to access the 3D API at a more fundamental
-	level (dealing direct with render states and rendering
-	primitives), but still benefiting from Ogre's abstraction
-	of exactly which 3D API is in use.
 	@author
 	@author
 	Steven Streeting
 	Steven Streeting
 	@version
 	@version
 	1.0
 	1.0
 	*/
 	*/
-	class CM_EXPORT RenderSystem
+	class CM_EXPORT RenderSystem : public Module<RenderSystem>
 	{
 	{
 	public:
 	public:
 		/** Default Constructor.
 		/** Default Constructor.
@@ -99,19 +90,6 @@ namespace CamelotEngine
 		*/
 		*/
 		virtual const String& getName(void) const = 0;
 		virtual const String& getName(void) const = 0;
 
 
-		 /* @brief	Start up the RenderSystem. Call before doing any operations on the render system.  
-		 *			Make sure all subsequent calls to the RenderSystem are done from the same thread it was started on.  
-		 *
-		 * @remark	If you want to access the render system from other threads, call RenderSystem::createRenderContext,
-		 * 			set the active context using RenderSystem::setActiveRenderContext and call the render system normally.
-		 * 			By default an automatically created primary render context is used.
-		 */
-		void startUp();
-
-		/** Shutdown the renderer and cleanup resources.
-		*/
-		void shutdown(void);
-
 		/** Attaches the passed render target to the render system.
 		/** Attaches the passed render target to the render system.
 		*/
 		*/
 		virtual void attachRenderTarget(RenderTarget &target);
 		virtual void attachRenderTarget(RenderTarget &target);
@@ -386,6 +364,8 @@ namespace CamelotEngine
 		/* 						INTERNAL DATA & METHODS                      	*/
 		/* 						INTERNAL DATA & METHODS                      	*/
 		/************************************************************************/
 		/************************************************************************/
 	protected:
 	protected:
+		friend class RenderSystemManager;
+
 		/** The render targets. */
 		/** The render targets. */
 		vector<RenderTarget*>::type mRenderTargets;
 		vector<RenderTarget*>::type mRenderTargets;
 		/** The render targets, ordered by priority. */
 		/** The render targets, ordered by priority. */
@@ -422,8 +402,12 @@ namespace CamelotEngine
 		/// Used to store the capabilities of the graphics card
 		/// Used to store the capabilities of the graphics card
 		RenderSystemCapabilities* mCurrentCapabilities;
 		RenderSystemCapabilities* mCurrentCapabilities;
 
 
-		virtual void startUp_internal();
-		virtual void shutdown_internal();
+		/**
+		 * @brief	Call right after creation to properly initialize the RenderSystem;
+		 */
+		void initialize();
+		virtual void initialize_internal();
+		virtual void destroy_internal();
 
 
 		/// Internal method used to set the underlying clip planes when needed
 		/// Internal method used to set the underlying clip planes when needed
 		virtual void setClipPlanesImpl(const PlaneList& clipPlanes) = 0;
 		virtual void setClipPlanesImpl(const PlaneList& clipPlanes) = 0;

+ 1 - 1
CamelotRenderer/Include/CmRenderSystemFactory.h

@@ -15,7 +15,7 @@ namespace CamelotEngine
 	class RenderSystemFactory
 	class RenderSystemFactory
 	{
 	{
 	public:
 	public:
-		virtual RenderSystemPtr create() = 0;
+		virtual void create() = 0;
 		virtual const std::string& name() const = 0;
 		virtual const std::string& name() const = 0;
 	};
 	};
 }
 }

+ 1 - 3
CamelotRenderer/Include/CmRenderSystemManager.h

@@ -11,13 +11,11 @@ namespace CamelotEngine
 	{
 	{
 	public:
 	public:
 		static void startUp(const String& name);
 		static void startUp(const String& name);
-		static RenderSystem* getActive() { return mActiveRenderSystem.get(); }
+		static RenderSystem* getActive();
 
 
 		static void registerRenderSystemFactory(RenderSystemFactoryPtr factory);
 		static void registerRenderSystemFactory(RenderSystemFactoryPtr factory);
 	private:
 	private:
 		static std::vector<RenderSystemFactoryPtr>& getAvailableFactories();
 		static std::vector<RenderSystemFactoryPtr>& getAvailableFactories();
-
-		static RenderSystemPtr mActiveRenderSystem;
 	};
 	};
 }
 }
 
 

+ 1 - 4
CamelotRenderer/Source/CmApplication.cpp

@@ -50,7 +50,6 @@ namespace CamelotEngine
 		RendererManager::setActive("ForwardRenderer");
 		RendererManager::setActive("ForwardRenderer");
 
 
 		RenderSystem* renderSystem = RenderSystemManager::getActive();
 		RenderSystem* renderSystem = RenderSystemManager::getActive();
-		renderSystem->startUp();
 
 
 		mPrimaryRenderWindow = RenderWindow::create("Camelot Renderer", 1280, 720, false);
 		mPrimaryRenderWindow = RenderWindow::create("Camelot Renderer", 1280, 720, false);
 		mPrimaryRenderContext = renderSystem->createDeferredContext();
 		mPrimaryRenderContext = renderSystem->createDeferredContext();
@@ -96,9 +95,7 @@ namespace CamelotEngine
 	void Application::shutDown()
 	void Application::shutDown()
 	{
 	{
 		SceneManager::shutDown();
 		SceneManager::shutDown();
-
-		if(RenderSystemManager::getActive() != nullptr)
-			RenderSystemManager::getActive()->shutdown();
+		RenderSystem::shutDown();
 
 
 		HighLevelGpuProgramManager::shutDown();
 		HighLevelGpuProgramManager::shutDown();
 		DynLibManager::shutDown();
 		DynLibManager::shutDown();

+ 7 - 12
CamelotRenderer/Source/CmRenderSystem.cpp

@@ -76,23 +76,25 @@ namespace CamelotEngine {
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     RenderSystem::~RenderSystem()
     RenderSystem::~RenderSystem()
     {
     {
-        shutdown_internal();
+		queueCommand(boost::bind(&RenderSystem::destroy_internal, this), true);
+		// TODO - What if something gets queued between these two calls?
+		shutdownRenderThread();
 
 
 		delete mCurrentCapabilities;
 		delete mCurrentCapabilities;
 		mCurrentCapabilities = 0;
 		mCurrentCapabilities = 0;
     }
     }
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------
-	void RenderSystem::startUp()
+	void RenderSystem::initialize()
 	{
 	{
 		mRenderThreadId = CM_THREAD_CURRENT_ID;
 		mRenderThreadId = CM_THREAD_CURRENT_ID;
 		mCommandQueue = new CommandQueue(CM_THREAD_CURRENT_ID);
 		mCommandQueue = new CommandQueue(CM_THREAD_CURRENT_ID);
 
 
 		initRenderThread();
 		initRenderThread();
 
 
-		queueCommand(boost::bind(&RenderSystem::startUp_internal, this), true);
+		queueCommand(boost::bind(&RenderSystem::initialize_internal, this), true);
 	}
 	}
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------
-	void RenderSystem::startUp_internal()
+	void RenderSystem::initialize_internal()
 	{
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 		THROW_IF_NOT_RENDER_THREAD;
 
 
@@ -101,14 +103,7 @@ namespace CamelotEngine {
 		mFragmentProgramBound = false;
 		mFragmentProgramBound = false;
 	}
 	}
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------
-	void RenderSystem::shutdown(void)
-	{
-		queueCommand(boost::bind(&RenderSystem::shutdown_internal, this), true);
-		// TODO - What if something gets queued between these two calls?
-		shutdownRenderThread();
-	}
-	//-----------------------------------------------------------------------
-	void RenderSystem::shutdown_internal(void)
+	void RenderSystem::destroy_internal(void)
 	{
 	{
 		// TODO - I should probably sync this up to make sure no other threads are doing anything while shutdown is in progress
 		// TODO - I should probably sync this up to make sure no other threads are doing anything while shutdown is in progress
 
 

+ 7 - 16
CamelotRenderer/Source/CmRenderSystemManager.cpp

@@ -6,8 +6,6 @@
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
-	RenderSystemPtr RenderSystemManager::mActiveRenderSystem;
-
 	void RenderSystemManager::startUp(const String& pluginFilename)
 	void RenderSystemManager::startUp(const String& pluginFilename)
 	{
 	{
 		DynLib* loadedLibrary = gDynLibManager().load(pluginFilename);
 		DynLib* loadedLibrary = gDynLibManager().load(pluginFilename);
@@ -25,22 +23,10 @@ namespace CamelotEngine
 		{
 		{
 			if((*iter)->name() == name)
 			if((*iter)->name() == name)
 			{
 			{
-				RenderSystemPtr newRenderSystem = (*iter)->create();
-				if(newRenderSystem != nullptr)
-				{
-					if(mActiveRenderSystem != nullptr)
-						mActiveRenderSystem->shutdown();
-
-					mActiveRenderSystem = newRenderSystem;
-				}				
+				(*iter)->create();		
+				RenderSystem::instance().initialize();
 			}
 			}
 		}
 		}
-
-		if(mActiveRenderSystem == nullptr)
-		{
-			CM_EXCEPT(InternalErrorException, 
-				"Cannot initialize render system. Renderer with the name '" + name + "' cannot be found.")
-		}
 	}
 	}
 
 
 	void RenderSystemManager::registerRenderSystemFactory(RenderSystemFactoryPtr factory)
 	void RenderSystemManager::registerRenderSystemFactory(RenderSystemFactoryPtr factory)
@@ -55,4 +41,9 @@ namespace CamelotEngine
 		static std::vector<RenderSystemFactoryPtr> availableFactories;
 		static std::vector<RenderSystemFactoryPtr> availableFactories;
 		return availableFactories;
 		return availableFactories;
 	}
 	}
+
+	RenderSystem* RenderSystemManager::getActive()
+	{
+		return RenderSystem::instancePtr();
+	}
 }
 }

+ 0 - 1
CamelotRenderer/TODO.txt

@@ -17,7 +17,6 @@
 
 
 
 
 /////
 /////
-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?)
 waitForVsync can probably be moved somewhere other than being directly in RenderSystem? (where is it in DX11?)
 
 
 Move createRenderTexture to TextureManager? (also createMultiRenderTexture)
 Move createRenderTexture to TextureManager? (also createMultiRenderTexture)