Просмотр исходного кода

Resources call destroy() automatically when reference count reaches 0

Marko Pintera 13 лет назад
Родитель
Сommit
05e0af19b4
58 измененных файлов с 325 добавлено и 578 удалено
  1. 49 50
      CamelotClient/CamelotClient.cpp
  2. 4 4
      CamelotD3D11RenderSystem/Include/CmD3D11HardwareBufferManager.h
  3. 5 40
      CamelotD3D11RenderSystem/Include/CmD3D11RenderStateManager.h
  4. 1 1
      CamelotD3D11RenderSystem/Include/CmD3D11RenderSystem.h
  5. 1 1
      CamelotD3D11RenderSystem/Include/CmD3D11RenderWindowManager.h
  6. 3 7
      CamelotD3D11RenderSystem/Include/CmD3D11TextureManager.h
  7. 0 6
      CamelotD3D11RenderSystem/Source/CmD3D11HLSLProgram.cpp
  8. 8 8
      CamelotD3D11RenderSystem/Source/CmD3D11HardwareBufferManager.cpp
  9. 8 56
      CamelotD3D11RenderSystem/Source/CmD3D11RenderStateManager.cpp
  10. 10 8
      CamelotD3D11RenderSystem/Source/CmD3D11RenderSystem.cpp
  11. 1 5
      CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp
  12. 2 3
      CamelotD3D11RenderSystem/Source/CmD3D11RenderWindowManager.cpp
  13. 6 16
      CamelotD3D11RenderSystem/Source/CmD3D11TextureManager.cpp
  14. 5 5
      CamelotD3D9Renderer/Include/CmD3D9HardwareBufferManager.h
  15. 1 1
      CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h
  16. 1 1
      CamelotD3D9Renderer/Include/CmD3D9RenderWindowManager.h
  17. 3 7
      CamelotD3D9Renderer/Include/CmD3D9TextureManager.h
  18. 1 1
      CamelotD3D9Renderer/Source/CmD3D9DeviceManager.cpp
  19. 10 10
      CamelotD3D9Renderer/Source/CmD3D9HardwareBufferManager.cpp
  20. 12 7
      CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp
  21. 2 2
      CamelotD3D9Renderer/Source/CmD3D9RenderWindowManager.cpp
  22. 6 18
      CamelotD3D9Renderer/Source/CmD3D9TextureManager.cpp
  23. 1 1
      CamelotForwardRenderer/Source/CmForwardRenderer.cpp
  24. 4 4
      CamelotGLRenderer/Include/CmGLHardwareBufferManager.h
  25. 1 1
      CamelotGLRenderer/Include/CmGLRenderSystem.h
  26. 1 1
      CamelotGLRenderer/Include/CmGLRenderWindowManager.h
  27. 3 7
      CamelotGLRenderer/Include/CmGLTextureManager.h
  28. 8 9
      CamelotGLRenderer/Source/CmGLHardwareBufferManager.cpp
  29. 13 11
      CamelotGLRenderer/Source/CmGLRenderSystem.cpp
  30. 2 4
      CamelotGLRenderer/Source/CmGLRenderWindowManager.cpp
  31. 6 89
      CamelotGLRenderer/Source/CmGLTextureManager.cpp
  32. 2 8
      CamelotGLRenderer/Source/GLSL/src/CmGLSLProgram.cpp
  33. 20 2
      CamelotRenderer/Include/CmCoreGpuObject.h
  34. 1 1
      CamelotRenderer/Include/CmDeferredRenderContext.h
  35. 6 6
      CamelotRenderer/Include/CmHardwareBufferManager.h
  36. 1 7
      CamelotRenderer/Include/CmMeshDataRTTI.h
  37. 15 10
      CamelotRenderer/Include/CmRenderStateManager.h
  38. 3 3
      CamelotRenderer/Include/CmRenderSystem.h
  39. 1 1
      CamelotRenderer/Include/CmRenderWindowManager.h
  40. 4 48
      CamelotRenderer/Include/CmTextureManager.h
  41. 0 1
      CamelotRenderer/Source/CmApplication.cpp
  42. 33 8
      CamelotRenderer/Source/CmCoreGpuObject.cpp
  43. 1 1
      CamelotRenderer/Source/CmDeferredRenderContext.cpp
  44. 1 2
      CamelotRenderer/Source/CmGpuProgramManager.cpp
  45. 11 10
      CamelotRenderer/Source/CmHardwareBufferManager.cpp
  46. 1 5
      CamelotRenderer/Source/CmHighLevelGpuProgram.cpp
  47. 3 3
      CamelotRenderer/Source/CmHighLevelGpuProgramManager.cpp
  48. 1 1
      CamelotRenderer/Source/CmMaterial.cpp
  49. 0 35
      CamelotRenderer/Source/CmMesh.cpp
  50. 0 2
      CamelotRenderer/Source/CmMeshData.cpp
  51. 1 1
      CamelotRenderer/Source/CmMeshManager.cpp
  52. 28 23
      CamelotRenderer/Source/CmRenderStateManager.cpp
  53. 3 2
      CamelotRenderer/Source/CmRenderSystem.cpp
  54. 1 1
      CamelotRenderer/Source/CmRenderWindowManager.cpp
  55. 1 1
      CamelotRenderer/Source/CmShader.cpp
  56. 4 4
      CamelotRenderer/Source/CmTextureManager.cpp
  57. 0 2
      CamelotRenderer/Source/CmVertexData.cpp
  58. 5 6
      CamelotRenderer/TODO.txt

+ 49 - 50
CamelotClient/CamelotClient.cpp

@@ -32,9 +32,9 @@ int CALLBACK WinMain(
 	_In_  int nCmdShow
 	)
 {
-	gApplication().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer");
+	//gApplication().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer");
 	//gApplication().startUp("CamelotD3D9RenderSystem", "CamelotForwardRenderer");
-	//gApplication().startUp("CamelotD3D11RenderSystem", "CamelotForwardRenderer");
+	gApplication().startUp("CamelotD3D11RenderSystem", "CamelotForwardRenderer");
 
 	RenderSystem* renderSystem = RenderSystem::instancePtr();
 	RenderWindowPtr renderWindow = gApplication().getPrimaryRenderWindow();
@@ -80,28 +80,28 @@ int CALLBACK WinMain(
 	//vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "hlsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 
 	/////////////////// HLSL 11 SHADERS //////////////////////////
-	//String fragShaderCode = "SamplerState samp : register(s0);			\
-	//						Texture2D tex : register(t0); \
-	//						float4 ps_main(in float4 inPos : SV_Position, float2 uv : TEXCOORD0) : SV_Target		\
-	//						{														\
-	//						float4 color = tex.Sample(samp, uv);				\
-	//						return color;										\
-	//						}";
-
-	//fragProg =  HighLevelGpuProgram::create(fragShaderCode, "ps_main", "hlsl", GPT_FRAGMENT_PROGRAM, GPP_PS_4_0);
-
-	//String vertShaderCode = "float4x4 matViewProjection;	\
-	//						void vs_main(										\
-	//						in float4 inPos : POSITION,							\
-	//						in float2 uv : TEXCOORD0,								\
-	//						out float4 oPosition : SV_Position,					\
-	//						out float2 oUv : TEXCOORD0)							\
-	//						{														\
-	//						oPosition = mul(matViewProjection, inPos);			\
-	//						oUv = uv;											\
-	//						}";
-
-	//vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "hlsl", GPT_VERTEX_PROGRAM, GPP_VS_4_0);
+	String fragShaderCode = "SamplerState samp : register(s0);			\
+							Texture2D tex : register(t0); \
+							float4 ps_main(in float4 inPos : SV_Position, float2 uv : TEXCOORD0) : SV_Target		\
+							{														\
+							float4 color = tex.Sample(samp, uv);				\
+							return color;										\
+							}";
+
+	fragProg =  HighLevelGpuProgram::create(fragShaderCode, "ps_main", "hlsl", GPT_FRAGMENT_PROGRAM, GPP_PS_4_0);
+
+	String vertShaderCode = "float4x4 matViewProjection;	\
+							void vs_main(										\
+							in float4 inPos : POSITION,							\
+							in float2 uv : TEXCOORD0,								\
+							out float4 oPosition : SV_Position,					\
+							out float2 oUv : TEXCOORD0)							\
+							{														\
+							oPosition = mul(matViewProjection, inPos);			\
+							oUv = uv;											\
+							}";
+
+	vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "hlsl", GPT_VERTEX_PROGRAM, GPP_VS_4_0);
 
 	/////////////////// CG SHADERS //////////////////////////
 	//String fragShaderCode = "sampler2D tex;					\
@@ -127,31 +127,31 @@ int CALLBACK WinMain(
 	//vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "cg", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 
 	///////////////// GLSL SHADERS ////////////////////////////
-	String fragShaderCode = " #version 400 \n \
-							  uniform sampler2D tex; \
-							  in vec2 texcoord0; \
-							  out vec4 fragColor; \
-							  void main() \
-							  {\
-								  vec4 texColor = texture2D(tex, texcoord0.st);\
-								  fragColor = texColor; \
-							  }";
-
-	fragProg = HighLevelGpuProgram::create(fragShaderCode, "main", "glsl", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
-
-	// TODO - Make sure to document the strict input parameter naming. (Exact supported names are in GLSLParamParser)
-	String vertShaderCode = "#version 400 \n \
-							 uniform mainFragBlock { mat4 matViewProjection; }; \
-							 in vec4 cm_position; \
-							 in vec2 cm_texcoord0; \
-							 out vec2 texcoord0; \
-							 void main() \
-							 { \
-								texcoord0 = cm_texcoord0; \
-								gl_Position = cm_position * matViewProjection; \
-							 }";
-
-	vertProg = HighLevelGpuProgram::create(vertShaderCode, "main", "glsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
+	//String fragShaderCode = " #version 400 \n \
+	//						  uniform sampler2D tex; \
+	//						  in vec2 texcoord0; \
+	//						  out vec4 fragColor; \
+	//						  void main() \
+	//						  {\
+	//							  vec4 texColor = texture2D(tex, texcoord0.st);\
+	//							  fragColor = texColor; \
+	//						  }";
+
+	//fragProg = HighLevelGpuProgram::create(fragShaderCode, "main", "glsl", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
+
+	//// TODO - Make sure to document the strict input parameter naming. (Exact supported names are in GLSLParamParser)
+	//String vertShaderCode = "#version 400 \n \
+	//						 uniform mainFragBlock { mat4 matViewProjection; }; \
+	//						 in vec4 cm_position; \
+	//						 in vec2 cm_texcoord0; \
+	//						 out vec2 texcoord0; \
+	//						 void main() \
+	//						 { \
+	//							texcoord0 = cm_texcoord0; \
+	//							gl_Position = cm_position * matViewProjection; \
+	//						 }";
+
+	//vertProg = HighLevelGpuProgram::create(vertShaderCode, "main", "glsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 
 	HighLevelGpuProgramHandle vertProgRef = gResources().create(vertProg, "C:\\vertProgCg.vprog", true);
 	gResources().unload(vertProgRef);
@@ -262,7 +262,6 @@ int CALLBACK WinMain(
 	newPassDX11 = nullptr;
 	newTechniqueDX11 = nullptr;
 
-	testShader->destroy();
 	testShader = nullptr;
 	
 	renderWindow = nullptr;

+ 4 - 4
CamelotD3D11RenderSystem/Include/CmD3D11HardwareBufferManager.h

@@ -17,22 +17,22 @@ namespace CamelotEngine
 		/**
 		 * @copydoc HardwareBufferManager::createVertexBufferImpl
 		 */
-		VertexBufferPtr createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
+		VertexBuffer* createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
 
 		/**
 		 * @copydoc HardwareBufferManager::createIndexBufferImpl
 		 */
-		IndexBufferPtr createIndexBufferImpl(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
+		IndexBuffer* createIndexBufferImpl(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
 
 		/** @copydoc HardwareBufferManager::createGpuParamBlock */
-		GpuParamBlockPtr createGpuParamBlockImpl(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage = GPBU_STATIC);
+		GpuParamBlock* createGpuParamBlockImpl(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage = GPBU_STATIC);
 
 		/**
 		 * @copydoc HardwareBufferManager::createGenericBufferImpl
 		 *
 		 * DirectX 9 does not support generic buffers so this method will return a dummy instance.
 		 */
-		GpuBufferPtr createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
+		GpuBuffer* createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
 			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
 	};
 }

+ 5 - 40
CamelotD3D11RenderSystem/Include/CmD3D11RenderStateManager.h

@@ -7,45 +7,10 @@ namespace CamelotEngine
 {
 	class CM_D3D11_EXPORT D3D11RenderStateManager : public RenderStateManager
 	{
-	public:
-		/**
-		 * @copydoc RenderStateManager::createSamplerState()
-		 */
-		SamplerStatePtr createSamplerState(const SAMPLER_STATE_DESC& desc) const;
-
-		/**
-		 * @copydoc RenderStateManager::createDepthStencilState()
-		 */
-		DepthStencilStatePtr createDepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc) const;
-
-		/**
-		 * @copydoc RenderStateManager::createRasterizerState()
-		 */
-		RasterizerStatePtr createRasterizerState(const RASTERIZER_STATE_DESC& desc) const;
-
-		/**
-		 * @copydoc RenderStateManager::createBlendState()
-		 */
-		BlendStatePtr createBlendState(const BLEND_STATE_DESC& desc) const;
-
-		/**
-		 * @copydoc RenderStateManager::createEmptySamplerState()
-		 */
-		SamplerStatePtr createEmptySamplerState() const;
-
-		/**
-		 * @copydoc RenderStateManager::createEmptyDepthStencilState()
-		 */
-		DepthStencilStatePtr createEmptyDepthStencilState() const;
-
-		/**
-		 * @copydoc RenderStateManager::createEmptyRasterizerState()
-		 */
-		RasterizerStatePtr createEmptyRasterizerState() const;
-
-		/**
-		 * @copydoc RenderStateManager::createEmptyBlendState()
-		 */
-		BlendStatePtr createEmptyBlendState() const;
+	protected:
+		virtual SamplerState* createSamplerStateImpl() const;
+		virtual BlendState* createBlendStateImpl() const;
+		virtual RasterizerState* createRasterizerStateImpl() const;
+		virtual DepthStencilState* createDepthStencilStateImpl() const;
 	};
 }

+ 1 - 1
CamelotD3D11RenderSystem/Include/CmD3D11RenderSystem.h

@@ -33,7 +33,7 @@ namespace CamelotEngine
 		void clear(RenderTargetPtr target, unsigned int buffers, const Color& color = Color::Black, float depth = 1.0f, unsigned short stencil = 0);
 
 		void setRenderTarget(RenderTarget* target);
-		void setViewport(const Viewport& vp);
+		void setViewport(const Viewport* vp);
 		void setScissorRect(UINT32 left = 0, UINT32 top = 0, UINT32 right = 800, UINT32 bottom = 600);
 
 		void setVertexBuffer(UINT32 index, const VertexBufferPtr& buffer);

+ 1 - 1
CamelotD3D11RenderSystem/Include/CmD3D11RenderWindowManager.h

@@ -14,7 +14,7 @@ namespace CamelotEngine
 		/**
 		 * @copydoc RenderWindowManager::createImpl()
 		 */
-		RenderWindowPtr createImpl(const RENDER_WINDOW_DESC& desc);
+		RenderWindow* createImpl(const RENDER_WINDOW_DESC& desc);
 
 	private:
 		D3D11RenderSystem* mRenderSystem;

+ 3 - 7
CamelotD3D11RenderSystem/Include/CmD3D11TextureManager.h

@@ -14,13 +14,9 @@ namespace CamelotEngine
 		/// @copydoc TextureManager::getNativeFormat
 		PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage);
 
-        /// @copydoc TextureManager::isHardwareFilteringSupported
-        bool isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage,
-            bool preciseFormatOnly = false);		
-
 	protected:		
-		TexturePtr createTextureImpl();
-		RenderTexturePtr createRenderTextureImpl();
-		MultiRenderTexturePtr createMultiRenderTextureImpl();
+		Texture* createTextureImpl();
+		RenderTexture* createRenderTextureImpl();
+		MultiRenderTexture* createMultiRenderTextureImpl();
 	};
 }

+ 0 - 6
CamelotD3D11RenderSystem/Source/CmD3D11HLSLProgram.cpp

@@ -84,15 +84,9 @@ namespace CamelotEngine
 
     void D3D11HLSLProgram::destroy_internal()
 	{
-		if(mAssemblerProgram != nullptr)
-			mAssemblerProgram->destroy();
-
 		mAssemblerProgram = nullptr;
 		mMicrocode.clear();
 
-		if(mInputDeclaration != nullptr)
-			mInputDeclaration->destroy();
-
 		mInputDeclaration = nullptr;
 
 		HighLevelGpuProgram::destroy_internal();

+ 8 - 8
CamelotD3D11RenderSystem/Source/CmD3D11HardwareBufferManager.cpp

@@ -16,26 +16,26 @@ namespace CamelotEngine
 
 	}
 
-	VertexBufferPtr D3D11HardwareBufferManager::createVertexBufferImpl(UINT32 vertexSize, 
+	VertexBuffer* D3D11HardwareBufferManager::createVertexBufferImpl(UINT32 vertexSize, 
 		UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
 	{
-		return VertexBufferPtr(new D3D11VertexBuffer(mDevice, this, vertexSize, numVerts, usage, false, streamOut));
+		return new D3D11VertexBuffer(mDevice, this, vertexSize, numVerts, usage, false, streamOut);
 	}
 
-	IndexBufferPtr D3D11HardwareBufferManager::createIndexBufferImpl(IndexBuffer::IndexType itype, 
+	IndexBuffer* D3D11HardwareBufferManager::createIndexBufferImpl(IndexBuffer::IndexType itype, 
 		UINT32 numIndexes, GpuBufferUsage usage)
 	{
-		return IndexBufferPtr(new D3D11IndexBuffer(mDevice, this, itype, numIndexes, usage, false));
+		return new D3D11IndexBuffer(mDevice, this, itype, numIndexes, usage, false);
 	}
 
-	GpuParamBlockPtr D3D11HardwareBufferManager::createGpuParamBlockImpl(const GpuParamBlockDesc& blockDesc, GpuParamBlockUsage usage)
+	GpuParamBlock* D3D11HardwareBufferManager::createGpuParamBlockImpl(const GpuParamBlockDesc& blockDesc, GpuParamBlockUsage usage)
 	{
-		return GpuParamBlockPtr(new D3D11GpuParamBlock(blockDesc, usage));
+		return new D3D11GpuParamBlock(blockDesc, usage);
 	}
 
-	GpuBufferPtr D3D11HardwareBufferManager::createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
+	GpuBuffer* D3D11HardwareBufferManager::createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
 		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
 	{
-		return GpuBufferPtr(new D3D11GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
+		return new D3D11GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter);
 	}
 }

+ 8 - 56
CamelotD3D11RenderSystem/Source/CmD3D11RenderStateManager.cpp

@@ -6,71 +6,23 @@
 
 namespace CamelotEngine
 {
-	SamplerStatePtr D3D11RenderStateManager::createSamplerState(const SAMPLER_STATE_DESC& desc) const
+	SamplerState* D3D11RenderStateManager::createSamplerStateImpl() const
 	{
-		D3D11SamplerStatePtr samplerState = D3D11SamplerStatePtr(new D3D11SamplerState());
-		samplerState->setThisPtr(samplerState);
-		samplerState->initialize(desc);
-
-		return samplerState;
-	}
-
-	DepthStencilStatePtr D3D11RenderStateManager::createDepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc) const
-	{
-		D3D11DepthStencilStatePtr depthStencilState = D3D11DepthStencilStatePtr(new D3D11DepthStencilState());
-		depthStencilState->setThisPtr(depthStencilState);
-		depthStencilState->initialize(desc);
-
-		return depthStencilState;
-	}
-
-	RasterizerStatePtr D3D11RenderStateManager::createRasterizerState(const RASTERIZER_STATE_DESC& desc) const
-	{
-		D3D11RasterizerStatePtr rasterizerState = D3D11RasterizerStatePtr(new D3D11RasterizerState());
-		rasterizerState->setThisPtr(rasterizerState);
-		rasterizerState->initialize(desc);
-
-		return rasterizerState;
-	}
-
-	BlendStatePtr D3D11RenderStateManager::createBlendState(const BLEND_STATE_DESC& desc) const
-	{
-		D3D11BlendStatePtr blendState = D3D11BlendStatePtr(new D3D11BlendState());
-		blendState->setThisPtr(blendState);
-		blendState->initialize(desc);
-
-		return blendState;
-	}
-
-	SamplerStatePtr D3D11RenderStateManager::createEmptySamplerState() const
-	{
-		D3D11SamplerStatePtr samplerState(new D3D11SamplerState());
-		samplerState->setThisPtr(samplerState);
-
-		return samplerState;
+		return new D3D11SamplerState();
 	}
 
-	DepthStencilStatePtr D3D11RenderStateManager::createEmptyDepthStencilState() const
+	BlendState* D3D11RenderStateManager::createBlendStateImpl() const
 	{
-		D3D11DepthStencilStatePtr depthStencilState(new D3D11DepthStencilState());
-		depthStencilState->setThisPtr(depthStencilState);
-
-		return depthStencilState;
+		return new D3D11BlendState();
 	}
 
-	RasterizerStatePtr D3D11RenderStateManager::createEmptyRasterizerState() const
+	RasterizerState* D3D11RenderStateManager::createRasterizerStateImpl() const
 	{
-		D3D11RasterizerStatePtr rasterizerState(new D3D11RasterizerState());
-		rasterizerState->setThisPtr(rasterizerState);
-
-		return rasterizerState;
+		return new D3D11RasterizerState();
 	}
 
-	BlendStatePtr D3D11RenderStateManager::createEmptyBlendState() const
+	DepthStencilState* D3D11RenderStateManager::createDepthStencilStateImpl() const
 	{
-		D3D11BlendStatePtr blendState(new D3D11BlendState());
-		blendState->setThisPtr(blendState);
-
-		return blendState;
+		return new D3D11DepthStencilState();
 	}
 }

+ 10 - 8
CamelotD3D11RenderSystem/Source/CmD3D11RenderSystem.cpp

@@ -275,26 +275,28 @@ namespace CamelotEngine
 		// Not used
 	}
 
-	void D3D11RenderSystem::setViewport(const Viewport& vp)
+	void D3D11RenderSystem::setViewport(const Viewport* vp)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
+		assert(vp != nullptr);
+
 		mActiveViewport = vp;
 
 		// Set render target
-		RenderTargetPtr target = vp.getTarget();
+		RenderTargetPtr target = vp->getTarget();
 		setRenderTarget(target.get());
 
 		// set viewport dimensions
-		mViewport.TopLeftX = (FLOAT)vp.getActualLeft();
-		mViewport.TopLeftY = (FLOAT)vp.getActualTop();
-		mViewport.Width = (FLOAT)vp.getActualWidth();
-		mViewport.Height = (FLOAT)vp.getActualHeight();
+		mViewport.TopLeftX = (FLOAT)vp->getActualLeft();
+		mViewport.TopLeftY = (FLOAT)vp->getActualTop();
+		mViewport.Width = (FLOAT)vp->getActualWidth();
+		mViewport.Height = (FLOAT)vp->getActualHeight();
 
-		if (vp.getTarget()->requiresTextureFlipping())
+		if (vp->getTarget()->requiresTextureFlipping())
 		{
 			// Convert "top-left" to "bottom-left"
-			mViewport.TopLeftY = vp.getTarget()->getHeight() - mViewport.Height - mViewport.TopLeftY;
+			mViewport.TopLeftY = vp->getTarget()->getHeight() - mViewport.Height - mViewport.TopLeftY;
 		}
 
 		// Z-values from 0.0 to 1.0 (TODO: standardise with OpenGL)

+ 1 - 5
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -540,11 +540,7 @@ namespace CamelotEngine
 		SAFE_RELEASE(mBackBuffer);
 		SAFE_RELEASE(mRenderTargetView);
 
-		if(mDepthStencilBuffer != nullptr)
-		{
-			mDepthStencilBuffer->destroy();
-			mDepthStencilBuffer = nullptr;
-		}
+		mDepthStencilBuffer = nullptr;
 	}
 
 	void D3D11RenderWindow::_resizeSwapChainBuffers(unsigned width, unsigned height)

+ 2 - 3
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindowManager.cpp

@@ -11,14 +11,13 @@ namespace CamelotEngine
 		assert(mRenderSystem != nullptr);
 	}
 
-	RenderWindowPtr D3D11RenderWindowManager::createImpl(const RENDER_WINDOW_DESC& desc)
+	RenderWindow* D3D11RenderWindowManager::createImpl(const RENDER_WINDOW_DESC& desc)
 	{
 		RenderSystem* rs = RenderSystem::instancePtr();
 		D3D11RenderSystem* d3d11rs = static_cast<D3D11RenderSystem*>(rs);
 
 		// Create the window
 		D3D11RenderWindow* renderWindow = new D3D11RenderWindow(desc, d3d11rs->getPrimaryDevice(), d3d11rs->getDXGIFactory());
-
-		return RenderWindowPtr(renderWindow);
+		return renderWindow;
 	}
 }

+ 6 - 16
CamelotD3D11RenderSystem/Source/CmD3D11TextureManager.cpp

@@ -14,19 +14,19 @@ namespace CamelotEngine
 	D3D11TextureManager::~D3D11TextureManager()
 	{ }
 
-	TexturePtr D3D11TextureManager::createTextureImpl()
+	Texture* D3D11TextureManager::createTextureImpl()
 	{
-		return TexturePtr(new D3D11Texture()); 
+		return new D3D11Texture(); 
 	}
 
-	RenderTexturePtr D3D11TextureManager::createRenderTextureImpl()
+	RenderTexture* D3D11TextureManager::createRenderTextureImpl()
 	{
-		return RenderTexturePtr(new D3D11RenderTexture());
+		return new D3D11RenderTexture();
 	}
 
-	MultiRenderTexturePtr D3D11TextureManager::createMultiRenderTextureImpl()
+	MultiRenderTexture* D3D11TextureManager::createMultiRenderTextureImpl()
 	{
-		return MultiRenderTexturePtr(new D3D11MultiRenderTexture());
+		return new D3D11MultiRenderTexture();
 	}
 
 	PixelFormat D3D11TextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage)
@@ -36,14 +36,4 @@ namespace CamelotEngine
 
 		return D3D11Mappings::_getPF(d3dPF);
 	}
-
-	bool D3D11TextureManager::isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage,
-		bool preciseFormatOnly)
-	{
-		if (!preciseFormatOnly)
-			format = getNativeFormat(ttype, format, usage);
-
-		D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
-		return rs->checkTextureFilteringSupported(ttype, format, usage);
-	}
 }

+ 5 - 5
CamelotD3D9Renderer/Include/CmD3D9HardwareBufferManager.h

@@ -42,27 +42,27 @@ namespace CamelotEngine {
 
 	protected:     
 		/// Internal method for creates a new vertex declaration, may be overridden by certain rendering APIs
-		VertexDeclarationPtr createVertexDeclarationImpl(void);
+		VertexDeclaration* createVertexDeclarationImpl();
 
 		/**
 		 * @copydoc HardwareBufferManager::createVertexBufferImpl
 		 */
-		VertexBufferPtr createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
+		VertexBuffer* createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
 
 		/**
 		 * @copydoc HardwareBufferManager::createIndexBufferImpl
 		 */
-		IndexBufferPtr createIndexBufferImpl(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
+		IndexBuffer* createIndexBufferImpl(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
 
 		/** @copydoc HardwareBufferManager::createGpuParamBlock */
-		GpuParamBlockPtr createGpuParamBlockImpl(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage = GPBU_STATIC);
+		GpuParamBlock* createGpuParamBlockImpl(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage = GPBU_STATIC);
 
 		/**
 		 * @copydoc HardwareBufferManager::createGenericBufferImpl
 		 *
 		 * DirectX 9 does not support generic buffers so this method will return a dummy instance.
 		 */
-		GpuBufferPtr createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
+		GpuBuffer* createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
 			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
     };
 }

+ 1 - 1
CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h

@@ -129,7 +129,7 @@ namespace CamelotEngine
 		/**
 		 * @copydoc RenderSystem::setViewport()
 		 */
-		void setViewport(const Viewport& vp);	
+		void setViewport(const Viewport* vp);	
 
 		/**
 		 * @copydoc RenderSystem::beginFrame()

+ 1 - 1
CamelotD3D9Renderer/Include/CmD3D9RenderWindowManager.h

@@ -14,7 +14,7 @@ namespace CamelotEngine
 		/**
 		 * @copydoc RenderWindowManager::createImpl()
 		 */
-		RenderWindowPtr createImpl(const RENDER_WINDOW_DESC& desc);
+		RenderWindow* createImpl(const RENDER_WINDOW_DESC& desc);
 
 	private:
 		D3D9RenderSystem* mRenderSystem;

+ 3 - 7
CamelotD3D9Renderer/Include/CmD3D9TextureManager.h

@@ -43,14 +43,10 @@ namespace CamelotEngine
 		/// @copydoc TextureManager::getNativeFormat
 		PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage);
 
-        /// @copydoc TextureManager::isHardwareFilteringSupported
-        bool isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage,
-            bool preciseFormatOnly = false);		
-
 	protected:		
-		TexturePtr createTextureImpl();
-		RenderTexturePtr createRenderTextureImpl();
-		MultiRenderTexturePtr createMultiRenderTextureImpl();
+		Texture* createTextureImpl();
+		RenderTexture* createRenderTextureImpl();
+		MultiRenderTexture* createMultiRenderTextureImpl();
 	};
 }
 #endif

+ 1 - 1
CamelotD3D9Renderer/Source/CmD3D9DeviceManager.cpp

@@ -77,7 +77,7 @@ namespace CamelotEngine
 			}	
 
 			// Invalidate active view port.
-			renderSystem->mActiveViewport = Viewport();
+			renderSystem->mActiveViewport = nullptr;
 		}						
 	}
 

+ 10 - 10
CamelotD3D9Renderer/Source/CmD3D9HardwareBufferManager.cpp

@@ -44,34 +44,34 @@ namespace CamelotEngine
     {
     }
     //-----------------------------------------------------------------------
-    VertexBufferPtr D3D9HardwareBufferManager::createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
+    VertexBuffer* D3D9HardwareBufferManager::createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
     {
 		assert (numVerts > 0);
 
-        return VertexBufferPtr(new D3D9VertexBuffer(this, vertexSize, numVerts, usage, false));
+        return new D3D9VertexBuffer(this, vertexSize, numVerts, usage, false);
     }
     //-----------------------------------------------------------------------
-	IndexBufferPtr D3D9HardwareBufferManager::createIndexBufferImpl(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
+	IndexBuffer* D3D9HardwareBufferManager::createIndexBufferImpl(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
     {
 		assert (numIndexes > 0);
 
-		return IndexBufferPtr(new D3D9IndexBuffer(this, itype, numIndexes, usage, false));
+		return new D3D9IndexBuffer(this, itype, numIndexes, usage, false);
             
     }
 	//-----------------------------------------------------------------------
-	GpuParamBlockPtr D3D9HardwareBufferManager::createGpuParamBlockImpl(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage)
+	GpuParamBlock* D3D9HardwareBufferManager::createGpuParamBlockImpl(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage)
 	{
-		return GpuParamBlockPtr(new GpuParamBlock(paramDesc, usage));
+		return new GpuParamBlock(paramDesc, usage);
 	}
 	//-----------------------------------------------------------------------
-	GpuBufferPtr D3D9HardwareBufferManager::createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
+	GpuBuffer* D3D9HardwareBufferManager::createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
 		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
 	{
-		return GpuBufferPtr(new D3D9GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
+		return new D3D9GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter);
 	}
     //-----------------------------------------------------------------------
-    VertexDeclarationPtr D3D9HardwareBufferManager::createVertexDeclarationImpl(void)
+    VertexDeclaration* D3D9HardwareBufferManager::createVertexDeclarationImpl(void)
     {
-        return VertexDeclarationPtr(new D3D9VertexDeclaration());
+        return new D3D9VertexDeclaration();
     }
 }

+ 12 - 7
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -263,6 +263,9 @@ namespace CamelotEngine
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
+		if(!prg.isLoaded())
+			return;
+
 		GpuProgram* bindingPrg = prg->getBindingDelegate();
 
 		HRESULT hr;
@@ -1121,10 +1124,12 @@ namespace CamelotEngine
 		}
 	}
 	//---------------------------------------------------------------------
-	void D3D9RenderSystem::setViewport(const Viewport& vp)
+	void D3D9RenderSystem::setViewport(const Viewport* vp)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
+		assert(vp != nullptr);
+
 		mActiveViewport = vp;
 
 		// ok, it's different, time to set render target and viewport params
@@ -1132,16 +1137,16 @@ namespace CamelotEngine
 		HRESULT hr;
 
 		// Set render target
-		RenderTargetPtr target = vp.getTarget();
+		RenderTargetPtr target = vp->getTarget();
 		setRenderTarget(target.get());
 
 		setCullingMode( mCullingMode );
 
 		// set viewport dimensions
-		d3dvp.X = vp.getActualLeft();
-		d3dvp.Y = vp.getActualTop();
-		d3dvp.Width = vp.getActualWidth();
-		d3dvp.Height = vp.getActualHeight();
+		d3dvp.X = vp->getActualLeft();
+		d3dvp.Y = vp->getActualTop();
+		d3dvp.Width = vp->getActualWidth();
+		d3dvp.Height = vp->getActualHeight();
 		if (target->requiresTextureFlipping())
 		{
 			// Convert "top-left" to "bottom-left"
@@ -2361,7 +2366,7 @@ namespace CamelotEngine
 		// Restore previous active device.
 
 		// Invalidate active view port.
-		mActiveViewport = Viewport();
+		mActiveViewport = nullptr;
 	}
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::determineFSAASettings(IDirect3DDevice9* d3d9Device,

+ 2 - 2
CamelotD3D9Renderer/Source/CmD3D9RenderWindowManager.cpp

@@ -11,8 +11,8 @@ namespace CamelotEngine
 		assert(mRenderSystem != nullptr);
 	}
 
-	RenderWindowPtr D3D9RenderWindowManager::createImpl(const RENDER_WINDOW_DESC& desc)
+	RenderWindow* D3D9RenderWindowManager::createImpl(const RENDER_WINDOW_DESC& desc)
 	{
-		return RenderWindowPtr(new D3D9RenderWindow(desc, mRenderSystem->getInstanceHandle()));
+		return new D3D9RenderWindow(desc, mRenderSystem->getInstanceHandle());
 	}
 }

+ 6 - 18
CamelotD3D9Renderer/Source/CmD3D9TextureManager.cpp

@@ -45,19 +45,19 @@ namespace CamelotEngine
 
 	}
 
-    TexturePtr D3D9TextureManager::createTextureImpl()
+    Texture* D3D9TextureManager::createTextureImpl()
     {
-		return TexturePtr(new D3D9Texture());
+		return new D3D9Texture();
     }
 
-	RenderTexturePtr D3D9TextureManager::createRenderTextureImpl()
+	RenderTexture* D3D9TextureManager::createRenderTextureImpl()
 	{
-		return RenderTexturePtr(new D3D9RenderTexture());
+		return new D3D9RenderTexture();
 	}
 
-	MultiRenderTexturePtr D3D9TextureManager::createMultiRenderTextureImpl()
+	MultiRenderTexture* D3D9TextureManager::createMultiRenderTextureImpl()
 	{
-		return MultiRenderTexturePtr(new D3D9MultiRenderTexture());
+		return new D3D9MultiRenderTexture();
 	}
 
 	PixelFormat D3D9TextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage)
@@ -103,16 +103,4 @@ namespace CamelotEngine
 
 		return D3D9Mappings::_getPF(d3dPF);
 	}
-
-    bool D3D9TextureManager::isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage,
-        bool preciseFormatOnly)
-    {
-        if (!preciseFormatOnly)
-            format = getNativeFormat(ttype, format, usage);
-
-        D3D9RenderSystem* rs = static_cast<D3D9RenderSystem*>(
-            CamelotEngine::RenderSystem::instancePtr());
-
-        return rs->checkTextureFilteringSupported(ttype, format, usage);
-    }
 }

+ 1 - 1
CamelotForwardRenderer/Source/CmForwardRenderer.cpp

@@ -45,7 +45,7 @@ namespace CamelotEngine
 		vector<RenderablePtr>::type allRenderables = gSceneManager().getVisibleRenderables(camera);
 
 		DeferredRenderContextPtr renderContext = gApplication().getPrimaryRenderContext();
-		renderContext->setViewport(*camera->getViewport());
+		renderContext->setViewport(camera->getViewport());
 
 		Matrix4 projMatrixCstm = camera->getProjectionMatrix();
 		Matrix4 viewMatrixCstm = camera->getViewMatrix();

+ 4 - 4
CamelotGLRenderer/Include/CmGLHardwareBufferManager.h

@@ -75,25 +75,25 @@ namespace CamelotEngine {
 		/**
 		 * @copydoc HardwareBufferManager::createVertexBufferImpl
 		 */
-        VertexBufferPtr createVertexBufferImpl(UINT32 vertexSize, 
+        VertexBuffer* createVertexBufferImpl(UINT32 vertexSize, 
             UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
 
 		/**
 		 * @copydoc HardwareBufferManager::createIndexBufferImpl
 		 */
-        IndexBufferPtr createIndexBufferImpl(
+        IndexBuffer* createIndexBufferImpl(
             IndexBuffer::IndexType itype, UINT32 numIndexes, 
             GpuBufferUsage usage);
 
 		/** @copydoc HardwareBufferManager::createGpuParamBlockImpl */
-		GpuParamBlockPtr createGpuParamBlockImpl(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage = GPBU_STATIC);
+		GpuParamBlock* createGpuParamBlockImpl(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage = GPBU_STATIC);
 
 		/**
 		 * @copydoc HardwareBufferManager::createGenericBufferImpl
 		 *
 		 * OpenGL does not support generic buffers so this method will return a dummy instance.
 		 */
-		GpuBufferPtr createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
+		GpuBuffer* createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
 			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
     };
 }

+ 1 - 1
CamelotGLRenderer/Include/CmGLRenderSystem.h

@@ -115,7 +115,7 @@ namespace CamelotEngine {
 		/**
 		 * @copydoc RenderSystem::setViewport()
 		 */
-        void setViewport(const Viewport& vp);
+        void setViewport(const Viewport* vp);
 
 		/**
 		 * @copydoc RenderSystem::bindGpuProgram()

+ 1 - 1
CamelotGLRenderer/Include/CmGLRenderWindowManager.h

@@ -14,7 +14,7 @@ namespace CamelotEngine
 		/**
 		 * @copydoc RenderWindowManager::createImpl()
 		 */
-		RenderWindowPtr createImpl(const RENDER_WINDOW_DESC& desc);
+		RenderWindow* createImpl(const RENDER_WINDOW_DESC& desc);
 
 	private:
 		GLRenderSystem* mRenderSystem;

+ 3 - 7
CamelotGLRenderer/Include/CmGLTextureManager.h

@@ -47,14 +47,10 @@ namespace CamelotEngine {
 		/// @copydoc TextureManager::getNativeFormat
 		PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage);
 
-        /// @copydoc TextureManager::isHardwareFilteringSupported
-        bool isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage,
-            bool preciseFormatOnly = false);
-
 	protected:		
-		TexturePtr createTextureImpl();
-		RenderTexturePtr createRenderTextureImpl();
-		MultiRenderTexturePtr createMultiRenderTextureImpl();
+		Texture* createTextureImpl();
+		RenderTexture* createRenderTextureImpl();
+		MultiRenderTexture* createMultiRenderTextureImpl();
 
 		/// Internal method to create a warning texture (bound when a texture unit is blank)
 		void createWarningTexture();

+ 8 - 9
CamelotGLRenderer/Source/CmGLHardwareBufferManager.cpp

@@ -80,29 +80,29 @@ namespace CamelotEngine {
 		_aligned_free(mScratchBufferPool);
     }
     //-----------------------------------------------------------------------
-    VertexBufferPtr GLHardwareBufferManager::createVertexBufferImpl(
+    VertexBuffer* GLHardwareBufferManager::createVertexBufferImpl(
         UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
     {
-		return VertexBufferPtr(new GLVertexBuffer(this, vertexSize, numVerts, usage));
+		return new GLVertexBuffer(this, vertexSize, numVerts, usage);
     }
     //-----------------------------------------------------------------------
-    IndexBufferPtr 
+    IndexBuffer* 
     GLHardwareBufferManager::createIndexBufferImpl(
         IndexBuffer::IndexType itype, UINT32 numIndexes, 
         GpuBufferUsage usage)
     {
-		return IndexBufferPtr(new GLIndexBuffer(this, itype, numIndexes, usage));
+		return new GLIndexBuffer(this, itype, numIndexes, usage);
     }
 	//---------------------------------------------------------------------
-	GpuParamBlockPtr GLHardwareBufferManager::createGpuParamBlockImpl(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage)
+	GpuParamBlock* GLHardwareBufferManager::createGpuParamBlockImpl(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage)
 	{
-		return GpuParamBlockPtr(new GLGpuParamBlock(paramDesc, usage));
+		return new GLGpuParamBlock(paramDesc, usage);
 	}
 	//---------------------------------------------------------------------
-	GpuBufferPtr GLHardwareBufferManager::createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
+	GpuBuffer* GLHardwareBufferManager::createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
 		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
 	{
-		return GpuBufferPtr(new GLGpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
+		return new GLGpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter);
 	}
     //---------------------------------------------------------------------
     GLenum GLHardwareBufferManager::getGLUsage(unsigned int usage)
@@ -141,7 +141,6 @@ namespace CamelotEngine {
                 return 0;
         };
     }
-	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
 	void* GLHardwareBufferManager::allocateScratch(UINT32 size)
 	{

+ 13 - 11
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -529,22 +529,24 @@ namespace CamelotEngine
 		setStencilRefValue(stencilRefValue);
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::setViewport(const Viewport& vp)
+	void GLRenderSystem::setViewport(const Viewport* vp)
 	{
 		THROW_IF_NOT_RENDER_THREAD;
 
+		assert(vp != nullptr);
+
 		RenderTargetPtr target;
-		target = vp.getTarget();
+		target = vp->getTarget();
 		setRenderTarget(target.get());
 		mActiveViewport = vp;
 		
 		GLsizei x, y, w, h;
 
 		// Calculate the "lower-left" corner of the viewport
-		w = vp.getActualWidth();
-		h = vp.getActualHeight();
-		x = vp.getActualLeft();
-		y = vp.getActualTop();
+		w = vp->getActualWidth();
+		h = vp->getActualHeight();
+		x = vp->getActualLeft();
+		y = vp->getActualTop();
 		if (!target->requiresTextureFlipping())
 		{
 			// Convert "upper-left" corner to "lower-left"
@@ -990,13 +992,13 @@ namespace CamelotEngine
 		{
 			glDisable(GL_SCISSOR_TEST);
 			// GL requires you to reset the scissor when disabling
-			w = mActiveViewport.getActualWidth();
-			h = mActiveViewport.getActualHeight();
-			x = mActiveViewport.getActualLeft();
+			w = mActiveViewport->getActualWidth();
+			h = mActiveViewport->getActualHeight();
+			x = mActiveViewport->getActualLeft();
 			if (flipping)
-				y = mActiveViewport.getActualTop();
+				y = mActiveViewport->getActualTop();
 			else
-				y = targetHeight - mActiveViewport.getActualTop() - h;
+				y = targetHeight - mActiveViewport->getActualTop() - h;
 			glScissor(x, y, w, h);
 		}
 	}

+ 2 - 4
CamelotGLRenderer/Source/CmGLRenderWindowManager.cpp

@@ -11,14 +11,12 @@ namespace CamelotEngine
 		assert(mRenderSystem != nullptr);
 	}
 
-	RenderWindowPtr GLRenderWindowManager::createImpl(const RENDER_WINDOW_DESC& desc)
+	RenderWindow* GLRenderWindowManager::createImpl(const RENDER_WINDOW_DESC& desc)
 	{
 		GLSupport* glSupport = mRenderSystem->getGLSupport();
 
 		// Create the window
 		RenderWindow* win = glSupport->newWindow(desc);
-
-		RenderWindowPtr winPtr(win);
-		return winPtr;
+		return win;
 	}
 }

+ 6 - 89
CamelotGLRenderer/Source/CmGLTextureManager.cpp

@@ -45,19 +45,19 @@ namespace CamelotEngine {
 		glDeleteTextures(1, &mWarningTextureID);
     }
     //-----------------------------------------------------------------------------
-    TexturePtr GLTextureManager::createTextureImpl()
+    Texture* GLTextureManager::createTextureImpl()
     {
-        return TexturePtr(new GLTexture(mGLSupport));
+        return new GLTexture(mGLSupport);
     }
 	//-----------------------------------------------------------------------------
-	RenderTexturePtr GLTextureManager::createRenderTextureImpl()
+	RenderTexture* GLTextureManager::createRenderTextureImpl()
 	{
-		return RenderTexturePtr(new GLRenderTexture());
+		return new GLRenderTexture();
 	}
 	//----------------------------------------------------------------------------
-	MultiRenderTexturePtr GLTextureManager::createMultiRenderTextureImpl()
+	MultiRenderTexture* GLTextureManager::createMultiRenderTextureImpl()
 	{
-		return MultiRenderTexturePtr(new GLMultiRenderTexture());
+		return new GLMultiRenderTexture();
 	}
 	//-----------------------------------------------------------------------------
 	void GLTextureManager::createWarningTexture()
@@ -119,88 +119,5 @@ namespace CamelotEngine {
 
 		// Supported
 		return format;
-
-		
 	}
-	//-----------------------------------------------------------------------------
-    bool GLTextureManager::isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage,
-            bool preciseFormatOnly)
-    {
-        if (format == PF_UNKNOWN)
-            return false;
-
-        // Check natively format
-        PixelFormat nativeFormat = getNativeFormat(ttype, format, usage);
-        if (preciseFormatOnly && format != nativeFormat)
-            return false;
-
-        // Assume non-floating point is supported always
-        if (!PixelUtil::isFloatingPoint(nativeFormat))
-            return true;
-
-        // Hack: there are no elegant GL API to detects texture filtering supported,
-        // just hard code for cards based on vendor specifications.
-
-        // TODO: Add cards that 16 bits floating point flitering supported by
-        // hardware below
-        static const String sFloat16SupportedCards[] =
-        {
-            // GeForce 8 Series
-            "*GeForce*8800*",
-
-            // GeForce 7 Series
-            "*GeForce*7950*",
-            "*GeForce*7900*",
-            "*GeForce*7800*",
-            "*GeForce*7600*",
-            "*GeForce*7500*",
-            "*GeForce*7300*",
-
-            // GeForce 6 Series
-            "*GeForce*6800*",
-            "*GeForce*6700*",
-            "*GeForce*6600*",
-            "*GeForce*6500*",
-
-            ""                      // Empty string means end of list
-        };
-
-        // TODO: Add cards that 32 bits floating point flitering supported by
-        // hardware below
-        static const String sFloat32SupportedCards[] =
-        {
-            // GeForce 8 Series
-            "*GeForce*8800*",
-
-            ""                      // Empty string means end of list
-        };
-
-        PixelComponentType pct = PixelUtil::getComponentType(nativeFormat);
-        const String* supportedCards;
-        switch (pct)
-        {
-        case PCT_FLOAT16:
-            supportedCards = sFloat16SupportedCards;
-            break;
-        case PCT_FLOAT32:
-            supportedCards = sFloat32SupportedCards;
-            break;
-        default:
-            return false;
-        }
-
-        const GLubyte* pcRenderer = glGetString(GL_RENDERER);
-        String str = (const char*)pcRenderer;
-
-        for (; !supportedCards->empty(); ++supportedCards)
-        {
-            if (StringUtil::match(str, *supportedCards))
-            {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
 }

+ 2 - 8
CamelotGLRenderer/Source/GLSL/src/CmGLSLProgram.cpp

@@ -182,17 +182,11 @@ namespace CamelotEngine
 	//---------------------------------------------------------------------------
 	void GLSLProgram::destroy_internal()
 	{   
-		if(mAssemblerProgram != nullptr)
-		{
-			mAssemblerProgram->destroy();
-			mAssemblerProgram = nullptr;
-		}
-		
+		mAssemblerProgram = nullptr;
+
 		if (isSupported())
 			glDeleteShader(mGLHandle);
 
-		mVertexDeclaration->destroy();
-
 		HighLevelGpuProgram::destroy_internal();
 	}
     //-----------------------------------------------------------------------

+ 20 - 2
CamelotRenderer/Include/CmCoreGpuObject.h

@@ -14,6 +14,13 @@ namespace CamelotEngine
 	 */
 	class CM_EXPORT CoreGpuObject
 	{
+	protected:
+		enum Flags
+		{
+			CGO_INITIALIZED = 0x01,
+			CGO_SCHEDULED_FOR_DELETE = 0x02
+		};
+
 	public:
 		CoreGpuObject();
 		virtual ~CoreGpuObject();
@@ -39,7 +46,7 @@ o		 *
 		 * @brief	Returns true if the object has been properly initialized. You are not
 		 * 			allowed to call any methods on the resource until you are sure resource is initialized.
 		 */
-		bool isInitialized() const { return mIsInitialized; }
+		bool isInitialized() const { return (mFlags & CGO_INITIALIZED) != 0; }
 
 		/**
 		 * @brief	Blocks the current thread until the resource is fully initialized.
@@ -54,6 +61,13 @@ o		 *
 		 */
 		void setThisPtr(std::shared_ptr<CoreGpuObject> ptrThis);
 
+		/**
+		 * @brief	Schedules the object to be destroyed, and then deleted.
+		 *
+		 * @note	You should never call this manually. It's meant for internal use only.
+		 */
+		static void _deleteDelayed(CoreGpuObject* obj);
+
 	protected:
 		/**
 		 * @brief	Frees all of the objects dynamically allocated memory. All derived classes that have something to free
@@ -76,10 +90,14 @@ o		 *
 		 */
 		UINT64 getInternalID() const { return mInternalID; }
 
+		bool isScheduledToBeDeleted() const { return (mFlags & CGO_SCHEDULED_FOR_DELETE) != 0; }
+
+		void setIsInitialized(bool initialized) { mFlags = initialized ? mFlags | CGO_INITIALIZED : mFlags & ~CGO_INITIALIZED; }
+		void setScheduledToBeDeleted(bool scheduled) { mFlags = scheduled ? mFlags | CGO_SCHEDULED_FOR_DELETE : mFlags & ~CGO_SCHEDULED_FOR_DELETE; }
 	private:
 		friend class CoreGpuObjectManager;
 
-		bool mIsInitialized;
+		UINT8 mFlags;
 		UINT64 mInternalID; // ID == 0 is not a valid ID
 		std::weak_ptr<CoreGpuObject> mThis;
 

+ 1 - 1
CamelotRenderer/Include/CmDeferredRenderContext.h

@@ -47,7 +47,7 @@ namespace CamelotEngine
 		void setDepthStencilState(const DepthStencilStatePtr& depthStencilState, UINT32 stencilRefValue);
 
 		/** @copydoc RenderSystem::setViewport() */
-		void setViewport(const Viewport& vp);
+		void setViewport(const Viewport* vp);
 
 		/** @copydoc RenderSystem::setVertexBuffer() */
 		void setVertexBuffer(UINT32 index, const VertexBufferPtr& buffer);

+ 6 - 6
CamelotRenderer/Include/CmHardwareBufferManager.h

@@ -113,14 +113,14 @@ namespace CamelotEngine {
 			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
 
         /** Creates a new vertex declaration. */
-        virtual VertexDeclarationPtr createVertexDeclaration(void);
+        virtual VertexDeclarationPtr createVertexDeclaration();
 
 	protected:
-		virtual VertexDeclarationPtr createVertexDeclarationImpl(void);
-		virtual VertexBufferPtr createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false) = 0;
-		virtual IndexBufferPtr createIndexBufferImpl(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage) = 0;
-		virtual GpuParamBlockPtr createGpuParamBlockImpl(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage = GPBU_STATIC) = 0;
-		virtual GpuBufferPtr createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, 
+		virtual VertexDeclaration* createVertexDeclarationImpl();
+		virtual VertexBuffer* createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false) = 0;
+		virtual IndexBuffer* createIndexBufferImpl(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage) = 0;
+		virtual GpuParamBlock* createGpuParamBlockImpl(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage = GPBU_STATIC) = 0;
+		virtual GpuBuffer* createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, 
 			bool randomGpuWrite = false, bool useCounter = false) = 0;
 	};
 

+ 1 - 7
CamelotRenderer/Include/CmMeshDataRTTI.h

@@ -103,13 +103,7 @@ namespace CamelotEngine
 		/************************************************************************/
 
 		VertexDeclarationPtr getVertexDecl(MeshData* obj) { return obj->declaration; }
-		void setVertexDecl(MeshData* obj, VertexDeclarationPtr vertexDecl) 
-		{ 
-			if(obj->declaration)
-				obj->declaration->destroy();
-
-			obj->declaration = vertexDecl; 
-		}
+		void setVertexDecl(MeshData* obj, VertexDeclarationPtr vertexDecl) { obj->declaration = vertexDecl; }
 
 		/************************************************************************/
 		/* 								vertexData                      		*/

+ 15 - 10
CamelotRenderer/Include/CmRenderStateManager.h

@@ -8,60 +8,65 @@ namespace CamelotEngine
 	class CM_EXPORT RenderStateManager : public Module<RenderStateManager>
 	{
 	public:
-		virtual ~RenderStateManager();
-
 		/**
 		 * @brief	Creates and initializes a new SamplerState.
 		 */
-		virtual SamplerStatePtr createSamplerState(const SAMPLER_STATE_DESC& desc) const;
+		SamplerStatePtr createSamplerState(const SAMPLER_STATE_DESC& desc) const;
 
 		/**
 		 * @brief	Creates and initializes a new DepthStencilState.
 		 */
-		virtual DepthStencilStatePtr createDepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc) const;
+		DepthStencilStatePtr createDepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc) const;
 
 		/**
 		 * @brief	Creates and initializes a new RasterizerState.
 		 */
-		virtual RasterizerStatePtr createRasterizerState(const RASTERIZER_STATE_DESC& desc) const;
+		RasterizerStatePtr createRasterizerState(const RASTERIZER_STATE_DESC& desc) const;
 
 		/**
 		 * @brief	Creates and initializes a new BlendState.
 		 */
-		virtual BlendStatePtr createBlendState(const BLEND_STATE_DESC& desc) const;
+		BlendStatePtr createBlendState(const BLEND_STATE_DESC& desc) const;
 
 		/**
 		 * @brief	Creates a completely empty and uninitialized SamplerState.
 		 * 			Should only be used for VERY specific purposes, like deserialization,
 		 * 			as it requires additional manual initialization that is not required normally.
 		 */
-		virtual SamplerStatePtr createEmptySamplerState() const;
+		SamplerStatePtr createEmptySamplerState() const;
 
 		/**
 		 * @brief	Creates a completely empty and uninitialized DepthStencilState.
 		 * 			Should only be used for VERY specific purposes, like deserialization,
 		 * 			as it requires additional manual initialization that is not required normally.
 		 */
-		virtual DepthStencilStatePtr createEmptyDepthStencilState() const;
+		DepthStencilStatePtr createEmptyDepthStencilState() const;
 
 		/**
 		 * @brief	Creates a completely empty and uninitialized RasterizerState.
 		 * 			Should only be used for VERY specific purposes, like deserialization,
 		 * 			as it requires additional manual initialization that is not required normally.
 		 */
-		virtual RasterizerStatePtr createEmptyRasterizerState() const;
+		RasterizerStatePtr createEmptyRasterizerState() const;
 
 		/**
 		 * @brief	Creates a completely empty and uninitialized BlendState.
 		 * 			Should only be used for VERY specific purposes, like deserialization,
 		 * 			as it requires additional manual initialization that is not required normally.
 		 */
-		virtual BlendStatePtr createEmptyBlendState() const;
+		BlendStatePtr createEmptyBlendState() const;
 
 		const SamplerStatePtr& getDefaultSamplerState() const;
 		const BlendStatePtr& getDefaultBlendState() const;
 		const RasterizerStatePtr& getDefaultRasterizerState() const;
 		const DepthStencilStatePtr& getDefaultDepthStencilState() const;
+
+	protected:
+		virtual SamplerState* createSamplerStateImpl() const;
+		virtual BlendState* createBlendStateImpl() const;
+		virtual RasterizerState* createRasterizerStateImpl() const;
+		virtual DepthStencilState* createDepthStencilStateImpl() const;
+
 	private:
 		mutable SamplerStatePtr mDefaultSamplerState;
 		mutable BlendStatePtr mDefaultBlendState;

+ 3 - 3
CamelotRenderer/Include/CmRenderSystem.h

@@ -188,9 +188,9 @@ namespace CamelotEngine
 
 		@param target Viewport to render to.
 		*/
-		virtual void setViewport(const Viewport& vp) = 0;
+		virtual void setViewport(const Viewport* vp) = 0;
 		/** Get the current active viewport for rendering. */
-		virtual Viewport getViewport(void);
+		virtual const Viewport* getViewport(void);
 
 		/** Sets the current vertex buffer for the specified source index.   
 		/** @note Set buffer to nullptr to clear the buffer at the specified index.*/
@@ -387,7 +387,7 @@ namespace CamelotEngine
 		RenderTarget* mActiveRenderTarget;
 
 		// Active viewport (dest for future rendering operations)
-		Viewport mActiveViewport;
+		const Viewport* mActiveViewport;
 
 		CullingMode mCullingMode;
 

+ 1 - 1
CamelotRenderer/Include/CmRenderWindowManager.h

@@ -14,6 +14,6 @@ namespace CamelotEngine
 		RenderWindowPtr create(const RENDER_WINDOW_DESC& desc);
 
 	protected:
-		virtual RenderWindowPtr createImpl(const RENDER_WINDOW_DESC& desc) = 0;
+		virtual RenderWindow* createImpl(const RENDER_WINDOW_DESC& desc) = 0;
 	};
 }

+ 4 - 48
CamelotRenderer/Include/CmTextureManager.h

@@ -57,10 +57,6 @@ namespace CamelotEngine {
      */
     class CM_EXPORT TextureManager : public Module<TextureManager>
     {
-	protected:
-		virtual TexturePtr createTextureImpl() = 0;
-		virtual RenderTexturePtr createRenderTextureImpl() = 0;
-		virtual MultiRenderTexturePtr createMultiRenderTextureImpl() = 0;
     public:
 
         TextureManager(void);
@@ -217,50 +213,10 @@ namespace CamelotEngine {
 		*/
 		virtual PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage) = 0;
 
-        /** Returns whether this render system has hardware filtering supported for the
-            texture format requested with the given usage options.
-        @remarks
-            Not all texture format are supports filtering by the hardware, i.e. some
-            cards support floating point format, but it doesn't supports filtering on
-            the floating point texture at all, or only a subset floating point formats
-            have flitering supported.
-        @par
-            In the case you want to write shader to work with floating point texture, and
-            you want to produce better visual quality, it's necessary to flitering the
-            texture manually in shader (potential requires four or more texture fetch
-            instructions, plus several arithmetic instructions) if filtering doesn't
-            supported by hardware. But in case on the hardware that supports floating
-            point filtering natively, it had better to adopt this capability for
-            performance (because only one texture fetch instruction are required) and
-            doesn't loss visual quality.
-        @par
-            This method allow you queries hardware texture filtering capability to deciding
-            which verion of the shader to be used. Note it's up to you to write multi-version
-            shaders for support various hardware, internal engine can't do that for you
-            automatically.
-        @note
-            Under GL, texture filtering are always supported by driver, but if it's not
-            supported by hardware natively, software simulation will be used, and you
-            will end up with very slow speed (less than 0.1 fps for example). To slove
-            this performance problem, you must disable filtering manually (by use
-            <b>filtering none</b> in the material script's texture_unit section, or
-            call TextureUnitState::setTextureFiltering with TFO_NONE if populate
-            material in code).
-		@param ttype The texture type requested
-		@param format The pixel format requested
-		@param usage The kind of usage this texture is intended for, a combination of 
-			the TextureUsage flags.
-        @param preciseFormatOnly Whether precise or fallback format mode is used to detecting.
-            In case the pixel format doesn't supported by device, false will be returned
-            if in precise mode, and natively used pixel format will be actually use to
-            check if in fallback mode.
-		@returns true if the texture filtering is supported.
-        */
-        virtual bool isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage,
-            bool preciseFormatOnly = false) = 0;
-
-    protected:
-
+	protected:
+		virtual Texture* createTextureImpl() = 0;
+		virtual RenderTexture* createRenderTextureImpl() = 0;
+		virtual MultiRenderTexture* createMultiRenderTextureImpl() = 0;
     };
 	/** @} */
 	/** @} */

+ 0 - 1
CamelotRenderer/Source/CmApplication.cpp

@@ -147,7 +147,6 @@ namespace CamelotEngine
 
 	void Application::shutDown()
 	{
-		mPrimaryRenderWindow->destroy();
 		mPrimaryRenderWindow = nullptr;
 
 		Importer::shutDown();

+ 33 - 8
CamelotRenderer/Source/CmCoreGpuObject.cpp

@@ -9,14 +9,14 @@ namespace CamelotEngine
 	CM_STATIC_MUTEX_CLASS_INSTANCE(mCoreGpuObjectLoadedMutex, CoreGpuObject)
 
 	CoreGpuObject::CoreGpuObject()
-		: mIsInitialized(false), mInternalID(0)
+		: mFlags(0), mInternalID(0)
 	{
 		mInternalID = CoreGpuObjectManager::instance().registerObject(this);
 	}
 
 	CoreGpuObject::~CoreGpuObject() 
 	{
-		if(mIsInitialized)
+		if(isInitialized())
 		{
 			// Object must be released with destroy() otherwise engine can still try to use it, even if it was destructed
 			// (e.g. if an object has one of its methods queued in a command queue, and is destructed, you will be accessing invalid memory)
@@ -43,14 +43,14 @@ namespace CamelotEngine
 	void CoreGpuObject::destroy_internal()
 	{
 #if CM_DEBUG_MODE
-		if(!mIsInitialized)
+		if(!isInitialized())
 		{
 			CoreGpuObjectManager::instance().unregisterObjectToDestroy(mThis.lock());
 			CM_EXCEPT(InternalErrorException, "Trying to destroy an object that is already destroyed (or it never was initialized).");
 		}
 #endif
 
-		mIsInitialized = false;
+		setIsInitialized(false);
 
 		CoreGpuObjectManager::instance().unregisterObjectToDestroy(mThis.lock());
 	}
@@ -58,7 +58,7 @@ namespace CamelotEngine
 	void CoreGpuObject::initialize()
 	{
 #if CM_DEBUG_MODE
-		if(mIsInitialized)
+		if(isInitialized())
 			CM_EXCEPT(InternalErrorException, "Trying to initialize an object that is already initialized");
 #endif
 
@@ -69,7 +69,7 @@ namespace CamelotEngine
 	{
 		{
 			CM_LOCK_MUTEX(mCoreGpuObjectLoadedMutex);
-			mIsInitialized = true;
+			setIsInitialized(true);
 		}	
 
 		CM_THREAD_NOTIFY_ALL(mCoreGpuObjectLoadedCondition);
@@ -82,10 +82,10 @@ namespace CamelotEngine
 			CM_EXCEPT(InternalErrorException, "You cannot call this method on the render thread. It will cause a deadlock!");
 #endif
 
-		if(!mIsInitialized)
+		if(!isInitialized())
 		{
 			CM_LOCK_MUTEX_NAMED(mCoreGpuObjectLoadedMutex, lock);
-			while(!mIsInitialized)
+			while(!isInitialized())
 			{
 				CM_THREAD_WAIT(mCoreGpuObjectLoadedCondition, mCoreGpuObjectLoadedMutex, lock);
 			}
@@ -96,4 +96,29 @@ namespace CamelotEngine
 	{
 		mThis = ptrThis;
 	}
+
+	void CoreGpuObject::_deleteDelayed(CoreGpuObject* obj)
+	{
+		assert(obj != nullptr);
+
+		// This method usually gets called automatically by the shared pointer when all references are released. The process:
+		// - If the deletion flag is set or object was never initialized then we immediately delete the object
+		// - Otherwise:
+		//  - We re-create the reference to the object by setting mThis pointer
+		//  - We queue the object to be destroyed so all of its GPU resources may be released on the render thread
+		//    - destroy() makes sure it keeps a reference of mThis so object isn't deleted
+		//    - Once the destroy() finishes the reference is removed and delete is called again, but this time deletion flag is set
+
+		if(obj->isScheduledToBeDeleted() || !obj->isInitialized())
+		{
+			delete obj;
+		}
+		else
+		{
+			std::shared_ptr<CoreGpuObject> thisPtr(obj);
+			obj->setThisPtr(thisPtr);
+			obj->setScheduledToBeDeleted(true);
+			obj->destroy();
+		}
+	}
 }

+ 1 - 1
CamelotRenderer/Source/CmDeferredRenderContext.cpp

@@ -26,7 +26,7 @@ namespace CamelotEngine
 		mCommandQueue->queue(boost::bind(&RenderSystem::swapAllRenderTargetBuffers, mRenderSystem, waitForVSync));
 	}
 
-	void DeferredRenderContext::setViewport(const Viewport& vp)
+	void DeferredRenderContext::setViewport(const Viewport* vp)
 	{
 		mCommandQueue->queue(boost::bind(&RenderSystem::setViewport, mRenderSystem, vp));
 	}

+ 1 - 2
CamelotRenderer/Source/CmGpuProgramManager.cpp

@@ -26,7 +26,6 @@ THE SOFTWARE.
 -----------------------------------------------------------------------------
 */
 #include "CmGpuProgramManager.h"
-//#include "CmHighLevelGpuProgramManager.h"
 #include "CmRenderSystem.h"
 
 
@@ -44,7 +43,7 @@ namespace CamelotEngine {
     //---------------------------------------------------------------------------
 	GpuProgramPtr GpuProgramManager::createProgram(const String& source, const String& entryPoint, const String& language, GpuProgramType gptype, GpuProgramProfile profile)
     {
-		GpuProgramPtr prg = GpuProgramPtr(create(source, entryPoint, language, gptype, profile));
+		GpuProgramPtr prg = GpuProgramPtr(create(source, entryPoint, language, gptype, profile), &CoreGpuObject::_deleteDelayed);
 		prg->setThisPtr(prg);
 
 		// TODO: Gpu programs get initialized by their parent HighLevelGpuProgram. I might handle that more intuitively later but

+ 11 - 10
CamelotRenderer/Source/CmHardwareBufferManager.cpp

@@ -44,22 +44,17 @@ namespace CamelotEngine {
     //-----------------------------------------------------------------------
     VertexDeclarationPtr HardwareBufferManager::createVertexDeclaration(void)
     {
-        VertexDeclarationPtr decl = createVertexDeclarationImpl();
+        VertexDeclarationPtr decl = VertexDeclarationPtr(createVertexDeclarationImpl(), &CoreGpuObject::_deleteDelayed);
 		decl->setThisPtr(decl);
 		decl->initialize();
         return decl;
-    }
-    //-----------------------------------------------------------------------
-    VertexDeclarationPtr HardwareBufferManager::createVertexDeclarationImpl(void)
-    {
-		return VertexDeclarationPtr(new VertexDeclaration());
     }
 	//-----------------------------------------------------------------------
 	VertexBufferPtr HardwareBufferManager::createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
 	{
 		assert (numVerts > 0);
 
-		VertexBufferPtr vbuf = createVertexBufferImpl(vertexSize, numVerts, usage, streamOut);
+		VertexBufferPtr vbuf = VertexBufferPtr(createVertexBufferImpl(vertexSize, numVerts, usage, streamOut), &CoreGpuObject::_deleteDelayed);
 		vbuf->setThisPtr(vbuf);
 		vbuf->initialize();
 		return vbuf;
@@ -69,7 +64,7 @@ namespace CamelotEngine {
 	{
 		assert (numIndexes > 0);
 
-		IndexBufferPtr ibuf = createIndexBufferImpl(itype, numIndexes, usage);
+		IndexBufferPtr ibuf = IndexBufferPtr(createIndexBufferImpl(itype, numIndexes, usage), &CoreGpuObject::_deleteDelayed);
 		ibuf->setThisPtr(ibuf);
 		ibuf->initialize();
 		return ibuf;
@@ -78,15 +73,21 @@ namespace CamelotEngine {
 	//-----------------------------------------------------------------------
 	GpuParamBlockPtr HardwareBufferManager::createGpuParamBlock(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage)
 	{
-		return createGpuParamBlockImpl(paramDesc, usage);
+		return GpuParamBlockPtr(createGpuParamBlockImpl(paramDesc, usage));
 	}
 	//-----------------------------------------------------------------------
 	GpuBufferPtr HardwareBufferManager::createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
 		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
 	{
-		GpuBufferPtr gbuf = createGpuBufferImpl(elementCount, elementSize, type, usage, randomGpuWrite, useCounter);
+		GpuBufferPtr gbuf = GpuBufferPtr(createGpuBufferImpl(elementCount, elementSize, type, 
+			usage, randomGpuWrite, useCounter), &CoreGpuObject::_deleteDelayed);
 		gbuf->setThisPtr(gbuf);
 		gbuf->initialize();
 		return gbuf;
 	}
+	//-----------------------------------------------------------------------
+	VertexDeclaration* HardwareBufferManager::createVertexDeclarationImpl(void)
+	{
+		return new VertexDeclaration();
+	}
 }

+ 1 - 5
CamelotRenderer/Source/CmHighLevelGpuProgram.cpp

@@ -69,11 +69,7 @@ namespace CamelotEngine
     //---------------------------------------------------------------------------
     void HighLevelGpuProgram::destroy_internal()
     {   
-        if (mAssemblerProgram != nullptr && mAssemblerProgram.get() != this)
-        {
-			mAssemblerProgram->destroy();
-            mAssemblerProgram = nullptr;
-        }
+        mAssemblerProgram = nullptr;
 
 		GpuProgram::destroy_internal();
     }

+ 3 - 3
CamelotRenderer/Source/CmHighLevelGpuProgramManager.cpp

@@ -145,7 +145,7 @@ namespace CamelotEngine {
 		GpuProgramType gptype, GpuProgramProfile profile)
     {
 		HighLevelGpuProgramFactory* factory = getFactory(language);
-        HighLevelGpuProgramPtr ret = HighLevelGpuProgramPtr(factory->create(source, entryPoint, gptype, profile));
+        HighLevelGpuProgramPtr ret = HighLevelGpuProgramPtr(factory->create(source, entryPoint, gptype, profile), &CoreGpuObject::_deleteDelayed);
 		ret->setThisPtr(ret);
 		ret->initialize();
 
@@ -155,7 +155,7 @@ namespace CamelotEngine {
 	HighLevelGpuProgramPtr HighLevelGpuProgramManager::create(const String& language)
 	{
 		HighLevelGpuProgramFactory* factory = getFactory(language);
-		HighLevelGpuProgramPtr ret = HighLevelGpuProgramPtr(factory->create());
+		HighLevelGpuProgramPtr ret = HighLevelGpuProgramPtr(factory->create(), &CoreGpuObject::_deleteDelayed);
 		ret->setThisPtr(ret);
 		ret->initialize();
 
@@ -165,7 +165,7 @@ namespace CamelotEngine {
 	HighLevelGpuProgramPtr HighLevelGpuProgramManager::createEmpty(const String& language)
 	{
 		HighLevelGpuProgramFactory* factory = getFactory(language);
-		HighLevelGpuProgramPtr ret = HighLevelGpuProgramPtr(factory->create());
+		HighLevelGpuProgramPtr ret = HighLevelGpuProgramPtr(factory->create(), &CoreGpuObject::_deleteDelayed);
 		ret->setThisPtr(ret);
 
 		return ret;

+ 1 - 1
CamelotRenderer/Source/CmMaterial.cpp

@@ -819,7 +819,7 @@ namespace CamelotEngine
 
 	MaterialPtr Material::create()
 	{
-		MaterialPtr newMat(new Material());
+		MaterialPtr newMat(new Material(), &CoreGpuObject::_deleteDelayed);
 		newMat->setThisPtr(newMat);
 		newMat->initialize();
 

+ 0 - 35
CamelotRenderer/Source/CmMesh.cpp

@@ -44,25 +44,10 @@ namespace CamelotEngine
 		mSubMeshes.clear();
 
 		if(mVertexData != nullptr)
-		{
-			for(UINT32 i = 0; i < mVertexData->getBufferCount(); i++)
-			{
-				VertexBufferPtr buffer = mVertexData->getBuffer(i);
-
-				if(buffer != nullptr)
-					buffer->destroy();
-			}
-
 			delete mVertexData;
-		}
 
 		if(mIndexData != nullptr)
-		{
-			if(mIndexData->indexBuffer != nullptr)
-				mIndexData->indexBuffer->destroy();
-
 			delete mIndexData;
-		}
 
 		// Submeshes
 		for(UINT32 i = 0; i < meshData->subMeshes.size(); i++)
@@ -90,10 +75,6 @@ namespace CamelotEngine
 		mVertexData = new VertexData();
 
 		mVertexData->vertexCount = meshData->vertexCount;
-
-		if(mVertexData->vertexDeclaration != nullptr)
-			mVertexData->vertexDeclaration->destroy();
-
 		mVertexData->vertexDeclaration = meshData->declaration->clone();
 
 		for(auto iter = meshData->vertexBuffers.begin(); iter != meshData->vertexBuffers.end(); ++iter)
@@ -195,7 +176,6 @@ namespace CamelotEngine
 	{
 		MeshDataPtr meshData(new MeshData());
 
-		meshData->declaration->destroy();
 		meshData->declaration = mVertexData->vertexDeclaration->clone();
 		
 		for(UINT32 i = 0; i < mSubMeshes.size(); i++)
@@ -339,25 +319,10 @@ namespace CamelotEngine
 		THROW_IF_NOT_RENDER_THREAD;
 
 		if(mVertexData != nullptr)
-		{
-			for(UINT32 i = 0; i < mVertexData->getBufferCount(); i++)
-			{
-				VertexBufferPtr buffer = mVertexData->getBuffer(i);
-
-				if(buffer != nullptr)
-					buffer->destroy();
-			}
-
 			delete mVertexData;
-		}
 
 		if(mIndexData != nullptr)
-		{
-			if(mIndexData->indexBuffer != nullptr)
-				mIndexData->indexBuffer->destroy();
-
 			delete mIndexData;
-		}
 
 		Resource::destroy_internal();
 	}

+ 0 - 2
CamelotRenderer/Source/CmMeshData.cpp

@@ -61,8 +61,6 @@ namespace CamelotEngine
 			delete [] index;
 
 		vertexBuffers.clear();
-
-		declaration->destroy();
 	}
 
 	/************************************************************************/

+ 1 - 1
CamelotRenderer/Source/CmMeshManager.cpp

@@ -36,7 +36,7 @@ namespace CamelotEngine
 
 	MeshPtr MeshManager::create()
 	{
-		MeshPtr mesh = MeshPtr(new Mesh());
+		MeshPtr mesh = MeshPtr(new Mesh(), &CoreGpuObject::_deleteDelayed);
 		mesh->setThisPtr(mesh);
 		mesh->initialize();
 

+ 28 - 23
CamelotRenderer/Source/CmRenderStateManager.cpp

@@ -6,24 +6,9 @@
 
 namespace CamelotEngine
 {
-	RenderStateManager::~RenderStateManager()
-	{
-		if(mDefaultSamplerState != nullptr)
-			mDefaultSamplerState->destroy();
-
-		if(mDefaultBlendState != nullptr)
-			mDefaultBlendState->destroy();
-
-		if(mDefaultRasterizerState != nullptr)
-			mDefaultRasterizerState->destroy();
-
-		if(mDefaultDepthStencilState != nullptr)
-			mDefaultDepthStencilState->destroy();
-	}
-
 	SamplerStatePtr RenderStateManager::createSamplerState(const SAMPLER_STATE_DESC& desc) const
 	{
-		SamplerStatePtr samplerState = SamplerStatePtr(new SamplerState());
+		SamplerStatePtr samplerState = SamplerStatePtr(createSamplerStateImpl(), &CoreGpuObject::_deleteDelayed);
 		samplerState->setThisPtr(samplerState);
 		samplerState->initialize(desc);
 
@@ -32,7 +17,7 @@ namespace CamelotEngine
 
 	DepthStencilStatePtr RenderStateManager::createDepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc) const
 	{
-		DepthStencilStatePtr depthStencilState = DepthStencilStatePtr(new DepthStencilState());
+		DepthStencilStatePtr depthStencilState = DepthStencilStatePtr(createDepthStencilStateImpl(), &CoreGpuObject::_deleteDelayed);
 		depthStencilState->setThisPtr(depthStencilState);
 		depthStencilState->initialize(desc);
 
@@ -41,7 +26,7 @@ namespace CamelotEngine
 
 	RasterizerStatePtr RenderStateManager::createRasterizerState(const RASTERIZER_STATE_DESC& desc) const
 	{
-		RasterizerStatePtr rasterizerState = RasterizerStatePtr(new RasterizerState());
+		RasterizerStatePtr rasterizerState = RasterizerStatePtr(createRasterizerStateImpl(), &CoreGpuObject::_deleteDelayed);
 		rasterizerState->setThisPtr(rasterizerState);
 		rasterizerState->initialize(desc);
 
@@ -50,7 +35,7 @@ namespace CamelotEngine
 
 	BlendStatePtr RenderStateManager::createBlendState(const BLEND_STATE_DESC& desc) const
 	{
-		BlendStatePtr blendState = BlendStatePtr(new BlendState());
+		BlendStatePtr blendState = BlendStatePtr(createBlendStateImpl(), &CoreGpuObject::_deleteDelayed);
 		blendState->setThisPtr(blendState);
 		blendState->initialize(desc);
 
@@ -59,7 +44,7 @@ namespace CamelotEngine
 
 	SamplerStatePtr RenderStateManager::createEmptySamplerState() const
 	{
-		SamplerStatePtr samplerState = SamplerStatePtr(new SamplerState());
+		SamplerStatePtr samplerState = SamplerStatePtr(createSamplerStateImpl(), &CoreGpuObject::_deleteDelayed);
 		samplerState->setThisPtr(samplerState);
 
 		return samplerState;
@@ -67,7 +52,7 @@ namespace CamelotEngine
 
 	DepthStencilStatePtr RenderStateManager::createEmptyDepthStencilState() const
 	{
-		DepthStencilStatePtr depthStencilState = DepthStencilStatePtr(new DepthStencilState());
+		DepthStencilStatePtr depthStencilState = DepthStencilStatePtr(createDepthStencilStateImpl(), &CoreGpuObject::_deleteDelayed);
 		depthStencilState->setThisPtr(depthStencilState);
 
 		return depthStencilState;
@@ -75,7 +60,7 @@ namespace CamelotEngine
 
 	RasterizerStatePtr RenderStateManager::createEmptyRasterizerState() const
 	{
-		RasterizerStatePtr rasterizerState = RasterizerStatePtr(new RasterizerState());
+		RasterizerStatePtr rasterizerState = RasterizerStatePtr(createRasterizerStateImpl(), &CoreGpuObject::_deleteDelayed);
 		rasterizerState->setThisPtr(rasterizerState);
 
 		return rasterizerState;
@@ -83,7 +68,7 @@ namespace CamelotEngine
 
 	BlendStatePtr RenderStateManager::createEmptyBlendState() const
 	{
-		BlendStatePtr blendState = BlendStatePtr(new BlendState());
+		BlendStatePtr blendState = BlendStatePtr(createBlendStateImpl(), &CoreGpuObject::_deleteDelayed);
 		blendState->setThisPtr(blendState);
 
 		return blendState;
@@ -120,4 +105,24 @@ namespace CamelotEngine
 
 		return mDefaultDepthStencilState; 
 	}
+
+	SamplerState* RenderStateManager::createSamplerStateImpl() const
+	{
+		return new SamplerState();
+	}
+
+	BlendState* RenderStateManager::createBlendStateImpl() const
+	{
+		return new BlendState();
+	}
+
+	RasterizerState* RenderStateManager::createRasterizerStateImpl() const
+	{
+		return new RasterizerState();
+	}
+
+	DepthStencilState* RenderStateManager::createDepthStencilStateImpl() const
+	{
+		return new DepthStencilState();
+	}
 }

+ 3 - 2
CamelotRenderer/Source/CmRenderSystem.cpp

@@ -55,7 +55,7 @@ namespace CamelotEngine {
 
     //-----------------------------------------------------------------------
     RenderSystem::RenderSystem()
-        : mActiveRenderTarget(0)
+        : mActiveRenderTarget(nullptr)
         , mCullingMode(CULL_CLOCKWISE)
 		, mVsync(false)
 		, mVSyncInterval(1)
@@ -70,6 +70,7 @@ namespace CamelotEngine {
 		, mRenderThreadShutdown(false)
 		, mCommandQueue(nullptr)
 		, mMaxCommandNotifyId(0)
+		, mActiveViewport(nullptr)
     {
     }
 
@@ -209,7 +210,7 @@ namespace CamelotEngine {
 		return mDriverVersion; 
 	}
     //-----------------------------------------------------------------------
-    Viewport RenderSystem::getViewport(void)
+    const Viewport* RenderSystem::getViewport(void)
     {
 		THROW_IF_NOT_RENDER_THREAD;
 

+ 1 - 1
CamelotRenderer/Source/CmRenderWindowManager.cpp

@@ -4,7 +4,7 @@ namespace CamelotEngine
 {
 	RenderWindowPtr RenderWindowManager::create(const RENDER_WINDOW_DESC& desc)
 	{
-		RenderWindowPtr renderWindow = createImpl(desc);
+		RenderWindowPtr renderWindow(createImpl(desc), &CoreGpuObject::_deleteDelayed);
 		renderWindow->setThisPtr(renderWindow);
 		renderWindow->initialize();
 

+ 1 - 1
CamelotRenderer/Source/CmShader.cpp

@@ -202,7 +202,7 @@ namespace CamelotEngine
 
 	ShaderPtr Shader::create(const String& name)
 	{
-		ShaderPtr newShader(new Shader(name));
+		ShaderPtr newShader(new Shader(name), &CoreGpuObject::_deleteDelayed);
 		newShader->setThisPtr(newShader);
 		newShader->initialize();
 

+ 4 - 4
CamelotRenderer/Source/CmTextureManager.cpp

@@ -47,7 +47,7 @@ namespace CamelotEngine {
         PixelFormat format, int usage, bool hwGamma, 
 		UINT32 fsaa, const String& fsaaHint)
     {
-        TexturePtr ret = TexturePtr(createTextureImpl());
+        TexturePtr ret = TexturePtr(createTextureImpl(), &CoreGpuObject::_deleteDelayed);
 		ret->setThisPtr(ret);
 		ret->initialize(texType, width, height, depth, static_cast<size_t>(numMipmaps), format, usage, hwGamma, fsaa, fsaaHint);
 
@@ -56,7 +56,7 @@ namespace CamelotEngine {
 	//-----------------------------------------------------------------------
 	TexturePtr TextureManager::createEmpty()
 	{
-		TexturePtr texture = TexturePtr(createTextureImpl());
+		TexturePtr texture = TexturePtr(createTextureImpl(), &CoreGpuObject::_deleteDelayed);
 		texture->setThisPtr(texture);
 
 		return texture;
@@ -84,7 +84,7 @@ namespace CamelotEngine {
 	//-----------------------------------------------------------------------
 	RenderTexturePtr TextureManager::createEmptyRenderTexture()
 	{
-		RenderTexturePtr newRT = createRenderTextureImpl();
+		RenderTexturePtr newRT = RenderTexturePtr(createRenderTextureImpl(), &CoreGpuObject::_deleteDelayed);
 		newRT->setThisPtr(newRT);
 
 		return newRT;
@@ -92,7 +92,7 @@ namespace CamelotEngine {
 	//-----------------------------------------------------------------------
 	MultiRenderTexturePtr TextureManager::createEmptyMultiRenderTexture()
 	{
-		MultiRenderTexturePtr newRT = createMultiRenderTextureImpl();
+		MultiRenderTexturePtr newRT = MultiRenderTexturePtr(createMultiRenderTextureImpl(), &CoreGpuObject::_deleteDelayed);
 		newRT->setThisPtr(newRT);
 
 		return newRT;

+ 0 - 2
CamelotRenderer/Source/CmVertexData.cpp

@@ -56,8 +56,6 @@ namespace CamelotEngine
 
 	VertexData::~VertexData()
 	{
-		if(mOwnsDeclaration && (vertexDeclaration != nullptr))
-			vertexDeclaration->destroy();
 	}
 
 	void VertexData::setBuffer(UINT32 index, VertexBufferPtr buffer)

+ 5 - 6
CamelotRenderer/TODO.txt

@@ -18,17 +18,15 @@ Pass
  - GpuParams support for bools, buffers, structs
 
 GpuParamBlock - Needs to derive from CoreGpuObject and needs to be initialized better
-
-Loading meshes doesn't work
- - And setMeshData is currently always synced
-creating a resource should add it to mLoaded
-also all unload() after creating a resource, for test purposes
+ - HardwareBufferManager::createGpuParamBlock needs &CoreGpuObject::_deleteDelayed added as a deleted to shared_ptr
 
 Having ResourceHandle closely tied in with Resources creates a problem when user just wants to create a resource in memory and use it? How to do it without saving it? e.g. material setTexture
  - create() methods return a ResourceHandle.
  - However those won't be released using unload() which is confusing.
-   - should create() register the resoruce with Resources right away?
+   - creating a resource should add it to mLoaded
 
+Switching the renderer will cause exceptions for the first couple of times I run it. It happens randomly and
+ goes away after I try to run the game for a few times. Restart the PC and try again if you want to get it to happen again.
 
 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
@@ -60,6 +58,7 @@ Can be delayed:
  Test if async loading still works
  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
+ Mesh::setMeshData is currently always synced
 >>>>>>>>>>>>>>>START WORKING ON THE EDITOR!