فهرست منبع

Made some constructors private to make sure constructor methods are used

Marko Pintera 13 سال پیش
والد
کامیت
0e2e1461aa

+ 12 - 3
CamelotD3D9Renderer/Include/CmD3D9GpuProgram.h

@@ -39,7 +39,6 @@ namespace CamelotEngine {
     class CM_D3D9_EXPORT D3D9GpuProgram : public GpuProgram, public D3D9Resource
     class CM_D3D9_EXPORT D3D9GpuProgram : public GpuProgram, public D3D9Resource
     {   
     {   
     public:
     public:
-        D3D9GpuProgram();
         ~D3D9GpuProgram();
         ~D3D9GpuProgram();
 
 
 		virtual void initialize_internal(void);
 		virtual void initialize_internal(void);
@@ -64,6 +63,10 @@ namespace CamelotEngine {
         /** Gets the external microcode buffer, if any. */
         /** Gets the external microcode buffer, if any. */
         LPD3DXBUFFER getExternalMicrocode(void);
         LPD3DXBUFFER getExternalMicrocode(void);
     protected:
     protected:
+		friend class D3D9GpuProgramManager;
+
+		D3D9GpuProgram();
+
         /** Overridden from GpuProgram */
         /** Overridden from GpuProgram */
         void loadFromSource(void);
         void loadFromSource(void);
 		/** Loads this program from source to specified device */
 		/** Loads this program from source to specified device */
@@ -90,7 +93,6 @@ namespace CamelotEngine {
     class CM_D3D9_EXPORT D3D9GpuVertexProgram : public D3D9GpuProgram
     class CM_D3D9_EXPORT D3D9GpuVertexProgram : public D3D9GpuProgram
     {  
     {  
     public:
     public:
-        D3D9GpuVertexProgram();
 		~D3D9GpuVertexProgram();
 		~D3D9GpuVertexProgram();
         
         
 		void unload(void);
 		void unload(void);
@@ -105,6 +107,10 @@ namespace CamelotEngine {
 		virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
 		virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
 
 
     protected:
     protected:
+		friend class D3D9GpuProgramManager;
+
+		D3D9GpuVertexProgram();
+
         void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
         void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
 
 
 	protected:
 	protected:
@@ -118,7 +124,6 @@ namespace CamelotEngine {
     class CM_D3D9_EXPORT D3D9GpuFragmentProgram : public D3D9GpuProgram
     class CM_D3D9_EXPORT D3D9GpuFragmentProgram : public D3D9GpuProgram
     {  
     {  
     public:
     public:
-        D3D9GpuFragmentProgram();
 		~D3D9GpuFragmentProgram();
 		~D3D9GpuFragmentProgram();
 
 
 		void unload(void);
 		void unload(void);
@@ -133,6 +138,10 @@ namespace CamelotEngine {
 		virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
 		virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
 
 
     protected:
     protected:
+		friend class D3D9GpuProgramManager;
+
+		D3D9GpuFragmentProgram();
+
         void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
         void loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode);
 
 
 	protected:
 	protected:

+ 26 - 23
CamelotD3D9Renderer/Include/CmD3D9HLSLProgram.h

@@ -42,28 +42,6 @@ namespace CamelotEngine {
     */
     */
     class CM_D3D9_EXPORT D3D9HLSLProgram : public HighLevelGpuProgram
     class CM_D3D9_EXPORT D3D9HLSLProgram : public HighLevelGpuProgram
     {
     {
-    protected:
-        /** Internal load implementation, must be implemented by subclasses.
-        */
-        void loadFromSource(void);
-        /** Internal method for creating an appropriate low-level program from this
-        high-level program, must be implemented by subclasses. */
-        void createLowLevelImpl(void);
-        /// Internal unload implementation, must be implemented by subclasses
-        void unloadHighLevelImpl(void);
-        /// Populate the passed parameters with name->index map, must be overridden
-        void buildConstantDefinitions() const;
-
-        // Recursive utility method for buildParamNameMap
-        void processParamElement(D3DXHANDLE parent, String prefix, unsigned int index) const;
-		void populateDef(D3DXCONSTANT_DESC& d3dDesc, GpuConstantDefinition& def) const;
-
-        String mPreprocessorDefines;
-        bool mColumnMajorMatrices;
-
-        LPD3DXBUFFER mpMicroCode;
-        LPD3DXCONSTANTTABLE mpConstTable;
-
 	public:
 	public:
 		LPD3DXBUFFER getMicroCode();
 		LPD3DXBUFFER getMicroCode();
 	public:
 	public:
@@ -87,7 +65,6 @@ namespace CamelotEngine {
 		OptimisationLevel mOptimisationLevel;
 		OptimisationLevel mOptimisationLevel;
 
 
     public:
     public:
-        D3D9HLSLProgram();
         ~D3D9HLSLProgram();
         ~D3D9HLSLProgram();
 
 
         /** Sets the entry point for this program ie the first method called. */
         /** Sets the entry point for this program ie the first method called. */
@@ -121,6 +98,32 @@ namespace CamelotEngine {
         /// Overridden from GpuProgram
         /// Overridden from GpuProgram
         const String& getLanguage(void) const;
         const String& getLanguage(void) const;
 
 
+    protected:
+		friend class D3D9HLSLProgramFactory;
+
+		D3D9HLSLProgram();
+
+        /** Internal load implementation, must be implemented by subclasses.
+        */
+        void loadFromSource(void);
+        /** Internal method for creating an appropriate low-level program from this
+        high-level program, must be implemented by subclasses. */
+        void createLowLevelImpl(void);
+        /// Internal unload implementation, must be implemented by subclasses
+        void unloadHighLevelImpl(void);
+        /// Populate the passed parameters with name->index map, must be overridden
+        void buildConstantDefinitions() const;
+
+        // Recursive utility method for buildParamNameMap
+        void processParamElement(D3DXHANDLE parent, String prefix, unsigned int index) const;
+		void populateDef(D3DXCONSTANT_DESC& d3dDesc, GpuConstantDefinition& def) const;
+
+        String mPreprocessorDefines;
+        bool mColumnMajorMatrices;
+
+        LPD3DXBUFFER mpMicroCode;
+        LPD3DXCONSTANTTABLE mpConstTable;
+
 		/************************************************************************/
 		/************************************************************************/
 		/* 								SERIALIZATION                      		*/
 		/* 								SERIALIZATION                      		*/
 		/************************************************************************/
 		/************************************************************************/

+ 6 - 2
CamelotGLRenderer/Include/CmGLGpuProgram.h

@@ -39,7 +39,6 @@ namespace CamelotEngine {
     class CM_RSGL_EXPORT GLGpuProgram : public GpuProgram
     class CM_RSGL_EXPORT GLGpuProgram : public GpuProgram
     {
     {
     public:
     public:
-        GLGpuProgram();
         virtual ~GLGpuProgram();
         virtual ~GLGpuProgram();
 
 
         /// Execute the binding functions for this program
         /// Execute the binding functions for this program
@@ -68,6 +67,8 @@ namespace CamelotEngine {
 		static GLuint getFixedAttributeIndex(VertexElementSemantic semantic, UINT32 index);
 		static GLuint getFixedAttributeIndex(VertexElementSemantic semantic, UINT32 index);
 
 
     protected:
     protected:
+		GLGpuProgram();
+
 		/** Overridden from GpuProgram, do nothing */
 		/** Overridden from GpuProgram, do nothing */
 		void loadFromSource(void) {}
 		void loadFromSource(void) {}
         /// @copydoc Resource::unloadImpl
         /// @copydoc Resource::unloadImpl
@@ -81,7 +82,6 @@ namespace CamelotEngine {
     class CM_RSGL_EXPORT GLArbGpuProgram : public GLGpuProgram
     class CM_RSGL_EXPORT GLArbGpuProgram : public GLGpuProgram
     {
     {
     public:
     public:
-        GLArbGpuProgram();
         virtual ~GLArbGpuProgram();
         virtual ~GLArbGpuProgram();
 
 
         /// @copydoc GpuProgram::setType
         /// @copydoc GpuProgram::setType
@@ -100,6 +100,10 @@ namespace CamelotEngine {
         { return mProgramType; }
         { return mProgramType; }
 
 
     protected:
     protected:
+		friend GpuProgram* createGLArbGpuProgram(GpuProgramType gptype, const String& syntaxCode);
+
+		GLArbGpuProgram();
+
         void loadFromSource(void);
         void loadFromSource(void);
         /// @copydoc Resource::unloadImpl
         /// @copydoc Resource::unloadImpl
         void unloadImpl(void);
         void unloadImpl(void);

+ 2 - 3
CamelotGLRenderer/Source/CmGLGpuProgramManager.cpp

@@ -28,6 +28,7 @@ THE SOFTWARE.
 
 
 #include "CmGLGpuProgramManager.h"
 #include "CmGLGpuProgramManager.h"
 #include "CmGLGpuProgram.h"
 #include "CmGLGpuProgram.h"
+#include "CmException.h"
 
 
 using namespace CamelotEngine;
 using namespace CamelotEngine;
 
 
@@ -56,9 +57,7 @@ GpuProgram* GLGpuProgramManager::create(GpuProgramType gptype, const String& syn
     ProgramMap::const_iterator iter = mProgramMap.find(syntaxCode);
     ProgramMap::const_iterator iter = mProgramMap.find(syntaxCode);
     if(iter == mProgramMap.end())
     if(iter == mProgramMap.end())
     {
     {
-        // No factory, this is an unsupported syntax code, probably for another rendersystem
-        // Create a basic one, it doesn't matter what it is since it won't be used
-        return new GLGpuProgram();
+        CM_EXCEPT(InternalErrorException, "Cannot find propery factory to create GpuProgram of type: " + syntaxCode);
     }
     }
     
     
     return (iter->second)(gptype, syntaxCode);
     return (iter->second)(gptype, syntaxCode);

+ 3 - 6
CamelotGLRenderer/Source/GLSL/include/CmGLSLGpuProgram.h

@@ -59,9 +59,8 @@ namespace CamelotEngine {
 		static GLuint mGeometryShaderCount;
 		static GLuint mGeometryShaderCount;
 
 
 	public:
 	public:
-        GLSLGpuProgram(GLSLProgram* parent);
 		~GLSLGpuProgram();
 		~GLSLGpuProgram();
-
+		GLSLGpuProgram(GLSLProgram* parent);
 
 
 		/// Execute the binding functions for this program
 		/// Execute the binding functions for this program
 		void bindProgram(void);
 		void bindProgram(void);
@@ -85,17 +84,15 @@ namespace CamelotEngine {
 		
 		
 
 
     protected:
     protected:
+		friend class GLSLProgramFactory;
+
         /// Overridden from GpuProgram
         /// Overridden from GpuProgram
         void loadFromSource(void);
         void loadFromSource(void);
 		/// @copydoc Resource::unloadImpl
 		/// @copydoc Resource::unloadImpl
 		void unloadImpl(void);
 		void unloadImpl(void);
 		/// @copydoc Resource::loadImpl
 		/// @copydoc Resource::loadImpl
 		void initialize_internal(void);
 		void initialize_internal(void);
-
-
     };
     };
-
-
 }
 }
 
 
 
 

+ 4 - 1
CamelotGLRenderer/Source/atifs/include/ATI_FS_GLGpuProgram.h

@@ -38,7 +38,6 @@ namespace CamelotEngine {
 	class CM_RSGL_EXPORT ATI_FS_GLGpuProgram : public GLGpuProgram
 	class CM_RSGL_EXPORT ATI_FS_GLGpuProgram : public GLGpuProgram
 	{
 	{
 	public:
 	public:
-        ATI_FS_GLGpuProgram();
 		virtual ~ATI_FS_GLGpuProgram();
 		virtual ~ATI_FS_GLGpuProgram();
 
 
 
 
@@ -54,6 +53,10 @@ namespace CamelotEngine {
 		{ return mProgramID; }
 		{ return mProgramID; }
 
 
 	protected:
 	protected:
+		friend GpuProgram* createGL_ATI_FS_GpuProgram(GpuProgramType gptype, const String& syntaxCode);
+
+		ATI_FS_GLGpuProgram();
+
 		/// @copydoc Resource::unload
 		/// @copydoc Resource::unload
 		void unloadImpl(void);
 		void unloadImpl(void);
 		void loadFromSource(void);
 		void loadFromSource(void);

+ 28 - 25
CamelotRenderer/Include/CmCgProgram.h

@@ -44,11 +44,39 @@ namespace CamelotEngine {
     */
     */
     class CM_EXPORT CgProgram : public HighLevelGpuProgram
     class CM_EXPORT CgProgram : public HighLevelGpuProgram
     {
     {
+    public:
+        ~CgProgram();
+
+        /** Sets the entry point for this program ie the first method called. */
+        void setEntryPoint(const String& entryPoint) { mEntryPoint = entryPoint; }
+        /** Gets the entry point defined for this program. */
+        const String& getEntryPoint(void) const { return mEntryPoint; }
+        /** Sets the Cg profiles which can be supported by the program. */
+        void setProfiles(const vector<String>::type& profiles);
+        /** Gets the Cg profiles which can be supported by the program. */
+        const vector<String>::type& getProfiles(void) const { return mProfiles; }
+        /** Sets the compilation arguments for this program ie the first method called. */
+        void setCompileArguments(const String& args) { mCompileArgs = args; }
+        /** Gets the entry point defined for this program. */
+        const String& getCompileArguments(void) const { return mCompileArgs; }
+        /// Overridden from GpuProgram
+        bool isSupported(void) const;
+        /// Overridden from GpuProgram
+        const String& getLanguage(void) const;
+
+		/// scan the file for #include and replace with source from the OGRE resources
+		static String resolveCgIncludes(const String& source, Resource* resourceBeingLoaded, const String& fileName);
+
     protected:
     protected:
+		friend class CgProgramFactory;
+
         /// The CG context to use, passed in by factory
         /// The CG context to use, passed in by factory
         CGcontext mCgContext;
         CGcontext mCgContext;
         /// Program handle
         /// Program handle
         CGprogram mCgProgram;
         CGprogram mCgProgram;
+
+		CgProgram(CGcontext context);
+
         /** Internal load implementation, must be implemented by subclasses.
         /** Internal load implementation, must be implemented by subclasses.
         */
         */
         void loadFromSource(void);
         void loadFromSource(void);
@@ -80,31 +108,6 @@ namespace CamelotEngine {
         /// Releases memory for the horrible Cg char**
         /// Releases memory for the horrible Cg char**
         void freeCgArgs(void);
         void freeCgArgs(void);
 
 
-
-    public:
-        CgProgram(CGcontext context);
-        ~CgProgram();
-
-        /** Sets the entry point for this program ie the first method called. */
-        void setEntryPoint(const String& entryPoint) { mEntryPoint = entryPoint; }
-        /** Gets the entry point defined for this program. */
-        const String& getEntryPoint(void) const { return mEntryPoint; }
-        /** Sets the Cg profiles which can be supported by the program. */
-        void setProfiles(const vector<String>::type& profiles);
-        /** Gets the Cg profiles which can be supported by the program. */
-        const vector<String>::type& getProfiles(void) const { return mProfiles; }
-        /** Sets the compilation arguments for this program ie the first method called. */
-        void setCompileArguments(const String& args) { mCompileArgs = args; }
-        /** Gets the entry point defined for this program. */
-        const String& getCompileArguments(void) const { return mCompileArgs; }
-        /// Overridden from GpuProgram
-        bool isSupported(void) const;
-        /// Overridden from GpuProgram
-        const String& getLanguage(void) const;
-
-		/// scan the file for #include and replace with source from the OGRE resources
-		static String resolveCgIncludes(const String& source, Resource* resourceBeingLoaded, const String& fileName);
-
 		/************************************************************************/
 		/************************************************************************/
 		/* 								SERIALIZATION                      		*/
 		/* 								SERIALIZATION                      		*/
 		/************************************************************************/
 		/************************************************************************/

+ 2 - 18
CamelotRenderer/Include/CmGpuProgram.h

@@ -115,9 +115,6 @@ namespace CamelotEngine {
 		void throwIfNotRenderThread() const;
 		void throwIfNotRenderThread() const;
 
 
 	public:
 	public:
-
-		GpuProgram();
-
 		virtual ~GpuProgram();
 		virtual ~GpuProgram();
 
 
 		/**
 		/**
@@ -215,6 +212,8 @@ namespace CamelotEngine {
     protected:
     protected:
 		friend class GpuProgramManager;
 		friend class GpuProgramManager;
 
 
+		GpuProgram();
+
         /// Virtual method which must be implemented by subclasses, load from mSource
         /// Virtual method which must be implemented by subclasses, load from mSource
         virtual void loadFromSource(void) = 0;
         virtual void loadFromSource(void) = 0;
 
 
@@ -225,21 +224,6 @@ namespace CamelotEngine {
 		friend class GpuProgramRTTI;
 		friend class GpuProgramRTTI;
 		static RTTITypeBase* getRTTIStatic();
 		static RTTITypeBase* getRTTIStatic();
 		virtual RTTITypeBase* getRTTI() const;
 		virtual RTTITypeBase* getRTTI() const;
-
-	/************************************************************************/
-	/* 								STATICS		                     		*/
-	/************************************************************************/
-	private:
-		/**
-		 * @brief	Schedules destruction of the provided object. Actual destruction happens on the
-		 * 			render thread.
-		 */
-		static void destruct(GpuProgram* ptr);
-
-		/**
-		 * @brief	Destroys the provided object. Should only be called on the render thread.
-		 */
-		static void destruct_internal(GpuProgram* ptr);
 	};
 	};
 
 
 	/** @} */
 	/** @} */

+ 3 - 0
CamelotRenderer/Include/CmGpuProgramManager.h

@@ -53,6 +53,9 @@ namespace CamelotEngine {
         */
         */
         virtual GpuProgram* create(GpuProgramType gptype, const String& syntaxCode) = 0;
         virtual GpuProgram* create(GpuProgramType gptype, const String& syntaxCode) = 0;
 
 
+		void destroy(GpuProgram* program);
+		virtual void destroy_internal(GpuProgram* program);
+
 	public:
 	public:
 		GpuProgramManager();
 		GpuProgramManager();
 		virtual ~GpuProgramManager();
 		virtual ~GpuProgramManager();

+ 0 - 11
CamelotRenderer/Include/CmTexture.h

@@ -307,17 +307,6 @@ namespace CamelotEngine {
 		static TexturePtr create(TextureType texType, UINT32 width, UINT32 height, int num_mips,
 		static TexturePtr create(TextureType texType, UINT32 width, UINT32 height, int num_mips,
 			PixelFormat format, int usage = TU_DEFAULT,
 			PixelFormat format, int usage = TU_DEFAULT,
 			bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
 			bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
-
-	private:
-		/**
-		 * @brief	Schedules destruction of the provided object. Actual destruction happens on the render thread.
-		 */
-		static void destruct(Texture* ptr);
-
-		/**
-		 * @brief	Destroys the provided object. Should only be called on the render thread.
-		 */
-		static void destruct_internal(Texture* ptr);
     };
     };
 
 
 	/** @} */
 	/** @} */

+ 5 - 2
CamelotRenderer/Include/CmTextureManager.h

@@ -58,8 +58,11 @@ namespace CamelotEngine {
      */
      */
     class CM_EXPORT TextureManager : public Module<TextureManager>
     class CM_EXPORT TextureManager : public Module<TextureManager>
     {
     {
-		protected:
-			virtual Texture* createImpl() = 0;
+	protected:
+		virtual Texture* createImpl() = 0;
+
+		void destroy(Texture* texture);
+		virtual void destroy_internal(Texture* texture);
 
 
     public:
     public:
 
 

+ 0 - 13
CamelotRenderer/Source/CmGpuProgram.cpp

@@ -184,19 +184,6 @@ namespace CamelotEngine
 	{
 	{
 		return GpuProgram::getRTTIStatic();
 		return GpuProgram::getRTTIStatic();
 	}
 	}
-
-	/************************************************************************/
-	/* 								STATICS		                     		*/
-	/************************************************************************/
-	void GpuProgram::destruct(GpuProgram* ptr)
-	{
-		RenderSystemManager::getActive()->queueResourceCommand(boost::bind(&GpuProgram::destruct_internal, ptr));
-	}
-
-	void GpuProgram::destruct_internal(GpuProgram* ptr)
-	{
-		delete ptr;
-	}
 }
 }
 
 
 #undef THROW_IF_NOT_RENDER_THREAD 
 #undef THROW_IF_NOT_RENDER_THREAD 

+ 12 - 1
CamelotRenderer/Source/CmGpuProgramManager.cpp

@@ -42,6 +42,17 @@ namespace CamelotEngine {
 	{
 	{
 		// subclasses should unregister with resource group manager
 		// subclasses should unregister with resource group manager
 	}
 	}
+	//-------------------------------------------------------------------------
+	void GpuProgramManager::destroy(GpuProgram* program)
+	{
+		RenderSystemManager::getActive()->queueResourceCommand(boost::bind(&GpuProgramManager::destroy_internal, this, program));
+	}
+	//-------------------------------------------------------------------------
+	void GpuProgramManager::destroy_internal(GpuProgram* program)
+	{
+		if(program != nullptr)
+			delete program;
+	}
     //---------------------------------------------------------------------------
     //---------------------------------------------------------------------------
 	GpuProgramPtr GpuProgramManager::load(const String& code, 
 	GpuProgramPtr GpuProgramManager::load(const String& code, 
         GpuProgramType gptype, const String& syntaxCode)
         GpuProgramType gptype, const String& syntaxCode)
@@ -57,7 +68,7 @@ namespace CamelotEngine {
 	GpuProgramPtr GpuProgramManager::createProgram(const String& code, GpuProgramType gptype, 
 	GpuProgramPtr GpuProgramManager::createProgram(const String& code, GpuProgramType gptype, 
 		const String& syntaxCode)
 		const String& syntaxCode)
     {
     {
-		GpuProgramPtr prg = GpuProgramPtr(create(gptype, syntaxCode), &GpuProgram::destruct);
+		GpuProgramPtr prg = GpuProgramPtr(create(gptype, syntaxCode), boost::bind(&GpuProgramManager::destroy, this, _1));
         // Set all prarmeters (create does not set, just determines factory)
         // Set all prarmeters (create does not set, just determines factory)
 		prg->setType(gptype);
 		prg->setType(gptype);
 		prg->setSyntaxCode(syntaxCode);
 		prg->setSyntaxCode(syntaxCode);

+ 0 - 10
CamelotRenderer/Source/CmTexture.cpp

@@ -250,16 +250,6 @@ namespace CamelotEngine {
 		return TextureManager::instance().create(texType, 
 		return TextureManager::instance().create(texType, 
 			width, height, num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
 			width, height, num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
 	}
 	}
-
-	void Texture::destruct(Texture* ptr)
-	{
-		RenderSystemManager::getActive()->queueResourceCommand(boost::bind(&Texture::destruct_internal, ptr));
-	}
-
-	void Texture::destruct_internal(Texture* ptr)
-	{
-		delete ptr;
-	}
 }
 }
 
 
 #undef THROW_IF_NOT_RENDER_THREAD
 #undef THROW_IF_NOT_RENDER_THREAD

+ 14 - 2
CamelotRenderer/Source/CmTextureManager.cpp

@@ -28,6 +28,8 @@ THE SOFTWARE.
 #include "CmTextureManager.h"
 #include "CmTextureManager.h"
 #include "CmException.h"
 #include "CmException.h"
 #include "CmPixelUtil.h"
 #include "CmPixelUtil.h"
+#include "CmRenderSystemManager.h"
+#include "CmRenderSystem.h"
 
 
 namespace CamelotEngine {
 namespace CamelotEngine {
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
@@ -40,12 +42,22 @@ namespace CamelotEngine {
     {
     {
         // subclasses should unregister with resource group manager
         // subclasses should unregister with resource group manager
     }
     }
+	//-----------------------------------------------------------------------
+	void TextureManager::destroy(Texture* texture)
+	{
+		RenderSystemManager::getActive()->queueResourceCommand(boost::bind(&TextureManager::destroy_internal, this, texture));
+	}
+	//-----------------------------------------------------------------------
+	void TextureManager::destroy_internal(Texture* texture)
+	{
+		delete texture;
+	}
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     TexturePtr TextureManager::create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, int numMipmaps,
     TexturePtr TextureManager::create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, int numMipmaps,
         PixelFormat format, int usage, bool hwGamma, 
         PixelFormat format, int usage, bool hwGamma, 
 		UINT32 fsaa, const String& fsaaHint)
 		UINT32 fsaa, const String& fsaaHint)
     {
     {
-        TexturePtr ret = TexturePtr(createImpl(), &Texture::destruct);
+        TexturePtr ret = TexturePtr(createImpl(), boost::bind(&TextureManager::destroy, this, _1));
 		ret->initialize(texType, width, height, depth, static_cast<size_t>(numMipmaps), format, usage, hwGamma, fsaa, fsaaHint);
 		ret->initialize(texType, width, height, depth, static_cast<size_t>(numMipmaps), format, usage, hwGamma, fsaa, fsaaHint);
 
 
 		return ret;
 		return ret;
@@ -53,7 +65,7 @@ namespace CamelotEngine {
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------
 	TexturePtr TextureManager::createEmpty()
 	TexturePtr TextureManager::createEmpty()
 	{
 	{
-		TexturePtr ret = TexturePtr(createImpl(), &Texture::destruct);
+		TexturePtr ret = TexturePtr(createImpl(), boost::bind(&TextureManager::destroy, this, _1));
 
 
 		return ret;
 		return ret;
 	}
 	}