2
0
Эх сурвалжийг харах

Fixed a bunch of DX11 bugs
Changed so that states get assigned by pointers instead of references

Marko Pintera 13 жил өмнө
parent
commit
a7e57abdbf
38 өөрчлөгдсөн 1082 нэмэгдсэн , 995 устгасан
  1. 57 27
      CamelotClient/CamelotClient.cpp
  2. 1 0
      CamelotD3D11RenderSystem/CamelotD3D11RenderSystem.vcxproj
  3. 3 0
      CamelotD3D11RenderSystem/CamelotD3D11RenderSystem.vcxproj.filters
  4. 7 7
      CamelotD3D11RenderSystem/Include/CmD3D11GpuProgram.h
  5. 1 1
      CamelotD3D11RenderSystem/Include/CmD3D11HLSLProgram.h
  6. 4 4
      CamelotD3D11RenderSystem/Include/CmD3D11RenderSystem.h
  7. 8 2
      CamelotD3D11RenderSystem/Source/CmD3D11BlendState.cpp
  8. 7 1
      CamelotD3D11RenderSystem/Source/CmD3D11DepthStencilState.cpp
  9. 146 143
      CamelotD3D11RenderSystem/Source/CmD3D11Device.cpp
  10. 103 103
      CamelotD3D11RenderSystem/Source/CmD3D11Driver.cpp
  11. 55 55
      CamelotD3D11RenderSystem/Source/CmD3D11DriverList.cpp
  12. 281 281
      CamelotD3D11RenderSystem/Source/CmD3D11GpuProgram.cpp
  13. 5 5
      CamelotD3D11RenderSystem/Source/CmD3D11GpuProgramManager.cpp
  14. 6 4
      CamelotD3D11RenderSystem/Source/CmD3D11HLSLProgram.cpp
  15. 10 0
      CamelotD3D11RenderSystem/Source/CmD3D11Plugin.cpp
  16. 7 1
      CamelotD3D11RenderSystem/Source/CmD3D11RasterizerState.cpp
  17. 135 126
      CamelotD3D11RenderSystem/Source/CmD3D11RenderSystem.cpp
  18. 7 1
      CamelotD3D11RenderSystem/Source/CmD3D11SamplerState.cpp
  19. 6 6
      CamelotD3D11RenderSystem/Source/CmD3D11Texture.cpp
  20. 101 101
      CamelotD3D11RenderSystem/Source/CmD3D11VideoModeList.cpp
  21. 4 4
      CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h
  22. 0 1
      CamelotD3D9Renderer/Source/CmD3D9HLSLProgram.cpp
  23. 38 33
      CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp
  24. 3 3
      CamelotForwardRenderer/Source/CmForwardRenderer.cpp
  25. 4 4
      CamelotGLRenderer/Include/CmGLRenderSystem.h
  26. 34 30
      CamelotGLRenderer/Source/CmGLRenderSystem.cpp
  27. 1 1
      CamelotRenderer/Include/CmBlendState.h
  28. 4 4
      CamelotRenderer/Include/CmDeferredRenderContext.h
  29. 1 1
      CamelotRenderer/Include/CmDepthStencilState.h
  30. 1 1
      CamelotRenderer/Include/CmRasterizerState.h
  31. 4 4
      CamelotRenderer/Include/CmRenderSystem.h
  32. 1 1
      CamelotRenderer/Include/CmSamplerState.h
  33. 2 9
      CamelotRenderer/Source/CmBlendState.cpp
  34. 4 4
      CamelotRenderer/Source/CmDeferredRenderContext.cpp
  35. 2 9
      CamelotRenderer/Source/CmDepthStencilState.cpp
  36. 2 9
      CamelotRenderer/Source/CmRasterizerState.cpp
  37. 2 9
      CamelotRenderer/Source/CmSamplerState.cpp
  38. 25 0
      CamelotRenderer/TODO.txt

+ 57 - 27
CamelotClient/CamelotClient.cpp

@@ -26,8 +26,9 @@ using namespace CamelotEngine;
 
 int _tmain(int argc, _TCHAR* argv[])
 {
-	gApplication().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer");
+	//gApplication().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer");
 	//gApplication().startUp("CamelotD3D9RenderSystem", "CamelotForwardRenderer");
+	gApplication().startUp("CamelotD3D11RenderSystem", "CamelotForwardRenderer");
 
 	RenderSystem* renderSystem = RenderSystem::instancePtr();
 	RenderWindowPtr renderWindow = gApplication().getPrimaryRenderWindow();
@@ -49,7 +50,7 @@ int _tmain(int argc, _TCHAR* argv[])
 	HighLevelGpuProgramPtr fragProg;
 	HighLevelGpuProgramPtr vertProg;
 
-	/////////////////// HLSL SHADERS //////////////////////////
+	/////////////////// HLSL 9 SHADERS //////////////////////////
 	//String fragShaderCode = "sampler2D tex;			\
 	//						float4 ps_main(float2 uv : TEXCOORD0) : COLOR0		\
 	//						{														\
@@ -72,6 +73,30 @@ int _tmain(int argc, _TCHAR* argv[])
 
 	//vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "hlsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 
+	/////////////////// HLSL 11 SHADERS //////////////////////////
+	String fragShaderCode = "SamplerState samp : register(s0);			\
+							Texture2D tex : register(t0); \
+							float4 ps_main(float2 uv : TEXCOORD0) : SV_Target		\
+							{														\
+							float4 color = tex.Sample(samp, uv);				\
+							return color;										\
+							}";
+
+	fragProg =  HighLevelGpuProgram::create(fragShaderCode, "ps_main", "hlsl", GPT_FRAGMENT_PROGRAM, GPP_PS_4_0);
+
+	String vertShaderCode = "float4x4 matViewProjection;	\
+							void vs_main(										\
+							in float4 inPos : POSITION,							\
+							in float2 uv : TEXCOORD0,								\
+							out float4 oPosition : SV_Position,					\
+							out float2 oUv : TEXCOORD0)							\
+							{														\
+							oPosition = mul(matViewProjection, inPos);			\
+							oUv = uv;											\
+							}";
+
+	vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "hlsl", GPT_VERTEX_PROGRAM, GPP_VS_4_0);
+
 	/////////////////// CG SHADERS //////////////////////////
 	//String fragShaderCode = "sampler2D tex;					\
 	//						float4 ps_main(float2 uv : TEXCOORD0) : COLOR0		\
@@ -96,31 +121,31 @@ int _tmain(int argc, _TCHAR* argv[])
 	//vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "cg", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 
 	///////////////// GLSL SHADERS ////////////////////////////
-	String fragShaderCode = " #version 400 \n \
-							  uniform sampler2D tex; \
-							  in vec2 texcoord0; \
-							  out vec4 fragColor; \
-							  void main() \
-							  {\
-								  vec4 texColor = texture2D(tex, texcoord0.st);\
-								  fragColor = texColor; \
-							  }";
-
-	fragProg = HighLevelGpuProgram::create(fragShaderCode, "main", "glsl", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
-
-	// TODO - Make sure to document the strict input parameter naming. (Exact supported names are in GLSLParamParser)
-	String vertShaderCode = "#version 400 \n \
-							 uniform mainFragBlock { mat4 matViewProjection; }; \
-							 in vec4 cm_position; \
-							 in vec2 cm_texcoord0; \
-							 out vec2 texcoord0; \
-							 void main() \
-							 { \
-								texcoord0 = cm_texcoord0; \
-								gl_Position = cm_position * matViewProjection; \
-							 }";
-
-	vertProg = HighLevelGpuProgram::create(vertShaderCode, "main", "glsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
+	//String fragShaderCode = " #version 400 \n \
+	//						  uniform sampler2D tex; \
+	//						  in vec2 texcoord0; \
+	//						  out vec4 fragColor; \
+	//						  void main() \
+	//						  {\
+	//							  vec4 texColor = texture2D(tex, texcoord0.st);\
+	//							  fragColor = texColor; \
+	//						  }";
+
+	//fragProg = HighLevelGpuProgram::create(fragShaderCode, "main", "glsl", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
+
+	//// TODO - Make sure to document the strict input parameter naming. (Exact supported names are in GLSLParamParser)
+	//String vertShaderCode = "#version 400 \n \
+	//						 uniform mainFragBlock { mat4 matViewProjection; }; \
+	//						 in vec4 cm_position; \
+	//						 in vec2 cm_texcoord0; \
+	//						 out vec2 texcoord0; \
+	//						 void main() \
+	//						 { \
+	//							texcoord0 = cm_texcoord0; \
+	//							gl_Position = cm_position * matViewProjection; \
+	//						 }";
+
+	//vertProg = HighLevelGpuProgram::create(vertShaderCode, "main", "glsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 
 	HighLevelGpuProgramHandle vertProgRef(vertProg);
 
@@ -147,6 +172,11 @@ int _tmain(int argc, _TCHAR* argv[])
 	newPassDX->setVertexProgram(vertProgRef);
 	newPassDX->setFragmentProgram(fragProgRef);
 
+	TechniquePtr newTechniqueDX11 = testShader->addTechnique("D3D11RenderSystem", "ForwardRenderer");
+	PassPtr newPassDX11 = newTechniqueDX11->addPass();
+	newPassDX11->setVertexProgram(vertProgRef);
+	newPassDX11->setFragmentProgram(fragProgRef);
+
 	MaterialHandle testMaterial = MaterialPtr(new Material());
 	testMaterial->setShader(testShader);
 

+ 1 - 0
CamelotD3D11RenderSystem/CamelotD3D11RenderSystem.vcxproj

@@ -199,6 +199,7 @@
     <ClCompile Include="Source\CmD3D11IndexBuffer.cpp" />
     <ClCompile Include="Source\CmD3D11HLSLProgramFactory.cpp" />
     <ClCompile Include="Source\CmD3D11Mappings.cpp" />
+    <ClCompile Include="Source\CmD3D11Plugin.cpp" />
     <ClCompile Include="Source\CmD3D11VertexBuffer.cpp" />
     <ClCompile Include="Source\CmD3D11MultiRenderTexture.cpp" />
     <ClCompile Include="Source\CmD3D11RasterizerState.cpp" />

+ 3 - 0
CamelotD3D11RenderSystem/CamelotD3D11RenderSystem.vcxproj.filters

@@ -218,5 +218,8 @@
     <ClCompile Include="Source\CmD3D11IndexBuffer.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Source\CmD3D11Plugin.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 7 - 7
CamelotD3D11RenderSystem/Include/CmD3D11GpuProgram.h

@@ -8,7 +8,7 @@ namespace CamelotEngine
 	class CM_D3D11_EXPORT D3D11GpuProgram : public GpuProgram
 	{
 	public:
-		D3D11GpuProgram(GpuProgramType type);
+		D3D11GpuProgram(GpuProgramType type, const String& profile);
 
 	protected:
 		void loadImpl(void);
@@ -30,7 +30,7 @@ namespace CamelotEngine
 	protected:
 		ID3D11VertexShader* mVertexShader;
 	public:
-		D3D11GpuVertexProgram();
+		D3D11GpuVertexProgram(const String& profile);
 		~D3D11GpuVertexProgram();
 
 		ID3D11VertexShader* getVertexShader(void) const;
@@ -44,7 +44,7 @@ namespace CamelotEngine
 	protected:
 		ID3D11PixelShader* mPixelShader;
 	public:
-		D3D11GpuFragmentProgram();
+		D3D11GpuFragmentProgram(const String& profile);
 		~D3D11GpuFragmentProgram();
 
 		ID3D11PixelShader* getPixelShader(void) const;
@@ -58,7 +58,7 @@ namespace CamelotEngine
 	protected:
 		ID3D11DomainShader* mDomainShader;
 	public:
-		D3D11GpuDomainProgram();
+		D3D11GpuDomainProgram(const String& profile);
 		~D3D11GpuDomainProgram();
 
 		ID3D11DomainShader* getDomainShader(void) const;
@@ -72,7 +72,7 @@ namespace CamelotEngine
 	protected:
 		ID3D11HullShader* mHullShader;
 	public:
-		D3D11GpuHullProgram();
+		D3D11GpuHullProgram(const String& profile);
 		~D3D11GpuHullProgram();
 
 		ID3D11HullShader* getHullShader() const;
@@ -86,7 +86,7 @@ namespace CamelotEngine
 	protected:
 		ID3D11GeometryShader* mGeometryShader;
 	public:
-		D3D11GpuGeometryProgram();
+		D3D11GpuGeometryProgram(const String& profile);
 		~D3D11GpuGeometryProgram();
 
 		ID3D11GeometryShader* getGeometryShader(void) const;
@@ -100,7 +100,7 @@ namespace CamelotEngine
 	protected:
 		ID3D11ComputeShader* mComputeShader;
 	public:
-		D3D11GpuComputeProgram();
+		D3D11GpuComputeProgram(const String& profile);
 		~D3D11GpuComputeProgram();
 
 		ID3D11ComputeShader* getComputeShader(void) const;

+ 1 - 1
CamelotD3D11RenderSystem/Include/CmD3D11HLSLProgram.h

@@ -75,7 +75,7 @@ namespace CamelotEngine
 		/**
 		 * @brief	Compiles the shader from source and generates the microcode.
 		 */
-		ID3DBlob* compileMicrocode();
+		ID3DBlob* compileMicrocode(const String& profile);
 
 		/**
 		 * @brief	Reflects the microcode and extracts input/output parameters, and constant

+ 4 - 4
CamelotD3D11RenderSystem/Include/CmD3D11RenderSystem.h

@@ -20,11 +20,11 @@ namespace CamelotEngine
 		 */
 		const String& getShadingLanguageName() const;
 
-		void setBlendState(const BlendState& blendState);
-		void setRasterizerState(const RasterizerState& rasterizerState);
-		void setDepthStencilState(const DepthStencilState& depthStencilState, UINT32 stencilRefValue);
+		void setBlendState(const BlendStatePtr& blendState);
+		void setRasterizerState(const RasterizerStatePtr& rasterizerState);
+		void setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue);
 
-		void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerState& samplerState);
+		void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerStatePtr& samplerState);
 		void setTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const TexturePtr &texPtr);
 		void disableTextureUnit(GpuProgramType gptype, UINT16 texUnit);
 

+ 8 - 2
CamelotD3D11RenderSystem/Source/CmD3D11BlendState.cpp

@@ -29,13 +29,19 @@ namespace CamelotEngine
 			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].RenderTargetWriteMask = 0xf & desc.renderTargetDesc[i].renderTargetWriteMask; // Mask out all but last 4 bits
 			blendStateDesc.RenderTarget[i].SrcBlend = D3D11Mappings::get(desc.renderTargetDesc[i].srcBlend);
 			blendStateDesc.RenderTarget[i].SrcBlendAlpha = D3D11Mappings::get(desc.renderTargetDesc[i].srcBlendAlpha);
 		}
 
 		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
 		D3D11Device& device = rs->getPrimaryDevice();
-		device.getD3D11Device()->CreateBlendState(&blendStateDesc, &mBlendState);
+		HRESULT hr = device.getD3D11Device()->CreateBlendState(&blendStateDesc, &mBlendState);
+
+		if(FAILED(hr) || device.hasError())
+		{
+			String errorDescription = device.getErrorDescription();
+			CM_EXCEPT(RenderingAPIException, "Cannot create blend state.\nError Description:" + errorDescription);
+		}
 	}
 }

+ 7 - 1
CamelotD3D11RenderSystem/Source/CmD3D11DepthStencilState.cpp

@@ -36,6 +36,12 @@ namespace CamelotEngine
 
 		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
 		D3D11Device& device = rs->getPrimaryDevice();
-		device.getD3D11Device()->CreateDepthStencilState(&depthStencilState, &mDepthStencilState);
+		HRESULT hr = device.getD3D11Device()->CreateDepthStencilState(&depthStencilState, &mDepthStencilState);
+
+		if(FAILED(hr) || device.hasError())
+		{
+			String errorDescription = device.getErrorDescription();
+			CM_EXCEPT(RenderingAPIException, "Cannot create depth stencil state.\nError Description:" + errorDescription);
+		}
 	}
 }

+ 146 - 143
CamelotD3D11RenderSystem/Source/CmD3D11Device.cpp

@@ -2,149 +2,152 @@
 #include "CmException.h"
 
 namespace CamelotEngine
-{
-	D3D11Device::D3D11Device() 
-		:mD3D11Device(nullptr), mImmediateContext(nullptr), mClassLinkage(nullptr)
-	{
-	}
-
-	D3D11Device::D3D11Device(ID3D11Device* device)
-		: mD3D11Device(device)
-		, mImmediateContext(nullptr)
-		, mInfoQueue(nullptr)
-		, mClassLinkage(nullptr)
-	{
-		assert(device != nullptr);
-
-		if (device)
-		{
-			device->GetImmediateContext(&mImmediateContext);
-
-			HRESULT hr = mD3D11Device->QueryInterface(__uuidof(ID3D11InfoQueue), (LPVOID*)&mInfoQueue);
-
-			if (FAILED(hr))
-				CM_EXCEPT(RenderingAPIException, "Unable to query D3D11InfoQueue");
-
-			// If feature level is 11, create class linkage
-			SAFE_RELEASE(mClassLinkage);
-			if (mD3D11Device->GetFeatureLevel() == D3D_FEATURE_LEVEL_11_0)
-			{
-				HRESULT hr = mD3D11Device->CreateClassLinkage(&mClassLinkage);
-
-				if (FAILED(hr))
-					CM_EXCEPT(RenderingAPIException, "Unable to create class linkage.");
-			}
-		}	
-	}
-
-	D3D11Device::~D3D11Device()
-	{
-		shutdown();
-	}
-
-	void D3D11Device::shutdown()
-	{
-		// Clear state
-		if (mImmediateContext)
-		{
-			mImmediateContext->Flush();
-			mImmediateContext->ClearState();
-		}
-
-		SAFE_RELEASE(mInfoQueue);
-		SAFE_RELEASE(mD3D11Device);
-		SAFE_RELEASE(mImmediateContext);
-		SAFE_RELEASE(mClassLinkage);
-	}
-
-	String D3D11Device::getErrorDescription(bool doClearErrors)
-	{
-		if (mD3D11Device == nullptr)
-			return "NULL device";
-
-		String res;
-
-		if (mInfoQueue != nullptr)
-		{
-			UINT64 numStoredMessages = mInfoQueue->GetNumStoredMessagesAllowedByRetrievalFilter();
-			for (UINT64 i = 0 ; i < numStoredMessages ; i++ )
-			{
-				// Get the size of the message
-				SIZE_T messageLength = 0;
-				mInfoQueue->GetMessage(i, nullptr, &messageLength);
-				// Allocate space and get the message
-				D3D11_MESSAGE* pMessage = (D3D11_MESSAGE*)malloc(messageLength);
-				mInfoQueue->GetMessage(i, pMessage, &messageLength);
-				res = res + pMessage->pDescription + "\n";
-				free(pMessage);
-			}
-		}
-
-		if(doClearErrors)
-			clearErrors();
-
-		return res;
-	}
-
-	bool D3D11Device::hasError() const
-	{
-		if (mInfoQueue != nullptr)
-		{
-			UINT64 numStoredMessages = mInfoQueue->GetNumStoredMessagesAllowedByRetrievalFilter();
-
-			if (numStoredMessages > 0)
-				return true;
-
-			return false;
-		}
-		else
-		{
-			return false;
-		}
-	}
-
-	void D3D11Device::clearErrors()
-	{
-		if (mD3D11Device != nullptr && mInfoQueue != nullptr)
-		{
-			mInfoQueue->ClearStoredMessages();
-		}
+{
+	D3D11Device::D3D11Device() 
+		:mD3D11Device(nullptr), mImmediateContext(nullptr), mClassLinkage(nullptr)
+	{
 	}
-
-	void D3D11Device::setExceptionsErrorLevel(const CM_D3D11_ERROR_LEVEL exceptionsErrorLevel)
-	{
-		if(mInfoQueue == nullptr)
-			return;
-
-		mInfoQueue->ClearRetrievalFilter();
-		mInfoQueue->ClearStorageFilter();
-
-		D3D11_INFO_QUEUE_FILTER filter;
-		ZeroMemory(&filter, sizeof(D3D11_INFO_QUEUE_FILTER));
-		std::vector<D3D11_MESSAGE_SEVERITY> severityList;
-
-		switch(exceptionsErrorLevel)
-		{
-		case D3D11ERR_NO_EXCEPTION:
-			severityList.push_back(D3D11_MESSAGE_SEVERITY_CORRUPTION);
-		case D3D11ERR_CORRUPTION:
-			severityList.push_back(D3D11_MESSAGE_SEVERITY_ERROR);
-		case D3D11ERR_ERROR:
-			severityList.push_back(D3D11_MESSAGE_SEVERITY_WARNING);
-		case D3D11ERR_WARNING:
-		case D3D11ERR_INFO:
-			severityList.push_back(D3D11_MESSAGE_SEVERITY_INFO);
-		default: 
-			break;
-		}
-
-		if (severityList.size() > 0)
-		{
-			filter.DenyList.NumSeverities = (UINT)severityList.size();
-			filter.DenyList.pSeverityList = &severityList[0];
-		}
-
-		mInfoQueue->AddStorageFilterEntries(&filter);
-		mInfoQueue->AddRetrievalFilterEntries(&filter);
+
+	D3D11Device::D3D11Device(ID3D11Device* device)
+		: mD3D11Device(device)
+		, mImmediateContext(nullptr)
+		, mInfoQueue(nullptr)
+		, mClassLinkage(nullptr)
+	{
+		assert(device != nullptr);
+
+		if (device)
+		{
+			device->GetImmediateContext(&mImmediateContext);
+
+#if CM_DEBUG_MODE
+			// This interface is not available unless we created the device with debug layer
+			HRESULT hr = mD3D11Device->QueryInterface(__uuidof(ID3D11InfoQueue), (LPVOID*)&mInfoQueue);
+
+			if (FAILED(hr))
+				CM_EXCEPT(RenderingAPIException, "Unable to query D3D11InfoQueue");
+#endif
+
+			// If feature level is 11, create class linkage
+			SAFE_RELEASE(mClassLinkage);
+			if (mD3D11Device->GetFeatureLevel() == D3D_FEATURE_LEVEL_11_0)
+			{
+				HRESULT hr = mD3D11Device->CreateClassLinkage(&mClassLinkage);
+
+				if (FAILED(hr))
+					CM_EXCEPT(RenderingAPIException, "Unable to create class linkage.");
+			}
+		}	
+	}
+
+	D3D11Device::~D3D11Device()
+	{
+		shutdown();
+	}
+
+	void D3D11Device::shutdown()
+	{
+		// Clear state
+		if (mImmediateContext)
+		{
+			mImmediateContext->Flush();
+			mImmediateContext->ClearState();
+		}
+
+		SAFE_RELEASE(mInfoQueue);
+		SAFE_RELEASE(mD3D11Device);
+		SAFE_RELEASE(mImmediateContext);
+		SAFE_RELEASE(mClassLinkage);
+	}
+
+	String D3D11Device::getErrorDescription(bool doClearErrors)
+	{
+		if (mD3D11Device == nullptr)
+			return "NULL device";
+
+		String res;
+
+		if (mInfoQueue != nullptr)
+		{
+			UINT64 numStoredMessages = mInfoQueue->GetNumStoredMessagesAllowedByRetrievalFilter();
+			for (UINT64 i = 0 ; i < numStoredMessages ; i++ )
+			{
+				// Get the size of the message
+				SIZE_T messageLength = 0;
+				mInfoQueue->GetMessage(i, nullptr, &messageLength);
+				// Allocate space and get the message
+				D3D11_MESSAGE* pMessage = (D3D11_MESSAGE*)malloc(messageLength);
+				mInfoQueue->GetMessage(i, pMessage, &messageLength);
+				res = res + pMessage->pDescription + "\n";
+				free(pMessage);
+			}
+		}
+
+		if(doClearErrors)
+			clearErrors();
+
+		return res;
+	}
+
+	bool D3D11Device::hasError() const
+	{
+		if (mInfoQueue != nullptr)
+		{
+			UINT64 numStoredMessages = mInfoQueue->GetNumStoredMessagesAllowedByRetrievalFilter();
+
+			if (numStoredMessages > 0)
+				return true;
+
+			return false;
+		}
+		else
+		{
+			return false;
+		}
+	}
+
+	void D3D11Device::clearErrors()
+	{
+		if (mD3D11Device != nullptr && mInfoQueue != nullptr)
+		{
+			mInfoQueue->ClearStoredMessages();
+		}
+	}
+
+	void D3D11Device::setExceptionsErrorLevel(const CM_D3D11_ERROR_LEVEL exceptionsErrorLevel)
+	{
+		if(mInfoQueue == nullptr)
+			return;
+
+		mInfoQueue->ClearRetrievalFilter();
+		mInfoQueue->ClearStorageFilter();
+
+		D3D11_INFO_QUEUE_FILTER filter;
+		ZeroMemory(&filter, sizeof(D3D11_INFO_QUEUE_FILTER));
+		std::vector<D3D11_MESSAGE_SEVERITY> severityList;
+
+		switch(exceptionsErrorLevel)
+		{
+		case D3D11ERR_NO_EXCEPTION:
+			severityList.push_back(D3D11_MESSAGE_SEVERITY_CORRUPTION);
+		case D3D11ERR_CORRUPTION:
+			severityList.push_back(D3D11_MESSAGE_SEVERITY_ERROR);
+		case D3D11ERR_ERROR:
+			severityList.push_back(D3D11_MESSAGE_SEVERITY_WARNING);
+		case D3D11ERR_WARNING:
+		case D3D11ERR_INFO:
+			severityList.push_back(D3D11_MESSAGE_SEVERITY_INFO);
+		default: 
+			break;
+		}
+
+		if (severityList.size() > 0)
+		{
+			filter.DenyList.NumSeverities = (UINT)severityList.size();
+			filter.DenyList.pSeverityList = &severityList[0];
+		}
+
+		mInfoQueue->AddStorageFilterEntries(&filter);
+		mInfoQueue->AddRetrievalFilterEntries(&filter);
 	}
 }

+ 103 - 103
CamelotD3D11RenderSystem/Source/CmD3D11Driver.cpp

@@ -3,108 +3,108 @@
 
 namespace CamelotEngine
 {
-	D3D11Driver::D3D11Driver( const D3D11Driver &ob ) 
-	{
-		mAdapterNumber = ob.mAdapterNumber;
-		mAdapterIdentifier = ob.mAdapterIdentifier;
-		mDesktopDisplayMode = ob.mDesktopDisplayMode;
-		mVideoModeList = nullptr;
-		mDXGIAdapter = ob.mDXGIAdapter;
-
-		if(mDXGIAdapter)
-			mDXGIAdapter->AddRef();
-
-		init();
-	}
-
-	D3D11Driver::D3D11Driver(unsigned int adapterNumber, IDXGIAdapter* pDXGIAdapter)
-	{
-		mAdapterNumber = adapterNumber;
-		mVideoModeList = nullptr;
-		mDXGIAdapter = pDXGIAdapter;
-
-		if(mDXGIAdapter)
-			mDXGIAdapter->AddRef();
-
-		// get the description of the adapter
-		pDXGIAdapter->GetDesc(&mAdapterIdentifier);
-
-		init();
-	}
-
-	D3D11Driver::~D3D11Driver()
-	{
-		for(UINT32 i = 0; i < mNumOutputs; i++)
-			SAFE_DELETE(mVideoModeList[i]);
-
-		SAFE_DELETE(mVideoModeList);
-		SAFE_RELEASE(mDXGIAdapter);
-	}
-
-	void D3D11Driver::init()
-	{
-		assert(mDXGIAdapter != nullptr);
-
-		UINT32 outputIdx = 0;
-		IDXGIOutput* output;
-		while(mDXGIAdapter->EnumOutputs(outputIdx, &output) != DXGI_ERROR_NOT_FOUND)
-		{
-			outputIdx++;
-		}
-
-		mNumOutputs = outputIdx + 1;
-
-		mVideoModeList = new D3D11VideoModeList*[mNumOutputs];
-		for(UINT32 i = 0; i < mNumOutputs; i++)
-			mVideoModeList[i] = new D3D11VideoModeList(this, i);
-	}
-
-	D3D11Driver& D3D11Driver::operator=(const D3D11Driver& ob)
-	{
-		mAdapterNumber = ob.mAdapterNumber;
-		mAdapterIdentifier = ob.mAdapterIdentifier;
-		mDesktopDisplayMode = ob.mDesktopDisplayMode;
-		mVideoModeList = nullptr;
-
-		if(ob.mDXGIAdapter)
-			ob.mDXGIAdapter->AddRef();
-
-		SAFE_RELEASE(mDXGIAdapter);
-		mDXGIAdapter=ob.mDXGIAdapter;
-
-		return *this;
-	}
-	
-	String D3D11Driver::getDriverName() const
-	{
-		size_t size = wcslen(mAdapterIdentifier.Description);
-		char* str = new char[size + 1];
-
-		wcstombs(str, mAdapterIdentifier.Description, size);
-		str[size] = '\0';
-		String Description = str;
-		delete str;
-		return String(Description );
-	}
-
-	String D3D11Driver::getDriverDescription() const
-	{
-		size_t size = wcslen(mAdapterIdentifier.Description);
-		char* str = new char[size + 1];
-
-		wcstombs(str, mAdapterIdentifier.Description, size);
-		str[size] = '\0';
-		String driverDescription = str;
-		delete [] str;
-		StringUtil::trim(driverDescription);
-
-		return driverDescription;
-	}
-
-	const D3D11VideoModeList* D3D11Driver::getVideoModeList(UINT32 adapterOutputIdx) const
-	{
-		assert(adapterOutputIdx >= 0 && adapterOutputIdx < mNumOutputs);
-
-		return mVideoModeList[adapterOutputIdx];
+	D3D11Driver::D3D11Driver( const D3D11Driver &ob ) 
+	{
+		mAdapterNumber = ob.mAdapterNumber;
+		mAdapterIdentifier = ob.mAdapterIdentifier;
+		mDesktopDisplayMode = ob.mDesktopDisplayMode;
+		mVideoModeList = nullptr;
+		mDXGIAdapter = ob.mDXGIAdapter;
+
+		if(mDXGIAdapter)
+			mDXGIAdapter->AddRef();
+
+		init();
+	}
+
+	D3D11Driver::D3D11Driver(unsigned int adapterNumber, IDXGIAdapter* pDXGIAdapter)
+	{
+		mAdapterNumber = adapterNumber;
+		mVideoModeList = nullptr;
+		mDXGIAdapter = pDXGIAdapter;
+
+		if(mDXGIAdapter)
+			mDXGIAdapter->AddRef();
+
+		// get the description of the adapter
+		pDXGIAdapter->GetDesc(&mAdapterIdentifier);
+
+		init();
+	}
+
+	D3D11Driver::~D3D11Driver()
+	{
+		for(UINT32 i = 0; i < mNumOutputs; i++)
+			SAFE_DELETE(mVideoModeList[i]);
+
+		SAFE_DELETE(mVideoModeList);
+		SAFE_RELEASE(mDXGIAdapter);
+	}
+
+	void D3D11Driver::init()
+	{
+		assert(mDXGIAdapter != nullptr);
+
+		UINT32 outputIdx = 0;
+		IDXGIOutput* output;
+		while(mDXGIAdapter->EnumOutputs(outputIdx, &output) != DXGI_ERROR_NOT_FOUND)
+		{
+			outputIdx++;
+		}
+
+		mNumOutputs = outputIdx;
+
+		mVideoModeList = new D3D11VideoModeList*[mNumOutputs];
+		for(UINT32 i = 0; i < mNumOutputs; i++)
+			mVideoModeList[i] = new D3D11VideoModeList(this, i);
+	}
+
+	D3D11Driver& D3D11Driver::operator=(const D3D11Driver& ob)
+	{
+		mAdapterNumber = ob.mAdapterNumber;
+		mAdapterIdentifier = ob.mAdapterIdentifier;
+		mDesktopDisplayMode = ob.mDesktopDisplayMode;
+		mVideoModeList = nullptr;
+
+		if(ob.mDXGIAdapter)
+			ob.mDXGIAdapter->AddRef();
+
+		SAFE_RELEASE(mDXGIAdapter);
+		mDXGIAdapter=ob.mDXGIAdapter;
+
+		return *this;
+	}
+	
+	String D3D11Driver::getDriverName() const
+	{
+		size_t size = wcslen(mAdapterIdentifier.Description);
+		char* str = new char[size + 1];
+
+		wcstombs(str, mAdapterIdentifier.Description, size);
+		str[size] = '\0';
+		String Description = str;
+		delete str;
+		return String(Description );
+	}
+
+	String D3D11Driver::getDriverDescription() const
+	{
+		size_t size = wcslen(mAdapterIdentifier.Description);
+		char* str = new char[size + 1];
+
+		wcstombs(str, mAdapterIdentifier.Description, size);
+		str[size] = '\0';
+		String driverDescription = str;
+		delete [] str;
+		StringUtil::trim(driverDescription);
+
+		return driverDescription;
+	}
+
+	const D3D11VideoModeList* D3D11Driver::getVideoModeList(UINT32 adapterOutputIdx) const
+	{
+		assert(adapterOutputIdx >= 0 && adapterOutputIdx < mNumOutputs);
+
+		return mVideoModeList[adapterOutputIdx];
 	}
 }

+ 55 - 55
CamelotD3D11RenderSystem/Source/CmD3D11DriverList.cpp

@@ -4,60 +4,60 @@
 
 namespace CamelotEngine
 {
-	D3D11DriverList::D3D11DriverList(IDXGIFactory* dxgiFactory) 
-	{
-		enumerate(dxgiFactory);
-	}
-
-	D3D11DriverList::~D3D11DriverList(void)
-	{
-		for(size_t i = 0; i < mDriverList.size(); i++)
-		{
-			delete (mDriverList[i]);
-		}
-
-		mDriverList.clear();
-	}
-
-	void D3D11DriverList::enumerate(IDXGIFactory* dxgiFactory)
-	{
-		UINT32 adapterIdx = 0;
-		IDXGIAdapter* dxgiAdapter = nullptr;
-		HRESULT hr;
-
-		while((hr = dxgiFactory->EnumAdapters(adapterIdx, &dxgiAdapter)) != DXGI_ERROR_NOT_FOUND)
-		{
-			if( FAILED(hr) )
-			{
-				SAFE_RELEASE(dxgiAdapter);
-				CM_EXCEPT(InternalErrorException, "Enumerating adapters failed.");
-			}
-
-			mDriverList.push_back(new D3D11Driver(adapterIdx, dxgiAdapter));
-
-			SAFE_RELEASE(dxgiAdapter);
-			adapterIdx++;
-		}
-	}
-
-	UINT32 D3D11DriverList::count() const 
-	{
-		return (UINT32)mDriverList.size();
-	}
-
-	D3D11Driver* D3D11DriverList::item(UINT32 idx) const
-	{
-		return mDriverList.at(idx);
-	}
-
-	D3D11Driver* D3D11DriverList::item(const String &name) const
-	{
-		for (auto it = mDriverList.begin(); it != mDriverList.end(); ++it)
-		{
-			if ((*it)->getDriverDescription() == name)
-				return (*it);
-		}
-
-		CM_EXCEPT(InvalidParametersException, "Cannot find video mode with the specified name.");
+	D3D11DriverList::D3D11DriverList(IDXGIFactory* dxgiFactory) 
+	{
+		enumerate(dxgiFactory);
+	}
+
+	D3D11DriverList::~D3D11DriverList(void)
+	{
+		for(size_t i = 0; i < mDriverList.size(); i++)
+		{
+			delete (mDriverList[i]);
+		}
+
+		mDriverList.clear();
+	}
+
+	void D3D11DriverList::enumerate(IDXGIFactory* dxgiFactory)
+	{
+		UINT32 adapterIdx = 0;
+		IDXGIAdapter* dxgiAdapter = nullptr;
+		HRESULT hr;
+
+		while((hr = dxgiFactory->EnumAdapters(adapterIdx, &dxgiAdapter)) != DXGI_ERROR_NOT_FOUND)
+		{
+			if( FAILED(hr) )
+			{
+				SAFE_RELEASE(dxgiAdapter);
+				CM_EXCEPT(InternalErrorException, "Enumerating adapters failed.");
+			}
+
+			mDriverList.push_back(new D3D11Driver(adapterIdx, dxgiAdapter));
+
+			SAFE_RELEASE(dxgiAdapter);
+			adapterIdx++;
+		}
+	}
+
+	UINT32 D3D11DriverList::count() const 
+	{
+		return (UINT32)mDriverList.size();
+	}
+
+	D3D11Driver* D3D11DriverList::item(UINT32 idx) const
+	{
+		return mDriverList.at(idx);
+	}
+
+	D3D11Driver* D3D11DriverList::item(const String &name) const
+	{
+		for (auto it = mDriverList.begin(); it != mDriverList.end(); ++it)
+		{
+			if ((*it)->getDriverDescription() == name)
+				return (*it);
+		}
+
+		CM_EXCEPT(InvalidParametersException, "Cannot find video mode with the specified name.");
 	}
 }

+ 281 - 281
CamelotD3D11RenderSystem/Source/CmD3D11GpuProgram.cpp

@@ -4,288 +4,288 @@
 #include "CmDebug.h"
 
 namespace CamelotEngine
-{
-	D3D11GpuProgram::D3D11GpuProgram(GpuProgramType type) 
-		: GpuProgram("", "", "", type, GPP_NONE)
-	{
-
-	}
-
-	void D3D11GpuProgram::loadImpl(void)
-	{
-		// Call polymorphic load
-		loadFromSource();
-	}
-
-	void D3D11GpuProgram::loadFromSource(void)
-	{
-		CM_EXCEPT(RenderingAPIException, "DirectX 11 doesn't support assembly shaders.");
-	}
-
-	D3D11GpuVertexProgram::D3D11GpuVertexProgram() 
-		: D3D11GpuProgram(GPT_VERTEX_PROGRAM)
-		, mVertexShader(nullptr)
-	{ }
-
-	D3D11GpuVertexProgram::~D3D11GpuVertexProgram()
-	{
-		// have to call this here reather than in Resource destructor
-		// since calling virtual methods in base destructors causes crash
-		unload_internal(); 
-	}
-
-	void D3D11GpuVertexProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob*  microcode)
-	{
-		if (isSupported())
-		{
-			// Create the shader
-			HRESULT hr = device.getD3D11Device()->CreateVertexShader( 
-				static_cast<DWORD*>(microcode->GetBufferPointer()), 
-				microcode->GetBufferSize(),
-				device.getClassLinkage(),
-				&mVertexShader);
-
-			if (FAILED(hr) || device.hasError())
-			{
-				String errorDescription = device.getErrorDescription();
-				CM_EXCEPT(RenderingAPIException, 
-					"Cannot create D3D11 vertex shader from microcode\nError Description:" + errorDescription);
-
-			}
-		}
-		else
-		{
-			LOGWRN("Unsupported D3D11 vertex shader was not loaded.");
-		}
-	}
-
-	void D3D11GpuVertexProgram::unloadImpl(void)
-	{
-		SAFE_RELEASE(mVertexShader);
-	}
-
-	ID3D11VertexShader * D3D11GpuVertexProgram::getVertexShader( void ) const
-	{
-		return mVertexShader;
-	}
-
-	D3D11GpuFragmentProgram::D3D11GpuFragmentProgram() 
-		: D3D11GpuProgram(GPT_FRAGMENT_PROGRAM)
-		, mPixelShader(nullptr)
-	{ }
-
-	D3D11GpuFragmentProgram::~D3D11GpuFragmentProgram()
-	{
-		unload_internal(); 
-	}
-
-	void D3D11GpuFragmentProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
-	{
-		if (isSupported())
-		{
-			// Create the shader
-			HRESULT hr = device.getD3D11Device()->CreatePixelShader(
-				static_cast<DWORD*>(microcode->GetBufferPointer()), 
-				microcode->GetBufferSize(),
-				device.getClassLinkage(),
-				&mPixelShader);
-
-			if (FAILED(hr) || device.hasError())
-			{
-				String errorDescription = device.getErrorDescription();
-				CM_EXCEPT(RenderingAPIException, 
-					"Cannot create D3D11 pixel shader from microcode.\nError Description:" + errorDescription);
-			}
-		}
-		else
-		{
-			LOGWRN("Unsupported D3D11 pixel shader was not loaded.");
-		}
-	}
-
-	void D3D11GpuFragmentProgram::unloadImpl(void)
-	{
-		SAFE_RELEASE(mPixelShader);
-	}
-
-	ID3D11PixelShader * D3D11GpuFragmentProgram::getPixelShader( void ) const
-	{
-		return mPixelShader;
-	}
-
-	D3D11GpuGeometryProgram::D3D11GpuGeometryProgram() 
-		: D3D11GpuProgram(GPT_GEOMETRY_PROGRAM)
-		, mGeometryShader(nullptr)
-	{ }
-
-	D3D11GpuGeometryProgram::~D3D11GpuGeometryProgram()
-	{
-		unload_internal(); 
-	}
-
-	void D3D11GpuGeometryProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
-	{
-		if (isSupported())
-		{
-			// Create the shader
-			HRESULT hr = device.getD3D11Device()->CreateGeometryShader(
-				static_cast<DWORD*>(microcode->GetBufferPointer()), 
-				microcode->GetBufferSize(),
-				device.getClassLinkage(),
-				&mGeometryShader);
-
-			if (FAILED(hr) || device.hasError())
-			{
-				String errorDescription = device.getErrorDescription();
-				CM_EXCEPT(RenderingAPIException, 
-					"Cannot create D3D11 geometry shader from microcode.\nError Description:" + errorDescription);
-			}
-		}
-		else
-		{
-			LOGWRN("Unsupported D3D11 geometry shader was not loaded.");
-		}
-	}
-
-	void D3D11GpuGeometryProgram::unloadImpl(void)
-	{
-		SAFE_RELEASE(mGeometryShader);
-	}
-
-	ID3D11GeometryShader * D3D11GpuGeometryProgram::getGeometryShader(void) const
-	{
-		return mGeometryShader;
-	}
-
-	D3D11GpuDomainProgram::D3D11GpuDomainProgram() 
-		: D3D11GpuProgram(GPT_DOMAIN_PROGRAM)
-		, mDomainShader(nullptr)
-	{ }
-
-	D3D11GpuDomainProgram::~D3D11GpuDomainProgram()
-	{
-		unload_internal(); 
-	}
-
-	void D3D11GpuDomainProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
-	{
-		if (isSupported())
-		{
-			// Create the shader
-			HRESULT hr = device.getD3D11Device()->CreateDomainShader(
-				static_cast<DWORD*>(microcode->GetBufferPointer()), 
-				microcode->GetBufferSize(),
-				device.getClassLinkage(),
-				&mDomainShader);
-
-			if (FAILED(hr) || device.hasError())
-			{
-				String errorDescription = device.getErrorDescription();
-				CM_EXCEPT(RenderingAPIException, 
-					"Cannot create D3D11 domain shader from microcode.\nError Description:" + errorDescription);
-			}
-		}
-		else
-		{
-			LOGWRN("Unsupported D3D11 domain shader was not loaded.");
-		}
-	}
-
-	void D3D11GpuDomainProgram::unloadImpl(void)
-	{
-		SAFE_RELEASE(mDomainShader);
-	}
-
-	ID3D11DomainShader * D3D11GpuDomainProgram::getDomainShader(void) const
-	{
-		return mDomainShader;
-	}
-
-	D3D11GpuHullProgram::D3D11GpuHullProgram() 
-		: D3D11GpuProgram(GPT_HULL_PROGRAM)
-		, mHullShader(nullptr)
-	{ }
-
-	D3D11GpuHullProgram::~D3D11GpuHullProgram()
-	{
-		unload_internal(); 
-	}
-
-	void D3D11GpuHullProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
-	{
-		if (isSupported())
-		{
-			// Create the shader
-			HRESULT hr = device.getD3D11Device()->CreateHullShader(
-				static_cast<DWORD*>(microcode->GetBufferPointer()), 
-				microcode->GetBufferSize(),
-				device.getClassLinkage(),
-				&mHullShader);
-
-			if (FAILED(hr) || device.hasError())
-			{
-				String errorDescription = device.getErrorDescription();
-				CM_EXCEPT(RenderingAPIException, 
-					"Cannot create D3D11 hull shader from microcode.\nError Description:" + errorDescription);
-			}
-		}
-		else
-		{
-			LOGWRN("Unsupported D3D11 hull shader was not loaded.");
-		}
-	}
-
-	void D3D11GpuHullProgram::unloadImpl(void)
-	{
-		SAFE_RELEASE(mHullShader);
-	}
-
-	ID3D11HullShader* D3D11GpuHullProgram::getHullShader(void) const
-	{
-		return mHullShader;
+{
+	D3D11GpuProgram::D3D11GpuProgram(GpuProgramType type, const String& profile) 
+		: GpuProgram("", "", profile, type, GPP_NONE)
+	{
+
+	}
+
+	void D3D11GpuProgram::loadImpl(void)
+	{
+		// Call polymorphic load
+		loadFromSource();
+	}
+
+	void D3D11GpuProgram::loadFromSource(void)
+	{
+		CM_EXCEPT(RenderingAPIException, "DirectX 11 doesn't support assembly shaders.");
+	}
+
+	D3D11GpuVertexProgram::D3D11GpuVertexProgram(const String& profile) 
+		: D3D11GpuProgram(GPT_VERTEX_PROGRAM, profile)
+		, mVertexShader(nullptr)
+	{ }
+
+	D3D11GpuVertexProgram::~D3D11GpuVertexProgram()
+	{
+		// have to call this here reather than in Resource destructor
+		// since calling virtual methods in base destructors causes crash
+		unload_internal(); 
+	}
+
+	void D3D11GpuVertexProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob*  microcode)
+	{
+		if (isSupported())
+		{
+			// Create the shader
+			HRESULT hr = device.getD3D11Device()->CreateVertexShader( 
+				static_cast<DWORD*>(microcode->GetBufferPointer()), 
+				microcode->GetBufferSize(),
+				device.getClassLinkage(),
+				&mVertexShader);
+
+			if (FAILED(hr) || device.hasError())
+			{
+				String errorDescription = device.getErrorDescription();
+				CM_EXCEPT(RenderingAPIException, 
+					"Cannot create D3D11 vertex shader from microcode\nError Description:" + errorDescription);
+
+			}
+		}
+		else
+		{
+			LOGWRN("Unsupported D3D11 vertex shader was not loaded.");
+		}
+	}
+
+	void D3D11GpuVertexProgram::unloadImpl(void)
+	{
+		SAFE_RELEASE(mVertexShader);
+	}
+
+	ID3D11VertexShader * D3D11GpuVertexProgram::getVertexShader( void ) const
+	{
+		return mVertexShader;
+	}
+
+	D3D11GpuFragmentProgram::D3D11GpuFragmentProgram(const String& profile) 
+		: D3D11GpuProgram(GPT_FRAGMENT_PROGRAM, profile)
+		, mPixelShader(nullptr)
+	{ }
+
+	D3D11GpuFragmentProgram::~D3D11GpuFragmentProgram()
+	{
+		unload_internal(); 
+	}
+
+	void D3D11GpuFragmentProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
+	{
+		if (isSupported())
+		{
+			// Create the shader
+			HRESULT hr = device.getD3D11Device()->CreatePixelShader(
+				static_cast<DWORD*>(microcode->GetBufferPointer()), 
+				microcode->GetBufferSize(),
+				device.getClassLinkage(),
+				&mPixelShader);
+
+			if (FAILED(hr) || device.hasError())
+			{
+				String errorDescription = device.getErrorDescription();
+				CM_EXCEPT(RenderingAPIException, 
+					"Cannot create D3D11 pixel shader from microcode.\nError Description:" + errorDescription);
+			}
+		}
+		else
+		{
+			LOGWRN("Unsupported D3D11 pixel shader was not loaded.");
+		}
+	}
+
+	void D3D11GpuFragmentProgram::unloadImpl(void)
+	{
+		SAFE_RELEASE(mPixelShader);
+	}
+
+	ID3D11PixelShader * D3D11GpuFragmentProgram::getPixelShader( void ) const
+	{
+		return mPixelShader;
+	}
+
+	D3D11GpuGeometryProgram::D3D11GpuGeometryProgram(const String& profile) 
+		: D3D11GpuProgram(GPT_GEOMETRY_PROGRAM, profile)
+		, mGeometryShader(nullptr)
+	{ }
+
+	D3D11GpuGeometryProgram::~D3D11GpuGeometryProgram()
+	{
+		unload_internal(); 
+	}
+
+	void D3D11GpuGeometryProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
+	{
+		if (isSupported())
+		{
+			// Create the shader
+			HRESULT hr = device.getD3D11Device()->CreateGeometryShader(
+				static_cast<DWORD*>(microcode->GetBufferPointer()), 
+				microcode->GetBufferSize(),
+				device.getClassLinkage(),
+				&mGeometryShader);
+
+			if (FAILED(hr) || device.hasError())
+			{
+				String errorDescription = device.getErrorDescription();
+				CM_EXCEPT(RenderingAPIException, 
+					"Cannot create D3D11 geometry shader from microcode.\nError Description:" + errorDescription);
+			}
+		}
+		else
+		{
+			LOGWRN("Unsupported D3D11 geometry shader was not loaded.");
+		}
+	}
+
+	void D3D11GpuGeometryProgram::unloadImpl(void)
+	{
+		SAFE_RELEASE(mGeometryShader);
+	}
+
+	ID3D11GeometryShader * D3D11GpuGeometryProgram::getGeometryShader(void) const
+	{
+		return mGeometryShader;
+	}
+
+	D3D11GpuDomainProgram::D3D11GpuDomainProgram(const String& profile) 
+		: D3D11GpuProgram(GPT_DOMAIN_PROGRAM, profile)
+		, mDomainShader(nullptr)
+	{ }
+
+	D3D11GpuDomainProgram::~D3D11GpuDomainProgram()
+	{
+		unload_internal(); 
+	}
+
+	void D3D11GpuDomainProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
+	{
+		if (isSupported())
+		{
+			// Create the shader
+			HRESULT hr = device.getD3D11Device()->CreateDomainShader(
+				static_cast<DWORD*>(microcode->GetBufferPointer()), 
+				microcode->GetBufferSize(),
+				device.getClassLinkage(),
+				&mDomainShader);
+
+			if (FAILED(hr) || device.hasError())
+			{
+				String errorDescription = device.getErrorDescription();
+				CM_EXCEPT(RenderingAPIException, 
+					"Cannot create D3D11 domain shader from microcode.\nError Description:" + errorDescription);
+			}
+		}
+		else
+		{
+			LOGWRN("Unsupported D3D11 domain shader was not loaded.");
+		}
+	}
+
+	void D3D11GpuDomainProgram::unloadImpl(void)
+	{
+		SAFE_RELEASE(mDomainShader);
+	}
+
+	ID3D11DomainShader * D3D11GpuDomainProgram::getDomainShader(void) const
+	{
+		return mDomainShader;
+	}
+
+	D3D11GpuHullProgram::D3D11GpuHullProgram(const String& profile) 
+		: D3D11GpuProgram(GPT_HULL_PROGRAM, profile)
+		, mHullShader(nullptr)
+	{ }
+
+	D3D11GpuHullProgram::~D3D11GpuHullProgram()
+	{
+		unload_internal(); 
+	}
+
+	void D3D11GpuHullProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
+	{
+		if (isSupported())
+		{
+			// Create the shader
+			HRESULT hr = device.getD3D11Device()->CreateHullShader(
+				static_cast<DWORD*>(microcode->GetBufferPointer()), 
+				microcode->GetBufferSize(),
+				device.getClassLinkage(),
+				&mHullShader);
+
+			if (FAILED(hr) || device.hasError())
+			{
+				String errorDescription = device.getErrorDescription();
+				CM_EXCEPT(RenderingAPIException, 
+					"Cannot create D3D11 hull shader from microcode.\nError Description:" + errorDescription);
+			}
+		}
+		else
+		{
+			LOGWRN("Unsupported D3D11 hull shader was not loaded.");
+		}
+	}
+
+	void D3D11GpuHullProgram::unloadImpl(void)
+	{
+		SAFE_RELEASE(mHullShader);
+	}
+
+	ID3D11HullShader* D3D11GpuHullProgram::getHullShader(void) const
+	{
+		return mHullShader;
+	}
+
+	D3D11GpuComputeProgram::D3D11GpuComputeProgram(const String& profile) 
+		: D3D11GpuProgram(GPT_COMPUTE_PROGRAM, profile)
+		, mComputeShader(nullptr)
+	{ }
+
+	D3D11GpuComputeProgram::~D3D11GpuComputeProgram()
+	{
+		unload_internal(); 
+	}
+
+	void D3D11GpuComputeProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
+	{
+		if (isSupported())
+		{
+			// Create the shader
+			HRESULT hr = device.getD3D11Device()->CreateComputeShader(
+				static_cast<DWORD*>(microcode->GetBufferPointer()), 
+				microcode->GetBufferSize(),
+				device.getClassLinkage(),
+				&mComputeShader);
+
+			if (FAILED(hr) || device.hasError())
+			{
+				String errorDescription = device.getErrorDescription();
+				CM_EXCEPT(RenderingAPIException, 
+					"Cannot create D3D11 compute shader from microcode.\nError Description:" + errorDescription);
+			}
+		}
+		else
+		{
+			LOGWRN("Unsupported D3D11 compute shader was not loaded.");
+		}
+	}
+
+	void D3D11GpuComputeProgram::unloadImpl(void)
+	{
+		SAFE_RELEASE(mComputeShader);
 	}
 
-	D3D11GpuComputeProgram::D3D11GpuComputeProgram() 
-		: D3D11GpuProgram(GPT_COMPUTE_PROGRAM)
-		, mComputeShader(nullptr)
-	{ }
-
-	D3D11GpuComputeProgram::~D3D11GpuComputeProgram()
-	{
-		unload_internal(); 
-	}
-
-	void D3D11GpuComputeProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
-	{
-		if (isSupported())
-		{
-			// Create the shader
-			HRESULT hr = device.getD3D11Device()->CreateComputeShader(
-				static_cast<DWORD*>(microcode->GetBufferPointer()), 
-				microcode->GetBufferSize(),
-				device.getClassLinkage(),
-				&mComputeShader);
-
-			if (FAILED(hr) || device.hasError())
-			{
-				String errorDescription = device.getErrorDescription();
-				CM_EXCEPT(RenderingAPIException, 
-					"Cannot create D3D11 compute shader from microcode.\nError Description:" + errorDescription);
-			}
-		}
-		else
-		{
-			LOGWRN("Unsupported D3D11 compute shader was not loaded.");
-		}
-	}
-
-	void D3D11GpuComputeProgram::unloadImpl(void)
-	{
-		SAFE_RELEASE(mComputeShader);
-	}
-
-	ID3D11ComputeShader* D3D11GpuComputeProgram::getComputeShader(void) const
-	{
-		return mComputeShader;
+	ID3D11ComputeShader* D3D11GpuComputeProgram::getComputeShader(void) const
+	{
+		return mComputeShader;
 	}
 }

+ 5 - 5
CamelotD3D11RenderSystem/Source/CmD3D11GpuProgramManager.cpp

@@ -16,15 +16,15 @@ namespace CamelotEngine
 		switch(gptype)
 		{
 		case GPT_VERTEX_PROGRAM:
-			return new D3D11GpuVertexProgram();
+			return new D3D11GpuVertexProgram(language);
 		case GPT_FRAGMENT_PROGRAM:
-			return new D3D11GpuFragmentProgram();
+			return new D3D11GpuFragmentProgram(language);
 		case GPT_HULL_PROGRAM:
-			return new D3D11GpuHullProgram();
+			return new D3D11GpuHullProgram(language);
 		case GPT_DOMAIN_PROGRAM:
-			return new D3D11GpuDomainProgram();
+			return new D3D11GpuDomainProgram(language);
 		case GPT_GEOMETRY_PROGRAM:
-			return new D3D11GpuGeometryProgram();
+			return new D3D11GpuGeometryProgram(language);
 		}
 		
 		return nullptr;

+ 6 - 4
CamelotD3D11RenderSystem/Source/CmD3D11HLSLProgram.cpp

@@ -24,7 +24,9 @@ namespace CamelotEngine
 
     void D3D11HLSLProgram::loadFromSource()
 	{
-		ID3DBlob* microcode = compileMicrocode();
+		String hlslProfile = GpuProgramManager::instance().gpuProgProfileToRSSpecificProfile(mProfile);
+
+		ID3DBlob* microcode = compileMicrocode(hlslProfile);
 
 		mMicrocode.resize(microcode->GetBufferSize());
 		memcpy(&mMicrocode[0], microcode->GetBufferPointer(), microcode->GetBufferSize());
@@ -33,7 +35,7 @@ namespace CamelotEngine
 
 		createConstantBuffers();
 
-		mAssemblerProgram = GpuProgramManager::instance().createProgram("", "", "", mType, GPP_NONE); // We load it from microcode, so none of this matters
+		mAssemblerProgram = GpuProgramManager::instance().createProgram("", "", hlslProfile, mType, GPP_NONE); // We load it from microcode, so none of this matters
 		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
 
 		switch(mType)
@@ -96,7 +98,7 @@ namespace CamelotEngine
 		return rs->getCapabilities()->isShaderProfileSupported(getSyntaxCode()) && HighLevelGpuProgram::isSupported();
 	}
 
-	ID3DBlob* D3D11HLSLProgram::compileMicrocode()
+	ID3DBlob* D3D11HLSLProgram::compileMicrocode(const String& profile)
 	{
 		// TODO - Preprocessor defines aren't supported
 
@@ -124,7 +126,7 @@ namespace CamelotEngine
 			nullptr,			// [in] Optional. Pointer to a NULL-terminated array of macro definitions. See D3D_SHADER_MACRO. If not used, set this to NULL. 
 			nullptr,			// [in] Optional. Pointer to an ID3DInclude Interface interface for handling include files. Setting this to NULL will cause a compile error if a shader contains a #include. 
 			mEntryPoint.c_str(),// [in] Name of the shader-entrypoint function where shader execution begins. 
-			mSyntaxCode.c_str(),// [in] A string that specifies the shader model; can be any profile in shader model 4 or higher. 
+			profile.c_str(),// [in] A string that specifies the shader model; can be any profile in shader model 4 or higher. 
 			compileFlags,		// [in] Effect compile flags - no D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY at the first try...
 			0,					// [in] Effect compile flags
 			&microCode,			// [out] A pointer to an ID3DBlob Interface which contains the compiled shader, as well as any embedded debug and symbol-table information. 

+ 10 - 0
CamelotD3D11RenderSystem/Source/CmD3D11Plugin.cpp

@@ -0,0 +1,10 @@
+#include "CmD3D11Prerequisites.h"
+#include "CmD3D11RenderSystemFactory.h"
+
+namespace CamelotEngine
+{
+	extern "C" CM_D3D11_EXPORT const String& getPluginName()
+	{
+		return SystemName;
+	}
+}

+ 7 - 1
CamelotD3D11RenderSystem/Source/CmD3D11RasterizerState.cpp

@@ -31,6 +31,12 @@ namespace CamelotEngine
 
 		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
 		D3D11Device& device = rs->getPrimaryDevice();
-		device.getD3D11Device()->CreateRasterizerState(&rasterizerStateDesc, &mRasterizerState);
+		HRESULT hr = device.getD3D11Device()->CreateRasterizerState(&rasterizerStateDesc, &mRasterizerState);
+
+		if(FAILED(hr) || device.hasError())
+		{
+			String errorDescription = device.getErrorDescription();
+			CM_EXCEPT(RenderingAPIException, "Cannot create rasterizer state.\nError Description:" + errorDescription);
+		}
 	}
 }

+ 135 - 126
CamelotD3D11RenderSystem/Source/CmD3D11RenderSystem.cpp

@@ -17,7 +17,7 @@
 #include "CmD3D11Mappings.h"
 #include "CmD3D11VertexBuffer.h"
 #include "CmD3D11IndexBuffer.h"
-#include "CmRenderSystem.h"
+#include "CmD3D11RenderStateManager.h"
 #include "CmDebug.h"
 #include "CmException.h"
 
@@ -79,9 +79,15 @@ namespace CamelotEngine
 
 		UINT32 numRequestedLevel = sizeof(requestedLevels) / sizeof(requestedLevels[0]);
 
+		UINT32 deviceFlags = 0;
+
+#if CM_DEBUG_MODE
+		deviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
+#endif
+
 		ID3D11Device* device;
-		hr = D3D11CreateDevice(selectedAdapter, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0, 
-			requestedLevels, numRequestedLevel, D3D11_SDK_VERSION, &device, &mFeatureLevel, 0);
+		hr = D3D11CreateDevice(selectedAdapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr, deviceFlags, 
+			requestedLevels, numRequestedLevel, D3D11_SDK_VERSION, &device, &mFeatureLevel, nullptr);
 
 		if(FAILED(hr))         
 			CM_EXCEPT(RenderingAPIException, "Failed to create Direct3D11 object. D3D11CreateDeviceN returned this error code: " + toString(hr));
@@ -112,6 +118,14 @@ namespace CamelotEngine
 		// Create & register HLSL factory		
 		mHLSLFactory = new D3D11HLSLProgramFactory();
 
+		// Create render state manager
+		RenderStateManager::startUp(new D3D11RenderStateManager());
+
+		mCurrentCapabilities = createRenderSystemCapabilities();
+
+		mCurrentCapabilities->addShaderProfile("hlsl");
+		HighLevelGpuProgramManager::instance().addFactory(mHLSLFactory);
+
 		RenderSystem::initialize_internal();
 	}
 
@@ -121,6 +135,7 @@ namespace CamelotEngine
 
 		SAFE_DELETE(mHLSLFactory);
 
+		RenderStateManager::shutDown();
 		RenderWindowManager::shutDown();
 		GpuProgramManager::shutDown();
 		HardwareBufferManager::shutDown();
@@ -134,7 +149,7 @@ namespace CamelotEngine
 		RenderSystem::destroy_internal();
 	}
 
-	void D3D11RenderSystem::setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerState& samplerState)
+	void D3D11RenderSystem::setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerStatePtr& samplerState)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
@@ -142,7 +157,7 @@ namespace CamelotEngine
 		//  and then set them all up at once before rendering? Needs testing
 
 		ID3D11SamplerState* samplerArray[1];
-		D3D11SamplerState* d3d11SamplerState = static_cast<D3D11SamplerState*>(const_cast<SamplerState*>(&samplerState));
+		D3D11SamplerState* d3d11SamplerState = static_cast<D3D11SamplerState*>(const_cast<SamplerState*>(samplerState.get()));
 		samplerArray[0] = d3d11SamplerState->getInternal();
 
 		switch(gptype)
@@ -170,27 +185,27 @@ namespace CamelotEngine
 		}
 	}
 
-	void D3D11RenderSystem::setBlendState(const BlendState& blendState)
+	void D3D11RenderSystem::setBlendState(const BlendStatePtr& blendState)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
-		D3D11BlendState* d3d11BlendState = static_cast<D3D11BlendState*>(const_cast<BlendState*>(&blendState));
+		D3D11BlendState* d3d11BlendState = static_cast<D3D11BlendState*>(const_cast<BlendState*>(blendState.get()));
 		mDevice->getImmediateContext()->OMSetBlendState(d3d11BlendState->getInternal(), nullptr, 0xFFFFFFFF);
 	}
 
-	void D3D11RenderSystem::setRasterizerState(const RasterizerState& rasterizerState)
+	void D3D11RenderSystem::setRasterizerState(const RasterizerStatePtr& rasterizerState)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
-		D3D11RasterizerState* d3d11RasterizerState = static_cast<D3D11RasterizerState*>(const_cast<RasterizerState*>(&rasterizerState));
+		D3D11RasterizerState* d3d11RasterizerState = static_cast<D3D11RasterizerState*>(const_cast<RasterizerState*>(rasterizerState.get()));
 		mDevice->getImmediateContext()->RSSetState(d3d11RasterizerState->getInternal());
 	}
 
-	void D3D11RenderSystem::setDepthStencilState(const DepthStencilState& depthStencilState, UINT32 stencilRefValue)
+	void D3D11RenderSystem::setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
-		D3D11DepthStencilState* d3d11RasterizerState = static_cast<D3D11DepthStencilState*>(const_cast<DepthStencilState*>(&depthStencilState));
+		D3D11DepthStencilState* d3d11RasterizerState = static_cast<D3D11DepthStencilState*>(const_cast<DepthStencilState*>(depthStencilState.get()));
 		mDevice->getImmediateContext()->OMSetDepthStencilState(d3d11RasterizerState->getInternal(), stencilRefValue);
 	}
 
@@ -517,118 +532,113 @@ namespace CamelotEngine
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
-		throw std::exception("The method or operation is not implemented.");
-	}
+		RenderSystemCapabilities* rsc = new RenderSystemCapabilities();
 
-	void D3D11RenderSystem::initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps)
-	{
-		mCurrentCapabilities = new RenderSystemCapabilities();
+		rsc->setDriverVersion(mDriverVersion);
+		rsc->setDeviceName(mActiveD3DDriver->getDriverDescription());
+		rsc->setRenderSystemName(getName());
 
-		mCurrentCapabilities->setDriverVersion(mDriverVersion);
-		mCurrentCapabilities->setDeviceName(mActiveD3DDriver->getDriverDescription());
-		mCurrentCapabilities->setRenderSystemName(getName());
+		rsc->setCapability(RSC_HWSTENCIL);
+		rsc->setStencilBufferBitDepth(8);
 
-		mCurrentCapabilities->setCapability(RSC_HWSTENCIL);
-		mCurrentCapabilities->setStencilBufferBitDepth(8);
-
-		mCurrentCapabilities->setCapability(RSC_ANISOTROPY);
-		mCurrentCapabilities->setCapability(RSC_AUTOMIPMAP);
-		mCurrentCapabilities->setCapability(RSC_BLENDING);
-		mCurrentCapabilities->setCapability(RSC_DOT3);
+		rsc->setCapability(RSC_ANISOTROPY);
+		rsc->setCapability(RSC_AUTOMIPMAP);
+		rsc->setCapability(RSC_BLENDING);
+		rsc->setCapability(RSC_DOT3);
 
 		// Cube map
-		mCurrentCapabilities->setCapability(RSC_CUBEMAPPING);
+		rsc->setCapability(RSC_CUBEMAPPING);
 
 		// We always support compression, D3DX will decompress if device does not support
-		mCurrentCapabilities->setCapability(RSC_TEXTURE_COMPRESSION);
-		mCurrentCapabilities->setCapability(RSC_TEXTURE_COMPRESSION_DXT);
-		mCurrentCapabilities->setCapability(RSC_VBO);
-		mCurrentCapabilities->setCapability(RSC_SCISSOR_TEST);
-		mCurrentCapabilities->setCapability(RSC_TWO_SIDED_STENCIL);
-		mCurrentCapabilities->setCapability(RSC_STENCIL_WRAP);
-		mCurrentCapabilities->setCapability(RSC_HWOCCLUSION);
-		mCurrentCapabilities->setCapability(RSC_HWOCCLUSION_ASYNCHRONOUS);
+		rsc->setCapability(RSC_TEXTURE_COMPRESSION);
+		rsc->setCapability(RSC_TEXTURE_COMPRESSION_DXT);
+		rsc->setCapability(RSC_VBO);
+		rsc->setCapability(RSC_SCISSOR_TEST);
+		rsc->setCapability(RSC_TWO_SIDED_STENCIL);
+		rsc->setCapability(RSC_STENCIL_WRAP);
+		rsc->setCapability(RSC_HWOCCLUSION);
+		rsc->setCapability(RSC_HWOCCLUSION_ASYNCHRONOUS);
 
 		if(mFeatureLevel >= D3D_FEATURE_LEVEL_10_1)
-			mCurrentCapabilities->setMaxBoundVertexBuffers(32);
+			rsc->setMaxBoundVertexBuffers(32);
 		else
-			mCurrentCapabilities->setMaxBoundVertexBuffers(16);
+			rsc->setMaxBoundVertexBuffers(16);
 
 		if(mFeatureLevel >= D3D_FEATURE_LEVEL_10_0)
 		{
-			mCurrentCapabilities->addShaderProfile("ps_4_0");
-			mCurrentCapabilities->addShaderProfile("vs_4_0");
-			mCurrentCapabilities->addShaderProfile("gs_4_0");
-
-			mCurrentCapabilities->addGpuProgramProfile(GPP_PS_4_0, "ps_4_0");
-			mCurrentCapabilities->addGpuProgramProfile(GPP_VS_4_0, "vs_4_0");
-			mCurrentCapabilities->addGpuProgramProfile(GPP_GS_4_0, "gs_4_0");
-			 
-			mCurrentCapabilities->setNumTextureUnits(GPT_FRAGMENT_PROGRAM, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT);
-			mCurrentCapabilities->setNumTextureUnits(GPT_VERTEX_PROGRAM, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT);
-			mCurrentCapabilities->setNumTextureUnits(GPT_GEOMETRY_PROGRAM, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT);
-
-			mCurrentCapabilities->setNumCombinedTextureUnits(mCurrentCapabilities->getNumTextureUnits(GPT_FRAGMENT_PROGRAM)
-				+ mCurrentCapabilities->getNumTextureUnits(GPT_VERTEX_PROGRAM) + mCurrentCapabilities->getNumTextureUnits(GPT_VERTEX_PROGRAM));
-
-			mCurrentCapabilities->setNumUniformBlockBuffers(GPT_FRAGMENT_PROGRAM, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
-			mCurrentCapabilities->setNumUniformBlockBuffers(GPT_VERTEX_PROGRAM, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
-			mCurrentCapabilities->setNumUniformBlockBuffers(GPT_GEOMETRY_PROGRAM, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
-
-			mCurrentCapabilities->setNumCombinedUniformBlockBuffers(mCurrentCapabilities->getNumUniformBlockBuffers(GPT_FRAGMENT_PROGRAM)
-				+ mCurrentCapabilities->getNumUniformBlockBuffers(GPT_VERTEX_PROGRAM) + mCurrentCapabilities->getNumUniformBlockBuffers(GPT_VERTEX_PROGRAM));
+			rsc->addShaderProfile("ps_4_0");
+			rsc->addShaderProfile("vs_4_0");
+			rsc->addShaderProfile("gs_4_0");
+
+			rsc->addGpuProgramProfile(GPP_PS_4_0, "ps_4_0");
+			rsc->addGpuProgramProfile(GPP_VS_4_0, "vs_4_0");
+			rsc->addGpuProgramProfile(GPP_GS_4_0, "gs_4_0");
+
+			rsc->setNumTextureUnits(GPT_FRAGMENT_PROGRAM, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT);
+			rsc->setNumTextureUnits(GPT_VERTEX_PROGRAM, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT);
+			rsc->setNumTextureUnits(GPT_GEOMETRY_PROGRAM, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT);
+
+			rsc->setNumCombinedTextureUnits(rsc->getNumTextureUnits(GPT_FRAGMENT_PROGRAM)
+				+ rsc->getNumTextureUnits(GPT_VERTEX_PROGRAM) + rsc->getNumTextureUnits(GPT_VERTEX_PROGRAM));
+
+			rsc->setNumUniformBlockBuffers(GPT_FRAGMENT_PROGRAM, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
+			rsc->setNumUniformBlockBuffers(GPT_VERTEX_PROGRAM, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
+			rsc->setNumUniformBlockBuffers(GPT_GEOMETRY_PROGRAM, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
+
+			rsc->setNumCombinedUniformBlockBuffers(rsc->getNumUniformBlockBuffers(GPT_FRAGMENT_PROGRAM)
+				+ rsc->getNumUniformBlockBuffers(GPT_VERTEX_PROGRAM) + rsc->getNumUniformBlockBuffers(GPT_VERTEX_PROGRAM));
 		}
-		
+
 		if(mFeatureLevel >= D3D_FEATURE_LEVEL_10_1)
 		{
-			mCurrentCapabilities->addShaderProfile("ps_4_1");
-			mCurrentCapabilities->addShaderProfile("vs_4_1");
-			mCurrentCapabilities->addShaderProfile("gs_4_1");
+			rsc->addShaderProfile("ps_4_1");
+			rsc->addShaderProfile("vs_4_1");
+			rsc->addShaderProfile("gs_4_1");
 
-			mCurrentCapabilities->addGpuProgramProfile(GPP_PS_4_1, "ps_4_1");
-			mCurrentCapabilities->addGpuProgramProfile(GPP_VS_4_1, "vs_4_1");
-			mCurrentCapabilities->addGpuProgramProfile(GPP_GS_4_1, "gs_4_1");
+			rsc->addGpuProgramProfile(GPP_PS_4_1, "ps_4_1");
+			rsc->addGpuProgramProfile(GPP_VS_4_1, "vs_4_1");
+			rsc->addGpuProgramProfile(GPP_GS_4_1, "gs_4_1");
 		}
 
 		if(mFeatureLevel >= D3D_FEATURE_LEVEL_11_0)
 		{
-			mCurrentCapabilities->addShaderProfile("ps_5_0");
-			mCurrentCapabilities->addShaderProfile("vs_5_0");
-			mCurrentCapabilities->addShaderProfile("gs_5_0");
-			mCurrentCapabilities->addShaderProfile("cs_5_0");
-			mCurrentCapabilities->addShaderProfile("hs_5_0");
-			mCurrentCapabilities->addShaderProfile("ds_5_0");
-
-			mCurrentCapabilities->addGpuProgramProfile(GPP_PS_5_0, "ps_5_0");
-			mCurrentCapabilities->addGpuProgramProfile(GPP_VS_5_0, "vs_5_0");
-			mCurrentCapabilities->addGpuProgramProfile(GPP_GS_5_0, "gs_5_0");
-			mCurrentCapabilities->addGpuProgramProfile(GPP_CS_5_0, "cs_5_0");
-			mCurrentCapabilities->addGpuProgramProfile(GPP_HS_5_0, "hs_5_0");
-			mCurrentCapabilities->addGpuProgramProfile(GPP_DS_5_0, "ds_5_0");
-
-			mCurrentCapabilities->setNumTextureUnits(GPT_HULL_PROGRAM, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT);
-			mCurrentCapabilities->setNumTextureUnits(GPT_DOMAIN_PROGRAM, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT);
-			mCurrentCapabilities->setNumTextureUnits(GPT_COMPUTE_PROGRAM, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT);
-
-			mCurrentCapabilities->setNumCombinedTextureUnits(mCurrentCapabilities->getNumTextureUnits(GPT_FRAGMENT_PROGRAM)
-				+ mCurrentCapabilities->getNumTextureUnits(GPT_VERTEX_PROGRAM) + mCurrentCapabilities->getNumTextureUnits(GPT_VERTEX_PROGRAM)
-				+ mCurrentCapabilities->getNumTextureUnits(GPT_HULL_PROGRAM) + mCurrentCapabilities->getNumTextureUnits(GPT_DOMAIN_PROGRAM)
-				+ mCurrentCapabilities->getNumTextureUnits(GPT_COMPUTE_PROGRAM));
-
-			mCurrentCapabilities->setNumUniformBlockBuffers(GPT_HULL_PROGRAM, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
-			mCurrentCapabilities->setNumUniformBlockBuffers(GPT_DOMAIN_PROGRAM, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
-			mCurrentCapabilities->setNumUniformBlockBuffers(GPT_COMPUTE_PROGRAM, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
-
-			mCurrentCapabilities->setNumCombinedUniformBlockBuffers(mCurrentCapabilities->getNumUniformBlockBuffers(GPT_FRAGMENT_PROGRAM)
-				+ mCurrentCapabilities->getNumUniformBlockBuffers(GPT_VERTEX_PROGRAM) + mCurrentCapabilities->getNumUniformBlockBuffers(GPT_VERTEX_PROGRAM)
-				+ mCurrentCapabilities->getNumUniformBlockBuffers(GPT_HULL_PROGRAM) + mCurrentCapabilities->getNumUniformBlockBuffers(GPT_DOMAIN_PROGRAM)
-				+ mCurrentCapabilities->getNumUniformBlockBuffers(GPT_COMPUTE_PROGRAM));
-
-			mCurrentCapabilities->setCapability(RSC_SHADER_SUBROUTINE);
+			rsc->addShaderProfile("ps_5_0");
+			rsc->addShaderProfile("vs_5_0");
+			rsc->addShaderProfile("gs_5_0");
+			rsc->addShaderProfile("cs_5_0");
+			rsc->addShaderProfile("hs_5_0");
+			rsc->addShaderProfile("ds_5_0");
+
+			rsc->addGpuProgramProfile(GPP_PS_5_0, "ps_5_0");
+			rsc->addGpuProgramProfile(GPP_VS_5_0, "vs_5_0");
+			rsc->addGpuProgramProfile(GPP_GS_5_0, "gs_5_0");
+			rsc->addGpuProgramProfile(GPP_CS_5_0, "cs_5_0");
+			rsc->addGpuProgramProfile(GPP_HS_5_0, "hs_5_0");
+			rsc->addGpuProgramProfile(GPP_DS_5_0, "ds_5_0");
+
+			rsc->setNumTextureUnits(GPT_HULL_PROGRAM, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT);
+			rsc->setNumTextureUnits(GPT_DOMAIN_PROGRAM, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT);
+			rsc->setNumTextureUnits(GPT_COMPUTE_PROGRAM, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT);
+
+			rsc->setNumCombinedTextureUnits(rsc->getNumTextureUnits(GPT_FRAGMENT_PROGRAM)
+				+ rsc->getNumTextureUnits(GPT_VERTEX_PROGRAM) + rsc->getNumTextureUnits(GPT_VERTEX_PROGRAM)
+				+ rsc->getNumTextureUnits(GPT_HULL_PROGRAM) + rsc->getNumTextureUnits(GPT_DOMAIN_PROGRAM)
+				+ rsc->getNumTextureUnits(GPT_COMPUTE_PROGRAM));
+
+			rsc->setNumUniformBlockBuffers(GPT_HULL_PROGRAM, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
+			rsc->setNumUniformBlockBuffers(GPT_DOMAIN_PROGRAM, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
+			rsc->setNumUniformBlockBuffers(GPT_COMPUTE_PROGRAM, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
+
+			rsc->setNumCombinedUniformBlockBuffers(rsc->getNumUniformBlockBuffers(GPT_FRAGMENT_PROGRAM)
+				+ rsc->getNumUniformBlockBuffers(GPT_VERTEX_PROGRAM) + rsc->getNumUniformBlockBuffers(GPT_VERTEX_PROGRAM)
+				+ rsc->getNumUniformBlockBuffers(GPT_HULL_PROGRAM) + rsc->getNumUniformBlockBuffers(GPT_DOMAIN_PROGRAM)
+				+ rsc->getNumUniformBlockBuffers(GPT_COMPUTE_PROGRAM));
+
+			rsc->setCapability(RSC_SHADER_SUBROUTINE);
 		}
 
-		mCurrentCapabilities->setCapability(RSC_USER_CLIP_PLANES);
-		mCurrentCapabilities->setCapability(RSC_VERTEX_FORMAT_UBYTE4);
+		rsc->setCapability(RSC_USER_CLIP_PLANES);
+		rsc->setCapability(RSC_VERTEX_FORMAT_UBYTE4);
 
 		// Adapter details
 		const DXGI_ADAPTER_DESC& adapterID = mActiveD3DDriver->getAdapterIdentifier();
@@ -638,56 +648,55 @@ namespace CamelotEngine
 		switch(adapterID.VendorId)
 		{
 		case 0x10DE:
-			mCurrentCapabilities->setVendor(GPU_NVIDIA);
+			rsc->setVendor(GPU_NVIDIA);
 			break;
 		case 0x1002:
-			mCurrentCapabilities->setVendor(GPU_ATI);
+			rsc->setVendor(GPU_ATI);
 			break;
 		case 0x163C:
 		case 0x8086:
-			mCurrentCapabilities->setVendor(GPU_INTEL);
+			rsc->setVendor(GPU_INTEL);
 			break;
 		case 0x5333:
-			mCurrentCapabilities->setVendor(GPU_S3);
+			rsc->setVendor(GPU_S3);
 			break;
 		case 0x3D3D:
-			mCurrentCapabilities->setVendor(GPU_3DLABS);
+			rsc->setVendor(GPU_3DLABS);
 			break;
 		case 0x102B:
-			mCurrentCapabilities->setVendor(GPU_MATROX);
+			rsc->setVendor(GPU_MATROX);
 			break;
 		default:
-			mCurrentCapabilities->setVendor(GPU_UNKNOWN);
+			rsc->setVendor(GPU_UNKNOWN);
 			break;
 		};
 
-		mCurrentCapabilities->setCapability(RSC_INFINITE_FAR_PLANE);
-
-		mCurrentCapabilities->setCapability(RSC_TEXTURE_3D);
-		mCurrentCapabilities->setCapability(RSC_NON_POWER_OF_2_TEXTURES);
-		mCurrentCapabilities->setCapability(RSC_HWRENDER_TO_TEXTURE);
-		mCurrentCapabilities->setCapability(RSC_TEXTURE_FLOAT);
-
-		mCurrentCapabilities->setNumMultiRenderTargets(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT);
-		mCurrentCapabilities->setCapability(RSC_MRT_DIFFERENT_BIT_DEPTHS);
+		rsc->setCapability(RSC_INFINITE_FAR_PLANE);
 
-		mCurrentCapabilities->setCapability(RSC_POINT_SPRITES);
-		mCurrentCapabilities->setCapability(RSC_POINT_EXTENDED_PARAMETERS);
-		mCurrentCapabilities->setMaxPointSize(256);
+		rsc->setCapability(RSC_TEXTURE_3D);
+		rsc->setCapability(RSC_NON_POWER_OF_2_TEXTURES);
+		rsc->setCapability(RSC_HWRENDER_TO_TEXTURE);
+		rsc->setCapability(RSC_TEXTURE_FLOAT);
 
-		mCurrentCapabilities->setCapability(RSC_VERTEX_TEXTURE_FETCH);
+		rsc->setNumMultiRenderTargets(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT);
+		rsc->setCapability(RSC_MRT_DIFFERENT_BIT_DEPTHS);
 
-		mCurrentCapabilities->setCapability(RSC_MIPMAP_LOD_BIAS);
-
-		mCurrentCapabilities->setCapability(RSC_PERSTAGECONSTANT);
+		rsc->setCapability(RSC_POINT_SPRITES);
+		rsc->setCapability(RSC_POINT_EXTENDED_PARAMETERS);
+		rsc->setMaxPointSize(256);
 
+		rsc->setCapability(RSC_VERTEX_TEXTURE_FETCH);
 
+		rsc->setCapability(RSC_MIPMAP_LOD_BIAS);
 
+		rsc->setCapability(RSC_PERSTAGECONSTANT);
 
+		return rsc;
+	}
 
-		// TODO - See what else needs to be initialized
-		
-		throw std::exception("The method or operation is not implemented.");
+	void D3D11RenderSystem::initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps)
+	{
+		// Do nothing
 	}
 
 	String D3D11RenderSystem::getErrorDescription(long errorNumber) const

+ 7 - 1
CamelotD3D11RenderSystem/Source/CmD3D11SamplerState.cpp

@@ -89,6 +89,12 @@ namespace CamelotEngine
 
 		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
 		D3D11Device& device = rs->getPrimaryDevice();
-		device.getD3D11Device()->CreateSamplerState(&samplerState, &mSamplerState);
+		HRESULT hr = device.getD3D11Device()->CreateSamplerState(&samplerState, &mSamplerState);
+
+		if(FAILED(hr) || device.hasError())
+		{
+			String errorDescription = device.getErrorDescription();
+			CM_EXCEPT(RenderingAPIException, "Cannot create sampler state.\nError Description:" + errorDescription);
+		}
 	}
 }

+ 6 - 6
CamelotD3D11RenderSystem/Source/CmD3D11Texture.cpp

@@ -51,9 +51,9 @@ namespace CamelotEngine
 
 	PixelData D3D11Texture::lockImpl(GpuLockOptions options, UINT32 mipLevel, UINT32 face)
 	{
-		UINT32 mipWidth = mipLevel >> mWidth;
-		UINT32 mipHeight = mipLevel >> mHeight;
-		UINT32 mipDepth = mipLevel >> mDepth;
+		UINT32 mipWidth = mWidth >> mipLevel;
+		UINT32 mipHeight = mHeight >> mipLevel;
+		UINT32 mipDepth = mDepth >> mipLevel;
 
 		PixelData lockedArea(mipWidth, mipHeight, mipDepth, mFormat);
 
@@ -196,7 +196,7 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Error creating texture\nError Description:" + errorDescription);
 		}
 
-		hr = m1DTex->QueryInterface(__uuidof(ID3D11Resource), (void **)mTex);
+		hr = m1DTex->QueryInterface(__uuidof(ID3D11Resource), (void **)&mTex);
 
 		if(FAILED(hr) || device.hasError())
 		{
@@ -290,7 +290,7 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Error creating texture\nError Description:" + errorDescription);
 		}
 
-		hr = m2DTex->QueryInterface(__uuidof(ID3D11Resource), (void **)mTex);
+		hr = m2DTex->QueryInterface(__uuidof(ID3D11Resource), (void **)&mTex);
 
 		if(FAILED(hr) || device.hasError())
 		{
@@ -395,7 +395,7 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Error creating texture\nError Description:" + errorDescription);
 		}
 
-		hr = m3DTex->QueryInterface(__uuidof(ID3D11Resource), (void **)mTex);
+		hr = m3DTex->QueryInterface(__uuidof(ID3D11Resource), (void **)&mTex);
 
 		if(FAILED(hr) || device.hasError())
 		{

+ 101 - 101
CamelotD3D11RenderSystem/Source/CmD3D11VideoModeList.cpp

@@ -3,106 +3,106 @@
 #include "CmD3D11Driver.h"
 
 namespace CamelotEngine
-{
-	D3D11VideoModeList::D3D11VideoModeList(D3D11Driver* driver, UINT32 adapterOutput)
-	{
-		if(driver == nullptr)
-			CM_EXCEPT(InvalidParametersException, "driver parameter is NULL");
-
-		mDriver = driver;
-		enumerate(adapterOutput);
-	}
-
-	D3D11VideoModeList::~D3D11VideoModeList()
-	{
-		mDriver = NULL;
-		mModeList.clear();
-	}
-
-	void D3D11VideoModeList::enumerate(UINT32 adapterOutput)
-	{
-		UINT adapter = mDriver->getAdapterNumber();
-		HRESULT hr;
-
-		IDXGIOutput* output;
-		hr = mDriver->getDeviceAdapter()->EnumOutputs(adapterOutput, &output);
-		if(hr == DXGI_ERROR_NOT_FOUND)
-			CM_EXCEPT(InvalidParametersException, "Adapter output " + toString(adapterOutput) + " not found!");
-
-		if(FAILED(hr))
-			CM_EXCEPT(InternalErrorException, "Error while enumerating adapter output video modes. Output index: " + toString(adapterOutput));
-
-		DXGI_OUTPUT_DESC outputDesc;
-		output->GetDesc(&outputDesc);
-
-		UINT32 numModes = 0;
-
-		hr = output->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, 0, &numModes, 0);
-		if(FAILED(hr))
-		{
-			SAFE_RELEASE(output);
-			CM_EXCEPT(InternalErrorException, "Error while enumerating adapter output video modes. Output index: " + toString(adapterOutput));
-		}
-
-		DXGI_MODE_DESC* modeDesc = new DXGI_MODE_DESC[numModes];
-
-		hr = output->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, 0, &numModes, modeDesc);
-		if(FAILED(hr))
-		{
-			SAFE_RELEASE(output);
-			CM_EXCEPT(InternalErrorException, "Error while enumerating adapter output video modes. Output index: " + toString(adapterOutput));
-		}
-
-		SAFE_RELEASE(output);
-
-		for(UINT32 i = 0; i < numModes; i++)
-		{
-			DXGI_MODE_DESC displayMode = modeDesc[i];
-
-			// Filter out low-resolutions
-			if(displayMode.Width < 640 || displayMode.Height < 400)
-				continue;
-
-			// Check to see if it is already in the list (to filter out refresh rates)
-			bool found = false;
-			for(auto it = mModeList.begin(); it != mModeList.end(); it++)
-			{
-				DXGI_MODE_DESC existingMode = it->getModeDesc();
-				if(	existingMode.Width == displayMode.Width && 
-					existingMode.Height == displayMode.Height &&
-					existingMode.Format == displayMode.Format &&
-					existingMode.RefreshRate.Numerator == displayMode.RefreshRate.Numerator &&
-					existingMode.RefreshRate.Denominator == displayMode.RefreshRate.Denominator
-					)
-				{
-					found = true;
-					break;
-				}
-			}
-
-			if(!found)
-				mModeList.push_back(D3D11VideoMode(outputDesc, displayMode));
-		}
-	}
-
-	UINT32 D3D11VideoModeList::count() const
-	{
-		return (UINT32)mModeList.size();
-	}
-
-	const D3D11VideoMode& D3D11VideoModeList::item(UINT32 idx) const
-	{
-		return mModeList.at(idx);
-	}
-
-	const D3D11VideoMode& D3D11VideoModeList::item(const String &name) const
-	{
-		for (auto iter = mModeList.begin(); iter != mModeList.end(); ++iter)
-		{
-			if (iter->getDescription() == name)
-				return (*iter);
-		}
-
-		CM_EXCEPT(InvalidParametersException, "Cannot find video mode with the specified name.");
+{
+	D3D11VideoModeList::D3D11VideoModeList(D3D11Driver* driver, UINT32 adapterOutput)
+	{
+		if(driver == nullptr)
+			CM_EXCEPT(InvalidParametersException, "driver parameter is NULL");
+
+		mDriver = driver;
+		enumerate(adapterOutput);
+	}
+
+	D3D11VideoModeList::~D3D11VideoModeList()
+	{
+		mDriver = NULL;
+		mModeList.clear();
+	}
+
+	void D3D11VideoModeList::enumerate(UINT32 adapterOutput)
+	{
+		UINT adapter = mDriver->getAdapterNumber();
+		HRESULT hr;
+
+		IDXGIOutput* output;
+		hr = mDriver->getDeviceAdapter()->EnumOutputs(adapterOutput, &output);
+		if(hr == DXGI_ERROR_NOT_FOUND)
+			CM_EXCEPT(InvalidParametersException, "Adapter output " + toString(adapterOutput) + " not found!");
+
+		if(FAILED(hr))
+			CM_EXCEPT(InternalErrorException, "Error while enumerating adapter output video modes. Output index: " + toString(adapterOutput));
+
+		DXGI_OUTPUT_DESC outputDesc;
+		output->GetDesc(&outputDesc);
+
+		UINT32 numModes = 0;
+
+		hr = output->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, 0, &numModes, 0);
+		if(FAILED(hr))
+		{
+			SAFE_RELEASE(output);
+			CM_EXCEPT(InternalErrorException, "Error while enumerating adapter output video modes. Output index: " + toString(adapterOutput));
+		}
+
+		DXGI_MODE_DESC* modeDesc = new DXGI_MODE_DESC[numModes];
+
+		hr = output->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, 0, &numModes, modeDesc);
+		if(FAILED(hr))
+		{
+			SAFE_RELEASE(output);
+			CM_EXCEPT(InternalErrorException, "Error while enumerating adapter output video modes. Output index: " + toString(adapterOutput));
+		}
+
+		SAFE_RELEASE(output);
+
+		for(UINT32 i = 0; i < numModes; i++)
+		{
+			DXGI_MODE_DESC displayMode = modeDesc[i];
+
+			// Filter out low-resolutions
+			if(displayMode.Width < 640 || displayMode.Height < 400)
+				continue;
+
+			// Check to see if it is already in the list (to filter out refresh rates)
+			bool found = false;
+			for(auto it = mModeList.begin(); it != mModeList.end(); it++)
+			{
+				DXGI_MODE_DESC existingMode = it->getModeDesc();
+				if(	existingMode.Width == displayMode.Width && 
+					existingMode.Height == displayMode.Height &&
+					existingMode.Format == displayMode.Format &&
+					existingMode.RefreshRate.Numerator == displayMode.RefreshRate.Numerator &&
+					existingMode.RefreshRate.Denominator == displayMode.RefreshRate.Denominator
+					)
+				{
+					found = true;
+					break;
+				}
+			}
+
+			if(!found)
+				mModeList.push_back(D3D11VideoMode(outputDesc, displayMode));
+		}
+	}
+
+	UINT32 D3D11VideoModeList::count() const
+	{
+		return (UINT32)mModeList.size();
+	}
+
+	const D3D11VideoMode& D3D11VideoModeList::item(UINT32 idx) const
+	{
+		return mModeList.at(idx);
+	}
+
+	const D3D11VideoMode& D3D11VideoModeList::item(const String &name) const
+	{
+		for (auto iter = mModeList.begin(); iter != mModeList.end(); ++iter)
+		{
+			if (iter->getDescription() == name)
+				return (*iter);
+		}
+
+		CM_EXCEPT(InvalidParametersException, "Cannot find video mode with the specified name.");
 	}
 }

+ 4 - 4
CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h

@@ -109,22 +109,22 @@ namespace CamelotEngine
 		/**
 		 * @copydoc RenderSystem::setSamplerState()
 		 */
-		void setSamplerState(GpuProgramType gptype, UINT16 unit, const SamplerState& state);
+		void setSamplerState(GpuProgramType gptype, UINT16 unit, const SamplerStatePtr& state);
 
 		/**
 		 * @copydoc RenderSystem::setBlendState()
 		 */
-		void setBlendState(const BlendState& blendState);
+		void setBlendState(const BlendStatePtr& blendState);
 
 		/**
 		 * @copydoc RenderSystem::setRasterizerState()
 		 */
-		void setRasterizerState(const RasterizerState& rasterizerState);
+		void setRasterizerState(const RasterizerStatePtr& rasterizerState);
 
 		/**
 		 * @copydoc RenderSystem::setDepthStencilState()
 		 */
-		void setDepthStencilState(const DepthStencilState& depthStencilState, UINT32 stencilRefValue);
+		void setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue);
 
 		/**
 		 * @copydoc RenderSystem::setViewport()

+ 0 - 1
CamelotD3D9Renderer/Source/CmD3D9HLSLProgram.cpp

@@ -466,7 +466,6 @@ namespace CamelotEngine {
 			break;
 		}
 
-
         LPD3DXBUFFER errors = 0;
 
 		// include handler

+ 38 - 33
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -48,6 +48,7 @@ THE SOFTWARE.
 #include "CmD3D9ResourceManager.h"
 #include "CmD3D9RenderWindowManager.h"
 #include "CmHighLevelGpuProgramManager.h"
+#include "CmRenderStateManager.h"
 #include "CmAsyncOp.h"
 #include "CmBlendState.h"
 #include "CmRasterizerState.h"
@@ -197,6 +198,9 @@ namespace CamelotEngine
 		// Create render window manager
 		RenderWindowManager::startUp(new D3D9RenderWindowManager(this));
 
+		// Create render state manager
+		RenderStateManager::startUp(new RenderStateManager());
+
 		// call superclass method
 		RenderSystem::initialize_internal();
 	}
@@ -220,6 +224,7 @@ namespace CamelotEngine
 		HardwareBufferManager::shutDown();
 		GpuProgramManager::shutDown();	
 		RenderWindowManager::shutDown();
+		RenderStateManager::shutDown();
 	}
 	//--------------------------------------------------------------------
 	void D3D9RenderSystem::registerRenderWindow(D3D9RenderWindowPtr renderWindow)
@@ -333,7 +338,7 @@ namespace CamelotEngine
 			if(samplerState == nullptr)
 				setSamplerState(gptype, iter->second.slot, SamplerState::getDefault());
 			else
-				setSamplerState(gptype, iter->second.slot, *samplerState);
+				setSamplerState(gptype, iter->second.slot, samplerState);
 		}
 
 		for(auto iter = paramDesc.textures.begin(); iter != paramDesc.textures.end(); ++iter)
@@ -549,7 +554,7 @@ namespace CamelotEngine
 		}
 	}
 	//-----------------------------------------------------------------------
-	void D3D9RenderSystem::setSamplerState(GpuProgramType gptype, UINT16 unit, const SamplerState& state)
+	void D3D9RenderSystem::setSamplerState(GpuProgramType gptype, UINT16 unit, const SamplerStatePtr& state)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
@@ -565,37 +570,37 @@ namespace CamelotEngine
 		}
 
 		// Set texture layer filtering
-		setTextureFiltering(unit, FT_MIN, state.getTextureFiltering(FT_MIN));
-		setTextureFiltering(unit, FT_MAG, state.getTextureFiltering(FT_MAG));
-		setTextureFiltering(unit, FT_MIP, state.getTextureFiltering(FT_MIP));
+		setTextureFiltering(unit, FT_MIN, state->getTextureFiltering(FT_MIN));
+		setTextureFiltering(unit, FT_MAG, state->getTextureFiltering(FT_MAG));
+		setTextureFiltering(unit, FT_MIP, state->getTextureFiltering(FT_MIP));
 
 		// Set texture layer filtering
-		setTextureAnisotropy(unit, state.getTextureAnisotropy());
+		setTextureAnisotropy(unit, state->getTextureAnisotropy());
 
 		// Set mipmap biasing
-		setTextureMipmapBias(unit, state.getTextureMipmapBias());
+		setTextureMipmapBias(unit, state->getTextureMipmapBias());
 
 		// Texture addressing mode
-		const UVWAddressingMode& uvw = state.getTextureAddressingMode();
+		const UVWAddressingMode& uvw = state->getTextureAddressingMode();
 		setTextureAddressingMode(unit, uvw);
 
 		// Set border color
-		setTextureBorderColor(unit, state.getBorderColor());
+		setTextureBorderColor(unit, state->getBorderColor());
 	}
 	//-----------------------------------------------------------------------
-	void D3D9RenderSystem::setBlendState(const BlendState& blendState)
+	void D3D9RenderSystem::setBlendState(const BlendStatePtr& blendState)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
 		// Alpha to coverage
-		setAlphaToCoverage(blendState.getAlphaToCoverageEnabled());
+		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))
+		if(blendState->getBlendEnabled(0))
 		{
-			setSceneBlending(blendState.getSrcBlend(0), blendState.getDstBlend(0), blendState.getAlphaSrcBlend(0), blendState.getAlphaDstBlend(0)
-				, blendState.getBlendOperation(0), blendState.getAlphaBlendOperation(0));
+			setSceneBlending(blendState->getSrcBlend(0), blendState->getDstBlend(0), blendState->getAlphaSrcBlend(0), blendState->getAlphaDstBlend(0)
+				, blendState->getBlendOperation(0), blendState->getAlphaBlendOperation(0));
 		}
 		else
 		{
@@ -603,47 +608,47 @@ namespace CamelotEngine
 		}
 
 		// Color write mask
-		UINT8 writeMask = blendState.getRenderTargetWriteMask(0);
+		UINT8 writeMask = blendState->getRenderTargetWriteMask(0);
 		setColorBufferWriteEnabled((writeMask & 0x1) != 0, (writeMask & 0x2) != 0, (writeMask & 0x4) != 0, (writeMask & 0x8) != 0);
 	}
 	//----------------------------------------------------------------------
-	void D3D9RenderSystem::setRasterizerState(const RasterizerState& rasterizerState)
+	void D3D9RenderSystem::setRasterizerState(const RasterizerStatePtr& rasterizerState)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
-		setDepthBias((float)rasterizerState.getDepthBias(), rasterizerState.getSlopeScaledDepthBias());
+		setDepthBias((float)rasterizerState->getDepthBias(), rasterizerState->getSlopeScaledDepthBias());
 
-		setCullingMode(rasterizerState.getCullMode());
+		setCullingMode(rasterizerState->getCullMode());
 
-		setPolygonMode(rasterizerState.getPolygonMode());
+		setPolygonMode(rasterizerState->getPolygonMode());
 
-		setScissorTestEnable(rasterizerState.getScissorEnable());
+		setScissorTestEnable(rasterizerState->getScissorEnable());
 
-		setMultisampleAntialiasEnable(rasterizerState.getMultisampleEnable());
+		setMultisampleAntialiasEnable(rasterizerState->getMultisampleEnable());
 
-		setAntialiasedLineEnable(rasterizerState.getAntialiasedLineEnable());
+		setAntialiasedLineEnable(rasterizerState->getAntialiasedLineEnable());
 	}
 	//----------------------------------------------------------------------
-	void D3D9RenderSystem::setDepthStencilState(const DepthStencilState& depthStencilState, UINT32 stencilRefValue)
+	void D3D9RenderSystem::setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
 		// Set stencil buffer options
-		setStencilCheckEnabled(depthStencilState.getStencilEnable());
+		setStencilCheckEnabled(depthStencilState->getStencilEnable());
 
-		setStencilBufferOperations(depthStencilState.getStencilFrontFailOp(), depthStencilState.getStencilFrontZFailOp(), depthStencilState.getStencilFrontPassOp(), true);
-		setStencilBufferFunc(depthStencilState.getStencilFrontCompFunc(), true);
+		setStencilBufferOperations(depthStencilState->getStencilFrontFailOp(), depthStencilState->getStencilFrontZFailOp(), depthStencilState->getStencilFrontPassOp(), true);
+		setStencilBufferFunc(depthStencilState->getStencilFrontCompFunc(), true);
 
-		setStencilBufferOperations(depthStencilState.getStencilBackFailOp(), depthStencilState.getStencilBackZFailOp(), depthStencilState.getStencilBackPassOp(), false);
-		setStencilBufferFunc(depthStencilState.getStencilBackCompFunc(), false);
+		setStencilBufferOperations(depthStencilState->getStencilBackFailOp(), depthStencilState->getStencilBackZFailOp(), depthStencilState->getStencilBackPassOp(), false);
+		setStencilBufferFunc(depthStencilState->getStencilBackCompFunc(), false);
 
-		setStencilBufferReadMask(depthStencilState.getStencilReadMask());
-		setStencilBufferWriteMask(depthStencilState.getStencilWriteMask());
+		setStencilBufferReadMask(depthStencilState->getStencilReadMask());
+		setStencilBufferWriteMask(depthStencilState->getStencilWriteMask());
 
 		// Set depth buffer options
-		setDepthBufferCheckEnabled(depthStencilState.getDepthReadEnable());
-		setDepthBufferWriteEnabled(depthStencilState.getDepthWriteEnable());
-		setDepthBufferFunction(depthStencilState.getDepthComparisonFunc());		
+		setDepthBufferCheckEnabled(depthStencilState->getDepthReadEnable());
+		setDepthBufferWriteEnabled(depthStencilState->getDepthWriteEnable());
+		setDepthBufferFunction(depthStencilState->getDepthComparisonFunc());		
 
 		// Set stencil ref value
 		setStencilRefValue(stencilRefValue);

+ 3 - 3
CamelotForwardRenderer/Source/CmForwardRenderer.cpp

@@ -133,7 +133,7 @@ namespace CamelotEngine
 		// The rest of the settings are the same no matter whether we use programs or not
 		BlendStatePtr blendState = pass->getBlendState();
 		if(blendState != nullptr)
-			renderContext->setBlendState(*blendState);
+			renderContext->setBlendState(blendState);
 		else
 			renderContext->setBlendState(BlendState::getDefault());
 		
@@ -147,13 +147,13 @@ namespace CamelotEngine
 		// Stencil & depth buffer settings
 		DepthStencilStatePtr depthStancilState = pass->getDepthStencilState();
 		if(depthStancilState != nullptr)
-			renderContext->setDepthStencilState(*depthStancilState, pass->getStencilRefValue());
+			renderContext->setDepthStencilState(depthStancilState, pass->getStencilRefValue());
 		else
 			renderContext->setDepthStencilState(DepthStencilState::getDefault(), pass->getStencilRefValue());
 
 		RasterizerStatePtr rasterizerState = pass->getRasterizerState();
 		if(rasterizerState != nullptr)
-			renderContext->setRasterizerState(*rasterizerState);
+			renderContext->setRasterizerState(rasterizerState);
 		else
 			renderContext->setRasterizerState(RasterizerState::getDefault());
 	}

+ 4 - 4
CamelotGLRenderer/Include/CmGLRenderSystem.h

@@ -95,22 +95,22 @@ namespace CamelotEngine {
 		/**
 		 * @copydoc RenderSystem::setSamplerState()
 		 */
-		void setSamplerState(GpuProgramType gptype, UINT16 unit, const SamplerState& state);
+		void setSamplerState(GpuProgramType gptype, UINT16 unit, const SamplerStatePtr& state);
 
 		/**
 		 * @copydoc RenderSystem::setBlendState()
 		 */
-		void setBlendState(const BlendState& blendState);
+		void setBlendState(const BlendStatePtr& blendState);
 
 		/**
 		 * @copydoc RenderSystem::setRasterizerState()
 		 */
-		void setRasterizerState(const RasterizerState& rasterizerState);
+		void setRasterizerState(const RasterizerStatePtr& rasterizerState);
 
 		/**
 		 * @copydoc RenderSystem::setDepthStencilState()
 		 */
-		void setDepthStencilState(const DepthStencilState& depthStencilState, UINT32 stencilRefValue);
+		void setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue);
 
 		/**
 		 * @copydoc RenderSystem::setViewport()

+ 34 - 30
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -48,6 +48,7 @@ THE SOFTWARE.s
 #include "CmGLRenderTexture.h"
 #include "CmGLRenderWindowManager.h"
 #include "CmGLSLProgramPipelineManager.h"
+#include "CmRenderStateManager.h"
 #include "CmGpuParams.h"
 #include "CmGLGpuParamBlock.h"
 #include "CmDebug.h"
@@ -160,6 +161,8 @@ namespace CamelotEngine
 		mGLSupport->start();
 		RenderWindowManager::startUp(new GLRenderWindowManager(this));
 
+		RenderStateManager::startUp(new RenderStateManager());
+
 		RenderSystem::initialize_internal();
 	}
 
@@ -211,6 +214,7 @@ namespace CamelotEngine
 
 		TextureManager::shutDown();
 		RenderWindowManager::shutDown();
+		RenderStateManager::shutDown();
 
 		// There will be a new initial window and so forth, thus any call to test
 		//  some params will access an invalid pointer, so it is best to reset
@@ -324,7 +328,7 @@ namespace CamelotEngine
 			if(samplerState == nullptr)
 				setSamplerState(gptype, iter->second.slot, SamplerState::getDefault());
 			else
-				setSamplerState(gptype, iter->second.slot, *samplerState);
+				setSamplerState(gptype, iter->second.slot, samplerState);
 
 			glProgramUniform1i(glProgram, iter->second.slot, getGLTextureUnit(gptype, texUnit));
 
@@ -462,44 +466,44 @@ namespace CamelotEngine
 		activateGLTextureUnit(0);
 	}
 	//-----------------------------------------------------------------------
-	void GLRenderSystem::setSamplerState(GpuProgramType gptype, UINT16 unit, const SamplerState& state)
+	void GLRenderSystem::setSamplerState(GpuProgramType gptype, UINT16 unit, const SamplerStatePtr& state)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
 		unit = getGLTextureUnit(gptype, unit);
 
 		// Set texture layer filtering
-		setTextureFiltering(unit, FT_MIN, state.getTextureFiltering(FT_MIN));
-		setTextureFiltering(unit, FT_MAG, state.getTextureFiltering(FT_MAG));
-		setTextureFiltering(unit, FT_MIP, state.getTextureFiltering(FT_MIP));
+		setTextureFiltering(unit, FT_MIN, state->getTextureFiltering(FT_MIN));
+		setTextureFiltering(unit, FT_MAG, state->getTextureFiltering(FT_MAG));
+		setTextureFiltering(unit, FT_MIP, state->getTextureFiltering(FT_MIP));
 
 		// Set texture anisotropy
-		setTextureAnisotropy(unit, state.getTextureAnisotropy());
+		setTextureAnisotropy(unit, state->getTextureAnisotropy());
 
 		// Set mipmap biasing
-		setTextureMipmapBias(unit, state.getTextureMipmapBias());
+		setTextureMipmapBias(unit, state->getTextureMipmapBias());
 
 		// Texture addressing mode
-		const UVWAddressingMode& uvw = state.getTextureAddressingMode();
+		const UVWAddressingMode& uvw = state->getTextureAddressingMode();
 		setTextureAddressingMode(unit, uvw);
 
 		// Set border color
-		setTextureBorderColor(unit, state.getBorderColor());
+		setTextureBorderColor(unit, state->getBorderColor());
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setBlendState(const BlendState& blendState)
+	void GLRenderSystem::setBlendState(const BlendStatePtr& blendState)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
 		// Alpha to coverage
-		setAlphaToCoverage(blendState.getAlphaToCoverageEnabled());
+		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))
+		if(blendState->getBlendEnabled(0))
 		{
-			setSceneBlending(blendState.getSrcBlend(0), blendState.getDstBlend(0), blendState.getAlphaSrcBlend(0), blendState.getAlphaDstBlend(0)
-				, blendState.getBlendOperation(0), blendState.getAlphaBlendOperation(0));
+			setSceneBlending(blendState->getSrcBlend(0), blendState->getDstBlend(0), blendState->getAlphaSrcBlend(0), blendState->getAlphaDstBlend(0)
+				, blendState->getBlendOperation(0), blendState->getAlphaBlendOperation(0));
 		}
 		else
 		{
@@ -507,42 +511,42 @@ namespace CamelotEngine
 		}
 
 		// Color write mask
-		UINT8 writeMask = blendState.getRenderTargetWriteMask(0);
+		UINT8 writeMask = blendState->getRenderTargetWriteMask(0);
 		setColorBufferWriteEnabled((writeMask & 0x1) != 0, (writeMask & 0x2) != 0, (writeMask & 0x4) != 0, (writeMask & 0x8) != 0);
 	}
 	//----------------------------------------------------------------------
-	void GLRenderSystem::setRasterizerState(const RasterizerState& rasterizerState)
+	void GLRenderSystem::setRasterizerState(const RasterizerStatePtr& rasterizerState)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
-		setDepthBias((float)rasterizerState.getDepthBias(), rasterizerState.getSlopeScaledDepthBias());
+		setDepthBias((float)rasterizerState->getDepthBias(), rasterizerState->getSlopeScaledDepthBias());
 
-		setCullingMode(rasterizerState.getCullMode());
+		setCullingMode(rasterizerState->getCullMode());
 
-		setPolygonMode(rasterizerState.getPolygonMode());
+		setPolygonMode(rasterizerState->getPolygonMode());
 
-		setScissorTestEnable(rasterizerState.getScissorEnable());
+		setScissorTestEnable(rasterizerState->getScissorEnable());
 	}
 	//---------------------------------------------------------------------
-	void GLRenderSystem::setDepthStencilState(const DepthStencilState& depthStencilState, UINT32 stencilRefValue)
+	void GLRenderSystem::setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
 		// Set stencil buffer options
-		setStencilCheckEnabled(depthStencilState.getStencilEnable());
+		setStencilCheckEnabled(depthStencilState->getStencilEnable());
 
-		setStencilBufferOperations(depthStencilState.getStencilFrontFailOp(), depthStencilState.getStencilFrontZFailOp(), depthStencilState.getStencilFrontPassOp(), true);
-		setStencilBufferFunc(depthStencilState.getStencilFrontCompFunc(), depthStencilState.getStencilReadMask(), true);
+		setStencilBufferOperations(depthStencilState->getStencilFrontFailOp(), depthStencilState->getStencilFrontZFailOp(), depthStencilState->getStencilFrontPassOp(), true);
+		setStencilBufferFunc(depthStencilState->getStencilFrontCompFunc(), depthStencilState->getStencilReadMask(), true);
 
-		setStencilBufferOperations(depthStencilState.getStencilBackFailOp(), depthStencilState.getStencilBackZFailOp(), depthStencilState.getStencilBackPassOp(), false);
-		setStencilBufferFunc(depthStencilState.getStencilBackCompFunc(), depthStencilState.getStencilReadMask(), false);
+		setStencilBufferOperations(depthStencilState->getStencilBackFailOp(), depthStencilState->getStencilBackZFailOp(), depthStencilState->getStencilBackPassOp(), false);
+		setStencilBufferFunc(depthStencilState->getStencilBackCompFunc(), depthStencilState->getStencilReadMask(), false);
 
-		setStencilBufferWriteMask(depthStencilState.getStencilWriteMask());
+		setStencilBufferWriteMask(depthStencilState->getStencilWriteMask());
 
 		// Set depth buffer options
-		setDepthBufferCheckEnabled(depthStencilState.getDepthReadEnable());
-		setDepthBufferWriteEnabled(depthStencilState.getDepthWriteEnable());
-		setDepthBufferFunction(depthStencilState.getDepthComparisonFunc());	
+		setDepthBufferCheckEnabled(depthStencilState->getDepthReadEnable());
+		setDepthBufferWriteEnabled(depthStencilState->getDepthWriteEnable());
+		setDepthBufferFunction(depthStencilState->getDepthComparisonFunc());	
 
 		// Set stencil ref value
 		setStencilRefValue(stencilRefValue);

+ 1 - 1
CamelotRenderer/Include/CmBlendState.h

@@ -65,7 +65,7 @@ namespace CamelotEngine
 		/**
 		 * @brief	Returns the default blend state;
 		 */
-		static const BlendState& getDefault();
+		static const BlendStatePtr& getDefault();
 
 	private:
 		friend class RenderStateManager;

+ 4 - 4
CamelotRenderer/Include/CmDeferredRenderContext.h

@@ -35,16 +35,16 @@ namespace CamelotEngine
 		void setTexture(GpuProgramType gptype, UINT16 unit, bool enabled, const TexturePtr &texPtr);
 
 		/** @copydoc RenderSystem::setSamplerState() */
-		void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerState& samplerState);
+		void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerStatePtr& samplerState);
 
 		/** @copydoc RenderSystem::setBlendState() */
-		void setBlendState(const BlendState& blendState);
+		void setBlendState(const BlendStatePtr& blendState);
 
 		/** @copydoc RenderSystem::setRasterizerState() */
-		void setRasterizerState(const RasterizerState& rasterizerState);
+		void setRasterizerState(const RasterizerStatePtr& rasterizerState);
 
 		/** @copydoc RenderSystem::setRasterizerState() */
-		void setDepthStencilState(const DepthStencilState& depthStencilState, UINT32 stencilRefValue);
+		void setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue);
 
 		/** @copydoc RenderSystem::setViewport() */
 		void setViewport(const Viewport& vp);

+ 1 - 1
CamelotRenderer/Include/CmDepthStencilState.h

@@ -73,7 +73,7 @@ namespace CamelotEngine
 		/**
 		 * @brief	Returns the default depth stencil state;
 		 */
-		static const DepthStencilState& getDefault();
+		static const DepthStencilStatePtr& getDefault();
 	private:
 		friend class RenderStateManager;
 

+ 1 - 1
CamelotRenderer/Include/CmRasterizerState.h

@@ -56,7 +56,7 @@ namespace CamelotEngine
 		/**
 		 * @brief	Returns the default rasterizer state;
 		 */
-		static const RasterizerState& getDefault();
+		static const RasterizerStatePtr& getDefault();
 
 	private:
 		friend class RenderStateManager;

+ 4 - 4
CamelotRenderer/Include/CmRenderSystem.h

@@ -135,7 +135,7 @@ namespace CamelotEngine
 		 * @brief	Sets a sampler state for the specified texture unit.
 		 * @see		SamplerState
 		 */
-		virtual void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerState& samplerState) = 0;
+		virtual void setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerStatePtr& samplerState) = 0;
 		/** Turns off a texture unit. */
 		virtual void disableTextureUnit(GpuProgramType gptype, UINT16 texUnit);
 
@@ -143,19 +143,19 @@ namespace CamelotEngine
 		 * @brief	Sets a blend state used for all active render targets.
 		 * @see		BlendState
 		 */
-		virtual void setBlendState(const BlendState& blendState) = 0;
+		virtual void setBlendState(const BlendStatePtr& blendState) = 0;
 
 		/**
 		 * @brief	Sets a state that controls various rasterizer options. 
 		 * @see		RasterizerState
 		 */
-		virtual void setRasterizerState(const RasterizerState& rasterizerState) = 0;
+		virtual void setRasterizerState(const RasterizerStatePtr& rasterizerState) = 0;
 
 		/**
 		 * @brief	Sets a state that controls depth & stencil buffer options.
 		 * @see		DepthStencilState
 		 */
-		virtual void setDepthStencilState(const DepthStencilState& depthStencilState, UINT32 stencilRefValue) = 0;
+		virtual void setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue) = 0;
 
 		/**
 		Sets the texture to bind to a given texture unit.

+ 1 - 1
CamelotRenderer/Include/CmSamplerState.h

@@ -97,7 +97,7 @@ namespace CamelotEngine
 		/**
 		 * @brief	Returns the default sampler state;
 		 */
-		static const SamplerState& getDefault();
+		static const SamplerStatePtr& getDefault();
 
 	private:
 		friend class RenderStateManager;

+ 2 - 9
CamelotRenderer/Source/CmBlendState.cpp

@@ -9,16 +9,9 @@ namespace CamelotEngine
 		mData = desc;
 	}
 
-	const BlendState& BlendState::getDefault()
+	const BlendStatePtr& BlendState::getDefault()
 	{
-		static BlendState blendState;
-		static bool initialized = false;
-
-		if(!initialized)
-		{
-			blendState.initialize(BLEND_STATE_DESC());
-			initialized = true;
-		}
+		static BlendStatePtr blendState = RenderStateManager::instance().createBlendState(BLEND_STATE_DESC());
 
 		return blendState;
 	}

+ 4 - 4
CamelotRenderer/Source/CmDeferredRenderContext.cpp

@@ -51,22 +51,22 @@ namespace CamelotEngine
 		mCommandQueue->queue(boost::bind(&RenderSystem::setDrawOperation, mRenderSystem, op));
 	}
 
-	void DeferredRenderContext::setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerState& samplerState)
+	void DeferredRenderContext::setSamplerState(GpuProgramType gptype, UINT16 texUnit, const SamplerStatePtr& samplerState)
 	{
 		mCommandQueue->queue(boost::bind(&RenderSystem::setSamplerState, mRenderSystem, gptype, texUnit, samplerState));
 	}
 
-	void DeferredRenderContext::setBlendState(const BlendState& blendState)
+	void DeferredRenderContext::setBlendState(const BlendStatePtr& blendState)
 	{
 		mCommandQueue->queue(boost::bind(&RenderSystem::setBlendState, mRenderSystem, blendState));
 	}
 
-	void DeferredRenderContext::setRasterizerState(const RasterizerState& rasterizerState)
+	void DeferredRenderContext::setRasterizerState(const RasterizerStatePtr& rasterizerState)
 	{
 		mCommandQueue->queue(boost::bind(&RenderSystem::setRasterizerState, mRenderSystem, rasterizerState));
 	}
 
-	void DeferredRenderContext::setDepthStencilState(const DepthStencilState& depthStencilState, UINT32 stencilRefValue)
+	void DeferredRenderContext::setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue)
 	{
 		mCommandQueue->queue(boost::bind(&RenderSystem::setDepthStencilState, mRenderSystem, depthStencilState, stencilRefValue));
 	}

+ 2 - 9
CamelotRenderer/Source/CmDepthStencilState.cpp

@@ -10,16 +10,9 @@ namespace CamelotEngine
 		mData = desc;
 	}
 
-	const DepthStencilState& DepthStencilState::getDefault()
+	const DepthStencilStatePtr& DepthStencilState::getDefault()
 	{
-		static DepthStencilState depthStencilState;
-		static bool initialized = false;
-
-		if(!initialized)
-		{
-			depthStencilState.initialize(DEPTH_STENCIL_STATE_DESC());
-			initialized = true;
-		}
+		static DepthStencilStatePtr depthStencilState = RenderStateManager::instance().createDepthStencilState(DEPTH_STENCIL_STATE_DESC());
 
 		return depthStencilState;
 	}

+ 2 - 9
CamelotRenderer/Source/CmRasterizerState.cpp

@@ -9,16 +9,9 @@ namespace CamelotEngine
 		mData = desc;
 	}
 
-	const RasterizerState& RasterizerState::getDefault()
+	const RasterizerStatePtr& RasterizerState::getDefault()
 	{
-		static RasterizerState rasterizerState;
-		static bool initialized = false;
-
-		if(!initialized)
-		{
-			rasterizerState.initialize(RASTERIZER_STATE_DESC());
-			initialized = true;
-		}
+		static RasterizerStatePtr rasterizerState = RenderStateManager::instance().createRasterizerState(RASTERIZER_STATE_DESC());
 
 		return rasterizerState;
 	}

+ 2 - 9
CamelotRenderer/Source/CmSamplerState.cpp

@@ -10,16 +10,9 @@ namespace CamelotEngine
 		mData = desc;
 	}
 
-	const SamplerState& SamplerState::getDefault()
+	const SamplerStatePtr& SamplerState::getDefault()
 	{
-		static SamplerState samplerState;
-		static bool initialized = false;
-
-		if(!initialized)
-		{
-			samplerState.initialize(SAMPLER_STATE_DESC());
-			initialized = true;
-		}
+		static SamplerStatePtr samplerState = RenderStateManager::instance().createSamplerState(SAMPLER_STATE_DESC());
 
 		return samplerState;
 	}

+ 25 - 0
CamelotRenderer/TODO.txt

@@ -19,6 +19,7 @@
  Fully implement DX11
  Better creation of PrimaryWindow
   - RENDERWINDOWDESC accepts a "externalWindow" flag and an "externalHandle" so when creating the primary window with RenderSystem::initialize we don't always need to create a new window
+  - Actually new OpenGL seems to support creating context without a window with the help of wglCreateContextAttribsARB and wglMakeCurrent:
  GpuParams support for bools, buffers, structs
  Static/Dynamic usage for GpuParamBlocks
  Ability to switch out GpuParamBlocks
@@ -38,6 +39,30 @@
 
 ---------------------------------------------------
 
+Resource destruction:
+ Each resource has isDestroyed flag. It is set to true when the user calls destroy(). Destroy will unload all heavyweight underlying data but won't destroy the actual pointer. 
+ If a destructor is called without having first called destroy() an error is logged that the resource wasn't freed properly.
+ Destroy requests will always get queued up at the end of the frame, so that if render system is still using those resources, it has access to them
+   - But then when and how do I actually delete the resource?
+   - Also queued up? OR I don't destroy it?
+   - All internal resources are handled via SharedPtrs so the lightweight reference only gets removed after all actual references are gone.
+ For example unloading a texture:
+  - Call texture.destroy()
+    - Removes the texture from Resources and any other place that holds a known reference
+    - Actually destroys the resource and sets isDestroyed flag to true
+    - Reference to the empty texture continues to exist but render system need to check if its destroyed before it tries to use it
+
+Binding input layout:
+ Upon call to draw()
+ Create or retrieve existing layout based on current set vertex shader and vertex buffer
+  (combine their input declarations into a new one, matching their semantics)
+  Use hash from input declarations to quickly find the combined one
+ Vertex buffer is almost certainly allowed to have more values than the input layout specifies
+ What about less values? If shader requests a field that isn't available?
+  - Test if DX11 supplies default values for the missing field
+  - If not, then throw an error if a value is missing
+    - And adjust DX9 and GL implementations accordingly
+
 Issue of setting individual parameters on a material
  - Material can contain multiple techniques
  - How do I ensure parameters are valid for all techniques?