فهرست منبع

More documentation
Refactored CoreThreadAccessor and Pass

Marko Pintera 11 سال پیش
والد
کامیت
59cb02050e

+ 1 - 0
BansheeEngine/Source/BsBuiltinResources.cpp

@@ -14,6 +14,7 @@
 #include "CmRTTIType.h"
 #include "CmFileSystem.h"
 #include "CmApplication.h"
+#include "CmCoreThread.h"
 
 namespace BansheeEngine
 {

+ 1 - 0
BansheeEngine/Source/BsGUIManager.cpp

@@ -33,6 +33,7 @@
 #include "CmTransientMesh.h"
 #include "BsVirtualInput.h"
 #include "BsCursor.h"
+#include "CmCoreThread.h"
 
 using namespace std::placeholders;
 

+ 4 - 4
BansheeForwardRenderer/Source/BsForwardRenderer.cpp

@@ -17,6 +17,7 @@
 #include "BsDrawHelper2D.h"
 #include "BsDrawHelper3D.h"
 #include "BsGUIManager.h"
+#include "CmCoreThread.h"
 
 #include "CmProfiler.h"
 
@@ -185,14 +186,13 @@ namespace BansheeEngine
 			const RenderOperation& renderOp = *iter->baseOperation;
 			MaterialPtr material = renderOp.material;
 
-			PassPtr pass = material->getPass(iter->passIdx);
-			pass->activate(coreAccessor);
-
 			gProfiler().endSample("renderG");
 			gProfiler().beginSample("renderH");
 
+			PassPtr pass = material->getPass(iter->passIdx);
 			PassParametersPtr paramsPtr = material->getPassParameters(iter->passIdx);
-			pass->bindParameters(coreAccessor, paramsPtr);
+
+			coreAccessor.setPass(pass, paramsPtr);
 
 			gProfiler().endSample("renderH");
 			gProfiler().beginSample("renderI");

+ 0 - 1
CamelotCore/Include/CmCommandQueue.h

@@ -176,7 +176,6 @@ namespace BansheeEngine
 		 */
 		static void addBreakpoint(UINT32 queueIdx, UINT32 commandIdx);
 
-	protected:
 		/**
 		 * @brief	Queue up a new command to execute. Make sure the provided function has all of its
 		 * 			parameters properly bound. Last parameter must be unbound and of AsyncOp& type.

+ 70 - 182
CamelotCore/Include/CmCoreThreadAccessor.h

@@ -4,193 +4,99 @@
 #include "CmCommonEnums.h"
 #include "CmRenderSystem.h"
 #include "CmCommandQueue.h"
-#include "CmSamplerState.h"
-#include "CmGpuProgram.h"
-#include "CmCoreThread.h"
 #include "CmAsyncOp.h"
 #include "CmColor.h"
-#include "CmFrameAlloc.h"
 
 namespace BansheeEngine
 {
 	/**
-	 * @brief	Core thread accessor allows you to schedule core commands outside of the core thread. Provides a set of common
-	 * 			methods you may want to execute on the core thread, as well as a general command queuing methods.
+	 * @brief	Contains some base functionality used for CoreThreadAccessor.
 	 * 			
-	 * @note	Queued commands are only executed after the call to submitToCoreThread, in the order they were submitted.
+	 * @see		CoreThreadAccesor
 	 */
-	template <class CommandQueueSyncPolicy = CommandQueueNoSync>
-	class CM_EXPORT CoreThreadAccessor
+	class CM_EXPORT CoreThreadAccessorBase
 	{
 	public:
-		/**
-		 * @brief	Constructor.
-		 *
-		 * @param	threadId		Identifier for the thread that created the accessor.
-		 */
-		CoreThreadAccessor(CM_THREAD_ID_TYPE threadId)
-		{
-			mCommandQueue = cm_new<CommandQueue<CommandQueueSyncPolicy>>(threadId);
-		}
-
-		~CoreThreadAccessor()
-		{
-			cm_delete(mCommandQueue);
-		}
+		CoreThreadAccessorBase(CommandQueueBase* commandQueue);
+		virtual ~CoreThreadAccessorBase();
 
 		/** @copydoc RenderSystem::disableTextureUnit() */
-		void disableTextureUnit(GpuProgramType gptype, UINT16 texUnit)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::disableTextureUnit, RenderSystem::instancePtr(), gptype, texUnit));
-		}
+		void disableTextureUnit(GpuProgramType gptype, UINT16 texUnit);
 
 		/** @copydoc RenderSystem::setTexture() */
-		void setTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const TexturePtr &texPtr)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::setTexture, RenderSystem::instancePtr(), gptype, unit, enabled, texPtr));
-		}
+		void setTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const TexturePtr &texPtr);
 
 		/** @copydoc RenderSystem::setSamplerState() */
-		void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerStatePtr& samplerState)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::setSamplerState, RenderSystem::instancePtr(), gptype, texUnit, samplerState));
-		}
+		void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerStatePtr& samplerState);
 
 		/** @copydoc RenderSystem::setBlendState() */
-		void setBlendState(const BlendStatePtr& blendState)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::setBlendState, RenderSystem::instancePtr(), blendState));
-		}
+		void setBlendState(const BlendStatePtr& blendState);
 
 		/** @copydoc RenderSystem::setRasterizerState() */
-		void setRasterizerState(const RasterizerStatePtr& rasterizerState)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::setRasterizerState, RenderSystem::instancePtr(), rasterizerState));
-		}
+		void setRasterizerState(const RasterizerStatePtr& rasterizerState);
 
 		/** @copydoc RenderSystem::setRasterizerState() */
-		void setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::setDepthStencilState, RenderSystem::instancePtr(), depthStencilState, stencilRefValue));
-		}
+		void setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue);
 
 		/** @copydoc RenderSystem::setViewport() */
-		void setViewport(const ViewportPtr& vp)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::setViewport, RenderSystem::instancePtr(), vp));
-		}
+		void setViewport(const ViewportPtr& vp);
 
 		/** @copydoc RenderSystem::setDrawOperation() */
-		void setDrawOperation(DrawOperationType op)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::setDrawOperation, RenderSystem::instancePtr(), op));
-		}
+		void setDrawOperation(DrawOperationType op);
 
 		/** @copydoc RenderSystem::setClipPlanes() */
-		void setClipPlanes(const PlaneList& clipPlanes)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::setClipPlanes, RenderSystem::instancePtr(), clipPlanes));
-		}
+		void setClipPlanes(const PlaneList& clipPlanes);
 
 		/** @copydoc RenderSystem::addClipPlane(const Plane&) */
-		void addClipPlane(const Plane& p)
-		{
-			mCommandQueue->queue(std::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(std::bind(&RenderSystem::addClipPlane, RenderSystem::instancePtr(), A, B, C, D));
-		}
+		void addClipPlane(const Plane& p);
 
 		/** @copydoc RenderSystem::resetClipPlanes() */
-		void resetClipPlanes()
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::resetClipPlanes, RenderSystem::instancePtr()));
-		}
+		void resetClipPlanes();
 
 		/** @copydoc RenderSystem::setScissorTest() */
-		void setScissorTest(UINT32 left = 0, UINT32 top = 0, UINT32 right = 800, UINT32 bottom = 600)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::setScissorRect, RenderSystem::instancePtr(), left, top, right, bottom));
-		}
+		void setScissorTest(UINT32 left = 0, UINT32 top = 0, UINT32 right = 800, UINT32 bottom = 600);
 
 		/** @copydoc RenderSystem::setRenderTarget() */
-		void setRenderTarget(RenderTargetPtr target)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::setRenderTarget, RenderSystem::instancePtr(), target));
-		}
+		void setRenderTarget(RenderTargetPtr target);
 
 		/** @copydoc RenderSystem::bindGpuProgram() */
-		void bindGpuProgram(HGpuProgram prg)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::bindGpuProgram, RenderSystem::instancePtr(), prg));
-		}
+		void bindGpuProgram(HGpuProgram prg);
 
 		/** @copydoc RenderSystem::unbindGpuProgram() */
-		void unbindGpuProgram(GpuProgramType gptype)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::unbindGpuProgram, RenderSystem::instancePtr(), gptype));
-		}
+		void unbindGpuProgram(GpuProgramType gptype);
 
 		/** @copydoc RenderSystem::bindGpuParams() */
-		void bindGpuParams(GpuProgramType gptype, const GpuParamsPtr& params)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::bindGpuParams, RenderSystem::instancePtr(), gptype, BindableGpuParams(params, gCoreThread().getFrameAlloc())));
-		}
+		void bindGpuParams(GpuProgramType gptype, const GpuParamsPtr& params);
 
 		/** @copydoc RenderSystem::beginFrame() */
-		void beginRender(void)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::beginFrame, RenderSystem::instancePtr()));
-		}
+		void beginRender();
 
 		/** @copydoc RenderSystem::endFrame() */
-		void endRender(void)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::endFrame, RenderSystem::instancePtr()));
-		}
+		void endRender();
 
-		/**
-		 * @copydoc RenderSystem::clearRenderTarget()
-		 */
-		void clearRenderTarget(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::clearRenderTarget, RenderSystem::instancePtr(), buffers, color, depth, stencil));
-		}
+		/** @copydoc RenderSystem::clearRenderTarget() */
+		void clearRenderTarget(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0);
 
-		/**
-		 * @copydoc RenderSystem::clearViewport()
-		 */
-		void clearViewport(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::clearViewport, RenderSystem::instancePtr(), buffers, color, depth, stencil));
-		}
+		/** @copydoc RenderSystem::clearViewport() */
+		void clearViewport(UINT32 buffers, const Color& color = Color::Black, float depth = 1.0f, UINT16 stencil = 0);
 
 		/** @copydoc RenderSystem::swapBuffers() */
-		void swapBuffers(RenderTargetPtr target)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::swapBuffers, RenderSystem::instancePtr(), target));
-		}
+		void swapBuffers(RenderTargetPtr target);
 
 		/** @copydoc RenderSystem::render() */
-		void render(const MeshBasePtr& mesh, UINT32 indexOffset = 0, UINT32 indexCount = 0, bool useIndices = true, DrawOperationType drawOp = DOT_TRIANGLE_LIST)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::render, RenderSystem::instancePtr(), mesh, indexOffset, indexCount, useIndices, drawOp));
-		}
+		void render(const MeshBasePtr& mesh, UINT32 indexOffset = 0, UINT32 indexCount = 0, bool useIndices = true, DrawOperationType drawOp = DOT_TRIANGLE_LIST);
 
 		/** @copydoc RenderSystem::draw() */
-		void draw(UINT32 vertexOffset, UINT32 vertexCount)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::draw, RenderSystem::instancePtr(), vertexOffset, vertexCount));
-		}
+		void draw(UINT32 vertexOffset, UINT32 vertexCount);
 
 		/** @copydoc RenderSystem::drawIndexed() */
-		void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexOffset, UINT32 vertexCount)
-		{
-			mCommandQueue->queue(std::bind(&RenderSystem::drawIndexed, RenderSystem::instancePtr(), startIndex, indexCount, vertexOffset, vertexCount));
-		}
+		void drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexOffset, UINT32 vertexCount);
+
+		/**
+		 * @brief	Binds the specified parameters to the pass GPU programs and activates the pass and its
+		 * 			states for any further rendering.
+		 */
+		void setPass(const PassPtr& pass, const PassParametersPtr& params);
 
 		/**
 		 * @copydoc RenderSystem::writeSubresource()
@@ -205,13 +111,7 @@ namespace BansheeEngine
 		 * 		 
 		 *		Normally dynamic buffers will require you to enable "discardEntireBuffer" flag, while static buffers require it disabled.
 		 */
-		AsyncOp writeSubresource(GpuResourcePtr resource, UINT32 subresourceIdx, const GpuResourceDataPtr& data, bool discardEntireBuffer = false)
-		{
-			data->lock();
-
-			return mCommandQueue->queueReturn(std::bind(&RenderSystem::writeSubresource, RenderSystem::instancePtr(), resource, 
-				subresourceIdx, data, discardEntireBuffer, std::placeholders::_1));
-		}
+		AsyncOp writeSubresource(GpuResourcePtr resource, UINT32 subresourceIdx, const GpuResourceDataPtr& data, bool discardEntireBuffer = false);
 
 		/**
 		 * @copydoc RenderSystem::readSubresource()
@@ -220,84 +120,72 @@ namespace BansheeEngine
 		 * 		 Until the async operation completes "data" is owned by the core thread and you won't
 		 * 		 be able to access it.
 		 */
-		AsyncOp readSubresource(GpuResourcePtr resource, UINT32 subresourceIdx, const GpuResourceDataPtr& data)
-		{
-			data->lock();
-
-			return mCommandQueue->queueReturn(std::bind(&RenderSystem::readSubresource, RenderSystem::instancePtr(), 
-				resource, subresourceIdx, data, std::placeholders::_1));
-		}
+		AsyncOp readSubresource(GpuResourcePtr resource, UINT32 subresourceIdx, const GpuResourceDataPtr& data);
 
 		/**
 		 * @brief	Resize the provided window to specified width and height in pixels.
 		 */
-		void resizeWindow(RenderWindowPtr& renderWindow, UINT32 width, UINT32 height)
-		{
-			mCommandQueue->queue(std::bind(&RenderWindow::resize, renderWindow.get(), width, height));
-		}
+		void resizeWindow(RenderWindowPtr& renderWindow, UINT32 width, UINT32 height);
 
 		/**
 		 * @brief	Move the provided window to specified screen coordinates.
 		 */
-		void moveWindow(RenderWindowPtr& renderWindow, INT32 left, INT32 top)
-		{
-			mCommandQueue->queue(std::bind(&RenderWindow::move, renderWindow.get(), left, top));
-		}
+		void moveWindow(RenderWindowPtr& renderWindow, INT32 left, INT32 top);
 
 		/**
 		 * @brief	Hide the provided window. (Does not destroy it, just hides it).
 		 */
-		void hideWindow(RenderWindowPtr& renderWindow)
-		{
-			mCommandQueue->queue(std::bind(&RenderWindow::setHidden, renderWindow.get(), true));
-		}
+		void hideWindow(RenderWindowPtr& renderWindow);
 
 		/**
 		 * @brief	Shows a previously hidden window.
 		 */
-		void showWindow(RenderWindowPtr& renderWindow)
-		{
-			mCommandQueue->queue(std::bind(&RenderWindow::setHidden, renderWindow.get(), false));
-		}
+		void showWindow(RenderWindowPtr& renderWindow);
 
 		/**
 		* @brief	Queues a new generic command that will be added to the command queue.
 		*/
-		AsyncOp queueReturnCommand(std::function<void(AsyncOp&)> commandCallback)
-		{
-			return mCommandQueue->queueReturn(commandCallback);
-		}
+		AsyncOp queueReturnCommand(std::function<void(AsyncOp&)> commandCallback);
 
 		/**
 		* @brief	Queues a new generic command that will be added to the command queue.
 		*/
-		void queueCommand(std::function<void()> commandCallback)
-		{
-			mCommandQueue->queue(commandCallback);
-		}
+		void queueCommand(std::function<void()> commandCallback);
 
 		/**
 		 * @brief	Makes all the currently queued commands available to the core thread. They will be executed
 		 * 			as soon as the core thread is ready. All queued commands are removed from the accessor.
 		 */
-		void submitToCoreThread(bool blockUntilComplete = false)
-		{
-			Queue<QueuedCommand>::type* commands = mCommandQueue->flush();
-
-			gCoreThread().queueCommand(std::bind(&CommandQueueBase::playback, mCommandQueue, commands), blockUntilComplete);
-		}
+		void submitToCoreThread(bool blockUntilComplete = false);
 
 		/**
 		 * @brief	Cancels all commands in the queue.
 		 */
-		void cancelAll()
-		{
-			// Note that this won't free any Frame data allocated for all the canceled commands since
-			// frame data will only get cleared at frame start
-			mCommandQueue->cancelAll();
-		}
+		void cancelAll();
 
 	private:
-		CommandQueue<CommandQueueSyncPolicy>* mCommandQueue;
+		CommandQueueBase* mCommandQueue;
+	};
+
+	/**
+	 * @brief	Core thread accessor allows you to schedule core commands outside of the core thread. Provides a set of common
+	 * 			methods you may want to execute on the core thread, as well as a general command queuing methods.
+	 * 			
+	 * @note	Queued commands are only executed after the call to submitToCoreThread, in the order they were submitted.
+	 */
+	template <class CommandQueueSyncPolicy = CommandQueueNoSync>
+	class CM_EXPORT CoreThreadAccessor : public CoreThreadAccessorBase
+	{
+	public:
+		/**
+		 * @brief	Constructor.
+		 *
+		 * @param	threadId		Identifier for the thread that created the accessor.
+		 */
+		CoreThreadAccessor(CM_THREAD_ID_TYPE threadId)
+			:CoreThreadAccessorBase(cm_new<CommandQueue<CommandQueueSyncPolicy>>(threadId))
+		{
+
+		}
 	};
 }

+ 335 - 8
CamelotCore/Include/CmMaterial.h

@@ -12,6 +12,10 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	Helper class containing parameters for all types
+	 * 			of GPU programs used in a pass.
+	 */
 	class CM_EXPORT PassParameters
 	{
 	public:
@@ -22,7 +26,11 @@ namespace BansheeEngine
 		GpuParamsPtr mDomainParams;
 		GpuParamsPtr mComputeParams;
 
-		// Helper method
+		/**
+		 * @brief	Returns a set of GPU parameters based on an index.
+		 *
+		 * @note	Useful when needing to iterate over all sets of GPU parameters.
+		 */
 		GpuParamsPtr& getParamByIdx(UINT32 idx)
 		{
 			GpuParamsPtr* paramArray[] = {&mVertParams, &mFragParams, &mGeomParams, &mHullParams, &mDomainParams, &mComputeParams};
@@ -30,13 +38,24 @@ namespace BansheeEngine
 			return *paramArray[idx];
 		}
 
-		// Helper method
+		/**
+		 * @brief	Returns the total number of stored sets of 
+		 * 			GPU parameters in this object.
+		 */
 		UINT32 getNumParams() const { return 6; }
 	};
 
+	/**
+	 * @brief	Material represents a shader and parameters used to set up
+	 * 			that shader. It provides a simple interface for manipulating the
+	 * 			parameters.
+	 */
 	class CM_EXPORT Material : public Resource
 	{
 	public:
+		/**
+		 * @brief	Data used to described a structure defined within a shader.
+		 */
 		struct StructData
 		{
 			StructData()
@@ -49,6 +68,10 @@ namespace BansheeEngine
 				data = std::shared_ptr<void>(cm_alloc<ScratchAlloc>(_size), &cm_free<ScratchAlloc>);
 			}
 
+			/**
+			 * @brief	Writes the specified data to the internal buffer. Caller
+			 * 			must ensure size of the provided buffer is correct.
+			 */
 			void write(void* _data)
 			{
 				memcpy(data.get(), _data, size);
@@ -61,62 +84,316 @@ namespace BansheeEngine
 		~Material();
 
 		/**
-		 * @brief	Sets a shader that will be used by the material. 
-		 * 			Shaders best technique will be retrieved and used in all subsequent Material
-		 * 			operations. 
-		 * 			You need to call this method before doing any other operations with this class.
-		 * 			After setting the shader if change any systems that a shader technique is defendant upon (render system, renderer, ...)
-		 * 			you will need to call this method again on all your Materials to make sure technique used is updated.
+		 * @brief	Sets a shader that will be used by the material. Best technique within the
+		 * 			provided shader will be used for the material.
+		 *
+		 * @note	Shader must be set before doing any other operations with the material.
+		 * 			
+		 * 			After setting the shader if change any systems that a shader technique is 
+		 * 			dependent upon (render system, renderer, etc), you will need to call this 
+		 * 			method again on all your Materials to make sure technique used is updated.
 		 */
 		void setShader(ShaderPtr shader);
 
+		/**
+		 * @brief	Returns the currently active shader.
+		 */
 		ShaderPtr getShader() const { return mShader; }
 
+		/** @brief	Assigns a texture to the shader parameter with the specified name. */
 		void setTexture(const String& name, const HTexture& value)								{ return getParamTexture(name).set(value); }
+
+		/** @brief	Assigns a sampler state to the shader parameter with the specified name. */
 		void setSamplerState(const String& name, const HSamplerState& value)					{ return getParamSamplerState(name).set(value); }
+
+		/**   
+		 *  @brief	Assigns a float value to the shader parameter with the specified name. 
+		 *
+		 *			Optionally if the parameter is an array you may provide an array index to assign the value to.
+		 */
 		void setFloat(const String& name, float value, UINT32 arrayIdx = 0)						{ return getParamFloat(name).set(value, arrayIdx); }
+
+		/**   
+		 *  @brief	Assigns a color to the shader parameter with the specified name. 
+		 *
+		 *			Optionally if the parameter is an array you may provide an array index to assign the value to.
+		 */
 		void setColor(const String& name, const Color& value, UINT32 arrayIdx = 0);
+
+		/**   
+		 *  @brief	Assigns a 2D vector to the shader parameter with the specified name. 
+		 *
+		 *			Optionally if the parameter is an array you may provide an array index to assign the value to.
+		 */
 		void setVec2(const String& name, const Vector2& value, UINT32 arrayIdx = 0)				{ return getParamVec2(name).set(value, arrayIdx); }
+
+		/**   
+		 *  @brief	Assigns a 3D vector to the shader parameter with the specified name. 
+		 *
+		 *			Optionally if the parameter is an array you may provide an array index to assign the value to.
+		 */
 		void setVec3(const String& name, const Vector3& value, UINT32 arrayIdx = 0)				{ return getParamVec3(name).set(value, arrayIdx); }
+
+		/**   
+		 *  @brief	Assigns a 4D vector to the shader parameter with the specified name. 
+		 *
+		 *			Optionally if the parameter is an array you may provide an array index to assign the value to.
+		 */
 		void setVec4(const String& name, const Vector4& value, UINT32 arrayIdx = 0)				{ return getParamVec4(name).set(value, arrayIdx); }
+
+		/**   
+		 *  @brief	Assigns a 3x3 matrix to the shader parameter with the specified name. 
+		 *
+		 *			Optionally if the parameter is an array you may provide an array index to assign the value to.
+		 */
 		void setMat3(const String& name, const Matrix3& value, UINT32 arrayIdx = 0)				{ return getParamMat3(name).set(value, arrayIdx); }
+
+		/**   
+		 *  @brief	Assigns a 4x4 matrix to the shader parameter with the specified name. 
+		 *
+		 *			Optionally if the parameter is an array you may provide an array index to assign the value to.
+		 */
 		void setMat4(const String& name, const Matrix4& value, UINT32 arrayIdx = 0)				{ return getParamMat4(name).set(value, arrayIdx); }
+
+		/**   
+		 *  @brief	Assigns a structure to the shader parameter with the specified name.
+		 *  		
+		 *			Structure is provided as a raw buffer and caller must ensure structure in buffer
+		 *			matches what the shader expects.
+		 *
+		 *			Optionally if the parameter is an array you may provide an array index to assign the value to.
+		 */
 		void setStructData(const String& name, void* value, UINT32 size, UINT32 arrayIdx = 0)	{ return getParamStruct(name).set(value, size, arrayIdx); }
+
+		/**
+		* @brief	Sets a render queue in which will objects with this material be rendered in. Objects
+		* 			with smaller render queue number will get rendered before objects with a large one.
+		 * 			
+		 * @note	This flag can be differently interpreted by renderers but normally you want to separate out
+		 * 			opaque and transparent objects as they usually require slightly different render ordering. 
+		 */
 		void setRenderQueue(INT16 renderQueue) { mRenderQueue = renderQueue; }
 
+		/**
+		 * @brief	Assign a parameter block buffer with the specified name.
+		 *
+		 * @note	Parameter block buffers can be used as quick way of setting multiple parameters on a material at once, or
+		 * 			potentially sharing parameters between multiple materials. This reduces driver overhead as the parameters
+		 * 			in the buffers need only be set once and then reused multiple times.
+		 */
 		void setParamBlockBuffer(const String& name, const GpuParamBlockBufferPtr& paramBlock);
 
+		/** @brief	Returns a texture assigned with the parameter with the specified name. */
 		HTexture getTexture(const String& name) const										{ return getParamTexture(name).get(); }
+
+		/** @brief	Returns a sampler state assigned with the parameter with the specified name. */
 		HSamplerState getSamplerState(const String& name) const								{ return getParamSamplerState(name).get(); }
+
+		/**
+		 * @brief	Returns a float value assigned with the parameter with the specified name.
+		 *
+		 *			Optionally if the parameter is an array you may provide an array index you which to retrieve.
+		 */
 		float getFloat(const String& name, UINT32 arrayIdx = 0) const						{ return getParamFloat(name).get(arrayIdx); }
+
+		/**
+		 * @brief	Returns a 2D vector assigned with the parameter with the specified name.
+		 *
+		 *			Optionally if the parameter is an array you may provide an array index you which to retrieve.
+		 */
 		Vector2 getVec2(const String& name, UINT32 arrayIdx = 0) const						{ return getParamVec2(name).get(arrayIdx); }
+
+		/**
+		 * @brief	Returns a 3D vector assigned with the parameter with the specified name.
+		 *
+		 *			Optionally if the parameter is an array you may provide an array index you which to retrieve.
+		 */
 		Vector3 getVec3(const String& name, UINT32 arrayIdx = 0) const						{ return getParamVec3(name).get(arrayIdx); }
+
+		/**
+		 * @brief	Returns a 4D vector assigned with the parameter with the specified name.
+		 *
+		 *			Optionally if the parameter is an array you may provide an array index you which to retrieve.
+		 */
 		Vector4 getVec4(const String& name, UINT32 arrayIdx = 0) const						{ return getParamVec4(name).get(arrayIdx); }
+
+		/**
+		 * @brief	Returns a 3x3 matrix assigned with the parameter with the specified name.
+		 *
+		 *			Optionally if the parameter is an array you may provide an array index you which to retrieve.
+		 */
 		Matrix3 getMat3(const String& name, UINT32 arrayIdx = 0) const						{ return getParamMat3(name).get(arrayIdx); }
+
+		/**
+		 * @brief	Returns a 4x4 matrix assigned with the parameter with the specified name.
+		 *
+		 *			Optionally if the parameter is an array you may provide an array index you which to retrieve.
+		 */
 		Matrix4 getMat4(const String& name, UINT32 arrayIdx = 0) const						{ return getParamMat4(name).get(arrayIdx); }
+
+		/**
+		 * @brief	Returns a buffer representing a structure assigned to the parameter with the specified name.
+		 *
+		 *			Optionally if the parameter is an array you may provide an array index you which to retrieve.
+		 */
 		StructData getStructData(const String& name, UINT32 arrayIdx = 0) const;
 
+		/**
+		 * @brief	Returns a float GPU parameter. This parameter may be used for
+		 * 			more efficiently getting/setting GPU parameter values than calling
+		 * 			Material::get* / Material::set* methods. 
+		 *
+		 * @note	Expected behavior is that you would retrieve this parameter when
+		 * 			initially constructing the material, and then use it throughout material
+		 * 			lifetime to assign and retrieve parameter values.
+		 * 			
+		 *			If material shader changes this handle will be invalidated.
+		 */
 		GpuParamFloat getParamFloat(const String& name) const;
+
+		/**
+		 * @brief	Returns a 2D vector GPU parameter. This parameter may be used for
+		 * 			more efficiently getting/setting GPU parameter values than calling
+		 * 			Material::get* / Material::set* methods. 
+		 *
+		 * @note	Expected behavior is that you would retrieve this parameter when
+		 * 			initially constructing the material, and then use it throughout material
+		 * 			lifetime to assign and retrieve parameter values.
+		 * 			
+		 *			If material shader changes this handle will be invalidated.
+		 */
 		GpuParamVec2 getParamVec2(const String& name) const;
+
+		/**
+		 * @brief	Returns a 3D vector GPU parameter. This parameter may be used for
+		 * 			more efficiently getting/setting GPU parameter values than calling
+		 * 			Material::get* / Material::set* methods. 
+		 *
+		 * @note	Expected behavior is that you would retrieve this parameter when
+		 * 			initially constructing the material, and then use it throughout material
+		 * 			lifetime to assign and retrieve parameter values.
+		 * 			
+		 *			If material shader changes this handle will be invalidated.
+		 */
 		GpuParamVec3 getParamVec3(const String& name) const;
+
+		/**
+		 * @brief	Returns a 4D vector GPU parameter. This parameter may be used for
+		 * 			more efficiently getting/setting GPU parameter values than calling
+		 * 			Material::get* / Material::set* methods. 
+		 *
+		 * @note	Expected behavior is that you would retrieve this parameter when
+		 * 			initially constructing the material, and then use it throughout material
+		 * 			lifetime to assign and retrieve parameter values.
+		 * 			
+		 *			If material shader changes this handle will be invalidated.
+		 */
 		GpuParamVec4 getParamVec4(const String& name) const;
+
+		/**
+		 * @brief	Returns a 3x3 matrix GPU parameter. This parameter may be used for
+		 * 			more efficiently getting/setting GPU parameter values than calling
+		 * 			Material::get* / Material::set* methods. 
+		 *
+		 * @note	Expected behavior is that you would retrieve this parameter when
+		 * 			initially constructing the material, and then use it throughout material
+		 * 			lifetime to assign and retrieve parameter values.
+		 * 			
+		 *			If material shader changes this handle will be invalidated.
+		 */
 		GpuParamMat3 getParamMat3(const String& name) const;
+
+		/**
+		 * @brief	Returns a 4x4 matrix GPU parameter. This parameter may be used for
+		 * 			more efficiently getting/setting GPU parameter values than calling
+		 * 			Material::get* / Material::set* methods. 
+		 *
+		 * @note	Expected behavior is that you would retrieve this parameter when
+		 * 			initially constructing the material, and then use it throughout material
+		 * 			lifetime to assign and retrieve parameter values.
+		 * 			
+		 *			If material shader changes this handle will be invalidated.
+		 */
 		GpuParamMat4 getParamMat4(const String& name) const;
+
+		/**
+		 * @brief	Returns a structure GPU parameter. This parameter may be used for
+		 * 			more efficiently getting/setting GPU parameter values than calling
+		 * 			Material::get* / Material::set* methods. 
+		 *
+		 * @note	Expected behavior is that you would retrieve this parameter when
+		 * 			initially constructing the material, and then use it throughout material
+		 * 			lifetime to assign and retrieve parameter values.
+		 * 			
+		 *			If material shader changes this handle will be invalidated.
+		 */
 		GpuParamStruct getParamStruct(const String& name) const;
+
+		/**
+		 * @brief	Returns a texture GPU parameter. This parameter may be used for
+		 * 			more efficiently getting/setting GPU parameter values than calling
+		 * 			Material::get* / Material::set* methods. 
+		 *
+		 * @note	Expected behavior is that you would retrieve this parameter when
+		 * 			initially constructing the material, and then use it throughout material
+		 * 			lifetime to assign and retrieve parameter values.
+		 * 			
+		 *			If material shader changes this handle will be invalidated.
+		 */
 		GpuParamTexture getParamTexture(const String& name) const;
+
+		/**
+		 * @brief	Returns a sampler state GPU parameter. This parameter may be used for
+		 * 			more efficiently getting/setting GPU parameter values than calling
+		 * 			Material::get* / Material::set* methods. 
+		 *
+		 * @note	Expected behavior is that you would retrieve this parameter when
+		 * 			initially constructing the material, and then use it throughout material
+		 * 			lifetime to assign and retrieve parameter values.
+		 * 			
+		 *			If material shader changes this handle will be invalidated.
+		 */
 		GpuParamSampState getParamSamplerState(const String& name) const;
 
+		/**
+		 * @brief	Returns the currently set render queue.
+		 *
+		 * @see		Material::setRenderQueue
+		 */
 		INT16 getRenderQueue() const { return mRenderQueue; }
 
+		/**
+		 * @brief	Returns the number of passes that are used
+		 * 			by the shader contained in the material.
+		 */
 		UINT32 getNumPasses() const;
 
+		/**
+		 * @brief	Retrieves a specific shader pass.
+		 */
 		PassPtr getPass(UINT32 passIdx) const;
 
+		/**
+		 * @brief	Returns a set of parameters for all GPU programs
+		 * 			in the specified shader pass.
+		 */
 		PassParametersPtr getPassParameters(UINT32 passIdx) const;
 
+		/**
+		 * @brief	Creates a new empty material.
+		 * 			
+		 * @note	Make sure you call Material::setShader before using it.
+		 */
 		static HMaterial create();
+
+		/**
+		 * @brief	Creates a new material with the specified shader.
+		 */
 		static HMaterial create(ShaderPtr shader);
 	protected:
+		/**
+		 * @copydoc	Resource::destroy_internal
+		 */
 		void destroy_internal();
 
 		/**
@@ -160,23 +437,73 @@ namespace BansheeEngine
 
 		Material();
 
+		/**
+		 * @brief	Throw an exception if no shader is set, or no acceptable
+		 * 			technique was found.
+		 */
 		void throwIfNotInitialized() const;
 
+		/**
+		 * @brief	Retrieves a list of all shader GPU parameters, and the GPU program variable names they map to.
+		 */
 		const Map<String, String>::type& getValidParamNames() const { return mValidParams; }
 
+		/**
+		 * @brief	Initializes the material by using the best technique from the currently set shader. Shader
+		 * 			must contain the technique that matches the current renderer and render system.
+		 */
 		void initBestTechnique();
 
+		/**
+		 * @brief	Constructs a map containing all data parameters (e.g. float, vector3, color).
+		 * 			Map contains parameter names and descriptions.
+		 */
 		Map<String, const GpuParamDataDesc*>::type determineValidDataParameters(const Vector<const GpuParamDesc*>::type& paramDescs) const;
+
+		/**
+		 * @brief	Constructs a list containing all object parameter (e.g. texture, sampler state) names.
+		 */
 		Set<String>::type determineValidObjectParameters(const Vector<const GpuParamDesc*>::type& paramDescs) const;
+
+		/**
+		 * @brief	Constructs a list containing all shareable parameter block names. Shareable blocks may be shared between
+		 * 			different GPU programs, passes or even materials. 
+		 */
 		Set<String>::type determineValidShareableParamBlocks(const Vector<const GpuParamDesc*>::type& paramDescs) const;
+
+		/**
+		 * @brief	Constructs a map that maps parameter names to a parameter block.
+		 */
 		Map<String, String>::type determineParameterToBlockMapping(const Vector<const GpuParamDesc*>::type& paramDescs);
 
+		/**
+		 * @brief	Checks are the specified two parameters equal
+		 *
+		 * @param	paramA			   	The parameter a to compare.
+		 * @param	paramB			   	The parameter b to compare.
+		 * @param	ignoreBufferOffsets	(optional) If true, parameter offsets into the parameter buffer will be ignored
+		 * 								when comparing.
+		 */
 		bool areParamsEqual(const GpuParamDataDesc& paramA, const GpuParamDataDesc& paramB, bool ignoreBufferOffsets = false) const;
 
+		/**
+		 * @brief	Frees all parameter block buffers.
+		 */
 		void freeParamBuffers();
 
+		/**
+		 * @brief	Finds a set of GPU parameters containing a data (e.g. float, vector2) parameter with the provided name.
+		 */
 		GpuParamsPtr findParamsWithName(const String& name) const;
+
+		/**
+		 * @brief	Finds a set of GPU parameters containing a texture parameter with the provided name.
+		 */
 		GpuParamsPtr findTexWithName(const String& name) const;
+
+		/**
+		 * @brief	Finds a set of GPU parameters containing a sampler state parameter with the provided name.
+		 */
 		GpuParamsPtr findSamplerStateWithName(const String& name) const;
 
 		/************************************************************************/

+ 12 - 0
CamelotCore/Include/CmMaterialManager.h

@@ -5,10 +5,22 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	Material manager handles material creation.
+	 */
 	class CM_EXPORT MaterialManager : public Module<MaterialManager>
 	{
 	public:
+		/**
+		 * @brief	Creates a new material without any assigned shader.
+		 *
+		 * @note	Make sure to call Material::setShader before using it.
+		 */
 		MaterialPtr create() const;
+
+		/**
+		 * @brief	Creates a new material with the specified shader.
+		 */
 		MaterialPtr create(ShaderPtr shader) const;
 	};
 }

+ 70 - 13
CamelotCore/Include/CmOSInputHandler.h

@@ -16,6 +16,9 @@ namespace BansheeEngine
 		*/
 	class CM_EXPORT OSInputHandler
 	{
+		/**
+		 * @brief	Contains information regarding a button state change event.
+		 */
 		struct ButtonStateChange
 		{
 			Vector2I cursorPos;
@@ -24,6 +27,9 @@ namespace BansheeEngine
 			bool pressed;
 		};
 
+		/**
+		 * @brief	Contains information regarding a double click event.
+		 */
 		struct DoubleClick
 		{
 			Vector2I cursorPos;
@@ -34,23 +40,60 @@ namespace BansheeEngine
 		OSInputHandler();
 		virtual ~OSInputHandler();
 
+		/**
+		 * @brief	Triggers when user inputs a character. The character might be a result of pressing
+		 * 			multiple keys, so character input will not necessarily correspond with button presses.
+		 * 			Provide character code of the input character.
+		 */
 		boost::signal<void(UINT32)> onCharInput;
+
+		/**
+		 * @brief	Triggers whenever user scrolls the mouse wheel. Returns the screen
+		 * 			position of the mouse cursor and delta amount of mouse scroll (can be negative or positive).
+		 */
 		boost::signal<void(const Vector2I&, float)> onMouseWheelScrolled;
+
+		/**
+		 * @brief	Triggers whenever user moves the mouse cursor.
+		 */
 		boost::signal<void(const PointerEvent&)> onCursorMoved;
+
+		/**
+		 * @brief	Triggers whenever user presses one of the mouse buttons.
+		 */
 		boost::signal<void(const PointerEvent&)> onCursorPressed;
+
+		/**
+		 * @brief	Triggers whenever user releases one of the mouse buttons.
+		 */
 		boost::signal<void(const PointerEvent&)> onCursorReleased;
+
+		/**
+		 * @brief	Triggers when user clicks a mouse button quickly twice in a row.
+		 */
 		boost::signal<void(const PointerEvent&)> onDoubleClick;
+
+		/**
+		 * @brief	Triggers when user inputa a special input command, like commands user
+		 * 			for manipulating text input.
+		 */
 		boost::signal<void(InputCommandType)> onInputCommand;
 
 		/**
-			* @brief	Called every frame by InputManager. Capture input here if needed.
-			*/
-		virtual void update();
+		 * @brief	Called once per frame. Capture input here if needed.
+		 * 			
+		 * @note	Internal method.
+		 */
+		virtual void _update();
 
 		/**
-			* @brief	Called by InputManager whenever window in focus changes.
-			*/
-		virtual void inputWindowChanged(const RenderWindow& win) {}
+		 * @brief	Called whenever the active window changes.
+		 *
+		 * @param	win	Newly active window.
+		 * 				
+		 * @note	Internal method.
+		 */
+		virtual void _inputWindowChanged(const RenderWindow& win) {}
 
 	private:
 		CM_MUTEX(mOSInputMutex);
@@ -72,37 +115,51 @@ namespace BansheeEngine
 		boost::signals::connection mMouseWheelScrolledConn;
 
 		/**
-		 * @brief	Called from the message loop.
+		 * @brief	Called from the message loop to notify user has entered a character.
+		 * 			
+		 * @see		onCharInput
 		 */
 		void charInput(UINT32 character);
 
 		/**
-		 * @brief	Called from the message loop.
+		 * @brief	Called from the message loop to notify user has moved the cursor.
+		 * 			
+		 * @see		onCursorMoved
 		 */
 		void cursorMoved(const Vector2I& cursorPos, OSPointerButtonStates& btnStates);
 
 		/**
-		 * @brief	Called from the message loop.
+		 * @brief	Called from the message loop to notify user has pressed a mouse button.
+		 * 			
+		 * @see		onCursorPressed
 		 */
 		void cursorPressed(const Vector2I& cursorPos, OSMouseButton button, OSPointerButtonStates& btnStates);
 
 		/**
-		 * @brief	Called from the message loop.
+		 * @brief	Called from the message loop to notify user has released a mouse button.
+		 * 			
+		 * @see		onCursorReleased
 		 */
 		void cursorReleased(const Vector2I& cursorPos, OSMouseButton button, OSPointerButtonStates& btnStates);
 
 		/**
-		 * @brief	Called from the message loop.
+		 * @brief	Called from the message loop to notify user has double-clicked a mouse button.
+		 * 
+		 * @see		onDoubleClick
 		 */
 		void cursorDoubleClick(const Vector2I& cursorPos, OSPointerButtonStates& btnStates);
 
 		/**
-		 * @brief	Called from the message loop.
+		 * @brief	Called from the message loop to notify user has entered an input command.
+		 * 			
+		 * @see		onInputCommand
 		 */
 		void inputCommandEntered(InputCommandType commandType);
 
 		/**
-		 * @brief	Called from the message loop.
+		 * @brief	Called from the message loop to notify user has scrolled the mouse wheel.
+		 * 			
+		 * @see		onMouseWheelScrolled
 		 */
 		void mouseWheelScrolled(float scrollPos);
 	};

+ 34 - 62
CamelotCore/Include/CmPass.h

@@ -8,33 +8,18 @@
 
 namespace BansheeEngine
 {
-	/** Class defining a single pass of a Technique (of a Material), i.e.
-        a single rendering call.
-    @remarks
-        Rendering can be repeated with many passes for more complex effects.
-        Each pass is a programmable pass (meaning it does
-        use either a vertex and fragment program, or both).
-    */
+	/**
+	 * @brief	Class defining a single pass of a technique (of a material), i.e.
+	 * 			a single rendering call. 
+	 * 			
+	 *			Pass may contain multiple GPU programs (vertex, fragment, geometry, etc.), and
+	 *			a set of pipeline states (blend, rasterizer, etc.).
+	 */
 	class CM_EXPORT Pass : public IReflectable
     {
-    protected:
-		HBlendState mBlendState;
-		HRasterizerState mRasterizerState;
-		HDepthStencilState mDepthStencilState;
-		UINT32 mStencilRefValue;
-
-		HGpuProgram mVertexProgram;
-		HGpuProgram mFragmentProgram;
-		HGpuProgram mGeometryProgram;
-		HGpuProgram mHullProgram;
-		HGpuProgram mDomainProgram;
-		HGpuProgram mComputeProgram;
     public:
-        /// Default constructor
 		Pass();
-        /// Copy constructor
-        Pass(const Pass& oth );
-        /// Operator = overload
+        Pass(const Pass& oth);
         Pass& operator=(const Pass& oth);
         virtual ~Pass();
 
@@ -45,12 +30,11 @@ namespace BansheeEngine
 		bool hasDomainProgram() const { return mDomainProgram != nullptr; }
 		bool hasComputeProgram() const { return mComputeProgram != nullptr; }
 
-		/** Returns true if this pass has some element of transparency. */
-		bool isTransparent(void) const;
-
 		/**
-		 * @brief	Sets a blend state used for all active render targets.
+		 * @brief	Returns true if this pass has some element of transparency.
 		 */
+		bool isTransparent() const;
+
 		void setBlendState(HBlendState& blendState);
 		HBlendState getBlendState() const;
 
@@ -60,60 +44,48 @@ namespace BansheeEngine
 		void setDepthStencilState(HDepthStencilState& depthStencilState);
 		HDepthStencilState getDepthStencilState() const;
 
+		/**
+		 * @brief	Sets the stencil reference value that is used when performing operations using the
+		 * 			stencil buffer.
+		 */
 		void setStencilRefValue(UINT32 refValue);
+
+		/**
+		 * @brief	Gets the stencil reference value that is used when performing operations using the
+		 * 			stencil buffer.
+		 */
 		UINT32 getStencilRefValue() const;
 
-		/** Sets the details of the vertex program to use.
-		*/
 		void setVertexProgram(HGpuProgram gpuProgram) { mVertexProgram = gpuProgram; }
+		const HGpuProgram& getVertexProgram() const { return mVertexProgram; }
 
-		/** Gets the vertex program used by this pass. */
-		const HGpuProgram& getVertexProgram(void) const { return mVertexProgram; }
-
-		/** Sets the details of the fragment program to use.
-		*/
 		void setFragmentProgram(HGpuProgram gpuProgram) { mFragmentProgram = gpuProgram; }
-		
-		/** Gets the fragment program used by this pass. */
-		const HGpuProgram& getFragmentProgram(void) const { return mFragmentProgram; }
+		const HGpuProgram& getFragmentProgram() const { return mFragmentProgram; }
 
-		/** Sets the details of the geometry program to use.
-		*/
 		void setGeometryProgram(HGpuProgram gpuProgram) { mGeometryProgram = gpuProgram; }
-		
-		/** Gets the geometry program used by this pass. */
-		const HGpuProgram& getGeometryProgram(void) const { return mGeometryProgram; }
+		const HGpuProgram& getGeometryProgram() const { return mGeometryProgram; }
 
-		/** Sets the details of the hull program to use.
-		*/
 		void setHullProgram(HGpuProgram gpuProgram) { mHullProgram = gpuProgram; }
-		
-		/** Gets the hull program used by this pass. */
 		const HGpuProgram& getHullProgram(void) const { return mHullProgram; }
 
-		/** Sets the details of the domain program to use.
-		*/
 		void setDomainProgram(HGpuProgram gpuProgram) { mDomainProgram = gpuProgram;}
-		
-		/** Gets the domain program used by this pass. */
 		const HGpuProgram& getDomainProgram(void) const { return mDomainProgram; }
 
-		/** Sets the details of the compute program to use.
-		*/
 		void setComputeProgram(HGpuProgram gpuProgram) { mComputeProgram = gpuProgram; }
-		
-		/** Gets the compute program used by this pass. */
 		const HGpuProgram& getComputeProgram(void) const { return mComputeProgram; }
 
-		/**
-		 * @brief	Makes this pass active. Anything rendered after this command will use this pass.
-		 */
-		void activate(CoreAccessor& coreAccessor) const;
+	protected:
+		HBlendState mBlendState;
+		HRasterizerState mRasterizerState;
+		HDepthStencilState mDepthStencilState;
+		UINT32 mStencilRefValue;
 
-		/**
-		 * @brief	Applies specified parameters to the active pass. 
-		 */
-		void bindParameters(CoreAccessor& coreAccessor, const PassParametersPtr& params) const;
+		HGpuProgram mVertexProgram;
+		HGpuProgram mFragmentProgram;
+		HGpuProgram mGeometryProgram;
+		HGpuProgram mHullProgram;
+		HGpuProgram mDomainProgram;
+		HGpuProgram mComputeProgram;
 
 		/************************************************************************/
 		/* 								RTTI		                     		*/

+ 36 - 5
CamelotCore/Include/CmRawInputHandler.h

@@ -7,12 +7,20 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	Contains relative and absolute position
+	 * 			of an input axis. Relative state represents
+	 * 			the difference between current and last state.
+	 */
 	struct RawAxisState
 	{
 		Vector2I rel;
 		Vector2I abs;
 	};
 
+	/**
+	 * @brief	Different types of input axes.
+	 */
 	enum class RawInputAxis
 	{
 		Mouse_XY,
@@ -38,7 +46,10 @@ namespace BansheeEngine
 
 	/**
 	 * @brief	Represents a specific way of acquiring low-level input. InputManager (which provides a higher level input)
-	 * 			must have at least one InputHandler attached. Attach events handler to the provided signals to handle input.
+	 * 			must have at least one RawInputHandler attached. Raw input handlers receive input as sent by the hardware
+	 * 			without OS modifications.
+	 * 			
+	 *			Attach events handler to the provided signals to handle input.
 	 */
 	class CM_EXPORT RawInputHandler
 	{
@@ -46,19 +57,39 @@ namespace BansheeEngine
 		RawInputHandler() {}
 		virtual ~RawInputHandler() {}
 
+		/**
+		 * @brief	Triggered when user presses a button. Parameters
+		 * 			include button code of the pressed button, and a timestamp of
+		 * 			the button press event.
+		 */
 		boost::signal<void(ButtonCode, UINT64)> onButtonDown;
+
+		/**
+		 * @brief	Triggered when user releases a button. Parameters
+		 * 			include button code of the released button, and a timestamp of
+		 * 			the button release event.
+		 */
 		boost::signal<void(ButtonCode, UINT64)> onButtonUp;
 
+		/**
+		 * @brief	Triggered whenever the specified axis state changes.
+		 */
 		boost::signal<void(const RawAxisState&, RawInputAxis)> onAxisMoved;
 
 		/**
-		 * @brief	Called every frame by InputManager. Capture input here if needed.
+		 * @brief	Called once per frame. Capture input here if needed.
+		 * 			
+		 * @note	Internal method.
 		 */
-		virtual void update() {}
+		virtual void _update() {}
 
 		/**
-		 * @brief	Called by InputManager whenever window in focus changes.
+		 * @brief	Called whenever the active window changes.
+		 *
+		 * @param	win	Newly active window.
+		 * 				
+		 * @note	Internal method.
 		 */
-		virtual void inputWindowChanged(const RenderWindow& win) {}
+		virtual void _inputWindowChanged(const RenderWindow& win) {}
 	};
 }

+ 0 - 2
CamelotCore/Include/CmRenderSystem.h

@@ -251,8 +251,6 @@ namespace BansheeEngine
 
 		/** Add a user clipping plane. */
 		virtual void addClipPlane (const Plane& p);
-		/** Add a user clipping plane. */
-		virtual void addClipPlane (float A, float B, float C, float D);
 
 		/** Clears the user clipping region.
 		*/

+ 1 - 0
CamelotCore/Source/CmCoreThread.cpp

@@ -1,6 +1,7 @@
 #include "CmCoreThread.h"
 #include "BsThreadPool.h"
 #include "BsTaskScheduler.h"
+#include "CmFrameAlloc.h"
 
 using namespace std::placeholders;
 

+ 268 - 0
CamelotCore/Source/CmCoreThreadAccessor.cpp

@@ -6,8 +6,276 @@
 #include "CmDepthStencilState.h"
 #include "CmGpuResourceData.h"
 #include "CmGpuParams.h"
+#include "CmPass.h"
+#include "CmMaterial.h"
+#include "CmCoreThread.h"
 
 namespace BansheeEngine
 {
+	CoreThreadAccessorBase::CoreThreadAccessorBase(CommandQueueBase* commandQueue)
+		:mCommandQueue(commandQueue)
+	{
 
+	}
+
+	CoreThreadAccessorBase::~CoreThreadAccessorBase()
+	{
+		cm_delete(mCommandQueue);
+	}
+
+	void CoreThreadAccessorBase::disableTextureUnit(GpuProgramType gptype, UINT16 texUnit)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::disableTextureUnit, RenderSystem::instancePtr(), gptype, texUnit));
+	}
+
+	void CoreThreadAccessorBase::setTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const TexturePtr &texPtr)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::setTexture, RenderSystem::instancePtr(), gptype, unit, enabled, texPtr));
+	}
+
+	void CoreThreadAccessorBase::setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerStatePtr& samplerState)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::setSamplerState, RenderSystem::instancePtr(), gptype, texUnit, samplerState));
+	}
+
+	void CoreThreadAccessorBase::setBlendState(const BlendStatePtr& blendState)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::setBlendState, RenderSystem::instancePtr(), blendState));
+	}
+
+	void CoreThreadAccessorBase::setRasterizerState(const RasterizerStatePtr& rasterizerState)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::setRasterizerState, RenderSystem::instancePtr(), rasterizerState));
+	}
+
+	void CoreThreadAccessorBase::setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::setDepthStencilState, RenderSystem::instancePtr(), depthStencilState, stencilRefValue));
+	}
+
+	void CoreThreadAccessorBase::setViewport(const ViewportPtr& vp)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::setViewport, RenderSystem::instancePtr(), vp));
+	}
+
+	void CoreThreadAccessorBase::setDrawOperation(DrawOperationType op)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::setDrawOperation, RenderSystem::instancePtr(), op));
+	}
+
+	void CoreThreadAccessorBase::setClipPlanes(const PlaneList& clipPlanes)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::setClipPlanes, RenderSystem::instancePtr(), clipPlanes));
+	}
+
+	void CoreThreadAccessorBase::addClipPlane(const Plane& p)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::addClipPlane, RenderSystem::instancePtr(), p));
+	}
+
+	void CoreThreadAccessorBase::resetClipPlanes()
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::resetClipPlanes, RenderSystem::instancePtr()));
+	}
+
+	void CoreThreadAccessorBase::setScissorTest(UINT32 left, UINT32 top, UINT32 right, UINT32 bottom)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::setScissorRect, RenderSystem::instancePtr(), left, top, right, bottom));
+	}
+
+	void CoreThreadAccessorBase::setRenderTarget(RenderTargetPtr target)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::setRenderTarget, RenderSystem::instancePtr(), target));
+	}
+
+	void CoreThreadAccessorBase::bindGpuProgram(HGpuProgram prg)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::bindGpuProgram, RenderSystem::instancePtr(), prg));
+	}
+
+	void CoreThreadAccessorBase::unbindGpuProgram(GpuProgramType gptype)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::unbindGpuProgram, RenderSystem::instancePtr(), gptype));
+	}
+
+	void CoreThreadAccessorBase::bindGpuParams(GpuProgramType gptype, const GpuParamsPtr& params)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::bindGpuParams, RenderSystem::instancePtr(), gptype, BindableGpuParams(params, gCoreThread().getFrameAlloc())));
+	}
+
+	void CoreThreadAccessorBase::beginRender()
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::beginFrame, RenderSystem::instancePtr()));
+	}
+
+	void CoreThreadAccessorBase::endRender()
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::endFrame, RenderSystem::instancePtr()));
+	}
+
+	void CoreThreadAccessorBase::clearRenderTarget(UINT32 buffers, const Color& color, float depth, UINT16 stencil)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::clearRenderTarget, RenderSystem::instancePtr(), buffers, color, depth, stencil));
+	}
+
+	void CoreThreadAccessorBase::clearViewport(UINT32 buffers, const Color& color, float depth, UINT16 stencil)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::clearViewport, RenderSystem::instancePtr(), buffers, color, depth, stencil));
+	}
+
+	void CoreThreadAccessorBase::swapBuffers(RenderTargetPtr target)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::swapBuffers, RenderSystem::instancePtr(), target));
+	}
+
+	void CoreThreadAccessorBase::render(const MeshBasePtr& mesh, UINT32 indexOffset, UINT32 indexCount, bool useIndices, DrawOperationType drawOp)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::render, RenderSystem::instancePtr(), mesh, indexOffset, indexCount, useIndices, drawOp));
+	}
+
+	void CoreThreadAccessorBase::draw(UINT32 vertexOffset, UINT32 vertexCount)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::draw, RenderSystem::instancePtr(), vertexOffset, vertexCount));
+	}
+
+	void CoreThreadAccessorBase::drawIndexed(UINT32 startIndex, UINT32 indexCount, UINT32 vertexOffset, UINT32 vertexCount)
+	{
+		mCommandQueue->queue(std::bind(&RenderSystem::drawIndexed, RenderSystem::instancePtr(), startIndex, indexCount, vertexOffset, vertexCount));
+	}
+
+	void CoreThreadAccessorBase::setPass(const PassPtr& pass, const PassParametersPtr& params)
+	{
+		HGpuProgram vertProgram = pass->getVertexProgram();
+		if(vertProgram)
+			bindGpuProgram(vertProgram);
+		else
+			unbindGpuProgram(GPT_VERTEX_PROGRAM);
+
+		HGpuProgram fragProgram = pass->getFragmentProgram();
+		if(fragProgram)
+			bindGpuProgram(fragProgram);
+		else
+			unbindGpuProgram(GPT_FRAGMENT_PROGRAM);
+
+		HGpuProgram geomProgram = pass->getGeometryProgram();
+		if(geomProgram)
+			bindGpuProgram(geomProgram);
+		else
+			unbindGpuProgram(GPT_GEOMETRY_PROGRAM);
+
+		HGpuProgram hullProgram = pass->getHullProgram();
+		if(hullProgram)
+			bindGpuProgram(hullProgram);
+		else
+			unbindGpuProgram(GPT_HULL_PROGRAM);
+
+		HGpuProgram domainProgram = pass->getDomainProgram();
+		if(domainProgram)
+			bindGpuProgram(domainProgram);
+		else
+			unbindGpuProgram(GPT_DOMAIN_PROGRAM);
+
+		// TODO - Try to limit amount of state changes, if previous state is already the same (especially with textures)
+
+		// TODO: Disable remaining texture units
+		//renderSystem->_disableTextureUnitsFrom(pass->getNumTextures());
+
+		// Set up non-texture related pass settings
+		HBlendState blendState = pass->getBlendState();
+		if(blendState != nullptr)
+			setBlendState(blendState.getInternalPtr());
+		else
+			setBlendState(BlendState::getDefault());
+
+		HDepthStencilState depthStancilState = pass->getDepthStencilState();
+		if(depthStancilState != nullptr)
+			setDepthStencilState(depthStancilState.getInternalPtr(), pass->getStencilRefValue());
+		else
+			setDepthStencilState(DepthStencilState::getDefault(), pass->getStencilRefValue());
+
+		HRasterizerState rasterizerState = pass->getRasterizerState();
+		if(rasterizerState != nullptr)
+			setRasterizerState(rasterizerState.getInternalPtr());
+		else
+			setRasterizerState(RasterizerState::getDefault());
+
+		if(vertProgram)
+			bindGpuParams(GPT_VERTEX_PROGRAM, params->mVertParams);
+
+		if(fragProgram)
+			bindGpuParams(GPT_FRAGMENT_PROGRAM, params->mFragParams);
+
+		if(geomProgram)
+			bindGpuParams(GPT_GEOMETRY_PROGRAM, params->mGeomParams);
+
+		if(hullProgram)
+			bindGpuParams(GPT_HULL_PROGRAM, params->mHullParams);
+
+		if(domainProgram)
+			bindGpuParams(GPT_DOMAIN_PROGRAM, params->mDomainParams);
+
+		HGpuProgram computeProgram = pass->getComputeProgram();
+		if(computeProgram)
+			bindGpuParams(GPT_COMPUTE_PROGRAM, params->mComputeParams);
+	}
+
+	AsyncOp CoreThreadAccessorBase::writeSubresource(GpuResourcePtr resource, UINT32 subresourceIdx, const GpuResourceDataPtr& data, bool discardEntireBuffer)
+	{
+		data->lock();
+
+		return mCommandQueue->queueReturn(std::bind(&RenderSystem::writeSubresource, RenderSystem::instancePtr(), resource, 
+			subresourceIdx, data, discardEntireBuffer, std::placeholders::_1));
+	}
+
+	AsyncOp CoreThreadAccessorBase::readSubresource(GpuResourcePtr resource, UINT32 subresourceIdx, const GpuResourceDataPtr& data)
+	{
+		data->lock();
+
+		return mCommandQueue->queueReturn(std::bind(&RenderSystem::readSubresource, RenderSystem::instancePtr(), 
+			resource, subresourceIdx, data, std::placeholders::_1));
+	}
+
+	void CoreThreadAccessorBase::resizeWindow(RenderWindowPtr& renderWindow, UINT32 width, UINT32 height)
+	{
+		mCommandQueue->queue(std::bind(&RenderWindow::resize, renderWindow.get(), width, height));
+	}
+
+	void CoreThreadAccessorBase::moveWindow(RenderWindowPtr& renderWindow, INT32 left, INT32 top)
+	{
+		mCommandQueue->queue(std::bind(&RenderWindow::move, renderWindow.get(), left, top));
+	}
+
+	void CoreThreadAccessorBase::hideWindow(RenderWindowPtr& renderWindow)
+	{
+		mCommandQueue->queue(std::bind(&RenderWindow::setHidden, renderWindow.get(), true));
+	}
+
+	void CoreThreadAccessorBase::showWindow(RenderWindowPtr& renderWindow)
+	{
+		mCommandQueue->queue(std::bind(&RenderWindow::setHidden, renderWindow.get(), false));
+	}
+
+	AsyncOp CoreThreadAccessorBase::queueReturnCommand(std::function<void(AsyncOp&)> commandCallback)
+	{
+		return mCommandQueue->queueReturn(commandCallback);
+	}
+
+	void CoreThreadAccessorBase::queueCommand(std::function<void()> commandCallback)
+	{
+		mCommandQueue->queue(commandCallback);
+	}
+
+	void CoreThreadAccessorBase::submitToCoreThread(bool blockUntilComplete)
+	{
+		Queue<QueuedCommand>::type* commands = mCommandQueue->flush();
+
+		gCoreThread().queueCommand(std::bind(&CommandQueueBase::playback, mCommandQueue, commands), blockUntilComplete);
+	}
+
+	void CoreThreadAccessorBase::cancelAll()
+	{
+		// Note that this won't free any Frame data allocated for all the canceled commands since
+		// frame data will only get cleared at frame start
+		mCommandQueue->cancelAll();
+	}
 }

+ 4 - 4
CamelotCore/Source/CmInput.cpp

@@ -82,7 +82,7 @@ namespace BansheeEngine
 			return;
 		}
 		else
-			mRawInputHandler->update();
+			mRawInputHandler->_update();
 
 		if(mOSInputHandler == nullptr)
 		{
@@ -90,7 +90,7 @@ namespace BansheeEngine
 			return;
 		}
 		else
-			mOSInputHandler->update();
+			mOSInputHandler->_update();
 
 		updateSmoothInput();
 	}
@@ -98,10 +98,10 @@ namespace BansheeEngine
 	void Input::inputWindowChanged(RenderWindow& win)
 	{
 		if(mRawInputHandler != nullptr)
-			mRawInputHandler->inputWindowChanged(win);
+			mRawInputHandler->_inputWindowChanged(win);
 
 		if(mOSInputHandler != nullptr)
-			mOSInputHandler->inputWindowChanged(win);
+			mOSInputHandler->_inputWindowChanged(win);
 	}
 
 	void Input::buttonDown(ButtonCode code, UINT64 timestamp)

+ 1 - 0
CamelotCore/Source/CmMeshRTTI.h

@@ -5,6 +5,7 @@
 #include "CmApplication.h"
 #include "CmMesh.h"
 #include "CmMeshManager.h"
+#include "CmCoreThread.h"
 
 namespace BansheeEngine
 {

+ 1 - 1
CamelotCore/Source/CmOSInputHandler.cpp

@@ -31,7 +31,7 @@ namespace BansheeEngine
 		mMouseWheelScrolledConn.disconnect();
 	}
 
-	void OSInputHandler::update()
+	void OSInputHandler::_update()
 	{
 		WString inputString;
 		Vector2I mousePosition;

+ 0 - 84
CamelotCore/Source/CmPass.cpp

@@ -104,90 +104,6 @@ namespace BansheeEngine
 		return mStencilRefValue;
 	}
 
-	void Pass::activate(CoreAccessor& coreAccessor) const
-	{
-		HGpuProgram vertProgram = getVertexProgram();
-		if(vertProgram)
-			coreAccessor.bindGpuProgram(vertProgram);
-		else
-			coreAccessor.unbindGpuProgram(GPT_VERTEX_PROGRAM);
-
-		HGpuProgram fragProgram = getFragmentProgram();
-		if(fragProgram)
-			coreAccessor.bindGpuProgram(fragProgram);
-		else
-			coreAccessor.unbindGpuProgram(GPT_FRAGMENT_PROGRAM);
-
-		HGpuProgram geomProgram = getGeometryProgram();
-		if(geomProgram)
-			coreAccessor.bindGpuProgram(geomProgram);
-		else
-			coreAccessor.unbindGpuProgram(GPT_GEOMETRY_PROGRAM);
-
-		HGpuProgram hullProgram = getHullProgram();
-		if(hullProgram)
-			coreAccessor.bindGpuProgram(hullProgram);
-		else
-			coreAccessor.unbindGpuProgram(GPT_HULL_PROGRAM);
-
-		HGpuProgram domainProgram = getDomainProgram();
-		if(domainProgram)
-			coreAccessor.bindGpuProgram(domainProgram);
-		else
-			coreAccessor.unbindGpuProgram(GPT_DOMAIN_PROGRAM);
-
-		// TODO - Try to limit amount of state changes, if previous state is already the same (especially with textures)
-
-		// TODO: Disable remaining texture units
-		//renderSystem->_disableTextureUnitsFrom(pass->getNumTextures());
-
-		// Set up non-texture related pass settings
-		HBlendState blendState = getBlendState();
-		if(blendState != nullptr)
-			coreAccessor.setBlendState(blendState.getInternalPtr());
-		else
-			coreAccessor.setBlendState(BlendState::getDefault());
-
-		HDepthStencilState depthStancilState = getDepthStencilState();
-		if(depthStancilState != nullptr)
-			coreAccessor.setDepthStencilState(depthStancilState.getInternalPtr(), getStencilRefValue());
-		else
-			coreAccessor.setDepthStencilState(DepthStencilState::getDefault(), getStencilRefValue());
-
-		HRasterizerState rasterizerState = getRasterizerState();
-		if(rasterizerState != nullptr)
-			coreAccessor.setRasterizerState(rasterizerState.getInternalPtr());
-		else
-			coreAccessor.setRasterizerState(RasterizerState::getDefault());
-	}
-
-	void Pass::bindParameters(CoreAccessor& coreAccessor, const PassParametersPtr& params) const
-	{
-		HGpuProgram vertProgram = getVertexProgram();
-		if(vertProgram)
-			coreAccessor.bindGpuParams(GPT_VERTEX_PROGRAM, params->mVertParams);
-
-		HGpuProgram fragProgram = getFragmentProgram();
-		if(fragProgram)
-			coreAccessor.bindGpuParams(GPT_FRAGMENT_PROGRAM, params->mFragParams);
-
-		HGpuProgram geomProgram = getGeometryProgram();
-		if(geomProgram)
-			coreAccessor.bindGpuParams(GPT_GEOMETRY_PROGRAM, params->mGeomParams);
-
-		HGpuProgram hullProgram = getHullProgram();
-		if(hullProgram)
-			coreAccessor.bindGpuParams(GPT_HULL_PROGRAM, params->mHullParams);
-
-		HGpuProgram domainProgram = getDomainProgram();
-		if(domainProgram)
-			coreAccessor.bindGpuParams(GPT_DOMAIN_PROGRAM, params->mDomainParams);
-
-		HGpuProgram computeProgram = getComputeProgram();
-		if(computeProgram)
-			coreAccessor.bindGpuParams(GPT_COMPUTE_PROGRAM, params->mComputeParams);
-	}
-
 	RTTITypeBase* Pass::getRTTIStatic()
 	{
 		return PassRTTI::instance();

+ 0 - 7
CamelotCore/Source/CmRenderSystem.cpp

@@ -126,13 +126,6 @@ namespace BansheeEngine {
 		mClipPlanesDirty = true;
 	}
 
-	void RenderSystem::addClipPlane (float A, float B, float C, float D)
-	{
-		THROW_IF_NOT_CORE_THREAD;
-
-		addClipPlane(Plane(A, B, C, D));
-	}
-
 	void RenderSystem::setClipPlanes(const PlaneList& clipPlanes)
 	{
 		THROW_IF_NOT_CORE_THREAD;

+ 1 - 0
CamelotFontImporter/Source/CmFontImporter.cpp

@@ -7,6 +7,7 @@
 #include "CmPath.h"
 #include "CmTexAtlasGenerator.h"
 #include "CmApplication.h"
+#include "CmCoreThread.h"
 #include "CmCoreThreadAccessor.h"
 
 #include <ft2build.h>

+ 2 - 2
CamelotOISInput/Include/CmInputHandlerOIS.h

@@ -29,8 +29,8 @@ namespace BansheeEngine
 		virtual bool mousePressed(const OIS::MouseEvent& arg, OIS::MouseButtonID id);
 		virtual bool mouseReleased(const OIS::MouseEvent& arg, OIS::MouseButtonID id);
 
-		virtual void update();
-		virtual void inputWindowChanged(const RenderWindow& win);
+		virtual void _update();
+		virtual void _inputWindowChanged(const RenderWindow& win);
 
 		ButtonCode keyCodeToButtonCode(OIS::KeyCode keyCode) const;
 		ButtonCode mouseButtonToButtonCode(OIS::MouseButtonID mouseBtn) const;

+ 2 - 2
CamelotOISInput/Source/CmInputHandlerOIS.cpp

@@ -59,13 +59,13 @@ namespace BansheeEngine
 		}
 	}
 
-	void InputHandlerOIS::update()
+	void InputHandlerOIS::_update()
 	{
 		mMouse->capture();
 		mKeyboard->capture();
 	}
 
-	void InputHandlerOIS::inputWindowChanged(const RenderWindow& win)
+	void InputHandlerOIS::_inputWindowChanged(const RenderWindow& win)
 	{
 		unsigned long long hWnd;
 		win.getCustomAttribute("WINDOW", &hWnd);