Browse Source

RenderTarget derived classes now have destroy()

Marko Pintera 13 years ago
parent
commit
8c9ac4d5ce
36 changed files with 269 additions and 125 deletions
  1. 2 0
      CamelotD3D11RenderSystem/Include/CmD3D11GpuBuffer.h
  2. 2 0
      CamelotD3D11RenderSystem/Include/CmD3D11MultiRenderTexture.h
  3. 2 0
      CamelotD3D11RenderSystem/Include/CmD3D11RenderTexture.h
  4. 2 1
      CamelotD3D11RenderSystem/Include/CmD3D11RenderWindow.h
  5. 8 5
      CamelotD3D11RenderSystem/Source/CmD3D11GpuBuffer.cpp
  6. 5 0
      CamelotD3D11RenderSystem/Source/CmD3D11MultiRenderTexture.cpp
  7. 5 0
      CamelotD3D11RenderSystem/Source/CmD3D11RenderTexture.cpp
  8. 26 25
      CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp
  9. 2 0
      CamelotD3D9Renderer/Include/CmD3D9GpuBuffer.h
  10. 2 0
      CamelotD3D9Renderer/Include/CmD3D9MultiRenderTexture.h
  11. 1 0
      CamelotD3D9Renderer/Include/CmD3D9RenderTexture.h
  12. 2 2
      CamelotD3D9Renderer/Include/CmD3D9RenderWindow.h
  13. 6 3
      CamelotD3D9Renderer/Source/CmD3D9GpuBuffer.cpp
  14. 5 0
      CamelotD3D9Renderer/Source/CmD3D9MultiRenderTexture.cpp
  15. 5 0
      CamelotD3D9Renderer/Source/CmD3D9RenderTexture.cpp
  16. 20 20
      CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp
  17. 2 0
      CamelotGLRenderer/Include/CmGLGpuBuffer.h
  18. 2 0
      CamelotGLRenderer/Include/CmGLMultiRenderTexture.h
  19. 2 0
      CamelotGLRenderer/Include/CmGLRenderTexture.h
  20. 2 1
      CamelotGLRenderer/Include/CmWin32Window.h
  21. 5 1
      CamelotGLRenderer/Source/CmGLGpuBuffer.cpp
  22. 7 0
      CamelotGLRenderer/Source/CmGLMultiRenderTexture.cpp
  23. 7 0
      CamelotGLRenderer/Source/CmGLRenderTexture.cpp
  24. 42 42
      CamelotGLRenderer/Source/CmWin32Window.cpp
  25. 12 1
      CamelotRenderer/Include/CmGpuBuffer.h
  26. 7 1
      CamelotRenderer/Include/CmMultiRenderTexture.h
  27. 14 3
      CamelotRenderer/Include/CmRenderTarget.h
  28. 5 0
      CamelotRenderer/Include/CmRenderTexture.h
  29. 6 5
      CamelotRenderer/Include/CmRenderWindow.h
  30. 2 1
      CamelotRenderer/Source/CmApplication.cpp
  31. 13 0
      CamelotRenderer/Source/CmGpuBuffer.cpp
  32. 10 0
      CamelotRenderer/Source/CmMultiRenderTexture.cpp
  33. 10 9
      CamelotRenderer/Source/CmRenderTarget.cpp
  34. 7 0
      CamelotRenderer/Source/CmRenderTexture.cpp
  35. 12 2
      CamelotRenderer/Source/CmRenderWindow.cpp
  36. 7 3
      CamelotRenderer/TODO.txt

+ 2 - 0
CamelotD3D11RenderSystem/Include/CmD3D11GpuBuffer.h

@@ -46,5 +46,7 @@ namespace CamelotEngine
 
 		virtual GpuBufferView* createView();
 		virtual void destroyView(GpuBufferView* view);
+
+		void destroy_internal();
     };
 }

+ 2 - 0
CamelotD3D11RenderSystem/Include/CmD3D11MultiRenderTexture.h

@@ -19,5 +19,7 @@ namespace CamelotEngine
 
 		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);
+
+		void destroy_internal();
 	};
 }

+ 2 - 0
CamelotD3D11RenderSystem/Include/CmD3D11RenderTexture.h

@@ -19,5 +19,7 @@ namespace CamelotEngine
 
 		D3D11RenderTexture();
 		void createInternalResourcesImpl();
+
+		void destroy_internal();
 	};
 }

+ 2 - 1
CamelotD3D11RenderSystem/Include/CmD3D11RenderWindow.h

@@ -11,7 +11,6 @@ namespace CamelotEngine
 		~D3D11RenderWindow();
 
 		void initialize(const RENDER_WINDOW_DESC& desc);
-		void destroy(void);
 
 		void reposition(int left, int top);
 		void resize(unsigned int width, unsigned int height);
@@ -51,6 +50,8 @@ namespace CamelotEngine
 		bool _getSwitchingFullscreen() const					{ return mSwitchingFullscreen; }
 		void _finishSwitchingFullscreen();
 		
+		void destroy_internal();
+
 	protected:
 		D3D11Device&	mDevice;			// D3D11 driver
 		IDXGIFactory*	mDXGIFactory;

+ 8 - 5
CamelotD3D11RenderSystem/Source/CmD3D11GpuBuffer.cpp

@@ -34,11 +34,7 @@ namespace CamelotEngine
 	}
 
 	D3D11GpuBuffer::~D3D11GpuBuffer()
-	{
-		delete mBuffer;
-
-		clearBufferViews();
-	}
+	{ }
 
 	void* D3D11GpuBuffer::lock(UINT32 offset, UINT32 length, GpuLockOptions options)
 	{
@@ -83,4 +79,11 @@ namespace CamelotEngine
 		if(view != nullptr)
 			delete view;
 	}
+
+	void D3D11GpuBuffer::destroy_internal()
+	{
+		delete mBuffer;
+
+		GpuBuffer::destroy_internal();
+	}
 }

+ 5 - 0
CamelotD3D11RenderSystem/Source/CmD3D11MultiRenderTexture.cpp

@@ -16,6 +16,11 @@ namespace CamelotEngine
 
 	}
 
+	void D3D11MultiRenderTexture::destroy_internal()
+	{
+		MultiRenderTexture::destroy_internal();
+	}
+
 	void D3D11MultiRenderTexture::setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
 	{	}
 

+ 5 - 0
CamelotD3D11RenderSystem/Source/CmD3D11RenderTexture.cpp

@@ -19,6 +19,11 @@ namespace CamelotEngine
 	{
 	}
 
+	void D3D11RenderTexture::destroy_internal()
+	{
+		RenderTexture::destroy_internal();
+	}
+
 	void D3D11RenderTexture::createInternalResourcesImpl()
 	{
 		// Do nothing

+ 26 - 25
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -30,7 +30,32 @@ namespace CamelotEngine
 
 	D3D11RenderWindow::~D3D11RenderWindow()
 	{
-		destroy();
+	}
+
+	void D3D11RenderWindow::destroy_internal()
+	{
+		_destroySizeDependedD3DResources();
+
+		mActive = false;
+		mClosed = true;
+
+		SAFE_RELEASE(mSwapChain);
+
+		if (mHWnd && !mIsExternal)
+		{
+			WindowEventUtilities::_removeRenderWindow(this);
+			DestroyWindow(mHWnd);
+		}
+
+		if(mDepthStencilView != nullptr)
+		{
+			Texture::releaseView(mDepthStencilView);
+			mDepthStencilView = nullptr;
+		}
+
+		mHWnd = nullptr;
+
+		RenderWindow::destroy_internal();
 	}
 
 	void D3D11RenderWindow::initialize(const RENDER_WINDOW_DESC& desc)
@@ -167,30 +192,6 @@ namespace CamelotEngine
 		setHidden(mHidden);
 	}
 
-	void D3D11RenderWindow::destroy()
-	{
-		_destroySizeDependedD3DResources();
-
-		mActive = false;
-		mClosed = true;
-
-		SAFE_RELEASE(mSwapChain);
-
-		if (mHWnd && !mIsExternal)
-		{
-			WindowEventUtilities::_removeRenderWindow(this);
-			DestroyWindow(mHWnd);
-		}
-
-		if(mDepthStencilView != nullptr)
-		{
-			Texture::releaseView(mDepthStencilView);
-			mDepthStencilView = nullptr;
-		}
-
-		mHWnd = nullptr;
-	}
-
 	void D3D11RenderWindow::swapBuffers(bool waitForVSync)
 	{
 		if(mDevice.getD3D11Device() != nullptr)

+ 2 - 0
CamelotD3D9Renderer/Include/CmD3D9GpuBuffer.h

@@ -41,5 +41,7 @@ namespace CamelotEngine
 	protected:
 		virtual GpuBufferView* createView();
 		virtual void destroyView(GpuBufferView* view);
+
+		virtual void destroy_internal();
 	};
 }

+ 2 - 0
CamelotD3D9Renderer/Include/CmD3D9MultiRenderTexture.h

@@ -22,6 +22,8 @@ namespace CamelotEngine
 		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);
 
+		void destroy_internal();
+
 		vector<IDirect3DSurface9*>::type mDX9ColorSurfaces;
 		IDirect3DSurface9* mDX9DepthStencilSurface;
 	};

+ 1 - 0
CamelotD3D9Renderer/Include/CmD3D9RenderTexture.h

@@ -23,5 +23,6 @@ namespace CamelotEngine
 		IDirect3DSurface9* mDX9DepthStencilSurface;
 
 		void createInternalResourcesImpl();
+		void destroy_internal();
 	};
 }

+ 2 - 2
CamelotD3D9Renderer/Include/CmD3D9RenderWindow.h

@@ -49,7 +49,6 @@ namespace CamelotEngine
 		
 		void				initialize			(const RENDER_WINDOW_DESC& desc);
 		void				setFullscreen		(bool fullScreen, unsigned int width, unsigned int height);
-		void				destroy				(void);
 		bool				isActive			() const;
 		bool				isVisible			() const;
 		bool 				isClosed			() const { return mClosed; }
@@ -123,8 +122,9 @@ namespace CamelotEngine
 		unsigned int mDesiredWidth;
 		unsigned int mDesiredHeight;
 
-
 		void updateWindowRect();
+
+		void destroy_internal();
 	};
 }
 #endif

+ 6 - 3
CamelotD3D9Renderer/Source/CmD3D9GpuBuffer.cpp

@@ -10,9 +10,7 @@ namespace CamelotEngine
 	}
 
 	D3D9GpuBuffer::~D3D9GpuBuffer()
-	{
-		clearBufferViews();
-	}
+	{ }
 
 	void* D3D9GpuBuffer::lock(UINT32 offset, UINT32 length, GpuLockOptions options)
 	{
@@ -44,4 +42,9 @@ namespace CamelotEngine
 	void D3D9GpuBuffer::destroyView(GpuBufferView* view)
 	{
 	}
+
+	void D3D9GpuBuffer::destroy_internal()
+	{
+		GpuBuffer::destroy_internal();
+	}
 }

+ 5 - 0
CamelotD3D9Renderer/Source/CmD3D9MultiRenderTexture.cpp

@@ -15,6 +15,11 @@ namespace CamelotEngine
 
 	}
 
+	void D3D9MultiRenderTexture::destroy_internal()
+	{
+		MultiRenderTexture::destroy_internal();
+	}
+
 	void D3D9MultiRenderTexture::setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
 	{
 		if(texture != nullptr)

+ 5 - 0
CamelotD3D9Renderer/Source/CmD3D9RenderTexture.cpp

@@ -17,6 +17,11 @@ namespace CamelotEngine
 
 	}
 
+	void D3D9RenderTexture::destroy_internal()
+	{
+		RenderTexture::destroy_internal();
+	}
+
 	void D3D9RenderTexture::getCustomAttribute(const String& name, void* pData)
 	{
 		if(name == "DDBACKBUFFER")

+ 20 - 20
CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp

@@ -52,8 +52,27 @@ namespace CamelotEngine
 	}
 
 	D3D9RenderWindow::~D3D9RenderWindow()
+	{ }
+
+	void D3D9RenderWindow::destroy_internal()
 	{
-		destroy();
+		if (mDevice != NULL)
+		{
+			mDevice->detachRenderWindow(this);
+			mDevice = NULL;
+		}
+
+		if (mHWnd && !mIsExternal)
+		{
+			WindowEventUtilities::_removeRenderWindow(this);
+			DestroyWindow(mHWnd);
+		}
+
+		mHWnd = 0;
+		mActive = false;
+		mClosed = true;
+
+		RenderWindow::destroy_internal();
 	}
 
 	void D3D9RenderWindow::initialize(const RENDER_WINDOW_DESC& desc)
@@ -542,25 +561,6 @@ namespace CamelotEngine
 
 		}
 	}
-	
-	void D3D9RenderWindow::destroy()
-	{
-		if (mDevice != NULL)
-		{
-			mDevice->detachRenderWindow(this);
-			mDevice = NULL;
-		}
-		
-		if (mHWnd && !mIsExternal)
-		{
-			WindowEventUtilities::_removeRenderWindow(this);
-			DestroyWindow(mHWnd);
-		}
-
-		mHWnd = 0;
-		mActive = false;
-		mClosed = true;
-	}
 
 	bool D3D9RenderWindow::isActive() const
 	{

+ 2 - 0
CamelotGLRenderer/Include/CmGLGpuBuffer.h

@@ -41,5 +41,7 @@ namespace CamelotEngine
 	protected:
 		virtual GpuBufferView* createView();
 		virtual void destroyView(GpuBufferView* view);
+
+		void destroy_internal();
 	};
 }

+ 2 - 0
CamelotGLRenderer/Include/CmGLMultiRenderTexture.h

@@ -21,6 +21,8 @@ namespace CamelotEngine
 
 		void setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 0, UINT32 mipLevel = 0);
 		void setDepthStencilImpl(TexturePtr depthStencilSurface, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0);
+
+		void destroy_internal();
 	private:
 		GLFrameBufferObject* mFB;
 	};

+ 2 - 0
CamelotGLRenderer/Include/CmGLRenderTexture.h

@@ -53,6 +53,8 @@ namespace CamelotEngine
 		friend class GLTextureManager;
 
 		GLRenderTexture();
+		void destroy_internal();
+
 		GLFrameBufferObject* mFB;
 
 		void createInternalResourcesImpl();

+ 2 - 1
CamelotGLRenderer/Include/CmWin32Window.h

@@ -41,7 +41,6 @@ namespace CamelotEngine {
 
        void initialize(const RENDER_WINDOW_DESC& desc);
 	   void setFullscreen(bool fullScreen, unsigned int width, unsigned int height);
-        void destroy(void);
 		bool isActive(void) const;
         bool isVisible() const;
         bool isClosed(void) const;
@@ -82,6 +81,8 @@ namespace CamelotEngine {
 		bool	mClosed;
         int     mDisplayFrequency;      // fullscreen only, to restore display
         Win32Context *mContext;
+
+		void destroy_internal();
     };
 }
 

+ 5 - 1
CamelotGLRenderer/Source/CmGLGpuBuffer.cpp

@@ -11,7 +11,6 @@ namespace CamelotEngine
 
 	GLGpuBuffer::~GLGpuBuffer()
 	{
-		clearBufferViews();
 	}
 
 	void* GLGpuBuffer::lock(UINT32 offset, UINT32 length, GpuLockOptions options)
@@ -44,4 +43,9 @@ namespace CamelotEngine
 	void GLGpuBuffer::destroyView(GpuBufferView* view)
 	{
 	}
+
+	void GLGpuBuffer::destroy_internal()
+	{
+		GpuBuffer::destroy_internal();
+	}
 }

+ 7 - 0
CamelotGLRenderer/Source/CmGLMultiRenderTexture.cpp

@@ -10,9 +10,16 @@ namespace CamelotEngine
 	}
 
 	GLMultiRenderTexture::~GLMultiRenderTexture()
+	{
+
+	}
+
+	void GLMultiRenderTexture::destroy_internal()
 	{
 		if(mFB != nullptr)
 			delete mFB;
+
+		MultiRenderTexture::destroy_internal();
 	}
 
 	void GLMultiRenderTexture::setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face, UINT32 numFaces, UINT32 mipLevel)

+ 7 - 0
CamelotGLRenderer/Source/CmGLRenderTexture.cpp

@@ -38,9 +38,16 @@ namespace CamelotEngine
 	}
 
 	GLRenderTexture::~GLRenderTexture()
+	{
+
+	}
+
+	void GLRenderTexture::destroy_internal()
 	{
 		if(mFB != nullptr)
 			delete mFB;
+
+		RenderTexture::destroy_internal();
 	}
 
 	void GLRenderTexture::createInternalResourcesImpl()

+ 42 - 42
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -60,7 +60,48 @@ namespace CamelotEngine {
 
 	Win32Window::~Win32Window()
 	{
-		destroy();
+
+	}
+
+	void Win32Window::destroy_internal()
+	{
+		if (!mHWnd)
+			return;
+
+		// Unregister and destroy OGRE GLContext
+		delete mContext;
+
+		if (!mIsExternalGLContext && mGlrc)
+		{
+			wglDeleteContext(mGlrc);
+			mGlrc = 0;
+		}
+		if (!mIsExternal)
+		{
+			WindowEventUtilities::_removeRenderWindow(this);
+
+			if (mIsFullScreen)
+				ChangeDisplaySettingsEx(mDeviceName, NULL, NULL, 0, NULL);
+			DestroyWindow(mHWnd);
+		}
+		else
+		{
+			// just release the DC
+			ReleaseDC(mHWnd, mHDC);
+		}
+
+		mActive = false;
+		mClosed = true;
+		mHDC = 0; // no release thanks to CS_OWNDC wndclass style
+		mHWnd = 0;
+
+		if (mDeviceName != NULL)
+		{
+			delete[] mDeviceName;
+			mDeviceName = NULL;
+		}
+
+		RenderWindow::destroy_internal();
 	}
 
 	void Win32Window::initialize(const RENDER_WINDOW_DESC& desc)
@@ -524,47 +565,6 @@ namespace CamelotEngine {
 		}
 	}
 
-	void Win32Window::destroy(void)
-	{
-		if (!mHWnd)
-			return;
-
-		// Unregister and destroy OGRE GLContext
-		delete mContext;
-
-		if (!mIsExternalGLContext && mGlrc)
-		{
-			wglDeleteContext(mGlrc);
-			mGlrc = 0;
-		}
-		if (!mIsExternal)
-		{
-			WindowEventUtilities::_removeRenderWindow(this);
-
-			if (mIsFullScreen)
-				ChangeDisplaySettingsEx(mDeviceName, NULL, NULL, 0, NULL);
-			DestroyWindow(mHWnd);
-		}
-		else
-		{
-			// just release the DC
-			ReleaseDC(mHWnd, mHDC);
-		}
-
-		mActive = false;
-		mClosed = true;
-		mHDC = 0; // no release thanks to CS_OWNDC wndclass style
-		mHWnd = 0;
-
-		if (mDeviceName != NULL)
-		{
-			delete[] mDeviceName;
-			mDeviceName = NULL;
-		}
-		
-	}
-
-
 	bool Win32Window::isActive(void) const
 	{
 		if (isFullScreen())

+ 12 - 1
CamelotRenderer/Include/CmGpuBuffer.h

@@ -3,10 +3,11 @@
 #include "CmPrerequisites.h"
 #include "CmCommonEnums.h"
 #include "CmGpuBufferView.h"
+#include "CmIDestroyable.h"
 
 namespace CamelotEngine 
 {
-	class CM_EXPORT GpuBuffer
+	class CM_EXPORT GpuBuffer : public IDestroyable
     {
     public:
         GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
@@ -31,6 +32,14 @@ namespace CamelotEngine
 		UINT32 getElementCount() const { return mElementCount; }
 		UINT32 getElementSize() const { return mElementSize; }
 
+		/**
+		 * @copydoc	IDestroyable::destroy()
+		 * 			
+		 * 	@note	Destruction is not done immediately, and is instead just scheduled on the
+		 * 			render thread. Unless called from render thread in which case it is executed right away.
+		 */
+		void destroy();
+
 	protected:
 		GpuBufferType mType;
 		GpuBufferUsage mUsage;
@@ -43,6 +52,8 @@ namespace CamelotEngine
 		virtual void destroyView(GpuBufferView* view) = 0;
 		void clearBufferViews();
 
+		virtual void destroy_internal();
+
 		struct GpuBufferReference
 		{
 			GpuBufferReference(GpuBufferView* _view)

+ 7 - 1
CamelotRenderer/Include/CmMultiRenderTexture.h

@@ -8,7 +8,7 @@ namespace CamelotEngine
 	class CM_EXPORT MultiRenderTexture : public RenderTarget
 	{
 	public:
-		virtual ~MultiRenderTexture() {}
+		virtual ~MultiRenderTexture();
 
 		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);
@@ -24,6 +24,12 @@ namespace CamelotEngine
 
 		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;
+
+		/**
+		 * @copydoc RenderTarget::destroy_internal()
+		 */
+		virtual void destroy_internal();
+
 	private:
 		void throwIfBuffersDontMatch() const;
 

+ 14 - 3
CamelotRenderer/Include/CmRenderTarget.h

@@ -33,6 +33,7 @@ THE SOFTWARE.
 #include "CmString.h"
 #include "CmPixelUtil.h"
 #include "CmViewport.h"
+#include "CmIDestroyable.h"
 
 /* Define the number of priority groups for the render system's render targets. */
 #ifndef CM_NUM_RENDERTARGET_GROUPS
@@ -60,7 +61,7 @@ namespace CamelotEngine
         @version
             1.0
      */
-    class CM_EXPORT RenderTarget
+    class CM_EXPORT RenderTarget : public IDestroyable
     {
     public:
 		enum FrameBuffer
@@ -231,6 +232,14 @@ namespace CamelotEngine
 		*/
 		virtual void _endUpdate();
 
+		/**
+		 * @copydoc	IDestroyable::destroy()
+		 * 			
+		 * 	@note	Destruction is not done immediately, and is instead just scheduled on the
+		 * 			render thread. Unless called from render thread in which case it is executed right away.
+		 */
+		void destroy();
+
     protected:
         /// The name of this target.
         String mName;
@@ -248,8 +257,10 @@ namespace CamelotEngine
 		UINT32 mFSAA;
 		String mFSAAHint;
 			
-		/// Internal implementation of update()
-		virtual void updateImpl();
+		/**
+		 * @brief	Destroys all texture resources, but doesn't actually delete the object.
+		 */
+		virtual void destroy_internal();
     };
 	/** @} */
 	/** @} */

+ 5 - 0
CamelotRenderer/Include/CmRenderTexture.h

@@ -64,6 +64,11 @@ namespace CamelotEngine
 		void createInternalResources();
 		virtual void createInternalResourcesImpl() = 0;
 
+		/**
+		 * @copydoc RenderTarget::destroy_internal()
+		 */
+		virtual void destroy_internal();
+
 	private:
 		void throwIfBuffersDontMatch() const;
 

+ 6 - 5
CamelotRenderer/Include/CmRenderWindow.h

@@ -100,7 +100,7 @@ namespace CamelotEngine
         /** Default constructor.
         */
         RenderWindow();
-		virtual ~RenderWindow() {}
+		virtual ~RenderWindow();
 
         /** Creates & displays a new window.
         */
@@ -115,10 +115,6 @@ namespace CamelotEngine
 		*/
 		virtual void setFullscreen(bool fullScreen, unsigned int width, unsigned int height)
                 { (void)fullScreen; (void)width; (void)height; }
-        
-        /** Destroys the window.
-        */
-        virtual void destroy(void) = 0;
 
         /** Alter the size of the window.
         */
@@ -194,6 +190,11 @@ namespace CamelotEngine
         /** Indicates that this is the primary window. 
         */
         void _setPrimary() { mIsPrimary = true; }
+
+		/**
+		 * @copydoc RenderTarget::destroy_internal()
+		 */
+		virtual void destroy_internal();
     };
 	/** @} */
 	/** @} */

+ 2 - 1
CamelotRenderer/Source/CmApplication.cpp

@@ -139,7 +139,8 @@ namespace CamelotEngine
 		RenderSystem::shutDown();
 
 		HighLevelGpuProgramManager::shutDown();
-		//DynLibManager::shutDown();
+		//DynLibManager::shutDown(); // TODO - I never shut this down, because then I'd have to ensure I classes loaded from dynamic libraries
+		// are destroyed before shutting it down, which is too hard to ensure at the moment
 		Resources::shutDown();
 		Input::shutDown();
 		Time::shutDown();

+ 13 - 0
CamelotRenderer/Source/CmGpuBuffer.cpp

@@ -1,5 +1,6 @@
 #include "CmGpuBuffer.h"
 #include "CmException.h"
+#include "CmRenderSystem.h"
 
 namespace CamelotEngine
 {
@@ -14,6 +15,18 @@ namespace CamelotEngine
 		// I can't call it here since it needs a virtual method call
 	}
 
+	void GpuBuffer::destroy()
+	{
+		RenderSystem::instancePtr()->queueCommand(boost::bind(&GpuBuffer::destroy_internal, this));
+	}
+
+	void GpuBuffer::destroy_internal()
+	{
+		clearBufferViews();
+
+		IDestroyable::destroy();
+	}
+
 	void GpuBuffer::clearBufferViews()
 	{
 		for(auto iter = mBufferViews.begin(); iter != mBufferViews.end(); ++iter)

+ 10 - 0
CamelotRenderer/Source/CmMultiRenderTexture.cpp

@@ -9,6 +9,16 @@ namespace CamelotEngine
 		mColorSurfaces.resize(CM_MAX_MULTIPLE_RENDER_TARGETS);
 	}
 
+	MultiRenderTexture::~MultiRenderTexture()
+	{
+
+	}
+
+	void MultiRenderTexture::destroy_internal()
+	{
+		RenderTarget::destroy_internal();
+	}
+
 	void MultiRenderTexture::setColorSurface(UINT32 surfaceIdx, TexturePtr texture, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
 	{
 		if(surfaceIdx < 0 || surfaceIdx >= CM_MAX_MULTIPLE_RENDER_TARGETS)

+ 10 - 9
CamelotRenderer/Source/CmRenderTarget.cpp

@@ -45,6 +45,16 @@ namespace CamelotEngine {
     {
     }
 
+	void RenderTarget::destroy()
+	{
+		RenderSystem::instancePtr()->queueCommand(boost::bind(&RenderTarget::destroy_internal, this));
+	}
+
+	void RenderTarget::destroy_internal()
+	{
+		IDestroyable::destroy();
+	}
+
     const String& RenderTarget::getName(void) const
     {
         return mName;
@@ -71,11 +81,6 @@ namespace CamelotEngine {
         return mColorDepth;
     }
 
-    void RenderTarget::updateImpl(void)
-    {
-		_beginUpdate();
-		_endUpdate();
-    }
 
 	void RenderTarget::_beginUpdate()
 	{
@@ -108,10 +113,6 @@ namespace CamelotEngine {
     //-----------------------------------------------------------------------
     void RenderTarget::update(bool swap)
     {
-        // call implementation
-        updateImpl();
-
-
 		if (swap)
 		{
 			// Swap buffers

+ 7 - 0
CamelotRenderer/Source/CmRenderTexture.cpp

@@ -41,12 +41,19 @@ namespace CamelotEngine
 	}
 
 	RenderTexture::~RenderTexture()
+	{
+
+	}
+
+	void RenderTexture::destroy_internal()
 	{
 		if(mColorSurface != nullptr)
 			Texture::releaseView(mColorSurface);
 
 		if(mDepthStencilSurface != nullptr)
 			Texture::releaseView(mDepthStencilSurface);
+
+		RenderTarget::destroy_internal();
 	}
 
 	void RenderTexture::createInternalResources()

+ 12 - 2
CamelotRenderer/Source/CmRenderWindow.cpp

@@ -29,8 +29,8 @@ THE SOFTWARE.
 #include "CmRenderWindowManager.h"
 #include "CmViewport.h"
 
-namespace CamelotEngine {
-
+namespace CamelotEngine 
+{
     RenderWindow::RenderWindow()
         : RenderTarget()
 		, mIsPrimary(false)
@@ -39,6 +39,16 @@ namespace CamelotEngine {
         mAutoDeactivatedOnFocusChange = true;
     }
 
+	RenderWindow::~RenderWindow() 
+	{
+
+	}
+
+	void RenderWindow::destroy_internal()
+	{
+		RenderTarget::destroy_internal();
+	}
+
     //-----------------------------------------------------------------------
     void RenderWindow::getMetrics(unsigned int& width, unsigned int& height, unsigned int& colourDepth,
 		int& left, int& top)

+ 7 - 3
CamelotRenderer/TODO.txt

@@ -38,11 +38,12 @@ Stuff that needs destroy():
  - Mesh - (DONE)
  - VertexBuffer (DONE)
  - IndexBuffer (DONE)
- - GpuBuffer
+ - GpuBuffer (DONE)
  - VertexDeclaration (DONE)
- - RenderWindow
+ - RenderWindow (DONE)
+ - RenderTexture (DONE)
+ - MultiRenderTexture (DONE)
  - Blend/DepthStencil/Rasterizer/SamplerState
- - GpuParamBlock
 ---
  Maybe
   - Material
@@ -54,6 +55,9 @@ I am currently completely ignoring D3D9ResourceManager. It is not notified when
 so it's mResources array contains many invalid pointers. Normally resource was removed from that list whenever it was 
 destructed but with my current approach, that might be AFTER the render system is shut down, which doesn't work. I need to 
 figure out a better way of releasing all resources when the application shuts down so that this doesn't happen.
+ - Also DynManager never gets shut down because I'd have to free all objects that use dynamic lib classes before shutting it down
+ - MAYBE, rename IDestroyable to GpuResource and just have every GPU resource derive from that.
+   - interface provides destroy(), and also keeps track of all created resources?
 
 Plan today & saturday:
  Add destroy() for remaining classes