Jelajahi Sumber

Moved the core thread outside of the render system

Marko Pintera 12 tahun lalu
induk
melakukan
8c982e0422
31 mengubah file dengan 219 tambahan dan 701 penghapusan
  1. 1 1
      BansheeEngine/Source/BsDebugDraw.cpp
  2. 1 1
      BansheeEngine/Source/BsGUIManager.cpp
  3. 1 1
      CamelotClient/CamelotClient.cpp
  4. 1 1
      CamelotCore/Include/CmCoreThread.h
  5. 35 39
      CamelotCore/Include/CmDeferredRenderContext.h
  6. 0 2
      CamelotCore/Include/CmGpuProgram.h
  7. 0 2
      CamelotCore/Include/CmMesh.h
  8. 0 118
      CamelotCore/Include/CmRenderSystem.h
  9. 0 2
      CamelotCore/Include/CmTexture.h
  10. 2 2
      CamelotCore/Include/CmTextureRTTI.h
  11. 5 8
      CamelotCore/Source/CmApplication.cpp
  12. 2 7
      CamelotCore/Source/CmCommandQueue.cpp
  13. 6 6
      CamelotCore/Source/CmCoreObject.cpp
  14. 3 3
      CamelotCore/Source/CmCoreThread.cpp
  15. 1 15
      CamelotCore/Source/CmGpuProgram.cpp
  16. 9 9
      CamelotCore/Source/CmGpuResourceData.cpp
  17. 2 11
      CamelotCore/Source/CmHighLevelGpuProgram.cpp
  18. 6 20
      CamelotCore/Source/CmMesh.cpp
  19. 1 1
      CamelotCore/Source/CmMeshManager.cpp
  20. 2 2
      CamelotCore/Source/CmMeshRTTI.h
  21. 18 269
      CamelotCore/Source/CmRenderSystem.cpp
  22. 7 20
      CamelotCore/Source/CmTexture.cpp
  23. 25 32
      CamelotD3D11RenderSystem/Source/CmD3D11RenderSystem.cpp
  24. 3 10
      CamelotD3D11RenderSystem/Source/CmD3D11Texture.cpp
  25. 49 59
      CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp
  26. 9 16
      CamelotD3D9Renderer/Source/CmD3D9Texture.cpp
  27. 1 1
      CamelotFBXImporter/Source/CmFBXImporter.cpp
  28. 1 1
      CamelotFontImporter/Source/CmFontImporter.cpp
  29. 1 1
      CamelotFreeImgImporter/Source/CmFreeImgImporter.cpp
  30. 23 30
      CamelotGLRenderer/Source/CmGLRenderSystem.cpp
  31. 4 11
      CamelotGLRenderer/Source/CmGLTexture.cpp

+ 1 - 1
BansheeEngine/Source/BsDebugDraw.cpp

@@ -157,7 +157,7 @@ namespace BansheeEngine
 
 		gMainSyncedCA().writeSubresource(mLineMesh.getInternalPtr(), 0, *lineMeshData);
 		gMainSyncedCA().writeSubresource(mTriangleMesh.getInternalPtr(), 0, *triangleMeshData);
-		gMainSyncedCA().submitToGpu(true);
+		gMainSyncedCA().submitToCoreThread(true);
 	}
 
 	void DebugDraw::render(const Camera* camera, RenderContext& renderContext)

+ 1 - 1
BansheeEngine/Source/BsGUIManager.cpp

@@ -403,7 +403,7 @@ namespace BansheeEngine
 				}
 
 				gMainSyncedCA().writeSubresource(renderData.cachedMeshes[groupIdx].getInternalPtr(), 0, *meshData);
-				gMainSyncedCA().submitToGpu(true); // TODO - Remove this once I make writeSubresource accept a shared_ptr for MeshData
+				gMainSyncedCA().submitToCoreThread(true); // TODO - Remove this once I make writeSubresource accept a shared_ptr for MeshData
 
 				groupIdx++;
 			}

+ 1 - 1
CamelotClient/CamelotClient.cpp

@@ -279,7 +279,7 @@ int CALLBACK WinMain(
 	PixelDataPtr cursorPixelData = dbgCursor->allocateSubresourceBuffer(0);
 
 	gMainSyncedCA().readSubresource(dbgCursor.getInternalPtr(), 0, *cursorPixelData);
-	gMainSyncedCA().submitToGpu(true);
+	gMainSyncedCA().submitToCoreThread(true);
 
 	//Cursor::setCustomCursor(*cursorPixelData, Int2(0, 0));
 

+ 1 - 1
CamelotCore/Include/CmCoreThread.h

@@ -132,7 +132,7 @@ private:
 	/**
 		* @brief	Throws an exception if current thread isn't the core thread;
 		*/
-	static void throwIfNotCoreThread();
+	CM_EXPORT void throwIfNotCoreThread();
 
 #if CM_DEBUG_MODE
 #define THROW_IF_NOT_CORE_THREAD throwIfNotCoreThread();

+ 35 - 39
CamelotCore/Include/CmDeferredRenderContext.h

@@ -7,6 +7,7 @@
 #include "CmCommandQueue.h"
 #include "CmSamplerState.h"
 #include "CmGpuProgram.h"
+#include "CmCoreThread.h"
 #include "CmColor.h"
 
 namespace CamelotFramework
@@ -30,11 +31,8 @@ namespace CamelotFramework
 		 * 							hit due to synchronization. In most cases you will want not to use synced access and instead create a separate context
 		 * 							for specific threads.
 		 */
-		DeferredRenderContext(RenderSystem* rs, CM_THREAD_ID_TYPE threadId)
-			:mRenderSystem(rs)
+		DeferredRenderContext(CM_THREAD_ID_TYPE threadId)
 		{
-			assert(mRenderSystem != nullptr);
-
 			mCommandQueue = cm_new<CommandQueue<CommandQueueSyncPolicy>>(threadId);
 		}
 
@@ -46,7 +44,7 @@ namespace CamelotFramework
 		/** @copydoc RenderSystem::disableTextureUnit() */
 		void disableTextureUnit(GpuProgramType gptype, UINT16 texUnit)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::disableTextureUnit, mRenderSystem, gptype, texUnit));
+			mCommandQueue->queue(boost::bind(&RenderSystem::disableTextureUnit, RenderSystem::instancePtr(), gptype, texUnit));
 		}
 
 		/** @copydoc RenderSystem::setPointParameters() */
@@ -55,161 +53,161 @@ namespace CamelotFramework
 		/** @copydoc RenderSystem::setTexture() */
 		void setTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const TexturePtr &texPtr)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::setTexture, mRenderSystem, gptype, unit, enabled, texPtr));
+			mCommandQueue->queue(boost::bind(&RenderSystem::setTexture, RenderSystem::instancePtr(), gptype, unit, enabled, texPtr));
 		}
 
 		/** @copydoc RenderSystem::setSamplerState() */
 		void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerStatePtr& samplerState)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::setSamplerState, mRenderSystem, gptype, texUnit, samplerState));
+			mCommandQueue->queue(boost::bind(&RenderSystem::setSamplerState, RenderSystem::instancePtr(), gptype, texUnit, samplerState));
 		}
 
 		/** @copydoc RenderSystem::setBlendState() */
 		void setBlendState(const BlendStatePtr& blendState)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::setBlendState, mRenderSystem, blendState));
+			mCommandQueue->queue(boost::bind(&RenderSystem::setBlendState, RenderSystem::instancePtr(), blendState));
 		}
 
 		/** @copydoc RenderSystem::setRasterizerState() */
 		void setRasterizerState(const RasterizerStatePtr& rasterizerState)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::setRasterizerState, mRenderSystem, rasterizerState));
+			mCommandQueue->queue(boost::bind(&RenderSystem::setRasterizerState, RenderSystem::instancePtr(), rasterizerState));
 		}
 
 		/** @copydoc RenderSystem::setRasterizerState() */
 		void setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::setDepthStencilState, mRenderSystem, depthStencilState, stencilRefValue));
+			mCommandQueue->queue(boost::bind(&RenderSystem::setDepthStencilState, RenderSystem::instancePtr(), depthStencilState, stencilRefValue));
 		}
 
 		/** @copydoc RenderSystem::setViewport() */
 		void setViewport(ViewportPtr& vp)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::setViewport, mRenderSystem, vp));
+			mCommandQueue->queue(boost::bind(&RenderSystem::setViewport, RenderSystem::instancePtr(), vp));
 		}
 
 		/** @copydoc RenderSystem::setVertexBuffer() */
 		void setVertexBuffer(UINT32 index, const VertexBufferPtr& buffer)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::setVertexBuffer, mRenderSystem, index, buffer));
+			mCommandQueue->queue(boost::bind(&RenderSystem::setVertexBuffer, RenderSystem::instancePtr(), index, buffer));
 		}
 
 		/** @copydoc RenderSystem::setIndexBuffer() */
 		void setIndexBuffer(const IndexBufferPtr& buffer)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::setIndexBuffer, mRenderSystem, buffer));
+			mCommandQueue->queue(boost::bind(&RenderSystem::setIndexBuffer, RenderSystem::instancePtr(), buffer));
 		}
 
 		/** @copydoc RenderSystem::setVertexDeclaration() */
 		void setVertexDeclaration(VertexDeclarationPtr vertexDeclaration)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::setVertexDeclaration, mRenderSystem, vertexDeclaration));
+			mCommandQueue->queue(boost::bind(&RenderSystem::setVertexDeclaration, RenderSystem::instancePtr(), vertexDeclaration));
 		}
 
 		/** @copydoc RenderSystem::setDrawOperation() */
 		void setDrawOperation(DrawOperationType op)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::setDrawOperation, mRenderSystem, op));
+			mCommandQueue->queue(boost::bind(&RenderSystem::setDrawOperation, RenderSystem::instancePtr(), op));
 		}
 
 
 		/** @copydoc RenderSystem::setClipPlanes() */
 		void setClipPlanes(const PlaneList& clipPlanes)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::setClipPlanes, mRenderSystem, clipPlanes));
+			mCommandQueue->queue(boost::bind(&RenderSystem::setClipPlanes, RenderSystem::instancePtr(), clipPlanes));
 		}
 
 		/** @copydoc RenderSystem::addClipPlane(const Plane&) */
 		void addClipPlane(const Plane& p)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::addClipPlane, mRenderSystem, p));
+			mCommandQueue->queue(boost::bind(&RenderSystem::addClipPlane, RenderSystem::instancePtr(), p));
 		}
 
 		/** @copydoc RenderSystem::addClipPlane(float, float, float, float) */
 		void addClipPlane(float A, float B, float C, float D)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::addClipPlane, mRenderSystem, A, B, C, D));
+			mCommandQueue->queue(boost::bind(&RenderSystem::addClipPlane, RenderSystem::instancePtr(), A, B, C, D));
 		}
 
 		/** @copydoc RenderSystem::resetClipPlanes() */
 		void resetClipPlanes()
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::resetClipPlanes, mRenderSystem));
+			mCommandQueue->queue(boost::bind(&RenderSystem::resetClipPlanes, RenderSystem::instancePtr()));
 		}
 
 		/** @copydoc RenderSystem::setScissorTest() */
 		void setScissorTest(UINT32 left = 0, UINT32 top = 0, UINT32 right = 800, UINT32 bottom = 600)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::setScissorRect, mRenderSystem, left, top, right, bottom));
+			mCommandQueue->queue(boost::bind(&RenderSystem::setScissorRect, RenderSystem::instancePtr(), left, top, right, bottom));
 		}
 
 
 		/** @copydoc RenderSystem::setRenderTarget() */
 		void setRenderTarget(RenderTargetPtr target)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::setRenderTarget, mRenderSystem, target));
+			mCommandQueue->queue(boost::bind(&RenderSystem::setRenderTarget, RenderSystem::instancePtr(), target));
 		}
 
 		/** @copydoc RenderSystem::bindGpuProgram() */
 		void bindGpuProgram(HGpuProgram prg)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::bindGpuProgram, mRenderSystem, prg));
+			mCommandQueue->queue(boost::bind(&RenderSystem::bindGpuProgram, RenderSystem::instancePtr(), prg));
 		}
 
 		/** @copydoc RenderSystem::unbindGpuProgram() */
 		void unbindGpuProgram(GpuProgramType gptype)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::unbindGpuProgram, mRenderSystem, gptype));
+			mCommandQueue->queue(boost::bind(&RenderSystem::unbindGpuProgram, RenderSystem::instancePtr(), gptype));
 		}
 
 		/** @copydoc RenderSystem::bindGpuParams() */
 		void bindGpuParams(GpuProgramType gptype, BindableGpuParams& params)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::bindGpuParams, mRenderSystem, gptype, params));
+			mCommandQueue->queue(boost::bind(&RenderSystem::bindGpuParams, RenderSystem::instancePtr(), gptype, params));
 		}
 
 
 		/** @copydoc RenderSystem::beginFrame() */
 		void beginFrame(void)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::beginFrame, mRenderSystem));
+			mCommandQueue->queue(boost::bind(&RenderSystem::beginFrame, RenderSystem::instancePtr()));
 		}
 
 		/** @copydoc RenderSystem::endFrame() */
 		void endFrame(void)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::endFrame, mRenderSystem));
+			mCommandQueue->queue(boost::bind(&RenderSystem::endFrame, RenderSystem::instancePtr()));
 		}
 
 		/** @copydoc RenderSystem::clear() */
 		void clear(RenderTargetPtr target, unsigned int buffers, const Color& color = Color::Black, float depth = 1.0f, unsigned short stencil = 0)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::clear, mRenderSystem, target, buffers, color, depth, stencil));
+			mCommandQueue->queue(boost::bind(&RenderSystem::clear, RenderSystem::instancePtr(), target, buffers, color, depth, stencil));
 		}
 
 		/** @copydoc RenderSystem::swapBuffers() */
 		void swapBuffers(RenderTargetPtr target)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::swapBuffers, mRenderSystem, target));
+			mCommandQueue->queue(boost::bind(&RenderSystem::swapBuffers, RenderSystem::instancePtr(), target));
 		}
 
 
 		/** @copydoc RenderSystem::render() */
 		void render(const RenderOperation& op)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::render, mRenderSystem, op));
+			mCommandQueue->queue(boost::bind(&RenderSystem::render, RenderSystem::instancePtr(), op));
 		}
 
 		/** @copydoc RenderSystem::draw() */
 		void draw(UINT32 vertexCount)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::draw, mRenderSystem, vertexCount));
+			mCommandQueue->queue(boost::bind(&RenderSystem::draw, RenderSystem::instancePtr(), vertexCount));
 		}
 
 		/** @copydoc RenderSystem::drawIndexed() */
 		void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexCount)
 		{
-			mCommandQueue->queue(boost::bind(&RenderSystem::drawIndexed, mRenderSystem, startIndex, indexCount, vertexCount));
+			mCommandQueue->queue(boost::bind(&RenderSystem::drawIndexed, RenderSystem::instancePtr(), startIndex, indexCount, vertexCount));
 		}
 
 
@@ -224,7 +222,7 @@ namespace CamelotFramework
 		{
 			data.lock();
 
-			return mCommandQueue->queueReturn(boost::bind(&RenderSystem::writeSubresource, mRenderSystem, resource, subresourceIdx, boost::cref(data), _1));
+			return mCommandQueue->queueReturn(boost::bind(&RenderSystem::writeSubresource, RenderSystem::instancePtr(), resource, subresourceIdx, boost::cref(data), _1));
 		}
 
 		/**
@@ -238,19 +236,18 @@ namespace CamelotFramework
 		{
 			data.lock();
 
-			return mCommandQueue->queueReturn(boost::bind(&RenderSystem::readSubresource, mRenderSystem, resource, subresourceIdx, boost::ref(data), _1));
+			return mCommandQueue->queueReturn(boost::bind(&RenderSystem::readSubresource, RenderSystem::instancePtr(), resource, subresourceIdx, boost::ref(data), _1));
 		}
 
 		/**
-		 * @brief	Makes all the currently queued commands available to the GPU. They will be executed
-		 * 			as soon as the render thread is ready.
+		 * @brief	Makes all the currently queued commands available to the core thread. They will be executed
+		 * 			as soon as the core thread is ready.
 		 */
-		void submitToGpu(bool blockUntilComplete = false)
+		void submitToCoreThread(bool blockUntilComplete = false)
 		{
 			Queue<QueuedCommand>::type* commands = mCommandQueue->flush();
 
-			RenderSystem* rs = RenderSystem::instancePtr();
-			rs->queueCommand(boost::bind(&CommandQueueBase::playback, mCommandQueue, commands), blockUntilComplete);
+			gCoreThread().queueCommand(boost::bind(&CommandQueueBase::playback, mCommandQueue, commands), blockUntilComplete);
 		}
 
 		/**
@@ -263,6 +260,5 @@ namespace CamelotFramework
 
 	private:
 		CommandQueue<CommandQueueSyncPolicy>* mCommandQueue;
-		RenderSystem* mRenderSystem;
 	};
 }

+ 0 - 2
CamelotCore/Include/CmGpuProgram.h

@@ -158,8 +158,6 @@ namespace CamelotFramework {
 		/// @copydoc Resource::calculateSize
 		size_t calculateSize(void) const { return 0; } // TODO 
 
-		void throwIfNotRenderThread() const;
-
 	protected:
 		/// The type of the program
 		GpuProgramType mType;

+ 0 - 2
CamelotCore/Include/CmMesh.h

@@ -75,8 +75,6 @@ namespace CamelotFramework
 
 		Vector<SubMesh>::type mSubMeshes;
 
-		void throwIfNotRenderThread() const;
-
 		/**
 		 * @copydoc Resource::initialize_internal()
 		 */

+ 0 - 118
CamelotCore/Include/CmRenderSystem.h

@@ -404,124 +404,6 @@ namespace CamelotFramework
 		virtual String getErrorDescription(long errorNumber) const = 0;
 
 		DriverVersion mDriverVersion;
-
-		/************************************************************************/
-		/* 							RENDER THREAD	                     		*/
-		/************************************************************************/
-
-		class RenderWorkerFunc CM_THREAD_WORKER_INHERIT
-		{
-		public:
-			RenderWorkerFunc(RenderSystem* rs);
-
-			void operator()();
-
-		private:
-			RenderSystem* mRS;
-		};
-
-		RenderWorkerFunc* mRenderThreadFunc;
-		volatile bool mRenderThreadStarted;
-		volatile bool mRenderThreadShutdown;
-
-		CM_THREAD_ID_TYPE mRenderThreadId;
-		CM_THREAD_SYNCHRONISER(mRenderThreadStartCondition)
-		CM_MUTEX(mRenderThreadStartMutex)
-		CM_MUTEX(mCommandQueueMutex)
-		CM_THREAD_SYNCHRONISER(mCommandReadyCondition)
-		CM_MUTEX(mCommandNotifyMutex)
-		CM_THREAD_SYNCHRONISER(mCommandCompleteCondition)
-
-#if CM_THREAD_SUPPORT
-		CM_THREAD_TYPE* mRenderThread;
-#endif
-
-		CommandQueue<CommandQueueSync>* mCommandQueue;
-
-		UINT32 mMaxCommandNotifyId; // ID that will be assigned to the next command with a notifier callback
-		Vector<UINT32>::type mCommandsCompleted; // Completed commands that have notifier callbacks set up
-
-		SyncedRenderContext* mSyncedRenderContext;
-
-		/**
-		 * @brief	Initializes a separate render thread. Should only be called once.
-		 */
-		void initRenderThread();
-
-		/**
-		 * @brief	Main function of the render thread. Called once thread is started.
-		 */
-		void runRenderThread();
-
-		/**
-		 * @brief	Shutdowns the render thread. It will complete all ready commands
-		 * 			before shutdown.
-		 */
-		void shutdownRenderThread();
-
-		/**
-		 * @brief	Throws an exception if current thread isn't the render thread;
-		 */
-		void throwIfNotRenderThread() const;
-
-		/**
-		 * @brief	Blocks the calling thread until the command with the specified ID completes.
-		 * 			Make sure that the specified ID actually exists, otherwise this will block forever.
-		 */
-		void blockUntilCommandCompleted(UINT32 commandId);
-
-		/**
-		 * @brief	Callback called by the command list when a specific command finishes executing.
-		 * 			This is only called on commands that have a special notify on complete flag set.
-		 *
-		 * @param	commandId	Identifier for the command.
-		 */
-		void commandCompletedNotify(UINT32 commandId);
-
-	public:
-		/**
-		 * @brief	Returns the id of the render thread. If a separate render thread
-		 * 			is not used, then it returns the id of the thread RenderSystem
-		 * 			was initialized on.
-		 */
-		CM_THREAD_ID_TYPE getRenderThreadId() const { return mRenderThreadId; }
-
-		/**
-		 * @brief	Creates a new render system context that you can use for executing GPU commands from 
-		 * 			a non-render thread. You can have as many of these as you wish, the only limitation
-		 * 			is that you do not use a single instance on more than one thread. Each thread
-		 * 			requires its own context. The context will be bound to the thread you call this method on.
-		 */
-		RenderContextPtr createDeferredContext();
-
-		/**
-		* @brief	Retrieves a context that may be used for rendering on the executing GPU commands from
-		* 			a non-render thread. There is only one synchronized context and you may access it from any thread you wish.
-		* 			Note however that it is much more efficient to create a separate non-synchronized context for each thread 
-		* 			you will be using it on.
-		 */
-		SyncedRenderContext& getSyncedDeferredContext();
-
-		/**
-		 * @brief	Queues a new command that will be added to the global command queue. You are allowed to call this from any thread,
-		 * 			however be aware that it involves possibly slow synchronization primitives, so limit your usage.
-		 * 			
-		 * @param	blockUntilComplete If true the thread will be blocked until the command executes. Be aware that there be many commands queued before it
-		 * 							   and they all need to be executed in order before the current command is reached, which might take a long time.
-		 * 	
-		 * @see		CommandQueue::queueReturn
-		 */
-		AsyncOp queueReturnCommand(boost::function<void(AsyncOp&)> commandCallback, bool blockUntilComplete = false);
-
-		/**
-		* @brief	Queues a new command that will be added to the global command queue.You are allowed to call this from any thread,
-		 * 			however be aware that it involves possibly slow synchronization primitives, so limit your usage.
-		 * 	
-		 * @param	blockUntilComplete If true the thread will be blocked until the command executes. Be aware that there be many commands queued before it
-		 * 							   and they all need to be executed in order before the current command is reached, which might take a long time.
-		 * @see		CommandQueue::queue
-		 */
-		void queueCommand(boost::function<void()> commandCallback, bool blockUntilComplete = false);
 	};
 	/** @} */
 	/** @} */

+ 0 - 2
CamelotCore/Include/CmTexture.h

@@ -246,8 +246,6 @@ namespace CamelotFramework {
 		/// @copydoc Resource::calculateSize
 		UINT32 calculateSize(void) const;
 
-		void throwIfNotRenderThread() const;
-
 		/************************************************************************/
 		/* 								SERIALIZATION                      		*/
 		/************************************************************************/

+ 2 - 2
CamelotCore/Include/CmTextureRTTI.h

@@ -40,7 +40,7 @@ namespace CamelotFramework
 			GpuResourcePtr sharedTexPtr = std::static_pointer_cast<GpuResource>(obj->getThisPtr());
 
 			gMainSyncedCA().readSubresource(sharedTexPtr, subresourceIdx, *pixelData);
-			gMainSyncedCA().submitToGpu(true); // We need the data right away, so execute the context and wait until we get it
+			gMainSyncedCA().submitToCoreThread(true); // We need the data right away, so execute the context and wait until we get it
 
 			return pixelData;
 		}
@@ -116,7 +116,7 @@ namespace CamelotFramework
 				gMainSyncedCA().writeSubresource(sharedTexPtr, subresourceIdx, *pixelData->at(i));
 			}
 
-			gMainSyncedCA().submitToGpu(true); // TODO - Possibly we can avoid this. I don't see a reason we need to wait for the update to complete.
+			gMainSyncedCA().submitToCoreThread(true); // TODO - Possibly we can avoid this. I don't see a reason we need to wait for the update to complete.
 
 			cm_delete<PoolAlloc>(pixelData);
 			texture->mRTTIData = nullptr;	

+ 5 - 8
CamelotCore/Source/CmApplication.cpp

@@ -65,10 +65,8 @@ namespace CamelotFramework
 		loadPlugin(desc.renderer);
 		RendererManager::instance().setActive(desc.renderer);
 
-		RenderSystem* renderSystem = RenderSystem::instancePtr();
-
-		mPrimaryRenderContext = renderSystem->createDeferredContext();
-		mPrimarySyncedRenderContext = &renderSystem->getSyncedDeferredContext();
+		mPrimaryRenderContext = gCoreThread().createAccessor();
+		mPrimarySyncedRenderContext = &gCoreThread().getSyncedAccessor();
 
 		SceneManager::startUp((SceneManager*)loadPlugin(desc.sceneManager));
 
@@ -99,7 +97,6 @@ namespace CamelotFramework
 			if(!mainLoopCallback.empty())
 				mainLoopCallback();
 
-			RenderSystem* renderSystem = RenderSystem::instancePtr();
 			RendererManager::instance().getActive()->renderAll();
 
 			// Only queue new commands if render thread has finished rendering
@@ -118,9 +115,9 @@ namespace CamelotFramework
 					mIsFrameRenderingFinished = false;
 				}
 				
-				renderSystem->queueCommand(boost::bind(&Application::updateMessagePump, this));
-				mPrimaryRenderContext->submitToGpu();
-				renderSystem->queueCommand(boost::bind(&Application::frameRenderingFinishedCallback, this));
+				gCoreThread().queueCommand(boost::bind(&Application::updateMessagePump, this));
+				mPrimaryRenderContext->submitToCoreThread();
+				gCoreThread().queueCommand(boost::bind(&Application::frameRenderingFinishedCallback, this));
 			}
 			else
 				mPrimaryRenderContext->cancelAll();

+ 2 - 7
CamelotCore/Source/CmCommandQueue.cpp

@@ -1,6 +1,6 @@
 #include "CmCommandQueue.h"
 #include "CmException.h"
-#include "CmRenderSystem.h"
+#include "CmCoreThread.h"
 #include "CmDebug.h"
 #include "CmUtil.h"
 
@@ -80,12 +80,7 @@ namespace CamelotFramework
 
 	void CommandQueueBase::playback(CamelotFramework::Queue<QueuedCommand>::type* commands, boost::function<void(UINT32)> notifyCallback)
 	{
-#if CM_DEBUG_MODE
-		RenderSystem* rs = RenderSystem::instancePtr();
-
-		if(rs->getRenderThreadId() != CM_THREAD_CURRENT_ID)
-			CM_EXCEPT(InternalErrorException, "This method should only be called from the render thread.");
-#endif
+		THROW_IF_NOT_CORE_THREAD;
 
 		if(commands == nullptr)
 			return;

+ 6 - 6
CamelotCore/Source/CmCoreObject.cpp

@@ -1,5 +1,5 @@
 #include "CmCoreObject.h"
-#include "CmRenderSystem.h"
+#include "CmCoreThread.h"
 #include "CmCoreObjectManager.h"
 #include "CmDebug.h"
 
@@ -104,8 +104,8 @@ namespace CamelotFramework
 			if(requiresInitOnRenderThread())
 			{
 #if CM_DEBUG_MODE
-				if(CM_THREAD_CURRENT_ID == RenderSystem::instancePtr()->getRenderThreadId())
-					CM_EXCEPT(InternalErrorException, "You cannot call this method on the render thread. It will cause a deadlock!");
+				if(CM_THREAD_CURRENT_ID == CoreThread::instance().getCoreThreadId())
+					CM_EXCEPT(InternalErrorException, "You cannot call this method on the core thread. It will cause a deadlock!");
 #endif
 
 				CM_LOCK_MUTEX_NAMED(mCoreGpuObjectLoadedMutex, lock);
@@ -137,7 +137,7 @@ namespace CamelotFramework
 		// - If the object wasn't initialized delete it right away
 		// - Otherwise:
 		//  - We re-create the reference to the object by setting mThis pointer
-		//  - We queue the object to be destroyed so all of its GPU resources may be released on the render thread
+		//  - We queue the object to be destroyed so all of its GPU resources may be released on the core thread
 		//    - destroy() makes sure it keeps a reference of mThis so object isn't deleted
 		//    - Once the destroy() finishes the reference is removed and the default shared_ptr deleter is called
 
@@ -157,13 +157,13 @@ namespace CamelotFramework
 		// reference to the obj (saved in the bound function).
 		// We could have called the function directly using "this" pointer but then we couldn't have used a shared_ptr for the object,
 		// in which case there is a possibility that the object would be released and deleted while still being in the command queue.
-		RenderSystem::instancePtr()->queueCommand(boost::bind(&CoreObject::executeGpuCommand, obj, func));
+		CoreThread::instance().queueCommand(boost::bind(&CoreObject::executeGpuCommand, obj, func));
 	}
 
 	AsyncOp CoreObject::queueReturnGpuCommand(std::shared_ptr<CoreObject>& obj, boost::function<void(AsyncOp&)> func)
 	{
 		// See queueGpuCommand
-		return RenderSystem::instancePtr()->queueReturnCommand(boost::bind(&CoreObject::executeReturnGpuCommand, obj, func, _1));
+		return CoreThread::instance().queueReturnCommand(boost::bind(&CoreObject::executeReturnGpuCommand, obj, func, _1));
 	}
 
 	void CoreObject::executeGpuCommand(std::shared_ptr<CoreObject>& obj, boost::function<void()> func)

+ 3 - 3
CamelotCore/Source/CmCoreThread.cpp

@@ -52,7 +52,7 @@ namespace CamelotFramework
 	{
 #if !CM_FORCE_SINGLETHREADED_RENDERING
 		mCoreThreadId = CM_THREAD_CURRENT_ID;
-		mSyncedCoreAccessor = cm_new<DeferredRenderContext<CommandQueueSync>>(nullptr, CM_THREAD_CURRENT_ID);
+		mSyncedCoreAccessor = cm_new<DeferredRenderContext<CommandQueueSync>>(CM_THREAD_CURRENT_ID);
 
 		{
 			CM_LOCK_MUTEX(mCoreThreadStartMutex);
@@ -118,7 +118,7 @@ namespace CamelotFramework
 
 	RenderContextPtr CoreThread::createAccessor()
 	{
-		return cm_shared_ptr<DeferredRenderContext<CommandQueueNoSync>>(nullptr, CM_THREAD_CURRENT_ID);
+		return cm_shared_ptr<DeferredRenderContext<CommandQueueNoSync>>(CM_THREAD_CURRENT_ID);
 	}
 
 	SyncedRenderContext& CoreThread::getSyncedAccessor()
@@ -232,7 +232,7 @@ namespace CamelotFramework
 	{
 #if !CM_FORCE_SINGLETHREADED_RENDERING
 		if(CM_THREAD_CURRENT_ID != CoreThread::instance().getCoreThreadId())
-			CM_EXCEPT(InternalErrorException, "Calling the render system from a non-render thread!");
+			CM_EXCEPT(InternalErrorException, "This method can only be accessed from the core thread.");
 #endif
 	}
 

+ 1 - 15
CamelotCore/Source/CmGpuProgram.cpp

@@ -37,12 +37,6 @@ THE SOFTWARE.
 #include "CmGpuProgInclude.h"
 #include "CmGpuProgramRTTI.h"
 
-#if CM_DEBUG_MODE
-#define THROW_IF_NOT_RENDER_THREAD throwIfNotRenderThread();
-#else
-#define THROW_IF_NOT_RENDER_THREAD 
-#endif
-
 namespace CamelotFramework
 {
     //-----------------------------------------------------------------------------
@@ -101,12 +95,6 @@ namespace CamelotFramework
 
         return language;
     }
-	//----------------------------------------------------------------------------- 
-	void GpuProgram::throwIfNotRenderThread() const
-	{
-		if(CM_THREAD_CURRENT_ID != RenderSystem::instancePtr()->getRenderThreadId())
-			CM_EXCEPT(InternalErrorException, "Calling an internal texture method from a non-render thread!");
-	}
 
 	/************************************************************************/
 	/* 								SERIALIZATION                      		*/
@@ -120,6 +108,4 @@ namespace CamelotFramework
 	{
 		return GpuProgram::getRTTIStatic();
 	}
-}
-
-#undef THROW_IF_NOT_RENDER_THREAD 
+}

+ 9 - 9
CamelotCore/Source/CmGpuResourceData.cpp

@@ -1,6 +1,6 @@
 #include "CmGpuResourceData.h"
 #include "CmGpuResourceDataRTTI.h"
-#include "CmRenderSystem.h"
+#include "CmCoreThread.h"
 #include "CmException.h"
 
 namespace CamelotFramework
@@ -28,8 +28,8 @@ namespace CamelotFramework
 #if !CM_FORCE_SINGLETHREADED_RENDERING
 		if(mLocked)
 		{
-			if(CM_THREAD_CURRENT_ID != RenderSystem::instance().getRenderThreadId())
-				CM_EXCEPT(InternalErrorException, "You are not allowed to access buffer data from non-render thread when the buffer is locked.");
+			if(CM_THREAD_CURRENT_ID != CoreThread::instance().getCoreThreadId())
+				CM_EXCEPT(InternalErrorException, "You are not allowed to access buffer data from non-core thread when the buffer is locked.");
 		}
 #endif
 
@@ -46,8 +46,8 @@ namespace CamelotFramework
 #if !CM_FORCE_SINGLETHREADED_RENDERING
 		if(mLocked)
 		{
-			if(CM_THREAD_CURRENT_ID != RenderSystem::instance().getRenderThreadId())
-				CM_EXCEPT(InternalErrorException, "You are not allowed to access buffer data from non-render thread when the buffer is locked.");
+			if(CM_THREAD_CURRENT_ID != CoreThread::instance().getCoreThreadId())
+				CM_EXCEPT(InternalErrorException, "You are not allowed to access buffer data from non-core thread when the buffer is locked.");
 		}
 #endif
 
@@ -65,8 +65,8 @@ namespace CamelotFramework
 #if !CM_FORCE_SINGLETHREADED_RENDERING
 		if(mLocked)
 		{
-			if(CM_THREAD_CURRENT_ID != RenderSystem::instance().getRenderThreadId())
-				CM_EXCEPT(InternalErrorException, "You are not allowed to access buffer data from non-render thread when the buffer is locked.");
+			if(CM_THREAD_CURRENT_ID != CoreThread::instance().getCoreThreadId())
+				CM_EXCEPT(InternalErrorException, "You are not allowed to access buffer data from non-core thread when the buffer is locked.");
 		}
 #endif
 
@@ -79,8 +79,8 @@ namespace CamelotFramework
 #if !CM_FORCE_SINGLETHREADED_RENDERING
 		if(mLocked)
 		{
-			if(CM_THREAD_CURRENT_ID != RenderSystem::instance().getRenderThreadId())
-				CM_EXCEPT(InternalErrorException, "You are not allowed to access buffer data from non-render thread when the buffer is locked.");
+			if(CM_THREAD_CURRENT_ID != CoreThread::instance().getCoreThreadId())
+				CM_EXCEPT(InternalErrorException, "You are not allowed to access buffer data from non-core thread when the buffer is locked.");
 		}
 #endif
 

+ 2 - 11
CamelotCore/Source/CmHighLevelGpuProgram.cpp

@@ -27,17 +27,10 @@ THE SOFTWARE.
 */
 #include "CmHighLevelGpuProgram.h"
 #include "CmHighLevelGpuProgramManager.h"
-#include "CmRenderSystem.h"
 #include "CmException.h"
-#include "CmRenderSystem.h"
+#include "CmCoreThread.h"
 #include "CmAsyncOp.h"
 
-#if CM_DEBUG_MODE
-#define THROW_IF_NOT_RENDER_THREAD throwIfNotRenderThread();
-#else
-#define THROW_IF_NOT_RENDER_THREAD 
-#endif
-
 namespace CamelotFramework
 {
     //---------------------------------------------------------------------------
@@ -81,6 +74,4 @@ namespace CamelotFramework
 
 		return static_resource_cast<HighLevelGpuProgram>(Resource::_createResourceHandle(programPtr));
 	}
-}
-
-#undef THROW_IF_NOT_RENDER_THREAD 
+}

+ 6 - 20
CamelotCore/Source/CmMesh.cpp

@@ -6,15 +6,9 @@
 #include "CmDebug.h"
 #include "CmHardwareBufferManager.h"
 #include "CmMeshManager.h"
-#include "CmRenderSystem.h"
+#include "CmCoreThread.h"
 #include "CmAsyncOp.h"
 
-#if CM_DEBUG_MODE
-#define THROW_IF_NOT_RENDER_THREAD throwIfNotRenderThread();
-#else
-#define THROW_IF_NOT_RENDER_THREAD 
-#endif
-
 namespace CamelotFramework
 {
 	Mesh::Mesh()
@@ -29,7 +23,7 @@ namespace CamelotFramework
 
 	void Mesh::writeSubresource(UINT32 subresourceIdx, const GpuResourceData& data)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		if(data.getTypeId() != TID_MeshData)
 			CM_EXCEPT(InvalidParametersException, "Invalid GpuResourceData type. Only MeshData is supported.");
@@ -107,7 +101,7 @@ namespace CamelotFramework
 
 	void Mesh::readSubresource(UINT32 subresourceIdx, GpuResourceData& data)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		if(data.getTypeId() != TID_MeshData)
 			CM_EXCEPT(InvalidParametersException, "Invalid GpuResourceData type. Only MeshData is supported.");
@@ -225,7 +219,7 @@ namespace CamelotFramework
 
 	void Mesh::initialize_internal()
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		// TODO Low priority - Initialize an empty mesh. A better way would be to only initialize the mesh
 		// once we set the proper mesh data (then we don't have to do it twice), but this makes the code less complex.
@@ -237,7 +231,7 @@ namespace CamelotFramework
 
 	void Mesh::destroy_internal()
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		if(mVertexData != nullptr)
 			cm_delete<PoolAlloc>(mVertexData);
@@ -253,12 +247,6 @@ namespace CamelotFramework
 		return MeshManager::instance().getDummyMesh();
 	}
 
-	void Mesh::throwIfNotRenderThread() const
-	{
-		if(CM_THREAD_CURRENT_ID != RenderSystem::instancePtr()->getRenderThreadId())
-			CM_EXCEPT(InternalErrorException, "Calling an internal texture method from a non-render thread!");
-	}
-
 	/************************************************************************/
 	/* 								SERIALIZATION                      		*/
 	/************************************************************************/
@@ -283,6 +271,4 @@ namespace CamelotFramework
 
 		return static_resource_cast<Mesh>(Resource::_createResourceHandle(meshPtr));
 	}
-}
-
-#undef THROW_IF_NOT_RENDER_THREAD
+}

+ 1 - 1
CamelotCore/Source/CmMeshManager.cpp

@@ -54,6 +54,6 @@ namespace CamelotFramework
 
 		mDummyMesh = Mesh::create();
 		renderContext.writeSubresource(mDummyMesh.getInternalPtr(), 0, *mDummyMeshData);
-		renderContext.submitToGpu(true); // TODO - Only temporary until I fix write/read subresource
+		renderContext.submitToCoreThread(true); // TODO - Only temporary until I fix write/read subresource
 	}
 }

+ 2 - 2
CamelotCore/Source/CmMeshRTTI.h

@@ -17,7 +17,7 @@ namespace CamelotFramework
 			GpuResourcePtr sharedMeshPtr = std::static_pointer_cast<GpuResource>(obj->getThisPtr());
 
 			gMainSyncedCA().readSubresource(sharedMeshPtr, 0, *meshData);
-			gMainSyncedCA().submitToGpu(true); // We need the data right away, so execute the context and wait until we get it
+			gMainSyncedCA().submitToCoreThread(true); // We need the data right away, so execute the context and wait until we get it
 
 			return meshData;
 		}
@@ -27,7 +27,7 @@ namespace CamelotFramework
 			GpuResourcePtr sharedMeshPtr = std::static_pointer_cast<GpuResource>(obj->getThisPtr());
 
 			gMainSyncedCA().writeSubresource(sharedMeshPtr, 0, *meshData);
-			gMainSyncedCA().submitToGpu(true); // TODO - Possibly we can avoid this. I don't see a reason we need to wait for the update to complete.
+			gMainSyncedCA().submitToCoreThread(true); // TODO - Possibly we can avoid this. I don't see a reason we need to wait for the update to complete.
 		}
 
 	public:

+ 18 - 269
CamelotCore/Source/CmRenderSystem.cpp

@@ -41,14 +41,9 @@ THE SOFTWARE.
 #include "CmPixelBuffer.h"
 #include "CmOcclusionQuery.h"
 #include "CmGpuResource.h"
+#include "CmCoreThread.h"
 #include "boost/bind.hpp"
 
-#if CM_DEBUG_MODE
-#define THROW_IF_NOT_RENDER_THREAD throwIfNotRenderThread();
-#else
-#define THROW_IF_NOT_RENDER_THREAD 
-#endif
-
 namespace CamelotFramework {
 
     static const TexturePtr sNullTexPtr;
@@ -62,12 +57,6 @@ namespace CamelotFramework {
         , mFragmentProgramBound(false)
 		, mClipPlanesDirty(true)
 		, mCurrentCapabilities(nullptr)
-		, mRenderThreadFunc(nullptr)
-		, mRenderThreadStarted(false)
-		, mRenderThreadShutdown(false)
-		, mCommandQueue(nullptr)
-		, mMaxCommandNotifyId(0)
-		, mSyncedRenderContext(nullptr)
     {
     }
 
@@ -75,77 +64,58 @@ namespace CamelotFramework {
     {
 		// Base classes need to call virtual destroy_internal method (queue it on render thread)
 
-		// TODO - What if something gets queued between the queued call to destroy_internal and this!?
-		shutdownRenderThread();
-
-		if(mCommandQueue != nullptr)
-		{
-			cm_delete(mCommandQueue);
-			mCommandQueue = nullptr;
-		}
-
 		cm_delete(mCurrentCapabilities);
 		mCurrentCapabilities = nullptr;
     }
 
 	RenderWindowPtr RenderSystem::initialize(const RENDER_WINDOW_DESC& primaryWindowDesc)
 	{
-		mRenderThreadId = CM_THREAD_CURRENT_ID;
-		mCommandQueue = cm_new<CommandQueue<CommandQueueSync>>(CM_THREAD_CURRENT_ID, true);
 		mPrimaryWindowDesc = primaryWindowDesc;
 
 		MemStack::setupHeap(HID_Render);
-		initRenderThread();
 
-		AsyncOp op = queueReturnCommand(boost::bind(&RenderSystem::initialize_internal, this, _1), true);
+		AsyncOp op = gCoreThread().queueReturnCommand(boost::bind(&RenderSystem::initialize_internal, this, _1), true);
 		return op.getReturnValue<RenderWindowPtr>();
 	}
 
 	void RenderSystem::initialize_internal(AsyncOp& asyncOp)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		mVertexProgramBound = false;
 		mGeometryProgramBound = false;
 		mFragmentProgramBound = false;
-
-		mSyncedRenderContext = cm_new<DeferredRenderContext<CommandQueueSync>>(this, CM_THREAD_CURRENT_ID);
 	}
 
 	void RenderSystem::destroy_internal()
 	{
 		mActiveRenderTarget = nullptr;
-
-		if(mSyncedRenderContext != nullptr)
-		{
-			cm_delete(mSyncedRenderContext);
-		}
 	}
 
 	const RenderSystemCapabilities* RenderSystem::getCapabilities(void) const 
 	{ 
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		return mCurrentCapabilities; 
 	}
 
 	const DriverVersion& RenderSystem::getDriverVersion(void) const 
 	{ 
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		return mDriverVersion; 
 	}
 
     void RenderSystem::disableTextureUnit(GpuProgramType gptype, UINT16 texUnit)
     {
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
         setTexture(gptype, texUnit, false, sNullTexPtr);
     }
 
 	void RenderSystem::addClipPlane (const Plane &p)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		mClipPlanes.push_back(p);
 		mClipPlanesDirty = true;
@@ -153,14 +123,14 @@ namespace CamelotFramework {
 
 	void RenderSystem::addClipPlane (float A, float B, float C, float D)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		addClipPlane(Plane(A, B, C, D));
 	}
 
 	void RenderSystem::setClipPlanes(const PlaneList& clipPlanes)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		if (clipPlanes != mClipPlanes)
 		{
@@ -171,7 +141,7 @@ namespace CamelotFramework {
 
 	void RenderSystem::resetClipPlanes()
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		if (!mClipPlanes.empty())
 		{
@@ -182,7 +152,7 @@ namespace CamelotFramework {
 
 	void RenderSystem::bindGpuProgram(HGpuProgram prg)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		switch(prg->getBindingDelegate()->getType())
 		{
@@ -204,7 +174,7 @@ namespace CamelotFramework {
 
 	void RenderSystem::unbindGpuProgram(GpuProgramType gptype)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		switch(gptype)
 		{
@@ -225,7 +195,7 @@ namespace CamelotFramework {
 
 	bool RenderSystem::isGpuProgramBound(GpuProgramType gptype)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 	    switch(gptype)
 	    {
@@ -242,7 +212,7 @@ namespace CamelotFramework {
 
 	void RenderSystem::render(const RenderOperation& op)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		// sort out clip planes
 		// have to do it here in case of matrix issues
@@ -271,14 +241,14 @@ namespace CamelotFramework {
 
 	void RenderSystem::swapBuffers(RenderTargetPtr target)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		target->swapBuffers();
 	}
 
 	void RenderSystem::writeSubresource(GpuResourcePtr resource, UINT32 subresourceIdx, const GpuResourceData& data, AsyncOp& asyncOp)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		resource->writeSubresource(subresourceIdx, data);
 		data.unlock();
@@ -287,231 +257,10 @@ namespace CamelotFramework {
 
 	void RenderSystem::readSubresource(GpuResourcePtr resource, UINT32 subresourceIdx, GpuResourceData& data, AsyncOp& asyncOp)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		resource->readSubresource(subresourceIdx, data);
 		data.unlock();
 		asyncOp.completeOperation();
 	}
-
-	/************************************************************************/
-	/* 								PRIVATE		                     		*/
-	/************************************************************************/
-
-	void RenderSystem::initRenderThread()
-	{
-#if !CM_FORCE_SINGLETHREADED_RENDERING
-		mRenderThreadFunc = cm_new<RenderWorkerFunc>(this);
-
-#if CM_THREAD_SUPPORT
-		CM_THREAD_CREATE(t, *mRenderThreadFunc);
-		mRenderThread = t;
-
-		CM_LOCK_MUTEX_NAMED(mRenderThreadStartMutex, lock);
-
-		while(!mRenderThreadStarted)
-			CM_THREAD_WAIT(mRenderThreadStartCondition, mRenderThreadStartMutex, lock);
-
-#else
-		CM_EXCEPT(InternalErrorException, "Attempting to start a render thread but Camelot isn't compiled with thread support.");
-#endif
-#endif
-	}
-
-	void RenderSystem::runRenderThread()
-	{
-#if !CM_FORCE_SINGLETHREADED_RENDERING
-		mRenderThreadId = CM_THREAD_CURRENT_ID;
-
-		{
-			CM_LOCK_MUTEX(mRenderThreadStartMutex);
-
-			mRenderThreadStarted = true;
-		}
-
-		CM_THREAD_NOTIFY_ALL(mRenderThreadStartCondition)
-
-		while(true)
-		{
-			// Wait until we get some ready commands
-			Queue<QueuedCommand>::type* commands = nullptr;
-			{
-				CM_LOCK_MUTEX_NAMED(mCommandQueueMutex, lock)
-
-				while(mCommandQueue->isEmpty())
-				{
-					if(mRenderThreadShutdown)
-						return;
-
-					CM_THREAD_WAIT(mCommandReadyCondition, mCommandQueueMutex, lock);
-				}
-
-				commands = mCommandQueue->flush();
-			}
-
-			// Play commands
-			mCommandQueue->playback(commands, boost::bind(&RenderSystem::commandCompletedNotify, this, _1)); 
-		}
-#endif
-	}
-
-	void RenderSystem::shutdownRenderThread()
-	{
-#if !CM_FORCE_SINGLETHREADED_RENDERING
-
-		{
-			CM_LOCK_MUTEX(mCommandQueueMutex);
-			mRenderThreadShutdown = true;
-		}
-
-		// Wake all threads. They will quit after they see the shutdown flag
-		CM_THREAD_NOTIFY_ALL(mCommandReadyCondition);
-
-		mRenderThread->join();
-		CM_THREAD_DESTROY(mRenderThread);
-
-		mRenderThread = nullptr;
-		mRenderThreadId = CM_THREAD_CURRENT_ID;
-
-		if(mRenderThreadFunc != nullptr)
-		{
-			cm_delete(mRenderThreadFunc);
-			mRenderThreadFunc = nullptr;
-		}
-#endif
-
-		mRenderThreadStarted = false;
-	}
-
-	RenderContextPtr RenderSystem::createDeferredContext()
-	{
-		return cm_shared_ptr<DeferredRenderContext<CommandQueueNoSync>>(this, CM_THREAD_CURRENT_ID);
-	}
-
-	SyncedRenderContext& RenderSystem::getSyncedDeferredContext()
-	{
-		return *mSyncedRenderContext;
-	}
-	
-	AsyncOp RenderSystem::queueReturnCommand(boost::function<void(AsyncOp&)> commandCallback, bool blockUntilComplete)
-	{
-		AsyncOp op;
-
-		if(CM_THREAD_CURRENT_ID == getRenderThreadId())
-		{
-			commandCallback(op); // Execute immediately
-			return op;
-		}
-
-		UINT32 commandId = -1;
-		{
-			CM_LOCK_MUTEX(mCommandQueueMutex);
-
-			if(blockUntilComplete)
-			{
-				commandId = mMaxCommandNotifyId++;
-				op = mCommandQueue->queueReturn(commandCallback, true, commandId);
-			}
-			else
-				op = mCommandQueue->queueReturn(commandCallback);
-		}
-
-		CM_THREAD_NOTIFY_ALL(mCommandReadyCondition);
-
-		if(blockUntilComplete)
-			blockUntilCommandCompleted(commandId);
-
-		return op;
-	}
-
-	void RenderSystem::queueCommand(boost::function<void()> commandCallback, bool blockUntilComplete)
-	{
-		if(CM_THREAD_CURRENT_ID == getRenderThreadId())
-		{
-			commandCallback(); // Execute immediately
-			return;
-		}
-
-		UINT32 commandId = -1;
-		{
-			CM_LOCK_MUTEX(mCommandQueueMutex);
-
-			if(blockUntilComplete)
-			{
-				commandId = mMaxCommandNotifyId++;
-				mCommandQueue->queue(commandCallback, true, commandId);
-			}
-			else
-				mCommandQueue->queue(commandCallback);
-		}
-
-		CM_THREAD_NOTIFY_ALL(mCommandReadyCondition);
-
-		if(blockUntilComplete)
-			blockUntilCommandCompleted(commandId);
-	}
-
-	void RenderSystem::blockUntilCommandCompleted(UINT32 commandId)
-	{
-#if !CM_FORCE_SINGLETHREADED_RENDERING
-		CM_LOCK_MUTEX_NAMED(mCommandNotifyMutex, lock);
-
-		while(true)
-		{
-			// TODO - This might be causing a deadlock in Release mode. I'm thinking because mCommandsCompleted isn't marked as volatile.
-
-			// Check if our command id is in the completed list
-			auto iter = mCommandsCompleted.begin();
-			for(; iter != mCommandsCompleted.end(); ++iter)
-			{
-				if(*iter == commandId)
-					break;
-			}
-
-			if(iter != mCommandsCompleted.end())
-			{
-				mCommandsCompleted.erase(iter);
-				break;
-			}
-
-			CM_THREAD_WAIT(mCommandCompleteCondition, mCommandNotifyMutex, lock);
-		}
-#endif
-	}
-
-	void RenderSystem::commandCompletedNotify(UINT32 commandId)
-	{
-		{
-			CM_LOCK_MUTEX(mCommandNotifyMutex);
-
-			mCommandsCompleted.push_back(commandId);
-		}
-
-		CM_THREAD_NOTIFY_ALL(mCommandCompleteCondition);
-	}
-
-	void RenderSystem::throwIfNotRenderThread() const
-	{
-#if !CM_FORCE_SINGLETHREADED_RENDERING
-		if(CM_THREAD_CURRENT_ID != getRenderThreadId())
-			CM_EXCEPT(InternalErrorException, "Calling the render system from a non-render thread!");
-#endif
-	}
-
-	/************************************************************************/
-	/* 								THREAD WORKER                      		*/
-	/************************************************************************/
-
-	RenderSystem::RenderWorkerFunc::RenderWorkerFunc(RenderSystem* rs)
-		:mRS(rs)
-	{
-		assert(mRS != nullptr);
-	}
-
-	void RenderSystem::RenderWorkerFunc::operator()()
-	{
-		mRS->runRenderThread();
-	}
-}
-
-#undef THROW_IF_NOT_RENDER_THREAD
+}

+ 7 - 20
CamelotCore/Source/CmTexture.cpp

@@ -31,14 +31,9 @@ THE SOFTWARE.
 #include "CmDataStream.h"
 #include "CmException.h"
 #include "CmDebug.h"
-#include "CmRenderSystem.h"
+#include "CmCoreThread.h"
 #include "CmAsyncOp.h"
 
-#if CM_DEBUG_MODE
-#define THROW_IF_NOT_RENDER_THREAD throwIfNotRenderThread();
-#else
-#define THROW_IF_NOT_RENDER_THREAD 
-#endif
 
 namespace CamelotFramework {
 	//--------------------------------------------------------------------------
@@ -93,7 +88,7 @@ namespace CamelotFramework {
 
 	void Texture::writeSubresource(UINT32 subresourceIdx, const GpuResourceData& data)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		if(data.getTypeId() != TID_PixelData)
 			CM_EXCEPT(InvalidParametersException, "Invalid GpuResourceData type. Only PixelData is supported.");
@@ -111,7 +106,7 @@ namespace CamelotFramework {
 
 	void Texture::readSubresource(UINT32 subresourceIdx, GpuResourceData& data)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		if(data.getTypeId() != TID_PixelData)
 			CM_EXCEPT(InvalidParametersException, "Invalid GpuResourceData type. Only PixelData is supported.");
@@ -182,7 +177,7 @@ namespace CamelotFramework {
 	//----------------------------------------------------------------------------
 	PixelData Texture::lock(GpuLockOptions options, UINT32 mipLevel, UINT32 face)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		if(mipLevel < 0 || mipLevel > mNumMipmaps)
 			CM_EXCEPT(InvalidParametersException, "Invalid mip level: " + toString(mipLevel) + ". Min is 0, max is " + toString(getNumMipmaps()));
@@ -195,14 +190,14 @@ namespace CamelotFramework {
 	//-----------------------------------------------------------------------------
 	void Texture::unlock()
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		unlockImpl();
 	}
 	//-----------------------------------------------------------------------------
 	void Texture::copy(TexturePtr& target)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		if (target->getUsage() != this->getUsage() ||
 			target->getTextureType() != this->getTextureType())
@@ -232,12 +227,6 @@ namespace CamelotFramework {
 
 		copyImpl(target);
 	}
-	//----------------------------------------------------------------------------- 
-	void Texture::throwIfNotRenderThread() const
-	{
-		if(CM_THREAD_CURRENT_ID != RenderSystem::instancePtr()->getRenderThreadId())
-			CM_EXCEPT(InternalErrorException, "Calling an internal texture method from a non-render thread!");
-	}
 
 	/************************************************************************/
 	/* 								TEXTURE VIEW                      		*/
@@ -344,6 +333,4 @@ namespace CamelotFramework {
 	{
 		return TextureManager::instance().getDummyTexture();
 	}
-}
-
-#undef THROW_IF_NOT_RENDER_THREAD
+}

+ 25 - 32
CamelotD3D11RenderSystem/Source/CmD3D11RenderSystem.cpp

@@ -21,15 +21,10 @@
 #include "CmD3D11InputLayoutManager.h"
 #include "CmD3D11HLSLProgram.h"
 #include "CmGpuParams.h"
+#include "CmCoreThread.h"
 #include "CmDebug.h"
 #include "CmException.h"
 
-#if CM_DEBUG_MODE
-#define THROW_IF_NOT_RENDER_THREAD throwIfNotRenderThread();
-#else
-#define THROW_IF_NOT_RENDER_THREAD 
-#endif
-
 namespace CamelotFramework
 {
 	D3D11RenderSystem::D3D11RenderSystem()
@@ -44,7 +39,7 @@ namespace CamelotFramework
 	D3D11RenderSystem::~D3D11RenderSystem()
 	{
 		// This needs to be called from the child class, since destroy_internal is virtual
-		queueCommand(boost::bind(&D3D11RenderSystem::destroy_internal, this), true);
+		gCoreThread().queueCommand(boost::bind(&D3D11RenderSystem::destroy_internal, this), true);
 	}
 
 	const String& D3D11RenderSystem::getName() const
@@ -61,7 +56,7 @@ namespace CamelotFramework
 
 	void D3D11RenderSystem::initialize_internal(AsyncOp& asyncOp)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&mDXGIFactory);
 		if(FAILED(hr))
@@ -141,7 +136,7 @@ namespace CamelotFramework
 
     void D3D11RenderSystem::destroy_internal()
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		if(mIAManager != nullptr)
 		{
@@ -185,7 +180,7 @@ namespace CamelotFramework
 
 	void D3D11RenderSystem::setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerStatePtr& samplerState)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		// TODO - I'm setting up views one by one, it might be more efficient to hold them in an array
 		//  and then set them all up at once before rendering? Needs testing
@@ -221,7 +216,7 @@ namespace CamelotFramework
 
 	void D3D11RenderSystem::setBlendState(const BlendStatePtr& blendState)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		D3D11BlendState* d3d11BlendState = static_cast<D3D11BlendState*>(const_cast<BlendState*>(blendState.get()));
 		mDevice->getImmediateContext()->OMSetBlendState(d3d11BlendState->getInternal(), nullptr, 0xFFFFFFFF);
@@ -229,7 +224,7 @@ namespace CamelotFramework
 
 	void D3D11RenderSystem::setRasterizerState(const RasterizerStatePtr& rasterizerState)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		D3D11RasterizerState* d3d11RasterizerState = static_cast<D3D11RasterizerState*>(const_cast<RasterizerState*>(rasterizerState.get()));
 		mDevice->getImmediateContext()->RSSetState(d3d11RasterizerState->getInternal());
@@ -237,7 +232,7 @@ namespace CamelotFramework
 
 	void D3D11RenderSystem::setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		D3D11DepthStencilState* d3d11RasterizerState = static_cast<D3D11DepthStencilState*>(const_cast<DepthStencilState*>(depthStencilState.get()));
 		mDevice->getImmediateContext()->OMSetDepthStencilState(d3d11RasterizerState->getInternal(), stencilRefValue);
@@ -245,7 +240,7 @@ namespace CamelotFramework
 
 	void D3D11RenderSystem::setTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const TexturePtr &texPtr)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		// TODO - Set up UAVs?
 		// TODO - I'm setting up views one by one, it might be more efficient to hold them in an array
@@ -287,7 +282,7 @@ namespace CamelotFramework
 
 	void D3D11RenderSystem::disableTextureUnit(GpuProgramType gptype, UINT16 texUnit)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		setTexture(gptype, texUnit, false, nullptr);
 	}
@@ -304,7 +299,7 @@ namespace CamelotFramework
 
 	void D3D11RenderSystem::setViewport(ViewportPtr& vp)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		assert(vp != nullptr);
 
@@ -333,7 +328,7 @@ namespace CamelotFramework
 
 	void D3D11RenderSystem::setVertexBuffer(UINT32 index, const VertexBufferPtr& buffer)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		UINT32 maxBoundVertexBuffers = mCurrentCapabilities->getMaxBoundVertexBuffers();
 		if(index < 0 || index >= maxBoundVertexBuffers)
@@ -351,7 +346,7 @@ namespace CamelotFramework
 
 	void D3D11RenderSystem::setIndexBuffer(const IndexBufferPtr& buffer)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		D3D11IndexBuffer* indexBuffer = static_cast<D3D11IndexBuffer*>(buffer.get());
 
@@ -368,21 +363,21 @@ namespace CamelotFramework
 
 	void D3D11RenderSystem::setVertexDeclaration(VertexDeclarationPtr vertexDeclaration)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		mActiveVertexDeclaration = vertexDeclaration;
 	}
 
 	void D3D11RenderSystem::setDrawOperation(DrawOperationType op)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		mDevice->getImmediateContext()->IASetPrimitiveTopology(D3D11Mappings::getPrimitiveType(op));
 	}
 
 	void D3D11RenderSystem::bindGpuProgram(HGpuProgram prg)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		if(!prg.isLoaded())
 			return;
@@ -433,7 +428,7 @@ namespace CamelotFramework
 
 	void D3D11RenderSystem::unbindGpuProgram(GpuProgramType gptype)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		switch(gptype)
 		{
@@ -463,7 +458,7 @@ namespace CamelotFramework
 
 	void D3D11RenderSystem::bindGpuParams(GpuProgramType gptype, BindableGpuParams& bindableParams)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		GpuParams& params = bindableParams.getParams();
 		params.updateHardwareBuffers();
@@ -532,7 +527,7 @@ namespace CamelotFramework
 
 	void D3D11RenderSystem::draw(UINT32 vertexCount)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		applyInputLayout();
 
@@ -546,7 +541,7 @@ namespace CamelotFramework
 
 	void D3D11RenderSystem::drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexCount)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		applyInputLayout();
 
@@ -560,7 +555,7 @@ namespace CamelotFramework
 
 	void D3D11RenderSystem::setScissorRect(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		mScissorRect.left = static_cast<LONG>(left);
 		mScissorRect.top = static_cast<LONG>(top);
@@ -572,7 +567,7 @@ namespace CamelotFramework
 
 	void D3D11RenderSystem::clear(RenderTargetPtr target, unsigned int buffers, const Color& color, float depth, unsigned short stencil)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		// Clear render surfaces
 		if (buffers & FBT_COLOR)
@@ -626,7 +621,7 @@ namespace CamelotFramework
 
 	void D3D11RenderSystem::setRenderTarget(RenderTargetPtr target)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		mActiveRenderTarget = target;
 
@@ -660,7 +655,7 @@ namespace CamelotFramework
 
 	RenderSystemCapabilities* D3D11RenderSystem::createRenderSystemCapabilities() const
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		RenderSystemCapabilities* rsc = cm_new<RenderSystemCapabilities>();
 
@@ -1008,6 +1003,4 @@ namespace CamelotFramework
 
 		mDevice->getImmediateContext()->IASetInputLayout(ia);
 	}
-}
-
-#undef THROW_IF_NOT_RENDER_THREAD
+}

+ 3 - 10
CamelotD3D11RenderSystem/Source/CmD3D11Texture.cpp

@@ -3,15 +3,10 @@
 #include "CmD3D11Device.h"
 #include "CmD3D11RenderSystem.h"
 #include "CmD3D11TextureView.h"
+#include "CmCoreThread.h"
 #include "CmException.h"
 #include "CmAsyncOp.h"
 
-#if CM_DEBUG_MODE
-#define THROW_IF_NOT_RENDER_THREAD throwIfNotRenderThread();
-#else
-#define THROW_IF_NOT_RENDER_THREAD 
-#endif
-
 namespace CamelotFramework
 {
 	D3D11Texture::D3D11Texture()
@@ -102,7 +97,7 @@ namespace CamelotFramework
 
 	void D3D11Texture::initialize_internal()
 	{
-		THROW_IF_NOT_RENDER_THREAD
+		THROW_IF_NOT_CORE_THREAD;
 
 		Texture::initialize_internal();
 
@@ -613,6 +608,4 @@ namespace CamelotFramework
 
 		return viewPtr;
 	}
-}
-
-#undef THROW_IF_NOT_RENDER_THREAD
+}

+ 49 - 59
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -55,16 +55,9 @@ THE SOFTWARE.
 #include "CmGpuParams.h"
 #include "CmGpuParamDesc.h"
 #include "CmGpuParamBlockBuffer.h"
+#include "CmCoreThread.h"
 #include "CmDebug.h"
 
-#if CM_DEBUG_MODE
-#define THROW_IF_NOT_RENDER_THREAD throwIfNotRenderThread();
-#define THROW_IF_NOT_RENDER_THREAD_STATIC msD3D9RenderSystem->throwIfNotRenderThread();
-#else
-#define THROW_IF_NOT_RENDER_THREAD 
-#define THROW_IF_NOT_RENDER_THREAD_STATIC
-#endif
-
 #define FLOAT2DWORD(f) *((DWORD*)&f)
 
 // Formats to try, in decreasing order of preference
@@ -118,7 +111,7 @@ namespace CamelotFramework
 	D3D9RenderSystem::~D3D9RenderSystem()
 	{
 		// This needs to be called from the child class, since destroy_internal is virtual
-		queueCommand(boost::bind(&D3D9RenderSystem::destroy_internal, this), true);
+		gCoreThread().queueCommand(boost::bind(&D3D9RenderSystem::destroy_internal, this), true);
 	}
 
 	const String& D3D9RenderSystem::getName() const
@@ -135,7 +128,7 @@ namespace CamelotFramework
 
 	void D3D9RenderSystem::initialize_internal(AsyncOp& asyncOp)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		// Create the resource manager.
 		mResourceManager = cm_new<D3D9ResourceManager>();
@@ -250,7 +243,7 @@ namespace CamelotFramework
 	//--------------------------------------------------------------------
 	void D3D9RenderSystem::registerWindow(RenderWindow& renderWindow)
 	{		
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		D3D9RenderWindow* d3d9renderWindow = static_cast<D3D9RenderWindow*>(&renderWindow);
 
@@ -276,7 +269,7 @@ namespace CamelotFramework
 
 	void D3D9RenderSystem::bindGpuProgram(HGpuProgram prg)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		if(!prg.isLoaded())
 			return;
@@ -317,7 +310,7 @@ namespace CamelotFramework
 
 	void D3D9RenderSystem::unbindGpuProgram(GpuProgramType gptype)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
 		switch(gptype)
@@ -343,7 +336,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::bindGpuParams(GpuProgramType gptype, BindableGpuParams& bindableParams)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		GpuParams& params = bindableParams.getParams();
 		params.updateHardwareBuffers();
@@ -505,7 +498,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const TexturePtr& tex)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		if(gptype != GPT_FRAGMENT_PROGRAM && gptype != GPT_VERTEX_PROGRAM)
 		{
@@ -575,7 +568,7 @@ namespace CamelotFramework
 	//-----------------------------------------------------------------------
 	void D3D9RenderSystem::setSamplerState(GpuProgramType gptype, UINT16 unit, const SamplerStatePtr& state)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		if(gptype != GPT_FRAGMENT_PROGRAM && gptype != GPT_VERTEX_PROGRAM)
 		{
@@ -609,7 +602,7 @@ namespace CamelotFramework
 	//-----------------------------------------------------------------------
 	void D3D9RenderSystem::setBlendState(const BlendStatePtr& blendState)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		// Alpha to coverage
 		setAlphaToCoverage(blendState->getAlphaToCoverageEnabled());
@@ -633,7 +626,7 @@ namespace CamelotFramework
 	//----------------------------------------------------------------------
 	void D3D9RenderSystem::setRasterizerState(const RasterizerStatePtr& rasterizerState)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		setDepthBias((float)rasterizerState->getDepthBias(), rasterizerState->getSlopeScaledDepthBias());
 
@@ -650,7 +643,7 @@ namespace CamelotFramework
 	//----------------------------------------------------------------------
 	void D3D9RenderSystem::setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		// Set stencil buffer options
 		setStencilCheckEnabled(depthStencilState->getStencilEnable());
@@ -675,7 +668,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setTextureMipmapBias(UINT16 unit, float bias)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		if (mCurrentCapabilities->hasCapability(RSC_MIPMAP_LOD_BIAS))
 		{
@@ -690,7 +683,7 @@ namespace CamelotFramework
 	void D3D9RenderSystem::setTextureAddressingMode( UINT16 stage, 
 		const UVWAddressingMode& uvw )
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
 		if( FAILED( hr = __SetSamplerState( static_cast<DWORD>(stage), D3DSAMP_ADDRESSU, D3D9Mappings::get(uvw.u, mDeviceManager->getActiveDevice()->getD3D9DeviceCaps()) ) ) )
@@ -704,7 +697,7 @@ namespace CamelotFramework
 	void D3D9RenderSystem::setTextureBorderColor(UINT16 stage,
 		const Color& colour)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
 		if( FAILED( hr = __SetSamplerState( static_cast<DWORD>(stage), D3DSAMP_BORDERCOLOR, colour.getAsBGRA()) ) )
@@ -713,7 +706,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setSceneBlending( BlendFactor sourceFactor, BlendFactor destFactor, BlendOperation op )
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
 		if( sourceFactor == BF_ONE && destFactor == BF_ZERO)
@@ -742,7 +735,7 @@ namespace CamelotFramework
 	void D3D9RenderSystem::setSceneBlending( BlendFactor sourceFactor, BlendFactor destFactor, BlendFactor sourceFactorAlpha, 
 		BlendFactor destFactorAlpha, BlendOperation op, BlendOperation alphaOp )
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
 		if( sourceFactor == BF_ONE && destFactor == BF_ZERO && 
@@ -775,7 +768,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setAlphaTest(CompareFunction func, unsigned char value)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
 
@@ -798,7 +791,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setAlphaToCoverage(bool enable)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
 		static bool lasta2c = false;
@@ -842,7 +835,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setCullingMode( CullingMode mode )
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		mCullingMode = mode;
 		HRESULT hr;
@@ -856,7 +849,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setDepthBufferParams( bool depthTest, bool depthWrite, CompareFunction depthFunction )
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		setDepthBufferCheckEnabled( depthTest );
 		setDepthBufferWriteEnabled( depthWrite );
@@ -865,7 +858,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setDepthBufferCheckEnabled( bool enabled )
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
 
@@ -880,7 +873,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setDepthBufferWriteEnabled( bool enabled )
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
 
@@ -890,7 +883,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setDepthBufferFunction( CompareFunction func )
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
 		if( FAILED( hr = __SetRenderState( D3DRS_ZFUNC, D3D9Mappings::get(func) ) ) )
@@ -899,7 +892,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setDepthBias(float constantBias, float slopeScaleBias)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		if ((mDeviceManager->getActiveDevice()->getD3D9DeviceCaps().RasterCaps & D3DPRASTERCAPS_DEPTHBIAS) != 0)
 		{
@@ -927,7 +920,7 @@ namespace CamelotFramework
 	void D3D9RenderSystem::setColorBufferWriteEnabled(bool red, bool green, 
 		bool blue, bool alpha)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		DWORD val = 0;
 		if (red) 
@@ -945,7 +938,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setPolygonMode(PolygonMode level)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr = __SetRenderState(D3DRS_FILLMODE, D3D9Mappings::get(level));
 		if (FAILED(hr))
@@ -954,7 +947,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setStencilCheckEnabled(bool enabled)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		// Allow stencilling
 		HRESULT hr = __SetRenderState(D3DRS_STENCILENABLE, enabled);
@@ -979,7 +972,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setStencilBufferOperations(StencilOperation stencilFailOp, StencilOperation depthFailOp, StencilOperation passOp, bool ccw)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
 
@@ -1051,7 +1044,7 @@ namespace CamelotFramework
 	//----------------------------------------------------------------------
 	void D3D9RenderSystem::setStencilRefValue(UINT32 refValue)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr = __SetRenderState(D3DRS_STENCILREF, refValue);
 		if (FAILED(hr))
@@ -1061,7 +1054,7 @@ namespace CamelotFramework
 	void D3D9RenderSystem::setTextureFiltering(UINT16 unit, FilterType ftype, 
 		FilterOptions filter)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
 		D3D9Mappings::eD3DTexType texType = mTexStageDesc[unit].texType;
@@ -1074,7 +1067,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setTextureAnisotropy(UINT16 unit, unsigned int maxAnisotropy)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		if (static_cast<DWORD>(maxAnisotropy) > mDeviceManager->getActiveDevice()->getD3D9DeviceCaps().MaxAnisotropy)
 			maxAnisotropy = mDeviceManager->getActiveDevice()->getD3D9DeviceCaps().MaxAnisotropy;
@@ -1085,7 +1078,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setRenderTarget(RenderTargetPtr target)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		mActiveRenderTarget = target;
 
@@ -1138,7 +1131,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setViewport(ViewportPtr& vp)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		assert(vp != nullptr);
 
@@ -1176,7 +1169,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::beginFrame()
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
 
@@ -1191,7 +1184,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::endFrame()
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
 		if( FAILED( hr = getActiveD3D9Device()->EndScene() ) )
@@ -1202,7 +1195,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setVertexDeclaration(VertexDeclarationPtr decl)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
 
@@ -1218,7 +1211,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setVertexBuffer(UINT32 index, const VertexBufferPtr& buffer)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		UINT32 maxBoundVertexBuffers = mCurrentCapabilities->getMaxBoundVertexBuffers();
 		if(index < 0 || index >= maxBoundVertexBuffers)
@@ -1247,7 +1240,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setIndexBuffer(const IndexBufferPtr& buffer)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		D3D9IndexBuffer* d3dIdxBuf = static_cast<D3D9IndexBuffer*>(buffer.get());
 
@@ -1258,7 +1251,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setDrawOperation(DrawOperationType op)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		mCurrentDrawOperation = op;
 	}
@@ -1299,7 +1292,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setScissorRect(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		mScissorRect.left = static_cast<LONG>(left);
 		mScissorRect.top = static_cast<LONG>(top);
@@ -1309,7 +1302,7 @@ namespace CamelotFramework
 	//--------------------------------------------------------------------
 	void D3D9RenderSystem::setScissorTestEnable(bool enable)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		HRESULT hr;
 		if (enable)
@@ -1374,7 +1367,7 @@ namespace CamelotFramework
 	void D3D9RenderSystem::clear(RenderTargetPtr target, unsigned int buffers, 
 		const Color& colour, float depth, unsigned short stencil)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		RenderTargetPtr previousRenderTarget = mActiveRenderTarget;
 		if(target != mActiveRenderTarget)
@@ -1420,7 +1413,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	IDirect3D9*	D3D9RenderSystem::getDirect3D9()
 	{
-		THROW_IF_NOT_RENDER_THREAD_STATIC;
+		THROW_IF_NOT_CORE_THREAD;
 
 		IDirect3D9* pDirect3D9 = msD3D9RenderSystem->mpD3D;
 
@@ -1435,7 +1428,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	UINT D3D9RenderSystem::getResourceCreationDeviceCount()
 	{
-		THROW_IF_NOT_RENDER_THREAD_STATIC;
+		THROW_IF_NOT_CORE_THREAD;
 
 		D3D9ResourceCreationPolicy creationPolicy = msD3D9RenderSystem->mResourceManager->getCreationPolicy();
 
@@ -1455,7 +1448,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	IDirect3DDevice9* D3D9RenderSystem::getResourceCreationDevice(UINT index)
 	{
-		THROW_IF_NOT_RENDER_THREAD_STATIC;
+		THROW_IF_NOT_CORE_THREAD;
 
 		D3D9ResourceCreationPolicy creationPolicy = msD3D9RenderSystem->mResourceManager->getCreationPolicy();
 		IDirect3DDevice9* d3d9Device = NULL;
@@ -1479,7 +1472,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	IDirect3DDevice9* D3D9RenderSystem::getActiveD3D9Device()
 	{	
-		THROW_IF_NOT_RENDER_THREAD_STATIC;
+		THROW_IF_NOT_CORE_THREAD;
 
 		D3D9Device* activeDevice = msD3D9RenderSystem->mDeviceManager->getActiveDevice();
 		IDirect3DDevice9* d3d9Device;
@@ -1504,7 +1497,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	D3D9DeviceManager* D3D9RenderSystem::getDeviceManager()
 	{
-		THROW_IF_NOT_RENDER_THREAD_STATIC;
+		THROW_IF_NOT_CORE_THREAD;
 
 		return msD3D9RenderSystem->mDeviceManager;
 	}
@@ -2594,7 +2587,4 @@ namespace CamelotFramework
 		getActiveD3D9Device()->GetSamplerState(static_cast<DWORD>(unit), D3DSAMP_MAXANISOTROPY, &oldVal);
 		return oldVal;
 	}
-}
-
-#undef THROW_IF_NOT_RENDER_THREAD
-#undef THROW_IF_NOT_RENDER_THREAD_STATIC
+}

+ 9 - 16
CamelotD3D9Renderer/Source/CmD3D9Texture.cpp

@@ -25,6 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 -----------------------------------------------------------------------------
 */
+#include "CmCoreThread.h"
 #include "CmD3D9Texture.h"
 #include "CmD3D9PixelBuffer.h"
 #include "CmException.h"
@@ -36,12 +37,6 @@ THE SOFTWARE.
 #include "CmD3D9DeviceManager.h"
 #include "CmD3D9ResourceManager.h"
 
-#if CM_DEBUG_MODE
-#define THROW_IF_NOT_RENDER_THREAD throwIfNotRenderThread();
-#else
-#define THROW_IF_NOT_RENDER_THREAD 
-#endif
-
 namespace CamelotFramework 
 {
 	/****************************************************************************************/
@@ -92,7 +87,7 @@ namespace CamelotFramework
 	/****************************************************************************************/
 	void D3D9Texture::copyImpl(TexturePtr& target)
 	{
-		THROW_IF_NOT_RENDER_THREAD
+		THROW_IF_NOT_CORE_THREAD;
 
         // check if this & target are the same format and type
 		// blitting from or to cube textures is not supported yet
@@ -201,7 +196,7 @@ namespace CamelotFramework
 	/****************************************************************************************/
 	void D3D9Texture::initialize_internal()
 	{ 
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		Texture::initialize_internal();
 
@@ -215,7 +210,7 @@ namespace CamelotFramework
 	/****************************************************************************************/
 	void D3D9Texture::destroy_internal()
 	{ 
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		DeviceToTextureResourcesIterator it = mMapDeviceToTextureResources.begin();
 		while (it != mMapDeviceToTextureResources.end())
@@ -1081,7 +1076,7 @@ namespace CamelotFramework
 	/****************************************************************************************/
 	PixelBufferPtr D3D9Texture::getBuffer(UINT32 face, UINT32 mipmap) 
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		if(face >= getNumFaces())
 			CM_EXCEPT(InvalidParametersException, "A three dimensional cube has six faces");
@@ -1186,7 +1181,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	IDirect3DBaseTexture9* D3D9Texture::getTexture_internal()
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		TextureResources* textureResources;			
 		IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getActiveD3D9Device();
@@ -1206,7 +1201,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	IDirect3DTexture9* D3D9Texture::getNormTexture_internal()
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		TextureResources* textureResources;
 		IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getActiveD3D9Device();
@@ -1226,7 +1221,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	IDirect3DCubeTexture9* D3D9Texture::getCubeTexture_internal()
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		TextureResources* textureResources;
 		IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getActiveD3D9Device();
@@ -1242,6 +1237,4 @@ namespace CamelotFramework
 
 		return textureResources->pCubeTex;
 	}	
-}
-
-#undef THROW_IF_NOT_RENDER_THREAD
+}

+ 1 - 1
CamelotFBXImporter/Source/CmFBXImporter.cpp

@@ -52,7 +52,7 @@ namespace CamelotFramework
 
 		mesh.waitUntilLoaded();
 		gMainSyncedCA().writeSubresource(mesh.getInternalPtr(), 0, *meshData);
-		gMainSyncedCA().submitToGpu(true); // TODO - Possibly we can avoid this. I don't see a reason we need to wait for the update to complete.
+		gMainSyncedCA().submitToCoreThread(true); // TODO - Possibly we can avoid this. I don't see a reason we need to wait for the update to complete.
 
 		return mesh;
 	}

+ 1 - 1
CamelotFontImporter/Source/CmFontImporter.cpp

@@ -273,7 +273,7 @@ namespace CamelotFramework
 
 				UINT32 subresourceIdx = newTex->mapToSubresourceIdx(0, 0);
 				gMainSyncedCA().writeSubresource(newTex.getInternalPtr(), subresourceIdx, pixelData);
-				gMainSyncedCA().submitToGpu(true); // TODO - Possibly we can avoid this. I don't see a reason we need to wait for the update to complete.
+				gMainSyncedCA().submitToCoreThread(true); // TODO - Possibly we can avoid this. I don't see a reason we need to wait for the update to complete.
 
 				fontData.texturePages.push_back(newTex);
 

+ 1 - 1
CamelotFreeImgImporter/Source/CmFreeImgImporter.cpp

@@ -136,7 +136,7 @@ namespace CamelotFramework
 
 			UINT32 subresourceIdx = newTexture->mapToSubresourceIdx(0, mip);
 			gMainSyncedCA().writeSubresource(newTexture.getInternalPtr(), subresourceIdx, src);
-			gMainSyncedCA().submitToGpu(true); // TODO - Possibly we can avoid this. I don't see a reason we need to wait for the update to complete.
+			gMainSyncedCA().submitToCoreThread(true); // TODO - Possibly we can avoid this. I don't see a reason we need to wait for the update to complete.
 		}
 
 		fileData->close();

+ 23 - 30
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -51,14 +51,9 @@ THE SOFTWARE.s
 #include "CmRenderStateManager.h"
 #include "CmGpuParams.h"
 #include "CmGLGpuParamBlockBuffer.h"
+#include "CmCoreThread.h"
 #include "CmDebug.h"
 
-#if CM_DEBUG_MODE
-#define THROW_IF_NOT_RENDER_THREAD throwIfNotRenderThread();
-#else
-#define THROW_IF_NOT_RENDER_THREAD 
-#endif
-
 // Convenience macro from ARB_vertex_buffer_object spec
 #define VBO_BUFFER_OFFSET(i) ((char *)NULL + (i))
 
@@ -121,7 +116,7 @@ namespace CamelotFramework
 	GLRenderSystem::~GLRenderSystem()
 	{
 		// This needs to be called from the child class, since destroy_internal is virtual
-		queueCommand(boost::bind(&GLRenderSystem::destroy_internal, this), true);
+		gCoreThread().queueCommand(boost::bind(&GLRenderSystem::destroy_internal, this), true);
 	}
 
 	const String& GLRenderSystem::getName(void) const
@@ -139,7 +134,7 @@ namespace CamelotFramework
 
 	void GLRenderSystem::initialize_internal(AsyncOp& asyncOp)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		mGLSupport->start();
 		RenderWindowManager::startUp(cm_new<GLRenderWindowManager>(this));
@@ -247,7 +242,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void GLRenderSystem::bindGpuProgram(HGpuProgram prg)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		GpuProgramPtr bindingPrg = prg->getBindingDelegate();
 		GLSLGpuProgramPtr glprg = std::static_pointer_cast<GLSLGpuProgram>(bindingPrg);
@@ -297,7 +292,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void GLRenderSystem::unbindGpuProgram(GpuProgramType gptype)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		setActiveProgram(gptype, nullptr);
 
@@ -306,7 +301,7 @@ namespace CamelotFramework
 	//-----------------------------------------------------------------------------
 	void GLRenderSystem::bindGpuParams(GpuProgramType gptype, BindableGpuParams& bindableParams)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		GpuParams& params = bindableParams.getParams();
 		params.updateHardwareBuffers();
@@ -456,7 +451,7 @@ namespace CamelotFramework
 	//-----------------------------------------------------------------------------
 	void GLRenderSystem::setTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const TexturePtr &texPtr)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		unit = getGLTextureUnit(gptype, unit);
 
@@ -486,7 +481,7 @@ namespace CamelotFramework
 	//-----------------------------------------------------------------------
 	void GLRenderSystem::setSamplerState(GpuProgramType gptype, UINT16 unit, const SamplerStatePtr& state)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		unit = getGLTextureUnit(gptype, unit);
 
@@ -511,7 +506,7 @@ namespace CamelotFramework
 	//-----------------------------------------------------------------------------
 	void GLRenderSystem::setBlendState(const BlendStatePtr& blendState)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		// Alpha to coverage
 		setAlphaToCoverage(blendState->getAlphaToCoverageEnabled());
@@ -535,7 +530,7 @@ namespace CamelotFramework
 	//----------------------------------------------------------------------
 	void GLRenderSystem::setRasterizerState(const RasterizerStatePtr& rasterizerState)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		setDepthBias((float)rasterizerState->getDepthBias(), rasterizerState->getSlopeScaledDepthBias());
 
@@ -548,7 +543,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void GLRenderSystem::setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		// Set stencil buffer options
 		setStencilCheckEnabled(depthStencilState->getStencilEnable());
@@ -572,7 +567,7 @@ namespace CamelotFramework
 	//-----------------------------------------------------------------------------
 	void GLRenderSystem::setViewport(ViewportPtr& vp)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		assert(vp != nullptr);
 
@@ -599,7 +594,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void GLRenderSystem::setRenderTarget(RenderTargetPtr target)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		mActiveRenderTarget = target;
 
@@ -639,7 +634,7 @@ namespace CamelotFramework
 	//-----------------------------------------------------------------------------
 	void GLRenderSystem::beginFrame(void)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		// Activate the viewport clipping
 		glEnable(GL_SCISSOR_TEST);
@@ -648,7 +643,7 @@ namespace CamelotFramework
 	//-----------------------------------------------------------------------------
 	void GLRenderSystem::endFrame(void)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		// Deactivate the viewport clipping.
 		glDisable(GL_SCISSOR_TEST);
@@ -661,28 +656,28 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void GLRenderSystem::setVertexBuffer(UINT32 index, const VertexBufferPtr& buffer)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		mBoundVertexBuffers[index] = buffer;
 	}
 	//---------------------------------------------------------------------
 	void GLRenderSystem::setVertexDeclaration(VertexDeclarationPtr vertexDeclaration)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		mBoundVertexDeclaration = vertexDeclaration;
 	}
 	//---------------------------------------------------------------------
 	void GLRenderSystem::setDrawOperation(DrawOperationType op)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		mCurrentDrawOperation = op;
 	}
 	//---------------------------------------------------------------------
 	void GLRenderSystem::setIndexBuffer(const IndexBufferPtr& buffer)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		mBoundIndexBuffer = buffer;
 	}
@@ -724,7 +719,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void GLRenderSystem::setScissorRect(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		mScissorTop = top;
 		mScissorBottom = bottom;
@@ -735,7 +730,7 @@ namespace CamelotFramework
 	void GLRenderSystem::clear(RenderTargetPtr target, unsigned int buffers, 
 		const Color& colour, float depth, unsigned short stencil)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		RenderTargetPtr previousRenderTarget = mActiveRenderTarget;
 		if(target != mActiveRenderTarget)
@@ -1201,7 +1196,7 @@ namespace CamelotFramework
 	//---------------------------------------------------------------------
 	void GLRenderSystem::setStencilRefValue(UINT32 refValue)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		mStencilRefValue = refValue;
 
@@ -2405,6 +2400,4 @@ namespace CamelotFramework
 		// no any conversion request for OpenGL
 		dest = matrix;
 	}
-}
-
-#undef THROW_IF_NOT_RENDER_THREAD
+}

+ 4 - 11
CamelotGLRenderer/Source/CmGLTexture.cpp

@@ -33,6 +33,7 @@ THE SOFTWARE.
 
 #include "CmException.h"
 #include "CmBitwise.h"
+#include "CmCoreThread.h"
 #include "CmTextureManager.h"
 
 #include "CmGLRenderTexture.h"
@@ -46,12 +47,6 @@ THE SOFTWARE.
 #  include <wingdi.h>
 #endif
 
-#if CM_DEBUG_MODE
-#define THROW_IF_NOT_RENDER_THREAD throwIfNotRenderThread();
-#else
-#define THROW_IF_NOT_RENDER_THREAD 
-#endif
-
 namespace CamelotFramework {
 
     GLTexture::GLTexture(GLSupport& support) 
@@ -233,7 +228,7 @@ namespace CamelotFramework {
 
 	GLuint GLTexture::getGLID() const
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		return mTextureID;
 	}
@@ -307,7 +302,7 @@ namespace CamelotFramework {
 	//---------------------------------------------------------------------------------------------
 	PixelBufferPtr GLTexture::getBuffer(UINT32 face, UINT32 mipmap)
 	{
-		THROW_IF_NOT_RENDER_THREAD;
+		THROW_IF_NOT_CORE_THREAD;
 
 		if(face >= getNumFaces())
 			CM_EXCEPT(InvalidParametersException, "Face index out of range");
@@ -317,6 +312,4 @@ namespace CamelotFramework {
 		assert(idx < mSurfaceList.size());
 		return mSurfaceList[idx];
 	}
-}
-
-#undef THROW_IF_NOT_RENDER_THREAD
+}