Răsfoiți Sursa

DX11 works with new depth stencil approach

Marko Pintera 13 ani în urmă
părinte
comite
0168ffa28f
25 a modificat fișierele cu 269 adăugiri și 265 ștergeri
  1. 34 34
      CamelotClient/CamelotClient.cpp
  2. 0 2
      CamelotD3D11RenderSystem/CamelotD3D11RenderSystem.vcxproj
  3. 0 6
      CamelotD3D11RenderSystem/CamelotD3D11RenderSystem.vcxproj.filters
  4. 0 21
      CamelotD3D11RenderSystem/Include/CmD3D11DepthStencilBuffer.h
  5. 0 2
      CamelotD3D11RenderSystem/Include/CmD3D11Mappings.h
  6. 2 1
      CamelotD3D11RenderSystem/Include/CmD3D11MultiRenderTexture.h
  7. 2 0
      CamelotD3D11RenderSystem/Include/CmD3D11RenderTexture.h
  8. 2 1
      CamelotD3D11RenderSystem/Include/CmD3D11RenderWindow.h
  9. 4 1
      CamelotD3D11RenderSystem/Include/CmD3D11Texture.h
  10. 0 6
      CamelotD3D11RenderSystem/Include/CmD3D11TextureManager.h
  11. 0 65
      CamelotD3D11RenderSystem/Source/CmD3D11DepthStencilBuffer.cpp
  12. 14 25
      CamelotD3D11RenderSystem/Source/CmD3D11Mappings.cpp
  13. 11 5
      CamelotD3D11RenderSystem/Source/CmD3D11MultiRenderTexture.cpp
  14. 63 8
      CamelotD3D11RenderSystem/Source/CmD3D11RenderTexture.cpp
  15. 6 4
      CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp
  16. 106 54
      CamelotD3D11RenderSystem/Source/CmD3D11Texture.cpp
  17. 0 7
      CamelotD3D11RenderSystem/Source/CmD3D11TextureManager.cpp
  18. 0 6
      CamelotGLRenderer/Include/CmGLTextureManager.h
  19. 0 6
      CamelotGLRenderer/Source/CmGLTextureManager.cpp
  20. 1 0
      CamelotRenderer.sln
  21. 1 0
      CamelotRenderer/Include/CmHardwareBufferManager.h
  22. 7 2
      CamelotRenderer/Include/CmTexture.h
  23. 9 5
      CamelotRenderer/Include/CmTextureManager.h
  24. 5 2
      CamelotRenderer/Source/CmTexture.cpp
  25. 2 2
      CamelotRenderer/Source/CmTextureManager.cpp

+ 34 - 34
CamelotClient/CamelotClient.cpp

@@ -27,8 +27,8 @@ using namespace CamelotEngine;
 int _tmain(int argc, _TCHAR* argv[])
 int _tmain(int argc, _TCHAR* argv[])
 {
 {
 	//gApplication().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer");
 	//gApplication().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer");
-	gApplication().startUp("CamelotD3D9RenderSystem", "CamelotForwardRenderer");
-	//gApplication().startUp("CamelotD3D11RenderSystem", "CamelotForwardRenderer");
+	//gApplication().startUp("CamelotD3D9RenderSystem", "CamelotForwardRenderer");
+	gApplication().startUp("CamelotD3D11RenderSystem", "CamelotForwardRenderer");
 
 
 	RenderSystem* renderSystem = RenderSystem::instancePtr();
 	RenderSystem* renderSystem = RenderSystem::instancePtr();
 	RenderWindowPtr renderWindow = gApplication().getPrimaryRenderWindow();
 	RenderWindowPtr renderWindow = gApplication().getPrimaryRenderWindow();
@@ -51,51 +51,51 @@ int _tmain(int argc, _TCHAR* argv[])
 	HighLevelGpuProgramPtr vertProg;
 	HighLevelGpuProgramPtr vertProg;
 
 
 	/////////////////// HLSL 9 SHADERS //////////////////////////
 	/////////////////// HLSL 9 SHADERS //////////////////////////
-	String fragShaderCode = "sampler2D tex;			\
-							float4 ps_main(float2 uv : TEXCOORD0) : COLOR0		\
-							{														\
-							float4 color = tex2D(tex, uv);				\
-							return color;										\
-							}";
-
-	fragProg =  HighLevelGpuProgram::create(fragShaderCode, "ps_main", "hlsl", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
-
-	String vertShaderCode = "float4x4 matViewProjection;	\
-							void vs_main(										\
-							float4 inPos : POSITION,							\
-							float2 uv : TEXCOORD0,								\
-							out float4 oPosition : POSITION,					\
-							out float2 oUv : TEXCOORD0)							\
-							{														\
-							oPosition = mul(matViewProjection, inPos);			\
-							oUv = uv;											\
-							}";
-
-	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(in float4 inPos : SV_Position, float2 uv : TEXCOORD0) : SV_Target		\
+	//String fragShaderCode = "sampler2D tex;			\
+	//						float4 ps_main(float2 uv : TEXCOORD0) : COLOR0		\
 	//						{														\
 	//						{														\
-	//						float4 color = tex.Sample(samp, uv);				\
+	//						float4 color = tex2D(tex, uv);				\
 	//						return color;										\
 	//						return color;										\
 	//						}";
 	//						}";
 
 
-	//fragProg =  HighLevelGpuProgram::create(fragShaderCode, "ps_main", "hlsl", GPT_FRAGMENT_PROGRAM, GPP_PS_4_0);
+	//fragProg =  HighLevelGpuProgram::create(fragShaderCode, "ps_main", "hlsl", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
 
 
 	//String vertShaderCode = "float4x4 matViewProjection;	\
 	//String vertShaderCode = "float4x4 matViewProjection;	\
 	//						void vs_main(										\
 	//						void vs_main(										\
-	//						in float4 inPos : POSITION,							\
-	//						in float2 uv : TEXCOORD0,								\
-	//						out float4 oPosition : SV_Position,					\
+	//						float4 inPos : POSITION,							\
+	//						float2 uv : TEXCOORD0,								\
+	//						out float4 oPosition : POSITION,					\
 	//						out float2 oUv : TEXCOORD0)							\
 	//						out float2 oUv : TEXCOORD0)							\
 	//						{														\
 	//						{														\
 	//						oPosition = mul(matViewProjection, inPos);			\
 	//						oPosition = mul(matViewProjection, inPos);			\
 	//						oUv = uv;											\
 	//						oUv = uv;											\
 	//						}";
 	//						}";
 
 
-	//vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "hlsl", GPT_VERTEX_PROGRAM, GPP_VS_4_0);
+	//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(in float4 inPos : SV_Position, 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 //////////////////////////
 	/////////////////// CG SHADERS //////////////////////////
 	//String fragShaderCode = "sampler2D tex;					\
 	//String fragShaderCode = "sampler2D tex;					\

+ 0 - 2
CamelotD3D11RenderSystem/CamelotD3D11RenderSystem.vcxproj

@@ -147,7 +147,6 @@
   </ItemDefinitionGroup>
   </ItemDefinitionGroup>
   <ItemGroup>
   <ItemGroup>
     <ClInclude Include="Include\CmD3D11BlendState.h" />
     <ClInclude Include="Include\CmD3D11BlendState.h" />
-    <ClInclude Include="Include\CmD3D11DepthStencilBuffer.h" />
     <ClInclude Include="Include\CmD3D11DepthStencilState.h" />
     <ClInclude Include="Include\CmD3D11DepthStencilState.h" />
     <ClInclude Include="Include\CmD3D11GenericBuffer.h" />
     <ClInclude Include="Include\CmD3D11GenericBuffer.h" />
     <ClInclude Include="Include\CmD3D11GenericBufferView.h" />
     <ClInclude Include="Include\CmD3D11GenericBufferView.h" />
@@ -184,7 +183,6 @@
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CmD3D11BlendState.cpp" />
     <ClCompile Include="Source\CmD3D11BlendState.cpp" />
-    <ClCompile Include="Source\CmD3D11DepthStencilBuffer.cpp" />
     <ClCompile Include="Source\CmD3D11DepthStencilState.cpp" />
     <ClCompile Include="Source\CmD3D11DepthStencilState.cpp" />
     <ClCompile Include="Source\CmD3D11Device.cpp" />
     <ClCompile Include="Source\CmD3D11Device.cpp" />
     <ClCompile Include="Source\CmD3D11Driver.cpp" />
     <ClCompile Include="Source\CmD3D11Driver.cpp" />

+ 0 - 6
CamelotD3D11RenderSystem/CamelotD3D11RenderSystem.vcxproj.filters

@@ -69,9 +69,6 @@
     <ClInclude Include="Include\CmD3D11TextureManager.h">
     <ClInclude Include="Include\CmD3D11TextureManager.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
-    <ClInclude Include="Include\CmD3D11DepthStencilBuffer.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
     <ClInclude Include="Include\CmD3D11HLSLProgramFactory.h">
     <ClInclude Include="Include\CmD3D11HLSLProgramFactory.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
@@ -173,9 +170,6 @@
     <ClCompile Include="Source\CmD3D11TextureManager.cpp">
     <ClCompile Include="Source\CmD3D11TextureManager.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="Source\CmD3D11DepthStencilBuffer.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="Source\CmD3D11HLSLProgramFactory.cpp">
     <ClCompile Include="Source\CmD3D11HLSLProgramFactory.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>

+ 0 - 21
CamelotD3D11RenderSystem/Include/CmD3D11DepthStencilBuffer.h

@@ -1,21 +0,0 @@
-#pragma once
-
-#include "CmD3D11Prerequisites.h"
-#include "CmDepthStencilBuffer.h"
-
-namespace CamelotEngine
-{
-	class CM_D3D11_EXPORT D3D11DepthStencilBuffer : public DepthStencilBuffer
-	{
-	public:
-		D3D11DepthStencilBuffer(DepthStencilFormat format, UINT32 width, UINT32 height, UINT32 fsaa, const String &fsaaHint);
-		~D3D11DepthStencilBuffer();
-
-		bool isCompatible(RenderTarget* renderTarget) const;
-		ID3D11DepthStencilView* getDepthStencilView() const { return mDepthStencilView; }
-
-	protected:
-		ID3D11Texture2D* mDepthStencil;
-		ID3D11DepthStencilView* mDepthStencilView;
-	};
-}

+ 0 - 2
CamelotD3D11RenderSystem/Include/CmD3D11Mappings.h

@@ -40,8 +40,6 @@ namespace CamelotEngine
 		static D3D11_FILL_MODE get(PolygonMode level);
 		static D3D11_FILL_MODE get(PolygonMode level);
 		/// return a D3D11 equivalent for an engine StencilOperation value
 		/// return a D3D11 equivalent for an engine StencilOperation value
 		static D3D11_STENCIL_OP get(StencilOperation op, bool invert = false);
 		static D3D11_STENCIL_OP get(StencilOperation op, bool invert = false);
-		/// return a D3D11 equivalent for an engine DepthStencilFormat
-		static DXGI_FORMAT get(DepthStencilFormat format);
 		/// return a D3D11 state type for engine FilterType value
 		/// return a D3D11 state type for engine FilterType value
 		static DWORD get(FilterType ft);
 		static DWORD get(FilterType ft);
 		static D3D11_FILTER get(const FilterOptions minification, const FilterOptions magnification, const FilterOptions mips, const bool comparison = false);
 		static D3D11_FILTER get(const FilterOptions minification, const FilterOptions magnification, const FilterOptions mips, const bool comparison = false);

+ 2 - 1
CamelotD3D11RenderSystem/Include/CmD3D11MultiRenderTexture.h

@@ -19,8 +19,9 @@ namespace CamelotEngine
 		void initialize();
 		void initialize();
 
 
 		void setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 0, UINT32 mipLevel = 0);
 		void setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 0, UINT32 mipLevel = 0);
-		void setDepthStencilImpl(DepthStencilBufferPtr depthStencilbuffer);
+		void setDepthStencilImpl(TexturePtr depthStencilSurface);
 
 
 		vector<ID3D11RenderTargetView*>::type mRenderTargetViews;
 		vector<ID3D11RenderTargetView*>::type mRenderTargetViews;
+		ID3D11DepthStencilView* mDepthStencilView;
 	};
 	};
 }
 }

+ 2 - 0
CamelotD3D11RenderSystem/Include/CmD3D11RenderTexture.h

@@ -15,10 +15,12 @@ namespace CamelotEngine
 		void getCustomAttribute(const String& name, void* pData);
 		void getCustomAttribute(const String& name, void* pData);
 
 
 		static ID3D11RenderTargetView* createRenderTargetView(const SurfaceDesc& surfaceDesc);
 		static ID3D11RenderTargetView* createRenderTargetView(const SurfaceDesc& surfaceDesc);
+		static ID3D11DepthStencilView* createDepthStencilView(const TexturePtr& depthStencilSurface);
 	protected:
 	protected:
 		friend class D3D11TextureManager;
 		friend class D3D11TextureManager;
 
 
 		ID3D11RenderTargetView* mRenderTargetView;
 		ID3D11RenderTargetView* mRenderTargetView;
+		ID3D11DepthStencilView* mDepthStencilView;
 
 
 		D3D11RenderTexture();
 		D3D11RenderTexture();
 		void createInternalResourcesImpl();
 		void createInternalResourcesImpl();

+ 2 - 1
CamelotD3D11RenderSystem/Include/CmD3D11RenderWindow.h

@@ -70,7 +70,8 @@ namespace CamelotEngine
 		// Window size depended resources - must be released before swapchain resize and recreated later
 		// Window size depended resources - must be released before swapchain resize and recreated later
 		ID3D11Texture2D*			mBackBuffer;
 		ID3D11Texture2D*			mBackBuffer;
 		ID3D11RenderTargetView*		mRenderTargetView;
 		ID3D11RenderTargetView*		mRenderTargetView;
-		DepthStencilBufferPtr		mDepthStencilBuffer;
+		ID3D11DepthStencilView*		mDepthStencilView;
+		TexturePtr					mDepthStencilBuffer;
 
 
 		IDXGISwapChain*				mSwapChain;
 		IDXGISwapChain*				mSwapChain;
 		DXGI_SWAP_CHAIN_DESC		mSwapChainDesc;
 		DXGI_SWAP_CHAIN_DESC		mSwapChainDesc;

+ 4 - 1
CamelotD3D11RenderSystem/Include/CmD3D11Texture.h

@@ -12,7 +12,8 @@ namespace CamelotEngine
 
 
 		ID3D11Resource* getDX11Resource() const { return mTex; }
 		ID3D11Resource* getDX11Resource() const { return mTex; }
 		ID3D11ShaderResourceView* getSRV() const { return mShaderResourceView; }
 		ID3D11ShaderResourceView* getSRV() const { return mShaderResourceView; }
-		const D3D11_SHADER_RESOURCE_VIEW_DESC& getSRVDesc() const { return mSRVDesc; }
+		D3D11_SRV_DIMENSION getDimension() const { return mDimension; }
+		DXGI_FORMAT getDXGIFormat() const { return mDXGIFormat; }
 	protected:
 	protected:
 		friend class D3D11TextureManager;
 		friend class D3D11TextureManager;
 
 
@@ -25,6 +26,8 @@ namespace CamelotEngine
 
 
 		ID3D11ShaderResourceView* mShaderResourceView;
 		ID3D11ShaderResourceView* mShaderResourceView;
 		D3D11_SHADER_RESOURCE_VIEW_DESC mSRVDesc;
 		D3D11_SHADER_RESOURCE_VIEW_DESC mSRVDesc;
+		D3D11_SRV_DIMENSION mDimension;
+		DXGI_FORMAT mDXGIFormat;
 
 
 		ID3D11Resource* mStagingBuffer;
 		ID3D11Resource* mStagingBuffer;
 		PixelData* mStaticBuffer;
 		PixelData* mStaticBuffer;

+ 0 - 6
CamelotD3D11RenderSystem/Include/CmD3D11TextureManager.h

@@ -18,12 +18,6 @@ namespace CamelotEngine
         bool isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage,
         bool isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage,
             bool preciseFormatOnly = false);		
             bool preciseFormatOnly = false);		
 
 
-		/**
-		 * @copydoc TextureManager::createDepthStencilBuffer()
-		 */
-		DepthStencilBufferPtr createDepthStencilBuffer(DepthStencilFormat format, UINT32 width, 
-			UINT32 height, UINT32 fsaa, const String& fsaaHint);
-
 		/**
 		/**
 		 * @copydoc TextureManager::createMultiRenderTexture()
 		 * @copydoc TextureManager::createMultiRenderTexture()
 		 */
 		 */

+ 0 - 65
CamelotD3D11RenderSystem/Source/CmD3D11DepthStencilBuffer.cpp

@@ -1,65 +0,0 @@
-#include "CmD3D11DepthStencilBuffer.h"
-#include "CmD3D11RenderSystem.h"
-#include "CmD3D11Device.h"
-#include "CmD3D11Mappings.h"
-#include "CmException.h"
-
-namespace CamelotEngine
-{
-	D3D11DepthStencilBuffer::D3D11DepthStencilBuffer(DepthStencilFormat format, UINT32 width, UINT32 height, UINT32 fsaa, const String &fsaaHint)
-		: DepthStencilBuffer(format, width, height, fsaa, fsaaHint)
-		, mDepthStencil(nullptr)
-		, mDepthStencilView(nullptr)
-	{
-		// Create depth stencil texture
-		D3D11_TEXTURE2D_DESC descDepth;
-
-		descDepth.Width = width;
-		descDepth.Height = height;
-		descDepth.MipLevels = 1;
-		descDepth.ArraySize = 1;
-		descDepth.Format = D3D11Mappings::get(format);
-		descDepth.Usage = D3D11_USAGE_DEFAULT;
-		descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
-		descDepth.CPUAccessFlags = 0;
-		descDepth.MiscFlags = 0;
-
-		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
-		rs->determineFSAASettings(fsaa, fsaaHint, descDepth.Format, &descDepth.SampleDesc);
-
-		D3D11Device& device = rs->getPrimaryDevice();
-		HRESULT hr = device.getD3D11Device()->CreateTexture2D(&descDepth, NULL, &mDepthStencil);
-		if( FAILED(hr) || device.hasError())
-		{
-			String errorDescription = device.getErrorDescription();
-			CM_EXCEPT(RenderingAPIException, "Unable to create depth texture\nError Description:" + errorDescription);
-		}
-
-		// Create the depth stencil view
-		D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
-		ZeroMemory(&descDSV, sizeof(D3D11_DEPTH_STENCIL_VIEW_DESC));
-
-		descDSV.Format =  descDepth.Format;
-		descDSV.ViewDimension = (fsaa != 0) ? D3D11_DSV_DIMENSION_TEXTURE2DMS : D3D11_DSV_DIMENSION_TEXTURE2D;
-		descDSV.Texture2D.MipSlice = 0;
-		hr = device.getD3D11Device()->CreateDepthStencilView(mDepthStencil, &descDSV, &mDepthStencilView);
-
-		if(FAILED(hr))
-		{
-			String errorDescription = device.getErrorDescription();
-			CM_EXCEPT(RenderingAPIException, "Unable to create depth stencil view\nError Description:" + errorDescription);
-		}
-	}
-
-	D3D11DepthStencilBuffer::~D3D11DepthStencilBuffer()
-	{
-		SAFE_RELEASE(mDepthStencilView);
-		SAFE_RELEASE(mDepthStencil);
-	}
-
-	bool D3D11DepthStencilBuffer::isCompatible(RenderTarget* renderTarget) const
-	{
-		// Implement once I have RenderTarget properly implemented
-		CM_EXCEPT(NotImplementedException, "Not implemented");
-	}
-}

+ 14 - 25
CamelotD3D11RenderSystem/Source/CmD3D11Mappings.cpp

@@ -149,25 +149,6 @@ namespace CamelotEngine
 		return D3D11_STENCIL_OP_KEEP;
 		return D3D11_STENCIL_OP_KEEP;
 	}
 	}
 
 
-	DXGI_FORMAT D3D11Mappings::get(DepthStencilFormat format)
-	{
-		switch(format)
-		{
-		case DFMT_D32_S8X24:
-			return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
-		case DFMT_D24S8:
-			return DXGI_FORMAT_D24_UNORM_S8_UINT;
-		case DFMT_D32:
-			return DXGI_FORMAT_D32_FLOAT;
-		case DFMT_D16:
-			return DXGI_FORMAT_D16_UNORM;
-		}
-
-		LOGWRN("Requesting unsupported DepthStencilFormat. Using D24S8 format instead.");
-
-		return DXGI_FORMAT_D24_UNORM_S8_UINT;
-	}
-
 	DWORD D3D11Mappings::get(FilterType ft)
 	DWORD D3D11Mappings::get(FilterType ft)
 	{
 	{
 		switch (ft)
 		switch (ft)
@@ -644,9 +625,9 @@ namespace CamelotEngine
 		}
 		}
 	}
 	}
 
 
-	DXGI_FORMAT D3D11Mappings::_getPF(PixelFormat ogrePF)
+	DXGI_FORMAT D3D11Mappings::_getPF(PixelFormat enginePF)
 	{
 	{
-		switch(ogrePF)
+		switch(enginePF)
 		{
 		{
 		case PF_L8:
 		case PF_L8:
 			return DXGI_FORMAT_R8_UNORM;
 			return DXGI_FORMAT_R8_UNORM;
@@ -700,19 +681,27 @@ namespace CamelotEngine
 			return DXGI_FORMAT_BC4_UNORM;
 			return DXGI_FORMAT_BC4_UNORM;
 		case PF_DXT5:
 		case PF_DXT5:
 			return DXGI_FORMAT_BC5_UNORM;
 			return DXGI_FORMAT_BC5_UNORM;
+		case PF_D32_S8X24:
+			return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
+		case PF_D24S8:
+			return DXGI_FORMAT_D24_UNORM_S8_UINT;
+		case PF_D32:
+			return DXGI_FORMAT_D32_FLOAT;
+		case PF_D16:
+			return DXGI_FORMAT_D16_UNORM;
 		case PF_UNKNOWN:
 		case PF_UNKNOWN:
 		default:
 		default:
 			return DXGI_FORMAT_UNKNOWN;
 			return DXGI_FORMAT_UNKNOWN;
 		}
 		}
 	}
 	}
 
 
-	PixelFormat D3D11Mappings::_getClosestSupportedPF(PixelFormat ogrePF)
+	PixelFormat D3D11Mappings::_getClosestSupportedPF(PixelFormat enginePF)
 	{
 	{
-		if (_getPF(ogrePF) != DXGI_FORMAT_UNKNOWN)
+		if (_getPF(enginePF) != DXGI_FORMAT_UNKNOWN)
 		{
 		{
-			return ogrePF;
+			return enginePF;
 		}
 		}
-		switch(ogrePF)
+		switch(enginePF)
 		{
 		{
 		case PF_FLOAT16_RGB:
 		case PF_FLOAT16_RGB:
 			return PF_FLOAT16_RGBA;
 			return PF_FLOAT16_RGBA;

+ 11 - 5
CamelotD3D11RenderSystem/Source/CmD3D11MultiRenderTexture.cpp

@@ -1,12 +1,11 @@
 #include "CmD3D11MultiRenderTexture.h"
 #include "CmD3D11MultiRenderTexture.h"
-#include "CmD3D11DepthStencilBuffer.h"
 #include "CmD3D11Texture.h"
 #include "CmD3D11Texture.h"
 #include "CmD3D11RenderTexture.h"
 #include "CmD3D11RenderTexture.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
 	D3D11MultiRenderTexture::D3D11MultiRenderTexture()
 	D3D11MultiRenderTexture::D3D11MultiRenderTexture()
-		:MultiRenderTexture()
+		:MultiRenderTexture(), mDepthStencilView(nullptr)
 	{
 	{
 
 
 	}
 	}
@@ -18,6 +17,9 @@ namespace CamelotEngine
 
 
 	void D3D11MultiRenderTexture::setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
 	void D3D11MultiRenderTexture::setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
 	{
 	{
+		if(mRenderTargetViews.size() <= surfaceIdx)
+			mRenderTargetViews.resize(surfaceIdx + 1, nullptr);
+
 		SAFE_RELEASE(mRenderTargetViews[surfaceIdx]);
 		SAFE_RELEASE(mRenderTargetViews[surfaceIdx]);
 
 
 		if(texture != nullptr)
 		if(texture != nullptr)
@@ -26,9 +28,14 @@ namespace CamelotEngine
 		}
 		}
 	}
 	}
 
 
-	void D3D11MultiRenderTexture::setDepthStencilImpl(DepthStencilBufferPtr depthStencilBuffer)
+	void D3D11MultiRenderTexture::setDepthStencilImpl(TexturePtr depthStencilSurface)
 	{
 	{
+		SAFE_RELEASE(mDepthStencilView);
 
 
+		if(mDepthStencilView != nullptr)
+		{
+			mDepthStencilView = D3D11RenderTexture::createDepthStencilView(mDepthStencilSurface);
+		}
 	}
 	}
 
 
 	void D3D11MultiRenderTexture::getCustomAttribute(const String& name, void* pData)
 	void D3D11MultiRenderTexture::getCustomAttribute(const String& name, void* pData)
@@ -44,9 +51,8 @@ namespace CamelotEngine
 		else if(name == "DSV")
 		else if(name == "DSV")
 		{
 		{
 			ID3D11DepthStencilView** pDSV = (ID3D11DepthStencilView **)pData;
 			ID3D11DepthStencilView** pDSV = (ID3D11DepthStencilView **)pData;
-			D3D11DepthStencilBuffer* d3d11depthStencilBuffer = static_cast<D3D11DepthStencilBuffer*>(mDepthStencilSurface.get());
 
 
-			*pDSV = d3d11depthStencilBuffer->getDepthStencilView();
+			*pDSV = mDepthStencilView;
 			return;
 			return;
 		}
 		}
 	}
 	}

+ 63 - 8
CamelotD3D11RenderSystem/Source/CmD3D11RenderTexture.cpp

@@ -1,5 +1,4 @@
 #include "CmD3D11RenderTexture.h"
 #include "CmD3D11RenderTexture.h"
-#include "CmD3D11DepthStencilBuffer.h"
 #include "CmD3D11RenderSystem.h"
 #include "CmD3D11RenderSystem.h"
 #include "CmD3D11Device.h"
 #include "CmD3D11Device.h"
 #include "CmD3D11Texture.h"
 #include "CmD3D11Texture.h"
@@ -18,6 +17,7 @@ namespace CamelotEngine
 	D3D11RenderTexture::~D3D11RenderTexture()
 	D3D11RenderTexture::~D3D11RenderTexture()
 	{
 	{
 		SAFE_RELEASE(mRenderTargetView);
 		SAFE_RELEASE(mRenderTargetView);
+		SAFE_RELEASE(mDepthStencilView);
 	}
 	}
 
 
 	ID3D11RenderTargetView* D3D11RenderTexture::createRenderTargetView(const SurfaceDesc& surfaceDesc)
 	ID3D11RenderTargetView* D3D11RenderTexture::createRenderTargetView(const SurfaceDesc& surfaceDesc)
@@ -27,10 +27,8 @@ namespace CamelotEngine
 
 
 		D3D11Texture* d3d11Texture = static_cast<D3D11Texture*>(surfaceDesc.texture.get());
 		D3D11Texture* d3d11Texture = static_cast<D3D11Texture*>(surfaceDesc.texture.get());
 
 
-		D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc = d3d11Texture->getSRVDesc();
-		RTVDesc.Format = SRVDesc.Format;
-
-		switch(SRVDesc.ViewDimension)
+		RTVDesc.Format = d3d11Texture->getDXGIFormat();
+		switch(d3d11Texture->getDimension())
 		{
 		{
 		case D3D11_SRV_DIMENSION_BUFFER:
 		case D3D11_SRV_DIMENSION_BUFFER:
 			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
 			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
@@ -93,11 +91,70 @@ namespace CamelotEngine
 		return rtv;
 		return rtv;
 	}
 	}
 
 
+	ID3D11DepthStencilView* D3D11RenderTexture::createDepthStencilView(const TexturePtr& depthStencilSurface)
+	{
+		// Create the depth stencil view
+		D3D11_DEPTH_STENCIL_VIEW_DESC DSVDesc;
+		ZeroMemory(&DSVDesc, sizeof(D3D11_DEPTH_STENCIL_VIEW_DESC));
+
+		D3D11Texture* d3d11Texture = static_cast<D3D11Texture*>(depthStencilSurface.get());
+
+		DSVDesc.Format = d3d11Texture->getDXGIFormat();
+		switch(d3d11Texture->getDimension())
+		{
+		case D3D11_SRV_DIMENSION_TEXTURE1D:
+			DSVDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE1D;
+			DSVDesc.Texture1D.MipSlice = 0;
+			break;
+		case D3D11_SRV_DIMENSION_TEXTURE1DARRAY:
+			DSVDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE1DARRAY;
+			DSVDesc.Texture1DArray.FirstArraySlice = 0;
+			DSVDesc.Texture1DArray.ArraySize = 1;
+			DSVDesc.Texture1DArray.MipSlice = 0;
+			break;
+		case D3D11_SRV_DIMENSION_TEXTURE2D:
+			DSVDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
+			DSVDesc.Texture2D.MipSlice = 0;
+			break;
+		case D3D11_SRV_DIMENSION_TEXTURE2DARRAY:
+			DSVDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
+			DSVDesc.Texture2DArray.FirstArraySlice = 0;
+			DSVDesc.Texture2DArray.ArraySize = 1;
+			DSVDesc.Texture2DArray.MipSlice = 0;
+			break;
+		case D3D11_SRV_DIMENSION_TEXTURE2DMS:
+			DSVDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;
+			break;
+		case D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY:
+			DSVDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY;
+			DSVDesc.Texture2DMSArray.FirstArraySlice = 0;
+			DSVDesc.Texture2DMSArray.ArraySize = 1;
+			break;
+		default:
+			assert(false);
+		}
+
+		ID3D11DepthStencilView* dsv;
+		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
+		D3D11Device& device = rs->getPrimaryDevice();
+		HRESULT hr = device.getD3D11Device()->CreateDepthStencilView(d3d11Texture->getDX11Resource(), &DSVDesc, &dsv);
+
+		if(FAILED(hr))
+		{
+			String errorDescription = device.getErrorDescription();
+			CM_EXCEPT(RenderingAPIException, "Unable to create depth stencil view\nError Description:" + errorDescription);
+		}
+
+		return dsv;
+	}
+
 	void D3D11RenderTexture::createInternalResourcesImpl()
 	void D3D11RenderTexture::createInternalResourcesImpl()
 	{
 	{
 		SAFE_RELEASE(mRenderTargetView);
 		SAFE_RELEASE(mRenderTargetView);
+		SAFE_RELEASE(mDepthStencilView);
 
 
 		mRenderTargetView = createRenderTargetView(mSurface);
 		mRenderTargetView = createRenderTargetView(mSurface);
+		mDepthStencilView = createDepthStencilView(mDepthStencilSurface);
 	}
 	}
 
 
 	void D3D11RenderTexture::getCustomAttribute(const String& name, void* pData)
 	void D3D11RenderTexture::getCustomAttribute(const String& name, void* pData)
@@ -112,9 +169,7 @@ namespace CamelotEngine
 		else if(name == "DSV")
 		else if(name == "DSV")
 		{
 		{
 			ID3D11DepthStencilView** pDSV = (ID3D11DepthStencilView **)pData;
 			ID3D11DepthStencilView** pDSV = (ID3D11DepthStencilView **)pData;
-			D3D11DepthStencilBuffer* d3d11depthStencilBuffer = static_cast<D3D11DepthStencilBuffer*>(mDepthStencilSurface.get());
-
-			*pDSV = d3d11depthStencilBuffer->getDepthStencilView();
+			*pDSV = mDepthStencilView;
 			return;
 			return;
 		}
 		}
 	}
 	}

+ 6 - 4
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -2,7 +2,7 @@
 #include "CmWindowEventUtilities.h"
 #include "CmWindowEventUtilities.h"
 #include "CmD3D11RenderSystem.h"
 #include "CmD3D11RenderSystem.h"
 #include "CmD3D11Device.h"
 #include "CmD3D11Device.h"
-#include "CmD3D11DepthStencilBuffer.h"
+#include "CmD3D11RenderTexture.h"
 #include "CmTextureManager.h"
 #include "CmTextureManager.h"
 #include "CmException.h"
 #include "CmException.h"
 
 
@@ -348,8 +348,7 @@ namespace CamelotEngine
 		}
 		}
 		else if(name == "DSV")
 		else if(name == "DSV")
 		{
 		{
-			D3D11DepthStencilBuffer* d3d11depthStencilBuffer = static_cast<D3D11DepthStencilBuffer*>(mDepthStencilBuffer.get());
-			*static_cast<ID3D11DepthStencilView**>(pData) = d3d11depthStencilBuffer->getDepthStencilView();
+			*static_cast<ID3D11DepthStencilView**>(pData) = mDepthStencilView;
 			return;
 			return;
 		}
 		}
 
 
@@ -512,7 +511,10 @@ namespace CamelotEngine
 			CM_EXCEPT(RenderingAPIException, "Unable to create rendertagert view\nError Description:" + errorDescription);
 			CM_EXCEPT(RenderingAPIException, "Unable to create rendertagert view\nError Description:" + errorDescription);
 		}
 		}
 
 
-		mDepthStencilBuffer = TextureManager::instance().createDepthStencilBuffer(DFMT_D24S8, BBDesc.Width, BBDesc.Height, mFSAA, mFSAAHint);
+		mDepthStencilBuffer = TextureManager::instance().createTexture(TEX_TYPE_2D, 
+			BBDesc.Width, BBDesc.Height, 0, PF_D24S8, TU_DEPTHSTENCIL, false, mFSAA, mFSAAHint, true);
+
+		mDepthStencilView = D3D11RenderTexture::createDepthStencilView(mDepthStencilBuffer);
 	}
 	}
 
 
 	void D3D11RenderWindow::_destroySizeDependedD3DResources()
 	void D3D11RenderWindow::_destroySizeDependedD3DResources()

+ 106 - 54
CamelotD3D11RenderSystem/Source/CmD3D11Texture.cpp

@@ -149,7 +149,14 @@ namespace CamelotEngine
 		{
 		{
 			desc.Usage			= D3D11_USAGE_DEFAULT;
 			desc.Usage			= D3D11_USAGE_DEFAULT;
 			desc.BindFlags		= D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
 			desc.BindFlags		= D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
-			desc.CPUAccessFlags = (mUsage & TU_RENDERTARGET) != 0 ? 0 : D3D11Mappings::_getAccessFlags(mUsage);
+			desc.CPUAccessFlags = 0;
+			desc.MipLevels		= 1;
+		}
+		else if((mUsage & TU_DEPTHSTENCIL) != 0)
+		{
+			desc.Usage			= D3D11_USAGE_DEFAULT;
+			desc.BindFlags		= D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;
+			desc.CPUAccessFlags = 0;
 			desc.MipLevels		= 1;
 			desc.MipLevels		= 1;
 		}
 		}
 		else
 		else
@@ -187,18 +194,22 @@ namespace CamelotEngine
 
 
 		m1DTex->GetDesc(&desc);
 		m1DTex->GetDesc(&desc);
 		mNumMipmaps = desc.MipLevels - 1;
 		mNumMipmaps = desc.MipLevels - 1;
+		mDimension = D3D11_SRV_DIMENSION_TEXTURE1D;
 
 
 		// Create texture view
 		// Create texture view
-		ZeroMemory(&mSRVDesc, sizeof(mSRVDesc));
-		mSRVDesc.Format = desc.Format;
-		mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D; 
-		mSRVDesc.Texture1D.MipLevels = desc.MipLevels;
-		hr = device.getD3D11Device()->CreateShaderResourceView(m1DTex, &mSRVDesc, &mShaderResourceView);
-
-		if (FAILED(hr) || device.hasError())
+		if((mUsage & TU_DEPTHSTENCIL) == 0)
 		{
 		{
-			String errorDescription = device.getErrorDescription();
-			CM_EXCEPT(RenderingAPIException, "D3D11 device can't create shader resource view.\nError Description:" + errorDescription);
+			ZeroMemory(&mSRVDesc, sizeof(mSRVDesc));
+			mSRVDesc.Format = desc.Format;
+			mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D; 
+			mSRVDesc.Texture1D.MipLevels = desc.MipLevels;
+			hr = device.getD3D11Device()->CreateShaderResourceView(m1DTex, &mSRVDesc, &mShaderResourceView);
+
+			if (FAILED(hr) || device.hasError())
+			{
+				String errorDescription = device.getErrorDescription();
+				CM_EXCEPT(RenderingAPIException, "D3D11 device can't create shader resource view.\nError Description:" + errorDescription);
+			}
 		}
 		}
 	}
 	}
 
 
@@ -222,7 +233,7 @@ namespace CamelotEngine
 		{
 		{
 			desc.Usage			= D3D11_USAGE_DEFAULT;
 			desc.Usage			= D3D11_USAGE_DEFAULT;
 			desc.BindFlags		= D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
 			desc.BindFlags		= D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
-			desc.CPUAccessFlags = (mUsage & TU_RENDERTARGET) != 0 ? 0 : D3D11Mappings::_getAccessFlags(mUsage);
+			desc.CPUAccessFlags = 0;
 			desc.MipLevels		= 1;
 			desc.MipLevels		= 1;
 
 
 			DXGI_SAMPLE_DESC sampleDesc;
 			DXGI_SAMPLE_DESC sampleDesc;
@@ -235,6 +246,23 @@ namespace CamelotEngine
 				CM_EXCEPT(NotImplementedException, "Cube map not yet supported as a render target."); // TODO: Will be once I add proper texture array support
 				CM_EXCEPT(NotImplementedException, "Cube map not yet supported as a render target."); // TODO: Will be once I add proper texture array support
 			}
 			}
 		}
 		}
+		else if((mUsage & TU_DEPTHSTENCIL) != 0)
+		{
+			desc.Usage			= D3D11_USAGE_DEFAULT;
+			desc.BindFlags		= D3D11_BIND_DEPTH_STENCIL;
+			desc.CPUAccessFlags = 0;
+			desc.MipLevels		= 1;
+
+			DXGI_SAMPLE_DESC sampleDesc;
+			D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
+			rs->determineFSAASettings(mFSAA, mFSAAHint, d3dPF, &sampleDesc);
+			desc.SampleDesc		= sampleDesc;
+
+			if(getTextureType() == TEX_TYPE_CUBE_MAP)
+			{
+				CM_EXCEPT(NotImplementedException, "Cube map not yet supported as a depth stencil target."); // TODO: Will be once I add proper texture array support
+			}
+		}
 		else
 		else
 		{
 		{
 			desc.Usage			= D3D11Mappings::_getUsage(mUsage);
 			desc.Usage			= D3D11Mappings::_getUsage(mUsage);
@@ -282,49 +310,62 @@ namespace CamelotEngine
 		m2DTex->GetDesc(&desc);
 		m2DTex->GetDesc(&desc);
 		mNumMipmaps = desc.MipLevels - 1;
 		mNumMipmaps = desc.MipLevels - 1;
 
 
-		// Create shader texture view
-		ZeroMemory(&mSRVDesc, sizeof(mSRVDesc));
-		mSRVDesc.Format = desc.Format;
+		mDXGIFormat = desc.Format;
 
 
-		if((mUsage & TU_RENDERTARGET) != 0)
+		// Create shader texture view
+		if((mUsage & TU_DEPTHSTENCIL) == 0)
 		{
 		{
-			if(mFSAA > 0)
+			ZeroMemory(&mSRVDesc, sizeof(mSRVDesc));
+			mSRVDesc.Format = desc.Format;
+
+			if((mUsage & TU_RENDERTARGET) != 0)
 			{
 			{
-				mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS;
-				mSRVDesc.Texture2D.MostDetailedMip = 0;
-				mSRVDesc.Texture2D.MipLevels = desc.MipLevels;
+				if(mFSAA > 0)
+				{
+					mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS;
+					mSRVDesc.Texture2D.MostDetailedMip = 0;
+					mSRVDesc.Texture2D.MipLevels = desc.MipLevels;
+				}
+				else
+				{
+					mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
+					mSRVDesc.Texture2D.MostDetailedMip = 0;
+					mSRVDesc.Texture2D.MipLevels = desc.MipLevels;
+				}
 			}
 			}
 			else
 			else
 			{
 			{
-				mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
-				mSRVDesc.Texture2D.MostDetailedMip = 0;
-				mSRVDesc.Texture2D.MipLevels = desc.MipLevels;
+				switch(getTextureType())
+				{
+				case TEX_TYPE_CUBE_MAP:
+					mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
+					mSRVDesc.TextureCube.MipLevels = desc.MipLevels;
+					mSRVDesc.TextureCube.MostDetailedMip = 0;
+					break;
+
+				case TEX_TYPE_2D:
+					mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
+					mSRVDesc.Texture2D.MostDetailedMip = 0;
+					mSRVDesc.Texture2D.MipLevels = desc.MipLevels;
+					break;
+				}
 			}
 			}
-		}
-		else
-		{
-			switch(getTextureType())
+
+			mDimension = mSRVDesc.ViewDimension;
+			hr = device.getD3D11Device()->CreateShaderResourceView(m2DTex, &mSRVDesc, &mShaderResourceView);
+
+			if (FAILED(hr) || device.hasError())
 			{
 			{
-			case TEX_TYPE_CUBE_MAP:
-				mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
-				mSRVDesc.TextureCube.MipLevels = desc.MipLevels;
-				mSRVDesc.TextureCube.MostDetailedMip = 0;
-				break;
-
-			case TEX_TYPE_2D:
-				mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
-				mSRVDesc.Texture2D.MostDetailedMip = 0;
-				mSRVDesc.Texture2D.MipLevels = desc.MipLevels;
-				break;
+				String errorDescription = device.getErrorDescription();
+				CM_EXCEPT(RenderingAPIException, "D3D11 device can't create shader resource view.\nError Description:" + errorDescription);
 			}
 			}
 		}
 		}
-
-		hr = device.getD3D11Device()->CreateShaderResourceView(m2DTex, &mSRVDesc, &mShaderResourceView);
-
-		if (FAILED(hr) || device.hasError())
+		else
 		{
 		{
-			String errorDescription = device.getErrorDescription();
-			CM_EXCEPT(RenderingAPIException, "D3D11 device can't create shader resource view.\nError Description:" + errorDescription);
+			if(mFSAA > 0)
+				mDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS;
+			else
+				mDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
 		}
 		}
 	}
 	}
 
 
@@ -348,7 +389,14 @@ namespace CamelotEngine
 		{
 		{
 			desc.Usage			= D3D11_USAGE_DEFAULT;
 			desc.Usage			= D3D11_USAGE_DEFAULT;
 			desc.BindFlags		= D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
 			desc.BindFlags		= D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
-			desc.CPUAccessFlags = (mUsage & TU_RENDERTARGET) != 0 ? 0 : D3D11Mappings::_getAccessFlags(mUsage);
+			desc.CPUAccessFlags = 0;
+			desc.MipLevels		= 1;
+		}
+		else if((mUsage & TU_DEPTHSTENCIL) != 0)
+		{
+			desc.Usage			= D3D11_USAGE_DEFAULT;
+			desc.BindFlags		= D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;
+			desc.CPUAccessFlags = 0;
 			desc.MipLevels		= 1;
 			desc.MipLevels		= 1;
 		}
 		}
 		else
 		else
@@ -387,19 +435,23 @@ namespace CamelotEngine
 		// Create texture view
 		// Create texture view
 		m3DTex->GetDesc(&desc);
 		m3DTex->GetDesc(&desc);
 		mNumMipmaps = desc.MipLevels - 1;
 		mNumMipmaps = desc.MipLevels - 1;
+		mDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
 
 
-		ZeroMemory(&mSRVDesc, sizeof(mSRVDesc));
-		mSRVDesc.Format = desc.Format;
-		mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
-		mSRVDesc.Texture3D.MostDetailedMip = 0;
-		mSRVDesc.Texture3D.MipLevels = desc.MipLevels;
+		if((mUsage & TU_DEPTHSTENCIL) == 0)
+		{
+			ZeroMemory(&mSRVDesc, sizeof(mSRVDesc));
+			mSRVDesc.Format = desc.Format;
+			mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
+			mSRVDesc.Texture3D.MostDetailedMip = 0;
+			mSRVDesc.Texture3D.MipLevels = desc.MipLevels;
 
 
-		hr = device.getD3D11Device()->CreateShaderResourceView(m2DTex, &mSRVDesc, &mShaderResourceView);
+			hr = device.getD3D11Device()->CreateShaderResourceView(m2DTex, &mSRVDesc, &mShaderResourceView);
 
 
-		if (FAILED(hr) || device.hasError())
-		{
-			String errorDescription = device.getErrorDescription();
-			CM_EXCEPT(RenderingAPIException, "D3D11 device can't create shader resource view.\nError Description:" + errorDescription);
+			if (FAILED(hr) || device.hasError())
+			{
+				String errorDescription = device.getErrorDescription();
+				CM_EXCEPT(RenderingAPIException, "D3D11 device can't create shader resource view.\nError Description:" + errorDescription);
+			}
 		}
 		}
 	}
 	}
 
 

+ 0 - 7
CamelotD3D11RenderSystem/Source/CmD3D11TextureManager.cpp

@@ -3,7 +3,6 @@
 #include "CmD3D11RenderTexture.h"
 #include "CmD3D11RenderTexture.h"
 #include "CmD3D11Mappings.h"
 #include "CmD3D11Mappings.h"
 #include "CmD3D11RenderSystem.h"
 #include "CmD3D11RenderSystem.h"
-#include "CmD3D11DepthStencilBuffer.h"
 #include "CmD3D11MultiRenderTexture.h"
 #include "CmD3D11MultiRenderTexture.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
@@ -25,12 +24,6 @@ namespace CamelotEngine
 		return new D3D11RenderTexture();
 		return new D3D11RenderTexture();
 	}
 	}
 
 
-	DepthStencilBufferPtr D3D11TextureManager::createDepthStencilBuffer(DepthStencilFormat format, UINT32 width, 
-		UINT32 height, UINT32 fsaa, const String& fsaaHint)
-	{
-		return DepthStencilBufferPtr(new D3D11DepthStencilBuffer(format, width, height, fsaa, fsaaHint));
-	}
-
 	MultiRenderTexturePtr D3D11TextureManager::createMultiRenderTexture()
 	MultiRenderTexturePtr D3D11TextureManager::createMultiRenderTexture()
 	{
 	{
 		D3D11MultiRenderTexture* newMRT = new D3D11MultiRenderTexture();
 		D3D11MultiRenderTexture* newMRT = new D3D11MultiRenderTexture();

+ 0 - 6
CamelotGLRenderer/Include/CmGLTextureManager.h

@@ -51,12 +51,6 @@ namespace CamelotEngine {
         bool isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage,
         bool isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage,
             bool preciseFormatOnly = false);
             bool preciseFormatOnly = false);
 
 
-		/**
-		 * @copydoc TextureManager::createDepthStencilBuffer()
-		 */
-		DepthStencilBufferPtr createDepthStencilBuffer(DepthStencilFormat format, UINT32 width, 
-			UINT32 height, UINT32 fsaa, const String& fsaaHint);
-
 		/**
 		/**
 		 * @copydoc TextureManager::createMultiRenderTexture()
 		 * @copydoc TextureManager::createMultiRenderTexture()
 		 */
 		 */

+ 0 - 6
CamelotGLRenderer/Source/CmGLTextureManager.cpp

@@ -56,12 +56,6 @@ namespace CamelotEngine {
 		return new GLRenderTexture();
 		return new GLRenderTexture();
 	}
 	}
 	//----------------------------------------------------------------------------
 	//----------------------------------------------------------------------------
-	DepthStencilBufferPtr GLTextureManager::createDepthStencilBuffer(DepthStencilFormat format, UINT32 width, 
-		UINT32 height, UINT32 fsaa, const String& fsaaHint)
-	{
-		return DepthStencilBufferPtr(new GLDepthStencilBuffer(format, width, height, fsaa, fsaaHint));
-	}
-	//----------------------------------------------------------------------------
 	MultiRenderTexturePtr GLTextureManager::createMultiRenderTexture()
 	MultiRenderTexturePtr GLTextureManager::createMultiRenderTexture()
 	{
 	{
 		GLMultiRenderTexture* newMRT = new GLMultiRenderTexture();
 		GLMultiRenderTexture* newMRT = new GLMultiRenderTexture();

+ 1 - 0
CamelotRenderer.sln

@@ -17,6 +17,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CamelotClient", "CamelotCli
 	ProjectSection(ProjectDependencies) = postProject
 	ProjectSection(ProjectDependencies) = postProject
 		{9B21D41C-516B-43BF-9B10-E99B599C7589} = {9B21D41C-516B-43BF-9B10-E99B599C7589}
 		{9B21D41C-516B-43BF-9B10-E99B599C7589} = {9B21D41C-516B-43BF-9B10-E99B599C7589}
 		{122B7A22-0C62-4B35-B661-EBF3F394EA79} = {122B7A22-0C62-4B35-B661-EBF3F394EA79}
 		{122B7A22-0C62-4B35-B661-EBF3F394EA79} = {122B7A22-0C62-4B35-B661-EBF3F394EA79}
+		{1437BB4E-DDB3-4307-AA41-8C035DA3014B} = {1437BB4E-DDB3-4307-AA41-8C035DA3014B}
 		{08975177-4A13-4EE7-BB21-3BB92FB3F3CC} = {08975177-4A13-4EE7-BB21-3BB92FB3F3CC}
 		{08975177-4A13-4EE7-BB21-3BB92FB3F3CC} = {08975177-4A13-4EE7-BB21-3BB92FB3F3CC}
 		{7F449698-73DF-4203-9F31-0877DBF01695} = {7F449698-73DF-4203-9F31-0877DBF01695}
 		{7F449698-73DF-4203-9F31-0877DBF01695} = {7F449698-73DF-4203-9F31-0877DBF01695}
 		{BFEBBAF8-8A84-4899-8899-D0D7196AF9A1} = {BFEBBAF8-8A84-4899-8899-D0D7196AF9A1}
 		{BFEBBAF8-8A84-4899-8899-D0D7196AF9A1} = {BFEBBAF8-8A84-4899-8899-D0D7196AF9A1}

+ 1 - 0
CamelotRenderer/Include/CmHardwareBufferManager.h

@@ -90,6 +90,7 @@ namespace CamelotEngine {
         */
         */
 		virtual VertexBufferPtr 
 		virtual VertexBufferPtr 
             createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false) = 0;
             createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false) = 0;
+
 		/** Create a hardware index buffer.
 		/** Create a hardware index buffer.
         @remarks Note that because buffers can be shared, they are reference
         @remarks Note that because buffers can be shared, they are reference
             counted so you do not need to worry about destroying them this will be done
             counted so you do not need to worry about destroying them this will be done

+ 7 - 2
CamelotRenderer/Include/CmTexture.h

@@ -227,10 +227,15 @@ namespace CamelotEngine {
 		 * @brief	Initializes the texture. This must be called right after the texture is constructed. Called by TextureManager
 		 * @brief	Initializes the texture. This must be called right after the texture is constructed. Called by TextureManager
 		 * 			upon texture creation, so usually you don't want to call this manually.
 		 * 			upon texture creation, so usually you don't want to call this manually.
 		 * 			
 		 * 			
-		 * @note	Initialization is not done immediately, and is instead just scheduled on the render thread.
+		 * @param	internalCall	(optional) Set to true if initializing from within the RenderSystem.
+		 * 							Most users don't have to be concerned about this.
+		 * 							
+		 * @note	Initialization is not done immediately, and is instead just scheduled on the
+		 * 			render thread. Unless internalCall is specified, in which case it is initialized
+		 * 			right away.
 		 */
 		 */
 		void initialize(TextureType textureType, UINT32 width, UINT32 height, UINT32 depth, UINT32 numMipmaps, 
 		void initialize(TextureType textureType, UINT32 width, UINT32 height, UINT32 depth, UINT32 numMipmaps, 
-			PixelFormat format, int usage, bool hwGamma, UINT32 fsaa, const String& fsaaHint);
+			PixelFormat format, int usage, bool hwGamma, UINT32 fsaa, const String& fsaaHint, bool internalCall = false);
 		
 		
 		/**
 		/**
 		 * @brief	Performs GpuProgram initialization. Only callable from the render thread.
 		 * @brief	Performs GpuProgram initialization. Only callable from the render thread.

+ 9 - 5
CamelotRenderer/Include/CmTextureManager.h

@@ -110,10 +110,12 @@ namespace CamelotEngine {
 			@param fsaa The level of multisampling to use if this is a render target. Ignored
 			@param fsaa The level of multisampling to use if this is a render target. Ignored
 				if usage does not include TU_RENDERTARGET or if the device does
 				if usage does not include TU_RENDERTARGET or if the device does
 				not support it.
 				not support it.
+			@param	internalCall	(optional) Set to true if calling this method from within the RenderSystem.
+										Most users don't have to be concerned about this.
         */
         */
         TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, 
         TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, 
-			int num_mips, PixelFormat format, int usage = TU_DEFAULT,
-			bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
+			int num_mips, PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false, 
+			UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK, bool internalCall = false);
 			
 			
         /** Create a manual texture with a depth of 1 (not loaded from a file).
         /** Create a manual texture with a depth of 1 (not loaded from a file).
             @param
             @param
@@ -156,13 +158,15 @@ namespace CamelotEngine {
 			@param fsaa The level of multisampling to use if this is a render target. Ignored
 			@param fsaa The level of multisampling to use if this is a render target. Ignored
 				if usage does not include TU_RENDERTARGET or if the device does
 				if usage does not include TU_RENDERTARGET or if the device does
 				not support it.
 				not support it.
+			@param	internalCall	(optional) Set to true if calling this method from within the RenderSystem.
+				Most users don't have to be concerned about this.
         */
         */
         TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, int num_mips,
         TexturePtr createTexture(TextureType texType, UINT32 width, UINT32 height, int num_mips,
-            PixelFormat format, int usage = TU_DEFAULT,
-			bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK)
+            PixelFormat format, int usage = TU_DEFAULT, bool hwGammaCorrection = false, UINT32 fsaa = 0, 
+			const String& fsaaHint = StringUtil::BLANK, bool internalCall = false)
 		{
 		{
 			return createTexture(texType, width, height, 1, 
 			return createTexture(texType, width, height, 1, 
-				num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
+				num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint, internalCall);
 		}
 		}
 
 
 		/**
 		/**

+ 5 - 2
CamelotRenderer/Source/CmTexture.cpp

@@ -58,7 +58,7 @@ namespace CamelotEngine {
     }
     }
 	//-------------------------------------------------------------------------
 	//-------------------------------------------------------------------------
 	void Texture::initialize(TextureType textureType, UINT32 width, UINT32 height, UINT32 depth, UINT32 numMipmaps, 
 	void Texture::initialize(TextureType textureType, UINT32 width, UINT32 height, UINT32 depth, UINT32 numMipmaps, 
-		PixelFormat format, int usage, bool hwGamma, UINT32 fsaa, const String& fsaaHint)
+		PixelFormat format, int usage, bool hwGamma, UINT32 fsaa, const String& fsaaHint, bool internalCall)
 	{
 	{
 		mTextureType = textureType;
 		mTextureType = textureType;
 		mWidth = width;
 		mWidth = width;
@@ -73,7 +73,10 @@ namespace CamelotEngine {
 
 
 		mSize = getNumFaces() * PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat);
 		mSize = getNumFaces() * PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat);
 
 
-		RenderSystem::instancePtr()->queueCommand(boost::bind(&Texture::initialize_internal, this));
+		if(internalCall)
+			initialize_internal();
+		else
+			RenderSystem::instancePtr()->queueCommand(boost::bind(&Texture::initialize_internal, this));
 	}
 	}
     //--------------------------------------------------------------------------
     //--------------------------------------------------------------------------
     bool Texture::hasAlpha(void) const
     bool Texture::hasAlpha(void) const

+ 2 - 2
CamelotRenderer/Source/CmTextureManager.cpp

@@ -54,10 +54,10 @@ namespace CamelotEngine {
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     TexturePtr TextureManager::createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, int numMipmaps,
     TexturePtr TextureManager::createTexture(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, int numMipmaps,
         PixelFormat format, int usage, bool hwGamma, 
         PixelFormat format, int usage, bool hwGamma, 
-		UINT32 fsaa, const String& fsaaHint)
+		UINT32 fsaa, const String& fsaaHint, bool internalCall)
     {
     {
         TexturePtr ret = TexturePtr(createTextureImpl(), boost::bind(&TextureManager::destroy, this, _1));
         TexturePtr ret = TexturePtr(createTextureImpl(), boost::bind(&TextureManager::destroy, this, _1));
-		ret->initialize(texType, width, height, depth, static_cast<size_t>(numMipmaps), format, usage, hwGamma, fsaa, fsaaHint);
+		ret->initialize(texType, width, height, depth, static_cast<size_t>(numMipmaps), format, usage, hwGamma, fsaa, fsaaHint, internalCall);
 
 
 		return ret;
 		return ret;
     }
     }