Browse Source

Modified GpuBufferViews so they hold a reference to their parent buffer

Marko Pintera 13 years ago
parent
commit
0527551a68
49 changed files with 389 additions and 442 deletions
  1. 49 49
      CamelotClient/CamelotClient.cpp
  2. 3 1
      CamelotD3D11RenderSystem/Include/CmD3D11GpuBuffer.h
  3. 5 4
      CamelotD3D11RenderSystem/Include/CmD3D11GpuBufferView.h
  4. 1 1
      CamelotD3D11RenderSystem/Include/CmD3D11HardwareBufferManager.h
  5. 2 6
      CamelotD3D11RenderSystem/Include/CmD3D11MultiRenderTexture.h
  6. 1 0
      CamelotD3D11RenderSystem/Include/CmD3D11Prerequisites.h
  7. 0 5
      CamelotD3D11RenderSystem/Include/CmD3D11RenderTexture.h
  8. 1 1
      CamelotD3D11RenderSystem/Include/CmD3D11RenderWindow.h
  9. 1 1
      CamelotD3D11RenderSystem/Include/CmD3D11Texture.h
  10. 8 1
      CamelotD3D11RenderSystem/Include/CmD3D11TextureView.h
  11. 7 2
      CamelotD3D11RenderSystem/Source/CmD3D11GpuBuffer.cpp
  12. 32 24
      CamelotD3D11RenderSystem/Source/CmD3D11GpuBufferView.cpp
  13. 2 2
      CamelotD3D11RenderSystem/Source/CmD3D11HardwareBufferManager.cpp
  14. 12 29
      CamelotD3D11RenderSystem/Source/CmD3D11MultiRenderTexture.cpp
  15. 8 139
      CamelotD3D11RenderSystem/Source/CmD3D11RenderTexture.cpp
  16. 17 2
      CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp
  17. 4 3
      CamelotD3D11RenderSystem/Source/CmD3D11Texture.cpp
  18. 10 4
      CamelotD3D11RenderSystem/Source/CmD3D11TextureView.cpp
  19. 1 1
      CamelotD3D9Renderer/Include/CmD3D9GpuBuffer.h
  20. 1 1
      CamelotD3D9Renderer/Include/CmD3D9HardwareBufferManager.h
  21. 2 2
      CamelotD3D9Renderer/Include/CmD3D9MultiRenderTexture.h
  22. 1 1
      CamelotD3D9Renderer/Source/CmD3D9GpuBuffer.cpp
  23. 2 2
      CamelotD3D9Renderer/Source/CmD3D9HardwareBufferManager.cpp
  24. 3 3
      CamelotD3D9Renderer/Source/CmD3D9MultiRenderTexture.cpp
  25. 7 4
      CamelotD3D9Renderer/Source/CmD3D9RenderTexture.cpp
  26. 1 1
      CamelotGLRenderer/Include/CmGLGpuBuffer.h
  27. 1 1
      CamelotGLRenderer/Include/CmGLHardwareBufferManager.h
  28. 1 1
      CamelotGLRenderer/Include/CmGLMultiRenderTexture.h
  29. 1 1
      CamelotGLRenderer/Source/CmGLGpuBuffer.cpp
  30. 2 2
      CamelotGLRenderer/Source/CmGLHardwareBufferManager.cpp
  31. 3 3
      CamelotGLRenderer/Source/CmGLMultiRenderTexture.cpp
  32. 7 4
      CamelotGLRenderer/Source/CmGLRenderTexture.cpp
  33. 5 5
      CamelotRenderer/Include/CmCommonEnums.h
  34. 10 3
      CamelotRenderer/Include/CmGpuBuffer.h
  35. 12 2
      CamelotRenderer/Include/CmGpuBufferView.h
  36. 1 1
      CamelotRenderer/Include/CmHardwareBufferManager.h
  37. 6 9
      CamelotRenderer/Include/CmMultiRenderTexture.h
  38. 3 1
      CamelotRenderer/Include/CmPrerequisites.h
  39. 2 11
      CamelotRenderer/Include/CmRenderTarget.h
  40. 5 8
      CamelotRenderer/Include/CmRenderTexture.h
  41. 3 3
      CamelotRenderer/Include/CmTexture.h
  42. 10 2
      CamelotRenderer/Include/CmTextureView.h
  43. 13 10
      CamelotRenderer/Source/CmGpuBuffer.cpp
  44. 7 2
      CamelotRenderer/Source/CmGpuBufferView.cpp
  45. 47 38
      CamelotRenderer/Source/CmMultiRenderTexture.cpp
  46. 46 28
      CamelotRenderer/Source/CmRenderTexture.cpp
  47. 17 13
      CamelotRenderer/Source/CmTexture.cpp
  48. 1 1
      CamelotRenderer/Source/CmTextureManager.cpp
  49. 5 4
      CamelotRenderer/Source/CmTextureView.cpp

+ 49 - 49
CamelotClient/CamelotClient.cpp

@@ -26,9 +26,9 @@ 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("CamelotD3D9RenderSystem", "CamelotForwardRenderer");
-	//gApplication().startUp("CamelotD3D11RenderSystem", "CamelotForwardRenderer");
+	gApplication().startUp("CamelotD3D11RenderSystem", "CamelotForwardRenderer");
 
 
 	RenderSystem* renderSystem = RenderSystem::instancePtr();
 	RenderSystem* renderSystem = RenderSystem::instancePtr();
 	RenderWindowPtr renderWindow = gApplication().getPrimaryRenderWindow();
 	RenderWindowPtr renderWindow = gApplication().getPrimaryRenderWindow();
@@ -74,28 +74,28 @@ int _tmain(int argc, _TCHAR* argv[])
 	//vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "hlsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 	//vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "hlsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 
 
 	/////////////////// HLSL 11 SHADERS //////////////////////////
 	/////////////////// 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);
+	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;					\
@@ -121,31 +121,31 @@ int _tmain(int argc, _TCHAR* argv[])
 	//vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "cg", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 	//vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "cg", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 
 
 	///////////////// GLSL SHADERS ////////////////////////////
 	///////////////// 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);
 	HighLevelGpuProgramHandle vertProgRef(vertProg);
 
 

+ 3 - 1
CamelotD3D11RenderSystem/Include/CmD3D11GpuBuffer.h

@@ -39,10 +39,12 @@ namespace CamelotEngine
 		void copyData(GpuBuffer& srcBuffer, UINT32 srcOffset, 
 		void copyData(GpuBuffer& srcBuffer, UINT32 srcOffset, 
 			UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
 			UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
 
 
+		ID3D11Buffer* getDX11Buffer() const;
+
 	protected:
 	protected:
 		D3D11HardwareBuffer* mBuffer;
 		D3D11HardwareBuffer* mBuffer;
 
 
-		virtual GpuBufferView* createView(GPU_BUFFER_DESC& desc);
+		virtual GpuBufferView* createView();
 		virtual void destroyView(GpuBufferView* view);
 		virtual void destroyView(GpuBufferView* view);
     };
     };
 }
 }

+ 5 - 4
CamelotD3D11RenderSystem/Include/CmD3D11GpuBufferView.h

@@ -1,7 +1,6 @@
 #pragma once
 #pragma once
 
 
 #include "CmD3D11Prerequisites.h"
 #include "CmD3D11Prerequisites.h"
-#include "CmGpuBuffer.h"
 #include "CmGpuBufferView.h"
 #include "CmGpuBufferView.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
@@ -9,14 +8,16 @@ namespace CamelotEngine
 	class CM_D3D11_EXPORT D3D11GpuBufferView : public GpuBufferView
 	class CM_D3D11_EXPORT D3D11GpuBufferView : public GpuBufferView
 	{
 	{
 	public:
 	public:
-		D3D11GpuBufferView(ID3D11Buffer* buffer, GpuBufferType type, GPU_BUFFER_DESC& desc);
+		D3D11GpuBufferView();
 		virtual ~D3D11GpuBufferView();
 		virtual ~D3D11GpuBufferView();
 
 
+		void initialize(GpuBufferPtr buffer, GPU_BUFFER_DESC& desc);
+
 	private:
 	private:
 		ID3D11ShaderResourceView* mSRV;
 		ID3D11ShaderResourceView* mSRV;
 		ID3D11UnorderedAccessView* mUAV;
 		ID3D11UnorderedAccessView* mUAV;
 
 
-		ID3D11ShaderResourceView* createSRV(ID3D11Buffer* buffer, GpuBufferType type, UINT32 firstElement, UINT32 elementWidth, UINT32 numElements);
-		ID3D11UnorderedAccessView* createUAV(ID3D11Buffer* buffer, GpuBufferType type, UINT32 firstElement, UINT32 numElements, bool useCounter);
+		ID3D11ShaderResourceView* createSRV(D3D11GpuBuffer* buffer, UINT32 firstElement, UINT32 elementWidth, UINT32 numElements);
+		ID3D11UnorderedAccessView* createUAV(D3D11GpuBuffer* buffer, UINT32 firstElement, UINT32 numElements, bool useCounter);
 	};
 	};
 }
 }

+ 1 - 1
CamelotD3D11RenderSystem/Include/CmD3D11HardwareBufferManager.h

@@ -31,7 +31,7 @@ namespace CamelotEngine
 		 *  - APPENDCONSUME buffer type can only be used with randomGpuWrite enabled  
 		 *  - APPENDCONSUME buffer type can only be used with randomGpuWrite enabled  
 		 *  - Counter can only be used with STRUCTURED buffer type
 		 *  - Counter can only be used with STRUCTURED buffer type
 		 */
 		 */
-		GenericBufferPtr createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
+		GpuBufferPtr createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
 			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
 			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
 
 
 	protected:     
 	protected:     

+ 2 - 6
CamelotD3D11RenderSystem/Include/CmD3D11MultiRenderTexture.h

@@ -16,12 +16,8 @@ namespace CamelotEngine
 		friend class D3D11TextureManager;
 		friend class D3D11TextureManager;
 
 
 		D3D11MultiRenderTexture();
 		D3D11MultiRenderTexture();
-		void initialize();
 
 
-		void setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 0, UINT32 mipLevel = 0);
-		void setDepthStencilImpl(TexturePtr depthStencilSurface);
-
-		vector<ID3D11RenderTargetView*>::type mRenderTargetViews;
-		ID3D11DepthStencilView* mDepthStencilView;
+		void setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0);
+		void setDepthStencilImpl(TexturePtr depthStencilSurface, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0);
 	};
 	};
 }
 }

+ 1 - 0
CamelotD3D11RenderSystem/Include/CmD3D11Prerequisites.h

@@ -53,6 +53,7 @@ namespace CamelotEngine
 	class D3D11SamplerState;
 	class D3D11SamplerState;
 	class D3D11DepthStencilState;
 	class D3D11DepthStencilState;
 	class D3D11InputLayoutManager;
 	class D3D11InputLayoutManager;
+	class D3D11GpuBuffer;
 
 
 	enum TypeID_D3D11
 	enum TypeID_D3D11
 	{
 	{

+ 0 - 5
CamelotD3D11RenderSystem/Include/CmD3D11RenderTexture.h

@@ -14,14 +14,9 @@ namespace CamelotEngine
 		bool requiresTextureFlipping() const { return false; }
 		bool requiresTextureFlipping() const { return false; }
 		void getCustomAttribute(const String& name, void* pData);
 		void getCustomAttribute(const String& name, void* pData);
 
 
-		static ID3D11RenderTargetView* createRenderTargetView(const SurfaceDesc& surfaceDesc);
-		static ID3D11DepthStencilView* createDepthStencilView(const TexturePtr& depthStencilSurface);
 	protected:
 	protected:
 		friend class D3D11TextureManager;
 		friend class D3D11TextureManager;
 
 
-		ID3D11RenderTargetView* mRenderTargetView;
-		ID3D11DepthStencilView* mDepthStencilView;
-
 		D3D11RenderTexture();
 		D3D11RenderTexture();
 		void createInternalResourcesImpl();
 		void createInternalResourcesImpl();
 	};
 	};

+ 1 - 1
CamelotD3D11RenderSystem/Include/CmD3D11RenderWindow.h

@@ -70,7 +70,7 @@ 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;
-		ID3D11DepthStencilView*		mDepthStencilView;
+		TextureView*				mDepthStencilView;
 		TexturePtr					mDepthStencilBuffer;
 		TexturePtr					mDepthStencilBuffer;
 
 
 		IDXGISwapChain*				mSwapChain;
 		IDXGISwapChain*				mSwapChain;

+ 1 - 1
CamelotD3D11RenderSystem/Include/CmD3D11Texture.h

@@ -83,7 +83,7 @@ namespace CamelotEngine
 		 */
 		 */
 		void freeInternalResourcesImpl();
 		void freeInternalResourcesImpl();
 
 
-		TextureView* createView(TEXTURE_VIEW_DESC& _desc);
+		TextureView* createView();
 		void destroyView(TextureView* view);
 		void destroyView(TextureView* view);
 	};
 	};
 }
 }

+ 8 - 1
CamelotD3D11RenderSystem/Include/CmD3D11TextureView.h

@@ -8,9 +8,16 @@ namespace CamelotEngine
 	class CM_D3D11_EXPORT D3D11TextureView : public TextureView
 	class CM_D3D11_EXPORT D3D11TextureView : public TextureView
 	{
 	{
 	public:
 	public:
-		D3D11TextureView(Texture* texture, TEXTURE_VIEW_DESC& _desc);
+		D3D11TextureView();
 		virtual ~D3D11TextureView();
 		virtual ~D3D11TextureView();
 
 
+		void initialize(TexturePtr texture, TEXTURE_VIEW_DESC& _desc);
+
+		ID3D11ShaderResourceView*	getSRV() const { return mSRV; }
+		ID3D11RenderTargetView*		getRTV() const { return mRTV; }
+		ID3D11UnorderedAccessView*	getUAV() const { return mUAV; }
+		ID3D11DepthStencilView*		getDSV() const { return mDSV; }
+
 	private:
 	private:
 		ID3D11ShaderResourceView*	mSRV;
 		ID3D11ShaderResourceView*	mSRV;
 		ID3D11RenderTargetView*		mRTV;
 		ID3D11RenderTargetView*		mRTV;

+ 7 - 2
CamelotD3D11RenderSystem/Source/CmD3D11GpuBuffer.cpp

@@ -68,9 +68,14 @@ namespace CamelotEngine
 		mBuffer->copyData(*d3d11SrcBuffer->mBuffer, srcOffset, dstOffset, length, discardWholeBuffer);
 		mBuffer->copyData(*d3d11SrcBuffer->mBuffer, srcOffset, dstOffset, length, discardWholeBuffer);
 	}
 	}
 
 
-	GpuBufferView* D3D11GpuBuffer::createView(GPU_BUFFER_DESC& desc)
+	ID3D11Buffer* D3D11GpuBuffer::getDX11Buffer() const 
+	{ 
+		return mBuffer->getD3DBuffer(); 
+	}
+
+	GpuBufferView* D3D11GpuBuffer::createView()
 	{
 	{
-		return new D3D11GpuBufferView(mBuffer->getD3DBuffer(), mType, desc);
+		return new D3D11GpuBufferView();
 	}
 	}
 
 
 	void D3D11GpuBuffer::destroyView(GpuBufferView* view)
 	void D3D11GpuBuffer::destroyView(GpuBufferView* view)

+ 32 - 24
CamelotD3D11RenderSystem/Source/CmD3D11GpuBufferView.cpp

@@ -1,4 +1,5 @@
 #include "CmD3D11GpuBufferView.h"
 #include "CmD3D11GpuBufferView.h"
+#include "CmD3D11GpuBuffer.h"
 #include "CmD3D11RenderSystem.h"
 #include "CmD3D11RenderSystem.h"
 #include "CmD3D11Device.h"
 #include "CmD3D11Device.h"
 #include "CmUtil.h"
 #include "CmUtil.h"
@@ -6,17 +7,10 @@
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
-	D3D11GpuBufferView::D3D11GpuBufferView(ID3D11Buffer* buffer, GpuBufferType type, GPU_BUFFER_DESC& desc)
-		:GpuBufferView(desc), mSRV(nullptr), mUAV(nullptr)
+	D3D11GpuBufferView::D3D11GpuBufferView()
+		:GpuBufferView(), mSRV(nullptr), mUAV(nullptr)
 	{
 	{
-		if((desc.usage & GVU_RANDOMWRITE) != 0)
-			mUAV = createUAV(buffer, type, desc.firstElement, desc.numElements, desc.useCounter);
-		else if((desc.usage & GVU_RENDERTARGET) != 0)
-		{
-			CM_EXCEPT(NotImplementedException, "Cannot create a render target view for buffers yet.");
-		}
-		else
-			mSRV = createSRV(buffer, type, desc.firstElement, desc.elementWidth, desc.numElements);
+
 	}
 	}
 
 
 	D3D11GpuBufferView::~D3D11GpuBufferView()
 	D3D11GpuBufferView::~D3D11GpuBufferView()
@@ -25,23 +19,38 @@ namespace CamelotEngine
 		SAFE_RELEASE(mUAV);
 		SAFE_RELEASE(mUAV);
 	}
 	}
 
 
-	ID3D11ShaderResourceView* D3D11GpuBufferView::createSRV(ID3D11Buffer* buffer, 
-		GpuBufferType type, UINT32 firstElement, UINT32 elementWidth, UINT32 numElements)
+	void D3D11GpuBufferView::initialize(GpuBufferPtr buffer, GPU_BUFFER_DESC& desc)
+	{
+		GpuBufferView::initialize(buffer, desc);
+
+		D3D11GpuBuffer* d3d11GpuBuffer = static_cast<D3D11GpuBuffer*>(buffer.get());
+
+		if((desc.usage & GVU_RANDOMWRITE) != 0)
+			mUAV = createUAV(d3d11GpuBuffer, desc.firstElement, desc.numElements, desc.useCounter);
+		else if((desc.usage & GVU_RENDERTARGET) != 0)
+		{
+			CM_EXCEPT(NotImplementedException, "Cannot create a render target view for buffers yet.");
+		}
+		else
+			mSRV = createSRV(d3d11GpuBuffer, desc.firstElement, desc.elementWidth, desc.numElements);
+	}
+
+	ID3D11ShaderResourceView* D3D11GpuBufferView::createSRV(D3D11GpuBuffer* buffer, UINT32 firstElement, UINT32 elementWidth, UINT32 numElements)
 	{
 	{
-		if(type == GBT_APPENDCONSUME)
+		if(buffer->getType() == GBT_APPENDCONSUME)
 			CM_EXCEPT(InvalidParametersException, "Cannot create ShaderResourceView for an append/consume buffer.");
 			CM_EXCEPT(InvalidParametersException, "Cannot create ShaderResourceView for an append/consume buffer.");
 
 
 		D3D11_SHADER_RESOURCE_VIEW_DESC desc;
 		D3D11_SHADER_RESOURCE_VIEW_DESC desc;
 		ZeroMemory(&desc, sizeof(desc));
 		ZeroMemory(&desc, sizeof(desc));
 
 
-		if(type == GBT_STRUCTURED)
+		if(buffer->getType() == GBT_STRUCTURED)
 		{
 		{
 			desc.Format = DXGI_FORMAT_UNKNOWN;
 			desc.Format = DXGI_FORMAT_UNKNOWN;
 			desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
 			desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
 			desc.Buffer.ElementOffset = firstElement * elementWidth;
 			desc.Buffer.ElementOffset = firstElement * elementWidth;
 			desc.Buffer.ElementWidth = elementWidth;
 			desc.Buffer.ElementWidth = elementWidth;
 		}
 		}
-		else if(type == GBT_RAW)
+		else if(buffer->getType() == GBT_RAW)
 		{
 		{
 			desc.Format = DXGI_FORMAT_R32_TYPELESS;
 			desc.Format = DXGI_FORMAT_R32_TYPELESS;
 			desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
 			desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
@@ -49,7 +58,7 @@ namespace CamelotEngine
 			desc.BufferEx.FirstElement = firstElement;
 			desc.BufferEx.FirstElement = firstElement;
 			desc.BufferEx.NumElements = numElements;
 			desc.BufferEx.NumElements = numElements;
 		}
 		}
-		else if(type == GBT_INDIRECTARGUMENT)
+		else if(buffer->getType() == GBT_INDIRECTARGUMENT)
 		{
 		{
 			desc.Format = DXGI_FORMAT_R32_UINT;
 			desc.Format = DXGI_FORMAT_R32_UINT;
 			desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
 			desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
@@ -60,7 +69,7 @@ namespace CamelotEngine
 		ID3D11ShaderResourceView* srv = nullptr;
 		ID3D11ShaderResourceView* srv = nullptr;
 
 
 		D3D11RenderSystem* d3d11rs = static_cast<D3D11RenderSystem*>(D3D11RenderSystem::instancePtr());
 		D3D11RenderSystem* d3d11rs = static_cast<D3D11RenderSystem*>(D3D11RenderSystem::instancePtr());
-		HRESULT hr = d3d11rs->getPrimaryDevice().getD3D11Device()->CreateShaderResourceView(buffer, &desc, &srv);
+		HRESULT hr = d3d11rs->getPrimaryDevice().getD3D11Device()->CreateShaderResourceView(buffer->getDX11Buffer(), &desc, &srv);
 
 
 		if (FAILED(hr) || d3d11rs->getPrimaryDevice().hasError())
 		if (FAILED(hr) || d3d11rs->getPrimaryDevice().hasError())
 		{
 		{
@@ -71,15 +80,14 @@ namespace CamelotEngine
 		return srv;
 		return srv;
 	}
 	}
 
 
-	ID3D11UnorderedAccessView* D3D11GpuBufferView::createUAV(ID3D11Buffer* buffer, 
-		GpuBufferType type, UINT32 firstElement, UINT32 numElements, bool useCounter)
+	ID3D11UnorderedAccessView* D3D11GpuBufferView::createUAV(D3D11GpuBuffer* buffer, UINT32 firstElement, UINT32 numElements, bool useCounter)
 	{
 	{
 		D3D11_UNORDERED_ACCESS_VIEW_DESC desc;
 		D3D11_UNORDERED_ACCESS_VIEW_DESC desc;
 		ZeroMemory(&desc, sizeof(desc));
 		ZeroMemory(&desc, sizeof(desc));
 
 
 		desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
 		desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
 
 
-		if(type == GBT_STRUCTURED)
+		if(buffer->getType() == GBT_STRUCTURED)
 		{
 		{
 			desc.Format = DXGI_FORMAT_UNKNOWN;
 			desc.Format = DXGI_FORMAT_UNKNOWN;
 			desc.Buffer.FirstElement = firstElement;
 			desc.Buffer.FirstElement = firstElement;
@@ -90,21 +98,21 @@ namespace CamelotEngine
 			else
 			else
 				desc.Buffer.Flags = 0;
 				desc.Buffer.Flags = 0;
 		}
 		}
-		else if(type == GBT_RAW)
+		else if(buffer->getType() == GBT_RAW)
 		{
 		{
 			desc.Format = DXGI_FORMAT_R32_TYPELESS;
 			desc.Format = DXGI_FORMAT_R32_TYPELESS;
 			desc.Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
 			desc.Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
 			desc.Buffer.FirstElement = firstElement;
 			desc.Buffer.FirstElement = firstElement;
 			desc.Buffer.NumElements = numElements;
 			desc.Buffer.NumElements = numElements;
 		}
 		}
-		else if(type == GBT_INDIRECTARGUMENT)
+		else if(buffer->getType() == GBT_INDIRECTARGUMENT)
 		{
 		{
 			desc.Format = DXGI_FORMAT_R32_UINT;
 			desc.Format = DXGI_FORMAT_R32_UINT;
 			desc.Buffer.Flags = 0;
 			desc.Buffer.Flags = 0;
 			desc.Buffer.FirstElement = firstElement;
 			desc.Buffer.FirstElement = firstElement;
 			desc.Buffer.NumElements = numElements;
 			desc.Buffer.NumElements = numElements;
 		}
 		}
-		else if(type == GBT_APPENDCONSUME)
+		else if(buffer->getType() == GBT_APPENDCONSUME)
 		{
 		{
 			desc.Format = DXGI_FORMAT_UNKNOWN;
 			desc.Format = DXGI_FORMAT_UNKNOWN;
 			desc.Buffer.Flags = D3D11_BUFFER_UAV_FLAG_APPEND;
 			desc.Buffer.Flags = D3D11_BUFFER_UAV_FLAG_APPEND;
@@ -115,7 +123,7 @@ namespace CamelotEngine
 		ID3D11UnorderedAccessView* uav = nullptr;
 		ID3D11UnorderedAccessView* uav = nullptr;
 
 
 		D3D11RenderSystem* d3d11rs = static_cast<D3D11RenderSystem*>(D3D11RenderSystem::instancePtr());
 		D3D11RenderSystem* d3d11rs = static_cast<D3D11RenderSystem*>(D3D11RenderSystem::instancePtr());
-		HRESULT hr = d3d11rs->getPrimaryDevice().getD3D11Device()->CreateUnorderedAccessView(buffer, &desc, &uav);
+		HRESULT hr = d3d11rs->getPrimaryDevice().getD3D11Device()->CreateUnorderedAccessView(buffer->getDX11Buffer(), &desc, &uav);
 
 
 		if (FAILED(hr) || d3d11rs->getPrimaryDevice().hasError())
 		if (FAILED(hr) || d3d11rs->getPrimaryDevice().hasError())
 		{
 		{

+ 2 - 2
CamelotD3D11RenderSystem/Source/CmD3D11HardwareBufferManager.cpp

@@ -49,10 +49,10 @@ namespace CamelotEngine
 		return GpuParamBlockPtr(new D3D11GpuParamBlock(blockDesc));
 		return GpuParamBlockPtr(new D3D11GpuParamBlock(blockDesc));
 	}
 	}
 
 
-	GenericBufferPtr D3D11HardwareBufferManager::createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
+	GpuBufferPtr D3D11HardwareBufferManager::createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
 		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
 		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
 	{
 	{
-		return GenericBufferPtr(new D3D11GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
+		return GpuBufferPtr(new D3D11GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
 	}
 	}
 
 
 	VertexDeclarationPtr D3D11HardwareBufferManager::createVertexDeclarationImpl(void)
 	VertexDeclarationPtr D3D11HardwareBufferManager::createVertexDeclarationImpl(void)

+ 12 - 29
CamelotD3D11RenderSystem/Source/CmD3D11MultiRenderTexture.cpp

@@ -1,11 +1,12 @@
 #include "CmD3D11MultiRenderTexture.h"
 #include "CmD3D11MultiRenderTexture.h"
 #include "CmD3D11Texture.h"
 #include "CmD3D11Texture.h"
 #include "CmD3D11RenderTexture.h"
 #include "CmD3D11RenderTexture.h"
+#include "CmD3D11TextureView.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
 	D3D11MultiRenderTexture::D3D11MultiRenderTexture()
 	D3D11MultiRenderTexture::D3D11MultiRenderTexture()
-		:MultiRenderTexture(), mDepthStencilView(nullptr)
+		:MultiRenderTexture()
 	{
 	{
 
 
 	}
 	}
@@ -16,35 +17,21 @@ 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]);
-
-		if(texture != nullptr)
-		{
-			mRenderTargetViews[surfaceIdx] = D3D11RenderTexture::createRenderTargetView(mSurfaces[surfaceIdx]);
-		}
-	}
-
-	void D3D11MultiRenderTexture::setDepthStencilImpl(TexturePtr depthStencilSurface)
-	{
-		SAFE_RELEASE(mDepthStencilView);
+	{	}
 
 
-		if(mDepthStencilView != nullptr)
-		{
-			mDepthStencilView = D3D11RenderTexture::createDepthStencilView(mDepthStencilSurface);
-		}
-	}
+	void D3D11MultiRenderTexture::setDepthStencilImpl(TexturePtr depthStencilSurface, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
+	{	}
 
 
 	void D3D11MultiRenderTexture::getCustomAttribute(const String& name, void* pData)
 	void D3D11MultiRenderTexture::getCustomAttribute(const String& name, void* pData)
 	{
 	{
 		if(name == "RTV")
 		if(name == "RTV")
 		{
 		{
 			ID3D11RenderTargetView** pRTVs = (ID3D11RenderTargetView **)pData;
 			ID3D11RenderTargetView** pRTVs = (ID3D11RenderTargetView **)pData;
-			for(size_t x = 0; x < mRenderTargetViews.size(); ++x)							
-				pRTVs[x] = mRenderTargetViews[x];			
+			for(size_t x = 0; x < mColorSurfaces.size(); ++x)		
+			{
+				D3D11TextureView* textureView = static_cast<D3D11TextureView*>(mColorSurfaces[x]);
+				pRTVs[x] = textureView->getRTV();	
+			}
 
 
 			return;
 			return;
 		}
 		}
@@ -52,13 +39,9 @@ namespace CamelotEngine
 		{
 		{
 			ID3D11DepthStencilView** pDSV = (ID3D11DepthStencilView **)pData;
 			ID3D11DepthStencilView** pDSV = (ID3D11DepthStencilView **)pData;
 
 
-			*pDSV = mDepthStencilView;
+			D3D11TextureView* depthStencilView = static_cast<D3D11TextureView*>(mDepthStencilSurface);
+			*pDSV = depthStencilView->getDSV();
 			return;
 			return;
 		}
 		}
 	}
 	}
-
-	void D3D11MultiRenderTexture::initialize()
-	{
-		mRenderTargetViews.resize(CM_MAX_MULTIPLE_RENDER_TARGETS);
-	}
 }
 }

+ 8 - 139
CamelotD3D11RenderSystem/Source/CmD3D11RenderTexture.cpp

@@ -3,173 +3,42 @@
 #include "CmD3D11Device.h"
 #include "CmD3D11Device.h"
 #include "CmD3D11Texture.h"
 #include "CmD3D11Texture.h"
 #include "CmD3D11Mappings.h"
 #include "CmD3D11Mappings.h"
+#include "CmD3D11TextureView.h"
 #include "CmTextureManager.h"
 #include "CmTextureManager.h"
 #include "CmException.h"
 #include "CmException.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
 	D3D11RenderTexture::D3D11RenderTexture()
 	D3D11RenderTexture::D3D11RenderTexture()
-		:RenderTexture(), mRenderTargetView(nullptr)
+		:RenderTexture()
 	{
 	{
 
 
 	}
 	}
 
 
 	D3D11RenderTexture::~D3D11RenderTexture()
 	D3D11RenderTexture::~D3D11RenderTexture()
 	{
 	{
-		SAFE_RELEASE(mRenderTargetView);
-		SAFE_RELEASE(mDepthStencilView);
-	}
-
-	ID3D11RenderTargetView* D3D11RenderTexture::createRenderTargetView(const SurfaceDesc& surfaceDesc)
-	{
-		D3D11_RENDER_TARGET_VIEW_DESC RTVDesc;
-		ZeroMemory(&RTVDesc, sizeof(RTVDesc));
-
-		D3D11Texture* d3d11Texture = static_cast<D3D11Texture*>(surfaceDesc.texture.get());
-
-		RTVDesc.Format = d3d11Texture->getDXGIFormat();
-		switch(d3d11Texture->getDimension())
-		{
-		case D3D11_SRV_DIMENSION_BUFFER:
-			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
-			break;
-		case D3D11_SRV_DIMENSION_TEXTURE1D:
-			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE1D;
-			RTVDesc.Texture1D.MipSlice = surfaceDesc.mipLevel;
-			break;
-		case D3D11_SRV_DIMENSION_TEXTURE1DARRAY:
-			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE1DARRAY;
-			RTVDesc.Texture1DArray.FirstArraySlice = surfaceDesc.face;
-			RTVDesc.Texture1DArray.ArraySize = surfaceDesc.numFaces;
-			RTVDesc.Texture1DArray.MipSlice = surfaceDesc.mipLevel;
-			break;
-		case D3D11_SRV_DIMENSION_TEXTURECUBE:
-			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
-			RTVDesc.Texture2DArray.FirstArraySlice = surfaceDesc.face;
-			RTVDesc.Texture2DArray.ArraySize = surfaceDesc.numFaces;
-			RTVDesc.Texture2DArray.MipSlice = surfaceDesc.mipLevel;
-			break;
-		case D3D11_SRV_DIMENSION_TEXTURE2D:
-			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
-			RTVDesc.Texture2D.MipSlice = surfaceDesc.mipLevel;
-			break;
-		case D3D11_SRV_DIMENSION_TEXTURE2DARRAY:
-			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
-			RTVDesc.Texture2DArray.FirstArraySlice = surfaceDesc.face;
-			RTVDesc.Texture2DArray.ArraySize = surfaceDesc.numFaces;
-			RTVDesc.Texture2DArray.MipSlice = surfaceDesc.mipLevel;
-			break;
-		case D3D11_SRV_DIMENSION_TEXTURE2DMS:
-			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
-			break;
-		case D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY:
-			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY;
-			RTVDesc.Texture2DMSArray.FirstArraySlice = surfaceDesc.face;
-			RTVDesc.Texture2DMSArray.ArraySize = surfaceDesc.numFaces;
-			break;
-		case D3D11_SRV_DIMENSION_TEXTURE3D:
-			RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
-			RTVDesc.Texture3D.MipSlice = surfaceDesc.mipLevel;
-			RTVDesc.Texture3D.FirstWSlice = surfaceDesc.face;
-			RTVDesc.Texture3D.WSize = surfaceDesc.numFaces;
-			break;
-		default:
-			assert(false);
-		}
-
-		ID3D11RenderTargetView* rtv;
-		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
-		D3D11Device& device = rs->getPrimaryDevice();
-		HRESULT hr = device.getD3D11Device()->CreateRenderTargetView(d3d11Texture->getDX11Resource(), &RTVDesc, &rtv);
-
-		if (FAILED(hr) || device.hasError())
-		{
-			String errorDescription = device.getErrorDescription();
-			CM_EXCEPT(RenderingAPIException, "Error creating Render Target View\nError Description:" + errorDescription);
-		}
-
-		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(mDepthStencilView);
-
-		mRenderTargetView = createRenderTargetView(mSurface);
-		mDepthStencilView = createDepthStencilView(mDepthStencilSurface);
+		// Do nothing
 	}
 	}
 
 
 	void D3D11RenderTexture::getCustomAttribute(const String& name, void* pData)
 	void D3D11RenderTexture::getCustomAttribute(const String& name, void* pData)
 	{
 	{
 		if(name == "RTV")
 		if(name == "RTV")
 		{
 		{
-			ID3D11RenderTargetView** pRTVs = (ID3D11RenderTargetView **)pData;						
-			*pRTVs = mRenderTargetView;		
+			ID3D11RenderTargetView** pRTVs = (ID3D11RenderTargetView **)pData;			
+			D3D11TextureView* textureView = static_cast<D3D11TextureView*>(mColorSurface);
+			*pRTVs = textureView->getRTV();		
 
 
 			return;
 			return;
 		}
 		}
 		else if(name == "DSV")
 		else if(name == "DSV")
 		{
 		{
 			ID3D11DepthStencilView** pDSV = (ID3D11DepthStencilView **)pData;
 			ID3D11DepthStencilView** pDSV = (ID3D11DepthStencilView **)pData;
-			*pDSV = mDepthStencilView;
+			D3D11TextureView* depthStencilView = static_cast<D3D11TextureView*>(mDepthStencilSurface);
+			*pDSV = depthStencilView->getDSV();
 			return;
 			return;
 		}
 		}
 	}
 	}

+ 17 - 2
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -3,6 +3,7 @@
 #include "CmD3D11RenderSystem.h"
 #include "CmD3D11RenderSystem.h"
 #include "CmD3D11Device.h"
 #include "CmD3D11Device.h"
 #include "CmD3D11RenderTexture.h"
 #include "CmD3D11RenderTexture.h"
+#include "CmD3D11TextureView.h"
 #include "CmTextureManager.h"
 #include "CmTextureManager.h"
 #include "CmException.h"
 #include "CmException.h"
 
 
@@ -22,6 +23,7 @@ namespace CamelotEngine
 		, mBackBuffer(nullptr)
 		, mBackBuffer(nullptr)
 		, mSwapChain(nullptr)
 		, mSwapChain(nullptr)
 		, mHWnd(0)
 		, mHWnd(0)
+		, mDepthStencilView(nullptr)
 	{
 	{
 		ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
 		ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
 	}
 	}
@@ -180,6 +182,12 @@ namespace CamelotEngine
 			DestroyWindow(mHWnd);
 			DestroyWindow(mHWnd);
 		}
 		}
 
 
+		if(mDepthStencilView != nullptr)
+		{
+			Texture::releaseView(mDepthStencilView);
+			mDepthStencilView = nullptr;
+		}
+
 		mHWnd = nullptr;
 		mHWnd = nullptr;
 	}
 	}
 
 
@@ -348,7 +356,8 @@ namespace CamelotEngine
 		}
 		}
 		else if(name == "DSV")
 		else if(name == "DSV")
 		{
 		{
-			*static_cast<ID3D11DepthStencilView**>(pData) = mDepthStencilView;
+			D3D11TextureView* d3d11TextureView = static_cast<D3D11TextureView*>(mDepthStencilView);
+			*static_cast<ID3D11DepthStencilView**>(pData) = d3d11TextureView->getDSV();
 			return;
 			return;
 		}
 		}
 
 
@@ -514,7 +523,13 @@ namespace CamelotEngine
 		mDepthStencilBuffer = TextureManager::instance().createTexture(TEX_TYPE_2D, 
 		mDepthStencilBuffer = TextureManager::instance().createTexture(TEX_TYPE_2D, 
 			BBDesc.Width, BBDesc.Height, 0, PF_D24S8, TU_DEPTHSTENCIL, false, mFSAA, mFSAAHint, true);
 			BBDesc.Width, BBDesc.Height, 0, PF_D24S8, TU_DEPTHSTENCIL, false, mFSAA, mFSAAHint, true);
 
 
-		mDepthStencilView = D3D11RenderTexture::createDepthStencilView(mDepthStencilBuffer);
+		if(mDepthStencilView != nullptr)
+		{
+			Texture::releaseView(mDepthStencilView);
+			mDepthStencilView = nullptr;
+		}
+
+		mDepthStencilView = Texture::requestView(mDepthStencilBuffer, 0, 1, 0, 1, GVU_DEPTHSTENCIL);
 	}
 	}
 
 
 	void D3D11RenderWindow::_destroySizeDependedD3DResources()
 	void D3D11RenderWindow::_destroySizeDependedD3DResources()

+ 4 - 3
CamelotD3D11RenderSystem/Source/CmD3D11Texture.cpp

@@ -15,7 +15,8 @@
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
 	D3D11Texture::D3D11Texture()
 	D3D11Texture::D3D11Texture()
-		: m1DTex(nullptr)
+		: Texture()
+		, m1DTex(nullptr)
 		, m2DTex(nullptr)
 		, m2DTex(nullptr)
 		, m3DTex(nullptr)
 		, m3DTex(nullptr)
 		, mTex(nullptr)
 		, mTex(nullptr)
@@ -590,9 +591,9 @@ namespace CamelotEngine
 		}
 		}
 	}
 	}
 
 
-	TextureView* D3D11Texture::createView(TEXTURE_VIEW_DESC& _desc)
+	TextureView* D3D11Texture::createView()
 	{
 	{
-		return new D3D11TextureView(this, _desc);
+		return new D3D11TextureView();
 	}
 	}
 
 
 	void D3D11Texture::destroyView(TextureView* view)
 	void D3D11Texture::destroyView(TextureView* view)

+ 10 - 4
CamelotD3D11RenderSystem/Source/CmD3D11TextureView.cpp

@@ -7,11 +7,17 @@
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
-	D3D11TextureView::D3D11TextureView(Texture* texture, TEXTURE_VIEW_DESC& _desc)
-		:TextureView(texture, _desc),
-		mSRV(nullptr), mUAV(nullptr), mDSV(nullptr), mRTV(nullptr)
+	D3D11TextureView::D3D11TextureView()
+		:TextureView(), mSRV(nullptr), mUAV(nullptr), mDSV(nullptr), mRTV(nullptr)
 	{
 	{
-		D3D11Texture* d3d11Texture = static_cast<D3D11Texture*>(texture);
+
+	}
+
+	void D3D11TextureView::initialize(TexturePtr texture, TEXTURE_VIEW_DESC& _desc)
+	{
+		TextureView::initialize(texture, _desc);
+
+		D3D11Texture* d3d11Texture = static_cast<D3D11Texture*>(texture.get());
 
 
 		if((mDesc.usage & GVU_RANDOMWRITE) != 0)
 		if((mDesc.usage & GVU_RANDOMWRITE) != 0)
 			mUAV = createUAV(d3d11Texture, mDesc.mostDetailMip, mDesc.numMips, mDesc.firstArraySlice, mDesc.numArraySlices);
 			mUAV = createUAV(d3d11Texture, mDesc.mostDetailMip, mDesc.numMips, mDesc.firstArraySlice, mDesc.numArraySlices);

+ 1 - 1
CamelotD3D9Renderer/Include/CmD3D9GpuBuffer.h

@@ -39,7 +39,7 @@ namespace CamelotEngine
 			UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
 			UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
 
 
 	protected:
 	protected:
-		virtual GpuBufferView* createView(GPU_BUFFER_DESC& desc);
+		virtual GpuBufferView* createView();
 		virtual void destroyView(GpuBufferView* view);
 		virtual void destroyView(GpuBufferView* view);
 	};
 	};
 }
 }

+ 1 - 1
CamelotD3D9Renderer/Include/CmD3D9HardwareBufferManager.h

@@ -64,7 +64,7 @@ namespace CamelotEngine {
 		 *
 		 *
 		 * DirectX 9 does not support generic buffers so this method will return a dummy instance.
 		 * DirectX 9 does not support generic buffers so this method will return a dummy instance.
 		 */
 		 */
-		GenericBufferPtr createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
+		GpuBufferPtr createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
 			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
 			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
     };
     };
 }
 }

+ 2 - 2
CamelotD3D9Renderer/Include/CmD3D9MultiRenderTexture.h

@@ -19,8 +19,8 @@ namespace CamelotEngine
 		D3D9MultiRenderTexture();
 		D3D9MultiRenderTexture();
 		void initialize();
 		void initialize();
 
 
-		void setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 0, UINT32 mipLevel = 0);
-		void setDepthStencilImpl(TexturePtr depthStencilSurface);
+		void setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0);
+		void setDepthStencilImpl(TexturePtr depthStencilSurface, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0);
 
 
 		vector<IDirect3DSurface9*>::type mDX9ColorSurfaces;
 		vector<IDirect3DSurface9*>::type mDX9ColorSurfaces;
 		IDirect3DSurface9* mDX9DepthStencilSurface;
 		IDirect3DSurface9* mDX9DepthStencilSurface;

+ 1 - 1
CamelotD3D9Renderer/Source/CmD3D9GpuBuffer.cpp

@@ -36,7 +36,7 @@ namespace CamelotEngine
 	{
 	{
 	}
 	}
 
 
-	GpuBufferView* D3D9GpuBuffer::createView(GPU_BUFFER_DESC& desc)
+	GpuBufferView* D3D9GpuBuffer::createView()
 	{
 	{
 		return nullptr;
 		return nullptr;
 	}
 	}

+ 2 - 2
CamelotD3D9Renderer/Source/CmD3D9HardwareBufferManager.cpp

@@ -72,10 +72,10 @@ namespace CamelotEngine {
 		return GpuParamBlockPtr(new GpuParamBlock(paramDesc));
 		return GpuParamBlockPtr(new GpuParamBlock(paramDesc));
 	}
 	}
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------
-	GenericBufferPtr D3D9HardwareBufferManager::createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
+	GpuBufferPtr D3D9HardwareBufferManager::createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
 		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
 		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
 	{
 	{
-		return GenericBufferPtr(new D3D9GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
+		return GpuBufferPtr(new D3D9GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
 	}
 	}
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     VertexDeclarationPtr D3D9HardwareBufferManager::createVertexDeclarationImpl(void)
     VertexDeclarationPtr D3D9HardwareBufferManager::createVertexDeclarationImpl(void)

+ 3 - 3
CamelotD3D9Renderer/Source/CmD3D9MultiRenderTexture.cpp

@@ -29,12 +29,12 @@ namespace CamelotEngine
 		}
 		}
 	}
 	}
 
 
-	void D3D9MultiRenderTexture::setDepthStencilImpl(TexturePtr depthStencilSurface)
+	void D3D9MultiRenderTexture::setDepthStencilImpl(TexturePtr depthStencilSurface, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
 	{
 	{
 		if(depthStencilSurface != nullptr)
 		if(depthStencilSurface != nullptr)
 		{
 		{
-			D3D9Texture* d3d9DepthStencil = static_cast<D3D9Texture*>(mDepthStencilSurface.get());
-			D3D9PixelBuffer* pixelBuffer = static_cast<D3D9PixelBuffer*>(d3d9DepthStencil->getBuffer(0, 0).get());
+			D3D9Texture* d3d9DepthStencil = static_cast<D3D9Texture*>(depthStencilSurface.get());
+			D3D9PixelBuffer* pixelBuffer = static_cast<D3D9PixelBuffer*>(d3d9DepthStencil->getBuffer(face, mipLevel).get());
 			mDX9DepthStencilSurface = pixelBuffer->getSurface(D3D9RenderSystem::getActiveD3D9Device());
 			mDX9DepthStencilSurface = pixelBuffer->getSurface(D3D9RenderSystem::getActiveD3D9Device());
 		}
 		}
 		else
 		else

+ 7 - 4
CamelotD3D9Renderer/Source/CmD3D9RenderTexture.cpp

@@ -2,6 +2,7 @@
 #include "CmD3D9Texture.h"
 #include "CmD3D9Texture.h"
 #include "CmD3D9PixelBuffer.h"
 #include "CmD3D9PixelBuffer.h"
 #include "CmD3D9RenderSystem.h"
 #include "CmD3D9RenderSystem.h"
+#include "CmTextureView.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
@@ -40,12 +41,14 @@ namespace CamelotEngine
 
 
 	void D3D9RenderTexture::createInternalResourcesImpl()
 	void D3D9RenderTexture::createInternalResourcesImpl()
 	{
 	{
-		D3D9Texture* d3d9texture = static_cast<D3D9Texture*>(mSurface.texture.get());
-		D3D9PixelBuffer* pixelBuffer = static_cast<D3D9PixelBuffer*>(d3d9texture->getBuffer(mSurface.face, mSurface.mipLevel).get());
+		D3D9Texture* d3d9texture = static_cast<D3D9Texture*>(mColorSurface->getTexture().get());
+		D3D9PixelBuffer* pixelBuffer = static_cast<D3D9PixelBuffer*>(
+			d3d9texture->getBuffer(mColorSurface->getFirstArraySlice(), mColorSurface->getMostDetailedMip()).get());
 		mDX9ColorSurface = pixelBuffer->getSurface(D3D9RenderSystem::getActiveD3D9Device());
 		mDX9ColorSurface = pixelBuffer->getSurface(D3D9RenderSystem::getActiveD3D9Device());
 
 
-		D3D9Texture* d3d9DepthStencil = static_cast<D3D9Texture*>(mDepthStencilSurface.get());
-		D3D9PixelBuffer* depthStencilBuffer = static_cast<D3D9PixelBuffer*>(d3d9DepthStencil->getBuffer(0, 0).get());
+		D3D9Texture* d3d9DepthStencil = static_cast<D3D9Texture*>(mDepthStencilSurface->getTexture().get());
+		D3D9PixelBuffer* depthStencilBuffer = static_cast<D3D9PixelBuffer*>(
+			d3d9DepthStencil->getBuffer(mDepthStencilSurface->getFirstArraySlice(), mDepthStencilSurface->getMostDetailedMip()).get());
 		mDX9DepthStencilSurface = depthStencilBuffer->getSurface(D3D9RenderSystem::getActiveD3D9Device());
 		mDX9DepthStencilSurface = depthStencilBuffer->getSurface(D3D9RenderSystem::getActiveD3D9Device());
 	}
 	}
 }
 }

+ 1 - 1
CamelotGLRenderer/Include/CmGLGpuBuffer.h

@@ -39,7 +39,7 @@ namespace CamelotEngine
 			UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
 			UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
 
 
 	protected:
 	protected:
-		virtual GpuBufferView* createView(GPU_BUFFER_DESC& desc);
+		virtual GpuBufferView* createView();
 		virtual void destroyView(GpuBufferView* view);
 		virtual void destroyView(GpuBufferView* view);
 	};
 	};
 }
 }

+ 1 - 1
CamelotGLRenderer/Include/CmGLHardwareBufferManager.h

@@ -70,7 +70,7 @@ namespace CamelotEngine {
 		 *
 		 *
 		 * OpenGL does not support generic buffers so this method will return a dummy instance.
 		 * OpenGL does not support generic buffers so this method will return a dummy instance.
 		 */
 		 */
-		GenericBufferPtr createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
+		GpuBufferPtr createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
 			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
 			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
 
 
         /// Utility function to get the correct GL usage based on HBU's
         /// Utility function to get the correct GL usage based on HBU's

+ 1 - 1
CamelotGLRenderer/Include/CmGLMultiRenderTexture.h

@@ -20,7 +20,7 @@ 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(TexturePtr depthStencilSurface);
+		void setDepthStencilImpl(TexturePtr depthStencilSurface, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0);
 	private:
 	private:
 		GLFrameBufferObject* mFB;
 		GLFrameBufferObject* mFB;
 	};
 	};

+ 1 - 1
CamelotGLRenderer/Source/CmGLGpuBuffer.cpp

@@ -36,7 +36,7 @@ namespace CamelotEngine
 	{
 	{
 	}
 	}
 
 
-	GpuBufferView* GLGpuBuffer::createView(GPU_BUFFER_DESC& desc)
+	GpuBufferView* GLGpuBuffer::createView()
 	{
 	{
 		return nullptr;
 		return nullptr;
 	}
 	}

+ 2 - 2
CamelotGLRenderer/Source/CmGLHardwareBufferManager.cpp

@@ -109,10 +109,10 @@ namespace CamelotEngine {
 		return GpuParamBlockPtr(new GLGpuParamBlock(paramDesc));
 		return GpuParamBlockPtr(new GLGpuParamBlock(paramDesc));
 	}
 	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
-	GenericBufferPtr GLHardwareBufferManager::createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
+	GpuBufferPtr GLHardwareBufferManager::createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
 		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
 		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
 	{
 	{
-		return GenericBufferPtr(new GLGpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
+		return GpuBufferPtr(new GLGpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
 	}
 	}
     //---------------------------------------------------------------------
     //---------------------------------------------------------------------
     GLenum GLHardwareBufferManager::getGLUsage(unsigned int usage)
     GLenum GLHardwareBufferManager::getGLUsage(unsigned int usage)

+ 3 - 3
CamelotGLRenderer/Source/CmGLMultiRenderTexture.cpp

@@ -34,12 +34,12 @@ namespace CamelotEngine
 		}
 		}
 	}
 	}
 
 
-	void GLMultiRenderTexture::setDepthStencilImpl(TexturePtr depthStencilSurface)
+	void GLMultiRenderTexture::setDepthStencilImpl(TexturePtr depthStencilSurface, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
 	{
 	{
 		if(depthStencilSurface != nullptr)
 		if(depthStencilSurface != nullptr)
 		{
 		{
-			GLTexture* glDepthStencilSurface = static_cast<GLTexture*>(mDepthStencilSurface.get());
-			GLPixelBufferPtr depthStencilBuffer = std::static_pointer_cast<GLPixelBuffer>(glDepthStencilSurface->getBuffer(0, 0));
+			GLTexture* glDepthStencilSurface = static_cast<GLTexture*>(depthStencilSurface.get());
+			GLPixelBufferPtr depthStencilBuffer = std::static_pointer_cast<GLPixelBuffer>(glDepthStencilSurface->getBuffer(face, mipLevel));
 
 
 			mFB->bindDepthStencil(depthStencilBuffer);
 			mFB->bindDepthStencil(depthStencilBuffer);
 		}
 		}

+ 7 - 4
CamelotGLRenderer/Source/CmGLRenderTexture.cpp

@@ -28,6 +28,7 @@ THE SOFTWARE.
 #include "CmGLRenderTexture.h"
 #include "CmGLRenderTexture.h"
 #include "CmGLPixelFormat.h"
 #include "CmGLPixelFormat.h"
 #include "CmGLPixelBuffer.h"
 #include "CmGLPixelBuffer.h"
+#include "CmTextureView.h"
 
 
 namespace CamelotEngine 
 namespace CamelotEngine 
 {
 {
@@ -53,13 +54,15 @@ namespace CamelotEngine
 		surfaceDesc.numSamples = mFSAA;
 		surfaceDesc.numSamples = mFSAA;
 		surfaceDesc.zoffset = 0;
 		surfaceDesc.zoffset = 0;
 
 
-		GLTexture* glTexture = static_cast<GLTexture*>(mSurface.texture.get());
-		surfaceDesc.buffer = std::static_pointer_cast<GLPixelBuffer>(glTexture->getBuffer(mSurface.face, mSurface.mipLevel));
+		GLTexture* glTexture = static_cast<GLTexture*>(mColorSurface->getTexture().get());
+		surfaceDesc.buffer = std::static_pointer_cast<GLPixelBuffer>(
+			glTexture->getBuffer(mColorSurface->getFirstArraySlice(), mColorSurface->getMostDetailedMip()));
 
 
 		mFB->bindSurface(0, surfaceDesc);
 		mFB->bindSurface(0, surfaceDesc);
 
 
-		GLTexture* glDepthStencilTexture = static_cast<GLTexture*>(mDepthStencilSurface.get());
-		GLPixelBufferPtr depthStencilBuffer = std::static_pointer_cast<GLPixelBuffer>(glDepthStencilTexture->getBuffer(0, 0));
+		GLTexture* glDepthStencilTexture = static_cast<GLTexture*>(mDepthStencilSurface->getTexture().get());
+		GLPixelBufferPtr depthStencilBuffer = std::static_pointer_cast<GLPixelBuffer>(
+			glDepthStencilTexture->getBuffer(mDepthStencilSurface->getFirstArraySlice(), mDepthStencilSurface->getMostDetailedMip()));
 
 
 		mFB->bindDepthStencil(depthStencilBuffer);
 		mFB->bindDepthStencil(depthStencilBuffer);
 	}
 	}

+ 5 - 5
CamelotRenderer/Include/CmCommonEnums.h

@@ -248,14 +248,14 @@ namespace CamelotEngine {
 	};
 	};
 
 
 	/**
 	/**
-	 * @brief	Combine these to generate a different type of gpu views
+	 * @brief	Different types of gpu views
 	 */
 	 */
 	enum GpuViewUsage
 	enum GpuViewUsage
 	{
 	{
-		GVU_DEFAULT,
-		GVU_RENDERTARGET,
-		GVU_DEPTHSTENCIL,
-		GVU_RANDOMWRITE
+		GVU_DEFAULT = 0x01,
+		GVU_RENDERTARGET = 0x02,
+		GVU_DEPTHSTENCIL = 0x04,
+		GVU_RANDOMWRITE = 0x08
 	};
 	};
 
 
 	/** Texture addressing mode for each texture coordinate. */
 	/** Texture addressing mode for each texture coordinate. */

+ 10 - 3
CamelotRenderer/Include/CmGpuBuffer.h

@@ -21,8 +21,15 @@ namespace CamelotEngine
 		virtual void copyData(GpuBuffer& srcBuffer, UINT32 srcOffset, 
 		virtual void copyData(GpuBuffer& srcBuffer, UINT32 srcOffset, 
 			UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false) = 0;
 			UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false) = 0;
 
 
-		GpuBufferView* requestView(UINT32 firstElement, UINT32 elementWidth, UINT32 numElements, bool useCounter, GpuViewUsage usage);
-		void releaseView(GpuBufferView* view);
+		static GpuBufferView* requestView(GpuBufferPtr buffer, UINT32 firstElement, UINT32 elementWidth, UINT32 numElements, bool useCounter, GpuViewUsage usage);
+		static void releaseView(GpuBufferView* view);
+
+		GpuBufferType getType() const { return mType; }
+		GpuBufferUsage getUsage() const { return mUsage; }
+		bool getRandomGpuWrite() const { return mRandomGpuWrite; }
+		bool getUseCounter() const { return mUseCounter; }
+		UINT32 getElementCount() const { return mElementCount; }
+		UINT32 getElementSize() const { return mElementSize; }
 
 
 	protected:
 	protected:
 		GpuBufferType mType;
 		GpuBufferType mType;
@@ -32,7 +39,7 @@ namespace CamelotEngine
 		UINT32 mElementCount;
 		UINT32 mElementCount;
 		UINT32 mElementSize;
 		UINT32 mElementSize;
 
 
-		virtual GpuBufferView* createView(GPU_BUFFER_DESC& desc) = 0;
+		virtual GpuBufferView* createView() = 0;
 		virtual void destroyView(GpuBufferView* view) = 0;
 		virtual void destroyView(GpuBufferView* view) = 0;
 		void clearBufferViews();
 		void clearBufferViews();
 
 

+ 12 - 2
CamelotRenderer/Include/CmGpuBufferView.h

@@ -29,12 +29,22 @@ namespace CamelotEngine
 			bool operator()(const GPU_BUFFER_DESC& a, const GPU_BUFFER_DESC& b) const;
 			bool operator()(const GPU_BUFFER_DESC& a, const GPU_BUFFER_DESC& b) const;
 		};
 		};
 
 
-		GpuBufferView(GPU_BUFFER_DESC& desc);
+		GpuBufferView();
 		virtual ~GpuBufferView();
 		virtual ~GpuBufferView();
 
 
+		virtual void initialize(GpuBufferPtr buffer, GPU_BUFFER_DESC& desc);
+
 		const GPU_BUFFER_DESC& getDesc() const { return mDesc; }
 		const GPU_BUFFER_DESC& getDesc() const { return mDesc; }
+		GpuBufferPtr getBuffer() const { return mBuffer; }
+
+		UINT32 getFirstElement() const { return mDesc.firstElement; }
+		UINT32 getElementWidth() const { return mDesc.elementWidth; }
+		UINT32 getNumElements() const { return mDesc.numElements; }
+		bool getUseCounter() const { return mDesc.useCounter; }
+		GpuViewUsage getUsage() const { return mDesc.usage; }
 
 
-	private:
+	protected:
 		GPU_BUFFER_DESC mDesc;
 		GPU_BUFFER_DESC mDesc;
+		GpuBufferPtr mBuffer;
 	};
 	};
 }
 }

+ 1 - 1
CamelotRenderer/Include/CmHardwareBufferManager.h

@@ -123,7 +123,7 @@ namespace CamelotEngine {
 		 *
 		 *
 		 * Be aware that some of these settings cannot be used together, and you will receive an assert if in debug mode.
 		 * Be aware that some of these settings cannot be used together, and you will receive an assert if in debug mode.
 		 */
 		 */
-		virtual GenericBufferPtr createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
+		virtual GpuBufferPtr createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
 			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false) = 0;
 			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false) = 0;
 
 
         /** Creates a new vertex declaration. */
         /** Creates a new vertex declaration. */

+ 6 - 9
CamelotRenderer/Include/CmMultiRenderTexture.h

@@ -10,23 +10,20 @@ namespace CamelotEngine
 	public:
 	public:
 		virtual ~MultiRenderTexture() {}
 		virtual ~MultiRenderTexture() {}
 
 
-		void setColorSurface(UINT32 surfaceIdx, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 0, UINT32 mipLevel = 0);
-		void setDepthStencilSurface(TexturePtr depthStencilbuffer);
-
-		SurfaceDesc getSurfaceDesc(UINT32 surfaceIdx) const { return mSurfaces.at(surfaceIdx); }
-		TexturePtr getDepthStencilSurface() const { return mDepthStencilSurface; }
+		void setColorSurface(UINT32 surfaceIdx, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0);
+		void setDepthStencilSurface(TexturePtr depthStencil, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0);
 
 
 		bool requiresTextureFlipping() const { return false; }
 		bool requiresTextureFlipping() const { return false; }
 
 
 	protected:
 	protected:
-		vector<SurfaceDesc>::type mSurfaces;
-		TexturePtr mDepthStencilSurface;
+		vector<TextureView*>::type mColorSurfaces;
+		TextureView* mDepthStencilSurface;
 
 
 		MultiRenderTexture();
 		MultiRenderTexture();
 		virtual void initialize() {}
 		virtual void initialize() {}
 
 
-		virtual void setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 0, UINT32 mipLevel = 0) = 0;
-		virtual void setDepthStencilImpl(TexturePtr depthStencilstencil) = 0;
+		virtual void setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0) = 0;
+		virtual void setDepthStencilImpl(TexturePtr depthStencilstencil, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0) = 0;
 	private:
 	private:
 		void throwIfBuffersDontMatch() const;
 		void throwIfBuffersDontMatch() const;
 
 

+ 3 - 1
CamelotRenderer/Include/CmPrerequisites.h

@@ -140,6 +140,7 @@ namespace CamelotEngine {
 	struct GpuParamDesc;
 	struct GpuParamDesc;
 	struct GpuParamMemberDesc;
 	struct GpuParamMemberDesc;
 	struct GpuParamBlockDesc;
 	struct GpuParamBlockDesc;
+	class TextureView;
 	// Asset import
 	// Asset import
 	class SpecificImporter;
 	class SpecificImporter;
 	class Importer;
 	class Importer;
@@ -170,7 +171,7 @@ namespace CamelotEngine
 	typedef std::shared_ptr<PixelBuffer> PixelBufferPtr;
 	typedef std::shared_ptr<PixelBuffer> PixelBufferPtr;
 	typedef std::shared_ptr<VertexBuffer> VertexBufferPtr;
 	typedef std::shared_ptr<VertexBuffer> VertexBufferPtr;
 	typedef std::shared_ptr<IndexBuffer> IndexBufferPtr;
 	typedef std::shared_ptr<IndexBuffer> IndexBufferPtr;
-	typedef std::shared_ptr<GpuBuffer> GenericBufferPtr;
+	typedef std::shared_ptr<GpuBuffer> GpuBufferPtr;
 	typedef std::shared_ptr<VertexDeclaration> VertexDeclarationPtr;
 	typedef std::shared_ptr<VertexDeclaration> VertexDeclarationPtr;
 	typedef std::shared_ptr<Mesh> MeshPtr;
 	typedef std::shared_ptr<Mesh> MeshPtr;
 	typedef std::shared_ptr<Texture> TexturePtr;
 	typedef std::shared_ptr<Texture> TexturePtr;
@@ -198,6 +199,7 @@ namespace CamelotEngine
 	typedef std::shared_ptr<MultiRenderTexture> MultiRenderTexturePtr;
 	typedef std::shared_ptr<MultiRenderTexture> MultiRenderTexturePtr;
 	typedef std::shared_ptr<GpuParamBlock> GpuParamBlockPtr;
 	typedef std::shared_ptr<GpuParamBlock> GpuParamBlockPtr;
 	typedef std::shared_ptr<GpuParams> GpuParamsPtr;
 	typedef std::shared_ptr<GpuParams> GpuParamsPtr;
+	typedef std::shared_ptr<TextureView> TextureViewPtr;
 }
 }
 
 
 // All type IDs used for RTTI
 // All type IDs used for RTTI

+ 2 - 11
CamelotRenderer/Include/CmRenderTarget.h

@@ -41,17 +41,8 @@ THE SOFTWARE.
 	#define CM_REND_TO_TEX_RT_GROUP 2
 	#define CM_REND_TO_TEX_RT_GROUP 2
 #endif
 #endif
 
 
-namespace CamelotEngine {
-
-	struct SurfaceDesc
-	{
-		TexturePtr texture;
-		UINT32 face;
-		UINT32 numFaces;
-		UINT32 mipLevel;
-		PixelFormat format;
-	};
-
+namespace CamelotEngine 
+{
 	/** \addtogroup Core
 	/** \addtogroup Core
 	*  @{
 	*  @{
 	*/
 	*/

+ 5 - 8
CamelotRenderer/Include/CmRenderTexture.h

@@ -48,19 +48,16 @@ namespace CamelotEngine
     class CM_EXPORT RenderTexture : public RenderTarget
     class CM_EXPORT RenderTexture : public RenderTarget
     {
     {
 	public:
 	public:
-		virtual ~RenderTexture() {}
+		virtual ~RenderTexture();
 
 
-		void setColorSurface(TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 0, UINT32 mipLevel = 0);
-		void setDepthStencilSurface(TexturePtr depthStencil);
-
-		SurfaceDesc getSurfaceDesc() const { return mSurface; }
-		TexturePtr getDepthStencilSurface() const { return mDepthStencilSurface; }
+		void setColorSurface(TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0);
+		void setDepthStencilSurface(TexturePtr depthStencil, UINT32 face = 0, UINT32 numFaces = 0, UINT32 mipLevel = 0);
 
 
 		bool requiresTextureFlipping() const { return false; }
 		bool requiresTextureFlipping() const { return false; }
 
 
 	protected:
 	protected:
-		SurfaceDesc mSurface;
-		TexturePtr mDepthStencilSurface;
+		TextureView* mColorSurface;
+		TextureView* mDepthStencilSurface;
 
 
 		RenderTexture();
 		RenderTexture();
 
 

+ 3 - 3
CamelotRenderer/Include/CmTexture.h

@@ -210,12 +210,12 @@ namespace CamelotEngine {
 		/* 								TEXTURE VIEW                      		*/
 		/* 								TEXTURE VIEW                      		*/
 		/************************************************************************/
 		/************************************************************************/
 
 
-		TextureView* requestView(UINT32 mostDetailMip, UINT32 numMips, UINT32 firstArraySlice, UINT32 numArraySlices, GpuViewUsage usage);
-		void releaseView(TextureView* view);
+		static TextureView* requestView(TexturePtr texture, UINT32 mostDetailMip, UINT32 numMips, UINT32 firstArraySlice, UINT32 numArraySlices, GpuViewUsage usage);
+		static void releaseView(TextureView* view);
 
 
 	protected:
 	protected:
 
 
-		virtual TextureView* createView(TEXTURE_VIEW_DESC& _desc);
+		virtual TextureView* createView();
 		virtual void destroyView(TextureView* view);
 		virtual void destroyView(TextureView* view);
 		void clearBufferViews();
 		void clearBufferViews();
 
 

+ 10 - 2
CamelotRenderer/Include/CmTextureView.h

@@ -29,12 +29,20 @@ namespace CamelotEngine
 			bool operator()(const TEXTURE_VIEW_DESC &a, const TEXTURE_VIEW_DESC &b) const;
 			bool operator()(const TEXTURE_VIEW_DESC &a, const TEXTURE_VIEW_DESC &b) const;
 		};
 		};
 
 
-		TextureView(Texture* texture, TEXTURE_VIEW_DESC& _desc);
-		virtual ~TextureView();
+		TextureView();
+		virtual void initialize(TexturePtr texture, TEXTURE_VIEW_DESC& _desc);
+
+		UINT32 getMostDetailedMip() const { return mDesc.mostDetailMip; }
+		UINT32 getNumMips() const { return mDesc.numMips; }
+		UINT32 getFirstArraySlice() const { return mDesc.firstArraySlice; }
+		UINT32 getNumArraySlices() const { return mDesc.numArraySlices; }
+		GpuViewUsage getUsage() const { return mDesc.usage; }
 
 
 		const TEXTURE_VIEW_DESC& getDesc() const { return mDesc; }
 		const TEXTURE_VIEW_DESC& getDesc() const { return mDesc; }
+		TexturePtr getTexture() const { return mOwnerTexture; }
 
 
 	protected:
 	protected:
 		TEXTURE_VIEW_DESC mDesc;
 		TEXTURE_VIEW_DESC mDesc;
+		TexturePtr mOwnerTexture;
 	};
 	};
 }
 }

+ 13 - 10
CamelotRenderer/Source/CmGpuBuffer.cpp

@@ -25,7 +25,7 @@ namespace CamelotEngine
 		mBufferViews.clear();
 		mBufferViews.clear();
 	}
 	}
 
 
-	GpuBufferView* GpuBuffer::requestView(UINT32 firstElement, UINT32 elementWidth, UINT32 numElements, bool useCounter, GpuViewUsage usage)
+	GpuBufferView* GpuBuffer::requestView(GpuBufferPtr buffer, UINT32 firstElement, UINT32 elementWidth, UINT32 numElements, bool useCounter, GpuViewUsage usage)
 	{
 	{
 		GPU_BUFFER_DESC key;
 		GPU_BUFFER_DESC key;
 		key.firstElement = firstElement;
 		key.firstElement = firstElement;
@@ -34,13 +34,14 @@ namespace CamelotEngine
 		key.numElements = numElements;
 		key.numElements = numElements;
 		key.usage = usage;
 		key.usage = usage;
 
 
-		auto iterFind = mBufferViews.find(key);
-		if(iterFind == mBufferViews.end())
+		auto iterFind = buffer->mBufferViews.find(key);
+		if(iterFind == buffer->mBufferViews.end())
 		{
 		{
-			GpuBufferView* newView = createView(key);
-			mBufferViews[key] = new GpuBufferReference(newView);
+			GpuBufferView* newView = buffer->createView();
+			newView->initialize(buffer, key);
+			buffer->mBufferViews[key] = new GpuBufferReference(newView);
 
 
-			iterFind = mBufferViews.find(key);
+			iterFind = buffer->mBufferViews.find(key);
 		}
 		}
 
 
 		iterFind->second->refCount++;
 		iterFind->second->refCount++;
@@ -49,8 +50,10 @@ namespace CamelotEngine
 
 
 	void GpuBuffer::releaseView(GpuBufferView* view)
 	void GpuBuffer::releaseView(GpuBufferView* view)
 	{
 	{
-		auto iterFind = mBufferViews.find(view->getDesc());
-		if(iterFind == mBufferViews.end())
+		GpuBufferPtr buffer = view->getBuffer();
+
+		auto iterFind = buffer->mBufferViews.find(view->getDesc());
+		if(iterFind == buffer->mBufferViews.end())
 		{
 		{
 			CM_EXCEPT(InternalErrorException, "Trying to release a buffer view that doesn't exist!");
 			CM_EXCEPT(InternalErrorException, "Trying to release a buffer view that doesn't exist!");
 		}
 		}
@@ -61,9 +64,9 @@ namespace CamelotEngine
 		{
 		{
 			GpuBufferReference* toRemove = iterFind->second;
 			GpuBufferReference* toRemove = iterFind->second;
 
 
-			mBufferViews.erase(iterFind);
+			buffer->mBufferViews.erase(iterFind);
 
 
-			destroyView(toRemove->view);
+			buffer->destroyView(toRemove->view);
 			delete toRemove;
 			delete toRemove;
 		}
 		}
 	}
 	}

+ 7 - 2
CamelotRenderer/Source/CmGpuBufferView.cpp

@@ -22,8 +22,7 @@ namespace CamelotEngine
 			&& a.numElements == b.numElements && a.useCounter == b.useCounter && a.usage == b.usage;
 			&& a.numElements == b.numElements && a.useCounter == b.useCounter && a.usage == b.usage;
 	}
 	}
 
 
-	GpuBufferView::GpuBufferView(GPU_BUFFER_DESC& desc)
-		:mDesc(desc)
+	GpuBufferView::GpuBufferView()
 	{
 	{
 
 
 	}
 	}
@@ -32,4 +31,10 @@ namespace CamelotEngine
 	{
 	{
 
 
 	}
 	}
+
+	void GpuBufferView::initialize(GpuBufferPtr buffer, GPU_BUFFER_DESC& desc)
+	{
+		mBuffer = buffer;
+		mDesc = desc;
+	}
 }
 }

+ 47 - 38
CamelotRenderer/Source/CmMultiRenderTexture.cpp

@@ -6,7 +6,7 @@ namespace CamelotEngine
 {
 {
 	MultiRenderTexture::MultiRenderTexture()
 	MultiRenderTexture::MultiRenderTexture()
 	{
 	{
-		mSurfaces.resize(CM_MAX_MULTIPLE_RENDER_TARGETS);
+		mColorSurfaces.resize(CM_MAX_MULTIPLE_RENDER_TARGETS);
 	}
 	}
 
 
 	void MultiRenderTexture::setColorSurface(UINT32 surfaceIdx, TexturePtr texture, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
 	void MultiRenderTexture::setColorSurface(UINT32 surfaceIdx, TexturePtr texture, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
@@ -17,14 +17,20 @@ namespace CamelotEngine
 		if(texture != nullptr && texture->getUsage() != TU_RENDERTARGET)
 		if(texture != nullptr && texture->getUsage() != TU_RENDERTARGET)
 			CM_EXCEPT(InvalidParametersException, "Provided texture is not created with render target usage.");
 			CM_EXCEPT(InvalidParametersException, "Provided texture is not created with render target usage.");
 
 
-		mSurfaces[surfaceIdx].texture = texture;
+		if(mColorSurfaces[surfaceIdx] != nullptr)
+		{
+			mColorSurfaces[surfaceIdx]->getTexture()->releaseView(mColorSurfaces[surfaceIdx]);
+			mColorSurfaces[surfaceIdx] = nullptr;
+		}
 
 
 		if(texture == nullptr)
 		if(texture == nullptr)
 		{
 		{
 			setColorSurfaceImpl(surfaceIdx, texture, face, numFaces, mipLevel);
 			setColorSurfaceImpl(surfaceIdx, texture, face, numFaces, mipLevel);
 			return;
 			return;
 		}
 		}
-			
+
+		mColorSurfaces[surfaceIdx] = Texture::requestView(texture, mipLevel, 1, face, numFaces, GVU_RENDERTARGET);
+
 		mPriority = CM_REND_TO_TEX_RT_GROUP;
 		mPriority = CM_REND_TO_TEX_RT_GROUP;
 		mWidth = texture->getWidth();
 		mWidth = texture->getWidth();
 		mHeight = texture->getWidth();
 		mHeight = texture->getWidth();
@@ -34,52 +40,55 @@ namespace CamelotEngine
 		mFSAA = texture->getFSAA();
 		mFSAA = texture->getFSAA();
 		mFSAAHint = texture->getFSAAHint();
 		mFSAAHint = texture->getFSAAHint();
 
 
-		mSurfaces[surfaceIdx].format = texture->getFormat();
-
-		mSurfaces[surfaceIdx].face = face;
-		mSurfaces[surfaceIdx].numFaces = numFaces;
-		mSurfaces[surfaceIdx].mipLevel = mipLevel;
-
 		throwIfBuffersDontMatch();
 		throwIfBuffersDontMatch();
 
 
 		setColorSurfaceImpl(surfaceIdx, texture, face, numFaces, mipLevel);
 		setColorSurfaceImpl(surfaceIdx, texture, face, numFaces, mipLevel);
 	}
 	}
 
 
-	void MultiRenderTexture::setDepthStencilSurface(TexturePtr depthStencilSurface)
+	void MultiRenderTexture::setDepthStencilSurface(TexturePtr depthStencil, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
 	{
 	{
-		if(depthStencilSurface != nullptr && depthStencilSurface->getUsage() != TU_DEPTHSTENCIL)
+		if(depthStencil != nullptr && depthStencil->getUsage() != TU_DEPTHSTENCIL)
 			CM_EXCEPT(InvalidParametersException, "Provided texture is not created with depth stencil usage.");
 			CM_EXCEPT(InvalidParametersException, "Provided texture is not created with depth stencil usage.");
 
 
-		mDepthStencilSurface = depthStencilSurface;
+		if(mDepthStencilSurface != nullptr)
+		{
+			Texture::releaseView(mDepthStencilSurface);
+			mDepthStencilSurface = nullptr;
+		}
+
+		if(depthStencil == nullptr)
+			return;
+
+		mDepthStencilSurface = Texture::requestView(depthStencil, mipLevel, 1, face, numFaces, GVU_DEPTHSTENCIL);
 
 
 		throwIfBuffersDontMatch();
 		throwIfBuffersDontMatch();
 
 
-		setDepthStencilImpl(depthStencilSurface);
+		setDepthStencilImpl(depthStencil, face, numFaces, mipLevel);
 	}
 	}
 
 
 	void MultiRenderTexture::throwIfBuffersDontMatch() const
 	void MultiRenderTexture::throwIfBuffersDontMatch() const
 	{
 	{
-		const SurfaceDesc* firstSurfaceDesc = nullptr;
-		for(size_t i = 0; i < mSurfaces.size(); i++)
+		const TextureView* firstSurfaceDesc = nullptr;
+		for(size_t i = 0; i < mColorSurfaces.size(); i++)
 		{
 		{
-			if(mSurfaces[i].texture == nullptr)
+			if(mColorSurfaces[i] == nullptr)
 				continue;
 				continue;
 
 
 			if(firstSurfaceDesc == nullptr)
 			if(firstSurfaceDesc == nullptr)
 			{
 			{
-				firstSurfaceDesc = &mSurfaces[i];
+				firstSurfaceDesc = mColorSurfaces[i];
 				continue;
 				continue;
 			}
 			}
 
 
-			if(mSurfaces[i].texture->getWidth() != firstSurfaceDesc->texture->getWidth() ||
-				mSurfaces[i].texture->getHeight() != firstSurfaceDesc->texture->getHeight() ||
-				mSurfaces[i].texture->getFSAA() != firstSurfaceDesc->texture->getFSAA() ||
-				mSurfaces[i].texture->getFSAAHint() != firstSurfaceDesc->texture->getFSAAHint())
+			if(mColorSurfaces[i]->getTexture()->getWidth() != firstSurfaceDesc->getTexture()->getWidth() ||
+				mColorSurfaces[i]->getTexture()->getHeight() != firstSurfaceDesc->getTexture()->getHeight() ||
+				mColorSurfaces[i]->getTexture()->getFSAA() != firstSurfaceDesc->getTexture()->getFSAA() ||
+				mColorSurfaces[i]->getTexture()->getFSAAHint() != firstSurfaceDesc->getTexture()->getFSAAHint())
 			{
 			{
-				String errorInfo = "\nWidth: " + toString(mSurfaces[i].texture->getWidth()) + "/" + toString(firstSurfaceDesc->texture->getWidth());
-				errorInfo += "\nHeight: " + toString(mSurfaces[i].texture->getHeight()) + "/" + toString(firstSurfaceDesc->texture->getHeight());
-				errorInfo += "\nFSAA: " + toString(mSurfaces[i].texture->getFSAA()) + "/" + toString(firstSurfaceDesc->texture->getFSAA());
-				errorInfo += "\nFSAAHint: " + mSurfaces[i].texture->getFSAAHint() + "/" + firstSurfaceDesc->texture->getFSAAHint();
+				String errorInfo = "\nWidth: " + toString(mColorSurfaces[i]->getTexture()->getWidth()) + "/" + toString(firstSurfaceDesc->getTexture()->getWidth());
+				errorInfo += "\nHeight: " + toString(mColorSurfaces[i]->getTexture()->getHeight()) + "/" + toString(firstSurfaceDesc->getTexture()->getHeight());
+				errorInfo += "\nFSAA: " + toString(mColorSurfaces[i]->getTexture()->getFSAA()) + "/" + toString(firstSurfaceDesc->getTexture()->getFSAA());
+				errorInfo += "\nFSAAHint: " + mColorSurfaces[i]->getTexture()->getFSAAHint() + "/" + firstSurfaceDesc->getTexture()->getFSAAHint();
 
 
 				CM_EXCEPT(InvalidParametersException, "Provided texture and depth stencil buffer don't match!" + errorInfo);
 				CM_EXCEPT(InvalidParametersException, "Provided texture and depth stencil buffer don't match!" + errorInfo);
 			}
 			}
@@ -88,33 +97,33 @@ namespace CamelotEngine
 		if(firstSurfaceDesc == nullptr)
 		if(firstSurfaceDesc == nullptr)
 			return;
 			return;
 
 
-		if(firstSurfaceDesc->texture->getTextureType() != TEX_TYPE_2D)
+		if(firstSurfaceDesc->getTexture()->getTextureType() != TEX_TYPE_2D)
 			CM_EXCEPT(NotImplementedException, "Render textures are currently only implemented for 2D surfaces.");
 			CM_EXCEPT(NotImplementedException, "Render textures are currently only implemented for 2D surfaces.");
 
 
-		if((firstSurfaceDesc->face + firstSurfaceDesc->numFaces) >= firstSurfaceDesc->texture->getNumFaces())
+		if((firstSurfaceDesc->getFirstArraySlice() + firstSurfaceDesc->getNumArraySlices()) >= firstSurfaceDesc->getTexture()->getNumFaces())
 		{
 		{
 			CM_EXCEPT(InvalidParametersException, "Provided number of faces is out of range. Face: " + 
 			CM_EXCEPT(InvalidParametersException, "Provided number of faces is out of range. Face: " + 
-				toString(firstSurfaceDesc->face + firstSurfaceDesc->numFaces) + ". Max num faces: " + toString(firstSurfaceDesc->texture->getNumFaces()));
+				toString(firstSurfaceDesc->getFirstArraySlice() + firstSurfaceDesc->getNumArraySlices()) + ". Max num faces: " + toString(firstSurfaceDesc->getTexture()->getNumFaces()));
 		}
 		}
 
 
-		if(firstSurfaceDesc->mipLevel >= firstSurfaceDesc->texture->getNumMipmaps())
+		if(firstSurfaceDesc->getMostDetailedMip() >= firstSurfaceDesc->getTexture()->getNumMipmaps())
 		{
 		{
 			CM_EXCEPT(InvalidParametersException, "Provided number of mip maps is out of range. Mip level: " + 
 			CM_EXCEPT(InvalidParametersException, "Provided number of mip maps is out of range. Mip level: " + 
-				toString(firstSurfaceDesc->mipLevel) + ". Max num mipmaps: " + toString(firstSurfaceDesc->texture->getNumMipmaps()));
+				toString(firstSurfaceDesc->getMostDetailedMip()) + ". Max num mipmaps: " + toString(firstSurfaceDesc->getTexture()->getNumMipmaps()));
 		}
 		}
 
 
 		if(mDepthStencilSurface == nullptr)
 		if(mDepthStencilSurface == nullptr)
 			return;
 			return;
 
 
-		if(mDepthStencilSurface->getWidth() != firstSurfaceDesc->texture->getWidth() ||
-			mDepthStencilSurface->getHeight() != firstSurfaceDesc->texture->getHeight() ||
-			mDepthStencilSurface->getFSAA() != firstSurfaceDesc->texture->getFSAA() ||
-			mDepthStencilSurface->getFSAAHint() != firstSurfaceDesc->texture->getFSAAHint())
+		if(mDepthStencilSurface->getTexture()->getWidth() != firstSurfaceDesc->getTexture()->getWidth() ||
+			mDepthStencilSurface->getTexture()->getHeight() != firstSurfaceDesc->getTexture()->getHeight() ||
+			mDepthStencilSurface->getTexture()->getFSAA() != firstSurfaceDesc->getTexture()->getFSAA() ||
+			mDepthStencilSurface->getTexture()->getFSAAHint() != firstSurfaceDesc->getTexture()->getFSAAHint())
 		{
 		{
-			String errorInfo = "\nWidth: " + toString(mDepthStencilSurface->getWidth()) + "/" + toString(firstSurfaceDesc->texture->getWidth());
-			errorInfo += "\nHeight: " + toString(mDepthStencilSurface->getHeight()) + "/" + toString(firstSurfaceDesc->texture->getHeight());
-			errorInfo += "\nFSAA: " + toString(mDepthStencilSurface->getFSAA()) + "/" + toString(firstSurfaceDesc->texture->getFSAA());
-			errorInfo += "\nFSAAHint: " + mDepthStencilSurface->getFSAAHint() + "/" + firstSurfaceDesc->texture->getFSAAHint();
+			String errorInfo = "\nWidth: " + toString(mDepthStencilSurface->getTexture()->getWidth()) + "/" + toString(firstSurfaceDesc->getTexture()->getWidth());
+			errorInfo += "\nHeight: " + toString(mDepthStencilSurface->getTexture()->getHeight()) + "/" + toString(firstSurfaceDesc->getTexture()->getHeight());
+			errorInfo += "\nFSAA: " + toString(mDepthStencilSurface->getTexture()->getFSAA()) + "/" + toString(firstSurfaceDesc->getTexture()->getFSAA());
+			errorInfo += "\nFSAAHint: " + mDepthStencilSurface->getTexture()->getFSAAHint() + "/" + firstSurfaceDesc->getTexture()->getFSAAHint();
 
 
 			CM_EXCEPT(InvalidParametersException, "Provided texture and depth stencil buffer don't match!" + errorInfo);
 			CM_EXCEPT(InvalidParametersException, "Provided texture and depth stencil buffer don't match!" + errorInfo);
 		}
 		}

+ 46 - 28
CamelotRenderer/Source/CmRenderTexture.cpp

@@ -35,27 +35,39 @@ THE SOFTWARE.
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
 	RenderTexture::RenderTexture()
 	RenderTexture::RenderTexture()
+		:mColorSurface(nullptr), mDepthStencilSurface(nullptr)
 	{
 	{
 
 
 	}
 	}
 
 
+	RenderTexture::~RenderTexture()
+	{
+		if(mColorSurface != nullptr)
+			Texture::releaseView(mColorSurface);
+
+		if(mDepthStencilSurface != nullptr)
+			Texture::releaseView(mDepthStencilSurface);
+	}
+
 	void RenderTexture::createInternalResources()
 	void RenderTexture::createInternalResources()
 	{
 	{
-		assert(mSurface.texture != nullptr);
+		assert(mColorSurface != nullptr);
+		assert(mColorSurface->getTexture() != nullptr);
 
 
-		if(mSurface.texture->getTextureType() != TEX_TYPE_2D)
+		if(mColorSurface->getTexture()->getTextureType() != TEX_TYPE_2D)
 			CM_EXCEPT(NotImplementedException, "Render textures are currently only implemented for 2D surfaces.");
 			CM_EXCEPT(NotImplementedException, "Render textures are currently only implemented for 2D surfaces.");
 
 
-		if((mSurface.face + mSurface.numFaces) >= mSurface.texture->getNumFaces())
+		if((mColorSurface->getFirstArraySlice() + mColorSurface->getNumArraySlices()) >= mColorSurface->getTexture()->getNumFaces())
 		{
 		{
 			CM_EXCEPT(InvalidParametersException, "Provided number of faces is out of range. Face: " + 
 			CM_EXCEPT(InvalidParametersException, "Provided number of faces is out of range. Face: " + 
-				toString(mSurface.face + mSurface.numFaces) + ". Max num faces: " + toString(mSurface.texture->getNumFaces()));
+				toString(mColorSurface->getFirstArraySlice() + mColorSurface->getNumArraySlices()) + 
+				". Max num faces: " + toString(mColorSurface->getTexture()->getNumFaces()));
 		}
 		}
 
 
-		if(mSurface.mipLevel >= mSurface.texture->getNumMipmaps())
+		if(mColorSurface->getMostDetailedMip() >= mColorSurface->getTexture()->getNumMipmaps())
 		{
 		{
 			CM_EXCEPT(InvalidParametersException, "Provided number of mip maps is out of range. Mip level: " + 
 			CM_EXCEPT(InvalidParametersException, "Provided number of mip maps is out of range. Mip level: " + 
-				toString(mSurface.mipLevel) + ". Max num mipmaps: " + toString(mSurface.texture->getNumMipmaps()));
+				toString(mColorSurface->getMostDetailedMip()) + ". Max num mipmaps: " + toString(mColorSurface->getTexture()->getNumMipmaps()));
 		}
 		}
 
 
 		createInternalResourcesImpl();
 		createInternalResourcesImpl();
@@ -66,11 +78,17 @@ namespace CamelotEngine
 		if(texture != nullptr && texture->getUsage() != TU_RENDERTARGET)
 		if(texture != nullptr && texture->getUsage() != TU_RENDERTARGET)
 			CM_EXCEPT(InvalidParametersException, "Provided texture is not created with render target usage.");
 			CM_EXCEPT(InvalidParametersException, "Provided texture is not created with render target usage.");
 
 
-		mSurface.texture = texture;
+		if(mColorSurface != nullptr)
+		{
+			mColorSurface->getTexture()->releaseView(mColorSurface);
+			mColorSurface = nullptr;
+		}
 
 
-		if(mSurface.texture == nullptr)
+		if(texture == nullptr)
 			return;
 			return;
 
 
+		mColorSurface = Texture::requestView(texture, mipLevel, 1, face, numFaces, GVU_RENDERTARGET);
+
 		mPriority = CM_REND_TO_TEX_RT_GROUP;
 		mPriority = CM_REND_TO_TEX_RT_GROUP;
 		mWidth = texture->getWidth();
 		mWidth = texture->getWidth();
 		mHeight = texture->getWidth();
 		mHeight = texture->getWidth();
@@ -79,49 +97,49 @@ namespace CamelotEngine
 		mHwGamma = texture->isHardwareGammaEnabled();
 		mHwGamma = texture->isHardwareGammaEnabled();
 		mFSAA = texture->getFSAA();
 		mFSAA = texture->getFSAA();
 		mFSAAHint = texture->getFSAAHint();
 		mFSAAHint = texture->getFSAAHint();
-
-		mSurface.format = texture->getFormat();
-		
-		mSurface.face = face;
-		mSurface.numFaces = numFaces;
-		mSurface.mipLevel = mipLevel;
 		
 		
 		throwIfBuffersDontMatch();
 		throwIfBuffersDontMatch();
 
 
-		if(mDepthStencilSurface != nullptr && mSurface.texture != nullptr)
+		if(mDepthStencilSurface != nullptr && mColorSurface != nullptr)
 			createInternalResourcesImpl();
 			createInternalResourcesImpl();
 	}
 	}
 
 
-	void RenderTexture::setDepthStencilSurface(TexturePtr depthStencilSurface)
+	void RenderTexture::setDepthStencilSurface(TexturePtr depthStencilSurface, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
 	{
 	{
 		if(depthStencilSurface != nullptr && depthStencilSurface->getUsage() != TU_DEPTHSTENCIL)
 		if(depthStencilSurface != nullptr && depthStencilSurface->getUsage() != TU_DEPTHSTENCIL)
 			CM_EXCEPT(InvalidParametersException, "Provided texture is not created with depth stencil usage.");
 			CM_EXCEPT(InvalidParametersException, "Provided texture is not created with depth stencil usage.");
 
 
-		mDepthStencilSurface = depthStencilSurface;
+		if(mDepthStencilSurface != nullptr)
+		{
+			mDepthStencilSurface->getTexture()->releaseView(mDepthStencilSurface);
+			mDepthStencilSurface = nullptr;
+		}
 
 
-		if(mDepthStencilSurface == nullptr)
+		if(depthStencilSurface == nullptr)
 			return;
 			return;
 
 
+		mDepthStencilSurface = Texture::requestView(depthStencilSurface, mipLevel, 1, face, numFaces, GVU_DEPTHSTENCIL);
+
 		throwIfBuffersDontMatch();
 		throwIfBuffersDontMatch();
 
 
-		if(mDepthStencilSurface != nullptr && mSurface.texture != nullptr)
+		if(mDepthStencilSurface != nullptr && mColorSurface != nullptr)
 			createInternalResourcesImpl();
 			createInternalResourcesImpl();
 	}
 	}
 
 
 	void RenderTexture::throwIfBuffersDontMatch() const
 	void RenderTexture::throwIfBuffersDontMatch() const
 	{
 	{
-		if(mSurface.texture == nullptr || mDepthStencilSurface == nullptr)
+		if(mColorSurface == nullptr || mDepthStencilSurface == nullptr)
 			return;
 			return;
 
 
-		if(mSurface.texture->getWidth() != mDepthStencilSurface->getWidth() ||
-			mSurface.texture->getHeight() != mDepthStencilSurface->getHeight() ||
-			mSurface.texture->getFSAA() != mDepthStencilSurface->getFSAA() ||
-			mSurface.texture->getFSAAHint() != mDepthStencilSurface->getFSAAHint())
+		if(mColorSurface->getTexture()->getWidth() != mDepthStencilSurface->getTexture()->getWidth() ||
+			mColorSurface->getTexture()->getHeight() != mDepthStencilSurface->getTexture()->getHeight() ||
+			mColorSurface->getTexture()->getFSAA() != mDepthStencilSurface->getTexture()->getFSAA() ||
+			mColorSurface->getTexture()->getFSAAHint() != mDepthStencilSurface->getTexture()->getFSAAHint())
 		{
 		{
-			String errorInfo = "\nWidth: " + toString(mSurface.texture->getWidth()) + "/" + toString(mDepthStencilSurface->getWidth());
-			errorInfo += "\nHeight: " + toString(mSurface.texture->getHeight()) + "/" + toString(mDepthStencilSurface->getHeight());
-			errorInfo += "\nFSAA: " + toString(mSurface.texture->getFSAA()) + "/" + toString(mDepthStencilSurface->getFSAA());
-			errorInfo += "\nFSAAHint: " + mSurface.texture->getFSAAHint() + "/" + mDepthStencilSurface->getFSAAHint();
+			String errorInfo = "\nWidth: " + toString(mColorSurface->getTexture()->getWidth()) + "/" + toString(mDepthStencilSurface->getTexture()->getWidth());
+			errorInfo += "\nHeight: " + toString(mColorSurface->getTexture()->getHeight()) + "/" + toString(mDepthStencilSurface->getTexture()->getHeight());
+			errorInfo += "\nFSAA: " + toString(mColorSurface->getTexture()->getFSAA()) + "/" + toString(mDepthStencilSurface->getTexture()->getFSAA());
+			errorInfo += "\nFSAAHint: " + mColorSurface->getTexture()->getFSAAHint() + "/" + mDepthStencilSurface->getTexture()->getFSAAHint();
 
 
 			CM_EXCEPT(InvalidParametersException, "Provided texture and depth stencil buffer don't match!" + errorInfo);
 			CM_EXCEPT(InvalidParametersException, "Provided texture and depth stencil buffer don't match!" + errorInfo);
 		}
 		}

+ 17 - 13
CamelotRenderer/Source/CmTexture.cpp

@@ -242,9 +242,9 @@ namespace CamelotEngine {
 	/* 								TEXTURE VIEW                      		*/
 	/* 								TEXTURE VIEW                      		*/
 	/************************************************************************/
 	/************************************************************************/
 
 
-	TextureView* Texture::createView(TEXTURE_VIEW_DESC& _desc)
+	TextureView* Texture::createView()
 	{
 	{
-		return new TextureView(this, _desc);
+		return new TextureView();
 	}
 	}
 
 
 	void Texture::destroyView(TextureView* view)
 	void Texture::destroyView(TextureView* view)
@@ -264,8 +264,10 @@ namespace CamelotEngine {
 		mTextureViews.clear();
 		mTextureViews.clear();
 	}
 	}
 
 
-	TextureView* Texture::requestView(UINT32 mostDetailMip, UINT32 numMips, UINT32 firstArraySlice, UINT32 numArraySlices, GpuViewUsage usage)
+	TextureView* Texture::requestView(TexturePtr texture, UINT32 mostDetailMip, UINT32 numMips, UINT32 firstArraySlice, UINT32 numArraySlices, GpuViewUsage usage)
 	{
 	{
+		assert(texture != nullptr);
+
 		TEXTURE_VIEW_DESC key;
 		TEXTURE_VIEW_DESC key;
 		key.mostDetailMip = mostDetailMip;
 		key.mostDetailMip = mostDetailMip;
 		key.numMips = numMips;
 		key.numMips = numMips;
@@ -273,13 +275,14 @@ namespace CamelotEngine {
 		key.numArraySlices = numArraySlices;
 		key.numArraySlices = numArraySlices;
 		key.usage = usage;
 		key.usage = usage;
 
 
-		auto iterFind = mTextureViews.find(key);
-		if(iterFind == mTextureViews.end())
+		auto iterFind = texture->mTextureViews.find(key);
+		if(iterFind == texture->mTextureViews.end())
 		{
 		{
-			TextureView* newView = createView(key);
-			mTextureViews[key] = new TextureViewReference(newView);
+			TextureView* newView = texture->createView();
+			newView->initialize(texture, key);
+			texture->mTextureViews[key] = new TextureViewReference(newView);
 
 
-			iterFind = mTextureViews.find(key);
+			iterFind = texture->mTextureViews.find(key);
 		}
 		}
 
 
 		iterFind->second->refCount++;
 		iterFind->second->refCount++;
@@ -288,10 +291,12 @@ namespace CamelotEngine {
 
 
 	void Texture::releaseView(TextureView* view)
 	void Texture::releaseView(TextureView* view)
 	{
 	{
-		TextureView key(*view);
+		assert(view != nullptr);
+
+		TexturePtr texture = view->getTexture();
 
 
-		auto iterFind = mTextureViews.find(view->getDesc());
-		if(iterFind == mTextureViews.end())
+		auto iterFind = texture->mTextureViews.find(view->getDesc());
+		if(iterFind == texture->mTextureViews.end())
 		{
 		{
 			CM_EXCEPT(InternalErrorException, "Trying to release a texture view that doesn't exist!");
 			CM_EXCEPT(InternalErrorException, "Trying to release a texture view that doesn't exist!");
 		}
 		}
@@ -302,9 +307,8 @@ namespace CamelotEngine {
 		{
 		{
 			TextureViewReference* toRemove = iterFind->second;
 			TextureViewReference* toRemove = iterFind->second;
 
 
-			mTextureViews.erase(iterFind);
+			texture->mTextureViews.erase(iterFind);
 
 
-			destroyView(toRemove->view);
 			delete toRemove;
 			delete toRemove;
 		}
 		}
 	}
 	}

+ 1 - 1
CamelotRenderer/Source/CmTextureManager.cpp

@@ -81,7 +81,7 @@ namespace CamelotEngine {
 
 
 		RenderTexturePtr newRT = RenderTexturePtr(createRenderTextureImpl());
 		RenderTexturePtr newRT = RenderTexturePtr(createRenderTextureImpl());
 		newRT->setColorSurface(texture, 0, 1, 0);
 		newRT->setColorSurface(texture, 0, 1, 0);
-		newRT->setDepthStencilSurface(depthStencil);
+		newRT->setDepthStencilSurface(depthStencil, 0, 1, 0);
 
 
 		return newRT;
 		return newRT;
 	}
 	}

+ 5 - 4
CamelotRenderer/Source/CmTextureView.cpp

@@ -1,4 +1,5 @@
 #include "CmTextureView.h"
 #include "CmTextureView.h"
+#include "CmTexture.h"
 #include "CmUtil.h"
 #include "CmUtil.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
@@ -22,14 +23,14 @@ namespace CamelotEngine
 			&& a.firstArraySlice == b.firstArraySlice && a.numArraySlices == b.numArraySlices && a.usage == b.usage;
 			&& a.firstArraySlice == b.firstArraySlice && a.numArraySlices == b.numArraySlices && a.usage == b.usage;
 	}
 	}
 
 
-	TextureView::TextureView(Texture* texture, TEXTURE_VIEW_DESC& _desc)
-		: mDesc(_desc)
+	TextureView::TextureView()
 	{
 	{
 
 
 	}
 	}
 
 
-	TextureView::~TextureView()
+	void TextureView::initialize(TexturePtr texture, TEXTURE_VIEW_DESC& _desc)
 	{
 	{
-
+		mOwnerTexture = texture;
+		mDesc = _desc;
 	}
 	}
 }
 }