Browse Source

Render systems now use blend states

Marko Pintera 13 years ago
parent
commit
aeed45563e

+ 2 - 2
CamelotClient/CamelotClient.cpp

@@ -27,8 +27,8 @@ using namespace CamelotEngine;
 
 int _tmain(int argc, _TCHAR* argv[])
 {
-	//gApplication().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer");
-	gApplication().startUp("CamelotD3D9RenderSystem", "CamelotForwardRenderer");
+	gApplication().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer");
+	//gApplication().startUp("CamelotD3D9RenderSystem", "CamelotForwardRenderer");
 
 	RenderSystem* renderSystem = RenderSystemManager::getActive();
 	RenderWindow* renderWindow = gApplication().getPrimaryRenderWindow();

+ 3 - 0
CamelotD3D9Renderer/Include/CmD3D9Prerequisites.h

@@ -70,6 +70,9 @@ namespace CamelotEngine
 	class D3D9DriverList;
 	class D3D9VideoMode;
 	class D3D9VideoModeList;
+	class D3D9Device;
+	class D3D9DeviceManager;
+	class D3D9ResourceManager;
 	class D3D9GpuProgram;
 	class D3D9GpuProgramManager;
     class D3D9HardwareBufferManager;

+ 125 - 81
CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h

@@ -38,17 +38,87 @@ THE SOFTWARE.
 
 namespace CamelotEngine 
 {
-	class D3D9DriverList;
-	class D3D9Driver;
-	class D3D9Device;
-	class D3D9DeviceManager;
-	class D3D9ResourceManager;
-
 	/**
 	Implementation of DirectX9 as a rendering system.
 	*/
 	class CM_D3D9_EXPORT D3D9RenderSystem : public RenderSystem
 	{
+	public:
+		// constructor
+		D3D9RenderSystem( HINSTANCE hInstance );
+		// destructor
+		~D3D9RenderSystem();
+
+		const String& getName() const;
+
+		void setStencilCheckEnabled(bool enabled);
+        void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
+            UINT32 refValue = 0, UINT32 mask = 0xFFFFFFFF, 
+            StencilOperation stencilFailOp = SOP_KEEP, 
+            StencilOperation depthFailOp = SOP_KEEP,
+            StencilOperation passOp = SOP_KEEP, 
+            bool twoSidedOperation = false);
+
+		void createRenderWindow_internal(const String &name, unsigned int width, unsigned int height, 
+			bool fullScreen, const NameValuePairList& miscParams, AsyncOp& asyncOp);
+		void destroyRenderTarget(RenderTarget* renderTarget);
+		void setRenderTarget(RenderTarget *target);
+
+		void bindGpuProgram(GpuProgramHandle prg);
+		void unbindGpuProgram(GpuProgramType gptype);
+		void bindGpuProgramParameters(GpuProgramType gptype, 
+			GpuProgramParametersSharedPtr params, UINT16 variabilityMask);
+
+		void setTexture(UINT16 unit, bool enabled, const TexturePtr &texPtr);
+
+		/**
+		 * @copydoc RenderSystem::setSamplerState()
+		 */
+		void setSamplerState(UINT16 unit, const SamplerState& state);
+
+		/**
+		 * @copydoc RenderSystem::setBlendState()
+		 */
+		void setBlendState(const BlendState& blendState);
+
+		void disableTextureUnit(UINT16 texUnit);
+		void setViewport(const Viewport& vp);		
+		void beginFrame();
+		void endFrame();		
+		void setCullingMode( CullingMode mode );
+		void setDepthBufferParams( bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL );
+		void setDepthBufferCheckEnabled( bool enabled = true );
+		void setDepthBufferWriteEnabled(bool enabled = true);
+		void setDepthBufferFunction( CompareFunction func = CMPF_LESS_EQUAL );
+		void setDepthBias(float constantBias, float slopeScaleBias);
+		void convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest, bool forGpuProgram = false);
+		void setPolygonMode(PolygonMode level);
+		void setVertexDeclaration(VertexDeclarationPtr decl);
+		void setVertexBufferBinding(VertexBufferBinding* binding);
+        void render(const RenderOperation& op);
+
+        void setScissorTest(bool enabled, UINT32 left = 0, UINT32 top = 0, UINT32 right = 800, UINT32 bottom = 600);
+        void clearFrameBuffer(unsigned int buffers, 
+            const Color& colour = Color::Black, 
+            float depth = 1.0f, unsigned short stencil = 0);
+
+        float getHorizontalTexelOffset();
+        float getVerticalTexelOffset();
+        float getMinimumDepthInputValue();
+        float getMaximumDepthInputValue();
+		VertexElementType getColorVertexElementType() const;
+
+		/************************************************************************/
+		/* 				Internal use by DX9 RenderSystem only                   */
+		/************************************************************************/
+
+		static D3D9ResourceManager* getResourceManager();
+		static D3D9DeviceManager* getDeviceManager();
+		static IDirect3D9* getDirect3D9();
+		static UINT	getResourceCreationDeviceCount();
+		static IDirect3DDevice9* getResourceCreationDevice(UINT index);
+		static IDirect3DDevice9* getActiveD3D9Device();
+
 	private:
 		/// Direct3D
 		IDirect3D9*	 mpD3D;		
@@ -95,12 +165,7 @@ namespace CamelotEngine
 
 		HRESULT __SetFloatRenderState(D3DRENDERSTATETYPE state, float value)
 		{
-#if OGRE_DOUBLE_PRECISION == 1
-			float temp = static_cast<float>(value);
-			return __SetRenderState(state, *((LPDWORD)(&temp)));
-#else
 			return __SetRenderState(state, *((LPDWORD)(&value)));
-#endif
 		}
 
 		/// return anisotropy level
@@ -175,6 +240,7 @@ namespace CamelotEngine
 		friend class D3D9RenderWindow;
 		friend class D3D9Device;
 		friend class D3D9TextureManager;
+		friend class D3D9DeviceManager;		
 
 		void startUp_internal();
 		void shutdown_internal();
@@ -219,6 +285,10 @@ namespace CamelotEngine
 		void determineFSAASettings(IDirect3DDevice9* d3d9Device, UINT32 fsaa, const String& fsaaHint, D3DFORMAT d3dPixelFormat, 
 			bool fullScreen, D3DMULTISAMPLE_TYPE *outMultisampleType, DWORD *outMultisampleQuality);
 	
+		/************************************************************************/
+		/* 							Sampler states                     			*/
+		/************************************************************************/
+
 		/** Sets the texture addressing mode for a texture unit.*/	
 		void setTextureAddressingMode(UINT16 stage, const UVWAddressingMode& uvw);
 
@@ -244,81 +314,59 @@ namespace CamelotEngine
 		@note Only does something if render system has capability RSC_MIPMAP_LOD_BIAS.
 		*/
 		void setTextureMipmapBias(UINT16 unit, float bias);
-	public:
-		// constructor
-		D3D9RenderSystem( HINSTANCE hInstance );
-		// destructor
-		~D3D9RenderSystem();
-
-		const String& getName() const;
-
-		void setStencilCheckEnabled(bool enabled);
-        void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
-            UINT32 refValue = 0, UINT32 mask = 0xFFFFFFFF, 
-            StencilOperation stencilFailOp = SOP_KEEP, 
-            StencilOperation depthFailOp = SOP_KEEP,
-            StencilOperation passOp = SOP_KEEP, 
-            bool twoSidedOperation = false);
 
-		void createRenderWindow_internal(const String &name, unsigned int width, unsigned int height, 
-			bool fullScreen, const NameValuePairList& miscParams, AsyncOp& asyncOp);
-		void destroyRenderTarget(RenderTarget* renderTarget);
-		void setRenderTarget(RenderTarget *target);
+		/************************************************************************/
+		/* 								Blend states                      		*/
+		/************************************************************************/
+
+		/** Sets the global blending factors for combining subsequent renders with the existing frame contents.
+		The result of the blending operation is:</p>
+		<p align="center">final = (texture * sourceFactor) + (pixel * destFactor)</p>
+		Each of the factors is specified as one of a number of options, as specified in the SceneBlendFactor
+		enumerated type.
+		By changing the operation you can change addition between the source and destination pixels to a different operator.
+		@param sourceFactor The source factor in the above calculation, i.e. multiplied by the texture colour components.
+		@param destFactor The destination factor in the above calculation, i.e. multiplied by the pixel colour components.
+		@param op The blend operation mode for combining pixels
+		*/
+		void setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
 
-		void bindGpuProgram(GpuProgramHandle prg);
-		void unbindGpuProgram(GpuProgramType gptype);
-		void bindGpuProgramParameters(GpuProgramType gptype, 
-			GpuProgramParametersSharedPtr params, UINT16 variabilityMask);
+		/** Sets the global blending factors for combining subsequent renders with the existing frame contents.
+		The result of the blending operation is:</p>
+		<p align="center">final = (texture * sourceFactor) + (pixel * destFactor)</p>
+		Each of the factors is specified as one of a number of options, as specified in the SceneBlendFactor
+		enumerated type.
+		@param sourceFactor The source factor in the above calculation, i.e. multiplied by the texture colour components.
+		@param destFactor The destination factor in the above calculation, i.e. multiplied by the pixel colour components.
+		@param sourceFactorAlpha The source factor in the above calculation for the alpha channel, i.e. multiplied by the texture alpha components.
+		@param destFactorAlpha The destination factor in the above calculation for the alpha channel, i.e. multiplied by the pixel alpha components.
+		@param op The blend operation mode for combining pixels
+		@param alphaOp The blend operation mode for combining pixel alpha values
+		*/
+		void setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, 
+			SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
 
-		// Low-level overridden members, mainly for internal use
-		void setPointParameters(float size, bool attenuationEnabled, 
-			float constant, float linear, float quadratic, float minSize, float maxSize);
-		void setTexture(UINT16 unit, bool enabled, const TexturePtr &texPtr);
+		/** Sets the global alpha rejection approach for future renders.
+		By default images are rendered regardless of texture alpha. This method lets you change that.
+		@param func The comparison function which must pass for a pixel to be written.
+		@param val The value to compare each pixels alpha value to (0-255)
+		*/
+		void setAlphaTest(CompareFunction func, unsigned char value);
 
 		/**
-		 * @copydoc RenderSystem::setSamplerState()
+		 * @brief	Enable alpha coverage if supported.
 		 */
-		void setSamplerState(UINT16 unit, const SamplerState& state);
+		void setAlphaToCoverage(bool enabled);
 
-		void disableTextureUnit(UINT16 texUnit);
-		void setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
-		void setSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
-		void setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage );
-		void setViewport(const Viewport& vp);		
-		void beginFrame();
-		void endFrame();		
-		void setCullingMode( CullingMode mode );
-		void setDepthBufferParams( bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL );
-		void setDepthBufferCheckEnabled( bool enabled = true );
+		/** Sets whether or not colour buffer writing is enabled, and for which channels. 
+		@remarks
+		For some advanced effects, you may wish to turn off the writing of certain colour
+		channels, or even all of the colour channels so that only the depth buffer is updated
+		in a rendering pass. However, the chances are that you really want to use this option
+		through the Material class.
+		@param red, green, blue, alpha Whether writing is enabled for each of the 4 colour channels. */
 		void setColorBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
-		void setDepthBufferWriteEnabled(bool enabled = true);
-		void setDepthBufferFunction( CompareFunction func = CMPF_LESS_EQUAL );
-		void setDepthBias(float constantBias, float slopeScaleBias);
-		void convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest, bool forGpuProgram = false);
-		void setPolygonMode(PolygonMode level);
-		void setVertexDeclaration(VertexDeclarationPtr decl);
-		void setVertexBufferBinding(VertexBufferBinding* binding);
-        void render(const RenderOperation& op);
-
-        void setScissorTest(bool enabled, UINT32 left = 0, UINT32 top = 0, UINT32 right = 800, UINT32 bottom = 600);
-        void clearFrameBuffer(unsigned int buffers, 
-            const Color& colour = Color::Black, 
-            float depth = 1.0f, unsigned short stencil = 0);
-
-        float getHorizontalTexelOffset();
-        float getVerticalTexelOffset();
-        float getMinimumDepthInputValue();
-        float getMaximumDepthInputValue();
-		VertexElementType getColorVertexElementType() const;
-
-		static D3D9ResourceManager* getResourceManager();
-		static D3D9DeviceManager* getDeviceManager();
-		static IDirect3D9* getDirect3D9();
-		static UINT	getResourceCreationDeviceCount();
-		static IDirect3DDevice9* getResourceCreationDevice(UINT index);
-		static IDirect3DDevice9* getActiveD3D9Device();
 
-	protected:	
 		/// Notify when a device has been lost.
 		void notifyOnDeviceLost(D3D9Device* device);
 
@@ -327,10 +375,6 @@ namespace CamelotEngine
 		
 		typedef map<RenderTarget*, ZBufferRef>::type TargetDepthStencilMap;
 		TargetDepthStencilMap mCheckedOutTextures;
-
-	private:
-		friend class D3D9Device;
-		friend class D3D9DeviceManager;		
 	};
 }
 #endif

+ 40 - 41
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -49,6 +49,7 @@ THE SOFTWARE.
 #include "CmD3D9ResourceManager.h"
 #include "CmHighLevelGpuProgramManager.h"
 #include "CmAsyncOp.h"
+#include "CmBlendState.h"
 
 #if CM_DEBUG_MODE
 #define THROW_IF_NOT_RENDER_THREAD throwIfNotRenderThread();
@@ -347,7 +348,7 @@ namespace CamelotEngine
 
 					SamplerStatePtr samplerState = params->getSamplerState(i->second.physicalIndex);
 					if(samplerState == nullptr)
-						setSamplerState(logicalIndex, SamplerState::DEFAULT);
+						setSamplerState(logicalIndex, SamplerState::getDefault());
 					else
 						setSamplerState(logicalIndex, *samplerState);
 				}
@@ -486,35 +487,6 @@ namespace CamelotEngine
 		// Do the real removal
 		RenderSystem::destroyRenderTarget(renderTarget);	
 	}
-
-	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setPointParameters(float size, 
-		bool attenuationEnabled, float constant, float linear, float quadratic,
-		float minSize, float maxSize)
-	{
-		THROW_IF_NOT_RENDER_THREAD;
-
-		if(attenuationEnabled)
-		{
-			// scaling required
-			__SetRenderState(D3DRS_POINTSCALEENABLE, TRUE);
-			__SetFloatRenderState(D3DRS_POINTSCALE_A, constant);
-			__SetFloatRenderState(D3DRS_POINTSCALE_B, linear);
-			__SetFloatRenderState(D3DRS_POINTSCALE_C, quadratic);
-		}
-		else
-		{
-			// no scaling required
-			__SetRenderState(D3DRS_POINTSCALEENABLE, FALSE);
-		}
-		__SetFloatRenderState(D3DRS_POINTSIZE, size);
-		__SetFloatRenderState(D3DRS_POINTSIZE_MIN, minSize);
-		if (maxSize == 0.0f)
-			maxSize = mCurrentCapabilities->getMaxPointSize();
-		__SetFloatRenderState(D3DRS_POINTSIZE_MAX, maxSize);
-
-
-	}
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setTexture( UINT16 stage, bool enabled, const TexturePtr& tex )
 	{
@@ -604,6 +576,30 @@ namespace CamelotEngine
 		// Set border color
 		setTextureBorderColor(unit, state.getBorderColor(0));
 	}
+	//-----------------------------------------------------------------------
+	void D3D9RenderSystem::setBlendState(const BlendState& blendState)
+	{
+		THROW_IF_NOT_RENDER_THREAD;
+
+		// Alpha to coverage
+		setAlphaToCoverage(blendState.getAlphaToCoverageEnabled());
+
+		// Blend states
+		// DirectX 9 doesn't allow us to specify blend state per render target, so we just use the first one.
+		if(blendState.getBlendEnabled(0))
+		{
+			setSceneBlending(blendState.getSrcBlend(0), blendState.getDstBlend(0), blendState.getAlphaSrcBlend(0), blendState.getAlphaDstBlend(0)
+				, blendState.getBlendOperation(0), blendState.getAlphaBlendOperation(0));
+		}
+		else
+		{
+			setSceneBlending(SBF_ONE, SBF_ZERO, SBO_ADD);
+		}
+
+		// Color write mask
+		UINT8 writeMask = blendState.getRenderTargetWriteMask(0);
+		setColorBufferWriteEnabled(writeMask & 0x1, writeMask & 0x2, writeMask & 0x4, writeMask & 0x8);
+	}
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setTextureMipmapBias(UINT16 unit, float bias)
 	{
@@ -672,7 +668,7 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Failed to set scene blending operation option");
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, 
+	void D3D9RenderSystem::setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, 
 		SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp )
 	{
 		THROW_IF_NOT_RENDER_THREAD;
@@ -706,20 +702,16 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Failed to set alpha scene blending operation option");
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage )
+	void D3D9RenderSystem::setAlphaTest(CompareFunction func, unsigned char value)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
 		HRESULT hr;
-		bool a2c = false;
-		static bool lasta2c = false;
 
 		if (func != CMPF_ALWAYS_PASS)
 		{
 			if( FAILED( hr = __SetRenderState( D3DRS_ALPHATESTENABLE,  TRUE ) ) )
 				CM_EXCEPT(RenderingAPIException, "Failed to enable alpha testing");
-
-			a2c = alphaToCoverage;
 		}
 		else
 		{
@@ -731,6 +723,14 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Failed to set alpha reject function");
 		if( FAILED( hr = __SetRenderState( D3DRS_ALPHAREF, value ) ) )
 			CM_EXCEPT(RenderingAPIException, "Failed to set render state D3DRS_ALPHAREF");
+	}
+	//---------------------------------------------------------------------
+	void D3D9RenderSystem::setAlphaToCoverage(bool enable)
+	{
+		THROW_IF_NOT_RENDER_THREAD;
+
+		HRESULT hr;
+		static bool lasta2c = false;
 
 		// Alpha to coverage
 		if (getCapabilities()->hasCapability(RSC_ALPHA_TO_COVERAGE))
@@ -738,7 +738,7 @@ namespace CamelotEngine
 			// Vendor-specific hacks on renderstate, gotta love 'em
 			if (getCapabilities()->getVendor() == GPU_NVIDIA)
 			{
-				if (a2c)
+				if (enable)
 				{
 					if( FAILED( hr = __SetRenderState( D3DRS_ADAPTIVETESS_Y,  (D3DFORMAT)MAKEFOURCC('A', 'T', 'O', 'C') ) ) )
 						CM_EXCEPT(RenderingAPIException, "Failed to set alpha to coverage option");
@@ -752,7 +752,7 @@ namespace CamelotEngine
 			}
 			else if ((getCapabilities()->getVendor() == GPU_ATI))
 			{
-				if (a2c)
+				if (enable)
 				{
 					if( FAILED( hr = __SetRenderState( D3DRS_POINTSIZE,  MAKEFOURCC('A','2','M','1') ) ) )
 						CM_EXCEPT(RenderingAPIException, "Failed to set alpha to coverage option");
@@ -764,10 +764,9 @@ namespace CamelotEngine
 						CM_EXCEPT(RenderingAPIException, "Failed to set alpha to coverage option");
 				}
 			}
-			// no hacks available for any other vendors?
-			lasta2c = a2c;
-		}
 
+			lasta2c = enable;
+		}
 	}
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setCullingMode( CullingMode mode )

+ 6 - 40
CamelotForwardRenderer/Source/CmForwardRenderer.cpp

@@ -6,6 +6,7 @@
 #include "CmMaterial.h"
 #include "CmMesh.h"
 #include "CmPass.h"
+#include "CmBlendState.h"
 #include "CmApplication.h"
 
 namespace CamelotEngine
@@ -131,42 +132,16 @@ namespace CamelotEngine
 		}
 
 		// The rest of the settings are the same no matter whether we use programs or not
-
-		// Set scene blending
-		if ( pass->hasSeparateSceneBlending( ) )
+		BlendStatePtr blendState = pass->getBlendState();
+		if(blendState != nullptr)
 		{
-			renderContext->setSeparateSceneBlending(
-				pass->getSourceBlendFactor(), pass->getDestBlendFactor(),
-				pass->getSourceBlendFactorAlpha(), pass->getDestBlendFactorAlpha(),
-				pass->getSceneBlendingOperation(), 
-				pass->hasSeparateSceneBlendingOperations() ? pass->getSceneBlendingOperation() : pass->getSceneBlendingOperationAlpha() );
+			renderContext->setBlendState(*blendState);
 		}
 		else
 		{
-			if(pass->hasSeparateSceneBlendingOperations( ) )
-			{
-				renderContext->setSeparateSceneBlending(
-					pass->getSourceBlendFactor(), pass->getDestBlendFactor(),
-					pass->getSourceBlendFactor(), pass->getDestBlendFactor(),
-					pass->getSceneBlendingOperation(), pass->getSceneBlendingOperationAlpha() );
-			}
-			else
-			{
-				renderContext->setSceneBlending(
-					pass->getSourceBlendFactor(), pass->getDestBlendFactor(), pass->getSceneBlendingOperation() );
-			}
+			renderContext->setBlendState(BlendState::getDefault());
 		}
-
-		// Set point parameters
-		renderContext->setPointParameters(
-			pass->getPointSize(),
-			false, 
-			false, 
-			false, 
-			false, 
-			pass->getPointMinSize(), 
-			pass->getPointMaxSize());
-
+		
 		// TODO - Try to limit amount of state changes, if previous state is already the same (especially with textures)
 
 		// TODO: Disable remaining texture units
@@ -180,15 +155,6 @@ namespace CamelotEngine
 		renderContext->setDepthBufferWriteEnabled(pass->getDepthWriteEnabled());
 		renderContext->setDepthBias(pass->getDepthBiasConstant(), pass->getDepthBiasSlopeScale());
 
-		// Alpha-reject settings
-		renderContext->setAlphaRejectSettings(
-			pass->getAlphaRejectFunction(), pass->getAlphaRejectValue(), pass->isAlphaToCoverageEnabled());
-
-		// Set colour write mode
-		// Right now we only use on/off, not per-channel
-		bool colWrite = pass->getColourWriteEnabled();
-		renderContext->setColorBufferWriteEnabled(colWrite, colWrite, colWrite, colWrite);
-
 		// Culling mode
 		renderContext->setCullingMode(pass->getCullingMode());
 

+ 198 - 163
CamelotGLRenderer/Include/CmGLRenderSystem.h

@@ -43,6 +43,148 @@ namespace CamelotEngine {
      */
     class CM_RSGL_EXPORT GLRenderSystem : public RenderSystem
     {
+    public:
+        // Default constructor / destructor
+        GLRenderSystem();
+        ~GLRenderSystem();
+
+        // ----------------------------------
+        // Overridden RenderSystem functions
+        // ----------------------------------
+        /** See
+          RenderSystem
+         */
+        const String& getName(void) const;
+
+        // -----------------------------
+        // Low-level overridden members
+        // -----------------------------
+		/** See
+          RenderSystem
+         */
+		void createRenderWindow_internal(const String &name, unsigned int width, unsigned int height, 
+			bool fullScreen, const NameValuePairList& miscParams, AsyncOp& asyncOp);
+        /**
+         * Set current render target to target, enabling its GL context if needed
+         */
+        void setRenderTarget(RenderTarget *target);
+		/** See
+          RenderSystem
+         */
+		void bindGpuProgram(GpuProgramHandle prg);
+        /** See
+          RenderSystem
+         */
+		void unbindGpuProgram(GpuProgramType gptype);
+		/** See
+          RenderSystem
+         */
+		void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, UINT16 mask);
+		/** See
+          RenderSystem
+         */
+        void setTexture(UINT16 unit, bool enabled, const TexturePtr &tex);
+        
+		/**
+		 * @copydoc RenderSystem::setSamplerState()
+		 */
+		void setSamplerState(UINT16 unit, const SamplerState& state);
+
+		/**
+		 * @copydoc RenderSystem::setBlendState()
+		 */
+		void setBlendState(const BlendState& blendState);
+
+        /** See
+          RenderSystem
+         */
+        void setViewport(const Viewport& vp);
+        /** See
+          RenderSystem
+         */
+        void beginFrame(void);
+        /** See
+          RenderSystem
+         */
+        void endFrame(void);
+        /** See
+          RenderSystem
+         */
+        void setCullingMode(CullingMode mode);
+        /** See
+          RenderSystem
+         */
+        void setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
+        /** See
+          RenderSystem
+         */
+        void setDepthBufferCheckEnabled(bool enabled = true);
+        /** See
+          RenderSystem
+         */
+        void setDepthBufferWriteEnabled(bool enabled = true);
+        /** See
+          RenderSystem
+         */
+        void setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
+        /** See
+          RenderSystem
+         */
+        void setDepthBias(float constantBias, float slopeScaleBias);
+        /** See
+          RenderSystem
+         */
+        void convertProjectionMatrix(const Matrix4& matrix,
+            Matrix4& dest, bool forGpuProgram = false);
+        /** See
+          RenderSystem
+         */
+        void setPolygonMode(PolygonMode level);
+        /** See
+          RenderSystem
+         */
+        void setStencilCheckEnabled(bool enabled);
+        /** See
+          RenderSystem.
+         */
+        void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
+            UINT32 refValue = 0, UINT32 mask = 0xFFFFFFFF, 
+            StencilOperation stencilFailOp = SOP_KEEP, 
+            StencilOperation depthFailOp = SOP_KEEP,
+            StencilOperation passOp = SOP_KEEP, 
+            bool twoSidedOperation = false);
+        /** See
+          RenderSystem
+         */
+		void setVertexDeclaration(VertexDeclarationPtr decl);
+        /** See
+          RenderSystem
+         */
+		void setVertexBufferBinding(VertexBufferBinding* binding);
+        /** See
+          RenderSystem
+         */
+        void render(const RenderOperation& op);
+
+        /** See
+          RenderSystem
+         */
+        void setScissorTest(bool enabled, UINT32 left = 0, UINT32 top = 0, UINT32 right = 800, UINT32 bottom = 600) ;
+        void clearFrameBuffer(unsigned int buffers, 
+            const Color& colour = Color::Black, 
+            float depth = 1.0f, unsigned short stencil = 0);
+
+		/** See
+          RenderSystem
+         */
+        VertexElementType getColorVertexElementType(void) const;
+        float getHorizontalTexelOffset(void);
+        float getVerticalTexelOffset(void);
+        float getMinimumDepthInputValue(void);
+        float getMaximumDepthInputValue(void);
+
+        void _unregisterContext(GLContext *context);
+
     private:
         /// Rendering loop control
         bool mStopRendering;
@@ -157,6 +299,10 @@ namespace CamelotEngine {
          */
         void enableClipPlane (UINT16 index, bool enable);
 
+		/************************************************************************/
+		/* 								Sampler states                     		*/
+		/************************************************************************/
+
 		/** Sets the texture addressing mode for a texture unit.*/
         void setTextureAddressingMode(UINT16 stage, const UVWAddressingMode& uvw);
 
@@ -183,6 +329,58 @@ namespace CamelotEngine {
 		/** Sets the maximal anisotropy for the specified texture unit.*/
 		void setTextureAnisotropy(UINT16 unit, unsigned int maxAnisotropy);
 
+		/************************************************************************/
+		/* 								Blend states                      		*/
+		/************************************************************************/
+
+		/** Sets the global blending factors for combining subsequent renders with the existing frame contents.
+		The result of the blending operation is:</p>
+		<p align="center">final = (texture * sourceFactor) + (pixel * destFactor)</p>
+		Each of the factors is specified as one of a number of options, as specified in the SceneBlendFactor
+		enumerated type.
+		By changing the operation you can change addition between the source and destination pixels to a different operator.
+		@param sourceFactor The source factor in the above calculation, i.e. multiplied by the texture colour components.
+		@param destFactor The destination factor in the above calculation, i.e. multiplied by the pixel colour components.
+		@param op The blend operation mode for combining pixels
+		*/
+		void setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
+
+		/** Sets the global blending factors for combining subsequent renders with the existing frame contents.
+		The result of the blending operation is:</p>
+		<p align="center">final = (texture * sourceFactor) + (pixel * destFactor)</p>
+		Each of the factors is specified as one of a number of options, as specified in the SceneBlendFactor
+		enumerated type.
+		@param sourceFactor The source factor in the above calculation, i.e. multiplied by the texture colour components.
+		@param destFactor The destination factor in the above calculation, i.e. multiplied by the pixel colour components.
+		@param sourceFactorAlpha The source factor in the above calculation for the alpha channel, i.e. multiplied by the texture alpha components.
+		@param destFactorAlpha The destination factor in the above calculation for the alpha channel, i.e. multiplied by the pixel alpha components.
+		@param op The blend operation mode for combining pixels
+		@param alphaOp The blend operation mode for combining pixel alpha values
+		*/
+		void setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, 
+			SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
+
+		/** Sets the global alpha rejection approach for future renders.
+		By default images are rendered regardless of texture alpha. This method lets you change that.
+		@param func The comparison function which must pass for a pixel to be written.
+		@param val The value to compare each pixels alpha value to (0-255)
+		*/
+		void setAlphaTest(CompareFunction func, unsigned char value);
+
+		/**
+		 * @brief	Enable alpha coverage if supported.
+		 */
+		void setAlphaToCoverage(bool enabled);
+
+		/** Sets whether or not colour buffer writing is enabled, and for which channels. 
+		@remarks
+		For some advanced effects, you may wish to turn off the writing of certain colour
+		channels, or even all of the colour channels so that only the depth buffer is updated
+		in a rendering pass. However, the chances are that you really want to use this option
+		through the Material class.
+		@param red, green, blue, alpha Whether writing is enabled for each of the 4 colour channels. */
+		void setColorBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
+
 		// ----------------------------------
         // GLRenderSystem specific members
         // ----------------------------------
@@ -203,169 +401,6 @@ namespace CamelotEngine {
 
 		/** Returns the main context */
 		GLContext* _getMainContext() {return mMainContext;} 
-
-    public:
-        // Default constructor / destructor
-        GLRenderSystem();
-        ~GLRenderSystem();
-
-        // ----------------------------------
-        // Overridden RenderSystem functions
-        // ----------------------------------
-        /** See
-          RenderSystem
-         */
-        const String& getName(void) const;
-
-        // -----------------------------
-        // Low-level overridden members
-        // -----------------------------
-		/** See
-          RenderSystem
-         */
-		void createRenderWindow_internal(const String &name, unsigned int width, unsigned int height, 
-			bool fullScreen, const NameValuePairList& miscParams, AsyncOp& asyncOp);
-        /**
-         * Set current render target to target, enabling its GL context if needed
-         */
-        void setRenderTarget(RenderTarget *target);
-		/** See
-          RenderSystem
-         */
-		void bindGpuProgram(GpuProgramHandle prg);
-        /** See
-          RenderSystem
-         */
-		void unbindGpuProgram(GpuProgramType gptype);
-		/** See
-          RenderSystem
-         */
-		void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, UINT16 mask);
-        /** See
-          RenderSystem
-         */
-		void setPointParameters(float size, bool attenuationEnabled, 
-			float constant, float linear, float quadratic, float minSize, float maxSize);
-		/** See
-          RenderSystem
-         */
-        void setTexture(UINT16 unit, bool enabled, const TexturePtr &tex);
-        
-		/**
-		 * @copydoc RenderSystem::setSamplerState()
-		 */
-		void setSamplerState(UINT16 unit, const SamplerState& state);
-
-        void setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
-        /** See
-          RenderSystem
-         */
-		void setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
-        /** See
-          RenderSystem
-         */
-		void _setSceneBlendingOperation(SceneBlendOperation op);
-		/** See
-          RenderSystem
-         */
-		void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp);
-		/** See
-          RenderSystem
-         */
-        void setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage);
-        /** See
-          RenderSystem
-         */
-        void setViewport(const Viewport& vp);
-        /** See
-          RenderSystem
-         */
-        void beginFrame(void);
-        /** See
-          RenderSystem
-         */
-        void endFrame(void);
-        /** See
-          RenderSystem
-         */
-        void setCullingMode(CullingMode mode);
-        /** See
-          RenderSystem
-         */
-        void setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
-        /** See
-          RenderSystem
-         */
-        void setDepthBufferCheckEnabled(bool enabled = true);
-        /** See
-          RenderSystem
-         */
-        void setDepthBufferWriteEnabled(bool enabled = true);
-        /** See
-          RenderSystem
-         */
-        void setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
-        /** See
-          RenderSystem
-         */
-        void setDepthBias(float constantBias, float slopeScaleBias);
-        /** See
-          RenderSystem
-         */
-        void setColorBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
-        /** See
-          RenderSystem
-         */
-        void convertProjectionMatrix(const Matrix4& matrix,
-            Matrix4& dest, bool forGpuProgram = false);
-        /** See
-          RenderSystem
-         */
-        void setPolygonMode(PolygonMode level);
-        /** See
-          RenderSystem
-         */
-        void setStencilCheckEnabled(bool enabled);
-        /** See
-          RenderSystem.
-         */
-        void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
-            UINT32 refValue = 0, UINT32 mask = 0xFFFFFFFF, 
-            StencilOperation stencilFailOp = SOP_KEEP, 
-            StencilOperation depthFailOp = SOP_KEEP,
-            StencilOperation passOp = SOP_KEEP, 
-            bool twoSidedOperation = false);
-        /** See
-          RenderSystem
-         */
-		void setVertexDeclaration(VertexDeclarationPtr decl);
-        /** See
-          RenderSystem
-         */
-		void setVertexBufferBinding(VertexBufferBinding* binding);
-        /** See
-          RenderSystem
-         */
-        void render(const RenderOperation& op);
-
-        /** See
-          RenderSystem
-         */
-        void setScissorTest(bool enabled, UINT32 left = 0, UINT32 top = 0, UINT32 right = 800, UINT32 bottom = 600) ;
-        void clearFrameBuffer(unsigned int buffers, 
-            const Color& colour = Color::Black, 
-            float depth = 1.0f, unsigned short stencil = 0);
-
-		/** See
-          RenderSystem
-         */
-        VertexElementType getColorVertexElementType(void) const;
-        float getHorizontalTexelOffset(void);
-        float getVerticalTexelOffset(void);
-        float getMinimumDepthInputValue(void);
-        float getMaximumDepthInputValue(void);
-
-        void _unregisterContext(GLContext *context);
     };
 }
 #endif

+ 40 - 81
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -43,6 +43,7 @@ THE SOFTWARE.s
 #include "CmGLHardwareOcclusionQuery.h"
 #include "CmGLContext.h"
 #include "CmAsyncOp.h"
+#include "CmBlendState.h"
 
 #include "CmGLFBORenderTexture.h"
 #include "CmGLPBRenderTexture.h"
@@ -353,7 +354,7 @@ namespace CamelotEngine {
 
 					SamplerStatePtr samplerState = params->getSamplerState(def.physicalIndex);
 					if(samplerState == nullptr)
-						setSamplerState(def.physicalIndex, SamplerState::DEFAULT);
+						setSamplerState(def.physicalIndex, SamplerState::getDefault());
 					else
 						setSamplerState(def.physicalIndex, *samplerState);
 				}
@@ -377,74 +378,6 @@ namespace CamelotEngine {
 		}
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setPointParameters(float size, 
-		bool attenuationEnabled, float constant, float linear, float quadratic,
-		float minSize, float maxSize)
-	{
-		THROW_IF_NOT_RENDER_THREAD;
-
-		float val[4] = {1, 0, 0, 1};
-		
-		if(attenuationEnabled) 
-		{
-			// Point size is still calculated in pixels even when attenuation is
-			// enabled, which is pretty awkward, since you typically want a viewport
-			// independent size if you're looking for attenuation.
-			// So, scale the point size up by viewport size (this is equivalent to
-			// what D3D does as standard)
-			size = size * mActiveViewport.getActualHeight();
-			minSize = minSize * mActiveViewport.getActualHeight();
-			if (maxSize == 0.0f)
-				maxSize = mCurrentCapabilities->getMaxPointSize(); // pixels
-			else
-				maxSize = maxSize * mActiveViewport.getActualHeight();
-			
-			// XXX: why do I need this for results to be consistent with D3D?
-			// Equations are supposedly the same once you factor in vp height
-			float correction = 0.005f;
-			// scaling required
-			val[0] = constant;
-			val[1] = linear * correction;
-			val[2] = quadratic * correction;
-			val[3] = 1;
-			
-			if (mCurrentCapabilities->hasCapability(RSC_VERTEX_PROGRAM))
-				glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
-			
-			
-		} 
-		else 
-		{
-			if (maxSize == 0.0f)
-				maxSize = mCurrentCapabilities->getMaxPointSize();
-			if (mCurrentCapabilities->hasCapability(RSC_VERTEX_PROGRAM))
-				glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
-		}
-		
-		// no scaling required
-		// GL has no disabled flag for this so just set to constant
-		glPointSize(size);
-		
-		if (mCurrentCapabilities->hasCapability(RSC_POINT_EXTENDED_PARAMETERS))
-		{
-			glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, val);
-			glPointParameterf(GL_POINT_SIZE_MIN, minSize);
-			glPointParameterf(GL_POINT_SIZE_MAX, maxSize);
-		} 
-		else if (mCurrentCapabilities->hasCapability(RSC_POINT_EXTENDED_PARAMETERS_ARB))
-		{
-			glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION, val);
-			glPointParameterfARB(GL_POINT_SIZE_MIN, minSize);
-			glPointParameterfARB(GL_POINT_SIZE_MAX, maxSize);
-		} 
-		else if (mCurrentCapabilities->hasCapability(RSC_POINT_EXTENDED_PARAMETERS_EXT))
-		{
-			glPointParameterfvEXT(GL_POINT_DISTANCE_ATTENUATION, val);
-			glPointParameterfEXT(GL_POINT_SIZE_MIN, minSize);
-			glPointParameterfEXT(GL_POINT_SIZE_MAX, maxSize);
-		}
-	}
-	//-----------------------------------------------------------------------------
 	void GLRenderSystem::setTexture(UINT16 stage, bool enabled, const TexturePtr &texPtr)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
@@ -527,6 +460,30 @@ namespace CamelotEngine {
 		setTextureBorderColor(unit, state.getBorderColor(0));
 	}
 	//-----------------------------------------------------------------------------
+	void GLRenderSystem::setBlendState(const BlendState& blendState)
+	{
+		THROW_IF_NOT_RENDER_THREAD;
+
+		// Alpha to coverage
+		setAlphaToCoverage(blendState.getAlphaToCoverageEnabled());
+
+		// Blend states
+		// DirectX 9 doesn't allow us to specify blend state per render target, so we just use the first one.
+		if(blendState.getBlendEnabled(0))
+		{
+			setSceneBlending(blendState.getSrcBlend(0), blendState.getDstBlend(0), blendState.getAlphaSrcBlend(0), blendState.getAlphaDstBlend(0)
+				, blendState.getBlendOperation(0), blendState.getAlphaBlendOperation(0));
+		}
+		else
+		{
+			setSceneBlending(SBF_ONE, SBF_ZERO, SBO_ADD);
+		}
+
+		// Color write mask
+		UINT8 writeMask = blendState.getRenderTargetWriteMask(0);
+		setColorBufferWriteEnabled(writeMask & 0x1, writeMask & 0x2, writeMask & 0x4, writeMask & 0x8);
+	}
+	//-----------------------------------------------------------------------------
 	void GLRenderSystem::setTextureAddressingMode(UINT16 stage, const UVWAddressingMode& uvw)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
@@ -615,7 +572,7 @@ namespace CamelotEngine {
 		}
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setSeparateSceneBlending(
+	void GLRenderSystem::setSceneBlending(
 		SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, 
 		SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha,
 		SceneBlendOperation op, SceneBlendOperation alphaOp )
@@ -686,13 +643,10 @@ namespace CamelotEngine {
 		}
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage)
+	void GLRenderSystem::setAlphaTest(CompareFunction func, unsigned char value)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
-		bool a2c = false;
-		static bool lasta2c = false;
-
 		if(func == CMPF_ALWAYS_PASS)
 		{
 			glDisable(GL_ALPHA_TEST);
@@ -700,20 +654,25 @@ namespace CamelotEngine {
 		else
 		{
 			glEnable(GL_ALPHA_TEST);
-			a2c = alphaToCoverage;
 			glAlphaFunc(convertCompareFunction(func), value / 255.0f);
 		}
+	}
+	//-----------------------------------------------------------------------------
+	void GLRenderSystem::setAlphaToCoverage(bool enable)
+	{
+		THROW_IF_NOT_RENDER_THREAD;
+
+		static bool lasta2c = false;
 
-		if (a2c != lasta2c && getCapabilities()->hasCapability(RSC_ALPHA_TO_COVERAGE))
+		if (enable != lasta2c && getCapabilities()->hasCapability(RSC_ALPHA_TO_COVERAGE))
 		{
-			if (a2c)
+			if (enable)
 				glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);
 			else
 				glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE);
 
-			lasta2c = a2c;
+			lasta2c = enable;
 		}
-
 	}
 	//-----------------------------------------------------------------------------
 	void GLRenderSystem::setViewport(const Viewport& vp)
@@ -1775,9 +1734,9 @@ namespace CamelotEngine {
 		return (errString != 0) ? String((const char*) errString) : StringUtil::BLANK;
 	}
 	//-----------------------------------------------------------------------------
-	GLint GLRenderSystem::getBlendMode(SceneBlendFactor ogreBlend) const
+	GLint GLRenderSystem::getBlendMode(SceneBlendFactor blendMode) const
 	{
-		switch(ogreBlend)
+		switch(blendMode)
 		{
 		case SBF_ONE:
 			return GL_ONE;

+ 1 - 0
CamelotRenderer/CamelotRenderer.vcxproj

@@ -177,6 +177,7 @@
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Include\CmApplication.h" />
+    <ClInclude Include="Include\CmBlendStateRTTI.h" />
     <ClInclude Include="Include\CmCamera.h" />
     <ClInclude Include="Include\CmCameraRTTI.h" />
     <ClInclude Include="Include\CmCgProgram.h" />

+ 3 - 0
CamelotRenderer/CamelotRenderer.vcxproj.filters

@@ -332,6 +332,9 @@
     <ClInclude Include="Include\CmBlendState.h">
       <Filter>Header Files\RenderSystem</Filter>
     </ClInclude>
+    <ClInclude Include="Include\CmBlendStateRTTI.h">
+      <Filter>Header Files\RTTI</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CamelotRenderer.cpp">

+ 35 - 2
CamelotRenderer/Include/CmBlendState.h

@@ -1,12 +1,24 @@
 #pragma once
 
 #include "CmPrerequisites.h"
+#include "CmIReflectable.h"
 #include "CmCommon.h"
 
 namespace CamelotEngine
 {
 	struct CM_EXPORT RENDER_TARGET_BLEND_STATE_DESC
 	{
+		RENDER_TARGET_BLEND_STATE_DESC()
+			: blendEnable(false)
+			, srcBlend(SBF_ONE)
+			, dstBlend(SBF_ZERO)
+			, blendOp(SBO_ADD)
+			, srcBlendAlpha(SBF_ONE)
+			, dstBlendAlpha(SBF_ZERO)
+			, blendOpAlpha(SBO_ADD)
+			, renderTargetWriteMask(0xFF)
+		{ }
+
 		bool blendEnable;
 		SceneBlendFactor srcBlend;
 		SceneBlendFactor dstBlend;
@@ -14,17 +26,24 @@ namespace CamelotEngine
 		SceneBlendFactor srcBlendAlpha;
 		SceneBlendFactor dstBlendAlpha;
 		SceneBlendOperation blendOpAlpha;
+		// Enable write to RGBA channels separately by setting first four bits (0 - R, 1 - G, 2 - B, 3 - A)
 		UINT8 renderTargetWriteMask;
 	};
 
 	struct CM_EXPORT BLEND_STATE_DESC
 	{
+		BLEND_STATE_DESC()
+			: alphaToCoverageEnable(false)
+			, independantBlendEnable(false)
+		{ }
+
 		bool alphaToCoverageEnable;
 		bool independantBlendEnable;
 		RENDER_TARGET_BLEND_STATE_DESC renderTargetDesc[CM_MAX_MULTIPLE_RENDER_TARGETS];
 	};
 
-	class CM_EXPORT BlendState
+	// TODO Low priority - Write doc explaining various states
+	class CM_EXPORT BlendState : public IReflectable
 	{
 	public:
 		virtual ~BlendState() {}
@@ -32,7 +51,7 @@ namespace CamelotEngine
 		bool getAlphaToCoverageEnabled() const { return mData.alphaToCoverageEnable; }
 		bool getIndependantBlendEnable() const { return mData.independantBlendEnable; }
 
-		bool getBlendEnable(UINT32 renderTargetIdx) const;
+		bool getBlendEnabled(UINT32 renderTargetIdx) const;
 		SceneBlendFactor getSrcBlend(UINT32 renderTargetIdx) const;
 		SceneBlendFactor getDstBlend(UINT32 renderTargetIdx) const;
 		SceneBlendOperation getBlendOperation(UINT32 renderTargetIdx) const;
@@ -43,10 +62,24 @@ namespace CamelotEngine
 
 		static BlendStatePtr create(const BLEND_STATE_DESC& desc);
 
+		/**
+		 * @brief	Returns the default sampler state;
+		 */
+		static const BlendState& getDefault();
+
 	private:
 		friend class RenderStateManager;
 
 		virtual void initialize(const BLEND_STATE_DESC& desc);
 		BLEND_STATE_DESC mData;
+
+		/************************************************************************/
+		/* 								RTTI		                     		*/
+		/************************************************************************/
+
+	public:
+		friend class BlendStateRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const;	
 	};
 }

+ 91 - 0
CamelotRenderer/Include/CmBlendStateRTTI.h

@@ -0,0 +1,91 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmRTTIType.h"
+#include "CmBlendState.h"
+#include "CmRenderStateManager.h"
+
+namespace CamelotEngine
+{
+	template<> struct SerializableSimpleType<BLEND_STATE_DESC>
+	{	
+		enum { id = 21 }; enum { hasDynamicSize = 1 };
+
+		static void toMemory(BLEND_STATE_DESC& data, char* memory)
+		{ 
+			UINT32 size = getDynamicSize(data);
+
+			memcpy(memory, &size, sizeof(UINT32));
+			memory += sizeof(UINT32);
+			memcpy(memory, &data, size); 
+		}
+
+		static void fromMemory(BLEND_STATE_DESC& data, char* memory)
+		{ 
+			UINT32 size;
+			memcpy(&size, memory, sizeof(UINT32)); 
+			memory += sizeof(UINT32);
+
+			size -= sizeof(UINT32);
+			memcpy((void*)&data, memory, size); 
+		}
+
+		static UINT32 getDynamicSize(BLEND_STATE_DESC& data)	
+		{ 
+			UINT64 dataSize = sizeof(data) + sizeof(UINT32);
+
+#if CM_DEBUG_MODE
+			if(dataSize > std::numeric_limits<UINT32>::max())
+			{
+				CM_EXCEPT(InternalErrorException, "Data overflow! Size doesn't fit into 32 bits.");
+			}
+#endif
+
+			return (UINT32)dataSize;
+		}	
+	}; 
+
+	class CM_EXPORT BlendStateRTTI : public RTTIType<BlendState, IReflectable, BlendStateRTTI>
+	{
+	private:
+		BLEND_STATE_DESC& getData(BlendState* obj) { return obj->mData; }
+		void setData(BlendState* obj, BLEND_STATE_DESC& val) 
+		{ 
+			obj->mRTTIData = val;
+		} 
+
+	public:
+		BlendStateRTTI()
+		{
+			addPlainField("mData", 0, &BlendStateRTTI::getData, &BlendStateRTTI::setData);
+		}
+
+		virtual void onDeserializationEnded(IReflectable* obj)
+		{
+			BlendState* blendState = static_cast<BlendState*>(obj);
+			if(!blendState->mRTTIData.empty())
+			{
+				BLEND_STATE_DESC desc = boost::any_cast<BLEND_STATE_DESC>(blendState->mRTTIData);
+
+				blendState->initialize(desc);
+			}
+
+		}
+
+		virtual const String& getRTTIName()
+		{
+			static String name = "BlendState";
+			return name;
+		}
+
+		virtual UINT32 getRTTIId()
+		{
+			return TID_BlendState;
+		}
+
+		virtual std::shared_ptr<IReflectable> newRTTIObject()
+		{
+			return RenderStateManager::instance().createEmptyBlendState();
+		}
+	};
+}

+ 3 - 11
CamelotRenderer/Include/CmDeferredRenderContext.h

@@ -36,16 +36,11 @@ namespace CamelotEngine
 		/** @copydoc RenderSystem::setTexture() */
 		void setTexture(UINT16 unit, bool enabled, const TexturePtr &texPtr);
 
-		/** @copydoc RenderSystem::setTextureUnitSettings() */
+		/** @copydoc RenderSystem::setSamplerState() */
 		void setSamplerState(UINT16 texUnit, const SamplerState& samplerState);
 
-		/** @copydoc RenderSystem::setSceneBlending() */
-		void setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op = SBO_ADD);
-		/** @copydoc RenderSystem::setSeparateSceneBlending() */
-		void setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, 
-			SceneBlendFactor destFactorAlpha, SceneBlendOperation op = SBO_ADD, SceneBlendOperation alphaOp = SBO_ADD);
-		/** @copydoc RenderSystem::setAlphaRejectSettings() */
-		void setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage);
+		/** @copydoc RenderSystem::setBlendState() */
+		void setBlendState(const BlendState& blendState);
 
 		/** @copydoc RenderSystem::setViewport() */
 		void setViewport(const Viewport& vp);
@@ -74,9 +69,6 @@ namespace CamelotEngine
 		/** @copydoc RenderSystem::setDepthBias() */
 		void setDepthBias(float constantBias, float slopeScaleBias = 0.0f);
 
-		/** @copydoc RenderSystem::setColorBufferWriteEnabled() */
-		void setColorBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
-
 		/** @copydoc RenderSystem::setStencilCheckEnabled() */
 		void setStencilCheckEnabled(bool enabled);
 		/** @copydoc RenderSystem::setStencilBufferParams() */

+ 1 - 0
CamelotRenderer/Include/CmDepthStencilState.h

@@ -43,6 +43,7 @@ namespace CamelotEngine
 		CompareFunction backStencilComparisonFunc;
 	};
 
+	// TODO Low priority - Write doc explaining various states
 	class CM_EXPORT DepthStencilState
 	{
 	public:

+ 8 - 217
CamelotRenderer/Include/CmPass.h

@@ -17,24 +17,6 @@ namespace CamelotEngine
 	class CM_EXPORT Pass : public IReflectable
     {
     protected:
-        //-------------------------------------------------------------------------
-        // Blending factors
-        SceneBlendFactor mSourceBlendFactor;
-        SceneBlendFactor mDestBlendFactor;
-		SceneBlendFactor mSourceBlendFactorAlpha;
-		SceneBlendFactor mDestBlendFactorAlpha;
-
-		// Used to determine if separate alpha blending should be used for color and alpha channels
-		bool mSeparateBlend;
-
-		//-------------------------------------------------------------------------
-		// Blending operations
-		SceneBlendOperation mBlendOperation;
-		SceneBlendOperation mAlphaBlendOperation;
-
-		// Determines if we should use separate blending operations for color and alpha channels
-		bool mSeparateBlendOperation;
-
         //-------------------------------------------------------------------------
         // Depth buffer settings
         bool mDepthCheck;
@@ -44,16 +26,6 @@ namespace CamelotEngine
 		float mDepthBiasSlopeScale;
 		float mDepthBiasPerIteration;
 
-        // Colour buffer settings
-        bool mColourWrite;
-
-		// Alpha reject settings
-		CompareFunction mAlphaRejectFunc;
-		unsigned char mAlphaRejectVal;
-		bool mAlphaToCoverageEnabled;
-
-        //-------------------------------------------------------------------------
-
         //-------------------------------------------------------------------------
         // Culling mode
         CullingMode mCullMode;
@@ -63,17 +35,14 @@ namespace CamelotEngine
 		PolygonMode mPolygonMode;
         //-------------------------------------------------------------------------
 
+		BlendStatePtr mBlendState;
+
 		// Vertex program
 		GpuProgramHandle mVertexProgram;
 		// Fragment program
 		GpuProgramHandle mFragmentProgram;
 		// Geometry program
 		GpuProgramHandle mGeometryProgram;
-
-		// point size, applies when not using per-vertex point size
-		float mPointSize;
-		float mPointMinSize;
-		float mPointMaxSize;
     public:
         /// Default constructor
 		Pass();
@@ -90,153 +59,15 @@ namespace CamelotEngine
         /// Returns true if this pass uses a programmable geometry pipeline
         bool hasGeometryProgram(void) const { return mGeometryProgram != nullptr; }
 
-        /** Gets the point size of the pass.
-		@remarks
-			This property determines what point size is used to render a point
-			list.
-        */
-        float getPointSize(void) const;
-
-		/** Sets the point size of this pass.
-		@remarks
-			This setting allows you to change the size of points when rendering
-			a point list, or a list of point sprites. The interpretation of this
-			command depends on the Pass::setPointSizeAttenuation option - if it
-			is off (the default), the point size is in screen pixels, if it is on,
-			it expressed as normalised screen coordinates (1.0 is the height of
-			the screen) when the point is at the origin.
-		@note
-			Some drivers have an upper limit on the size of points they support
-			- this can even vary between APIs on the same card! Don't rely on
-			point sizes that cause the point sprites to get very large on screen,
-			since they may get clamped on some cards. Upper sizes can range from
-			64 to 256 pixels.
-		*/
-		void setPointSize(float ps);
-
-		/** Set the minimum point size, when point attenuation is in use. */
-		void setPointMinSize(float min);
-		/** Get the minimum point size, when point attenuation is in use. */
-		float getPointMinSize(void) const;
-		/** Set the maximum point size, when point attenuation is in use.
-		@remarks Setting this to 0 indicates the max size supported by the card.
-		*/
-		void setPointMaxSize(float max);
-		/** Get the maximum point size, when point attenuation is in use.
-		@remarks 0 indicates the max size supported by the card.
-		*/
-		float getPointMaxSize(void) const;
-
-        /** Allows very fine control of blending this Pass with the existing contents of the scene.
-        @remarks
-        Whereas the texture blending operations seen in the TextureUnitState class are concerned with
-        blending between texture layers, this blending is about combining the output of the material
-        as a whole with the existing contents of the rendering target. This blending therefore allows
-        object transparency and other special effects.
-        @par
-        This version of the method allows complete control over the blending operation, by specifying the
-        source and destination blending factors. The result of the blending operation is:
-        <span align="center">
-        final = (texture * sourceFactor) + (pixel * destFactor)
-        </span>
-        @par
-        Each of the factors is specified as one of a number of options, as specified in the SceneBlendFactor
-        enumerated type.
-        @param
-        sourceFactor The source factor in the above calculation, i.e. multiplied by the texture colour components.
-        @param
-        destFactor The destination factor in the above calculation, i.e. multiplied by the pixel colour components.
-        @note
-        This method is applicable for both the fixed-function and programmable pipelines.
-        */
-        void setSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor);
-
-        /** Allows very fine control of blending this Pass with the existing contents of the scene.
-        @remarks
-        Wheras the texture blending operations seen in the TextureUnitState class are concerned with
-        blending between texture layers, this blending is about combining the output of the material
-        as a whole with the existing contents of the rendering target. This blending therefore allows
-        object transparency and other special effects.
-        @par
-        This version of the method allows complete control over the blending operation, by specifying the
-        source and destination blending factors. The result of the blending operation is:
-        <span align="center">
-        final = (texture * sourceFactor) + (pixel * destFactor)
-        </span>
-        @par
-        Each of the factors is specified as one of a number of options, as specified in the SceneBlendFactor
-        enumerated type.
-        @param
-        sourceFactor The source factor in the above calculation, i.e. multiplied by the texture colour components.
-        @param
-        destFactor The destination factor in the above calculation, i.e. multiplied by the pixel colour components.
-        @param
-        sourceFactorAlpha The alpha source factor in the above calculation, i.e. multiplied by the texture alpha component.
-        @param
-        destFactorAlpha The alpha destination factor in the above calculation, i.e. multiplied by the pixel alpha component.
-		@note
-        This method is applicable for both the fixed-function and programmable pipelines.
-        */
-		void setSeparateSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor, const SceneBlendFactor sourceFactorAlpha, const SceneBlendFactor destFactorAlpha );
-
-		/** Return true if this pass uses separate scene blending */
-		bool hasSeparateSceneBlending() const;
-
-        /** Retrieves the source blending factor for the material (as set using Materiall::setSceneBlending).
-        */
-        SceneBlendFactor getSourceBlendFactor() const;
-
-        /** Retrieves the destination blending factor for the material (as set using Materiall::setSceneBlending).
-        */
-        SceneBlendFactor getDestBlendFactor() const;
-
-	    /** Retrieves the alpha source blending factor for the material (as set using Materiall::setSeparateSceneBlending).
-        */
-		SceneBlendFactor getSourceBlendFactorAlpha() const;
-
-	    /** Retrieves the alpha destination blending factor for the material (as set using Materiall::setSeparateSceneBlending).
-        */
-		SceneBlendFactor getDestBlendFactorAlpha() const;
-
-		/** Sets the specific operation used to blend source and destination pixels together.
-			@remarks 
-			By default this operation is +, which creates this equation
-			<span align="center">
-			final = (texture * sourceFactor) + (pixel * destFactor)
-			</span>
-			By setting this to something other than SBO_ADD you can change the operation to achieve
-			a different effect.
-			@param op The blending operation mode to use for this pass
-		*/
-		void setSceneBlendingOperation(SceneBlendOperation op);
-
-		/** Sets the specific operation used to blend source and destination pixels together.
-			@remarks 
-			By default this operation is +, which creates this equation
-			<span align="center">
-			final = (texture * sourceFactor) + (pixel * destFactor)
-			</span>
-			By setting this to something other than SBO_ADD you can change the operation to achieve
-			a different effect.
-			This function allows more control over blending since it allows you to select different blending
-			modes for the color and alpha channels
-			@param op The blending operation mode to use for color channels in this pass
-			@param op The blending operation mode to use for alpha channels in this pass
-		*/
-		void setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp);
-
-		/** Returns true if this pass uses separate scene blending operations. */
-		bool hasSeparateSceneBlendingOperations() const;
-
-		/** Returns the current blending operation */
-		SceneBlendOperation getSceneBlendingOperation() const;
-
-		/** Returns the current alpha blending operation */
-		SceneBlendOperation getSceneBlendingOperationAlpha() const;
-
 		/** 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.
+		 */
+		void setBlendState(BlendStatePtr blendState);
+		BlendStatePtr getBlendState() const;
+
 		/** Sets whether or not this pass renders with depth-buffer checking on or not.
         @remarks
         If depth-buffer checking is on, whenever a pixel is about to be written to the frame buffer
@@ -368,46 +199,6 @@ namespace CamelotEngine
 		*/
 		float getIterationDepthBias() const;
 
-        /** Sets the way the pass will have use alpha to totally reject pixels from the pipeline.
-        @remarks
-			The default is CMPF_ALWAYS_PASS i.e. alpha is not used to reject pixels.
-        @param func The comparison which must pass for the pixel to be written.
-        @param value 1 byte value against which alpha values will be tested(0-255)
-		@param alphaToCoverageEnabled Whether to enable alpha to coverage support
-        @note
-			This option applies in both the fixed function and the programmable pipeline.
-        */
-        void setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverageEnabled = false);
-
-		/** Sets the alpha reject function. See setAlphaRejectSettings for more information.
-		*/
-		void setAlphaRejectFunction(CompareFunction func);
-
-		/** Gets the alpha reject value. See setAlphaRejectSettings for more information.
-		*/
-		void setAlphaRejectValue(unsigned char val);
-
-		/** Gets the alpha reject function. See setAlphaRejectSettings for more information.
-        */
-		CompareFunction getAlphaRejectFunction(void) const { return mAlphaRejectFunc; }
-
-        /** Gets the alpha reject value. See setAlphaRejectSettings for more information.
-        */
-		unsigned char getAlphaRejectValue(void) const { return mAlphaRejectVal; }
-
-		/** Sets whether to use alpha to coverage (A2C) when blending alpha rejected values. 
-		@remarks
-			Alpha to coverage performs multisampling on the edges of alpha-rejected
-			textures to produce a smoother result. It is only supported when multisampling
-			is already enabled on the render target, and when the hardware supports
-			alpha to coverage (see RenderSystemCapabilities). 
-		*/
-		void setAlphaToCoverageEnabled(bool enabled);
-
-		/** Gets whether to use alpha to coverage (A2C) when blending alpha rejected values. 
-		*/
-		bool isAlphaToCoverageEnabled() const { return mAlphaToCoverageEnabled; }
-
 		/** Sets the details of the vertex program to use.
 		*/
 		void setVertexProgram(GpuProgramHandle gpuProgram);

+ 17 - 76
CamelotRenderer/Include/CmPassRTTI.h

@@ -9,29 +9,8 @@ namespace CamelotEngine
 	class CM_EXPORT PassRTTI : public RTTIType<Pass, IReflectable, PassRTTI>
 	{
 	private:
-		SceneBlendFactor& getSourceBlendFactor(Pass* obj) { return obj->mSourceBlendFactor; }
-		void setSourceBlendFactor(Pass* obj, SceneBlendFactor& val) { obj->mSourceBlendFactor = val; } 
-
-		SceneBlendFactor& getDestBlendFactor(Pass* obj) { return obj->mDestBlendFactor; }
-		void setDestBlendFactor(Pass* obj, SceneBlendFactor& val) { obj->mDestBlendFactor = val; } 
-
-		SceneBlendFactor& getSourceBlendFactorAlpha(Pass* obj) { return obj->mSourceBlendFactorAlpha; }
-		void setSourceBlendFactorAlpha(Pass* obj, SceneBlendFactor& val) { obj->mSourceBlendFactorAlpha = val; } 
-
-		SceneBlendFactor& getDestBlendFactorAlpha(Pass* obj) { return obj->mDestBlendFactorAlpha; }
-		void setDestBlendFactorAlpha(Pass* obj, SceneBlendFactor& val) { obj->mDestBlendFactorAlpha = val; } 
-
-		bool& getSeparateBlend(Pass* obj) { return obj->mSeparateBlend; }
-		void setSeparateBlend(Pass* obj, bool& val) { obj->mSeparateBlend = val; } 
-
-		SceneBlendOperation& getBlendOperation(Pass* obj) { return obj->mBlendOperation; }
-		void setBlendOperation(Pass* obj, SceneBlendOperation& val) { obj->mBlendOperation = val; } 
-
-		SceneBlendOperation& getAlphaBlendOperation(Pass* obj) { return obj->mAlphaBlendOperation; }
-		void setAlphaBlendOperation(Pass* obj, SceneBlendOperation& val) { obj->mAlphaBlendOperation = val; } 
-
-		bool& getSeparateBlendOperation(Pass* obj) { return obj->mSeparateBlendOperation; }
-		void setSeparateBlendOperation(Pass* obj, bool& val) { obj->mSeparateBlendOperation = val; } 
+		BlendStatePtr getBlendState(Pass* obj) { return obj->mBlendState; }
+		void setBlendState(Pass* obj, BlendStatePtr val) { obj->mBlendState = val; } 
 
 		bool& getDepthCheck(Pass* obj) { return obj->mDepthCheck; }
 		void setDepthCheck(Pass* obj, bool& val) { obj->mDepthCheck = val; } 
@@ -51,33 +30,12 @@ namespace CamelotEngine
 		float& getDepthBiasPerIteration(Pass* obj) { return obj->mDepthBiasPerIteration; }
 		void setDepthBiasPerIteration(Pass* obj, float& val) { obj->mDepthBiasPerIteration = val; } 
 
-		bool& getColourWrite(Pass* obj) { return obj->mColourWrite; }
-		void setColourWrite(Pass* obj, bool& val) { obj->mColourWrite = val; } 
-
-		CompareFunction& getAlphaRejectFunc(Pass* obj) { return obj->mAlphaRejectFunc; }
-		void setAlphaRejectFunc(Pass* obj, CompareFunction& val) { obj->mAlphaRejectFunc = val; } 
-
-		UINT8& getAlphaRejectVal(Pass* obj) { return obj->mAlphaRejectVal; }
-		void setAlphaRejectVal(Pass* obj, UINT8& val) { obj->mAlphaRejectVal = val; } 
-
-		bool& getAlphaToCoverageEnabled(Pass* obj) { return obj->mAlphaToCoverageEnabled; }
-		void setAlphaToCoverageEnabled(Pass* obj, bool& val) { obj->mAlphaToCoverageEnabled = val; } 
-
 		CullingMode& getCullMode(Pass* obj) { return obj->mCullMode; }
 		void setCullMode(Pass* obj, CullingMode& val) { obj->mCullMode = val; } 
 
 		PolygonMode& getPolygonMode(Pass* obj) { return obj->mPolygonMode; }
 		void setPolygonMode(Pass* obj, PolygonMode& val) { obj->mPolygonMode = val; } 
 
-		float& getPointSize(Pass* obj) { return obj->mPointSize; }
-		void setPointSize(Pass* obj, float& val) { obj->mPointSize = val; } 
-
-		float& getPointMinSize(Pass* obj) { return obj->mPointMinSize; }
-		void setPointMinSize(Pass* obj, float& val) { obj->mPointMinSize = val; } 
-
-		float& getPointMaxSize(Pass* obj) { return obj->mPointMaxSize; }
-		void setPointMaxSize(Pass* obj, float& val) { obj->mPointMaxSize = val; } 
-
 		GpuProgramHandle& getVertexProgram(Pass* obj) { return obj->mVertexProgram; }
 		void setVertexProgram(Pass* obj, GpuProgramHandle& val) { obj->mVertexProgram = val; } 
 
@@ -89,38 +47,21 @@ namespace CamelotEngine
 	public:
 		PassRTTI()
 		{
-			addPlainField("mSourceBlendFactor", 0, &PassRTTI::getSourceBlendFactor, &PassRTTI::setSourceBlendFactor);
-			addPlainField("mDestBlendFactor", 1, &PassRTTI::getDestBlendFactor, &PassRTTI::setDestBlendFactor);
-			addPlainField("mSourceBlendFactorAlpha", 2, &PassRTTI::getSourceBlendFactorAlpha, &PassRTTI::setSourceBlendFactorAlpha);
-			addPlainField("mDestBlendFactorAlpha", 3, &PassRTTI::getDestBlendFactorAlpha, &PassRTTI::setDestBlendFactorAlpha);
-
-			addPlainField("mSeparateBlend", 4, &PassRTTI::getSeparateBlend, &PassRTTI::setSeparateBlend);
-			addPlainField("mBlendOperation", 5, &PassRTTI::getBlendOperation, &PassRTTI::setBlendOperation);
-			addPlainField("mAlphaBlendOperation", 6, &PassRTTI::getAlphaBlendOperation, &PassRTTI::setAlphaBlendOperation);
-			addPlainField("mSeparateBlendOperation", 7, &PassRTTI::getSeparateBlendOperation, &PassRTTI::setSeparateBlendOperation);
-
-			addPlainField("mDepthCheck", 8, &PassRTTI::getDepthCheck, &PassRTTI::setDepthCheck);
-			addPlainField("mDepthWrite", 9, &PassRTTI::getDepthWrite, &PassRTTI::setDepthWrite);
-			addPlainField("mDepthFunc", 10, &PassRTTI::getCompareFunction, &PassRTTI::setCompareFunction);
-			addPlainField("mDepthBiasConstant", 11, &PassRTTI::getDepthBiasConstant, &PassRTTI::setDepthBiasConstant);
-			addPlainField("mDepthBiasSlopeScale", 12, &PassRTTI::getDepthBiasSlopeScale, &PassRTTI::setDepthBiasSlopeScale);
-			addPlainField("mDepthBiasPerIteration", 13, &PassRTTI::getDepthBiasPerIteration, &PassRTTI::setDepthBiasPerIteration);
-
-			addPlainField("mColourWrite", 14, &PassRTTI::getColourWrite, &PassRTTI::setColourWrite);
-			addPlainField("mAlphaRejectFunc", 15, &PassRTTI::getAlphaRejectFunc, &PassRTTI::setAlphaRejectFunc);
-			addPlainField("mAlphaRejectVal", 16, &PassRTTI::getAlphaRejectVal, &PassRTTI::setAlphaRejectVal);
-			addPlainField("mAlphaToCoverageEnabled", 17, &PassRTTI::getAlphaToCoverageEnabled, &PassRTTI::setAlphaToCoverageEnabled);
-
-			addPlainField("mCullMode", 20, &PassRTTI::getCullMode, &PassRTTI::setCullMode);
-			addPlainField("mPolygonMode", 21, &PassRTTI::getPolygonMode, &PassRTTI::setPolygonMode);
-
-			addPlainField("mPointSize", 23, &PassRTTI::getPointSize, &PassRTTI::setPointSize);
-			addPlainField("mPointMinSize", 24, &PassRTTI::getPointMinSize, &PassRTTI::setPointMinSize);
-			addPlainField("mPointMaxSize", 25, &PassRTTI::getPointMaxSize, &PassRTTI::setPointMaxSize);
-
-			addReflectableField("mVertexProgram", 26, &PassRTTI::getVertexProgram, &PassRTTI::setVertexProgram);
-			addReflectableField("mFragmentProgram", 27, &PassRTTI::getFragmentProgram, &PassRTTI::setFragmentProgram);
-			addReflectableField("mGeometryProgram", 28, &PassRTTI::getGeometryProgram, &PassRTTI::setGeometryProgram);
+			addReflectablePtrField("mBlendState", 0, &PassRTTI::getBlendState, &PassRTTI::setBlendState);
+
+			addPlainField("mDepthCheck", 1, &PassRTTI::getDepthCheck, &PassRTTI::setDepthCheck);
+			addPlainField("mDepthWrite", 2, &PassRTTI::getDepthWrite, &PassRTTI::setDepthWrite);
+			addPlainField("mDepthFunc", 3, &PassRTTI::getCompareFunction, &PassRTTI::setCompareFunction);
+			addPlainField("mDepthBiasConstant", 4, &PassRTTI::getDepthBiasConstant, &PassRTTI::setDepthBiasConstant);
+			addPlainField("mDepthBiasSlopeScale", 5, &PassRTTI::getDepthBiasSlopeScale, &PassRTTI::setDepthBiasSlopeScale);
+			addPlainField("mDepthBiasPerIteration", 6, &PassRTTI::getDepthBiasPerIteration, &PassRTTI::setDepthBiasPerIteration);
+
+			addPlainField("mCullMode", 7, &PassRTTI::getCullMode, &PassRTTI::setCullMode);
+			addPlainField("mPolygonMode", 8, &PassRTTI::getPolygonMode, &PassRTTI::setPolygonMode);
+
+			addReflectableField("mVertexProgram", 9, &PassRTTI::getVertexProgram, &PassRTTI::setVertexProgram);
+			addReflectableField("mFragmentProgram", 10, &PassRTTI::getFragmentProgram, &PassRTTI::setFragmentProgram);
+			addReflectableField("mGeometryProgram", 11, &PassRTTI::getGeometryProgram, &PassRTTI::setGeometryProgram);
 		}
 
 		virtual const String& getRTTIName()

+ 2 - 1
CamelotRenderer/Include/CmPrerequisites.h

@@ -193,7 +193,8 @@ namespace CamelotEngine
 		TID_FloatParamKVP = 1019,
 		TID_MaterialTexParamKVP = 1020,
 		TID_SamplerState = 1021,
-		TID_SamplerStateParamKVP = 1022
+		TID_SamplerStateParamKVP = 1022,
+		TID_BlendState = 1023
 	};
 }
 

+ 1 - 0
CamelotRenderer/Include/CmRasterizerState.h

@@ -32,6 +32,7 @@ namespace CamelotEngine
 		bool antialiasedLineEnable;
 	};
 
+	// TODO Low priority - Write doc explaining various states
 	class CM_EXPORT RasterizerState
 	{
 	public:

+ 5 - 58
CamelotRenderer/Include/CmRenderSystem.h

@@ -366,19 +366,10 @@ namespace CamelotEngine
 		/** Disables all texture units from the given unit upwards */
 		virtual void disableTextureUnitsFrom(UINT16 texUnit);
 
-		/** Sets the size of points and how they are attenuated with distance.
-		@remarks
-		When performing point rendering or point sprite rendering,
-		point size can be attenuated with distance. The equation for
-		doing this is attenuation = 1 / (constant + linear * dist + quadratic * d^2) .
-		@par
-		For example, to disable distance attenuation (constant screensize) 
-		you would set constant to 1, and linear and quadratic to 0. A
-		standard perspective attenuation would be 0, 1, 0 respectively.
-		*/
-		virtual void setPointParameters(float size, bool attenuationEnabled, 
-			float constant, float linear, float quadratic, float minSize, float maxSize) = 0;
-
+		/**
+		 * @brief	Sets a blend state used for all active render targets.
+		 */
+		virtual void setBlendState(const BlendState& blendState) = 0;
 
 		/**
 		Sets the texture to bind to a given texture unit.
@@ -395,41 +386,6 @@ namespace CamelotEngine
 		virtual void setTexture(UINT16 unit, bool enabled, 
 			const TexturePtr &texPtr) = 0;
 
-		/** Sets the global blending factors for combining subsequent renders with the existing frame contents.
-		The result of the blending operation is:</p>
-		<p align="center">final = (texture * sourceFactor) + (pixel * destFactor)</p>
-		Each of the factors is specified as one of a number of options, as specified in the SceneBlendFactor
-		enumerated type.
-		By changing the operation you can change addition between the source and destination pixels to a different operator.
-		@param sourceFactor The source factor in the above calculation, i.e. multiplied by the texture colour components.
-		@param destFactor The destination factor in the above calculation, i.e. multiplied by the pixel colour components.
-		@param op The blend operation mode for combining pixels
-		*/
-		virtual void setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op = SBO_ADD) = 0;
-
-		/** Sets the global blending factors for combining subsequent renders with the existing frame contents.
-		The result of the blending operation is:</p>
-		<p align="center">final = (texture * sourceFactor) + (pixel * destFactor)</p>
-		Each of the factors is specified as one of a number of options, as specified in the SceneBlendFactor
-		enumerated type.
-		@param sourceFactor The source factor in the above calculation, i.e. multiplied by the texture colour components.
-		@param destFactor The destination factor in the above calculation, i.e. multiplied by the pixel colour components.
-		@param sourceFactorAlpha The source factor in the above calculation for the alpha channel, i.e. multiplied by the texture alpha components.
-		@param destFactorAlpha The destination factor in the above calculation for the alpha channel, i.e. multiplied by the pixel alpha components.
-		@param op The blend operation mode for combining pixels
-		@param alphaOp The blend operation mode for combining pixel alpha values
-		*/
-		virtual void setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, 
-			SceneBlendFactor destFactorAlpha, SceneBlendOperation op = SBO_ADD, SceneBlendOperation alphaOp = SBO_ADD) = 0;
-
-		/** Sets the global alpha rejection approach for future renders.
-		By default images are rendered regardless of texture alpha. This method lets you change that.
-		@param func The comparison function which must pass for a pixel to be written.
-		@param val The value to compare each pixels alpha value to (0-255)
-		@param alphaToCoverage Whether to enable alpha to coverage, if supported
-		*/
-		virtual void setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage) = 0;
-
 		/**
 		* Signifies the beginning of a frame, i.e. the start of rendering on a single viewport. Will occur
 		* several times per complete frame if multiple viewports exist.
@@ -502,15 +458,6 @@ namespace CamelotEngine
 		*/
 		virtual void setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL) = 0;
 
-		/** Sets whether or not colour buffer writing is enabled, and for which channels. 
-		@remarks
-		For some advanced effects, you may wish to turn off the writing of certain colour
-		channels, or even all of the colour channels so that only the depth buffer is updated
-		in a rendering pass. However, the chances are that you really want to use this option
-		through the Material class.
-		@param red, green, blue, alpha Whether writing is enabled for each of the 4 colour channels. */
-		virtual void setColorBufferWriteEnabled(bool red, bool green, bool blue, bool alpha) = 0;
-
 		/** Sets the depth bias, NB you should use the Material version of this. 
 		@remarks
 		When polygons are coplanar, you can get problems with 'depth fighting' where
@@ -656,7 +603,7 @@ namespace CamelotEngine
 
 		/** Sets whether or not vertex windings set should be inverted; this can be important
 		for rendering reflections. */
-		virtual void setInvertVertexWinding_(bool invert);
+		virtual void setInvertVertexWinding(bool invert);
 
 		/** Indicates whether or not the vertex windings set will be inverted for the current render (e.g. reflections)
 		@see RenderSystem::setInvertVertexWinding

+ 6 - 2
CamelotRenderer/Include/CmSamplerState.h

@@ -39,6 +39,7 @@ namespace CamelotEngine
 		CompareFunction comparisonFunc;
 	};
 
+	// TODO Low priority - Write doc explaining various states
 	/**
 	* @brief	Class representing the state of a single sampler unit during a Pass of a Technique, of a Material.
 	*	
@@ -54,8 +55,6 @@ namespace CamelotEngine
     public:
 		virtual ~SamplerState() {}
 
-		static SamplerState DEFAULT;
-
         /** Gets the texture addressing mode for a given coordinate, 
 		 	i.e. what happens at uv values above 1.0.
         @note
@@ -96,6 +95,11 @@ namespace CamelotEngine
 
 		static SamplerStatePtr create(const SAMPLER_STATE_DESC& desc);
 
+		/**
+		 * @brief	Returns the default sampler state;
+		 */
+		static const SamplerState& getDefault();
+
 	private:
 		friend class RenderStateManager;
 

+ 30 - 1
CamelotRenderer/Source/CmBlendState.cpp

@@ -1,5 +1,6 @@
 #include "CmBlendState.h"
 #include "CmRenderStateManager.h"
+#include "CmBlendStateRTTI.h"
 
 namespace CamelotEngine
 {
@@ -8,7 +9,21 @@ namespace CamelotEngine
 		mData = desc;
 	}
 
-	bool BlendState::getBlendEnable(UINT32 renderTargetIdx) const
+	const BlendState& BlendState::getDefault()
+	{
+		static BlendState blendState;
+		static bool initialized = false;
+
+		if(!initialized)
+		{
+			blendState.initialize(BLEND_STATE_DESC());
+			initialized = true;
+		}
+
+		return blendState;
+	}
+
+	bool BlendState::getBlendEnabled(UINT32 renderTargetIdx) const
 	{
 		assert(renderTargetIdx >= 0 && renderTargetIdx < CM_MAX_MULTIPLE_RENDER_TARGETS);
 
@@ -68,4 +83,18 @@ namespace CamelotEngine
 	{
 		return RenderStateManager::instance().createBlendState(desc);
 	}
+
+	/************************************************************************/
+	/* 								RTTI		                     		*/
+	/************************************************************************/
+
+	RTTITypeBase* BlendState::getRTTIStatic()
+	{
+		return BlendStateRTTI::instance();
+	}
+
+	RTTITypeBase* BlendState::getRTTI() const
+	{
+		return BlendState::getRTTIStatic();
+	}
 }

+ 7 - 28
CamelotRenderer/Source/CmDeferredRenderContext.cpp

@@ -2,6 +2,7 @@
 #include "CmCommandQueue.h"
 #include "CmRenderSystemManager.h"
 #include "CmRenderSystem.h"
+#include "CmBlendState.h"
 
 namespace CamelotEngine
 {
@@ -35,6 +36,11 @@ namespace CamelotEngine
 		mCommandQueue->queue(boost::bind(&RenderSystem::setSamplerState, mRenderSystem, texUnit, samplerState));
 	}
 
+	void DeferredRenderContext::setBlendState(const BlendState& blendState)
+	{
+		mCommandQueue->queue(boost::bind(&RenderSystem::setBlendState, mRenderSystem, blendState));
+	}
+
 	void DeferredRenderContext::setTexture(UINT16 unit, bool enabled, const TexturePtr &texPtr)
 	{
 		mCommandQueue->queue(boost::bind(&RenderSystem::setTexture, mRenderSystem, unit, enabled, texPtr));
@@ -50,28 +56,6 @@ namespace CamelotEngine
 		mCommandQueue->queue(boost::bind(&RenderSystem::disableTextureUnitsFrom, mRenderSystem, texUnit));
 	}
 
-	void DeferredRenderContext::setPointParameters(float size, bool attenuationEnabled, 
-		float constant, float linear, float quadratic, float minSize, float maxSize)
-	{
-		mCommandQueue->queue(boost::bind(&RenderSystem::setPointParameters, mRenderSystem, size, attenuationEnabled, constant, linear, quadratic, minSize, maxSize));
-	}
-
-	void DeferredRenderContext::setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op)
-	{
-		mCommandQueue->queue(boost::bind(&RenderSystem::setSceneBlending, mRenderSystem, sourceFactor, destFactor, op));
-	}
-
-	void DeferredRenderContext::setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, 
-		SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp)
-	{
-		mCommandQueue->queue(boost::bind(&RenderSystem::setSeparateSceneBlending, mRenderSystem, sourceFactor, destFactor, sourceFactorAlpha, destFactorAlpha, op, alphaOp));
-	}
-
-	void DeferredRenderContext::setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage)
-	{
-		mCommandQueue->queue(boost::bind(&RenderSystem::setAlphaRejectSettings, mRenderSystem, func, value, alphaToCoverage));
-	}
-
 	void DeferredRenderContext::setScissorTest(bool enabled, UINT32 left, UINT32 top, UINT32 right, UINT32 bottom)
 	{
 		mCommandQueue->queue(boost::bind(&RenderSystem::setScissorTest, mRenderSystem, enabled, left, top, right, bottom));
@@ -91,7 +75,7 @@ namespace CamelotEngine
 	void DeferredRenderContext::setInvertVertexWinding(bool invert)
 	{
 		mInvertVertexWinding = invert;
-		mCommandQueue->queue(boost::bind(&RenderSystem::setInvertVertexWinding_, mRenderSystem, invert));
+		mCommandQueue->queue(boost::bind(&RenderSystem::setInvertVertexWinding, mRenderSystem, invert));
 	}
 
 	bool DeferredRenderContext::getInvertVertexWinding(void) const
@@ -119,11 +103,6 @@ namespace CamelotEngine
 		mCommandQueue->queue(boost::bind(&RenderSystem::setDepthBufferFunction, mRenderSystem, func));
 	}
 
-	void DeferredRenderContext::setColorBufferWriteEnabled(bool red, bool green, bool blue, bool alpha)
-	{
-		mCommandQueue->queue(boost::bind(&RenderSystem::setColorBufferWriteEnabled, mRenderSystem, red, green, blue, alpha));
-	}
-
 	void DeferredRenderContext::setDepthBias(float constantBias, float slopeScaleBias)
 	{
 		mCommandQueue->queue(boost::bind(&RenderSystem::setDepthBias, mRenderSystem, constantBias, slopeScaleBias));

+ 27 - 173
CamelotRenderer/Source/CmPass.cpp

@@ -1,34 +1,20 @@
 #include "CmPass.h"
 #include "CmPassRTTI.h"
 #include "CmException.h"
+#include "CmBlendState.h"
 
 namespace CamelotEngine
 {
     //-----------------------------------------------------------------------------
 	Pass::Pass()
-		: mSourceBlendFactor(SBF_ONE)
-		, mDestBlendFactor(SBF_ZERO)
-		, mSourceBlendFactorAlpha(SBF_ONE)
-		, mDestBlendFactorAlpha(SBF_ZERO)
-		, mSeparateBlend(false)
-		, mBlendOperation(SBO_ADD)
-		, mAlphaBlendOperation(SBO_ADD)
-		, mSeparateBlendOperation(false)
-		, mDepthCheck(true)
+		: mDepthCheck(true)
 		, mDepthWrite(true)
 		, mDepthFunc(CMPF_LESS_EQUAL)
 		, mDepthBiasConstant(0.0f)
 		, mDepthBiasSlopeScale(0.0f)
 		, mDepthBiasPerIteration(0.0f)
-		, mColourWrite(true)
-		, mAlphaRejectFunc(CMPF_ALWAYS_PASS)
-		, mAlphaRejectVal(0)
-		, mAlphaToCoverageEnabled(false)
 		, mCullMode(CULL_CLOCKWISE)
 		, mPolygonMode(PM_SOLID)
-		, mPointSize(1.0f)
-		, mPointMinSize(0.0f)
-		, mPointMaxSize(0.0f)	
     {
 
    }
@@ -47,31 +33,16 @@ namespace CamelotEngine
     Pass& Pass::operator=(const Pass& oth)
     {
 	    // Default blending (overwrite)
-	    mSourceBlendFactor = oth.mSourceBlendFactor;
-	    mDestBlendFactor = oth.mDestBlendFactor;
-		mSourceBlendFactorAlpha = oth.mSourceBlendFactorAlpha;
-		mDestBlendFactorAlpha = oth.mDestBlendFactorAlpha;
-		mSeparateBlend = oth.mSeparateBlend;
-
-		mBlendOperation = oth.mBlendOperation;
-		mAlphaBlendOperation = oth.mAlphaBlendOperation;
-		mSeparateBlendOperation = oth.mSeparateBlendOperation;
+	    mBlendState = oth.mBlendState;
 
 	    mDepthCheck = oth.mDepthCheck;
 	    mDepthWrite = oth.mDepthWrite;
-		mAlphaRejectFunc = oth.mAlphaRejectFunc;
-		mAlphaRejectVal = oth.mAlphaRejectVal;
-		mAlphaToCoverageEnabled = oth.mAlphaToCoverageEnabled;
-        mColourWrite = oth.mColourWrite;
 	    mDepthFunc = oth.mDepthFunc;
         mDepthBiasConstant = oth.mDepthBiasConstant;
 		mDepthBiasSlopeScale = oth.mDepthBiasSlopeScale;
 		mDepthBiasPerIteration = oth.mDepthBiasPerIteration;
 	    mCullMode = oth.mCullMode;
 		mPolygonMode = oth.mPolygonMode;
-		mPointSize = oth.mPointSize;
-		mPointMinSize = oth.mPointMinSize;
-		mPointMaxSize = oth.mPointMaxSize;
 
 		mVertexProgram = oth.mVertexProgram;
 		mFragmentProgram = oth.mFragmentProgram;
@@ -80,124 +51,39 @@ namespace CamelotEngine
 		return *this;
     }
     //-----------------------------------------------------------------------
-    void Pass::setPointSize(float ps)
-    {
-	    mPointSize = ps;
-    }
-    //-----------------------------------------------------------------------
-	void Pass::setPointMinSize(float min)
-	{
-		mPointMinSize = min;
-	}
-    //-----------------------------------------------------------------------
-	float Pass::getPointMinSize(void) const
-	{
-		return mPointMinSize;
-	}
-    //-----------------------------------------------------------------------
-	void Pass::setPointMaxSize(float max)
-	{
-		mPointMaxSize = max;
-	}
-    //-----------------------------------------------------------------------
-	float Pass::getPointMaxSize(void) const
-	{
-		return mPointMaxSize;
-	}
-    //-----------------------------------------------------------------------
-    float Pass::getPointSize(void) const
-    {
-	    return mPointSize;
-    }
-    //-----------------------------------------------------------------------
-    void Pass::setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor)
+    bool Pass::isTransparent(void) const
     {
-	    mSourceBlendFactor = sourceFactor;
-	    mDestBlendFactor = destFactor;
+		bool transparent = false;
 
-		mSeparateBlend = false;
-    }
-	//-----------------------------------------------------------------------
-	void Pass::setSeparateSceneBlending( const SceneBlendFactor sourceFactor, const SceneBlendFactor destFactor, const SceneBlendFactor sourceFactorAlpha, const SceneBlendFactor destFactorAlpha )
-	{
-		mSourceBlendFactor = sourceFactor;
-		mDestBlendFactor = destFactor;
-		mSourceBlendFactorAlpha = sourceFactorAlpha;
-		mDestBlendFactorAlpha = destFactorAlpha;
+		if(mBlendState != nullptr)
+		{
+			for(UINT32 i = 0; i < CM_MAX_MULTIPLE_RENDER_TARGETS; i++)
+			{
+				// Transparent if destination color is taken into account
+				if (mBlendState->getDstBlend(i) != SBF_ZERO ||
+					mBlendState->getSrcBlend(i) == SBF_DEST_COLOUR ||
+					mBlendState->getSrcBlend(i) == SBF_ONE_MINUS_DEST_COLOUR ||
+					mBlendState->getSrcBlend(i) == SBF_DEST_ALPHA ||
+					mBlendState->getSrcBlend(i) == SBF_ONE_MINUS_DEST_ALPHA)
+				{
+					transparent = true;
+				}
+			}
+		}
 
-		mSeparateBlend = true;
-	}
-    //-----------------------------------------------------------------------
-    SceneBlendFactor Pass::getSourceBlendFactor(void) const
-    {
-	    return mSourceBlendFactor;
-    }
-    //-----------------------------------------------------------------------
-    SceneBlendFactor Pass::getDestBlendFactor(void) const
-    {
-	    return mDestBlendFactor;
-    }
-    //-----------------------------------------------------------------------
-    SceneBlendFactor Pass::getSourceBlendFactorAlpha(void) const
-    {
-	    return mSourceBlendFactorAlpha;
-    }
-    //-----------------------------------------------------------------------
-    SceneBlendFactor Pass::getDestBlendFactorAlpha(void) const
-    {
-	    return mDestBlendFactorAlpha;
+		return transparent;
     }
-	//-----------------------------------------------------------------------
-	bool Pass::hasSeparateSceneBlending() const
-	{
-		return mSeparateBlend;
-	}
-	//-----------------------------------------------------------------------
-	void Pass::setSceneBlendingOperation(SceneBlendOperation op)
-	{
-		mBlendOperation = op;
-		mSeparateBlendOperation = false;
-	}
-	//-----------------------------------------------------------------------
-	void Pass::setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp)
-	{
-		mBlendOperation = op;
-		mAlphaBlendOperation = alphaOp;
-		mSeparateBlendOperation = true;
-	}
-	//-----------------------------------------------------------------------
-	SceneBlendOperation Pass::getSceneBlendingOperation() const
-	{
-		return mBlendOperation;
-	}
-	//-----------------------------------------------------------------------
-	SceneBlendOperation Pass::getSceneBlendingOperationAlpha() const
+	//----------------------------------------------------------------------
+	void Pass::setBlendState(BlendStatePtr blendState)
 	{
-		return mAlphaBlendOperation;
+		mBlendState = blendState;
 	}
-	//-----------------------------------------------------------------------
-	bool Pass::hasSeparateSceneBlendingOperations() const
+	//----------------------------------------------------------------------
+	BlendStatePtr Pass::getBlendState() const
 	{
-		return mSeparateBlendOperation;
+		return mBlendState;
 	}
     //-----------------------------------------------------------------------
-    bool Pass::isTransparent(void) const
-    {
-		// Transparent if any of the destination colour is taken into account
-		if (mDestBlendFactor == SBF_ZERO &&
-			mSourceBlendFactor != SBF_DEST_COLOUR &&
-			mSourceBlendFactor != SBF_ONE_MINUS_DEST_COLOUR &&
-			mSourceBlendFactor != SBF_DEST_ALPHA &&
-			mSourceBlendFactor != SBF_ONE_MINUS_DEST_ALPHA)
-		{
-		    return false;
-		}
-	    else
-		{
-		    return true;
-		}
-    }
-    //-----------------------------------------------------------------------
     void Pass::setDepthCheckEnabled(bool enabled)
     {
 	    mDepthCheck = enabled;
@@ -227,38 +113,6 @@ namespace CamelotEngine
     {
 	    return mDepthFunc;
     }
-	//-----------------------------------------------------------------------
-	void Pass::setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage)
-	{
-		mAlphaRejectFunc = func;
-		mAlphaRejectVal = value;
-		mAlphaToCoverageEnabled = alphaToCoverage;
-	}
-	//-----------------------------------------------------------------------
-	void Pass::setAlphaRejectFunction(CompareFunction func)
-	{
-		mAlphaRejectFunc = func;
-	}
-	//-----------------------------------------------------------------------
-	void Pass::setAlphaRejectValue(unsigned char val)
-	{
-		mAlphaRejectVal = val;
-	}
-	//---------------------------------------------------------------------
-	void Pass::setAlphaToCoverageEnabled(bool enabled)
-	{
-		mAlphaToCoverageEnabled = enabled;
-	}
-    //-----------------------------------------------------------------------
-	void Pass::setColourWriteEnabled(bool enabled)
-	{
-		mColourWrite = enabled;
-	}
-    //-----------------------------------------------------------------------
-	bool Pass::getColourWriteEnabled(void) const
-	{
-		return mColourWrite;
-	}
     //-----------------------------------------------------------------------
     void Pass::setCullingMode( CullingMode mode)
     {

+ 1 - 1
CamelotRenderer/Source/CmRenderSystem.cpp

@@ -280,7 +280,7 @@ namespace CamelotEngine {
 		mVsync = enabled;
 	}
 	//-----------------------------------------------------------------------
-	void RenderSystem::setInvertVertexWinding_(bool invert)
+	void RenderSystem::setInvertVertexWinding(bool invert)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 

+ 14 - 2
CamelotRenderer/Source/CmSamplerState.cpp

@@ -5,13 +5,25 @@
 
 namespace CamelotEngine 
 {
-	SamplerState SamplerState::DEFAULT;
-
 	void SamplerState::initialize(const SAMPLER_STATE_DESC& desc)
 	{
 		mData = desc;
 	}
 
+	const SamplerState& SamplerState::getDefault()
+	{
+		static SamplerState samplerState;
+		static bool initialized = false;
+
+		if(!initialized)
+		{
+			samplerState.initialize(SAMPLER_STATE_DESC());
+			initialized = true;
+		}
+
+		return samplerState;
+	}
+
 	FilterOptions SamplerState::getTextureFiltering(FilterType ft) const
 	{
         switch (ft)