Browse Source

RenderTexture is initialized fully via initialize() and is immutable after

Marko Pintera 13 years ago
parent
commit
181d9f6431

+ 5 - 1
CamelotD3D11RenderSystem/Include/CmD3D11RenderTexture.h

@@ -18,6 +18,10 @@ namespace CamelotEngine
 		friend class D3D11TextureManager;
 		friend class D3D11TextureManager;
 
 
 		D3D11RenderTexture();
 		D3D11RenderTexture();
-		void createInternalResourcesImpl();
+
+		/**
+		 * @copydoc RenderTexture::initialize_internal().
+		 */
+		void initialize_internal();
 	};
 	};
 }
 }

+ 1 - 1
CamelotD3D11RenderSystem/Include/CmD3D11RenderWindow.h

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

+ 1 - 2
CamelotD3D11RenderSystem/Include/CmD3D11Texture.h

@@ -78,7 +78,6 @@ namespace CamelotEngine
 		 */
 		 */
 		void destroy_internal();
 		void destroy_internal();
 
 
-		TextureView* createView();
-		void destroyView(TextureView* view);
+		TextureViewPtr createView();
 	};
 	};
 }
 }

+ 9 - 5
CamelotD3D11RenderSystem/Include/CmD3D11TextureView.h

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

+ 2 - 2
CamelotD3D11RenderSystem/Source/CmD3D11MultiRenderTexture.cpp

@@ -29,7 +29,7 @@ namespace CamelotEngine
 			ID3D11RenderTargetView** pRTVs = (ID3D11RenderTargetView **)pData;
 			ID3D11RenderTargetView** pRTVs = (ID3D11RenderTargetView **)pData;
 			for(size_t x = 0; x < mColorSurfaces.size(); ++x)		
 			for(size_t x = 0; x < mColorSurfaces.size(); ++x)		
 			{
 			{
-				D3D11TextureView* textureView = static_cast<D3D11TextureView*>(mColorSurfaces[x]);
+				D3D11TextureView* textureView = static_cast<D3D11TextureView*>(mColorSurfaces[x].get());
 				pRTVs[x] = textureView->getRTV();	
 				pRTVs[x] = textureView->getRTV();	
 			}
 			}
 
 
@@ -39,7 +39,7 @@ namespace CamelotEngine
 		{
 		{
 			ID3D11DepthStencilView** pDSV = (ID3D11DepthStencilView **)pData;
 			ID3D11DepthStencilView** pDSV = (ID3D11DepthStencilView **)pData;
 
 
-			D3D11TextureView* depthStencilView = static_cast<D3D11TextureView*>(mDepthStencilSurface);
+			D3D11TextureView* depthStencilView = static_cast<D3D11TextureView*>(mDepthStencilSurface.get());
 			*pDSV = depthStencilView->getDSV();
 			*pDSV = depthStencilView->getDSV();
 			return;
 			return;
 		}
 		}

+ 3 - 3
CamelotD3D11RenderSystem/Source/CmD3D11RenderTexture.cpp

@@ -19,7 +19,7 @@ namespace CamelotEngine
 	{
 	{
 	}
 	}
 
 
-	void D3D11RenderTexture::createInternalResourcesImpl()
+	void D3D11RenderTexture::initialize_internal()
 	{
 	{
 		// Do nothing
 		// Do nothing
 	}
 	}
@@ -29,7 +29,7 @@ namespace CamelotEngine
 		if(name == "RTV")
 		if(name == "RTV")
 		{
 		{
 			ID3D11RenderTargetView** pRTVs = (ID3D11RenderTargetView **)pData;			
 			ID3D11RenderTargetView** pRTVs = (ID3D11RenderTargetView **)pData;			
-			D3D11TextureView* textureView = static_cast<D3D11TextureView*>(mColorSurface);
+			D3D11TextureView* textureView = static_cast<D3D11TextureView*>(mColorSurface.get());
 			*pRTVs = textureView->getRTV();		
 			*pRTVs = textureView->getRTV();		
 
 
 			return;
 			return;
@@ -37,7 +37,7 @@ namespace CamelotEngine
 		else if(name == "DSV")
 		else if(name == "DSV")
 		{
 		{
 			ID3D11DepthStencilView** pDSV = (ID3D11DepthStencilView **)pData;
 			ID3D11DepthStencilView** pDSV = (ID3D11DepthStencilView **)pData;
-			D3D11TextureView* depthStencilView = static_cast<D3D11TextureView*>(mDepthStencilSurface);
+			D3D11TextureView* depthStencilView = static_cast<D3D11TextureView*>(mDepthStencilSurface.get());
 			*pDSV = depthStencilView->getDSV();
 			*pDSV = depthStencilView->getDSV();
 			return;
 			return;
 		}
 		}

+ 1 - 1
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -359,7 +359,7 @@ namespace CamelotEngine
 		}
 		}
 		else if(name == "DSV")
 		else if(name == "DSV")
 		{
 		{
-			D3D11TextureView* d3d11TextureView = static_cast<D3D11TextureView*>(mDepthStencilView);
+			D3D11TextureView* d3d11TextureView = static_cast<D3D11TextureView*>(mDepthStencilView.get());
 			*static_cast<ID3D11DepthStencilView**>(pData) = d3d11TextureView->getDSV();
 			*static_cast<ID3D11DepthStencilView**>(pData) = d3d11TextureView->getDSV();
 			return;
 			return;
 		}
 		}

+ 4 - 7
CamelotD3D11RenderSystem/Source/CmD3D11Texture.cpp

@@ -588,15 +588,12 @@ namespace CamelotEngine
 		}
 		}
 	}
 	}
 
 
-	TextureView* D3D11Texture::createView()
+	TextureViewPtr D3D11Texture::createView()
 	{
 	{
-		return new D3D11TextureView();
-	}
+		TextureViewPtr viewPtr(new D3D11TextureView(), &CoreGpuObject::_deleteDelayed);
+		viewPtr->setThisPtr(viewPtr);
 
 
-	void D3D11Texture::destroyView(TextureView* view)
-	{
-		if(view != nullptr)
-			delete view;
+		return viewPtr;
 	}
 	}
 }
 }
 
 

+ 7 - 5
CamelotD3D11RenderSystem/Source/CmD3D11TextureView.cpp

@@ -13,11 +13,9 @@ namespace CamelotEngine
 
 
 	}
 	}
 
 
-	void D3D11TextureView::initialize(TexturePtr texture, TEXTURE_VIEW_DESC& _desc)
+	void D3D11TextureView::initialize_internal()
 	{
 	{
-		TextureView::initialize(texture, _desc);
-
-		D3D11Texture* d3d11Texture = static_cast<D3D11Texture*>(texture.get());
+		D3D11Texture* d3d11Texture = static_cast<D3D11Texture*>(mOwnerTexture.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);
@@ -27,14 +25,18 @@ namespace CamelotEngine
 			mDSV = createDSV(d3d11Texture, mDesc.mostDetailMip, mDesc.numMips, mDesc.firstArraySlice, mDesc.numArraySlices);
 			mDSV = createDSV(d3d11Texture, mDesc.mostDetailMip, mDesc.numMips, mDesc.firstArraySlice, mDesc.numArraySlices);
 		else
 		else
 			mSRV = createSRV(d3d11Texture, mDesc.mostDetailMip, mDesc.numMips, mDesc.firstArraySlice, mDesc.numArraySlices);
 			mSRV = createSRV(d3d11Texture, mDesc.mostDetailMip, mDesc.numMips, mDesc.firstArraySlice, mDesc.numArraySlices);
+
+		TextureView::initialize_internal();
 	}
 	}
 
 
-	D3D11TextureView::~D3D11TextureView()
+	void D3D11TextureView::destroy_internal()
 	{
 	{
 		SAFE_RELEASE(mSRV);
 		SAFE_RELEASE(mSRV);
 		SAFE_RELEASE(mUAV);
 		SAFE_RELEASE(mUAV);
 		SAFE_RELEASE(mDSV);
 		SAFE_RELEASE(mDSV);
 		SAFE_RELEASE(mRTV);
 		SAFE_RELEASE(mRTV);
+
+		TextureView::destroy_internal();
 	}
 	}
 
 
 	ID3D11ShaderResourceView* D3D11TextureView::createSRV(D3D11Texture* texture, 
 	ID3D11ShaderResourceView* D3D11TextureView::createSRV(D3D11Texture* texture, 

+ 5 - 2
CamelotD3D9Renderer/Include/CmD3D9RenderTexture.h

@@ -19,9 +19,12 @@ namespace CamelotEngine
 
 
 		D3D9RenderTexture();
 		D3D9RenderTexture();
 
 
+		/**
+		 * @copydoc RenderTexture::initialize_internal().
+		 */
+		void initialize_internal();
+
 		IDirect3DSurface9* mDX9ColorSurface;
 		IDirect3DSurface9* mDX9ColorSurface;
 		IDirect3DSurface9* mDX9DepthStencilSurface;
 		IDirect3DSurface9* mDX9DepthStencilSurface;
-
-		void createInternalResourcesImpl();
 	};
 	};
 }
 }

+ 3 - 1
CamelotD3D9Renderer/Source/CmD3D9RenderTexture.cpp

@@ -39,7 +39,7 @@ namespace CamelotEngine
 		}
 		}
 	}
 	}
 
 
-	void D3D9RenderTexture::createInternalResourcesImpl()
+	void D3D9RenderTexture::initialize_internal()
 	{
 	{
 		D3D9Texture* d3d9texture = static_cast<D3D9Texture*>(mColorSurface->getTexture().get());
 		D3D9Texture* d3d9texture = static_cast<D3D9Texture*>(mColorSurface->getTexture().get());
 		D3D9PixelBuffer* pixelBuffer = static_cast<D3D9PixelBuffer*>(
 		D3D9PixelBuffer* pixelBuffer = static_cast<D3D9PixelBuffer*>(
@@ -50,5 +50,7 @@ namespace CamelotEngine
 		D3D9PixelBuffer* depthStencilBuffer = static_cast<D3D9PixelBuffer*>(
 		D3D9PixelBuffer* depthStencilBuffer = static_cast<D3D9PixelBuffer*>(
 			d3d9DepthStencil->getBuffer(mDepthStencilSurface->getFirstArraySlice(), mDepthStencilSurface->getMostDetailedMip()).get());
 			d3d9DepthStencil->getBuffer(mDepthStencilSurface->getFirstArraySlice(), mDepthStencilSurface->getMostDetailedMip()).get());
 		mDX9DepthStencilSurface = depthStencilBuffer->getSurface(D3D9RenderSystem::getActiveD3D9Device());
 		mDX9DepthStencilSurface = depthStencilBuffer->getSurface(D3D9RenderSystem::getActiveD3D9Device());
+
+		RenderTexture::initialize_internal();
 	}
 	}
 }
 }

+ 5 - 2
CamelotGLRenderer/Include/CmGLRenderTexture.h

@@ -54,14 +54,17 @@ namespace CamelotEngine
 
 
 		GLRenderTexture();
 		GLRenderTexture();
 
 
+		/**
+		 * @copydoc RenderTexture::initialize_internal().
+		 */
+		void initialize_internal();
+
 		/**
 		/**
 		 * @copydoc RenderTexture::destroy_internal().
 		 * @copydoc RenderTexture::destroy_internal().
 		 */
 		 */
 		void destroy_internal();
 		void destroy_internal();
 
 
 		GLFrameBufferObject* mFB;
 		GLFrameBufferObject* mFB;
-
-		void createInternalResourcesImpl();
     };
     };
 
 
     /** Manager/factory for RenderTextures.
     /** Manager/factory for RenderTextures.

+ 3 - 1
CamelotGLRenderer/Source/CmGLRenderTexture.cpp

@@ -50,7 +50,7 @@ namespace CamelotEngine
 		RenderTexture::destroy_internal();
 		RenderTexture::destroy_internal();
 	}
 	}
 
 
-	void GLRenderTexture::createInternalResourcesImpl()
+	void GLRenderTexture::initialize_internal()
 	{
 	{
 		if(mFB != nullptr)
 		if(mFB != nullptr)
 			delete mFB;
 			delete mFB;
@@ -72,6 +72,8 @@ namespace CamelotEngine
 			glDepthStencilTexture->getBuffer(mDepthStencilSurface->getFirstArraySlice(), mDepthStencilSurface->getMostDetailedMip()));
 			glDepthStencilTexture->getBuffer(mDepthStencilSurface->getFirstArraySlice(), mDepthStencilSurface->getMostDetailedMip()));
 
 
 		mFB->bindDepthStencil(depthStencilBuffer);
 		mFB->bindDepthStencil(depthStencilBuffer);
+
+		RenderTexture::initialize_internal();
 	}
 	}
 
 
 	void GLRenderTexture::getCustomAttribute(const String& name, void* pData)
 	void GLRenderTexture::getCustomAttribute(const String& name, void* pData)

+ 2 - 2
CamelotRenderer/Include/CmMultiRenderTexture.h

@@ -16,8 +16,8 @@ namespace CamelotEngine
 		bool requiresTextureFlipping() const { return false; }
 		bool requiresTextureFlipping() const { return false; }
 
 
 	protected:
 	protected:
-		vector<TextureView*>::type mColorSurfaces;
-		TextureView* mDepthStencilSurface;
+		vector<TextureViewPtr>::type mColorSurfaces;
+		TextureViewPtr mDepthStencilSurface;
 
 
 		MultiRenderTexture();
 		MultiRenderTexture();
 
 

+ 1 - 0
CamelotRenderer/Include/CmPrerequisites.h

@@ -163,6 +163,7 @@ namespace CamelotEngine {
 	struct RASTERIZER_STATE_DESC;
 	struct RASTERIZER_STATE_DESC;
 	struct BLEND_STATE_DESC;
 	struct BLEND_STATE_DESC;
 	struct RENDER_TARGET_BLEND_STATE_DESC;
 	struct RENDER_TARGET_BLEND_STATE_DESC;
+	struct RENDER_TEXTURE_DESC;
 }
 }
 
 
 /* Shared pointer typedefs*/
 /* Shared pointer typedefs*/

+ 18 - 8
CamelotRenderer/Include/CmRenderTexture.h

@@ -34,6 +34,20 @@ THE SOFTWARE.
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {    
 {    
+	struct RENDER_SURFACE_DESC
+	{
+		TexturePtr texture;
+		UINT32 face;
+		UINT32 numFaces;
+		UINT32 mipLevel;
+	};
+
+	struct CM_EXPORT RENDER_TEXTURE_DESC
+	{
+		RENDER_SURFACE_DESC colorSurface;
+		RENDER_SURFACE_DESC depthStencilSurface;
+	};
+
 	/** \addtogroup Core
 	/** \addtogroup Core
 	*  @{
 	*  @{
 	*/
 	*/
@@ -50,25 +64,21 @@ namespace CamelotEngine
 	public:
 	public:
 		virtual ~RenderTexture();
 		virtual ~RenderTexture();
 
 
-		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; }
 
 
+		void initialize(const RENDER_TEXTURE_DESC& desc);
+
 	protected:
 	protected:
 		RenderTexture();
 		RenderTexture();
 
 
-		void createInternalResources();
-		virtual void createInternalResourcesImpl() = 0;
-
 		/**
 		/**
 		 * @copydoc RenderTarget::destroy_internal()
 		 * @copydoc RenderTarget::destroy_internal()
 		 */
 		 */
 		virtual void destroy_internal();
 		virtual void destroy_internal();
 
 
 	protected:
 	protected:
-		TextureView* mColorSurface;
-		TextureView* mDepthStencilSurface;
+		TextureViewPtr mColorSurface;
+		TextureViewPtr mDepthStencilSurface;
 
 
 	private:
 	private:
 		void throwIfBuffersDontMatch() const;
 		void throwIfBuffersDontMatch() const;

+ 5 - 6
CamelotRenderer/Include/CmTexture.h

@@ -203,22 +203,21 @@ namespace CamelotEngine {
 		/* 								TEXTURE VIEW                      		*/
 		/* 								TEXTURE VIEW                      		*/
 		/************************************************************************/
 		/************************************************************************/
 
 
-		static TextureView* requestView(TexturePtr texture, UINT32 mostDetailMip, UINT32 numMips, UINT32 firstArraySlice, UINT32 numArraySlices, GpuViewUsage usage);
-		static void releaseView(TextureView* view);
+		static TextureViewPtr requestView(TexturePtr texture, UINT32 mostDetailMip, UINT32 numMips, UINT32 firstArraySlice, UINT32 numArraySlices, GpuViewUsage usage);
+		static void releaseView(TextureViewPtr view);
 
 
 	protected:
 	protected:
 
 
-		virtual TextureView* createView();
-		virtual void destroyView(TextureView* view);
+		virtual TextureViewPtr createView();
 		void clearBufferViews();
 		void clearBufferViews();
 
 
 		struct TextureViewReference
 		struct TextureViewReference
 		{
 		{
-			TextureViewReference(TextureView* _view)
+			TextureViewReference(TextureViewPtr _view)
 				:view(_view), refCount(0)
 				:view(_view), refCount(0)
 			{ }
 			{ }
 
 
-			TextureView* view;
+			TextureViewPtr view;
 			UINT32 refCount;
 			UINT32 refCount;
 		};
 		};
 
 

+ 2 - 3
CamelotRenderer/Include/CmTextureManager.h

@@ -174,10 +174,9 @@ namespace CamelotEngine {
 			bool createDepth = true, PixelFormat depthStencilFormat = PF_D24S8);
 			bool createDepth = true, PixelFormat depthStencilFormat = PF_D24S8);
 
 
 		/**
 		/**
-		 * @brief	Creates an empty RenderTexture. You need to assign color and depth/stencil buffers to
-		 * 			it manually before using it.
+		 * @brief	Creates a RenderTexture using the description struct.
 		 */
 		 */
-		virtual RenderTexturePtr createEmptyRenderTexture();
+		virtual RenderTexturePtr createRenderTexture(const RENDER_TEXTURE_DESC& desc);
 
 
 		/**
 		/**
 		 * @brief	Creates a new multi render texture. You may use this type of texture
 		 * @brief	Creates a new multi render texture. You may use this type of texture

+ 8 - 2
CamelotRenderer/Include/CmTextureView.h

@@ -1,6 +1,7 @@
 #pragma once
 #pragma once
 
 
 #include "CmPrerequisites.h"
 #include "CmPrerequisites.h"
+#include "CmCoreGpuObject.h"
 #include "CmCommonEnums.h"
 #include "CmCommonEnums.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
@@ -14,7 +15,7 @@ namespace CamelotEngine
 		GpuViewUsage usage;
 		GpuViewUsage usage;
 	};
 	};
 
 
-	class CM_EXPORT TextureView
+	class CM_EXPORT TextureView : public CoreGpuObject
 	{
 	{
 	public:
 	public:
 		class HashFunction
 		class HashFunction
@@ -29,7 +30,8 @@ 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();
+		virtual ~TextureView();
+
 		virtual void initialize(TexturePtr texture, TEXTURE_VIEW_DESC& _desc);
 		virtual void initialize(TexturePtr texture, TEXTURE_VIEW_DESC& _desc);
 
 
 		UINT32 getMostDetailedMip() const { return mDesc.mostDetailMip; }
 		UINT32 getMostDetailedMip() const { return mDesc.mostDetailMip; }
@@ -42,7 +44,11 @@ namespace CamelotEngine
 		TexturePtr getTexture() const { return mOwnerTexture; }
 		TexturePtr getTexture() const { return mOwnerTexture; }
 
 
 	protected:
 	protected:
+		friend class Texture;
+
 		TEXTURE_VIEW_DESC mDesc;
 		TEXTURE_VIEW_DESC mDesc;
 		TexturePtr mOwnerTexture;
 		TexturePtr mOwnerTexture;
+
+		TextureView();
 	};
 	};
 }
 }

+ 1 - 1
CamelotRenderer/Source/CmMultiRenderTexture.cpp

@@ -87,7 +87,7 @@ namespace CamelotEngine
 
 
 	void MultiRenderTexture::throwIfBuffersDontMatch() const
 	void MultiRenderTexture::throwIfBuffersDontMatch() const
 	{
 	{
-		const TextureView* firstSurfaceDesc = nullptr;
+		TextureViewPtr firstSurfaceDesc = nullptr;
 		for(size_t i = 0; i < mColorSurfaces.size(); i++)
 		for(size_t i = 0; i < mColorSurfaces.size(); i++)
 		{
 		{
 			if(mColorSurfaces[i] == nullptr)
 			if(mColorSurfaces[i] == nullptr)

+ 35 - 55
CamelotRenderer/Source/CmRenderTexture.cpp

@@ -56,8 +56,41 @@ namespace CamelotEngine
 		RenderTarget::destroy_internal();
 		RenderTarget::destroy_internal();
 	}
 	}
 
 
-	void RenderTexture::createInternalResources()
+	void RenderTexture::initialize(const RENDER_TEXTURE_DESC& desc)
 	{
 	{
+		if(desc.colorSurface.texture != nullptr)
+		{
+			TexturePtr texture = desc.colorSurface.texture;
+
+			if(texture->getUsage() != TU_RENDERTARGET)
+				CM_EXCEPT(InvalidParametersException, "Provided texture is not created with render target usage.");
+
+			mColorSurface = Texture::requestView(texture, desc.colorSurface.mipLevel, 1, 
+				desc.colorSurface.face, desc.colorSurface.numFaces, GVU_RENDERTARGET);
+
+			mPriority = CM_REND_TO_TEX_RT_GROUP;
+			mWidth = texture->getWidth();
+			mHeight = texture->getWidth();
+			mColorDepth = CamelotEngine::PixelUtil::getNumElemBits(texture->getFormat());
+			mActive = true;
+			mHwGamma = texture->isHardwareGammaEnabled();
+			mFSAA = texture->getFSAA();
+			mFSAAHint = texture->getFSAAHint();
+		}
+
+		if(desc.depthStencilSurface.texture != nullptr)
+		{
+			TexturePtr texture = desc.depthStencilSurface.texture;
+
+			if(texture->getUsage() != TU_DEPTHSTENCIL)
+				CM_EXCEPT(InvalidParametersException, "Provided texture is not created with depth stencil usage.");
+
+			mDepthStencilSurface = Texture::requestView(texture, desc.depthStencilSurface.mipLevel, 1, 
+				desc.depthStencilSurface.face, desc.depthStencilSurface.numFaces, GVU_DEPTHSTENCIL);
+		}
+
+		throwIfBuffersDontMatch();
+
 		assert(mColorSurface != nullptr);
 		assert(mColorSurface != nullptr);
 		assert(mColorSurface->getTexture() != nullptr);
 		assert(mColorSurface->getTexture() != nullptr);
 
 
@@ -77,60 +110,7 @@ namespace CamelotEngine
 				toString(mColorSurface->getMostDetailedMip()) + ". Max num mipmaps: " + toString(mColorSurface->getTexture()->getNumMipmaps()));
 				toString(mColorSurface->getMostDetailedMip()) + ". Max num mipmaps: " + toString(mColorSurface->getTexture()->getNumMipmaps()));
 		}
 		}
 
 
-		createInternalResourcesImpl();
-	}
-
-	void RenderTexture::setColorSurface(TexturePtr texture, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
-	{
-		if(texture != nullptr && texture->getUsage() != TU_RENDERTARGET)
-			CM_EXCEPT(InvalidParametersException, "Provided texture is not created with render target usage.");
-
-		if(mColorSurface != nullptr)
-		{
-			mColorSurface->getTexture()->releaseView(mColorSurface);
-			mColorSurface = nullptr;
-		}
-
-		if(texture == nullptr)
-			return;
-
-		mColorSurface = Texture::requestView(texture, mipLevel, 1, face, numFaces, GVU_RENDERTARGET);
-
-		mPriority = CM_REND_TO_TEX_RT_GROUP;
-		mWidth = texture->getWidth();
-		mHeight = texture->getWidth();
-		mColorDepth = CamelotEngine::PixelUtil::getNumElemBits(texture->getFormat());
-		mActive = true;
-		mHwGamma = texture->isHardwareGammaEnabled();
-		mFSAA = texture->getFSAA();
-		mFSAAHint = texture->getFSAAHint();
-		
-		throwIfBuffersDontMatch();
-
-		if(mDepthStencilSurface != nullptr && mColorSurface != nullptr)
-			createInternalResources();
-	}
-
-	void RenderTexture::setDepthStencilSurface(TexturePtr depthStencilSurface, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
-	{
-		if(depthStencilSurface != nullptr && depthStencilSurface->getUsage() != TU_DEPTHSTENCIL)
-			CM_EXCEPT(InvalidParametersException, "Provided texture is not created with depth stencil usage.");
-
-		if(mDepthStencilSurface != nullptr)
-		{
-			mDepthStencilSurface->getTexture()->releaseView(mDepthStencilSurface);
-			mDepthStencilSurface = nullptr;
-		}
-
-		if(depthStencilSurface == nullptr)
-			return;
-
-		mDepthStencilSurface = Texture::requestView(depthStencilSurface, mipLevel, 1, face, numFaces, GVU_DEPTHSTENCIL);
-
-		throwIfBuffersDontMatch();
-
-		if(mDepthStencilSurface != nullptr && mColorSurface != nullptr)
-			createInternalResources();
+		RenderTarget::initialize();
 	}
 	}
 
 
 	void RenderTexture::throwIfBuffersDontMatch() const
 	void RenderTexture::throwIfBuffersDontMatch() const

+ 7 - 17
CamelotRenderer/Source/CmTexture.cpp

@@ -216,29 +216,20 @@ namespace CamelotEngine {
 	/* 								TEXTURE VIEW                      		*/
 	/* 								TEXTURE VIEW                      		*/
 	/************************************************************************/
 	/************************************************************************/
 
 
-	TextureView* Texture::createView()
+	TextureViewPtr Texture::createView()
 	{
 	{
-		return new TextureView();
-	}
+		TextureViewPtr viewPtr(new TextureView(), &CoreGpuObject::_deleteDelayed);
+		viewPtr->setThisPtr(viewPtr);
 
 
-	void Texture::destroyView(TextureView* view)
-	{
-		if(view != nullptr)
-			delete view;
+		return viewPtr;
 	}
 	}
 
 
 	void Texture::clearBufferViews()
 	void Texture::clearBufferViews()
 	{
 	{
-		for(auto iter = mTextureViews.begin(); iter != mTextureViews.end(); ++iter)
-		{
-			destroyView(iter->second->view);
-			delete iter->second;
-		}
-
 		mTextureViews.clear();
 		mTextureViews.clear();
 	}
 	}
 
 
-	TextureView* Texture::requestView(TexturePtr texture, UINT32 mostDetailMip, UINT32 numMips, UINT32 firstArraySlice, UINT32 numArraySlices, GpuViewUsage usage)
+	TextureViewPtr Texture::requestView(TexturePtr texture, UINT32 mostDetailMip, UINT32 numMips, UINT32 firstArraySlice, UINT32 numArraySlices, GpuViewUsage usage)
 	{
 	{
 		assert(texture != nullptr);
 		assert(texture != nullptr);
 
 
@@ -252,7 +243,7 @@ namespace CamelotEngine {
 		auto iterFind = texture->mTextureViews.find(key);
 		auto iterFind = texture->mTextureViews.find(key);
 		if(iterFind == texture->mTextureViews.end())
 		if(iterFind == texture->mTextureViews.end())
 		{
 		{
-			TextureView* newView = texture->createView();
+			TextureViewPtr newView = texture->createView();
 			newView->initialize(texture, key);
 			newView->initialize(texture, key);
 			texture->mTextureViews[key] = new TextureViewReference(newView);
 			texture->mTextureViews[key] = new TextureViewReference(newView);
 
 
@@ -263,7 +254,7 @@ namespace CamelotEngine {
 		return iterFind->second->view;
 		return iterFind->second->view;
 	}
 	}
 
 
-	void Texture::releaseView(TextureView* view)
+	void Texture::releaseView(TextureViewPtr view)
 	{
 	{
 		assert(view != nullptr);
 		assert(view != nullptr);
 
 
@@ -281,7 +272,6 @@ namespace CamelotEngine {
 		{
 		{
 			TextureViewReference* toRemove = iterFind->second;
 			TextureViewReference* toRemove = iterFind->second;
 
 
-			texture->destroyView(iterFind->second->view);
 			texture->mTextureViews.erase(iterFind);
 			texture->mTextureViews.erase(iterFind);
 
 
 			delete toRemove;
 			delete toRemove;

+ 14 - 5
CamelotRenderer/Source/CmTextureManager.cpp

@@ -74,18 +74,27 @@ namespace CamelotEngine {
 			depthStencil = createTexture(TEX_TYPE_2D, width, height, 0, depthStencilFormat, TU_DEPTHSTENCIL, false, fsaa, fsaaHint);
 			depthStencil = createTexture(TEX_TYPE_2D, width, height, 0, depthStencilFormat, TU_DEPTHSTENCIL, false, fsaa, fsaaHint);
 		}
 		}
 
 
-		RenderTexturePtr newRT = createEmptyRenderTexture();
-		newRT->setColorSurface(texture, 0, 1, 0);
-		newRT->setDepthStencilSurface(depthStencil, 0, 1, 0);
-		newRT->initialize();
+		RENDER_TEXTURE_DESC desc;
+		desc.colorSurface.texture = texture;
+		desc.colorSurface.face = 0;
+		desc.colorSurface.mipLevel = 0;
+		desc.colorSurface.numFaces = 1;
+
+		desc.depthStencilSurface.texture = depthStencil;
+		desc.depthStencilSurface.face = 0;
+		desc.depthStencilSurface.mipLevel = 0;
+		desc.depthStencilSurface.numFaces = 1;
+
+		RenderTexturePtr newRT = createRenderTexture(desc);
 
 
 		return newRT;
 		return newRT;
 	}
 	}
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------
-	RenderTexturePtr TextureManager::createEmptyRenderTexture()
+	RenderTexturePtr TextureManager::createRenderTexture(const RENDER_TEXTURE_DESC& desc)
 	{
 	{
 		RenderTexturePtr newRT = RenderTexturePtr(createRenderTextureImpl(), &CoreGpuObject::_deleteDelayed);
 		RenderTexturePtr newRT = RenderTexturePtr(createRenderTextureImpl(), &CoreGpuObject::_deleteDelayed);
 		newRT->setThisPtr(newRT);
 		newRT->setThisPtr(newRT);
+		newRT->initialize(desc);
 
 
 		return newRT;
 		return newRT;
 	}
 	}

+ 5 - 2
CamelotRenderer/Source/CmTextureView.cpp

@@ -24,13 +24,16 @@ namespace CamelotEngine
 	}
 	}
 
 
 	TextureView::TextureView()
 	TextureView::TextureView()
-	{
+	{ }
 
 
-	}
+	TextureView::~TextureView()
+	{ }
 
 
 	void TextureView::initialize(TexturePtr texture, TEXTURE_VIEW_DESC& _desc)
 	void TextureView::initialize(TexturePtr texture, TEXTURE_VIEW_DESC& _desc)
 	{
 	{
 		mOwnerTexture = texture;
 		mOwnerTexture = texture;
 		mDesc = _desc;
 		mDesc = _desc;
+
+		CoreGpuObject::initialize();
 	}
 	}
 }
 }

+ 1 - 2
CamelotRenderer/TODO.txt

@@ -20,8 +20,6 @@ Pass
 GpuParamBlock - Needs to derive from CoreGpuObject and needs to be initialized better
 GpuParamBlock - Needs to derive from CoreGpuObject and needs to be initialized better
  - HardwareBufferManager::createGpuParamBlock needs &CoreGpuObject::_deleteDelayed added as a deleted to shared_ptr
  - HardwareBufferManager::createGpuParamBlock needs &CoreGpuObject::_deleteDelayed added as a deleted to shared_ptr
 
 
-Seems there is a possible deadlock when starting the render thread, while waiting for the thread to be started
-
 RenderTextures and MultiRenderTextures will only work properly if used directly from render thread, as setting each surface calls render methods, so its impossible to set one outside of render thread
 RenderTextures and MultiRenderTextures will only work properly if used directly from render thread, as setting each surface calls render methods, so its impossible to set one outside of render thread
  - also they don't have initialize_internal
  - also they don't have initialize_internal
  - I should probably make these immutable. Once they are set they can't be changed, so everything can be initialized when calling initialize()
  - I should probably make these immutable. Once they are set they can't be changed, so everything can be initialized when calling initialize()
@@ -37,6 +35,7 @@ Make sure we can add an include file to a HighLevelGpuProgram, and make sure it
  waitForVsync can probably be moved somewhere other than being directly in RenderSystem? (where is it in DX11?)
  waitForVsync can probably be moved somewhere other than being directly in RenderSystem? (where is it in DX11?)
 
 
 Go through RenderSystem classes and make sure we don't hold any raw pointer references.
 Go through RenderSystem classes and make sure we don't hold any raw pointer references.
+Seems there is a possible deadlock when starting the render thread, while waiting for the thread to be started
 
 
 Can be delayed:
 Can be delayed:
  Make sure that I am able to blit contents from render textures on all render systems
  Make sure that I am able to blit contents from render textures on all render systems