Browse Source

added destroy() for vertex/index/vertex declarations

Marko Pintera 13 years ago
parent
commit
25fcacb372

+ 2 - 2
CamelotClient/CamelotClient.cpp

@@ -185,8 +185,8 @@ int _tmain(int argc, _TCHAR* argv[])
 
 
 	testMaterial->setMat4("matViewProjection", Matrix4::IDENTITY);
 	testMaterial->setMat4("matViewProjection", Matrix4::IDENTITY);
 
 
-	//gResources().create(testMaterial, "C:\\testMaterial.mat", true);
-	//testMaterial = static_resource_cast<MaterialHandle>(gResources().load("C:\\testMaterial.mat"));
+	gResources().create(testMaterial, "C:\\testMaterial.mat", true);
+	testMaterial = static_resource_cast<MaterialHandle>(gResources().load("C:\\testMaterial.mat"));
 
 
 	/*TextureRef testTex = static_resource_cast<Texture>(Importer::instance().import("C:\\ImportTest.tga"));*/
 	/*TextureRef testTex = static_resource_cast<Texture>(Importer::instance().import("C:\\ImportTest.tga"));*/
 	TextureHandle testTex = static_resource_cast<Texture>(Importer::instance().import("C:\\ArenaTowerDFS.psd"));
 	TextureHandle testTex = static_resource_cast<Texture>(Importer::instance().import("C:\\ArenaTowerDFS.psd"));

+ 2 - 0
CamelotD3D11RenderSystem/Include/CmD3D11IndexBuffer.h

@@ -45,6 +45,8 @@ namespace CamelotEngine
 		 */
 		 */
 		void unlockImpl(void);
 		void unlockImpl(void);
 
 
+		void destroy_internal();
+
 		D3D11HardwareBuffer* mBuffer;
 		D3D11HardwareBuffer* mBuffer;
 	};
 	};
 }
 }

+ 2 - 0
CamelotD3D11RenderSystem/Include/CmD3D11VertexBuffer.h

@@ -45,6 +45,8 @@ namespace CamelotEngine
 		 */
 		 */
 		void unlockImpl(void);
 		void unlockImpl(void);
 
 
+		void destroy_internal();
+
 		D3D11HardwareBuffer* mBuffer;
 		D3D11HardwareBuffer* mBuffer;
 	};
 	};
 }
 }

+ 9 - 1
CamelotD3D11RenderSystem/Source/CmD3D11IndexBuffer.cpp

@@ -11,7 +11,7 @@ namespace CamelotEngine
 
 
 	D3D11IndexBuffer::~D3D11IndexBuffer()
 	D3D11IndexBuffer::~D3D11IndexBuffer()
 	{
 	{
-		delete mBuffer;
+		
 	}
 	}
 
 
 	void* D3D11IndexBuffer::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
 	void* D3D11IndexBuffer::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
@@ -39,4 +39,12 @@ namespace CamelotEngine
 	{
 	{
 		mBuffer->copyData(srcBuffer, srcOffset, dstOffset, length, discardWholeBuffer);
 		mBuffer->copyData(srcBuffer, srcOffset, dstOffset, length, discardWholeBuffer);
 	}
 	}
+
+	void D3D11IndexBuffer::destroy_internal()
+	{
+		if(mBuffer != nullptr)
+			delete mBuffer;
+
+		IndexBuffer::destroy_internal();
+	}
 }
 }

+ 9 - 1
CamelotD3D11RenderSystem/Source/CmD3D11VertexBuffer.cpp

@@ -11,7 +11,7 @@ namespace CamelotEngine
 
 
 	D3D11VertexBuffer::~D3D11VertexBuffer()
 	D3D11VertexBuffer::~D3D11VertexBuffer()
 	{
 	{
-		delete mBuffer;
+		
 	}
 	}
 
 
 	void* D3D11VertexBuffer::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
 	void* D3D11VertexBuffer::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
@@ -39,4 +39,12 @@ namespace CamelotEngine
 	{
 	{
 		mBuffer->copyData(srcBuffer, srcOffset, dstOffset, length, discardWholeBuffer);
 		mBuffer->copyData(srcBuffer, srcOffset, dstOffset, length, discardWholeBuffer);
 	}
 	}
+
+	void D3D11VertexBuffer::destroy_internal()
+	{
+		if(mBuffer != nullptr)
+			delete mBuffer;
+
+		VertexBuffer::destroy_internal();
+	}
 }
 }

+ 2 - 0
CamelotD3D9Renderer/Include/CmD3D9IndexBuffer.h

@@ -85,6 +85,8 @@ namespace CamelotEngine {
 		// updates buffer resources from system memory buffer.
 		// updates buffer resources from system memory buffer.
 		bool updateBufferResources(const char* systemMemoryBuffer, BufferResources* bufferResources);
 		bool updateBufferResources(const char* systemMemoryBuffer, BufferResources* bufferResources);
 
 
+		void destroy_internal();
+
 	protected:		
 	protected:		
 		typedef map<IDirect3DDevice9*, BufferResources*>::type	DeviceToBufferResourcesMap;
 		typedef map<IDirect3DDevice9*, BufferResources*>::type	DeviceToBufferResourcesMap;
 		typedef DeviceToBufferResourcesMap::iterator			DeviceToBufferResourcesIterator;
 		typedef DeviceToBufferResourcesMap::iterator			DeviceToBufferResourcesIterator;

+ 3 - 3
CamelotD3D9Renderer/Include/CmD3D9VertexBuffer.h

@@ -76,8 +76,7 @@ namespace CamelotEngine {
 			GpuLockOptions					mLockOptions;
 			GpuLockOptions					mLockOptions;
 			UINT32						mLastUsedFrame;
 			UINT32						mLastUsedFrame;
 		};
 		};
-
-	protected:		
+	
 		/** See HardwareBuffer. */
 		/** See HardwareBuffer. */
 		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);		
 		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);		
 		/** See HardwareBuffer. */
 		/** See HardwareBuffer. */
@@ -85,7 +84,8 @@ namespace CamelotEngine {
 		// updates buffer resources from system memory buffer.
 		// updates buffer resources from system memory buffer.
 		bool updateBufferResources(const char* systemMemoryBuffer, BufferResources* bufferResources);		
 		bool updateBufferResources(const char* systemMemoryBuffer, BufferResources* bufferResources);		
 
 
-	protected:
+		void destroy_internal();
+
 		typedef map<IDirect3DDevice9*, BufferResources*>::type	DeviceToBufferResourcesMap;
 		typedef map<IDirect3DDevice9*, BufferResources*>::type	DeviceToBufferResourcesMap;
 		typedef DeviceToBufferResourcesMap::iterator			DeviceToBufferResourcesIterator;
 		typedef DeviceToBufferResourcesMap::iterator			DeviceToBufferResourcesIterator;
 
 

+ 2 - 2
CamelotD3D9Renderer/Include/CmD3D9VertexDeclaration.h

@@ -75,8 +75,8 @@ namespace CamelotEngine {
         IDirect3DVertexDeclaration9* getD3DVertexDeclaration(void);
         IDirect3DVertexDeclaration9* getD3DVertexDeclaration(void);
 
 
 	protected:
 	protected:
-		void	releaseDeclaration();
-
+		void releaseDeclaration();
+		void destroy_internal();
 
 
 	protected:        
 	protected:        
 		typedef map<IDirect3DDevice9*, IDirect3DVertexDeclaration9*>::type	DeviceToDeclarationMap;
 		typedef map<IDirect3DDevice9*, IDirect3DVertexDeclaration9*>::type	DeviceToDeclarationMap;

+ 19 - 14
CamelotD3D9Renderer/Source/CmD3D9IndexBuffer.cpp

@@ -71,20 +71,7 @@ namespace CamelotEngine {
     }
     }
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
     D3D9IndexBuffer::~D3D9IndexBuffer()
     D3D9IndexBuffer::~D3D9IndexBuffer()
-    {
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.begin();
-
-		while (it != mMapDeviceToBufferResources.end())
-		{
-			SAFE_RELEASE(it->second->mBuffer);
-			SAFE_DELETE(it->second);
-			++it;
-		}	
-		mMapDeviceToBufferResources.clear();   
-		SAFE_DELETE_ARRAY(mSystemMemoryBuffer);
-    }
+    { }
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
     void* D3D9IndexBuffer::lockImpl(UINT32 offset, 
     void* D3D9IndexBuffer::lockImpl(UINT32 offset, 
         UINT32 length, GpuLockOptions options)
         UINT32 length, GpuLockOptions options)
@@ -338,4 +325,22 @@ namespace CamelotEngine {
 
 
 		return true;			
 		return true;			
 	}
 	}
+	//---------------------------------------------------------------------
+	void D3D9IndexBuffer::destroy_internal()
+	{
+		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
+
+			DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.begin();
+
+		while (it != mMapDeviceToBufferResources.end())
+		{
+			SAFE_RELEASE(it->second->mBuffer);
+			SAFE_DELETE(it->second);
+			++it;
+		}	
+		mMapDeviceToBufferResources.clear();   
+		SAFE_DELETE_ARRAY(mSystemMemoryBuffer);
+
+		IndexBuffer::destroy_internal();
+	}
 }
 }

+ 19 - 14
CamelotD3D9Renderer/Source/CmD3D9VertexBuffer.cpp

@@ -71,20 +71,7 @@ namespace CamelotEngine {
     }
     }
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
     D3D9VertexBuffer::~D3D9VertexBuffer()
     D3D9VertexBuffer::~D3D9VertexBuffer()
-    {	
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.begin();
-
-		while (it != mMapDeviceToBufferResources.end())
-		{
-			SAFE_RELEASE(it->second->mBuffer);
-			SAFE_DELETE(it->second);
-			++it;
-		}	
-		mMapDeviceToBufferResources.clear();   
-		SAFE_DELETE_ARRAY(mSystemMemoryBuffer);
-    }
+    {	    }
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
     void* D3D9VertexBuffer::lockImpl(UINT32 offset, 
     void* D3D9VertexBuffer::lockImpl(UINT32 offset, 
         UINT32 length, GpuLockOptions options)
         UINT32 length, GpuLockOptions options)
@@ -337,4 +324,22 @@ namespace CamelotEngine {
 
 
 		return true;		
 		return true;		
 	}
 	}
+	//---------------------------------------------------------------------
+	void D3D9VertexBuffer::destroy_internal()
+	{
+		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
+
+			DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.begin();
+
+		while (it != mMapDeviceToBufferResources.end())
+		{
+			SAFE_RELEASE(it->second->mBuffer);
+			SAFE_DELETE(it->second);
+			++it;
+		}	
+		mMapDeviceToBufferResources.clear();   
+		SAFE_DELETE_ARRAY(mSystemMemoryBuffer);
+
+		VertexBuffer::destroy_internal();
+	}
 }
 }

+ 8 - 3
CamelotD3D9Renderer/Source/CmD3D9VertexDeclaration.cpp

@@ -39,9 +39,7 @@ namespace CamelotEngine {
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     D3D9VertexDeclaration::~D3D9VertexDeclaration()
     D3D9VertexDeclaration::~D3D9VertexDeclaration()
-    {
-       releaseDeclaration();
-    }
+    {    }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     const VertexElement& D3D9VertexDeclaration::addElement(unsigned short source, 
     const VertexElement& D3D9VertexDeclaration::addElement(unsigned short source, 
         UINT32 offset, VertexElementType theType,
         UINT32 offset, VertexElementType theType,
@@ -185,5 +183,12 @@ namespace CamelotEngine {
 		}	
 		}	
 		mMapDeviceToDeclaration.clear();
 		mMapDeviceToDeclaration.clear();
 	}
 	}
+	//-----------------------------------------------------------------------
+	void D3D9VertexDeclaration::destroy_internal()
+	{
+		releaseDeclaration();
+
+		VertexDeclaration::destroy_internal();
+	}
 }
 }
 
 

+ 17 - 13
CamelotGLRenderer/Include/CmGLIndexBuffer.h

@@ -36,19 +36,6 @@ namespace CamelotEngine {
 
 
     class CM_RSGL_EXPORT GLIndexBuffer : public IndexBuffer
     class CM_RSGL_EXPORT GLIndexBuffer : public IndexBuffer
     {
     {
-    private:
-        GLuint mBufferId;
-		// Scratch buffer handling
-		bool mLockedToScratch;
-		UINT32 mScratchOffset;
-		UINT32 mScratchSize;
-		void* mScratchPtr;
-		bool mScratchUploadOnUnlock;
-    protected:
-        /** See HardwareBuffer. */
-        void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
-        /** See HardwareBuffer. */
-        void unlockImpl(void);
     public:
     public:
         GLIndexBuffer(HardwareBufferManager* mgr, IndexType idxType, UINT32 numIndexes, 
         GLIndexBuffer(HardwareBufferManager* mgr, IndexType idxType, UINT32 numIndexes, 
             GpuBufferUsage usage); 
             GpuBufferUsage usage); 
@@ -60,6 +47,23 @@ namespace CamelotEngine {
             const void* pSource, bool discardWholeBuffer = false);
             const void* pSource, bool discardWholeBuffer = false);
 
 
         GLuint getGLBufferId(void) const { return mBufferId; }
         GLuint getGLBufferId(void) const { return mBufferId; }
+
+	protected:
+		/** See HardwareBuffer. */
+		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
+		/** See HardwareBuffer. */
+		void unlockImpl(void);
+
+		void destroy_internal();
+
+	private:
+		GLuint mBufferId;
+		// Scratch buffer handling
+		bool mLockedToScratch;
+		UINT32 mScratchOffset;
+		UINT32 mScratchSize;
+		void* mScratchPtr;
+		bool mScratchUploadOnUnlock;
     };
     };
 
 
 }
 }

+ 17 - 14
CamelotGLRenderer/Include/CmGLVertexBuffer.h

@@ -36,20 +36,6 @@ namespace CamelotEngine {
     /// Specialisation of HardwareVertexBuffer for OpenGL
     /// Specialisation of HardwareVertexBuffer for OpenGL
     class CM_RSGL_EXPORT GLVertexBuffer : public VertexBuffer 
     class CM_RSGL_EXPORT GLVertexBuffer : public VertexBuffer 
     {
     {
-    private:
-        GLuint mBufferId;
-		// Scratch buffer handling
-		bool mLockedToScratch;
-		UINT32 mScratchOffset;
-		UINT32 mScratchSize;
-		void* mScratchPtr;
-		bool mScratchUploadOnUnlock;
-
-    protected:
-        /** See HardwareBuffer. */
-        void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
-        /** See HardwareBuffer. */
-        void unlockImpl(void);
     public:
     public:
         GLVertexBuffer(HardwareBufferManager* mgr, UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage); 
         GLVertexBuffer(HardwareBufferManager* mgr, UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage); 
         ~GLVertexBuffer();
         ~GLVertexBuffer();
@@ -60,6 +46,23 @@ namespace CamelotEngine {
             const void* pSource, bool discardWholeBuffer = false);
             const void* pSource, bool discardWholeBuffer = false);
 
 
         GLuint getGLBufferId(void) const { return mBufferId; }
         GLuint getGLBufferId(void) const { return mBufferId; }
+
+	protected:
+		/** See HardwareBuffer. */
+		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
+		/** See HardwareBuffer. */
+		void unlockImpl(void);
+
+		void destroy_internal();
+
+	private:
+		GLuint mBufferId;
+		// Scratch buffer handling
+		bool mLockedToScratch;
+		UINT32 mScratchOffset;
+		UINT32 mScratchSize;
+		void* mScratchPtr;
+		bool mScratchUploadOnUnlock;
     };
     };
 
 
 }
 }

+ 8 - 3
CamelotGLRenderer/Source/CmGLIndexBuffer.cpp

@@ -54,9 +54,7 @@ namespace CamelotEngine {
     }
     }
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
     GLIndexBuffer::~GLIndexBuffer()
     GLIndexBuffer::~GLIndexBuffer()
-    {
-        glDeleteBuffersARB(1, &mBufferId);
-    }
+    {    }
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
     void* GLIndexBuffer::lockImpl(UINT32 offset, 
     void* GLIndexBuffer::lockImpl(UINT32 offset, 
         UINT32 length, GpuLockOptions options)
         UINT32 length, GpuLockOptions options)
@@ -191,4 +189,11 @@ namespace CamelotEngine {
             glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length, pSource);
             glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length, pSource);
         }
         }
     }
     }
+	//---------------------------------------------------------------------
+	void GLIndexBuffer::destroy_internal()
+	{
+		 glDeleteBuffersARB(1, &mBufferId);
+
+		IndexBuffer::destroy_internal();
+	}
 }
 }

+ 7 - 1
CamelotGLRenderer/Source/CmGLVertexBuffer.cpp

@@ -55,7 +55,6 @@ namespace CamelotEngine {
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
     GLVertexBuffer::~GLVertexBuffer()
     GLVertexBuffer::~GLVertexBuffer()
     {
     {
-        glDeleteBuffersARB(1, &mBufferId);
     }
     }
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
     void* GLVertexBuffer::lockImpl(UINT32 offset, 
     void* GLVertexBuffer::lockImpl(UINT32 offset, 
@@ -194,4 +193,11 @@ namespace CamelotEngine {
             glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, offset, length, pSource); 
             glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, offset, length, pSource); 
         }
         }
     }
     }
+	//---------------------------------------------------------------------
+	void GLVertexBuffer::destroy_internal()
+	{
+		glDeleteBuffersARB(1, &mBufferId);
+
+		VertexBuffer::destroy_internal();
+	}
 }
 }

+ 6 - 1
CamelotRenderer/Include/CmIndexBuffer.h

@@ -31,6 +31,7 @@ THE SOFTWARE.
 // Precompiler options
 // Precompiler options
 #include "CmPrerequisites.h"
 #include "CmPrerequisites.h"
 #include "CmHardwareBuffer.h"
 #include "CmHardwareBuffer.h"
+#include "CmIDestroyable.h"
 
 
 namespace CamelotEngine 
 namespace CamelotEngine 
 {
 {
@@ -41,7 +42,7 @@ namespace CamelotEngine
 	*  @{
 	*  @{
 	*/
 	*/
 	/** Specialisation of HardwareBuffer for vertex index buffers, still abstract. */
 	/** Specialisation of HardwareBuffer for vertex index buffers, still abstract. */
-    class CM_EXPORT IndexBuffer : public HardwareBuffer
+    class CM_EXPORT IndexBuffer : public HardwareBuffer, public IDestroyable
     {
     {
 	    public:
 	    public:
 		    enum IndexType {
 		    enum IndexType {
@@ -55,6 +56,8 @@ namespace CamelotEngine
 		    UINT32 mNumIndexes;
 		    UINT32 mNumIndexes;
             UINT32 mIndexSize;
             UINT32 mIndexSize;
 
 
+			virtual void destroy_internal();
+
 	    public:
 	    public:
 		    /// Should be called by HardwareBufferManager
 		    /// Should be called by HardwareBufferManager
 		    IndexBuffer(HardwareBufferManager* mgr, IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage,
 		    IndexBuffer(HardwareBufferManager* mgr, IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage,
@@ -69,6 +72,8 @@ namespace CamelotEngine
             /// Get the size in bytes of each index
             /// Get the size in bytes of each index
             UINT32 getIndexSize(void) const { return mIndexSize; }
             UINT32 getIndexSize(void) const { return mIndexSize; }
 
 
+			void destroy();
+
 		    // NB subclasses should override lock, unlock, readData, writeData
 		    // NB subclasses should override lock, unlock, readData, writeData
     };
     };
 	/** @} */
 	/** @} */

+ 5 - 2
CamelotRenderer/Include/CmMesh.h

@@ -29,7 +29,6 @@ namespace CamelotEngine
 		virtual ~Mesh();
 		virtual ~Mesh();
 
 
 		void initialize();
 		void initialize();
-		virtual void initialize_internal();
 
 
 		/**
 		/**
 		 * @brief	Mesh data that is used for initializing the mesh. Needs to be set before calling load.
 		 * @brief	Mesh data that is used for initializing the mesh. Needs to be set before calling load.
@@ -45,7 +44,7 @@ namespace CamelotEngine
 
 
 		RenderOperation getRenderOperation(UINT32 subMeshIdx = 0) const;
 		RenderOperation getRenderOperation(UINT32 subMeshIdx = 0) const;
 
 
-	private:
+	protected:
 		Mesh();
 		Mesh();
 
 
 		VertexData* mVertexData;
 		VertexData* mVertexData;
@@ -53,8 +52,12 @@ namespace CamelotEngine
 
 
 		vector<SubMesh>::type mSubMeshes;
 		vector<SubMesh>::type mSubMeshes;
 
 
+		virtual void initialize_internal();
 		void throwIfNotRenderThread() const;
 		void throwIfNotRenderThread() const;
 
 
+		/** @copydoc Resource::destroy_internal(). */
+		virtual void destroy_internal();
+
 		/************************************************************************/
 		/************************************************************************/
 		/* 								SERIALIZATION                      		*/
 		/* 								SERIALIZATION                      		*/
 		/************************************************************************/
 		/************************************************************************/

+ 21 - 17
CamelotRenderer/Include/CmVertexBuffer.h

@@ -31,7 +31,7 @@ THE SOFTWARE.
 // Precompiler options
 // Precompiler options
 #include "CmPrerequisites.h"
 #include "CmPrerequisites.h"
 #include "CmHardwareBuffer.h"
 #include "CmHardwareBuffer.h"
-#include "CmIReflectable.h"
+#include "CmIDestroyable.h"
 #include "CmColor.h"
 #include "CmColor.h"
 
 
 namespace CamelotEngine 
 namespace CamelotEngine 
@@ -43,24 +43,28 @@ namespace CamelotEngine
 	*  @{
 	*  @{
 	*/
 	*/
 	/** Specialisation of HardwareBuffer for a vertex buffer. */
 	/** Specialisation of HardwareBuffer for a vertex buffer. */
-    class CM_EXPORT VertexBuffer : public HardwareBuffer
+    class CM_EXPORT VertexBuffer : public HardwareBuffer, public IDestroyable
     {
     {
-	    protected:
-			HardwareBufferManager* mMgr;
-		    UINT32 mNumVertices;
-            UINT32 mVertexSize;
+	public:
+		/// Should be called by HardwareBufferManager
+		VertexBuffer(HardwareBufferManager* mgr, UINT32 vertexSize, UINT32 numVertices,
+            GpuBufferUsage usage, bool useSystemMemory);
+        ~VertexBuffer();
 
 
-	    public:
-		    /// Should be called by HardwareBufferManager
-		    VertexBuffer(HardwareBufferManager* mgr, UINT32 vertexSize, UINT32 numVertices,
-                GpuBufferUsage usage, bool useSystemMemory);
-            ~VertexBuffer();
-			/// Return the manager of this buffer, if any
-			HardwareBufferManager* getManager() const { return mMgr; }
-            /// Gets the size in bytes of a single vertex in this buffer
-            UINT32 getVertexSize(void) const { return mVertexSize; }
-            /// Get the number of vertices in this buffer
-            UINT32 getNumVertices(void) const { return mNumVertices; }
+		void destroy();
+
+		/// Return the manager of this buffer, if any
+		HardwareBufferManager* getManager() const { return mMgr; }
+        /// Gets the size in bytes of a single vertex in this buffer
+        UINT32 getVertexSize(void) const { return mVertexSize; }
+        /// Get the number of vertices in this buffer
+        UINT32 getNumVertices(void) const { return mNumVertices; }
+	protected:
+		HardwareBufferManager* mMgr;
+		UINT32 mNumVertices;
+		UINT32 mVertexSize;
+
+		virtual void destroy_internal();
     };
     };
 }
 }
 #endif
 #endif

+ 1 - 0
CamelotRenderer/Include/CmVertexData.h

@@ -100,6 +100,7 @@ namespace CamelotEngine {
         VertexData& operator=(const VertexData& rhs); /* do not use */
         VertexData& operator=(const VertexData& rhs); /* do not use */
 
 
 		HardwareBufferManager* mMgr;
 		HardwareBufferManager* mMgr;
+		bool mOwnsDeclaration;
 
 
 		/** The vertex buffer bindings to be used. 
 		/** The vertex buffer bindings to be used. 
 		@remarks Note that this is created for you on construction.
 		@remarks Note that this is created for you on construction.

+ 6 - 1
CamelotRenderer/Include/CmVertexDeclaration.h

@@ -2,6 +2,7 @@
 
 
 #include "CmPrerequisites.h"
 #include "CmPrerequisites.h"
 #include "CmColor.h"
 #include "CmColor.h"
+#include "CmIDestroyable.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
@@ -241,7 +242,7 @@ namespace CamelotEngine
 	Like the other classes in this functional area, these declarations should be created and
 	Like the other classes in this functional area, these declarations should be created and
 	destroyed using the HardwareBufferManager.
 	destroyed using the HardwareBufferManager.
     */
     */
-	class CM_EXPORT VertexDeclaration : public IReflectable
+	class CM_EXPORT VertexDeclaration : public IReflectable, public IDestroyable
     {
     {
     public:
     public:
 		/// Defines the list of vertex elements that makes up this declaration
 		/// Defines the list of vertex elements that makes up this declaration
@@ -256,6 +257,8 @@ namespace CamelotEngine
 		 * @brief	Generates a hash value based on all elements in the declaration.
 		 * @brief	Generates a hash value based on all elements in the declaration.
 		 */
 		 */
 		void recalculateHash();
 		void recalculateHash();
+
+		virtual void destroy_internal();
     public:
     public:
         /// Standard constructor, not you should use HardwareBufferManager::createVertexDeclaration
         /// Standard constructor, not you should use HardwareBufferManager::createVertexDeclaration
         VertexDeclaration();
         VertexDeclaration();
@@ -380,6 +383,8 @@ namespace CamelotEngine
 		*/
 		*/
         virtual VertexDeclarationPtr clone(HardwareBufferManager* mgr = 0);
         virtual VertexDeclarationPtr clone(HardwareBufferManager* mgr = 0);
 
 
+		void destroy();
+
         inline bool operator== (const VertexDeclaration& rhs) const
         inline bool operator== (const VertexDeclaration& rhs) const
         {
         {
             if (mElementList.size() != rhs.mElementList.size())
             if (mElementList.size() != rhs.mElementList.size())

+ 14 - 3
CamelotRenderer/Source/CmIndexBuffer.cpp

@@ -28,6 +28,7 @@ THE SOFTWARE.
 
 
 #include "CmIndexBuffer.h"
 #include "CmIndexBuffer.h"
 #include "CmHardwareBufferManager.h"
 #include "CmHardwareBufferManager.h"
+#include "CmRenderSystem.h"
 
 
 namespace CamelotEngine {
 namespace CamelotEngine {
 
 
@@ -55,10 +56,20 @@ namespace CamelotEngine {
     //-----------------------------------------------------------------------------
     //-----------------------------------------------------------------------------
     IndexBuffer::~IndexBuffer()
     IndexBuffer::~IndexBuffer()
     {
     {
+
+    }
+	//----------------------------------------------------------------------------
+	void IndexBuffer::destroy()
+	{
+		RenderSystem::instancePtr()->queueCommand(boost::bind(&IndexBuffer::destroy_internal, this));
+	}
+	//----------------------------------------------------------------------------
+	void IndexBuffer::destroy_internal()
+	{
 		if (mMgr)
 		if (mMgr)
-		{
 			mMgr->_notifyIndexBufferDestroyed(this);
 			mMgr->_notifyIndexBufferDestroyed(this);
-		}
-    }
+
+		IDestroyable::destroy();
+	}
 }
 }
 
 

+ 14 - 9
CamelotRenderer/Source/CmMesh.cpp

@@ -23,15 +23,7 @@ namespace CamelotEngine
 	}
 	}
 
 
 	Mesh::~Mesh()
 	Mesh::~Mesh()
-	{
-		THROW_IF_NOT_RENDER_THREAD;
-
-		if(mVertexData)
-			delete mVertexData;
-
-		if(mIndexData)
-			delete mIndexData;
-	}
+	{ }
 
 
 	void Mesh::setMeshData(MeshDataPtr meshData)
 	void Mesh::setMeshData(MeshDataPtr meshData)
 	{
 	{
@@ -317,6 +309,19 @@ namespace CamelotEngine
 		Resource::initialize_internal();
 		Resource::initialize_internal();
 	}
 	}
 
 
+	void Mesh::destroy_internal()
+	{
+		THROW_IF_NOT_RENDER_THREAD;
+
+		if(mVertexData)
+			delete mVertexData;
+
+		if(mIndexData)
+			delete mIndexData;
+
+		IDestroyable::destroy();
+	}
+
 	void Mesh::throwIfNotRenderThread() const
 	void Mesh::throwIfNotRenderThread() const
 	{
 	{
 		if(CM_THREAD_CURRENT_ID != RenderSystem::instancePtr()->getRenderThreadId())
 		if(CM_THREAD_CURRENT_ID != RenderSystem::instancePtr()->getRenderThreadId())

+ 1 - 1
CamelotRenderer/Source/CmResource.cpp

@@ -28,7 +28,7 @@ namespace CamelotEngine
 
 
 	void Resource::destroy()
 	void Resource::destroy()
 	{
 	{
-		RenderSystem::instancePtr()->queueCommand(boost::bind(&Texture::destroy_internal, this));
+		RenderSystem::instancePtr()->queueCommand(boost::bind(&Resource::destroy_internal, this));
 	}
 	}
 
 
 	void Resource::waitUntilInitialized()
 	void Resource::waitUntilInitialized()

+ 13 - 3
CamelotRenderer/Source/CmVertexBuffer.cpp

@@ -48,9 +48,19 @@ namespace CamelotEngine
 
 
     VertexBuffer::~VertexBuffer()
     VertexBuffer::~VertexBuffer()
     {
     {
+
+    }
+
+	void VertexBuffer::destroy()
+	{
+		RenderSystem::instancePtr()->queueCommand(boost::bind(&VertexBuffer::destroy_internal, this));
+	}
+
+	void VertexBuffer::destroy_internal()
+	{
 		if (mMgr)
 		if (mMgr)
-		{
 			mMgr->_notifyVertexBufferDestroyed(this);
 			mMgr->_notifyVertexBufferDestroyed(this);
-		}
-    }
+
+		IDestroyable::destroy();
+	}
 }
 }

+ 4 - 1
CamelotRenderer/Source/CmVertexData.cpp

@@ -37,6 +37,7 @@ THE SOFTWARE.
 namespace CamelotEngine 
 namespace CamelotEngine 
 {
 {
 	VertexData::VertexData(HardwareBufferManager* mgr)
 	VertexData::VertexData(HardwareBufferManager* mgr)
+		:mOwnsDeclaration(false)
 	{
 	{
 		mMgr = mgr ? mgr : HardwareBufferManager::instancePtr();
 		mMgr = mgr ? mgr : HardwareBufferManager::instancePtr();
 		vertexDeclaration = mMgr->createVertexDeclaration();
 		vertexDeclaration = mMgr->createVertexDeclaration();
@@ -45,6 +46,7 @@ namespace CamelotEngine
 	}
 	}
 
 
 	VertexData::VertexData(VertexDeclarationPtr dcl)
 	VertexData::VertexData(VertexDeclarationPtr dcl)
+		:mOwnsDeclaration(true)
 	{
 	{
 		// this is a fallback rather than actively used
 		// this is a fallback rather than actively used
 		mMgr = HardwareBufferManager::instancePtr();
 		mMgr = HardwareBufferManager::instancePtr();
@@ -54,7 +56,8 @@ namespace CamelotEngine
 
 
 	VertexData::~VertexData()
 	VertexData::~VertexData()
 	{
 	{
-
+		if(mOwnsDeclaration && (vertexDeclaration != nullptr))
+			vertexDeclaration->destroy();
 	}
 	}
 
 
 	void VertexData::setBuffer(UINT32 index, VertexBufferPtr buffer)
 	void VertexData::setBuffer(UINT32 index, VertexBufferPtr buffer)

+ 11 - 0
CamelotRenderer/Source/CmVertexDeclaration.cpp

@@ -461,6 +461,17 @@ namespace CamelotEngine
 		}
 		}
 		return ret;
 		return ret;
 	}
 	}
+
+	void VertexDeclaration::destroy()
+	{
+		RenderSystem::instancePtr()->queueCommand(boost::bind(&VertexDeclaration::destroy_internal, this));
+	}
+
+	void VertexDeclaration::destroy_internal()
+	{
+		IDestroyable::destroy();
+	}
+
 	//----------------------------------------------------------------------------
 	//----------------------------------------------------------------------------
 	void VertexDeclaration::recalculateHash()
 	void VertexDeclaration::recalculateHash()
 	{
 	{

+ 6 - 7
CamelotRenderer/TODO.txt

@@ -35,11 +35,11 @@ Stuff that needs destroy():
  - GpuProgram (DONE)
  - GpuProgram (DONE)
  - HighLevelGpuProgram (DONE)
  - HighLevelGpuProgram (DONE)
  - Texture (DONE)
  - Texture (DONE)
- - Mesh
- - VertexBuffer
- - IndexBuffer
+ - Mesh - (DONE)
+ - VertexBuffer (DONE)
+ - IndexBuffer (DONE)
  - GpuBuffer
  - GpuBuffer
- - VertexDeclaration
+ - VertexDeclaration (DONE)
  - RenderWindow
  - RenderWindow
  - Blend/DepthStencil/Rasterizer/SamplerState
  - Blend/DepthStencil/Rasterizer/SamplerState
  - GpuParamBlock
  - GpuParamBlock
@@ -54,9 +54,8 @@ Calling destroy() and then immediately releasing last reference to an object wil
 
 
 Upon calling destroy() I should keep a temporary reference to the object until it actually is destroyed.
 Upon calling destroy() I should keep a temporary reference to the object until it actually is destroyed.
 
 
-  Material RTTI should also serialize shared buffers (they need to be made into a resource)
-
-DX9 will have the same name for sampler and texture. This will cause an error in Material param checking.
+Material RTTI should also serialize shared buffers (they need to be made into a resource)
+ - BE CAREFUL on how this will be implemented. Likely it will have much of the same interface as a material and/or GpuParams
 
 
 Add support for include file resource
 Add support for include file resource
 Make sure we can add an include file to a HighLevelGpuProgram, and make sure it uses it
 Make sure we can add an include file to a HighLevelGpuProgram, and make sure it uses it