Browse Source

Added D3D11 render states

Marko Pintera 13 years ago
parent
commit
6c2fc529be

+ 11 - 0
CamelotD3D11RenderSystem/CamelotD3D11RenderSystem.vcxproj

@@ -146,7 +146,9 @@
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClInclude Include="Include\CmD3D11BlendState.h" />
     <ClInclude Include="Include\CmD3D11DepthStencilBuffer.h" />
+    <ClInclude Include="Include\CmD3D11DepthStencilState.h" />
     <ClInclude Include="Include\CmD3D11HardwareBufferManager.h" />
     <ClInclude Include="Include\CmD3D11HardwareConstantBuffer.h" />
     <ClInclude Include="Include\CmD3D11Device.h" />
@@ -158,13 +160,17 @@
     <ClInclude Include="Include\CmD3D11HLSLProgram.h" />
     <ClInclude Include="Include\CmD3D11HardwareIndexBuffer.h" />
     <ClInclude Include="Include\CmD3D11HLSLProgramFactory.h" />
+    <ClInclude Include="Include\CmD3D11HLSLProgramRTTI.h" />
     <ClInclude Include="Include\CmD3D11Mappings.h" />
     <ClInclude Include="Include\CmD3D11Prerequisites.h" />
     <ClInclude Include="Include\CmD3D11HardwareVertexBuffer.h" />
+    <ClInclude Include="Include\CmD3D11RasterizerState.h" />
+    <ClInclude Include="Include\CmD3D11RenderStateManager.h" />
     <ClInclude Include="Include\CmD3D11RenderSystem.h" />
     <ClInclude Include="Include\CmD3D11RenderSystemFactory.h" />
     <ClInclude Include="Include\CmD3D11RenderTexture.h" />
     <ClInclude Include="Include\CmD3D11RenderWindow.h" />
+    <ClInclude Include="Include\CmD3D11SamplerState.h" />
     <ClInclude Include="Include\CmD3D11Texture.h" />
     <ClInclude Include="Include\CmD3D11TextureManager.h" />
     <ClInclude Include="Include\CmD3D11VertexDeclaration.h" />
@@ -172,7 +178,9 @@
     <ClInclude Include="Include\CmD3D11VideoModeList.h" />
   </ItemGroup>
   <ItemGroup>
+    <ClCompile Include="Source\CmD3D11BlendState.cpp" />
     <ClCompile Include="Source\CmD3D11DepthStencilBuffer.cpp" />
+    <ClCompile Include="Source\CmD3D11DepthStencilState.cpp" />
     <ClCompile Include="Source\CmD3D11Device.cpp" />
     <ClCompile Include="Source\CmD3D11Driver.cpp" />
     <ClCompile Include="Source\CmD3D11DriverList.cpp" />
@@ -186,10 +194,13 @@
     <ClCompile Include="Source\CmD3D11HLSLProgramFactory.cpp" />
     <ClCompile Include="Source\CmD3D11Mappings.cpp" />
     <ClCompile Include="Source\CmD3D11HardwareVertexBuffer.cpp" />
+    <ClCompile Include="Source\CmD3D11RasterizerState.cpp" />
+    <ClCompile Include="Source\CmD3D11RenderStateManager.cpp" />
     <ClCompile Include="Source\CmD3D11RenderSystem.cpp" />
     <ClCompile Include="Source\CmD3D11RenderSystemFactory.cpp" />
     <ClCompile Include="Source\CmD3D11RenderTexture.cpp" />
     <ClCompile Include="Source\CmD3D11RenderWindow.cpp" />
+    <ClCompile Include="Source\CmD3D11SamplerState.cpp" />
     <ClCompile Include="Source\CmD3D11Texture.cpp" />
     <ClCompile Include="Source\CmD3D11TextureManager.cpp" />
     <ClCompile Include="Source\CmD3D11VertexDeclaration.cpp" />

+ 36 - 0
CamelotD3D11RenderSystem/CamelotD3D11RenderSystem.vcxproj.filters

@@ -13,6 +13,9 @@
       <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
       <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
     </Filter>
+    <Filter Include="Header Files\RTTI">
+      <UniqueIdentifier>{13c33212-5974-4214-8658-e58e12142f4b}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Include\CmD3D11Prerequisites.h">
@@ -87,6 +90,24 @@
     <ClInclude Include="Include\CmD3D11RenderSystemFactory.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\CmD3D11HLSLProgramRTTI.h">
+      <Filter>Header Files\RTTI</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\CmD3D11RenderStateManager.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\CmD3D11SamplerState.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\CmD3D11DepthStencilState.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\CmD3D11RasterizerState.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\CmD3D11BlendState.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CmD3D11GpuProgram.cpp">
@@ -158,5 +179,20 @@
     <ClCompile Include="Source\CmD3D11RenderSystemFactory.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Source\CmD3D11RenderStateManager.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\CmD3D11SamplerState.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\CmD3D11BlendState.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\CmD3D11RasterizerState.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\CmD3D11DepthStencilState.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 24 - 0
CamelotD3D11RenderSystem/Include/CmD3D11BlendState.h

@@ -0,0 +1,24 @@
+#pragma once
+
+#include "CmD3D11Prerequisites.h"
+#include "CmBlendState.h"
+
+namespace CamelotEngine
+{
+	class CM_D3D11_EXPORT D3D11BlendState : public BlendState
+	{
+	public:
+		~D3D11BlendState();
+
+		ID3D11BlendState* getInternal() const { return mBlendState; }
+
+	protected:
+		friend class D3D11RenderStateManager;
+
+		D3D11BlendState();
+
+		void initialize(const BLEND_STATE_DESC& desc);
+
+		ID3D11BlendState* mBlendState;
+	};
+}

+ 24 - 0
CamelotD3D11RenderSystem/Include/CmD3D11DepthStencilState.h

@@ -0,0 +1,24 @@
+#pragma once
+
+#include "CmD3D11Prerequisites.h"
+#include "CmDepthStencilState.h"
+
+namespace CamelotEngine
+{
+	class CM_D3D11_EXPORT D3D11DepthStencilState : public DepthStencilState
+	{
+	public:
+		~D3D11DepthStencilState();
+
+		ID3D11DepthStencilState* getInternal() const { return mDepthStencilState; }
+
+	protected:
+		friend class D3D11RenderStateManager;
+
+		D3D11DepthStencilState();
+
+		void initialize(const DEPTH_STENCIL_STATE_DESC& desc);
+
+		ID3D11DepthStencilState* mDepthStencilState;
+	};
+}

+ 8 - 0
CamelotD3D11RenderSystem/Include/CmD3D11HLSLProgram.h

@@ -93,5 +93,13 @@ namespace CamelotEngine
 		 * @brief	Creates constant buffers based on available parameter and constant data.
 		 */
 		void createConstantBuffers();
+
+		/************************************************************************/
+		/* 								SERIALIZATION                      		*/
+		/************************************************************************/
+	public:
+		friend class D3D11HLSLProgramRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const;
 	};
 }

+ 33 - 0
CamelotD3D11RenderSystem/Include/CmD3D11HLSLProgramRTTI.h

@@ -0,0 +1,33 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmRTTIType.h"
+#include "CmHighLevelGpuProgramManager.h"
+#include "CmHighLevelGpuProgram.h"
+#include "CmD3D11HLSLProgram.h"
+
+namespace CamelotEngine
+{
+	class CM_D3D11_EXPORT D3D11HLSLProgramRTTI : public RTTIType<D3D11HLSLProgram, HighLevelGpuProgram, D3D11HLSLProgramRTTI>
+	{
+	public:
+		D3D11HLSLProgramRTTI()
+		{ }
+
+		virtual const String& getRTTIName()
+		{
+			static String name = "D3D11HLSLProgram";
+			return name;
+		}
+
+		virtual UINT32 getRTTIId()
+		{
+			return TID_D3D11_HLSLProgram;
+		}
+
+		virtual std::shared_ptr<IReflectable> newRTTIObject()
+		{
+			return HighLevelGpuProgramManager::instance().createEmpty("hlsl");
+		}
+	};
+}

+ 8 - 0
CamelotD3D11RenderSystem/Include/CmD3D11Prerequisites.h

@@ -49,6 +49,10 @@ namespace CamelotEngine
 	class D3D11GpuGeometryProgram;
 	class D3D11GpuHullProgram;
 	class D3D11GpuDomainProgram;
+	class D3D11BlendState;
+	class D3D11RasterizerState;
+	class D3D11SamplerState;
+	class D3D11DepthStencilState;
 
 	enum TypeID_D3D11
 	{
@@ -62,6 +66,10 @@ namespace CamelotEngine
 	typedef std::shared_ptr<D3D11GpuGeometryProgram> D3D11GpuGeometryProgramPtr;
 	typedef std::shared_ptr<D3D11GpuHullProgram> D3D11GpuHullProgramPtr;
 	typedef std::shared_ptr<D3D11GpuDomainProgram> D3D11GpuDomainProgramPtr;
+	typedef std::shared_ptr<D3D11BlendState> D3D11BlendStatePtr;
+	typedef std::shared_ptr<D3D11RasterizerState> D3D11RasterizerStatePtr;
+	typedef std::shared_ptr<D3D11SamplerState> D3D11SamplerStatePtr;
+	typedef std::shared_ptr<D3D11DepthStencilState> D3D11DepthStencilStatePtr;
 
 // Should we ask D3D to manage vertex/index buffers automatically?
 // Doing so avoids lost devices, but also has a performance impact

+ 23 - 0
CamelotD3D11RenderSystem/Include/CmD3D11RasterizerState.h

@@ -0,0 +1,23 @@
+#pragma once
+
+#include "CmD3D11Prerequisites.h"
+#include "CmRasterizerState.h"
+
+namespace CamelotEngine
+{
+	class CM_D3D11_EXPORT D3D11RasterizerState : public RasterizerState
+	{
+	public:
+		~D3D11RasterizerState();
+		ID3D11RasterizerState* getInternal() const { return mRasterizerState; }
+
+	protected:
+		friend class D3D11RenderStateManager;
+
+		D3D11RasterizerState();
+
+		void initialize(const RASTERIZER_STATE_DESC& desc);
+
+		ID3D11RasterizerState* mRasterizerState;
+	};
+}

+ 51 - 0
CamelotD3D11RenderSystem/Include/CmD3D11RenderStateManager.h

@@ -0,0 +1,51 @@
+#pragma once
+
+#include "CmD3D11Prerequisites.h"
+#include "CmRenderStateManager.h"
+
+namespace CamelotEngine
+{
+	class CM_D3D11_EXPORT D3D11RenderStateManager : public RenderStateManager
+	{
+	public:
+		/**
+		 * @copydoc RenderStateManager::createSamplerState()
+		 */
+		SamplerStatePtr createSamplerState(const SAMPLER_STATE_DESC& desc) const;
+
+		/**
+		 * @copydoc RenderStateManager::createDepthStencilState()
+		 */
+		DepthStencilStatePtr createDepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc) const;
+
+		/**
+		 * @copydoc RenderStateManager::createRasterizerState()
+		 */
+		RasterizerStatePtr createRasterizerState(const RASTERIZER_STATE_DESC& desc) const;
+
+		/**
+		 * @copydoc RenderStateManager::createBlendState()
+		 */
+		BlendStatePtr createBlendState(const BLEND_STATE_DESC& desc) const;
+
+		/**
+		 * @copydoc RenderStateManager::createEmptySamplerState()
+		 */
+		SamplerStatePtr createEmptySamplerState() const;
+
+		/**
+		 * @copydoc RenderStateManager::createEmptyDepthStencilState()
+		 */
+		DepthStencilStatePtr createEmptyDepthStencilState() const;
+
+		/**
+		 * @copydoc RenderStateManager::createEmptyRasterizerState()
+		 */
+		RasterizerStatePtr createEmptyRasterizerState() const;
+
+		/**
+		 * @copydoc RenderStateManager::createEmptyBlendState()
+		 */
+		BlendStatePtr createEmptyBlendState() const;
+	};
+}

+ 23 - 0
CamelotD3D11RenderSystem/Include/CmD3D11SamplerState.h

@@ -0,0 +1,23 @@
+#pragma once
+
+#include "CmD3D11Prerequisites.h"
+#include "CmSamplerState.h"
+
+namespace CamelotEngine
+{
+	class CM_D3D11_EXPORT D3D11SamplerState : public SamplerState
+	{
+	public:
+		~D3D11SamplerState();
+		ID3D11SamplerState* getInternal() const { return mSamplerState; }
+
+	protected:
+		friend class D3D11RenderStateManager;
+
+		D3D11SamplerState();
+
+		void initialize(const SAMPLER_STATE_DESC& desc);
+
+		ID3D11SamplerState* mSamplerState;
+	};
+}

+ 40 - 0
CamelotD3D11RenderSystem/Source/CmD3D11BlendState.cpp

@@ -0,0 +1,40 @@
+#include "CmD3D11BlendState.h"
+#include "CmD3D11Mappings.h"
+#include "CmD3D11RenderSystem.h"
+#include "CmD3D11Device.h"
+
+namespace CamelotEngine
+{
+	D3D11BlendState::D3D11BlendState()
+		:mBlendState(nullptr)
+	{ }
+
+	D3D11BlendState::~D3D11BlendState()
+	{
+		SAFE_RELEASE(mBlendState);
+	}
+
+	void D3D11BlendState::initialize(const BLEND_STATE_DESC& desc)
+	{
+		D3D11_BLEND_DESC blendStateDesc;
+		ZeroMemory(&blendStateDesc, sizeof(D3D11_BLEND_DESC));
+
+		blendStateDesc.AlphaToCoverageEnable = desc.alphaToCoverageEnable;
+		blendStateDesc.IndependentBlendEnable = desc.independantBlendEnable;
+		
+		for(UINT32 i = 0; i < CM_MAX_MULTIPLE_RENDER_TARGETS; i++)
+		{
+			blendStateDesc.RenderTarget[i].BlendEnable = desc.renderTargetDesc[i].blendEnable;
+			blendStateDesc.RenderTarget[i].BlendOp = D3D11Mappings::get(desc.renderTargetDesc[i].blendOp);
+			blendStateDesc.RenderTarget[i].BlendOpAlpha = D3D11Mappings::get(desc.renderTargetDesc[i].blendOpAlpha);
+			blendStateDesc.RenderTarget[i].DestBlend = D3D11Mappings::get(desc.renderTargetDesc[i].dstBlend);
+			blendStateDesc.RenderTarget[i].DestBlendAlpha = D3D11Mappings::get(desc.renderTargetDesc[i].dstBlendAlpha);
+			blendStateDesc.RenderTarget[i].RenderTargetWriteMask = desc.renderTargetDesc[i].renderTargetWriteMask;
+			blendStateDesc.RenderTarget[i].SrcBlend = D3D11Mappings::get(desc.renderTargetDesc[i].srcBlend);
+			blendStateDesc.RenderTarget[i].SrcBlendAlpha = D3D11Mappings::get(desc.renderTargetDesc[i].srcBlendAlpha);
+		}
+
+		D3D11Device& device = D3D11RenderSystem::getPrimaryDevice();
+		device.getD3D11Device()->CreateBlendState(&blendStateDesc, &mBlendState);
+	}
+}

+ 40 - 0
CamelotD3D11RenderSystem/Source/CmD3D11DepthStencilState.cpp

@@ -0,0 +1,40 @@
+#include "CmD3D11DepthStencilState.h"
+#include "CmD3D11Device.h"
+#include "CmD3D11RenderSystem.h"
+#include "CmD3D11Mappings.h"
+
+namespace CamelotEngine
+{
+	D3D11DepthStencilState::D3D11DepthStencilState()
+		:mDepthStencilState(nullptr)
+	{ }
+
+	D3D11DepthStencilState::~D3D11DepthStencilState()
+	{
+		SAFE_RELEASE(mDepthStencilState);
+	}
+
+	void D3D11DepthStencilState::initialize(const DEPTH_STENCIL_STATE_DESC& desc)
+	{
+		D3D11_DEPTH_STENCIL_DESC depthStencilState;
+		ZeroMemory(&depthStencilState, sizeof(D3D11_DEPTH_STENCIL_DESC));
+
+		depthStencilState.BackFace.StencilPassOp = D3D11Mappings::get(desc.backStencilPassOp);
+		depthStencilState.BackFace.StencilFailOp = D3D11Mappings::get(desc.backStencilFailOp);
+		depthStencilState.BackFace.StencilDepthFailOp = D3D11Mappings::get(desc.backStencilZFailOp);
+		depthStencilState.BackFace.StencilFunc = D3D11Mappings::get(desc.backStencilComparisonFunc);
+		depthStencilState.FrontFace.StencilPassOp = D3D11Mappings::get(desc.frontStencilPassOp);
+		depthStencilState.FrontFace.StencilFailOp = D3D11Mappings::get(desc.frontStencilFailOp);
+		depthStencilState.FrontFace.StencilDepthFailOp = D3D11Mappings::get(desc.frontStencilZFailOp);
+		depthStencilState.FrontFace.StencilFunc = D3D11Mappings::get(desc.frontStencilComparisonFunc);
+		depthStencilState.DepthEnable = desc.depthReadEnable;
+		depthStencilState.DepthWriteMask = desc.depthWriteEnable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
+		depthStencilState.DepthFunc = D3D11Mappings::get(desc.depthComparisonFunc);
+		depthStencilState.StencilEnable = desc.stencilEnable;
+		depthStencilState.StencilReadMask = desc.stencilReadMask;
+		depthStencilState.StencilWriteMask = desc.stencilWriteMask;
+
+		D3D11Device& device = D3D11RenderSystem::getPrimaryDevice();
+		device.getD3D11Device()->CreateDepthStencilState(&depthStencilState, &mDepthStencilState);
+	}
+}

+ 14 - 0
CamelotD3D11RenderSystem/Source/CmD3D11HLSLProgram.cpp

@@ -1,4 +1,5 @@
 #include "CmD3D11HLSLProgram.h"
+#include "CmD3D11HLSLProgramRTTI.h"
 #include "CmRenderSystem.h"
 #include "CmGpuProgramManager.h"
 #include "CmD3D11GpuProgram.h"
@@ -458,4 +459,17 @@ namespace CamelotEngine
 			mConstantBuffers.push_back(constantBuffer);
 		}
 	}
+
+	/************************************************************************/
+	/* 								SERIALIZATION                      		*/
+	/************************************************************************/
+	RTTITypeBase* D3D11HLSLProgram::getRTTIStatic()
+	{
+		return D3D11HLSLProgramRTTI::instance();
+	}
+
+	RTTITypeBase* D3D11HLSLProgram::getRTTI() const
+	{
+		return D3D11HLSLProgram::getRTTIStatic();
+	}
 }

+ 35 - 0
CamelotD3D11RenderSystem/Source/CmD3D11RasterizerState.cpp

@@ -0,0 +1,35 @@
+#include "CmD3D11RasterizerState.h"
+#include "CmD3D11RenderSystem.h"
+#include "CmD3D11Device.h"
+#include "CmD3D11Mappings.h"
+
+namespace CamelotEngine
+{
+	D3D11RasterizerState::D3D11RasterizerState()
+		:mRasterizerState(nullptr)
+	{ }
+
+	D3D11RasterizerState::~D3D11RasterizerState()
+	{
+		SAFE_RELEASE(mRasterizerState);
+	}
+
+	void D3D11RasterizerState::initialize(const RASTERIZER_STATE_DESC& desc)
+	{
+		D3D11_RASTERIZER_DESC rasterizerStateDesc;
+		ZeroMemory(&rasterizerStateDesc, sizeof(D3D11_RASTERIZER_DESC));
+
+		rasterizerStateDesc.AntialiasedLineEnable = desc.antialiasedLineEnable;
+		rasterizerStateDesc.CullMode = D3D11Mappings::get(desc.cullMode);
+		rasterizerStateDesc.DepthBias = desc.depthBias;
+		rasterizerStateDesc.DepthBiasClamp = desc.depthBiasClamp;
+		rasterizerStateDesc.DepthClipEnable = desc.depthClipEnable;
+		rasterizerStateDesc.FillMode = D3D11Mappings::get(desc.polygonMode);
+		rasterizerStateDesc.MultisampleEnable = desc.multisampleEnable;
+		rasterizerStateDesc.ScissorEnable = desc.scissorEnable;
+		rasterizerStateDesc.SlopeScaledDepthBias = desc.slopeScaledDepthBias;
+
+		D3D11Device& device = D3D11RenderSystem::getPrimaryDevice();
+		device.getD3D11Device()->CreateRasterizerState(&rasterizerStateDesc, &mRasterizerState);
+	}
+}

+ 60 - 0
CamelotD3D11RenderSystem/Source/CmD3D11RenderStateManager.cpp

@@ -0,0 +1,60 @@
+#include "CmD3D11RenderStateManager.h"
+#include "CmD3D11SamplerState.h"
+#include "CmD3D11DepthStencilState.h"
+#include "CmD3D11RasterizerState.h"
+#include "CmD3D11BlendState.h"
+
+namespace CamelotEngine
+{
+	SamplerStatePtr D3D11RenderStateManager::createSamplerState(const SAMPLER_STATE_DESC& desc) const
+	{
+		D3D11SamplerStatePtr samplerState = D3D11SamplerStatePtr(new D3D11SamplerState());
+		samplerState->initialize(desc);
+
+		return samplerState;
+	}
+
+	DepthStencilStatePtr D3D11RenderStateManager::createDepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc) const
+	{
+		D3D11DepthStencilStatePtr depthStencilState = D3D11DepthStencilStatePtr(new D3D11DepthStencilState());
+		depthStencilState->initialize(desc);
+
+		return depthStencilState;
+	}
+
+	RasterizerStatePtr D3D11RenderStateManager::createRasterizerState(const RASTERIZER_STATE_DESC& desc) const
+	{
+		D3D11RasterizerStatePtr rasterizerState = D3D11RasterizerStatePtr(new D3D11RasterizerState());
+		rasterizerState->initialize(desc);
+
+		return rasterizerState;
+	}
+
+	BlendStatePtr D3D11RenderStateManager::createBlendState(const BLEND_STATE_DESC& desc) const
+	{
+		D3D11BlendStatePtr blendState = D3D11BlendStatePtr(new D3D11BlendState());
+		blendState->initialize(desc);
+
+		return blendState;
+	}
+
+	SamplerStatePtr D3D11RenderStateManager::createEmptySamplerState() const
+	{
+		return D3D11SamplerStatePtr(new D3D11SamplerState());
+	}
+
+	DepthStencilStatePtr D3D11RenderStateManager::createEmptyDepthStencilState() const
+	{
+		return D3D11DepthStencilStatePtr(new D3D11DepthStencilState());
+	}
+
+	RasterizerStatePtr D3D11RenderStateManager::createEmptyRasterizerState() const
+	{
+		return D3D11RasterizerStatePtr(new D3D11RasterizerState());
+	}
+
+	BlendStatePtr D3D11RenderStateManager::createEmptyBlendState() const
+	{
+		return D3D11BlendStatePtr(new D3D11BlendState());
+	}
+}

+ 93 - 0
CamelotD3D11RenderSystem/Source/CmD3D11SamplerState.cpp

@@ -0,0 +1,93 @@
+#include "CmD3D11SamplerState.h"
+#include "CmD3D11RenderSystem.h"
+#include "CmD3D11Device.h"
+#include "CmD3D11Mappings.h"
+
+namespace CamelotEngine
+{
+	D3D11SamplerState::D3D11SamplerState()
+		:mSamplerState(nullptr)
+	{ }
+
+	D3D11SamplerState::~D3D11SamplerState()
+	{
+		SAFE_RELEASE(mSamplerState);
+	}
+
+	void D3D11SamplerState::initialize(const SAMPLER_STATE_DESC& desc)
+	{
+		D3D11_SAMPLER_DESC samplerState;
+		ZeroMemory(&samplerState, sizeof(D3D11_SAMPLER_DESC));
+
+		samplerState.AddressU = D3D11Mappings::get(desc.addressMode.u);
+		samplerState.AddressV = D3D11Mappings::get(desc.addressMode.v);
+		samplerState.AddressW = D3D11Mappings::get(desc.addressMode.w);
+		samplerState.BorderColor[0] = desc.borderColor[0];
+		samplerState.BorderColor[1] = desc.borderColor[1];
+		samplerState.BorderColor[2] = desc.borderColor[2];
+		samplerState.BorderColor[3] = desc.borderColor[3];
+		samplerState.ComparisonFunc = D3D11Mappings::get(desc.comparisonFunc);
+		samplerState.MaxAnisotropy = desc.maxAniso;
+		samplerState.MaxLOD = desc.mipMax;
+		samplerState.MinLOD = desc.mipMin;
+		samplerState.MipLODBias =desc.mipmapBias;
+
+		bool isComparison = ((desc.minFilter & FO_USE_COMPARISON) & (desc.magFilter & FO_USE_COMPARISON) & (desc.mipFilter & FO_USE_COMPARISON)) != 0;
+
+		FilterOptions minFilter = (FilterOptions)(desc.minFilter & ~FO_USE_COMPARISON);
+		FilterOptions magFilter = (FilterOptions)(desc.magFilter & ~FO_USE_COMPARISON);
+		FilterOptions mipFilter = (FilterOptions)(desc.mipFilter & ~FO_USE_COMPARISON);
+
+		if(minFilter == FO_ANISOTROPIC && desc.magFilter == FO_ANISOTROPIC && desc.mipFilter == FO_ANISOTROPIC)
+		{
+			samplerState.Filter = D3D11_FILTER_ANISOTROPIC;
+		}
+		else
+		{
+			if(minFilter == FO_POINT || minFilter == FO_NONE)
+			{
+				if(magFilter == FO_POINT || magFilter == FO_NONE)
+				{
+					if(mipFilter == FO_POINT || mipFilter == FO_NONE)
+						samplerState.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
+					else if(mipFilter == FO_LINEAR)
+						samplerState.Filter = D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR;
+				}
+				else if(magFilter == FO_LINEAR)
+				{
+					if(mipFilter == FO_POINT || mipFilter == FO_NONE)
+						samplerState.Filter = D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT;
+					else if(mipFilter == FO_LINEAR)
+						samplerState.Filter = D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR;
+				}
+			}
+			else if(minFilter == FO_LINEAR)
+			{
+				if(magFilter == FO_POINT || magFilter == FO_NONE)
+				{
+					if(mipFilter == FO_POINT || mipFilter == FO_NONE)
+						samplerState.Filter = D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT;
+					else if(mipFilter == FO_LINEAR)
+						samplerState.Filter = D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
+				}
+				else if(magFilter == FO_LINEAR)
+				{
+					if(mipFilter == FO_POINT || mipFilter == FO_NONE)
+						samplerState.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
+					else if(mipFilter == FO_LINEAR)
+						samplerState.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
+				}
+			}
+		}
+
+		if(isComparison)
+		{
+			// Adds COMPARISON flag to the filter
+			// See: http://msdn.microsoft.com/en-us/library/windows/desktop/ff476132(v=vs.85).aspx
+			samplerState.Filter = (D3D11_FILTER)(0x80 | samplerState.Filter);
+		}
+
+		D3D11Device& device = D3D11RenderSystem::getPrimaryDevice();
+		device.getD3D11Device()->CreateSamplerState(&samplerState, &mSamplerState);
+	}
+}

+ 1 - 1
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -578,7 +578,7 @@ namespace CamelotEngine
 		setTextureAddressingMode(unit, uvw);
 
 		// Set border color
-		setTextureBorderColor(unit, state.getBorderColor(0));
+		setTextureBorderColor(unit, state.getBorderColor());
 	}
 	//-----------------------------------------------------------------------
 	void D3D9RenderSystem::setBlendState(const BlendState& blendState)

+ 1 - 1
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -422,7 +422,7 @@ namespace CamelotEngine {
 		setTextureAddressingMode(unit, uvw);
 
 		// Set border color
-		setTextureBorderColor(unit, state.getBorderColor(0));
+		setTextureBorderColor(unit, state.getBorderColor());
 	}
 	//-----------------------------------------------------------------------------
 	void GLRenderSystem::setBlendState(const BlendState& blendState)

+ 4 - 5
CamelotRenderer/Include/CmSamplerState.h

@@ -22,9 +22,8 @@ namespace CamelotEngine
 			, comparisonFunc(CMPF_ALWAYS_FAIL)
 			, mipMin(-FLT_MAX)
 			, mipMax(FLT_MAX)
+			, borderColor(Color::White)
 		{
-			for(int i = 0; i < 4; i++)
-				borderColor[i] = Color::White;
 		}
 
 		UVWAddressingMode addressMode;
@@ -35,7 +34,7 @@ namespace CamelotEngine
 		float mipmapBias;
 		float mipMin;
 		float mipMax;
-		Color borderColor[4];
+		Color borderColor;
 		CompareFunction comparisonFunc;
 	};
 
@@ -89,9 +88,9 @@ namespace CamelotEngine
 		float getMaximumMip() const { return mData.mipMax; }
 
 		/**
-		 * @brief	Gets a border color for the specified side. Index must be >= 0 and < 4.
+		 * @brief	Gets the border color
 		 */
-		const Color& getBorderColor(UINT32 idx) const;
+		const Color& getBorderColor() const;
 
 		static SamplerStatePtr create(const SAMPLER_STATE_DESC& desc);
 

+ 2 - 4
CamelotRenderer/Source/CmSamplerState.cpp

@@ -39,11 +39,9 @@ namespace CamelotEngine
 		return mData.minFilter;
 	}
 
-	const Color& SamplerState::getBorderColor(UINT32 idx) const
+	const Color& SamplerState::getBorderColor() const
 	{
-		assert(idx >= 0 && idx < 4);
-
-		return mData.borderColor[idx];
+		return mData.borderColor;
 	}
 
 	SamplerStatePtr SamplerState::create(const SAMPLER_STATE_DESC& desc)