Browse Source

CoreGpuObject

Marko Pintera 13 years ago
parent
commit
e090e96915
100 changed files with 1297 additions and 1035 deletions
  1. 77 48
      CamelotClient/CamelotClient.cpp
  2. 14 2
      CamelotD3D11RenderSystem/Include/CmD3D11GpuBuffer.h
  3. 50 23
      CamelotD3D11RenderSystem/Include/CmD3D11GpuProgram.h
  4. 13 20
      CamelotD3D11RenderSystem/Include/CmD3D11HardwareBufferManager.h
  5. 14 2
      CamelotD3D11RenderSystem/Include/CmD3D11IndexBuffer.h
  6. 0 2
      CamelotD3D11RenderSystem/Include/CmD3D11MultiRenderTexture.h
  7. 0 2
      CamelotD3D11RenderSystem/Include/CmD3D11RenderTexture.h
  8. 9 4
      CamelotD3D11RenderSystem/Include/CmD3D11RenderWindow.h
  9. 2 2
      CamelotD3D11RenderSystem/Include/CmD3D11RenderWindowManager.h
  10. 2 2
      CamelotD3D11RenderSystem/Include/CmD3D11Texture.h
  11. 3 7
      CamelotD3D11RenderSystem/Include/CmD3D11TextureManager.h
  12. 16 3
      CamelotD3D11RenderSystem/Include/CmD3D11VertexBuffer.h
  13. 21 12
      CamelotD3D11RenderSystem/Source/CmD3D11GpuBuffer.cpp
  14. 5 0
      CamelotD3D11RenderSystem/Source/CmD3D11GpuProgram.cpp
  15. 6 32
      CamelotD3D11RenderSystem/Source/CmD3D11HardwareBufferManager.cpp
  16. 16 9
      CamelotD3D11RenderSystem/Source/CmD3D11IndexBuffer.cpp
  17. 0 5
      CamelotD3D11RenderSystem/Source/CmD3D11MultiRenderTexture.cpp
  18. 0 5
      CamelotD3D11RenderSystem/Source/CmD3D11RenderTexture.cpp
  19. 52 46
      CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp
  20. 3 7
      CamelotD3D11RenderSystem/Source/CmD3D11RenderWindowManager.cpp
  21. 4 4
      CamelotD3D11RenderSystem/Source/CmD3D11Texture.cpp
  22. 6 9
      CamelotD3D11RenderSystem/Source/CmD3D11TextureManager.cpp
  23. 11 7
      CamelotD3D11RenderSystem/Source/CmD3D11VertexBuffer.cpp
  24. 8 2
      CamelotD3D9Renderer/Include/CmD3D9GpuBuffer.h
  25. 5 5
      CamelotD3D9Renderer/Include/CmD3D9GpuProgram.h
  26. 8 4
      CamelotD3D9Renderer/Include/CmD3D9HLSLProgram.h
  27. 11 13
      CamelotD3D9Renderer/Include/CmD3D9HardwareBufferManager.h
  28. 13 2
      CamelotD3D9Renderer/Include/CmD3D9IndexBuffer.h
  29. 5 3
      CamelotD3D9Renderer/Include/CmD3D9MultiRenderTexture.h
  30. 1 1
      CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h
  31. 0 1
      CamelotD3D9Renderer/Include/CmD3D9RenderTexture.h
  32. 17 13
      CamelotD3D9Renderer/Include/CmD3D9RenderWindow.h
  33. 2 2
      CamelotD3D9Renderer/Include/CmD3D9RenderWindowManager.h
  34. 2 2
      CamelotD3D9Renderer/Include/CmD3D9Texture.h
  35. 3 7
      CamelotD3D9Renderer/Include/CmD3D9TextureManager.h
  36. 13 2
      CamelotD3D9Renderer/Include/CmD3D9VertexBuffer.h
  37. 8 2
      CamelotD3D9Renderer/Include/CmD3D9VertexDeclaration.h
  38. 7 6
      CamelotD3D9Renderer/Source/CmD3D9GpuBuffer.cpp
  39. 47 50
      CamelotD3D9Renderer/Source/CmD3D9GpuProgram.cpp
  40. 8 21
      CamelotD3D9Renderer/Source/CmD3D9HardwareBufferManager.cpp
  41. 32 25
      CamelotD3D9Renderer/Source/CmD3D9IndexBuffer.cpp
  42. 2 7
      CamelotD3D9Renderer/Source/CmD3D9MultiRenderTexture.cpp
  43. 4 4
      CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp
  44. 0 5
      CamelotD3D9Renderer/Source/CmD3D9RenderTexture.cpp
  45. 63 58
      CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp
  46. 2 10
      CamelotD3D9Renderer/Source/CmD3D9RenderWindowManager.cpp
  47. 3 3
      CamelotD3D9Renderer/Source/CmD3D9Texture.cpp
  48. 6 9
      CamelotD3D9Renderer/Source/CmD3D9TextureManager.cpp
  49. 34 29
      CamelotD3D9Renderer/Source/CmD3D9VertexBuffer.cpp
  50. 7 7
      CamelotD3D9Renderer/Source/CmD3D9VertexDeclaration.cpp
  51. 8 2
      CamelotGLRenderer/Include/CmGLGpuBuffer.h
  52. 29 29
      CamelotGLRenderer/Include/CmGLHardwareBufferManager.h
  53. 13 2
      CamelotGLRenderer/Include/CmGLIndexBuffer.h
  54. 8 1
      CamelotGLRenderer/Include/CmGLMultiRenderTexture.h
  55. 4 0
      CamelotGLRenderer/Include/CmGLRenderTexture.h
  56. 2 2
      CamelotGLRenderer/Include/CmGLRenderWindowManager.h
  57. 4 15
      CamelotGLRenderer/Include/CmGLTextureManager.h
  58. 12 1
      CamelotGLRenderer/Include/CmGLVertexBuffer.h
  59. 13 2
      CamelotGLRenderer/Include/CmWin32Window.h
  60. 7 6
      CamelotGLRenderer/Source/CmGLGpuBuffer.cpp
  61. 6 16
      CamelotGLRenderer/Source/CmGLHardwareBufferManager.cpp
  62. 24 21
      CamelotGLRenderer/Source/CmGLIndexBuffer.cpp
  63. 10 10
      CamelotGLRenderer/Source/CmGLMultiRenderTexture.cpp
  64. 2 7
      CamelotGLRenderer/Source/CmGLRenderWindowManager.cpp
  65. 3 3
      CamelotGLRenderer/Source/CmGLTexture.cpp
  66. 6 9
      CamelotGLRenderer/Source/CmGLTextureManager.cpp
  67. 19 15
      CamelotGLRenderer/Source/CmGLVertexBuffer.cpp
  68. 31 27
      CamelotGLRenderer/Source/CmWin32GLSupport.cpp
  69. 94 84
      CamelotGLRenderer/Source/CmWin32Window.cpp
  70. 0 10
      CamelotGLRenderer/Source/GLSL/include/CmGLSLGpuProgram.h
  71. 2 2
      CamelotGLRenderer/Source/GLSL/include/CmGLSLProgram.h
  72. 0 12
      CamelotGLRenderer/Source/GLSL/src/CmGLSLGpuProgram.cpp
  73. 6 1
      CamelotGLRenderer/Source/GLSL/src/CmGLSLProgram.cpp
  74. 2 0
      CamelotRenderer/CamelotRenderer.vcxproj
  75. 6 0
      CamelotRenderer/CamelotRenderer.vcxproj.filters
  76. 52 2
      CamelotRenderer/Include/CmCoreGpuObject.h
  77. 34 0
      CamelotRenderer/Include/CmCoreGpuObjectManager.h
  78. 9 7
      CamelotRenderer/Include/CmGpuBuffer.h
  79. 15 36
      CamelotRenderer/Include/CmGpuProgram.h
  80. 11 22
      CamelotRenderer/Include/CmHardwareBufferManager.h
  81. 8 4
      CamelotRenderer/Include/CmHighLevelGpuProgram.h
  82. 1 7
      CamelotRenderer/Include/CmIndexBuffer.h
  83. 5 3
      CamelotRenderer/Include/CmMesh.h
  84. 0 1
      CamelotRenderer/Include/CmMultiRenderTexture.h
  85. 1 0
      CamelotRenderer/Include/CmPrerequisites.h
  86. 2 6
      CamelotRenderer/Include/CmRenderTarget.h
  87. 4 3
      CamelotRenderer/Include/CmRenderTexture.h
  88. 11 17
      CamelotRenderer/Include/CmRenderWindow.h
  89. 1 10
      CamelotRenderer/Include/CmRenderWindowManager.h
  90. 0 34
      CamelotRenderer/Include/CmResource.h
  91. 9 0
      CamelotRenderer/Include/CmResourceHandle.h
  92. 4 4
      CamelotRenderer/Include/CmTextureManager.h
  93. 1 7
      CamelotRenderer/Include/CmVertexBuffer.h
  94. 6 8
      CamelotRenderer/Include/CmVertexDeclaration.h
  95. 10 3
      CamelotRenderer/Source/CmApplication.cpp
  96. 62 4
      CamelotRenderer/Source/CmCoreGpuObject.cpp
  97. 67 0
      CamelotRenderer/Source/CmCoreGpuObjectManager.cpp
  98. 0 16
      CamelotRenderer/Source/CmGpuProgram.cpp
  99. 5 0
      CamelotRenderer/Source/CmGpuProgramManager.cpp
  100. 33 18
      CamelotRenderer/Source/CmHardwareBufferManager.cpp

+ 77 - 48
CamelotClient/CamelotClient.cpp

@@ -32,8 +32,8 @@ int CALLBACK WinMain(
 	_In_  int nCmdShow
 	_In_  int nCmdShow
 	)
 	)
 {
 {
-	//gApplication().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer");
-	gApplication().startUp("CamelotD3D9RenderSystem", "CamelotForwardRenderer");
+	gApplication().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer");
+	//gApplication().startUp("CamelotD3D9RenderSystem", "CamelotForwardRenderer");
 	//gApplication().startUp("CamelotD3D11RenderSystem", "CamelotForwardRenderer");
 	//gApplication().startUp("CamelotD3D11RenderSystem", "CamelotForwardRenderer");
 
 
 	RenderSystem* renderSystem = RenderSystem::instancePtr();
 	RenderSystem* renderSystem = RenderSystem::instancePtr();
@@ -57,27 +57,27 @@ int CALLBACK WinMain(
 	HighLevelGpuProgramPtr vertProg;
 	HighLevelGpuProgramPtr vertProg;
 
 
 	/////////////////// HLSL 9 SHADERS //////////////////////////
 	/////////////////// HLSL 9 SHADERS //////////////////////////
-	String fragShaderCode = "sampler2D tex;			\
-							float4 ps_main(float2 uv : TEXCOORD0) : COLOR0		\
-							{														\
-							float4 color = tex2D(tex, uv);				\
-							return color;										\
-							}";
-
-	fragProg =  HighLevelGpuProgram::create(fragShaderCode, "ps_main", "hlsl", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
-
-	String vertShaderCode = "float4x4 matViewProjection;	\
-							void vs_main(										\
-							float4 inPos : POSITION,							\
-							float2 uv : TEXCOORD0,								\
-							out float4 oPosition : POSITION,					\
-							out float2 oUv : TEXCOORD0)							\
-							{														\
-							oPosition = mul(matViewProjection, inPos);			\
-							oUv = uv;											\
-							}";
-
-	vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "hlsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
+	//String fragShaderCode = "sampler2D tex;			\
+	//						float4 ps_main(float2 uv : TEXCOORD0) : COLOR0		\
+	//						{														\
+	//						float4 color = tex2D(tex, uv);				\
+	//						return color;										\
+	//						}";
+
+	//fragProg =  HighLevelGpuProgram::create(fragShaderCode, "ps_main", "hlsl", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
+
+	//String vertShaderCode = "float4x4 matViewProjection;	\
+	//						void vs_main(										\
+	//						float4 inPos : POSITION,							\
+	//						float2 uv : TEXCOORD0,								\
+	//						out float4 oPosition : POSITION,					\
+	//						out float2 oUv : TEXCOORD0)							\
+	//						{														\
+	//						oPosition = mul(matViewProjection, inPos);			\
+	//						oUv = uv;											\
+	//						}";
+
+	//vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "hlsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 
 
 	/////////////////// HLSL 11 SHADERS //////////////////////////
 	/////////////////// HLSL 11 SHADERS //////////////////////////
 	//String fragShaderCode = "SamplerState samp : register(s0);			\
 	//String fragShaderCode = "SamplerState samp : register(s0);			\
@@ -127,31 +127,31 @@ int CALLBACK WinMain(
 	//vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "cg", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 	//vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "cg", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 
 
 	///////////////// GLSL SHADERS ////////////////////////////
 	///////////////// 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(vertProg);
 	HighLevelGpuProgramHandle vertProgRef(vertProg);
 
 
@@ -221,6 +221,35 @@ int CALLBACK WinMain(
 
 
 	gApplication().runMainLoop();
 	gApplication().runMainLoop();
 
 
+	// Release everything before shutdown
+	//testMaterial->destroy();
+	testMaterial.reset();
+
+	testTex->destroy();
+	testTex.reset(); // TODO - Maybe instead of reset() override assignment so I can just do testTex = nullptr;
+
+	dbgMesh->destroy();
+	dbgMesh.reset();
+
+	fragProgRef->destroy();
+	fragProgRef.reset();
+	fragProg = nullptr;
+
+	vertProgRef->destroy();
+	vertProgRef.reset();
+	vertProg = nullptr;
+
+	newPassGL = nullptr;
+	newTechniqueGL = nullptr;
+
+	newPassDX = nullptr;
+	newTechniqueDX = nullptr;
+
+	newPassDX11 = nullptr;
+	newTechniqueDX11 = nullptr;
+
+	testShader = nullptr;
+
 	gApplication().shutDown();
 	gApplication().shutDown();
 
 
 	return 0;
 	return 0;

+ 14 - 2
CamelotD3D11RenderSystem/Include/CmD3D11GpuBuffer.h

@@ -9,7 +9,6 @@ namespace CamelotEngine
 	class CM_D3D11_EXPORT D3D11GpuBuffer : public GpuBuffer
 	class CM_D3D11_EXPORT D3D11GpuBuffer : public GpuBuffer
     {
     {
     public:
     public:
-		D3D11GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
         ~D3D11GpuBuffer();
         ~D3D11GpuBuffer();
 
 
 		/**
 		/**
@@ -42,11 +41,24 @@ namespace CamelotEngine
 		ID3D11Buffer* getDX11Buffer() const;
 		ID3D11Buffer* getDX11Buffer() const;
 
 
 	protected:
 	protected:
-		D3D11HardwareBuffer* mBuffer;
+		friend class D3D11HardwareBufferManager;
+
+		D3D11GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
 
 
 		virtual GpuBufferView* createView();
 		virtual GpuBufferView* createView();
 		virtual void destroyView(GpuBufferView* view);
 		virtual void destroyView(GpuBufferView* view);
 
 
+		/**
+		 * @copydoc GpuBuffer::initialize_internal()
+		 */
+		void initialize_internal();	
+		
+		/**
+		 * @copydoc GpuBuffer::destroy_internal()
+		 */
 		void destroy_internal();
 		void destroy_internal();
+
+	private:
+		D3D11HardwareBuffer* mBuffer;
     };
     };
 }
 }

+ 50 - 23
CamelotD3D11RenderSystem/Include/CmD3D11GpuProgram.h

@@ -8,9 +8,11 @@ namespace CamelotEngine
 	class CM_D3D11_EXPORT D3D11GpuProgram : public GpuProgram
 	class CM_D3D11_EXPORT D3D11GpuProgram : public GpuProgram
 	{
 	{
 	public:
 	public:
-		D3D11GpuProgram(GpuProgramType type, const String& profile);
+		virtual ~D3D11GpuProgram();
 
 
 	protected:
 	protected:
+		D3D11GpuProgram(GpuProgramType type, const String& profile);
+
 		/**
 		/**
 		 * @brief	Loads shader from microcode.
 		 * @brief	Loads shader from microcode.
 		 */
 		 */
@@ -19,103 +21,128 @@ namespace CamelotEngine
 
 
 	class CM_D3D11_EXPORT D3D11GpuVertexProgram : public D3D11GpuProgram
 	class CM_D3D11_EXPORT D3D11GpuVertexProgram : public D3D11GpuProgram
 	{
 	{
-	protected:
-		ID3D11VertexShader* mVertexShader;
 	public:
 	public:
-		D3D11GpuVertexProgram(const String& profile);
 		~D3D11GpuVertexProgram();
 		~D3D11GpuVertexProgram();
 
 
 		ID3D11VertexShader* getVertexShader(void) const;
 		ID3D11VertexShader* getVertexShader(void) const;
 		void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
 		void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
 	protected:
 	protected:
+		friend class D3D11GpuProgramManager;
+
+		D3D11GpuVertexProgram(const String& profile);
+
 		/**
 		/**
 		 * @copydoc GpuProgram::destroy_internal().
 		 * @copydoc GpuProgram::destroy_internal().
 		 */
 		 */
 		void destroy_internal();
 		void destroy_internal();
+
+	protected:
+		ID3D11VertexShader* mVertexShader;
 	};
 	};
 
 
 	class CM_D3D11_EXPORT D3D11GpuFragmentProgram : public D3D11GpuProgram
 	class CM_D3D11_EXPORT D3D11GpuFragmentProgram : public D3D11GpuProgram
 	{
 	{
-	protected:
-		ID3D11PixelShader* mPixelShader;
 	public:
 	public:
-		D3D11GpuFragmentProgram(const String& profile);
 		~D3D11GpuFragmentProgram();
 		~D3D11GpuFragmentProgram();
 
 
 		ID3D11PixelShader* getPixelShader(void) const;
 		ID3D11PixelShader* getPixelShader(void) const;
 		void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
 		void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
 	protected:
 	protected:
+		friend class D3D11GpuProgramManager;
+
+		D3D11GpuFragmentProgram(const String& profile);
+
 		/**
 		/**
 		 * @copydoc GpuProgram::destroy_internal().
 		 * @copydoc GpuProgram::destroy_internal().
 		 */
 		 */
 		void destroy_internal();
 		void destroy_internal();
+	protected:
+		ID3D11PixelShader* mPixelShader;
 	};
 	};
 
 
-	class D3D11GpuDomainProgram : public D3D11GpuProgram
+	class CM_D3D11_EXPORT D3D11GpuDomainProgram : public D3D11GpuProgram
 	{
 	{
-	protected:
-		ID3D11DomainShader* mDomainShader;
 	public:
 	public:
-		D3D11GpuDomainProgram(const String& profile);
 		~D3D11GpuDomainProgram();
 		~D3D11GpuDomainProgram();
 
 
 		ID3D11DomainShader* getDomainShader(void) const;
 		ID3D11DomainShader* getDomainShader(void) const;
 		void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
 		void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
 	protected:
 	protected:
+		friend class D3D11GpuProgramManager;
+
+		D3D11GpuDomainProgram(const String& profile);
+
 		/**
 		/**
 		 * @copydoc GpuProgram::destroy_internal().
 		 * @copydoc GpuProgram::destroy_internal().
 		 */
 		 */
 		void destroy_internal();
 		void destroy_internal();
+
+	protected:
+		ID3D11DomainShader* mDomainShader;
 	};
 	};
 
 
-	class D3D11GpuHullProgram : public D3D11GpuProgram
+	class CM_D3D11_EXPORT D3D11GpuHullProgram : public D3D11GpuProgram
 	{
 	{
-	protected:
-		ID3D11HullShader* mHullShader;
 	public:
 	public:
-		D3D11GpuHullProgram(const String& profile);
 		~D3D11GpuHullProgram();
 		~D3D11GpuHullProgram();
 
 
 		ID3D11HullShader* getHullShader() const;
 		ID3D11HullShader* getHullShader() const;
 		void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
 		void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
 	protected:
 	protected:
+		friend class D3D11GpuProgramManager;
+
+		D3D11GpuHullProgram(const String& profile);
+
 		/**
 		/**
 		 * @copydoc GpuProgram::destroy_internal().
 		 * @copydoc GpuProgram::destroy_internal().
 		 */
 		 */
 		void destroy_internal();
 		void destroy_internal();
+
+	protected:
+		ID3D11HullShader* mHullShader;
 	};
 	};
 
 
-	class D3D11GpuGeometryProgram : public D3D11GpuProgram
+	class CM_D3D11_EXPORT D3D11GpuGeometryProgram : public D3D11GpuProgram
 	{
 	{
-	protected:
-		ID3D11GeometryShader* mGeometryShader;
 	public:
 	public:
-		D3D11GpuGeometryProgram(const String& profile);
 		~D3D11GpuGeometryProgram();
 		~D3D11GpuGeometryProgram();
 
 
 		ID3D11GeometryShader* getGeometryShader(void) const;
 		ID3D11GeometryShader* getGeometryShader(void) const;
 		void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
 		void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
+
 	protected:
 	protected:
+		friend class D3D11GpuProgramManager;
+
+		D3D11GpuGeometryProgram(const String& profile);
+
 		/**
 		/**
 		 * @copydoc GpuProgram::destroy_internal().
 		 * @copydoc GpuProgram::destroy_internal().
 		 */
 		 */
 		void destroy_internal();
 		void destroy_internal();
+
+	protected:
+		ID3D11GeometryShader* mGeometryShader;
 	};
 	};
 
 
-	class D3D11GpuComputeProgram : public D3D11GpuProgram
+	class CM_D3D11_EXPORT D3D11GpuComputeProgram : public D3D11GpuProgram
 	{
 	{
-	protected:
-		ID3D11ComputeShader* mComputeShader;
 	public:
 	public:
-		D3D11GpuComputeProgram(const String& profile);
 		~D3D11GpuComputeProgram();
 		~D3D11GpuComputeProgram();
 
 
 		ID3D11ComputeShader* getComputeShader(void) const;
 		ID3D11ComputeShader* getComputeShader(void) const;
 		void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
 		void loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode);
+
 	protected:
 	protected:
+		friend class D3D11GpuProgramManager;
+
+		D3D11GpuComputeProgram(const String& profile);
+
 		/**
 		/**
 		 * @copydoc GpuProgram::destroy_internal().
 		 * @copydoc GpuProgram::destroy_internal().
 		 */
 		 */
 		void destroy_internal();
 		void destroy_internal();
+
+	protected:
+		ID3D11ComputeShader* mComputeShader;
 	};
 	};
 }
 }

+ 13 - 20
CamelotD3D11RenderSystem/Include/CmD3D11HardwareBufferManager.h

@@ -11,35 +11,28 @@ namespace CamelotEngine
 		D3D11HardwareBufferManager(D3D11Device& device);
 		D3D11HardwareBufferManager(D3D11Device& device);
 		~D3D11HardwareBufferManager();
 		~D3D11HardwareBufferManager();
 
 
+	protected:     
+		D3D11Device& mDevice;
+
 		/**
 		/**
-		 * @brief	Creates a hardware vertex buffer.
+		 * @copydoc HardwareBufferManager::createVertexBufferImpl
 		 */
 		 */
-		VertexBufferPtr createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
-		
+		VertexBufferPtr createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
+
 		/**
 		/**
-		 * @brief	Creates a hardware index buffer.
+		 * @copydoc HardwareBufferManager::createIndexBufferImpl
 		 */
 		 */
-		IndexBufferPtr createIndexBuffer(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
+		IndexBufferPtr createIndexBufferImpl(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
 
 
-		/** @copydoc HardwareBufferManagerInterface::createGpuParamBlock */
-		GpuParamBlockPtr createGpuParamBlock(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage = GPBU_STATIC);
+		/** @copydoc HardwareBufferManager::createGpuParamBlock */
+		GpuParamBlockPtr createGpuParamBlockImpl(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage = GPBU_STATIC);
 
 
 		/**
 		/**
-		 * @copydoc HardwareBufferManagerInterface::createGpuBuffer
+		 * @copydoc HardwareBufferManager::createGenericBufferImpl
 		 *
 		 *
-		 * Some limitations are imposed on the combinations of parameters:
-		 *  - APPENDCONSUME buffer type can only be used with randomGpuWrite enabled  
-		 *  - Counter can only be used with STRUCTURED buffer type
+		 * DirectX 9 does not support generic buffers so this method will return a dummy instance.
 		 */
 		 */
-		GpuBufferPtr createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
+		GpuBufferPtr createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
 			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
 			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
-
-	protected:     
-		/// Internal method for creates a new vertex declaration, may be overridden by certain rendering APIs
-		VertexDeclarationPtr createVertexDeclarationImpl(void);
-		/// Internal method for destroys a vertex declaration, may be overridden by certain rendering APIs
-		void destroyVertexDeclarationImpl(VertexDeclaration* decl);
-
-		D3D11Device& mDevice;
 	};
 	};
 }
 }

+ 14 - 2
CamelotD3D11RenderSystem/Include/CmD3D11IndexBuffer.h

@@ -9,8 +9,6 @@ namespace CamelotEngine
 	class CM_D3D11_EXPORT D3D11IndexBuffer : public IndexBuffer
 	class CM_D3D11_EXPORT D3D11IndexBuffer : public IndexBuffer
 	{
 	{
 	public:
 	public:
-		D3D11IndexBuffer(D3D11Device& device, HardwareBufferManager* mgr, IndexType idxType, UINT32 numIndexes, 
-			GpuBufferUsage usage, bool useSystemMem);
 		~D3D11IndexBuffer();
 		~D3D11IndexBuffer();
 
 
 		/**
 		/**
@@ -35,6 +33,11 @@ namespace CamelotEngine
 		ID3D11Buffer* getD3DIndexBuffer() const { return mBuffer->getD3DBuffer(); }		
 		ID3D11Buffer* getD3DIndexBuffer() const { return mBuffer->getD3DBuffer(); }		
 
 
 	protected:
 	protected:
+		friend class D3D11HardwareBufferManager;
+
+		D3D11IndexBuffer(D3D11Device& device, HardwareBufferManager* mgr, IndexType idxType, UINT32 numIndexes, 
+			GpuBufferUsage usage, bool useSystemMem);
+
 		/**
 		/**
 		* @copydoc HardwareBuffer::lockImpl
 		* @copydoc HardwareBuffer::lockImpl
 		 */
 		 */
@@ -45,8 +48,17 @@ namespace CamelotEngine
 		 */
 		 */
 		void unlockImpl(void);
 		void unlockImpl(void);
 
 
+		/**
+		 * @copydoc IndexBuffer::initialize_internal()
+		 */
+		void initialize_internal();	
+		
+		/**
+		 * @copydoc IndexBuffer::destroy_internal()
+		 */
 		void destroy_internal();
 		void destroy_internal();
 
 
 		D3D11HardwareBuffer* mBuffer;
 		D3D11HardwareBuffer* mBuffer;
+		D3D11Device& mDevice;
 	};
 	};
 }
 }

+ 0 - 2
CamelotD3D11RenderSystem/Include/CmD3D11MultiRenderTexture.h

@@ -19,7 +19,5 @@ namespace CamelotEngine
 
 
 		void setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0);
 		void setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0);
 		void setDepthStencilImpl(TexturePtr depthStencilSurface, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0);
 		void setDepthStencilImpl(TexturePtr depthStencilSurface, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0);
-
-		void destroy_internal();
 	};
 	};
 }
 }

+ 0 - 2
CamelotD3D11RenderSystem/Include/CmD3D11RenderTexture.h

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

+ 9 - 4
CamelotD3D11RenderSystem/Include/CmD3D11RenderWindow.h

@@ -10,8 +10,6 @@ namespace CamelotEngine
 	public:
 	public:
 		~D3D11RenderWindow();
 		~D3D11RenderWindow();
 
 
-		void initialize(const RENDER_WINDOW_DESC& desc);
-
 		void reposition(int left, int top);
 		void reposition(int left, int top);
 		void resize(unsigned int width, unsigned int height);
 		void resize(unsigned int width, unsigned int height);
 
 
@@ -35,7 +33,7 @@ namespace CamelotEngine
 
 
 	protected:
 	protected:
 		friend class D3D11RenderWindowManager;
 		friend class D3D11RenderWindowManager;
-		D3D11RenderWindow(D3D11Device& device, IDXGIFactory* DXGIFactory);
+		D3D11RenderWindow(const RENDER_WINDOW_DESC& desc, D3D11Device& device, IDXGIFactory* DXGIFactory);
 
 
 		void _createSizeDependedD3DResources();
 		void _createSizeDependedD3DResources();
 		void _destroySizeDependedD3DResources();
 		void _destroySizeDependedD3DResources();
@@ -50,8 +48,15 @@ namespace CamelotEngine
 		bool _getSwitchingFullscreen() const					{ return mSwitchingFullscreen; }
 		bool _getSwitchingFullscreen() const					{ return mSwitchingFullscreen; }
 		void _finishSwitchingFullscreen();
 		void _finishSwitchingFullscreen();
 		
 		
+		/**
+		 * @copydoc RenderWindow::initialize_internal().
+		 */
+		void initialize_internal();
+
+		/**
+		 * @copydoc RenderWindow::destroy_internal().
+		 */
 		void destroy_internal();
 		void destroy_internal();
-
 	protected:
 	protected:
 		D3D11Device&	mDevice;			// D3D11 driver
 		D3D11Device&	mDevice;			// D3D11 driver
 		IDXGIFactory*	mDXGIFactory;
 		IDXGIFactory*	mDXGIFactory;

+ 2 - 2
CamelotD3D11RenderSystem/Include/CmD3D11RenderWindowManager.h

@@ -12,9 +12,9 @@ namespace CamelotEngine
 
 
 	protected:
 	protected:
 		/**
 		/**
-		 * @copydoc RenderWindowManager::create()
+		 * @copydoc RenderWindowManager::createImpl()
 		 */
 		 */
-		void createImpl(const RENDER_WINDOW_DESC& desc, AsyncOp& asyncOp);
+		RenderWindowPtr createImpl(const RENDER_WINDOW_DESC& desc);
 
 
 	private:
 	private:
 		D3D11RenderSystem* mRenderSystem;
 		D3D11RenderSystem* mRenderSystem;

+ 2 - 2
CamelotD3D11RenderSystem/Include/CmD3D11Texture.h

@@ -69,12 +69,12 @@ namespace CamelotEngine
 		void _unmapstaticbuffer();
 		void _unmapstaticbuffer();
 
 
 		/**
 		/**
-		 * @copydoc	Resource::initialize_internal()
+		 * @copydoc	Texture::initialize_internal()
 		 */
 		 */
 		void initialize_internal();
 		void initialize_internal();
 
 
 		/**
 		/**
-		 * @copydoc Resource::destroy_internal()
+		 * @copydoc Texture::destroy_internal()
 		 */
 		 */
 		void destroy_internal();
 		void destroy_internal();
 
 

+ 3 - 7
CamelotD3D11RenderSystem/Include/CmD3D11TextureManager.h

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

+ 16 - 3
CamelotD3D11RenderSystem/Include/CmD3D11VertexBuffer.h

@@ -9,8 +9,6 @@ namespace CamelotEngine
 	class CM_D3D11_EXPORT D3D11VertexBuffer : public VertexBuffer
 	class CM_D3D11_EXPORT D3D11VertexBuffer : public VertexBuffer
 	{
 	{
 	public:
 	public:
-		D3D11VertexBuffer(D3D11Device& device, HardwareBufferManager* mgr, UINT32 vertexSize, UINT32 numVertices, 
-			GpuBufferUsage usage, bool useSystemMem, bool streamOut);
 		~D3D11VertexBuffer();
 		~D3D11VertexBuffer();
 
 
 		/**
 		/**
@@ -34,7 +32,12 @@ namespace CamelotEngine
 		 */
 		 */
 		ID3D11Buffer* getD3DVertexBuffer() const { return mBuffer->getD3DBuffer(); }		
 		ID3D11Buffer* getD3DVertexBuffer() const { return mBuffer->getD3DBuffer(); }		
 
 
-	protected:
+	protected: 
+		friend class D3D11HardwareBufferManager;
+
+		D3D11VertexBuffer(D3D11Device& device, HardwareBufferManager* mgr, UINT32 vertexSize, UINT32 numVertices, 
+			GpuBufferUsage usage, bool useSystemMem, bool streamOut);
+
 		/**
 		/**
 		* @copydoc HardwareBuffer::lockImpl
 		* @copydoc HardwareBuffer::lockImpl
 		 */
 		 */
@@ -45,8 +48,18 @@ namespace CamelotEngine
 		 */
 		 */
 		void unlockImpl(void);
 		void unlockImpl(void);
 
 
+		/**
+		 * @copydoc VertexBuffer::initialize_internal()
+		 */
+		void initialize_internal();	
+		
+		/**
+		 * @copydoc VertexBuffer::destroy_internal()
+		 */
 		void destroy_internal();
 		void destroy_internal();
 
 
 		D3D11HardwareBuffer* mBuffer;
 		D3D11HardwareBuffer* mBuffer;
+		bool mStreamOut;
+		D3D11Device& mDevice;
 	};
 	};
 }
 }

+ 21 - 12
CamelotD3D11RenderSystem/Source/CmD3D11GpuBuffer.cpp

@@ -9,11 +9,19 @@ namespace CamelotEngine
 {
 {
 	D3D11GpuBuffer::D3D11GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter) 
 	D3D11GpuBuffer::D3D11GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter) 
 		: GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter), mBuffer(nullptr)
 		: GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter), mBuffer(nullptr)
+	{
+
+	}
+
+	D3D11GpuBuffer::~D3D11GpuBuffer()
+	{ }
+
+	void D3D11GpuBuffer::initialize_internal()
 	{
 	{
 		D3D11HardwareBuffer::BufferType bufferType;
 		D3D11HardwareBuffer::BufferType bufferType;
 		D3D11RenderSystem* d3d11rs = static_cast<D3D11RenderSystem*>(D3D11RenderSystem::instancePtr());
 		D3D11RenderSystem* d3d11rs = static_cast<D3D11RenderSystem*>(D3D11RenderSystem::instancePtr());
 
 
-		switch(type)
+		switch(mType)
 		{
 		{
 		case GBT_STRUCTURED:
 		case GBT_STRUCTURED:
 			bufferType = D3D11HardwareBuffer::BT_STRUCTURED;
 			bufferType = D3D11HardwareBuffer::BT_STRUCTURED;
@@ -27,14 +35,22 @@ namespace CamelotEngine
 		case GBT_APPENDCONSUME:
 		case GBT_APPENDCONSUME:
 			bufferType = D3D11HardwareBuffer::BT_APPENDCONSUME;
 			bufferType = D3D11HardwareBuffer::BT_APPENDCONSUME;
 			break;
 			break;
+		default:
+			CM_EXCEPT(InvalidParametersException, "Unsupported buffer type " + toString(mType));
 		}
 		}
 
 
-		mBuffer = new D3D11HardwareBuffer(bufferType, usage, elementCount, elementSize, 
-			d3d11rs->getPrimaryDevice(), false, false, randomGpuWrite, useCounter);
+		mBuffer = new D3D11HardwareBuffer(bufferType, mUsage, mElementCount, mElementSize, 
+			d3d11rs->getPrimaryDevice(), false, false, mRandomGpuWrite, mUseCounter);
+
+		GpuBuffer::initialize_internal();
 	}
 	}
 
 
-	D3D11GpuBuffer::~D3D11GpuBuffer()
-	{ }
+	void D3D11GpuBuffer::destroy_internal()
+	{
+		delete mBuffer;
+
+		GpuBuffer::destroy_internal();
+	}
 
 
 	void* D3D11GpuBuffer::lock(UINT32 offset, UINT32 length, GpuLockOptions options)
 	void* D3D11GpuBuffer::lock(UINT32 offset, UINT32 length, GpuLockOptions options)
 	{
 	{
@@ -79,11 +95,4 @@ namespace CamelotEngine
 		if(view != nullptr)
 		if(view != nullptr)
 			delete view;
 			delete view;
 	}
 	}
-
-	void D3D11GpuBuffer::destroy_internal()
-	{
-		delete mBuffer;
-
-		GpuBuffer::destroy_internal();
-	}
 }
 }

+ 5 - 0
CamelotD3D11RenderSystem/Source/CmD3D11GpuProgram.cpp

@@ -11,6 +11,11 @@ namespace CamelotEngine
 
 
 	}
 	}
 
 
+	D3D11GpuProgram::~D3D11GpuProgram()
+	{
+
+	}
+
 	D3D11GpuVertexProgram::D3D11GpuVertexProgram(const String& profile) 
 	D3D11GpuVertexProgram::D3D11GpuVertexProgram(const String& profile) 
 		: D3D11GpuProgram(GPT_VERTEX_PROGRAM, profile)
 		: D3D11GpuProgram(GPT_VERTEX_PROGRAM, profile)
 		, mVertexShader(nullptr)
 		, mVertexShader(nullptr)

+ 6 - 32
CamelotD3D11RenderSystem/Source/CmD3D11HardwareBufferManager.cpp

@@ -16,52 +16,26 @@ namespace CamelotEngine
 
 
 	}
 	}
 
 
-	VertexBufferPtr D3D11HardwareBufferManager::createVertexBuffer(UINT32 vertexSize, 
+	VertexBufferPtr D3D11HardwareBufferManager::createVertexBufferImpl(UINT32 vertexSize, 
 		UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
 		UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
 	{
 	{
-		assert (numVerts > 0);
-		D3D11VertexBuffer* vbuf = new D3D11VertexBuffer(mDevice,
-			this, vertexSize, numVerts, usage, false, streamOut);
-		{
-			mVertexBuffers.insert(vbuf);
-		}
-
-		return VertexBufferPtr(vbuf);
+		return VertexBufferPtr(new D3D11VertexBuffer(mDevice, this, vertexSize, numVerts, usage, false, streamOut));
 	}
 	}
 
 
-	IndexBufferPtr D3D11HardwareBufferManager::createIndexBuffer(IndexBuffer::IndexType itype, 
+	IndexBufferPtr D3D11HardwareBufferManager::createIndexBufferImpl(IndexBuffer::IndexType itype, 
 		UINT32 numIndexes, GpuBufferUsage usage)
 		UINT32 numIndexes, GpuBufferUsage usage)
 	{
 	{
-		assert (numIndexes > 0);
-
-		D3D11IndexBuffer* idx = new D3D11IndexBuffer(mDevice,
-			this, itype, numIndexes, usage, false);
-		{
-
-				mIndexBuffers.insert(idx);
-		}
-
-		return IndexBufferPtr(idx);
+		return IndexBufferPtr(new D3D11IndexBuffer(mDevice, this, itype, numIndexes, usage, false));
 	}
 	}
 
 
-	GpuParamBlockPtr D3D11HardwareBufferManager::createGpuParamBlock(const GpuParamBlockDesc& blockDesc, GpuParamBlockUsage usage)
+	GpuParamBlockPtr D3D11HardwareBufferManager::createGpuParamBlockImpl(const GpuParamBlockDesc& blockDesc, GpuParamBlockUsage usage)
 	{
 	{
 		return GpuParamBlockPtr(new D3D11GpuParamBlock(blockDesc, usage));
 		return GpuParamBlockPtr(new D3D11GpuParamBlock(blockDesc, usage));
 	}
 	}
 
 
-	GpuBufferPtr D3D11HardwareBufferManager::createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
+	GpuBufferPtr D3D11HardwareBufferManager::createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
 		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
 		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
 	{
 	{
 		return GpuBufferPtr(new D3D11GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
 		return GpuBufferPtr(new D3D11GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
 	}
 	}
-
-	VertexDeclarationPtr D3D11HardwareBufferManager::createVertexDeclarationImpl(void)
-	{
-		return VertexDeclarationPtr(new VertexDeclaration());
-	}
-
-	void D3D11HardwareBufferManager::destroyVertexDeclarationImpl(VertexDeclaration* decl)
-	{
-		delete decl;
-	}
 }
 }

+ 16 - 9
CamelotD3D11RenderSystem/Source/CmD3D11IndexBuffer.cpp

@@ -4,7 +4,7 @@ namespace CamelotEngine
 {
 {
 	D3D11IndexBuffer::D3D11IndexBuffer(D3D11Device& device, HardwareBufferManager* mgr, IndexType idxType, UINT32 numIndexes, 
 	D3D11IndexBuffer::D3D11IndexBuffer(D3D11Device& device, HardwareBufferManager* mgr, IndexType idxType, UINT32 numIndexes, 
 		GpuBufferUsage usage, bool useSystemMem)
 		GpuBufferUsage usage, bool useSystemMem)
-		:IndexBuffer(mgr, idxType, numIndexes, usage, useSystemMem)
+		:IndexBuffer(mgr, idxType, numIndexes, usage, useSystemMem), mDevice(device)
 	{
 	{
 		mBuffer = new D3D11HardwareBuffer(D3D11HardwareBuffer::BT_INDEX, usage, 1, mSizeInBytes, device, useSystemMem);
 		mBuffer = new D3D11HardwareBuffer(D3D11HardwareBuffer::BT_INDEX, usage, 1, mSizeInBytes, device, useSystemMem);
 	}
 	}
@@ -14,6 +14,21 @@ namespace CamelotEngine
 		
 		
 	}
 	}
 
 
+	void D3D11IndexBuffer::initialize_internal()
+	{
+		mBuffer = new D3D11HardwareBuffer(D3D11HardwareBuffer::BT_INDEX, mUsage, 1, mSizeInBytes, mDevice, mSystemMemory);
+
+		IndexBuffer::initialize_internal();
+	}
+
+	void D3D11IndexBuffer::destroy_internal()
+	{
+		if(mBuffer != nullptr)
+			delete mBuffer;
+
+		IndexBuffer::destroy_internal();
+	}
+
 	void* D3D11IndexBuffer::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
 	void* D3D11IndexBuffer::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
 	{
 	{
 		return mBuffer->lock(offset, length, options);
 		return mBuffer->lock(offset, length, options);
@@ -39,12 +54,4 @@ namespace CamelotEngine
 	{
 	{
 		mBuffer->copyData(srcBuffer, srcOffset, dstOffset, length, discardWholeBuffer);
 		mBuffer->copyData(srcBuffer, srcOffset, dstOffset, length, discardWholeBuffer);
 	}
 	}
-
-	void D3D11IndexBuffer::destroy_internal()
-	{
-		if(mBuffer != nullptr)
-			delete mBuffer;
-
-		IndexBuffer::destroy_internal();
-	}
 }
 }

+ 0 - 5
CamelotD3D11RenderSystem/Source/CmD3D11MultiRenderTexture.cpp

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

+ 0 - 5
CamelotD3D11RenderSystem/Source/CmD3D11RenderTexture.cpp

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

+ 52 - 46
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -9,8 +9,8 @@
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
-	D3D11RenderWindow::D3D11RenderWindow(D3D11Device& device, IDXGIFactory* DXGIFactory)
-		: RenderWindow()
+	D3D11RenderWindow::D3D11RenderWindow(const RENDER_WINDOW_DESC& desc,D3D11Device& device, IDXGIFactory* DXGIFactory)
+		: RenderWindow(desc)
 		, mDevice(device)
 		, mDevice(device)
 		, mDXGIFactory(DXGIFactory)
 		, mDXGIFactory(DXGIFactory)
 		, mIsExternal(false)
 		, mIsExternal(false)
@@ -32,33 +32,7 @@ namespace CamelotEngine
 	{
 	{
 	}
 	}
 
 
-	void D3D11RenderWindow::destroy_internal()
-	{
-		_destroySizeDependedD3DResources();
-
-		mActive = false;
-		mClosed = true;
-
-		SAFE_RELEASE(mSwapChain);
-
-		if (mHWnd && !mIsExternal)
-		{
-			WindowEventUtilities::_removeRenderWindow(this);
-			DestroyWindow(mHWnd);
-		}
-
-		if(mDepthStencilView != nullptr)
-		{
-			Texture::releaseView(mDepthStencilView);
-			mDepthStencilView = nullptr;
-		}
-
-		mHWnd = nullptr;
-
-		RenderWindow::destroy_internal();
-	}
-
-	void D3D11RenderWindow::initialize(const RENDER_WINDOW_DESC& desc)
+	void D3D11RenderWindow::initialize_internal()
 	{
 	{
 		mFSAAType.Count = 1;
 		mFSAAType.Count = 1;
 		mFSAAType.Quality = 0;
 		mFSAAType.Quality = 0;
@@ -73,17 +47,17 @@ namespace CamelotEngine
 		NameValuePairList::const_iterator opt;
 		NameValuePairList::const_iterator opt;
 
 
 		// parentWindowHandle		-> parentHWnd
 		// parentWindowHandle		-> parentHWnd
-		opt = desc.platformSpecific.find("parentWindowHandle");
-		if(opt != desc.platformSpecific.end())
+		opt = mDesc.platformSpecific.find("parentWindowHandle");
+		if(opt != mDesc.platformSpecific.end())
 			parentHWnd = (HWND)parseUnsignedInt(opt->second);
 			parentHWnd = (HWND)parseUnsignedInt(opt->second);
 		// externalWindowHandle		-> externalHandle
 		// externalWindowHandle		-> externalHandle
-		opt = desc.platformSpecific.find("externalWindowHandle");
-		if(opt != desc.platformSpecific.end())
+		opt = mDesc.platformSpecific.find("externalWindowHandle");
+		if(opt != mDesc.platformSpecific.end())
 			externalHandle = (HWND)parseUnsignedInt(opt->second);
 			externalHandle = (HWND)parseUnsignedInt(opt->second);
 
 
-		mName = desc.title;
-		mIsFullScreen = desc.fullscreen;
-		mColorDepth = desc.colorDepth;
+		mName = mDesc.title;
+		mIsFullScreen = mDesc.fullscreen;
+		mColorDepth = mDesc.colorDepth;
 		mWidth = mHeight = mLeft = mTop = 0;
 		mWidth = mHeight = mLeft = mTop = 0;
 
 
 		mActive = true;
 		mActive = true;
@@ -94,12 +68,12 @@ namespace CamelotEngine
 			DWORD dwStyle = (mHidden ? 0 : WS_VISIBLE) | WS_CLIPCHILDREN;
 			DWORD dwStyle = (mHidden ? 0 : WS_VISIBLE) | WS_CLIPCHILDREN;
 			RECT rc;
 			RECT rc;
 
 
-			mWidth = desc.width;
-			mHeight = desc.height;
-			mTop = desc.top;
-			mLeft = desc.left;
+			mWidth = mDesc.width;
+			mHeight = mDesc.height;
+			mTop = mDesc.top;
+			mLeft = mDesc.left;
 
 
-			if (!desc.fullscreen)
+			if (!mDesc.fullscreen)
 			{
 			{
 				if (parentHWnd)
 				if (parentHWnd)
 				{
 				{
@@ -107,16 +81,16 @@ namespace CamelotEngine
 				}
 				}
 				else
 				else
 				{
 				{
-					if (desc.border == "none")
+					if (mDesc.border == "none")
 						dwStyle |= WS_POPUP;
 						dwStyle |= WS_POPUP;
-					else if (desc.border == "fixed")
+					else if (mDesc.border == "fixed")
 						dwStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION |
 						dwStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION |
 						WS_SYSMENU | WS_MINIMIZEBOX;
 						WS_SYSMENU | WS_MINIMIZEBOX;
 					else
 					else
 						dwStyle |= WS_OVERLAPPEDWINDOW;
 						dwStyle |= WS_OVERLAPPEDWINDOW;
 				}
 				}
 
 
-				if (!desc.outerDimensions)
+				if (!mDesc.outerDimensions)
 				{
 				{
 					// Calculate window dimensions required
 					// Calculate window dimensions required
 					// to get the requested client area
 					// to get the requested client area
@@ -145,7 +119,7 @@ namespace CamelotEngine
 			}
 			}
 
 
 			UINT classStyle = 0;
 			UINT classStyle = 0;
-			if (desc.enableDoubleClick)
+			if (mDesc.enableDoubleClick)
 				classStyle |= CS_DBLCLKS;
 				classStyle |= CS_DBLCLKS;
 
 
 			HINSTANCE hInst = NULL;
 			HINSTANCE hInst = NULL;
@@ -161,7 +135,7 @@ namespace CamelotEngine
 			// Create our main window
 			// Create our main window
 			// Pass pointer to self
 			// Pass pointer to self
 			mIsExternal = false;
 			mIsExternal = false;
-			mHWnd = CreateWindow("D3D11Wnd", desc.title.c_str(), dwStyle,
+			mHWnd = CreateWindow("D3D11Wnd", mDesc.title.c_str(), dwStyle,
 				mLeft, mTop, mWidth, mHeight, parentHWnd, 0, hInst, this);
 				mLeft, mTop, mWidth, mHeight, parentHWnd, 0, hInst, this);
 
 
 			WindowEventUtilities::_addRenderWindow(this);
 			WindowEventUtilities::_addRenderWindow(this);
@@ -186,6 +160,38 @@ namespace CamelotEngine
 		_createSizeDependedD3DResources();
 		_createSizeDependedD3DResources();
 		mDXGIFactory->MakeWindowAssociation(mHWnd, NULL);
 		mDXGIFactory->MakeWindowAssociation(mHWnd, NULL);
 		setHidden(mHidden);
 		setHidden(mHidden);
+
+		RenderSystem* rs = RenderSystem::instancePtr();
+		D3D11RenderSystem* d3d11rs = static_cast<D3D11RenderSystem*>(rs);
+		d3d11rs->attachRenderTarget(*this);
+
+		RenderWindow::initialize_internal();
+	}
+
+	void D3D11RenderWindow::destroy_internal()
+	{
+		_destroySizeDependedD3DResources();
+
+		mActive = false;
+		mClosed = true;
+
+		SAFE_RELEASE(mSwapChain);
+
+		if (mHWnd && !mIsExternal)
+		{
+			WindowEventUtilities::_removeRenderWindow(this);
+			DestroyWindow(mHWnd);
+		}
+
+		if(mDepthStencilView != nullptr)
+		{
+			Texture::releaseView(mDepthStencilView);
+			mDepthStencilView = nullptr;
+		}
+
+		mHWnd = nullptr;
+
+		RenderWindow::destroy_internal();
 	}
 	}
 
 
 	void D3D11RenderWindow::swapBuffers(bool waitForVSync)
 	void D3D11RenderWindow::swapBuffers(bool waitForVSync)

+ 3 - 7
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindowManager.cpp

@@ -11,18 +11,14 @@ namespace CamelotEngine
 		assert(mRenderSystem != nullptr);
 		assert(mRenderSystem != nullptr);
 	}
 	}
 
 
-	void D3D11RenderWindowManager::createImpl(const RENDER_WINDOW_DESC& desc, AsyncOp& asyncOp)
+	RenderWindowPtr D3D11RenderWindowManager::createImpl(const RENDER_WINDOW_DESC& desc)
 	{
 	{
 		RenderSystem* rs = RenderSystem::instancePtr();
 		RenderSystem* rs = RenderSystem::instancePtr();
 		D3D11RenderSystem* d3d11rs = static_cast<D3D11RenderSystem*>(rs);
 		D3D11RenderSystem* d3d11rs = static_cast<D3D11RenderSystem*>(rs);
 
 
 		// Create the window
 		// Create the window
-		D3D11RenderWindow* renderWindow = new D3D11RenderWindow(d3d11rs->getPrimaryDevice(), d3d11rs->getDXGIFactory());
-		renderWindow->initialize(desc);
+		D3D11RenderWindow* renderWindow = new D3D11RenderWindow(desc, d3d11rs->getPrimaryDevice(), d3d11rs->getDXGIFactory());
 
 
-		d3d11rs->attachRenderTarget(*renderWindow);
-
-		D3D11RenderWindowPtr winPtr(renderWindow);
-		asyncOp.completeOperation(std::static_pointer_cast<RenderWindow>(winPtr));
+		return RenderWindowPtr(renderWindow);
 	}
 	}
 }
 }

+ 4 - 4
CamelotD3D11RenderSystem/Source/CmD3D11Texture.cpp

@@ -94,8 +94,10 @@ namespace CamelotEngine
 	{
 	{
 		THROW_IF_NOT_RENDER_THREAD
 		THROW_IF_NOT_RENDER_THREAD
 
 
+		Texture::initialize_internal();
+
 			// load based on tex.type
 			// load based on tex.type
-			switch (getTextureType())
+		switch (getTextureType())
 		{
 		{
 			case TEX_TYPE_1D:
 			case TEX_TYPE_1D:
 				_create1DTex();
 				_create1DTex();
@@ -111,8 +113,6 @@ namespace CamelotEngine
 				destroy_internal();
 				destroy_internal();
 				CM_EXCEPT(RenderingAPIException, "Unknown texture type");
 				CM_EXCEPT(RenderingAPIException, "Unknown texture type");
 		}
 		}
-
-		Resource::initialize_internal();
 	}
 	}
 
 
 	void D3D11Texture::destroy_internal()
 	void D3D11Texture::destroy_internal()
@@ -126,7 +126,7 @@ namespace CamelotEngine
 
 
 		clearBufferViews();
 		clearBufferViews();
 
 
-		CoreGpuObject::destroy_internal();
+		Texture::destroy_internal();
 	}
 	}
 
 
 	void D3D11Texture::_create1DTex()
 	void D3D11Texture::_create1DTex()

+ 6 - 9
CamelotD3D11RenderSystem/Source/CmD3D11TextureManager.cpp

@@ -14,22 +14,19 @@ namespace CamelotEngine
 	D3D11TextureManager::~D3D11TextureManager()
 	D3D11TextureManager::~D3D11TextureManager()
 	{ }
 	{ }
 
 
-	Texture* D3D11TextureManager::createTextureImpl()
+	TexturePtr D3D11TextureManager::createTextureImpl()
 	{
 	{
-		return new D3D11Texture(); 
+		return TexturePtr(new D3D11Texture()); 
 	}
 	}
 
 
-	RenderTexture* D3D11TextureManager::createRenderTextureImpl()
+	RenderTexturePtr D3D11TextureManager::createRenderTextureImpl()
 	{
 	{
-		return new D3D11RenderTexture();
+		return RenderTexturePtr(new D3D11RenderTexture());
 	}
 	}
 
 
-	MultiRenderTexturePtr D3D11TextureManager::createMultiRenderTexture()
+	MultiRenderTexturePtr D3D11TextureManager::createMultiRenderTextureImpl()
 	{
 	{
-		D3D11MultiRenderTexture* newMRT = new D3D11MultiRenderTexture();
-		newMRT->initialize();
-
-		return MultiRenderTexturePtr(newMRT);
+		return MultiRenderTexturePtr(new D3D11MultiRenderTexture());
 	}
 	}
 
 
 	PixelFormat D3D11TextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage)
 	PixelFormat D3D11TextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage)

+ 11 - 7
CamelotD3D11RenderSystem/Source/CmD3D11VertexBuffer.cpp

@@ -4,15 +4,11 @@ namespace CamelotEngine
 {
 {
 	D3D11VertexBuffer::D3D11VertexBuffer(D3D11Device& device, HardwareBufferManager* mgr, UINT32 vertexSize, UINT32 numVertices, 
 	D3D11VertexBuffer::D3D11VertexBuffer(D3D11Device& device, HardwareBufferManager* mgr, UINT32 vertexSize, UINT32 numVertices, 
 		GpuBufferUsage usage, bool useSystemMem, bool streamOut)
 		GpuBufferUsage usage, bool useSystemMem, bool streamOut)
-		:VertexBuffer(mgr, vertexSize, numVertices, usage, useSystemMem)
-	{
-		mBuffer = new D3D11HardwareBuffer(D3D11HardwareBuffer::BT_VERTEX, usage, 1, mSizeInBytes, device, useSystemMem, streamOut);
-	}
+		:VertexBuffer(mgr, vertexSize, numVertices, usage, useSystemMem), mDevice(device), mStreamOut(streamOut)
+	{ }
 
 
 	D3D11VertexBuffer::~D3D11VertexBuffer()
 	D3D11VertexBuffer::~D3D11VertexBuffer()
-	{
-		
-	}
+	{ }
 
 
 	void* D3D11VertexBuffer::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
 	void* D3D11VertexBuffer::lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options)
 	{
 	{
@@ -40,6 +36,14 @@ namespace CamelotEngine
 		mBuffer->copyData(srcBuffer, srcOffset, dstOffset, length, discardWholeBuffer);
 		mBuffer->copyData(srcBuffer, srcOffset, dstOffset, length, discardWholeBuffer);
 	}
 	}
 
 
+	void D3D11VertexBuffer::initialize_internal()
+	{
+		mBuffer = new D3D11HardwareBuffer(D3D11HardwareBuffer::BT_VERTEX, 
+			mUsage, 1, mSizeInBytes, mDevice, mSystemMemory, mStreamOut);
+
+		VertexBuffer::initialize_internal();
+	}
+
 	void D3D11VertexBuffer::destroy_internal()
 	void D3D11VertexBuffer::destroy_internal()
 	{
 	{
 		if(mBuffer != nullptr)
 		if(mBuffer != nullptr)

+ 8 - 2
CamelotD3D9Renderer/Include/CmD3D9GpuBuffer.h

@@ -8,7 +8,6 @@ namespace CamelotEngine
 	class CM_D3D9_EXPORT D3D9GpuBuffer : public GpuBuffer
 	class CM_D3D9_EXPORT D3D9GpuBuffer : public GpuBuffer
 	{
 	{
 	public:
 	public:
-		D3D9GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
         ~D3D9GpuBuffer();
         ~D3D9GpuBuffer();
 
 
 		/**
 		/**
@@ -39,9 +38,16 @@ namespace CamelotEngine
 			UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
 			UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
 
 
 	protected:
 	protected:
+		friend class D3D9HardwareBufferManager;
+
+		D3D9GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
+
 		virtual GpuBufferView* createView();
 		virtual GpuBufferView* createView();
 		virtual void destroyView(GpuBufferView* view);
 		virtual void destroyView(GpuBufferView* view);
 
 
-		virtual void destroy_internal();
+		/**
+		 * @copydoc GpuBuffer::initialize_internal()
+		 */
+		void initialize_internal();	
 	};
 	};
 }
 }

+ 5 - 5
CamelotD3D9Renderer/Include/CmD3D9GpuProgram.h

@@ -41,11 +41,6 @@ namespace CamelotEngine {
     public:
     public:
         ~D3D9GpuProgram();
         ~D3D9GpuProgram();
 
 
-		/**
-		 * @copydoc GpuProgram::initialize_internal().
-		 */
-		virtual void initialize_internal();
-
         /** Sets whether matrix packing in column-major order. */ 
         /** Sets whether matrix packing in column-major order. */ 
         void setColumnMajorMatrices(bool columnMajor) { mColumnMajorMatrices = columnMajor; }
         void setColumnMajorMatrices(bool columnMajor) { mColumnMajorMatrices = columnMajor; }
         /** Gets whether matrix packed in column-major order. */
         /** Gets whether matrix packed in column-major order. */
@@ -68,6 +63,11 @@ namespace CamelotEngine {
 
 
 		void createInternalResources(IDirect3DDevice9* d3d9Device);
 		void createInternalResources(IDirect3DDevice9* d3d9Device);
 
 
+		/**
+		 * @copydoc GpuProgram::initialize_internal().
+		 */
+		void initialize_internal();
+
 		/**
 		/**
 		 * @copydoc GpuProgram::destroy_internal().
 		 * @copydoc GpuProgram::destroy_internal().
 		 */
 		 */

+ 8 - 4
CamelotD3D9Renderer/Include/CmD3D9HLSLProgram.h

@@ -85,16 +85,20 @@ namespace CamelotEngine {
         /// Overridden from GpuProgram
         /// Overridden from GpuProgram
         const String& getLanguage(void) const;
         const String& getLanguage(void) const;
 
 
-		/** @copydoc HighLevelGpuProgram::initialize_internal(). */
-		void initialize_internal();
-
     protected:
     protected:
 		friend class D3D9HLSLProgramFactory;
 		friend class D3D9HLSLProgramFactory;
 
 
 		D3D9HLSLProgram(const String& source, const String& entryPoint, const String& language, 
 		D3D9HLSLProgram(const String& source, const String& entryPoint, const String& language, 
 			GpuProgramType gptype, GpuProgramProfile profile, bool isAdjacencyInfoRequired = false);
 			GpuProgramType gptype, GpuProgramProfile profile, bool isAdjacencyInfoRequired = false);
+ 
+		/**
+		 * @copydoc HighLevelGpuProgram::initialize_internal().
+		 */
+		void initialize_internal();
 
 
-		/** @copydoc HighLevelGpuProgram::destroy_internal(). */
+		/**
+		 * @copydoc HighLevelGpuProgram::destroy_internal().
+		 */
         void destroy_internal();
         void destroy_internal();
 
 
         String mPreprocessorDefines;
         String mPreprocessorDefines;

+ 11 - 13
CamelotD3D9Renderer/Include/CmD3D9HardwareBufferManager.h

@@ -36,35 +36,33 @@ namespace CamelotEngine {
     /** Implementation of HardwareBufferManager for D3D9. */
     /** Implementation of HardwareBufferManager for D3D9. */
     class CM_D3D9_EXPORT D3D9HardwareBufferManager : public HardwareBufferManager
     class CM_D3D9_EXPORT D3D9HardwareBufferManager : public HardwareBufferManager
     {
     {
-    protected:     
-        /// Internal method for creates a new vertex declaration, may be overridden by certain rendering APIs
-        VertexDeclarationPtr createVertexDeclarationImpl(void);
-        /// Internal method for destroys a vertex declaration, may be overridden by certain rendering APIs
-        void destroyVertexDeclarationImpl(VertexDeclaration* decl);
-
     public:
     public:
         D3D9HardwareBufferManager();
         D3D9HardwareBufferManager();
         ~D3D9HardwareBufferManager();
         ~D3D9HardwareBufferManager();
 
 
+	protected:     
+		/// Internal method for creates a new vertex declaration, may be overridden by certain rendering APIs
+		VertexDeclarationPtr createVertexDeclarationImpl(void);
+
 		/**
 		/**
-		 * @copydoc HardwareBufferManager::createVertexBuffer
+		 * @copydoc HardwareBufferManager::createVertexBufferImpl
 		 */
 		 */
-		VertexBufferPtr createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
+		VertexBufferPtr createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
 
 
 		/**
 		/**
-		 * @copydoc HardwareBufferManager::createIndexBuffer
+		 * @copydoc HardwareBufferManager::createIndexBufferImpl
 		 */
 		 */
-		IndexBufferPtr createIndexBuffer(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
+		IndexBufferPtr createIndexBufferImpl(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
 
 
 		/** @copydoc HardwareBufferManager::createGpuParamBlock */
 		/** @copydoc HardwareBufferManager::createGpuParamBlock */
-		GpuParamBlockPtr createGpuParamBlock(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage = GPBU_STATIC);
+		GpuParamBlockPtr createGpuParamBlockImpl(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage = GPBU_STATIC);
 
 
 		/**
 		/**
-		 * @copydoc HardwareBufferManager::createGenericBuffer
+		 * @copydoc HardwareBufferManager::createGenericBufferImpl
 		 *
 		 *
 		 * DirectX 9 does not support generic buffers so this method will return a dummy instance.
 		 * DirectX 9 does not support generic buffers so this method will return a dummy instance.
 		 */
 		 */
-		GpuBufferPtr createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
+		GpuBufferPtr createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
 			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
 			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
     };
     };
 }
 }

+ 13 - 2
CamelotD3D9Renderer/Include/CmD3D9IndexBuffer.h

@@ -39,8 +39,6 @@ namespace CamelotEngine {
     {
     {
   
   
     public:
     public:
-		D3D9IndexBuffer(HardwareBufferManager* mgr, IndexType idxType, UINT32 numIndexes, 
-			GpuBufferUsage usage, bool useSystemMem);
         ~D3D9IndexBuffer();
         ~D3D9IndexBuffer();
         /** See HardwareBuffer. */
         /** See HardwareBuffer. */
         void readData(UINT32 offset, UINT32 length, void* pDest);
         void readData(UINT32 offset, UINT32 length, void* pDest);
@@ -78,6 +76,11 @@ namespace CamelotEngine {
 		};
 		};
 
 
 	protected:
 	protected:
+		friend class D3D9HardwareBufferManager;
+
+		D3D9IndexBuffer(HardwareBufferManager* mgr, IndexType idxType, UINT32 numIndexes, 
+			GpuBufferUsage usage, bool useSystemMem);
+
 		/** See HardwareBuffer. */
 		/** See HardwareBuffer. */
 		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
 		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
 		/** See HardwareBuffer. */
 		/** See HardwareBuffer. */
@@ -85,6 +88,14 @@ namespace CamelotEngine {
 		// updates buffer resources from system memory buffer.
 		// updates buffer resources from system memory buffer.
 		bool updateBufferResources(const char* systemMemoryBuffer, BufferResources* bufferResources);
 		bool updateBufferResources(const char* systemMemoryBuffer, BufferResources* bufferResources);
 
 
+		/**
+		 * @copydoc IndexBuffer::initialize_internal()
+		 */
+		void initialize_internal();	
+		
+		/**
+		 * @copydoc IndexBuffer::destroy_internal()
+		 */
 		void destroy_internal();
 		void destroy_internal();
 
 
 	protected:		
 	protected:		

+ 5 - 3
CamelotD3D9Renderer/Include/CmD3D9MultiRenderTexture.h

@@ -17,13 +17,15 @@ namespace CamelotEngine
 		friend class D3D9TextureManager;
 		friend class D3D9TextureManager;
 
 
 		D3D9MultiRenderTexture();
 		D3D9MultiRenderTexture();
-		void initialize();
+
+		/**
+		 * @copydoc MultiRenderTexture::initialize_internal().
+		 */
+		void initialize_internal();
 
 
 		void setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0);
 		void setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0);
 		void setDepthStencilImpl(TexturePtr depthStencilSurface, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0);
 		void setDepthStencilImpl(TexturePtr depthStencilSurface, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0);
 
 
-		void destroy_internal();
-
 		vector<IDirect3DSurface9*>::type mDX9ColorSurfaces;
 		vector<IDirect3DSurface9*>::type mDX9ColorSurfaces;
 		IDirect3DSurface9* mDX9DepthStencilSurface;
 		IDirect3DSurface9* mDX9DepthStencilSurface;
 	};
 	};

+ 1 - 1
CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h

@@ -293,7 +293,7 @@ namespace CamelotEngine
 		/**
 		/**
 		 * @brief	Called internally by RenderWindowManager whenever a new window is created.
 		 * @brief	Called internally by RenderWindowManager whenever a new window is created.
 		 */
 		 */
-		void registerRenderWindow(D3D9RenderWindowPtr renderWindow);
+		void registerRenderWindow(D3D9RenderWindow* renderWindow);
 	
 	
 		/************************************************************************/
 		/************************************************************************/
 		/* 							Sampler states                     			*/
 		/* 							Sampler states                     			*/

+ 0 - 1
CamelotD3D9Renderer/Include/CmD3D9RenderTexture.h

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

+ 17 - 13
CamelotD3D9Renderer/Include/CmD3D9RenderWindow.h

@@ -37,17 +37,8 @@ namespace CamelotEngine
 	class CM_D3D9_EXPORT D3D9RenderWindow : public RenderWindow
 	class CM_D3D9_EXPORT D3D9RenderWindow : public RenderWindow
 	{
 	{
 	public:
 	public:
-		/** Constructor.
-		@param instance The application instance
-		@param driver The root driver
-		@param deviceIfSwapChain The existing D3D device to create an additional swap chain from, if this is not
-			the first window.
-		*/
-		D3D9RenderWindow					(HINSTANCE instance);
 		~D3D9RenderWindow					();
 		~D3D9RenderWindow					();
 		
 		
-		
-		void				initialize			(const RENDER_WINDOW_DESC& desc);
 		void				setFullscreen		(bool fullScreen, unsigned int width, unsigned int height);
 		void				setFullscreen		(bool fullScreen, unsigned int width, unsigned int height);
 		bool				isActive			() const;
 		bool				isActive			() const;
 		bool				isVisible			() const;
 		bool				isVisible			() const;
@@ -102,6 +93,23 @@ namespace CamelotEngine
 		void adjustWindow(unsigned int clientWidth, unsigned int clientHeight, 
 		void adjustWindow(unsigned int clientWidth, unsigned int clientHeight, 
 			DWORD style, unsigned int* winWidth, unsigned int* winHeight);
 			DWORD style, unsigned int* winWidth, unsigned int* winHeight);
 
 
+	protected:
+		friend class D3D9RenderWindowManager;
+
+		D3D9RenderWindow (const RENDER_WINDOW_DESC& desc, HINSTANCE instance);
+
+		void updateWindowRect();
+
+		/**
+		 * @copydoc RenderWindow::initialize_internal().
+		 */
+		void initialize_internal();
+
+		/**
+		 * @copydoc RenderWindow::destroy_internal().
+		 */
+		void destroy_internal();
+
 	protected:
 	protected:
 		HINSTANCE					mInstance;				// Process instance
 		HINSTANCE					mInstance;				// Process instance
 		D3D9Device* 				mDevice;				// D3D9 device wrapper class.
 		D3D9Device* 				mDevice;				// D3D9 device wrapper class.
@@ -121,10 +129,6 @@ namespace CamelotEngine
 		// Desired width / height after resizing
 		// Desired width / height after resizing
 		unsigned int mDesiredWidth;
 		unsigned int mDesiredWidth;
 		unsigned int mDesiredHeight;
 		unsigned int mDesiredHeight;
-
-		void updateWindowRect();
-
-		void destroy_internal();
 	};
 	};
 }
 }
 #endif
 #endif

+ 2 - 2
CamelotD3D9Renderer/Include/CmD3D9RenderWindowManager.h

@@ -12,9 +12,9 @@ namespace CamelotEngine
 
 
 	protected:
 	protected:
 		/**
 		/**
-		 * @copydoc RenderWindowManager::create()
+		 * @copydoc RenderWindowManager::createImpl()
 		 */
 		 */
-		void createImpl(const RENDER_WINDOW_DESC& desc, AsyncOp& asyncOp);
+		RenderWindowPtr createImpl(const RENDER_WINDOW_DESC& desc);
 
 
 	private:
 	private:
 		D3D9RenderSystem* mRenderSystem;
 		D3D9RenderSystem* mRenderSystem;

+ 2 - 2
CamelotD3D9Renderer/Include/CmD3D9Texture.h

@@ -135,12 +135,12 @@ namespace CamelotEngine {
 		D3D9Texture();
 		D3D9Texture();
 
 
 		/**
 		/**
-		 * @copydoc Resource::initialize_internal()
+		 * @copydoc Texture::initialize_internal()
 		 */
 		 */
 		void initialize_internal();	
 		void initialize_internal();	
 		
 		
 		/**
 		/**
-		 * @copydoc Resource::destroy_internal()
+		 * @copydoc Texture::destroy_internal()
 		 */
 		 */
 		void destroy_internal();
 		void destroy_internal();
 
 

+ 3 - 7
CamelotD3D9Renderer/Include/CmD3D9TextureManager.h

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

+ 13 - 2
CamelotD3D9Renderer/Include/CmD3D9VertexBuffer.h

@@ -39,8 +39,6 @@ namespace CamelotEngine {
     {   
     {   
 
 
     public:
     public:
-		D3D9VertexBuffer(HardwareBufferManager* mgr, UINT32 vertexSize, 
-			UINT32 numVertices, GpuBufferUsage usage, bool useSystemMem);
         ~D3D9VertexBuffer();
         ~D3D9VertexBuffer();
         /** See HardwareBuffer. */
         /** See HardwareBuffer. */
         void readData(UINT32 offset, UINT32 length, void* pDest);
         void readData(UINT32 offset, UINT32 length, void* pDest);
@@ -76,6 +74,11 @@ namespace CamelotEngine {
 			GpuLockOptions					mLockOptions;
 			GpuLockOptions					mLockOptions;
 			UINT32						mLastUsedFrame;
 			UINT32						mLastUsedFrame;
 		};
 		};
+
+		friend class D3D9HardwareBufferManager;
+
+		D3D9VertexBuffer(HardwareBufferManager* mgr, UINT32 vertexSize, 
+			UINT32 numVertices, GpuBufferUsage usage, bool useSystemMem);
 	
 	
 		/** See HardwareBuffer. */
 		/** See HardwareBuffer. */
 		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);		
 		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);		
@@ -84,6 +87,14 @@ namespace CamelotEngine {
 		// updates buffer resources from system memory buffer.
 		// updates buffer resources from system memory buffer.
 		bool updateBufferResources(const char* systemMemoryBuffer, BufferResources* bufferResources);		
 		bool updateBufferResources(const char* systemMemoryBuffer, BufferResources* bufferResources);		
 
 
+		/**
+		 * @copydoc VertexBuffer::initialize_internal()
+		 */
+		void initialize_internal();	
+		
+		/**
+		 * @copydoc VertexBuffer::destroy_internal()
+		 */
 		void destroy_internal();
 		void destroy_internal();
 
 
 		typedef map<IDirect3DDevice9*, BufferResources*>::type	DeviceToBufferResourcesMap;
 		typedef map<IDirect3DDevice9*, BufferResources*>::type	DeviceToBufferResourcesMap;

+ 8 - 2
CamelotD3D9Renderer/Include/CmD3D9VertexDeclaration.h

@@ -37,9 +37,7 @@ namespace CamelotEngine {
     /** Specialisation of VertexDeclaration for D3D9 */
     /** Specialisation of VertexDeclaration for D3D9 */
     class CM_D3D9_EXPORT D3D9VertexDeclaration : public VertexDeclaration, public D3D9Resource
     class CM_D3D9_EXPORT D3D9VertexDeclaration : public VertexDeclaration, public D3D9Resource
     {
     {
-    
     public:
     public:
-        D3D9VertexDeclaration();
         ~D3D9VertexDeclaration();
         ~D3D9VertexDeclaration();
         
         
         /** See VertexDeclaration */
         /** See VertexDeclaration */
@@ -75,7 +73,15 @@ namespace CamelotEngine {
         IDirect3DVertexDeclaration9* getD3DVertexDeclaration(void);
         IDirect3DVertexDeclaration9* getD3DVertexDeclaration(void);
 
 
 	protected:
 	protected:
+		friend class D3D9HardwareBufferManager;
+
+		D3D9VertexDeclaration();
+
 		void releaseDeclaration();
 		void releaseDeclaration();
+
+		/**
+		 * @copydoc VertexDeclaration::destroy_internal().
+		 */
 		void destroy_internal();
 		void destroy_internal();
 
 
 	protected:        
 	protected:        

+ 7 - 6
CamelotD3D9Renderer/Source/CmD3D9GpuBuffer.cpp

@@ -6,12 +6,18 @@ namespace CamelotEngine
 	D3D9GpuBuffer::D3D9GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter) 
 	D3D9GpuBuffer::D3D9GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter) 
 		: GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter)
 		: GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter)
 	{
 	{
-		LOGWRN("Generic buffers are not supported in DirectX 9. Creating a dummy buffer. All operations on it will either be no-op or return a nullptr.");
 	}
 	}
 
 
 	D3D9GpuBuffer::~D3D9GpuBuffer()
 	D3D9GpuBuffer::~D3D9GpuBuffer()
 	{ }
 	{ }
 
 
+	void D3D9GpuBuffer::initialize_internal()
+	{
+		LOGWRN("Generic buffers are not supported in DirectX 9. Creating a dummy buffer. All operations on it will either be no-op or return a nullptr.");
+
+		GpuBuffer::initialize_internal();
+	}
+
 	void* D3D9GpuBuffer::lock(UINT32 offset, UINT32 length, GpuLockOptions options)
 	void* D3D9GpuBuffer::lock(UINT32 offset, UINT32 length, GpuLockOptions options)
 	{
 	{
 		return nullptr;
 		return nullptr;
@@ -42,9 +48,4 @@ namespace CamelotEngine
 	void D3D9GpuBuffer::destroyView(GpuBufferView* view)
 	void D3D9GpuBuffer::destroyView(GpuBufferView* view)
 	{
 	{
 	}
 	}
-
-	void D3D9GpuBuffer::destroy_internal()
-	{
-		GpuBuffer::destroy_internal();
-	}
 }
 }

+ 47 - 50
CamelotD3D9Renderer/Source/CmD3D9GpuProgram.cpp

@@ -46,7 +46,25 @@ namespace CamelotEngine {
 	{
 	{
 
 
 	}
 	}
-    
+	//-----------------------------------------------------------------------------
+	void D3D9GpuProgram::initialize_internal()
+	{
+		for (UINT32 i = 0; i < D3D9RenderSystem::getResourceCreationDeviceCount(); ++i)
+		{
+			IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getResourceCreationDevice(i);
+
+			createInternalResources(d3d9Device);
+		}		       
+
+		GpuProgram::initialize_internal();
+	}
+	//----------------------------------------------------------------------------
+	void D3D9GpuProgram::destroy_internal()
+	{
+		SAFE_RELEASE(mpExternalMicrocode);
+
+		GpuProgram::destroy_internal();
+	}
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
 	void D3D9GpuProgram::setExternalMicrocode(const void* pMicrocode, UINT32 size)
 	void D3D9GpuProgram::setExternalMicrocode(const void* pMicrocode, UINT32 size)
 	{
 	{
@@ -75,18 +93,6 @@ namespace CamelotEngine {
 		return mpExternalMicrocode;
 		return mpExternalMicrocode;
 	}
 	}
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
-    void D3D9GpuProgram::initialize_internal()
-    {
-		for (UINT32 i = 0; i < D3D9RenderSystem::getResourceCreationDeviceCount(); ++i)
-		{
-			IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getResourceCreationDevice(i);
-
-			createInternalResources(d3d9Device);
-		}		       
-
-		GpuProgram::initialize_internal();
-    }
-	//-----------------------------------------------------------------------------
 	void D3D9GpuProgram::createInternalResources(IDirect3DDevice9* d3d9Device)
 	void D3D9GpuProgram::createInternalResources(IDirect3DDevice9* d3d9Device)
 	{
 	{
 		if (mpExternalMicrocode)
 		if (mpExternalMicrocode)
@@ -126,13 +132,6 @@ namespace CamelotEngine {
 			SAFE_RELEASE(errors);
 			SAFE_RELEASE(errors);
 		}
 		}
 	}
 	}
-	//----------------------------------------------------------------------------
-	void D3D9GpuProgram::destroy_internal()
-	{
-		SAFE_RELEASE(mpExternalMicrocode);
-
-		GpuProgram::destroy_internal();
-	}
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
 	GpuParamsPtr D3D9GpuProgram::createParameters()
 	GpuParamsPtr D3D9GpuProgram::createParameters()
 	{
 	{
@@ -152,6 +151,20 @@ namespace CamelotEngine {
 	{	
 	{	
 	}
 	}
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
+	void D3D9GpuVertexProgram::destroy_internal(void)
+	{
+		DeviceToVertexShaderIterator it = mMapDeviceToVertexShader.begin();
+
+		while (it != mMapDeviceToVertexShader.end())
+		{
+			SAFE_RELEASE(it->second);
+			++it;
+		}
+		mMapDeviceToVertexShader.clear();	
+
+		D3D9GpuProgram::destroy_internal();
+	}
+	//-----------------------------------------------------------------------------
     void D3D9GpuVertexProgram::loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode)
     void D3D9GpuVertexProgram::loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode)
     {		 
     {		 
 		DeviceToVertexShaderIterator it = mMapDeviceToVertexShader.find(d3d9Device);
 		DeviceToVertexShaderIterator it = mMapDeviceToVertexShader.find(d3d9Device);
@@ -184,26 +197,10 @@ namespace CamelotEngine {
 		}
 		}
     }
     }
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
-    void D3D9GpuVertexProgram::destroy_internal(void)
-    {
-        DeviceToVertexShaderIterator it = mMapDeviceToVertexShader.begin();
-
-		while (it != mMapDeviceToVertexShader.end())
-		{
-			SAFE_RELEASE(it->second);
-			++it;
-		}
-		mMapDeviceToVertexShader.clear();	
-
-		D3D9GpuProgram::destroy_internal();
-    }
-
-	//-----------------------------------------------------------------------------
 	void D3D9GpuVertexProgram::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
 	void D3D9GpuVertexProgram::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
 	{
 	{
 		
 		
 	}
 	}
-
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
 	void D3D9GpuVertexProgram::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
 	void D3D9GpuVertexProgram::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
 	{
 	{
@@ -249,6 +246,20 @@ namespace CamelotEngine {
 	{
 	{
 	}
 	}
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
+	void D3D9GpuFragmentProgram::destroy_internal()
+	{
+		DeviceToPixelShaderIterator it = mMapDeviceToPixelShader.begin();
+
+		while (it != mMapDeviceToPixelShader.end())
+		{
+			SAFE_RELEASE(it->second);
+			++it;
+		}
+		mMapDeviceToPixelShader.clear();	
+
+		D3D9GpuProgram::destroy_internal();
+	}
+	//-----------------------------------------------------------------------------
     void D3D9GpuFragmentProgram::loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode)
     void D3D9GpuFragmentProgram::loadFromMicrocode(IDirect3DDevice9* d3d9Device, ID3DXBuffer* microcode)
     {
     {
 		DeviceToPixelShaderIterator it = mMapDeviceToPixelShader.find(d3d9Device);
 		DeviceToPixelShaderIterator it = mMapDeviceToPixelShader.find(d3d9Device);
@@ -279,20 +290,6 @@ namespace CamelotEngine {
 
 
 			mMapDeviceToPixelShader[d3d9Device] = NULL;
 			mMapDeviceToPixelShader[d3d9Device] = NULL;
 		}
 		}
-    }
-	//-----------------------------------------------------------------------------
-    void D3D9GpuFragmentProgram::destroy_internal()
-    {
-		DeviceToPixelShaderIterator it = mMapDeviceToPixelShader.begin();
-
-		while (it != mMapDeviceToPixelShader.end())
-		{
-			SAFE_RELEASE(it->second);
-			++it;
-		}
-		mMapDeviceToPixelShader.clear();	
-
-		D3D9GpuProgram::destroy_internal();
     }
     }
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
 	void D3D9GpuFragmentProgram::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
 	void D3D9GpuFragmentProgram::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)

+ 8 - 21
CamelotD3D9Renderer/Source/CmD3D9HardwareBufferManager.cpp

@@ -33,7 +33,8 @@ THE SOFTWARE.
 #include "CmGpuParamBlock.h"
 #include "CmGpuParamBlock.h"
 #include "CmException.h"
 #include "CmException.h"
 
 
-namespace CamelotEngine {
+namespace CamelotEngine 
+{
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     D3D9HardwareBufferManager::D3D9HardwareBufferManager()       
     D3D9HardwareBufferManager::D3D9HardwareBufferManager()       
     {
     {
@@ -43,36 +44,27 @@ namespace CamelotEngine {
     {
     {
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
-    VertexBufferPtr D3D9HardwareBufferManager::createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
+    VertexBufferPtr D3D9HardwareBufferManager::createVertexBufferImpl(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
     {
     {
 		assert (numVerts > 0);
 		assert (numVerts > 0);
 
 
-		D3D9VertexBuffer* vbuf = new D3D9VertexBuffer(
-			this, vertexSize, numVerts, usage, false);
-		{
-			mVertexBuffers.insert(vbuf);
-		}
-        return VertexBufferPtr(vbuf);
+        return VertexBufferPtr(new D3D9VertexBuffer(this, vertexSize, numVerts, usage, false));
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
-	IndexBufferPtr D3D9HardwareBufferManager::createIndexBuffer(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
+	IndexBufferPtr D3D9HardwareBufferManager::createIndexBufferImpl(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
     {
     {
 		assert (numIndexes > 0);
 		assert (numIndexes > 0);
 
 
-		D3D9IndexBuffer* idx = new D3D9IndexBuffer(this, itype, numIndexes, usage, false);
-		{
-			mIndexBuffers.insert(idx);
-		}
-		return IndexBufferPtr(idx);
+		return IndexBufferPtr(new D3D9IndexBuffer(this, itype, numIndexes, usage, false));
             
             
     }
     }
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------
-	GpuParamBlockPtr D3D9HardwareBufferManager::createGpuParamBlock(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage)
+	GpuParamBlockPtr D3D9HardwareBufferManager::createGpuParamBlockImpl(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage)
 	{
 	{
 		return GpuParamBlockPtr(new GpuParamBlock(paramDesc, usage));
 		return GpuParamBlockPtr(new GpuParamBlock(paramDesc, usage));
 	}
 	}
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------
-	GpuBufferPtr D3D9HardwareBufferManager::createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
+	GpuBufferPtr D3D9HardwareBufferManager::createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
 		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
 		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
 	{
 	{
 		return GpuBufferPtr(new D3D9GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
 		return GpuBufferPtr(new D3D9GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
@@ -82,9 +74,4 @@ namespace CamelotEngine {
     {
     {
         return VertexDeclarationPtr(new D3D9VertexDeclaration());
         return VertexDeclarationPtr(new D3D9VertexDeclaration());
     }
     }
-    //-----------------------------------------------------------------------
-    void D3D9HardwareBufferManager::destroyVertexDeclarationImpl(VertexDeclaration* decl)
-    {
-        delete decl;
-    }
 }
 }

+ 32 - 25
CamelotD3D9Renderer/Source/CmD3D9IndexBuffer.cpp

@@ -41,19 +41,27 @@ namespace CamelotEngine {
         bool useSystemMemory)
         bool useSystemMemory)
         : IndexBuffer(mgr, idxType, numIndexes, usage, useSystemMemory)
         : IndexBuffer(mgr, idxType, numIndexes, usage, useSystemMemory)
     {
     {
+			
+    }
+	//---------------------------------------------------------------------
+    D3D9IndexBuffer::~D3D9IndexBuffer()
+    { }
+	//---------------------------------------------------------------------
+	void D3D9IndexBuffer::initialize_internal()
+	{
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
 
 
 		D3DPOOL eResourcePool;
 		D3DPOOL eResourcePool;
 
 
 #if CM_D3D_MANAGE_BUFFERS
 #if CM_D3D_MANAGE_BUFFERS
-		eResourcePool = useSystemMemory ? D3DPOOL_SYSTEMMEM : D3DPOOL_MANAGED;
+		eResourcePool = mSystemMemory ? D3DPOOL_SYSTEMMEM : D3DPOOL_MANAGED;
 #else
 #else
-		eResourcePool = useSystemMemory? D3DPOOL_SYSTEMMEM : D3DPOOL_DEFAULT;
+		eResourcePool = mSystemMemory? D3DPOOL_SYSTEMMEM : D3DPOOL_DEFAULT;
 #endif
 #endif
 
 
 		// Set the desired memory pool.
 		// Set the desired memory pool.
 		mBufferDesc.Pool = eResourcePool;
 		mBufferDesc.Pool = eResourcePool;
-				
+
 		// Allocate the system memory buffer.
 		// Allocate the system memory buffer.
 		mSystemMemoryBuffer = new char [getSizeInBytes()];
 		mSystemMemoryBuffer = new char [getSizeInBytes()];
 		memset(mSystemMemoryBuffer, 0, getSizeInBytes());
 		memset(mSystemMemoryBuffer, 0, getSizeInBytes());
@@ -67,11 +75,28 @@ namespace CamelotEngine {
 
 
 				createBuffer(d3d9Device, mBufferDesc.Pool);
 				createBuffer(d3d9Device, mBufferDesc.Pool);
 			}
 			}
-		}				
-    }
+		}	
+
+		IndexBuffer::initialize_internal();
+	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
-    D3D9IndexBuffer::~D3D9IndexBuffer()
-    { }
+	void D3D9IndexBuffer::destroy_internal()
+	{
+		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
+
+			DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.begin();
+
+		while (it != mMapDeviceToBufferResources.end())
+		{
+			SAFE_RELEASE(it->second->mBuffer);
+			SAFE_DELETE(it->second);
+			++it;
+		}	
+		mMapDeviceToBufferResources.clear();   
+		SAFE_DELETE_ARRAY(mSystemMemoryBuffer);
+
+		IndexBuffer::destroy_internal();
+	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
     void* D3D9IndexBuffer::lockImpl(UINT32 offset, 
     void* D3D9IndexBuffer::lockImpl(UINT32 offset, 
         UINT32 length, GpuLockOptions options)
         UINT32 length, GpuLockOptions options)
@@ -325,22 +350,4 @@ namespace CamelotEngine {
 
 
 		return true;			
 		return true;			
 	}
 	}
-	//---------------------------------------------------------------------
-	void D3D9IndexBuffer::destroy_internal()
-	{
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-			DeviceToBufferResourcesIterator it = mMapDeviceToBufferResources.begin();
-
-		while (it != mMapDeviceToBufferResources.end())
-		{
-			SAFE_RELEASE(it->second->mBuffer);
-			SAFE_DELETE(it->second);
-			++it;
-		}	
-		mMapDeviceToBufferResources.clear();   
-		SAFE_DELETE_ARRAY(mSystemMemoryBuffer);
-
-		IndexBuffer::destroy_internal();
-	}
 }
 }

+ 2 - 7
CamelotD3D9Renderer/Source/CmD3D9MultiRenderTexture.cpp

@@ -15,9 +15,9 @@ namespace CamelotEngine
 
 
 	}
 	}
 
 
-	void D3D9MultiRenderTexture::destroy_internal()
+	void D3D9MultiRenderTexture::initialize_internal()
 	{
 	{
-		MultiRenderTexture::destroy_internal();
+		mDX9ColorSurfaces.resize(CM_MAX_MULTIPLE_RENDER_TARGETS);
 	}
 	}
 
 
 	void D3D9MultiRenderTexture::setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
 	void D3D9MultiRenderTexture::setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face, UINT32 numFaces, UINT32 mipLevel)
@@ -72,9 +72,4 @@ namespace CamelotEngine
 			return;
 			return;
 		}
 		}
 	}
 	}
-
-	void D3D9MultiRenderTexture::initialize()
-	{
-		mDX9ColorSurfaces.resize(CM_MAX_MULTIPLE_RENDER_TARGETS);
-	}
 }
 }

+ 4 - 4
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -228,7 +228,7 @@ namespace CamelotEngine
 		msD3D9RenderSystem = NULL;
 		msD3D9RenderSystem = NULL;
 	}
 	}
 	//--------------------------------------------------------------------
 	//--------------------------------------------------------------------
-	void D3D9RenderSystem::registerRenderWindow(D3D9RenderWindowPtr renderWindow)
+	void D3D9RenderSystem::registerRenderWindow(D3D9RenderWindow* renderWindow)
 	{		
 	{		
 		THROW_IF_NOT_RENDER_THREAD;
 		THROW_IF_NOT_RENDER_THREAD;
 
 
@@ -238,7 +238,7 @@ namespace CamelotEngine
 
 
 		try
 		try
 		{
 		{
-			mDeviceManager->linkRenderWindow(renderWindow.get());
+			mDeviceManager->linkRenderWindow(renderWindow);
 		}
 		}
 		catch (const CamelotEngine::RenderingAPIException&)
 		catch (const CamelotEngine::RenderingAPIException&)
 		{
 		{
@@ -252,9 +252,9 @@ namespace CamelotEngine
 		mResourceManager->unlockDeviceAccess();
 		mResourceManager->unlockDeviceAccess();
 
 
 		// TODO - Storing raw pointer here might not be a good idea?
 		// TODO - Storing raw pointer here might not be a good idea?
-		mRenderWindows.push_back(renderWindow.get());		
+		mRenderWindows.push_back(renderWindow);		
 
 
-		updateRenderSystemCapabilities(renderWindow.get());
+		updateRenderSystemCapabilities(renderWindow);
 
 
 		attachRenderTarget(*renderWindow);
 		attachRenderTarget(*renderWindow);
 	}	
 	}	

+ 0 - 5
CamelotD3D9Renderer/Source/CmD3D9RenderTexture.cpp

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

+ 63 - 58
CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp

@@ -36,8 +36,8 @@ THE SOFTWARE.
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
-	D3D9RenderWindow::D3D9RenderWindow(HINSTANCE instance)
-        : mInstance(instance), mIsDepthBuffered(true)  
+	D3D9RenderWindow::D3D9RenderWindow(const RENDER_WINDOW_DESC& desc, HINSTANCE instance)
+        : RenderWindow(desc), mInstance(instance), mIsDepthBuffered(true)  
 	{
 	{
 		mDevice = NULL;
 		mDevice = NULL;
 		mIsFullScreen = false;		
 		mIsFullScreen = false;		
@@ -54,36 +54,15 @@ namespace CamelotEngine
 	D3D9RenderWindow::~D3D9RenderWindow()
 	D3D9RenderWindow::~D3D9RenderWindow()
 	{ }
 	{ }
 
 
-	void D3D9RenderWindow::destroy_internal()
-	{
-		if (mDevice != NULL)
-		{
-			mDevice->detachRenderWindow(this);
-			mDevice = NULL;
-		}
-
-		if (mHWnd && !mIsExternal)
-		{
-			WindowEventUtilities::_removeRenderWindow(this);
-			DestroyWindow(mHWnd);
-		}
-
-		mHWnd = 0;
-		mActive = false;
-		mClosed = true;
-
-		RenderWindow::destroy_internal();
-	}
-
-	void D3D9RenderWindow::initialize(const RENDER_WINDOW_DESC& desc)
+	void D3D9RenderWindow::initialize_internal()
 	{
 	{
 		HINSTANCE hInst = mInstance;
 		HINSTANCE hInst = mInstance;
-	
+
 		mFSAAType = D3DMULTISAMPLE_NONE;
 		mFSAAType = D3DMULTISAMPLE_NONE;
 		mFSAAQuality = 0;
 		mFSAAQuality = 0;
-		mFSAA = desc.FSAA;
-		mVSync = desc.vsync;
-		mVSyncInterval = desc.vsyncInterval;
+		mFSAA = mDesc.FSAA;
+		mVSync = mDesc.vsync;
+		mVSyncInterval = mDesc.vsyncInterval;
 		mUseNVPerfHUD = false;
 		mUseNVPerfHUD = false;
 
 
 		HWND parentHWnd = 0;
 		HWND parentHWnd = 0;
@@ -91,12 +70,12 @@ namespace CamelotEngine
 
 
 		NameValuePairList::const_iterator opt;
 		NameValuePairList::const_iterator opt;
 		// parentWindowHandle		-> parentHWnd
 		// parentWindowHandle		-> parentHWnd
-		opt = desc.platformSpecific.find("parentWindowHandle");
-		if(opt != desc.platformSpecific.end())
+		opt = mDesc.platformSpecific.find("parentWindowHandle");
+		if(opt != mDesc.platformSpecific.end())
 			parentHWnd = (HWND)parseUnsignedInt(opt->second);
 			parentHWnd = (HWND)parseUnsignedInt(opt->second);
 		// externalWindowHandle		-> externalHandle
 		// externalWindowHandle		-> externalHandle
-		opt = desc.platformSpecific.find("externalWindowHandle");
-		if(opt != desc.platformSpecific.end())
+		opt = mDesc.platformSpecific.find("externalWindowHandle");
+		if(opt != mDesc.platformSpecific.end())
 			externalHandle = (HWND)parseUnsignedInt(opt->second);
 			externalHandle = (HWND)parseUnsignedInt(opt->second);
 
 
 		if (!externalHandle)
 		if (!externalHandle)
@@ -108,13 +87,13 @@ namespace CamelotEngine
 			RECT		rc;
 			RECT		rc;
 
 
 			// If we specified which adapter we want to use - find it's monitor.
 			// If we specified which adapter we want to use - find it's monitor.
-			if (desc.monitorIndex != -1)
+			if (mDesc.monitorIndex != -1)
 			{
 			{
 				IDirect3D9* direct3D9 = D3D9RenderSystem::getDirect3D9();
 				IDirect3D9* direct3D9 = D3D9RenderSystem::getDirect3D9();
 
 
 				for (UINT32 i=0; i < direct3D9->GetAdapterCount(); ++i)
 				for (UINT32 i=0; i < direct3D9->GetAdapterCount(); ++i)
 				{
 				{
-					if (i == desc.monitorIndex)
+					if (i == mDesc.monitorIndex)
 					{
 					{
 						hMonitor = direct3D9->GetAdapterMonitor(i);
 						hMonitor = direct3D9->GetAdapterMonitor(i);
 						break;
 						break;
@@ -128,8 +107,8 @@ namespace CamelotEngine
 				POINT windowAnchorPoint;
 				POINT windowAnchorPoint;
 
 
 				// Fill in anchor point.
 				// Fill in anchor point.
-				windowAnchorPoint.x = desc.left;
-				windowAnchorPoint.y = desc.top;
+				windowAnchorPoint.x = mDesc.left;
+				windowAnchorPoint.y = mDesc.top;
 
 
 				// Get the nearest monitor to this window.
 				// Get the nearest monitor to this window.
 				hMonitor = MonitorFromPoint(windowAnchorPoint, MONITOR_DEFAULTTOPRIMARY);
 				hMonitor = MonitorFromPoint(windowAnchorPoint, MONITOR_DEFAULTTOPRIMARY);
@@ -142,11 +121,11 @@ namespace CamelotEngine
 
 
 
 
 			unsigned int winWidth, winHeight;
 			unsigned int winWidth, winHeight;
-			winWidth = desc.width;
-			winHeight = desc.height;
+			winWidth = mDesc.width;
+			winHeight = mDesc.height;
 
 
-			UINT32 left = desc.left;
-			UINT32 top = desc.top;
+			UINT32 left = mDesc.left;
+			UINT32 top = mDesc.top;
 
 
 			// No specified top left -> Center the window in the middle of the monitor
 			// No specified top left -> Center the window in the middle of the monitor
 			if (left == -1 || top == -1)
 			if (left == -1 || top == -1)
@@ -160,26 +139,26 @@ namespace CamelotEngine
 
 
 				if (left == -1)
 				if (left == -1)
 					left = monitorInfo.rcWork.left + (screenw - outerw) / 2;
 					left = monitorInfo.rcWork.left + (screenw - outerw) / 2;
-				else if (desc.monitorIndex != -1)
+				else if (mDesc.monitorIndex != -1)
 					left += monitorInfo.rcWork.left;
 					left += monitorInfo.rcWork.left;
 
 
 				if (top == -1)
 				if (top == -1)
 					top = monitorInfo.rcWork.top + (screenh - outerh) / 2;
 					top = monitorInfo.rcWork.top + (screenh - outerh) / 2;
-				else if (desc.monitorIndex != -1)
+				else if (mDesc.monitorIndex != -1)
 					top += monitorInfo.rcWork.top;
 					top += monitorInfo.rcWork.top;
 			}
 			}
-			else if (desc.monitorIndex != -1)
+			else if (mDesc.monitorIndex != -1)
 			{
 			{
 				left += monitorInfo.rcWork.left;
 				left += monitorInfo.rcWork.left;
 				top += monitorInfo.rcWork.top;
 				top += monitorInfo.rcWork.top;
 			}
 			}
 
 
-			mWidth = mDesiredWidth = desc.width;
-			mHeight = mDesiredHeight = desc.height;
+			mWidth = mDesiredWidth = mDesc.width;
+			mHeight = mDesiredHeight = mDesc.height;
 			mTop = top;
 			mTop = top;
 			mLeft = left;
 			mLeft = left;
 
 
-			if (desc.fullscreen)
+			if (mDesc.fullscreen)
 			{
 			{
 				dwStyleEx |= WS_EX_TOPMOST;
 				dwStyleEx |= WS_EX_TOPMOST;
 				dwStyle |= WS_POPUP;
 				dwStyle |= WS_POPUP;
@@ -194,18 +173,18 @@ namespace CamelotEngine
 				}
 				}
 				else
 				else
 				{
 				{
-					if (desc.border == "none")
+					if (mDesc.border == "none")
 						dwStyle |= WS_POPUP;
 						dwStyle |= WS_POPUP;
-					else if (desc.border == "fixed")
+					else if (mDesc.border == "fixed")
 						dwStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION |
 						dwStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION |
 						WS_SYSMENU | WS_MINIMIZEBOX;
 						WS_SYSMENU | WS_MINIMIZEBOX;
 					else
 					else
 						dwStyle |= WS_OVERLAPPEDWINDOW;
 						dwStyle |= WS_OVERLAPPEDWINDOW;
 				}
 				}
 
 
-				adjustWindow(desc.width, desc.height, dwStyle, &winWidth, &winHeight);
+				adjustWindow(mDesc.width, mDesc.height, dwStyle, &winWidth, &winHeight);
 
 
-				if (!desc.outerDimensions)
+				if (!mDesc.outerDimensions)
 				{
 				{
 					// Calculate window dimensions required
 					// Calculate window dimensions required
 					// to get the requested client area
 					// to get the requested client area
@@ -220,7 +199,7 @@ namespace CamelotEngine
 
 
 					if (mTop < monitorInfo.rcWork.top)					
 					if (mTop < monitorInfo.rcWork.top)					
 						mTop = monitorInfo.rcWork.top;					
 						mTop = monitorInfo.rcWork.top;					
-				
+
 					if (static_cast<int>(winWidth) > monitorInfo.rcWork.right - mLeft)					
 					if (static_cast<int>(winWidth) > monitorInfo.rcWork.right - mLeft)					
 						winWidth = monitorInfo.rcWork.right - mLeft;	
 						winWidth = monitorInfo.rcWork.right - mLeft;	
 
 
@@ -228,7 +207,7 @@ namespace CamelotEngine
 						winHeight = monitorInfo.rcWork.bottom - mTop;										
 						winHeight = monitorInfo.rcWork.bottom - mTop;										
 				}
 				}
 			}
 			}
-			
+
 
 
 			// Register the window class
 			// Register the window class
 			// NB allow 4 bytes of window data for D3D9RenderWindow pointer
 			// NB allow 4 bytes of window data for D3D9RenderWindow pointer
@@ -240,7 +219,7 @@ namespace CamelotEngine
 			// Create our main window
 			// Create our main window
 			// Pass pointer to self
 			// Pass pointer to self
 			mIsExternal = false;
 			mIsExternal = false;
-			mHWnd = CreateWindowEx(dwStyleEx, "D3D9Wnd", desc.title.c_str(), dwStyle,
+			mHWnd = CreateWindowEx(dwStyleEx, "D3D9Wnd", mDesc.title.c_str(), dwStyle,
 				mLeft, mTop, winWidth, winHeight, parentHWnd, 0, hInst, this);
 				mLeft, mTop, winWidth, winHeight, parentHWnd, 0, hInst, this);
 			mStyle = dwStyle;
 			mStyle = dwStyle;
 
 
@@ -262,13 +241,39 @@ namespace CamelotEngine
 		mWidth = rc.right;
 		mWidth = rc.right;
 		mHeight = rc.bottom;
 		mHeight = rc.bottom;
 
 
-		mName = desc.title;
-		mIsDepthBuffered = desc.depthBuffer;
-		mIsFullScreen = desc.fullscreen;
-		mColorDepth = desc.colorDepth;
-									
+		mName = mDesc.title;
+		mIsDepthBuffered = mDesc.depthBuffer;
+		mIsFullScreen = mDesc.fullscreen;
+		mColorDepth = mDesc.colorDepth;
+
 		mActive = true;
 		mActive = true;
 		mClosed = false;
 		mClosed = false;
+
+		D3D9RenderSystem* rs = static_cast<D3D9RenderSystem*>(RenderSystem::instancePtr());
+		rs->registerRenderWindow(this);
+
+		RenderWindow::initialize_internal();
+	}
+
+	void D3D9RenderWindow::destroy_internal()
+	{
+		if (mDevice != NULL)
+		{
+			mDevice->detachRenderWindow(this);
+			mDevice = NULL;
+		}
+
+		if (mHWnd && !mIsExternal)
+		{
+			WindowEventUtilities::_removeRenderWindow(this);
+			DestroyWindow(mHWnd);
+		}
+
+		mHWnd = 0;
+		mActive = false;
+		mClosed = true;
+
+		RenderWindow::destroy_internal();
 	}
 	}
 
 
 	void D3D9RenderWindow::setFullscreen(bool fullScreen, unsigned int width, unsigned int height)
 	void D3D9RenderWindow::setFullscreen(bool fullScreen, unsigned int width, unsigned int height)

+ 2 - 10
CamelotD3D9Renderer/Source/CmD3D9RenderWindowManager.cpp

@@ -11,16 +11,8 @@ namespace CamelotEngine
 		assert(mRenderSystem != nullptr);
 		assert(mRenderSystem != nullptr);
 	}
 	}
 
 
-	void D3D9RenderWindowManager::createImpl(const RENDER_WINDOW_DESC& desc, AsyncOp& asyncOp)
+	RenderWindowPtr D3D9RenderWindowManager::createImpl(const RENDER_WINDOW_DESC& desc)
 	{
 	{
-		// Create the window
-		D3D9RenderWindow* renderWindow = new D3D9RenderWindow(mRenderSystem->getInstanceHandle());
-
-		renderWindow->initialize(desc);
-
-		D3D9RenderWindowPtr winPtr(renderWindow);
-		mRenderSystem->registerRenderWindow(winPtr);
-
-		asyncOp.completeOperation(std::static_pointer_cast<RenderWindow>(winPtr));
+		return RenderWindowPtr(new D3D9RenderWindow(desc, mRenderSystem->getInstanceHandle()));
 	}
 	}
 }
 }

+ 3 - 3
CamelotD3D9Renderer/Source/CmD3D9Texture.cpp

@@ -203,14 +203,14 @@ namespace CamelotEngine
 	{ 
 	{ 
 		THROW_IF_NOT_RENDER_THREAD;
 		THROW_IF_NOT_RENDER_THREAD;
 
 
+		Texture::initialize_internal();
+
 		for (UINT32 i = 0; i < D3D9RenderSystem::getResourceCreationDeviceCount(); ++i)
 		for (UINT32 i = 0; i < D3D9RenderSystem::getResourceCreationDeviceCount(); ++i)
 		{
 		{
 			IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getResourceCreationDevice(i);
 			IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getResourceCreationDevice(i);
 
 
 			createInternalResources(d3d9Device);
 			createInternalResources(d3d9Device);
 		}
 		}
-
-		Resource::initialize_internal();
 	}
 	}
 	/****************************************************************************************/
 	/****************************************************************************************/
 	void D3D9Texture::destroy_internal()
 	void D3D9Texture::destroy_internal()
@@ -240,7 +240,7 @@ namespace CamelotEngine
 		
 		
 		clearBufferViews();
 		clearBufferViews();
 
 
-		CoreGpuObject::destroy_internal();
+		Texture::destroy_internal();
 	}
 	}
 	/****************************************************************************************/
 	/****************************************************************************************/
 	D3D9Texture::TextureResources* D3D9Texture::getTextureResources(IDirect3DDevice9* d3d9Device)
 	D3D9Texture::TextureResources* D3D9Texture::getTextureResources(IDirect3DDevice9* d3d9Device)

+ 6 - 9
CamelotD3D9Renderer/Source/CmD3D9TextureManager.cpp

@@ -45,22 +45,19 @@ namespace CamelotEngine
 
 
 	}
 	}
 
 
-    Texture* D3D9TextureManager::createTextureImpl()
+    TexturePtr D3D9TextureManager::createTextureImpl()
     {
     {
-		return new D3D9Texture();
+		return TexturePtr(new D3D9Texture());
     }
     }
 
 
-	RenderTexture* D3D9TextureManager::createRenderTextureImpl()
+	RenderTexturePtr D3D9TextureManager::createRenderTextureImpl()
 	{
 	{
-		return new D3D9RenderTexture();
+		return RenderTexturePtr(new D3D9RenderTexture());
 	}
 	}
 
 
-	MultiRenderTexturePtr D3D9TextureManager::createMultiRenderTexture()
+	MultiRenderTexturePtr D3D9TextureManager::createMultiRenderTextureImpl()
 	{
 	{
-		D3D9MultiRenderTexture* newMRT = new D3D9MultiRenderTexture();
-		newMRT->initialize();
-
-		return MultiRenderTexturePtr(newMRT);
+		return MultiRenderTexturePtr(new D3D9MultiRenderTexture());
 	}
 	}
 
 
 	PixelFormat D3D9TextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage)
 	PixelFormat D3D9TextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage)

+ 34 - 29
CamelotD3D9Renderer/Source/CmD3D9VertexBuffer.cpp

@@ -40,35 +40,7 @@ namespace CamelotEngine {
         UINT32 numVertices, GpuBufferUsage usage, 
         UINT32 numVertices, GpuBufferUsage usage, 
         bool useSystemMemory)
         bool useSystemMemory)
 		: VertexBuffer(mgr, vertexSize, numVertices, usage, useSystemMemory)
 		: VertexBuffer(mgr, vertexSize, numVertices, usage, useSystemMemory)
-    {
-		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
-
-		D3DPOOL eResourcePool;
-		       
-#if CM_D3D_MANAGE_BUFFERS
-		eResourcePool = useSystemMemory? D3DPOOL_SYSTEMMEM : D3DPOOL_MANAGED;
-#else
-		eResourcePool = useSystemMemory? D3DPOOL_SYSTEMMEM : D3DPOOL_DEFAULT;
-#endif       		
-
-		// Set the desired memory pool.
-		mBufferDesc.Pool = eResourcePool;
-
-		// Allocate the system memory buffer.
-		mSystemMemoryBuffer = new char [getSizeInBytes()];
-		memset(mSystemMemoryBuffer, 0, getSizeInBytes());	
-
-		// Case we have to create this buffer resource on loading.
-		if (D3D9RenderSystem::getResourceManager()->getCreationPolicy() == RCP_CREATE_ON_ALL_DEVICES)
-		{
-			for (UINT32 i = 0; i < D3D9RenderSystem::getResourceCreationDeviceCount(); ++i)
-			{
-				IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getResourceCreationDevice(i);
-
-				createBuffer(d3d9Device, mBufferDesc.Pool);
-			}
-		}				
-    }
+    {    }
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
     D3D9VertexBuffer::~D3D9VertexBuffer()
     D3D9VertexBuffer::~D3D9VertexBuffer()
     {	    }
     {	    }
@@ -324,6 +296,39 @@ namespace CamelotEngine {
 
 
 		return true;		
 		return true;		
 	}
 	}
+	//--------------------------------------------------------------------
+	void D3D9VertexBuffer::initialize_internal()
+	{
+		D3D9_DEVICE_ACCESS_CRITICAL_SECTION
+
+		D3DPOOL eResourcePool;
+
+#if CM_D3D_MANAGE_BUFFERS
+		eResourcePool = mSystemMemory ? D3DPOOL_SYSTEMMEM : D3DPOOL_MANAGED;
+#else
+		eResourcePool = mSystemMemory ? D3DPOOL_SYSTEMMEM : D3DPOOL_DEFAULT;
+#endif       		
+
+		// Set the desired memory pool.
+		mBufferDesc.Pool = eResourcePool;
+
+		// Allocate the system memory buffer.
+		mSystemMemoryBuffer = new char [getSizeInBytes()];
+		memset(mSystemMemoryBuffer, 0, getSizeInBytes());	
+
+		// Case we have to create this buffer resource on loading.
+		if (D3D9RenderSystem::getResourceManager()->getCreationPolicy() == RCP_CREATE_ON_ALL_DEVICES)
+		{
+			for (UINT32 i = 0; i < D3D9RenderSystem::getResourceCreationDeviceCount(); ++i)
+			{
+				IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getResourceCreationDevice(i);
+
+				createBuffer(d3d9Device, mBufferDesc.Pool);
+			}
+		}
+
+		VertexBuffer::initialize_internal();
+	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
 	void D3D9VertexBuffer::destroy_internal()
 	void D3D9VertexBuffer::destroy_internal()
 	{
 	{

+ 7 - 7
CamelotD3D9Renderer/Source/CmD3D9VertexDeclaration.cpp

@@ -41,6 +41,13 @@ namespace CamelotEngine {
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     D3D9VertexDeclaration::~D3D9VertexDeclaration()
     D3D9VertexDeclaration::~D3D9VertexDeclaration()
     {    }
     {    }
+	//-----------------------------------------------------------------------
+	void D3D9VertexDeclaration::destroy_internal()
+	{
+		releaseDeclaration();
+
+		VertexDeclaration::destroy_internal();
+	}
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     const VertexElement& D3D9VertexDeclaration::addElement(unsigned short source, 
     const VertexElement& D3D9VertexDeclaration::addElement(unsigned short source, 
         UINT32 offset, VertexElementType theType,
         UINT32 offset, VertexElementType theType,
@@ -184,12 +191,5 @@ namespace CamelotEngine {
 		}	
 		}	
 		mMapDeviceToDeclaration.clear();
 		mMapDeviceToDeclaration.clear();
 	}
 	}
-	//-----------------------------------------------------------------------
-	void D3D9VertexDeclaration::destroy_internal()
-	{
-		releaseDeclaration();
-
-		VertexDeclaration::destroy_internal();
-	}
 }
 }
 
 

+ 8 - 2
CamelotGLRenderer/Include/CmGLGpuBuffer.h

@@ -8,7 +8,6 @@ namespace CamelotEngine
 	class CM_RSGL_EXPORT GLGpuBuffer : public GpuBuffer
 	class CM_RSGL_EXPORT GLGpuBuffer : public GpuBuffer
 	{
 	{
 	public:
 	public:
-		GLGpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
         ~GLGpuBuffer();
         ~GLGpuBuffer();
 
 
 		/**
 		/**
@@ -39,9 +38,16 @@ namespace CamelotEngine
 			UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
 			UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
 
 
 	protected:
 	protected:
+		friend class GLHardwareBufferManager;
+
+		GLGpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
+
 		virtual GpuBufferView* createView();
 		virtual GpuBufferView* createView();
 		virtual void destroyView(GpuBufferView* view);
 		virtual void destroyView(GpuBufferView* view);
 
 
-		void destroy_internal();
+		/**
+		 * @copydoc GpuBuffer::initialize_internal()
+		 */
+		void initialize_internal();	
 	};
 	};
 }
 }

+ 29 - 29
CamelotGLRenderer/Include/CmGLHardwareBufferManager.h

@@ -40,39 +40,10 @@ namespace CamelotEngine {
     /** Implementation of HardwareBufferManager for OpenGL. */
     /** Implementation of HardwareBufferManager for OpenGL. */
     class CM_RSGL_EXPORT GLHardwareBufferManager : public HardwareBufferManager
     class CM_RSGL_EXPORT GLHardwareBufferManager : public HardwareBufferManager
     {
     {
-	protected:
-		char* mScratchBufferPool;
-		CM_MUTEX(mScratchMutex)
-		UINT32 mMapBufferThreshold;
-
     public:
     public:
         GLHardwareBufferManager();
         GLHardwareBufferManager();
         ~GLHardwareBufferManager();
         ~GLHardwareBufferManager();
 
 
-		/**
-		 * @copydoc HardwareBufferManager::createVertexBuffer
-		 */
-        VertexBufferPtr createVertexBuffer(UINT32 vertexSize, 
-            UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
-
-		/**
-		 * @copydoc HardwareBufferManager::createIndexBuffer
-		 */
-        IndexBufferPtr createIndexBuffer(
-            IndexBuffer::IndexType itype, UINT32 numIndexes, 
-            GpuBufferUsage usage);
-
-		/** @copydoc HardwareBufferManager::createGpuParamBlock */
-		GpuParamBlockPtr createGpuParamBlock(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage = GPBU_STATIC);
-
-		/**
-		 * @copydoc HardwareBufferManager::createGenericBuffer
-		 *
-		 * OpenGL does not support generic buffers so this method will return a dummy instance.
-		 */
-		GpuBufferPtr createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
-			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
-
         /// Utility function to get the correct GL usage based on HBU's
         /// Utility function to get the correct GL usage based on HBU's
         static GLenum getGLUsage(unsigned int usage);
         static GLenum getGLUsage(unsigned int usage);
 
 
@@ -95,6 +66,35 @@ namespace CamelotEngine {
 		*/
 		*/
 		const UINT32 getGLMapBufferThreshold() const;
 		const UINT32 getGLMapBufferThreshold() const;
 		void setGLMapBufferThreshold( const UINT32 value );
 		void setGLMapBufferThreshold( const UINT32 value );
+
+	protected:
+		char* mScratchBufferPool;
+		CM_MUTEX(mScratchMutex);
+		UINT32 mMapBufferThreshold;
+
+		/**
+		 * @copydoc HardwareBufferManager::createVertexBufferImpl
+		 */
+        VertexBufferPtr createVertexBufferImpl(UINT32 vertexSize, 
+            UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
+
+		/**
+		 * @copydoc HardwareBufferManager::createIndexBufferImpl
+		 */
+        IndexBufferPtr createIndexBufferImpl(
+            IndexBuffer::IndexType itype, UINT32 numIndexes, 
+            GpuBufferUsage usage);
+
+		/** @copydoc HardwareBufferManager::createGpuParamBlockImpl */
+		GpuParamBlockPtr 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, 
+			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
     };
     };
 }
 }
 
 

+ 13 - 2
CamelotGLRenderer/Include/CmGLIndexBuffer.h

@@ -37,8 +37,6 @@ namespace CamelotEngine {
     class CM_RSGL_EXPORT GLIndexBuffer : public IndexBuffer
     class CM_RSGL_EXPORT GLIndexBuffer : public IndexBuffer
     {
     {
     public:
     public:
-        GLIndexBuffer(HardwareBufferManager* mgr, IndexType idxType, UINT32 numIndexes, 
-            GpuBufferUsage usage); 
         ~GLIndexBuffer();
         ~GLIndexBuffer();
         /** See HardwareBuffer. */
         /** See HardwareBuffer. */
         void readData(UINT32 offset, UINT32 length, void* pDest);
         void readData(UINT32 offset, UINT32 length, void* pDest);
@@ -49,11 +47,24 @@ namespace CamelotEngine {
         GLuint getGLBufferId(void) const { return mBufferId; }
         GLuint getGLBufferId(void) const { return mBufferId; }
 
 
 	protected:
 	protected:
+		friend class GLHardwareBufferManager;
+
+		GLIndexBuffer(HardwareBufferManager* mgr, IndexType idxType, UINT32 numIndexes, 
+			GpuBufferUsage usage); 
+
 		/** See HardwareBuffer. */
 		/** See HardwareBuffer. */
 		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
 		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
 		/** See HardwareBuffer. */
 		/** See HardwareBuffer. */
 		void unlockImpl(void);
 		void unlockImpl(void);
 
 
+		/**
+		 * @copydoc IndexBuffer::initialize_internal()
+		 */
+		void initialize_internal();	
+		
+		/**
+		 * @copydoc IndexBuffer::destroy_internal()
+		 */
 		void destroy_internal();
 		void destroy_internal();
 
 
 	private:
 	private:

+ 8 - 1
CamelotGLRenderer/Include/CmGLMultiRenderTexture.h

@@ -17,11 +17,18 @@ namespace CamelotEngine
 		friend class GLTextureManager;
 		friend class GLTextureManager;
 
 
 		GLMultiRenderTexture();
 		GLMultiRenderTexture();
-		void initialize();
 
 
 		void setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 0, UINT32 mipLevel = 0);
 		void setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 0, UINT32 mipLevel = 0);
 		void setDepthStencilImpl(TexturePtr depthStencilSurface, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0);
 		void setDepthStencilImpl(TexturePtr depthStencilSurface, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0);
 
 
+		/**
+		 * @copydoc MultiRenderTexture::initialize_internal().
+		 */
+		void initialize_internal();
+
+		/**
+		 * @copydoc MultiRenderTexture::destroy_internal().
+		 */
 		void destroy_internal();
 		void destroy_internal();
 	private:
 	private:
 		GLFrameBufferObject* mFB;
 		GLFrameBufferObject* mFB;

+ 4 - 0
CamelotGLRenderer/Include/CmGLRenderTexture.h

@@ -53,6 +53,10 @@ namespace CamelotEngine
 		friend class GLTextureManager;
 		friend class GLTextureManager;
 
 
 		GLRenderTexture();
 		GLRenderTexture();
+
+		/**
+		 * @copydoc RenderTexture::destroy_internal().
+		 */
 		void destroy_internal();
 		void destroy_internal();
 
 
 		GLFrameBufferObject* mFB;
 		GLFrameBufferObject* mFB;

+ 2 - 2
CamelotGLRenderer/Include/CmGLRenderWindowManager.h

@@ -12,9 +12,9 @@ namespace CamelotEngine
 
 
 	protected:
 	protected:
 		/**
 		/**
-		 * @copydoc RenderWindowManager::create()
+		 * @copydoc RenderWindowManager::createImpl()
 		 */
 		 */
-		void createImpl(const RENDER_WINDOW_DESC& desc, AsyncOp& asyncOp);
+		RenderWindowPtr createImpl(const RENDER_WINDOW_DESC& desc);
 
 
 	private:
 	private:
 		GLRenderSystem* mRenderSystem;
 		GLRenderSystem* mRenderSystem;

+ 4 - 15
CamelotGLRenderer/Include/CmGLTextureManager.h

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

+ 12 - 1
CamelotGLRenderer/Include/CmGLVertexBuffer.h

@@ -37,7 +37,6 @@ namespace CamelotEngine {
     class CM_RSGL_EXPORT GLVertexBuffer : public VertexBuffer 
     class CM_RSGL_EXPORT GLVertexBuffer : public VertexBuffer 
     {
     {
     public:
     public:
-        GLVertexBuffer(HardwareBufferManager* mgr, UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage); 
         ~GLVertexBuffer();
         ~GLVertexBuffer();
         /** See HardwareBuffer. */
         /** See HardwareBuffer. */
         void readData(UINT32 offset, UINT32 length, void* pDest);
         void readData(UINT32 offset, UINT32 length, void* pDest);
@@ -48,11 +47,23 @@ namespace CamelotEngine {
         GLuint getGLBufferId(void) const { return mBufferId; }
         GLuint getGLBufferId(void) const { return mBufferId; }
 
 
 	protected:
 	protected:
+		friend class GLHardwareBufferManager;
+
+		GLVertexBuffer(HardwareBufferManager* mgr, UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage); 
+
 		/** See HardwareBuffer. */
 		/** See HardwareBuffer. */
 		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
 		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
 		/** See HardwareBuffer. */
 		/** See HardwareBuffer. */
 		void unlockImpl(void);
 		void unlockImpl(void);
 
 
+		/**
+		 * @copydoc VertexBuffer::initialize_internal()
+		 */
+		void initialize_internal();	
+		
+		/**
+		 * @copydoc VertexBuffer::destroy_internal()
+		 */
 		void destroy_internal();
 		void destroy_internal();
 
 
 	private:
 	private:

+ 13 - 2
CamelotGLRenderer/Include/CmWin32Window.h

@@ -36,10 +36,8 @@ namespace CamelotEngine {
     class CM_RSGL_EXPORT Win32Window : public RenderWindow
     class CM_RSGL_EXPORT Win32Window : public RenderWindow
     {
     {
     public:
     public:
-        Win32Window(Win32GLSupport &glsupport);
         ~Win32Window();
         ~Win32Window();
 
 
-       void initialize(const RENDER_WINDOW_DESC& desc);
 	   void setFullscreen(bool fullScreen, unsigned int width, unsigned int height);
 	   void setFullscreen(bool fullScreen, unsigned int width, unsigned int height);
 		bool isActive(void) const;
 		bool isActive(void) const;
         bool isVisible() const;
         bool isVisible() const;
@@ -69,6 +67,11 @@ namespace CamelotEngine {
 			unsigned int* winWidth, unsigned int* winHeight);
 			unsigned int* winWidth, unsigned int* winHeight);
 
 
 	protected:
 	protected:
+		friend class GLRenderWindowManager;
+		friend class Win32GLSupport;
+
+		Win32Window(const RENDER_WINDOW_DESC& desc, Win32GLSupport &glsupport);
+
 		Win32GLSupport &mGLSupport;
 		Win32GLSupport &mGLSupport;
 		HWND	mHWnd;					// Win32 Window handle
 		HWND	mHWnd;					// Win32 Window handle
 		HDC		mHDC;
 		HDC		mHDC;
@@ -82,6 +85,14 @@ namespace CamelotEngine {
         int     mDisplayFrequency;      // fullscreen only, to restore display
         int     mDisplayFrequency;      // fullscreen only, to restore display
         Win32Context *mContext;
         Win32Context *mContext;
 
 
+		/**
+		 * @copydoc RenderWindow::initialize_internal().
+		 */
+		void initialize_internal();
+
+		/**
+		 * @copydoc RenderWindow::destroy_internal().
+		 */
 		void destroy_internal();
 		void destroy_internal();
     };
     };
 }
 }

+ 7 - 6
CamelotGLRenderer/Source/CmGLGpuBuffer.cpp

@@ -6,13 +6,19 @@ namespace CamelotEngine
 	GLGpuBuffer::GLGpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter) 
 	GLGpuBuffer::GLGpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter) 
 		: GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter)
 		: GpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter)
 	{
 	{
-		LOGWRN("Generic buffers are not supported in OpenGL. Creating a dummy buffer. All operations on it will either be no-op or return a nullptr.");
 	}
 	}
 
 
 	GLGpuBuffer::~GLGpuBuffer()
 	GLGpuBuffer::~GLGpuBuffer()
 	{
 	{
 	}
 	}
 
 
+	void GLGpuBuffer::initialize_internal()
+	{
+		LOGWRN("Generic buffers are not supported in OpenGL. Creating a dummy buffer. All operations on it will either be no-op or return a nullptr.");
+
+		GpuBuffer::initialize_internal();
+	}
+
 	void* GLGpuBuffer::lock(UINT32 offset, UINT32 length, GpuLockOptions options)
 	void* GLGpuBuffer::lock(UINT32 offset, UINT32 length, GpuLockOptions options)
 	{
 	{
 		return nullptr;
 		return nullptr;
@@ -43,9 +49,4 @@ namespace CamelotEngine
 	void GLGpuBuffer::destroyView(GpuBufferView* view)
 	void GLGpuBuffer::destroyView(GpuBufferView* view)
 	{
 	{
 	}
 	}
-
-	void GLGpuBuffer::destroy_internal()
-	{
-		GpuBuffer::destroy_internal();
-	}
 }
 }

+ 6 - 16
CamelotGLRenderer/Source/CmGLHardwareBufferManager.cpp

@@ -80,36 +80,26 @@ namespace CamelotEngine {
 		_aligned_free(mScratchBufferPool);
 		_aligned_free(mScratchBufferPool);
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
-    VertexBufferPtr GLHardwareBufferManager::createVertexBuffer(
+    VertexBufferPtr GLHardwareBufferManager::createVertexBufferImpl(
         UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
         UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
     {
     {
-		GLVertexBuffer* buf = 
-			new GLVertexBuffer(this, vertexSize, numVerts, usage);
-		{
-			mVertexBuffers.insert(buf);
-		}
-		return VertexBufferPtr(buf);
+		return VertexBufferPtr(new GLVertexBuffer(this, vertexSize, numVerts, usage));
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     IndexBufferPtr 
     IndexBufferPtr 
-    GLHardwareBufferManager::createIndexBuffer(
+    GLHardwareBufferManager::createIndexBufferImpl(
         IndexBuffer::IndexType itype, UINT32 numIndexes, 
         IndexBuffer::IndexType itype, UINT32 numIndexes, 
         GpuBufferUsage usage)
         GpuBufferUsage usage)
     {
     {
-		GLIndexBuffer* buf = 
-			new GLIndexBuffer(this, itype, numIndexes, usage);
-		{
-			mIndexBuffers.insert(buf);
-		}
-		return IndexBufferPtr(buf);
+		return IndexBufferPtr(new GLIndexBuffer(this, itype, numIndexes, usage));
     }
     }
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
-	GpuParamBlockPtr GLHardwareBufferManager::createGpuParamBlock(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage)
+	GpuParamBlockPtr GLHardwareBufferManager::createGpuParamBlockImpl(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage)
 	{
 	{
 		return GpuParamBlockPtr(new GLGpuParamBlock(paramDesc, usage));
 		return GpuParamBlockPtr(new GLGpuParamBlock(paramDesc, usage));
 	}
 	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
-	GpuBufferPtr GLHardwareBufferManager::createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
+	GpuBufferPtr GLHardwareBufferManager::createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
 		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
 		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
 	{
 	{
 		return GpuBufferPtr(new GLGpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
 		return GpuBufferPtr(new GLGpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));

+ 24 - 21
CamelotGLRenderer/Source/CmGLIndexBuffer.cpp

@@ -35,26 +35,36 @@ namespace CamelotEngine {
     GLIndexBuffer::GLIndexBuffer(HardwareBufferManager* mgr, IndexType idxType,
     GLIndexBuffer::GLIndexBuffer(HardwareBufferManager* mgr, IndexType idxType,
         UINT32 numIndexes, GpuBufferUsage usage)
         UINT32 numIndexes, GpuBufferUsage usage)
         : IndexBuffer(mgr, idxType, numIndexes, usage, false)
         : IndexBuffer(mgr, idxType, numIndexes, usage, false)
-    {
-        glGenBuffersARB( 1, &mBufferId );
+    {  }
+	//---------------------------------------------------------------------
+    GLIndexBuffer::~GLIndexBuffer()
+    {    }
+	//---------------------------------------------------------------------
+	void GLIndexBuffer::initialize_internal()
+	{
+		glGenBuffersARB( 1, &mBufferId );
 
 
-        if (!mBufferId)
-        {
+		if (!mBufferId)
+		{
 			CM_EXCEPT(InternalErrorException, 
 			CM_EXCEPT(InternalErrorException, 
-                "Cannot create GL index buffer");
-        }
+				"Cannot create GL index buffer");
+		}
 
 
-        glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, mBufferId);
+		glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, mBufferId);
 
 
-        // Initialise buffer and set usage
-        glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, mSizeInBytes, NULL, 
-            GLHardwareBufferManager::getGLUsage(usage));
+		// Initialise buffer and set usage
+		glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, mSizeInBytes, NULL, 
+			GLHardwareBufferManager::getGLUsage(mUsage));
 
 
-        //std::cerr << "creating index buffer " << mBufferId << std::endl;
-    }
+		IndexBuffer::initialize_internal();
+	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
-    GLIndexBuffer::~GLIndexBuffer()
-    {    }
+	void GLIndexBuffer::destroy_internal()
+	{
+		glDeleteBuffersARB(1, &mBufferId);
+
+		IndexBuffer::destroy_internal();
+	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
     void* GLIndexBuffer::lockImpl(UINT32 offset, 
     void* GLIndexBuffer::lockImpl(UINT32 offset, 
         UINT32 length, GpuLockOptions options)
         UINT32 length, GpuLockOptions options)
@@ -189,11 +199,4 @@ namespace CamelotEngine {
             glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length, pSource);
             glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length, pSource);
         }
         }
     }
     }
-	//---------------------------------------------------------------------
-	void GLIndexBuffer::destroy_internal()
-	{
-		 glDeleteBuffersARB(1, &mBufferId);
-
-		IndexBuffer::destroy_internal();
-	}
 }
 }

+ 10 - 10
CamelotGLRenderer/Source/CmGLMultiRenderTexture.cpp

@@ -14,6 +14,16 @@ namespace CamelotEngine
 
 
 	}
 	}
 
 
+	void GLMultiRenderTexture::initialize_internal()
+	{
+		if(mFB != nullptr)
+			delete mFB;
+
+		mFB = new GLFrameBufferObject(mFSAA);
+
+		MultiRenderTexture::initialize_internal();
+	}
+
 	void GLMultiRenderTexture::destroy_internal()
 	void GLMultiRenderTexture::destroy_internal()
 	{
 	{
 		if(mFB != nullptr)
 		if(mFB != nullptr)
@@ -67,14 +77,4 @@ namespace CamelotEngine
 			*static_cast<GLuint*>(pData) = mFB->getGLFBOID();
 			*static_cast<GLuint*>(pData) = mFB->getGLFBOID();
 		}
 		}
 	}
 	}
-
-	void GLMultiRenderTexture::initialize()
-	{
-		if(mFB != nullptr)
-			delete mFB;
-
-		mFB = new GLFrameBufferObject(mFSAA);
-
-		MultiRenderTexture::initialize();
-	}
 }
 }

+ 2 - 7
CamelotGLRenderer/Source/CmGLRenderWindowManager.cpp

@@ -11,19 +11,14 @@ namespace CamelotEngine
 		assert(mRenderSystem != nullptr);
 		assert(mRenderSystem != nullptr);
 	}
 	}
 
 
-	void GLRenderWindowManager::createImpl(const RENDER_WINDOW_DESC& desc, AsyncOp& asyncOp)
+	RenderWindowPtr GLRenderWindowManager::createImpl(const RENDER_WINDOW_DESC& desc)
 	{
 	{
 		GLSupport* glSupport = mRenderSystem->getGLSupport();
 		GLSupport* glSupport = mRenderSystem->getGLSupport();
 
 
 		// Create the window
 		// Create the window
 		RenderWindow* win = glSupport->newWindow(desc);
 		RenderWindow* win = glSupport->newWindow(desc);
 
 
-		mRenderSystem->attachRenderTarget(*win);
-		GLContext* context;
-		win->getCustomAttribute("GLCONTEXT", &context);
-		mRenderSystem->registerContext(context);
-
 		RenderWindowPtr winPtr(win);
 		RenderWindowPtr winPtr(win);
-		asyncOp.completeOperation(winPtr);
+		return winPtr;
 	}
 	}
 }
 }

+ 3 - 3
CamelotGLRenderer/Source/CmGLTexture.cpp

@@ -69,6 +69,8 @@ namespace CamelotEngine {
 
 
 	void GLTexture::initialize_internal()
 	void GLTexture::initialize_internal()
 	{
 	{
+		Texture::initialize_internal();
+
 		// Convert to nearest power-of-two size if required
 		// Convert to nearest power-of-two size if required
 		mWidth = GLPixelUtil::optionalPO2(mWidth);      
 		mWidth = GLPixelUtil::optionalPO2(mWidth);      
 		mHeight = GLPixelUtil::optionalPO2(mHeight);
 		mHeight = GLPixelUtil::optionalPO2(mHeight);
@@ -196,8 +198,6 @@ namespace CamelotEngine {
 		createSurfaceList();
 		createSurfaceList();
 		// Get final internal format
 		// Get final internal format
 		mFormat = getBuffer(0,0)->getFormat();
 		mFormat = getBuffer(0,0)->getFormat();
-
-		Resource::initialize_internal();
 	}
 	}
 
 
 	void GLTexture::destroy_internal()
 	void GLTexture::destroy_internal()
@@ -207,7 +207,7 @@ namespace CamelotEngine {
 
 
 		clearBufferViews();
 		clearBufferViews();
 
 
-		CoreGpuObject::destroy_internal();
+		Texture::destroy_internal();
 	}
 	}
 
 
     GLenum GLTexture::getGLTextureTarget(void) const
     GLenum GLTexture::getGLTextureTarget(void) const

+ 6 - 9
CamelotGLRenderer/Source/CmGLTextureManager.cpp

@@ -45,22 +45,19 @@ namespace CamelotEngine {
 		glDeleteTextures(1, &mWarningTextureID);
 		glDeleteTextures(1, &mWarningTextureID);
     }
     }
     //-----------------------------------------------------------------------------
     //-----------------------------------------------------------------------------
-    Texture* GLTextureManager::createTextureImpl()
+    TexturePtr GLTextureManager::createTextureImpl()
     {
     {
-        return new GLTexture(mGLSupport);
+        return TexturePtr(new GLTexture(mGLSupport));
     }
     }
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
-	RenderTexture* GLTextureManager::createRenderTextureImpl()
+	RenderTexturePtr GLTextureManager::createRenderTextureImpl()
 	{
 	{
-		return new GLRenderTexture();
+		return RenderTexturePtr(new GLRenderTexture());
 	}
 	}
 	//----------------------------------------------------------------------------
 	//----------------------------------------------------------------------------
-	MultiRenderTexturePtr GLTextureManager::createMultiRenderTexture()
+	MultiRenderTexturePtr GLTextureManager::createMultiRenderTextureImpl()
 	{
 	{
-		GLMultiRenderTexture* newMRT = new GLMultiRenderTexture();
-		newMRT->initialize();
-
-		return MultiRenderTexturePtr(newMRT);
+		return MultiRenderTexturePtr(new GLMultiRenderTexture());
 	}
 	}
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
 	void GLTextureManager::createWarningTexture()
 	void GLTextureManager::createWarningTexture()

+ 19 - 15
CamelotGLRenderer/Source/CmGLVertexBuffer.cpp

@@ -36,21 +36,6 @@ namespace CamelotEngine {
         UINT32 numVertices, GpuBufferUsage usage)
         UINT32 numVertices, GpuBufferUsage usage)
         : VertexBuffer(mgr, vertexSize, numVertices, usage, false)
         : VertexBuffer(mgr, vertexSize, numVertices, usage, false)
     {
     {
-        glGenBuffersARB( 1, &mBufferId );
-
-        if (!mBufferId)
-        {
-            CM_EXCEPT(InternalErrorException, 
-                "Cannot create GL vertex buffer");
-        }
-
-        glBindBufferARB(GL_ARRAY_BUFFER_ARB, mBufferId);
-
-        // Initialise mapped buffer and set usage
-        glBufferDataARB(GL_ARRAY_BUFFER_ARB, mSizeInBytes, NULL, 
-            GLHardwareBufferManager::getGLUsage(usage));
-
-        //std::cerr << "creating vertex buffer = " << mBufferId << std::endl;
     }
     }
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
     GLVertexBuffer::~GLVertexBuffer()
     GLVertexBuffer::~GLVertexBuffer()
@@ -193,6 +178,25 @@ namespace CamelotEngine {
             glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, offset, length, pSource); 
             glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, offset, length, pSource); 
         }
         }
     }
     }
+	//---------------------------------------------------------------------
+	void GLVertexBuffer::initialize_internal()
+	{
+		glGenBuffersARB( 1, &mBufferId );
+
+		if (!mBufferId)
+		{
+			CM_EXCEPT(InternalErrorException, 
+				"Cannot create GL vertex buffer");
+		}
+
+		glBindBufferARB(GL_ARRAY_BUFFER_ARB, mBufferId);
+
+		// Initialise mapped buffer and set usage
+		glBufferDataARB(GL_ARRAY_BUFFER_ARB, mSizeInBytes, NULL, 
+			GLHardwareBufferManager::getGLUsage(mUsage));
+
+		VertexBuffer::initialize_internal();
+	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
 	void GLVertexBuffer::destroy_internal()
 	void GLVertexBuffer::destroy_internal()
 	{
 	{

+ 31 - 27
CamelotGLRenderer/Source/CmWin32GLSupport.cpp

@@ -58,42 +58,46 @@ namespace CamelotEngine
 
 
 	RenderWindow* Win32GLSupport::newWindow(const RENDER_WINDOW_DESC& desc)
 	RenderWindow* Win32GLSupport::newWindow(const RENDER_WINDOW_DESC& desc)
 	{		
 	{		
-		Win32Window* window = new Win32Window(*this);
+		Win32Window* window = new Win32Window(desc, *this);
 		
 		
-		HMONITOR hMonitor = NULL;
-		int monitorIndex = desc.monitorIndex;
-		
-		// If monitor index found, try to assign the monitor handle based on it.
-		if(monitorIndex >= 0)
-		{
-			if (mMonitorInfoList.empty())		
-				EnumDisplayMonitors(NULL, NULL, sCreateMonitorsInfoEnumProc, (LPARAM)&mMonitorInfoList);			
+		// TODO - Looking for monitors is disabled for now, as it should be done on the render thread and I need to port it but 
+		//  I don't feel like it at the moment. Plus I'll probably implemented a more streamlined approach to this anyway.
 
 
-			if (monitorIndex < (int)mMonitorInfoList.size())					
-				hMonitor = mMonitorInfoList[monitorIndex].hMonitor;	
-		}
-
-		// If we didn't specified the monitor index, or if it didn't find it
-		if (hMonitor == NULL)
-		{
-			POINT windowAnchorPoint;
-		
-			// Fill in anchor point.
-			windowAnchorPoint.x = desc.left;
-			windowAnchorPoint.y = desc.top;
+		//HMONITOR hMonitor = NULL;
+		//int monitorIndex = desc.monitorIndex;
+		//
+		//// If monitor index found, try to assign the monitor handle based on it.
+		//if(monitorIndex >= 0)
+		//{
+		//	if (mMonitorInfoList.empty())		
+		//		EnumDisplayMonitors(NULL, NULL, sCreateMonitorsInfoEnumProc, (LPARAM)&mMonitorInfoList);			
+
+		//	if (monitorIndex < (int)mMonitorInfoList.size())					
+		//		hMonitor = mMonitorInfoList[monitorIndex].hMonitor;	
+		//}
+
+		//// If we didn't specified the monitor index, or if it didn't find it
+		//if (hMonitor == NULL)
+		//{
+		//	POINT windowAnchorPoint;
+		//
+		//	// Fill in anchor point.
+		//	windowAnchorPoint.x = desc.left;
+		//	windowAnchorPoint.y = desc.top;
 
 
 
 
-			// Get the nearest monitor to this window.
-			hMonitor = MonitorFromPoint(windowAnchorPoint, MONITOR_DEFAULTTONEAREST);				
-		}
+		//	// Get the nearest monitor to this window.
+		//	hMonitor = MonitorFromPoint(windowAnchorPoint, MONITOR_DEFAULTTONEAREST);				
+		//}
 
 
-		RENDER_WINDOW_DESC newDesc = desc;
-		newDesc.platformSpecific["monitorHandle"] = toString((size_t)hMonitor);
+		//RENDER_WINDOW_DESC newDesc = desc;
+		//newDesc.platformSpecific["monitorHandle"] = toString((size_t)hMonitor);
 
 
-		window->initialize(newDesc);
+		//window->initialize(newDesc);
 
 
 		if(!mInitialWindow)
 		if(!mInitialWindow)
 			mInitialWindow = window;
 			mInitialWindow = window;
+
 		return window;
 		return window;
 	}
 	}
 
 

+ 94 - 84
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -41,7 +41,8 @@ namespace CamelotEngine {
 
 
 	#define _MAX_CLASS_NAME_ 128
 	#define _MAX_CLASS_NAME_ 128
 
 
-	Win32Window::Win32Window(Win32GLSupport &glsupport):
+	Win32Window::Win32Window(const RENDER_WINDOW_DESC& desc, Win32GLSupport &glsupport):
+		RenderWindow(desc),
 		mGLSupport(glsupport),
 		mGLSupport(glsupport),
 		mContext(0)
 		mContext(0)
 	{
 	{
@@ -63,48 +64,7 @@ namespace CamelotEngine {
 
 
 	}
 	}
 
 
-	void Win32Window::destroy_internal()
-	{
-		if (!mHWnd)
-			return;
-
-		// Unregister and destroy OGRE GLContext
-		delete mContext;
-
-		if (!mIsExternalGLContext && mGlrc)
-		{
-			wglDeleteContext(mGlrc);
-			mGlrc = 0;
-		}
-		if (!mIsExternal)
-		{
-			WindowEventUtilities::_removeRenderWindow(this);
-
-			if (mIsFullScreen)
-				ChangeDisplaySettingsEx(mDeviceName, NULL, NULL, 0, NULL);
-			DestroyWindow(mHWnd);
-		}
-		else
-		{
-			// just release the DC
-			ReleaseDC(mHWnd, mHDC);
-		}
-
-		mActive = false;
-		mClosed = true;
-		mHDC = 0; // no release thanks to CS_OWNDC wndclass style
-		mHWnd = 0;
-
-		if (mDeviceName != NULL)
-		{
-			delete[] mDeviceName;
-			mDeviceName = NULL;
-		}
-
-		RenderWindow::destroy_internal();
-	}
-
-	void Win32Window::initialize(const RENDER_WINDOW_DESC& desc)
+	void Win32Window::initialize_internal()
 	{
 	{
 #ifdef CM_STATIC_LIB
 #ifdef CM_STATIC_LIB
 		HINSTANCE hInst = GetModuleHandle( NULL );
 		HINSTANCE hInst = GetModuleHandle( NULL );
@@ -113,19 +73,21 @@ namespace CamelotEngine {
 #endif
 #endif
 
 
 		mHWnd = 0;
 		mHWnd = 0;
-		mName = desc.title;
-		mIsFullScreen = desc.fullscreen;
+		mName = mDesc.title;
+		mIsFullScreen = mDesc.fullscreen;
 		mClosed = false;		
 		mClosed = false;		
-		mDisplayFrequency = desc.displayFrequency;
-		mColorDepth = desc.colorDepth;
+		mDisplayFrequency = mDesc.displayFrequency;
+		mColorDepth = mDesc.colorDepth;
 		HWND parent = 0;
 		HWND parent = 0;
 		HMONITOR hMonitor = NULL;
 		HMONITOR hMonitor = NULL;
 
 
+		int monitorIndex = mDesc.monitorIndex;
+
 		// Get variable-length params
 		// Get variable-length params
 		NameValuePairList::const_iterator opt;
 		NameValuePairList::const_iterator opt;
-		NameValuePairList::const_iterator end = desc.platformSpecific.end();
+		NameValuePairList::const_iterator end = mDesc.platformSpecific.end();
 
 
-		if ((opt = desc.platformSpecific.find("externalWindowHandle")) != end)
+		if ((opt = mDesc.platformSpecific.find("externalWindowHandle")) != end)
 		{
 		{
 			mHWnd = (HWND)parseUnsignedInt(opt->second);
 			mHWnd = (HWND)parseUnsignedInt(opt->second);
 			if (mHWnd)
 			if (mHWnd)
@@ -134,12 +96,12 @@ namespace CamelotEngine {
 				mIsFullScreen = false;
 				mIsFullScreen = false;
 			}
 			}
 
 
-			if ((opt = desc.platformSpecific.find("externalGLControl")) != end) {
+			if ((opt = mDesc.platformSpecific.find("externalGLControl")) != end) {
 				mIsExternalGLControl = parseBool(opt->second);
 				mIsExternalGLControl = parseBool(opt->second);
 			}
 			}
 		}
 		}
 
 
-		if ((opt = desc.platformSpecific.find("externalGLContext")) != end)
+		if ((opt = mDesc.platformSpecific.find("externalGLContext")) != end)
 		{
 		{
 			mGlrc = (HGLRC)parseUnsignedLong(opt->second);
 			mGlrc = (HGLRC)parseUnsignedLong(opt->second);
 			if( mGlrc )
 			if( mGlrc )
@@ -147,11 +109,11 @@ namespace CamelotEngine {
 		}
 		}
 
 
 		// incompatible with fullscreen
 		// incompatible with fullscreen
-		if ((opt = desc.platformSpecific.find("parentWindowHandle")) != end)
+		if ((opt = mDesc.platformSpecific.find("parentWindowHandle")) != end)
 			parent = (HWND)parseUnsignedInt(opt->second);
 			parent = (HWND)parseUnsignedInt(opt->second);
 
 
 		// monitor handle
 		// monitor handle
-		if ((opt = desc.platformSpecific.find("monitorHandle")) != end)
+		if ((opt = mDesc.platformSpecific.find("monitorHandle")) != end)
 			hMonitor = (HMONITOR)parseInt(opt->second);			
 			hMonitor = (HMONITOR)parseInt(opt->second);			
 
 
 		if (!mIsFullScreen)
 		if (!mIsFullScreen)
@@ -167,15 +129,15 @@ namespace CamelotEngine {
 			DWORD		  dwStyleEx = 0;					
 			DWORD		  dwStyleEx = 0;					
 			MONITORINFOEX monitorInfoEx;
 			MONITORINFOEX monitorInfoEx;
 			RECT		  rc;
 			RECT		  rc;
-			
+
 			// If we didn't specified the adapter index, or if it didn't find it
 			// If we didn't specified the adapter index, or if it didn't find it
 			if (hMonitor == NULL)
 			if (hMonitor == NULL)
 			{
 			{
 				POINT windowAnchorPoint;
 				POINT windowAnchorPoint;
 
 
 				// Fill in anchor point.
 				// Fill in anchor point.
-				windowAnchorPoint.x = desc.left;
-				windowAnchorPoint.y = desc.top;
+				windowAnchorPoint.x = mDesc.left;
+				windowAnchorPoint.y = mDesc.top;
 
 
 
 
 				// Get the nearest monitor to this window.
 				// Get the nearest monitor to this window.
@@ -189,11 +151,11 @@ namespace CamelotEngine {
 
 
 			size_t devNameLen = strlen(monitorInfoEx.szDevice);
 			size_t devNameLen = strlen(monitorInfoEx.szDevice);
 			mDeviceName = new char[devNameLen + 1];
 			mDeviceName = new char[devNameLen + 1];
-	
+
 			strcpy_s(mDeviceName, devNameLen + 1, monitorInfoEx.szDevice);
 			strcpy_s(mDeviceName, devNameLen + 1, monitorInfoEx.szDevice);
 
 
-			UINT32 left = desc.left;
-			UINT32 top = desc.top;
+			UINT32 left = mDesc.left;
+			UINT32 top = mDesc.top;
 
 
 			// No specified top left -> Center the window in the middle of the monitor
 			// No specified top left -> Center the window in the middle of the monitor
 			if (left == -1 || top == -1)
 			if (left == -1 || top == -1)
@@ -202,7 +164,7 @@ namespace CamelotEngine {
 				int screenh = monitorInfoEx.rcWork.bottom - monitorInfoEx.rcWork.top;
 				int screenh = monitorInfoEx.rcWork.bottom - monitorInfoEx.rcWork.top;
 
 
 				unsigned int winWidth, winHeight;
 				unsigned int winWidth, winHeight;
-				adjustWindow(desc.width, desc.height, &winWidth, &winHeight);
+				adjustWindow(mDesc.width, mDesc.height, &winWidth, &winHeight);
 
 
 				// clamp window dimensions to screen size
 				// clamp window dimensions to screen size
 				int outerw = (int(winWidth) < screenw)? int(winWidth) : screenw;
 				int outerw = (int(winWidth) < screenw)? int(winWidth) : screenw;
@@ -210,22 +172,22 @@ namespace CamelotEngine {
 
 
 				if (left == -1)
 				if (left == -1)
 					left = monitorInfoEx.rcWork.left + (screenw - outerw) / 2;
 					left = monitorInfoEx.rcWork.left + (screenw - outerw) / 2;
-				else if (desc.monitorIndex != -1)
+				else if (mDesc.monitorIndex != -1)
 					left += monitorInfoEx.rcWork.left;
 					left += monitorInfoEx.rcWork.left;
 
 
 				if (top == -1)
 				if (top == -1)
 					top = monitorInfoEx.rcWork.top + (screenh - outerh) / 2;
 					top = monitorInfoEx.rcWork.top + (screenh - outerh) / 2;
-				else if (desc.monitorIndex != -1)
+				else if (mDesc.monitorIndex != -1)
 					top += monitorInfoEx.rcWork.top;
 					top += monitorInfoEx.rcWork.top;
 			}
 			}
-			else if (desc.monitorIndex != -1)
+			else if (mDesc.monitorIndex != -1)
 			{
 			{
 				left += monitorInfoEx.rcWork.left;
 				left += monitorInfoEx.rcWork.left;
 				top += monitorInfoEx.rcWork.top;
 				top += monitorInfoEx.rcWork.top;
 			}
 			}
 
 
-			mWidth = desc.width;
-			mHeight = desc.height;
+			mWidth = mDesc.width;
+			mHeight = mDesc.height;
 			mTop = top;
 			mTop = top;
 			mLeft = left;
 			mLeft = left;
 
 
@@ -244,9 +206,9 @@ namespace CamelotEngine {
 				}
 				}
 				else
 				else
 				{
 				{
-					if (desc.border == "none")
+					if (mDesc.border == "none")
 						dwStyle |= WS_POPUP;
 						dwStyle |= WS_POPUP;
-					else if (desc.border == "fixed")
+					else if (mDesc.border == "fixed")
 						dwStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION |
 						dwStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION |
 						WS_SYSMENU | WS_MINIMIZEBOX;
 						WS_SYSMENU | WS_MINIMIZEBOX;
 					else
 					else
@@ -256,7 +218,7 @@ namespace CamelotEngine {
 				int screenw = GetSystemMetrics(SM_CXSCREEN);
 				int screenw = GetSystemMetrics(SM_CXSCREEN);
 				int screenh = GetSystemMetrics(SM_CYSCREEN);
 				int screenh = GetSystemMetrics(SM_CYSCREEN);
 
 
-				if (!desc.outerDimensions)
+				if (!mDesc.outerDimensions)
 				{
 				{
 					// Calculate window dimensions required
 					// Calculate window dimensions required
 					// to get the requested client area
 					// to get the requested client area
@@ -316,9 +278,9 @@ namespace CamelotEngine {
 			}
 			}
 
 
 			// Pass pointer to self as WM_CREATE parameter
 			// Pass pointer to self as WM_CREATE parameter
-			mHWnd = CreateWindowEx(dwStyleEx, "GLWindow", desc.title.c_str(),
+			mHWnd = CreateWindowEx(dwStyleEx, "GLWindow", mDesc.title.c_str(),
 				dwStyle, mLeft, mTop, mWidth, mHeight, parent, 0, hInst, this);
 				dwStyle, mLeft, mTop, mWidth, mHeight, parent, 0, hInst, this);
-		
+
 			WindowEventUtilities::_addRenderWindow(this);			
 			WindowEventUtilities::_addRenderWindow(this);			
 		}
 		}
 
 
@@ -340,7 +302,7 @@ namespace CamelotEngine {
 		if (!mIsExternalGLControl)
 		if (!mIsExternalGLControl)
 		{
 		{
 			int testFsaa = mFSAA;
 			int testFsaa = mFSAA;
-			bool testHwGamma = desc.gamma;
+			bool testHwGamma = mDesc.gamma;
 			bool formatOk = mGLSupport.selectPixelFormat(mHDC, mColorDepth, testFsaa, testHwGamma);
 			bool formatOk = mGLSupport.selectPixelFormat(mHDC, mColorDepth, testFsaa, testHwGamma);
 			if (!formatOk)
 			if (!formatOk)
 			{
 			{
@@ -351,7 +313,7 @@ namespace CamelotEngine {
 					formatOk = mGLSupport.selectPixelFormat(mHDC, mColorDepth, testFsaa, testHwGamma);
 					formatOk = mGLSupport.selectPixelFormat(mHDC, mColorDepth, testFsaa, testHwGamma);
 				}
 				}
 
 
-				if (!formatOk && desc.gamma)
+				if (!formatOk && mDesc.gamma)
 				{
 				{
 					// try without sRGB
 					// try without sRGB
 					testHwGamma = false;
 					testHwGamma = false;
@@ -359,7 +321,7 @@ namespace CamelotEngine {
 					formatOk = mGLSupport.selectPixelFormat(mHDC, mColorDepth, testFsaa, testHwGamma);
 					formatOk = mGLSupport.selectPixelFormat(mHDC, mColorDepth, testFsaa, testHwGamma);
 				}
 				}
 
 
-				if (!formatOk && desc.gamma && (mFSAA > 0))
+				if (!formatOk && mDesc.gamma && (mFSAA > 0))
 				{
 				{
 					// try without both
 					// try without both
 					testHwGamma = false;
 					testHwGamma = false;
@@ -382,7 +344,7 @@ namespace CamelotEngine {
 			if (!mGlrc)
 			if (!mGlrc)
 			{
 			{
 				CM_EXCEPT(RenderingAPIException, 
 				CM_EXCEPT(RenderingAPIException, 
-				"wglCreateContext failed: " + translateWGLError());
+					"wglCreateContext failed: " + translateWGLError());
 			}
 			}
 		}
 		}
 
 
@@ -397,24 +359,72 @@ namespace CamelotEngine {
 			PFNWGLSWAPINTERVALEXTPROC _wglSwapIntervalEXT = 
 			PFNWGLSWAPINTERVALEXTPROC _wglSwapIntervalEXT = 
 				(PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
 				(PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
 			if (_wglSwapIntervalEXT)
 			if (_wglSwapIntervalEXT)
-				_wglSwapIntervalEXT(desc.vsync ? desc.vsyncInterval : 0);
+				_wglSwapIntervalEXT(mDesc.vsync ? mDesc.vsyncInterval : 0);
 		}
 		}
 
 
-        if (old_context && old_context != mGlrc)
-        {
-            // Restore old context
-		    if (!wglMakeCurrent(old_hdc, old_context))
-			    CM_EXCEPT(RenderingAPIException, "wglMakeCurrent() failed");
+		if (old_context && old_context != mGlrc)
+		{
+			// Restore old context
+			if (!wglMakeCurrent(old_hdc, old_context))
+				CM_EXCEPT(RenderingAPIException, "wglMakeCurrent() failed");
 
 
-            // Share lists with old context
-		    if (!wglShareLists(old_context, mGlrc))
-			    CM_EXCEPT(RenderingAPIException, "wglShareLists() failed");
-        }
+			// Share lists with old context
+			if (!wglShareLists(old_context, mGlrc))
+				CM_EXCEPT(RenderingAPIException, "wglShareLists() failed");
+		}
 
 
 		// Create RenderSystem context
 		// Create RenderSystem context
 		mContext = new Win32Context(mHDC, mGlrc);
 		mContext = new Win32Context(mHDC, mGlrc);
 
 
 		mActive = true;
 		mActive = true;
+
+		GLRenderSystem* rs = static_cast<GLRenderSystem*>(RenderSystem::instancePtr());
+
+		rs->attachRenderTarget(*this);
+		rs->registerContext(mContext);
+
+		RenderWindow::initialize_internal();
+	}
+
+	void Win32Window::destroy_internal()
+	{
+		if (!mHWnd)
+			return;
+
+		// Unregister and destroy OGRE GLContext
+		delete mContext;
+
+		if (!mIsExternalGLContext && mGlrc)
+		{
+			wglDeleteContext(mGlrc);
+			mGlrc = 0;
+		}
+		if (!mIsExternal)
+		{
+			WindowEventUtilities::_removeRenderWindow(this);
+
+			if (mIsFullScreen)
+				ChangeDisplaySettingsEx(mDeviceName, NULL, NULL, 0, NULL);
+			DestroyWindow(mHWnd);
+		}
+		else
+		{
+			// just release the DC
+			ReleaseDC(mHWnd, mHDC);
+		}
+
+		mActive = false;
+		mClosed = true;
+		mHDC = 0; // no release thanks to CS_OWNDC wndclass style
+		mHWnd = 0;
+
+		if (mDeviceName != NULL)
+		{
+			delete[] mDeviceName;
+			mDeviceName = NULL;
+		}
+
+		RenderWindow::destroy_internal();
 	}
 	}
 
 
 	void Win32Window::adjustWindow(unsigned int clientWidth, unsigned int clientHeight, 
 	void Win32Window::adjustWindow(unsigned int clientWidth, unsigned int clientHeight, 

+ 0 - 10
CamelotGLRenderer/Source/GLSL/include/CmGLSLGpuProgram.h

@@ -76,16 +76,6 @@ namespace CamelotEngine {
 
 
     protected:
     protected:
 		friend class GLSLProgramFactory;
 		friend class GLSLProgramFactory;
-
-		/**
-		 * @copydoc GpuProgram::initialize_internal
-		 */
-		void initialize_internal();
-
-		/**
-		 * @copydoc GpuProgram::destroy_internal
-		 */
-		void destroy_internal();
     };
     };
 }
 }
 
 

+ 2 - 2
CamelotGLRenderer/Source/GLSL/include/CmGLSLProgram.h

@@ -96,7 +96,7 @@ namespace CamelotEngine {
 		virtual void setMaxOutputVertices(int maxOutputVertices) 
 		virtual void setMaxOutputVertices(int maxOutputVertices) 
 		{ mMaxOutputVertices = maxOutputVertices; }
 		{ mMaxOutputVertices = maxOutputVertices; }
 
 
-		const VertexDeclaration& getInputAttributes() const { return mVertexDeclaration; }
+		const VertexDeclaration& getInputAttributes() const { return *mVertexDeclaration; }
 
 
 	protected:
 	protected:
 		friend class GLSLProgramFactory;
 		friend class GLSLProgramFactory;
@@ -127,7 +127,7 @@ namespace CamelotEngine {
 		int mMaxOutputVertices;
 		int mMaxOutputVertices;
 		/// Preprocessor options
 		/// Preprocessor options
 		String mPreprocessorDefines;
 		String mPreprocessorDefines;
-		VertexDeclaration mVertexDeclaration;
+		VertexDeclarationPtr mVertexDeclaration;
 
 
 		/************************************************************************/
 		/************************************************************************/
 		/* 								SERIALIZATION                      		*/
 		/* 								SERIALIZATION                      		*/

+ 0 - 12
CamelotGLRenderer/Source/GLSL/src/CmGLSLGpuProgram.cpp

@@ -71,17 +71,5 @@ namespace CamelotEngine {
     GLSLGpuProgram::~GLSLGpuProgram()
     GLSLGpuProgram::~GLSLGpuProgram()
     {
     {
     }
     }
-	//-----------------------------------------------------------------------------
-    void GLSLGpuProgram::initialize_internal(void)
-    {
-		// Nothing to load
-		GpuProgram::initialize_internal();
-    }
-	//-----------------------------------------------------------------------------
-	void GLSLGpuProgram::destroy_internal()
-	{
-		// Nothing to destroy
-		GpuProgram::destroy_internal();
-	}
 }
 }
 
 

+ 6 - 1
CamelotGLRenderer/Source/GLSL/src/CmGLSLProgram.cpp

@@ -39,6 +39,7 @@ THE SOFTWARE.
 #include "CmGLSLExtSupport.h"
 #include "CmGLSLExtSupport.h"
 #include "CmGLSLPreprocessor.h"
 #include "CmGLSLPreprocessor.h"
 #include "CmGLSLParamParser.h"
 #include "CmGLSLParamParser.h"
+#include "CmHardwareBufferManager.h"
 
 
 #include "CmGLSLProgramRTTI.h"
 #include "CmGLSLProgramRTTI.h"
 
 
@@ -63,6 +64,8 @@ namespace CamelotEngine
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
 	void GLSLProgram::initialize_internal()
 	void GLSLProgram::initialize_internal()
 	{
 	{
+		mVertexDeclaration = HardwareBufferManager::instance().createVertexDeclaration();
+
 		// only create a shader object if glsl is supported
 		// only create a shader object if glsl is supported
 		GLenum shaderType = 0x0000;
 		GLenum shaderType = 0x0000;
 		if (isSupported())
 		if (isSupported())
@@ -169,7 +172,7 @@ namespace CamelotEngine
 
 
 		GLSLParamParser paramParser;
 		GLSLParamParser paramParser;
 		paramParser.buildUniformDescriptions(mGLHandle, mParametersDesc);
 		paramParser.buildUniformDescriptions(mGLHandle, mParametersDesc);
-		paramParser.buildVertexDeclaration(mGLHandle, mVertexDeclaration);
+		paramParser.buildVertexDeclaration(mGLHandle, *mVertexDeclaration);
 
 
 		HighLevelGpuProgram::initialize_internal();
 		HighLevelGpuProgram::initialize_internal();
 	}
 	}
@@ -184,6 +187,8 @@ namespace CamelotEngine
 		if (isSupported())
 		if (isSupported())
 			glDeleteShader(mGLHandle);
 			glDeleteShader(mGLHandle);
 
 
+		mVertexDeclaration->destroy();
+
 		HighLevelGpuProgram::destroy_internal();
 		HighLevelGpuProgram::destroy_internal();
 	}
 	}
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------

+ 2 - 0
CamelotRenderer/CamelotRenderer.vcxproj

@@ -192,6 +192,7 @@
     <ClInclude Include="Include\CmComponentRTTI.h" />
     <ClInclude Include="Include\CmComponentRTTI.h" />
     <ClInclude Include="Include\CmConfigOptionMap.h" />
     <ClInclude Include="Include\CmConfigOptionMap.h" />
     <ClInclude Include="Include\CmCoreGpuObject.h" />
     <ClInclude Include="Include\CmCoreGpuObject.h" />
+    <ClInclude Include="Include\CmCoreGpuObjectManager.h" />
     <ClInclude Include="Include\CmDeferredRenderContext.h" />
     <ClInclude Include="Include\CmDeferredRenderContext.h" />
     <ClInclude Include="Include\CmDepthStencilStateRTTI.h" />
     <ClInclude Include="Include\CmDepthStencilStateRTTI.h" />
     <ClInclude Include="Include\CmDepthStencilState.h" />
     <ClInclude Include="Include\CmDepthStencilState.h" />
@@ -283,6 +284,7 @@
     <ClCompile Include="Source\CmCgProgramFactory.cpp" />
     <ClCompile Include="Source\CmCgProgramFactory.cpp" />
     <ClCompile Include="Source\CmCommandQueue.cpp" />
     <ClCompile Include="Source\CmCommandQueue.cpp" />
     <ClCompile Include="Source\CmCoreGpuObject.cpp" />
     <ClCompile Include="Source\CmCoreGpuObject.cpp" />
+    <ClCompile Include="Source\CmCoreGpuObjectManager.cpp" />
     <ClCompile Include="Source\CmDeferredRenderContext.cpp" />
     <ClCompile Include="Source\CmDeferredRenderContext.cpp" />
     <ClCompile Include="Source\CmDepthStencilState.cpp" />
     <ClCompile Include="Source\CmDepthStencilState.cpp" />
     <ClCompile Include="Source\CmGpuBuffer.cpp" />
     <ClCompile Include="Source\CmGpuBuffer.cpp" />

+ 6 - 0
CamelotRenderer/CamelotRenderer.vcxproj.filters

@@ -368,6 +368,9 @@
     <ClInclude Include="Include\CmCoreGpuObject.h">
     <ClInclude Include="Include\CmCoreGpuObject.h">
       <Filter>Header Files\RenderSystem</Filter>
       <Filter>Header Files\RenderSystem</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="Include\CmCoreGpuObjectManager.h">
+      <Filter>Header Files\RenderSystem</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CamelotRenderer.cpp">
     <ClCompile Include="Source\CamelotRenderer.cpp">
@@ -559,5 +562,8 @@
     <ClCompile Include="Source\CmCoreGpuObject.cpp">
     <ClCompile Include="Source\CmCoreGpuObject.cpp">
       <Filter>Source Files\RenderSystem</Filter>
       <Filter>Source Files\RenderSystem</Filter>
     </ClCompile>
     </ClCompile>
+    <ClCompile Include="Source\CmCoreGpuObjectManager.cpp">
+      <Filter>Source Files\RenderSystem</Filter>
+    </ClCompile>
   </ItemGroup>
   </ItemGroup>
 </Project>
 </Project>

+ 52 - 2
CamelotRenderer/Include/CmCoreGpuObject.h

@@ -9,6 +9,8 @@ namespace CamelotEngine
 	 * 			need to implement.
 	 * 			need to implement.
 	 * 			
 	 * 			
 	 * @note	This involves initializing, keeping track of, and releasing all GPU resources.
 	 * @note	This involves initializing, keeping track of, and releasing all GPU resources.
+	 * 			All core GPU objects are initialized on the render thread, and destroyed on the render thread,
+	 * 			so majority of these methods will just schedule object initialization/destruction.
 	 */
 	 */
 	class CM_EXPORT CoreGpuObject
 	class CM_EXPORT CoreGpuObject
 	{
 	{
@@ -24,16 +26,64 @@ namespace CamelotEngine
 		 */
 		 */
 		virtual void destroy();
 		virtual void destroy();
 
 
-		bool isDestroyed() { return mDestroyed; }
+		/**
+		 * @brief	Initializes all the internal resources of this object. Should be called by the
+		 * 			factory creation methods automatically after construction and not by user directly.
+		 * 					
+		 * @note	Initialization is not done immediately, and is instead just scheduled on the
+		 * 			render thread. Unless called from render thread in which case it is executed right away.
+		 */
+		virtual void initialize();
+
+		/**
+		 * @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; }
+
+		/**
+		 * @brief	Blocks the current thread until the resource is fully initialized.
+		 * 			If you call this without calling initialize first a deadlock will occurr.
+		 */
+		void waitUntilInitialized();
+
+		/**
+		 * @brief	Sets a shared this pointer to this object. This MUST be called immediately after construction.
+		 *
+		 * @note	Called automatically by the factory creation methods so user should not call this manually.
+		 */
+		void setThisPtr(std::shared_ptr<CoreGpuObject> ptrThis);
 
 
 	protected:
 	protected:
 		/**
 		/**
 		 * @brief	Frees all of the objects dynamically allocated memory. All derived classes that have something to free
 		 * @brief	Frees all of the objects dynamically allocated memory. All derived classes that have something to free
 		 * 			should do it here instead of their destructor. All derived classes need to call this base method when they're done.
 		 * 			should do it here instead of their destructor. All derived classes need to call this base method when they're done.
+		 * 			
+		 * @note	Since this is scheduled to be executed on the render thread, normally you want to destroy all GPU specific resources here.
 		 */
 		 */
 		virtual void destroy_internal();
 		virtual void destroy_internal();
 
 
+		/**
+		 * @brief	Initializes all the internal resources of this object. Needs to be called before doing
+		 * 			any operations with the object. All derived classes also need to call this base method.
+		 * 			
+		 * @note	Since this is scheduled to be executed on the render thread, normally you want to initialize all GPU specific resources here.
+		 */
+		virtual void initialize_internal();
+
+		/**
+		 * @brief	Returns an unique identifier for this object.
+		 */
+		UINT64 getInternalID() const { return mInternalID; }
+
 	private:
 	private:
-		bool mDestroyed;
+		friend class CoreGpuObjectManager;
+
+		bool mIsInitialized;
+		UINT64 mInternalID; // ID == 0 is not a valid ID
+		std::weak_ptr<CoreGpuObject> mThis;
+
+		CM_STATIC_THREAD_SYNCHRONISER(mCoreGpuObjectLoadedCondition)
+		CM_STATIC_MUTEX(mCoreGpuObjectLoadedMutex)
 	};
 	};
 }
 }

+ 34 - 0
CamelotRenderer/Include/CmCoreGpuObjectManager.h

@@ -0,0 +1,34 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmModule.h"
+
+namespace CamelotEngine
+{
+	// TODO - Add debug option that would remember a call stack for each resource initialization,
+	// so when we fail to release one we know which one it is.
+	class CM_EXPORT CoreGpuObjectManager : public Module<CoreGpuObjectManager>
+	{
+	public:
+		CoreGpuObjectManager();
+		~CoreGpuObjectManager();
+
+		UINT64 registerObject(CoreGpuObject* object);
+		void unregisterObject(CoreGpuObject* object);
+
+		void registerObjectToDestroy(std::shared_ptr<CoreGpuObject> object);
+		void unregisterObjectToDestroy(std::shared_ptr<CoreGpuObject> object);
+	private:
+		// Keeps a list of ALL loaded core GPU objects
+		UINT64 mNextAvailableID;
+		map<UINT64, CoreGpuObject*>::type mObjects;
+		CM_MUTEX(mObjectsMutex);
+
+		// Keeps a list of GPU objects scheduled to be destroyed. We need a reference
+		// to the object here, otherwise the object may reach reference count of 0 and be
+		// deleted before its scheduled destroy() method is called. Object is added to the list
+		// when destroy() is initialized, and removed when it is finished.
+		map<UINT64, std::shared_ptr<CoreGpuObject>>::type mObjectsToDestroy;
+		CM_MUTEX(mObjectsToDestroyMutex);
+	};
+}

+ 9 - 7
CamelotRenderer/Include/CmGpuBuffer.h

@@ -10,7 +10,6 @@ namespace CamelotEngine
 	class CM_EXPORT GpuBuffer : public CoreGpuObject
 	class CM_EXPORT GpuBuffer : public CoreGpuObject
     {
     {
     public:
     public:
-        GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
         virtual ~GpuBuffer();
         virtual ~GpuBuffer();
 
 
 		virtual void* lock(UINT32 offset, UINT32 length, GpuLockOptions options) = 0;
 		virtual void* lock(UINT32 offset, UINT32 length, GpuLockOptions options) = 0;
@@ -33,12 +32,7 @@ namespace CamelotEngine
 		UINT32 getElementSize() const { return mElementSize; }
 		UINT32 getElementSize() const { return mElementSize; }
 
 
 	protected:
 	protected:
-		GpuBufferType mType;
-		GpuBufferUsage mUsage;
-		bool mRandomGpuWrite;
-		bool mUseCounter;
-		UINT32 mElementCount;
-		UINT32 mElementSize;
+		GpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
 
 
 		virtual GpuBufferView* createView() = 0;
 		virtual GpuBufferView* createView() = 0;
 		virtual void destroyView(GpuBufferView* view) = 0;
 		virtual void destroyView(GpuBufferView* view) = 0;
@@ -60,5 +54,13 @@ namespace CamelotEngine
 		};
 		};
 
 
 		std::unordered_map<GPU_BUFFER_DESC, GpuBufferReference*, GpuBufferView::HashFunction, GpuBufferView::EqualFunction> mBufferViews;
 		std::unordered_map<GPU_BUFFER_DESC, GpuBufferReference*, GpuBufferView::HashFunction, GpuBufferView::EqualFunction> mBufferViews;
+
+	protected:
+		GpuBufferType mType;
+		GpuBufferUsage mUsage;
+		bool mRandomGpuWrite;
+		bool mUseCounter;
+		UINT32 mElementCount;
+		UINT32 mElementSize;
     };
     };
 }
 }

+ 15 - 36
CamelotRenderer/Include/CmGpuProgram.h

@@ -100,11 +100,6 @@ namespace CamelotEngine {
 	public:
 	public:
 		virtual ~GpuProgram();
 		virtual ~GpuProgram();
 
 
-		/**
-		 * @brief	Performs GpuProgram initialization. Only callable from the render thread.
-		 */
-		virtual void initialize_internal();
-
         /** Gets the syntax code for this program e.g. arbvp1, fp20, vs_1_1 etc */
         /** Gets the syntax code for this program e.g. arbvp1, fp20, vs_1_1 etc */
         virtual const String& getSyntaxCode(void) const { return mSyntaxCode; }
         virtual const String& getSyntaxCode(void) const { return mSyntaxCode; }
 
 
@@ -149,6 +144,21 @@ namespace CamelotEngine {
         */
         */
         virtual const String& getLanguage(void) const;
         virtual const String& getLanguage(void) const;
 
 
+	protected:
+		friend class GpuProgramManager;
+
+		GpuProgram(const String& source, const String& entryPoint, const String& language, 
+			GpuProgramType gptype, GpuProgramProfile profile, bool isAdjacencyInfoRequired = false);
+
+        /** Internal method returns whether required capabilities for this program is supported.
+        */
+        bool isRequiredCapabilitiesSupported(void) const;
+
+		/// @copydoc Resource::calculateSize
+		size_t calculateSize(void) const { return 0; } // TODO 
+
+		void throwIfNotRenderThread() const;
+
 	protected:
 	protected:
 		/// The type of the program
 		/// The type of the program
 		GpuProgramType mType;
 		GpuProgramType mType;
@@ -168,37 +178,6 @@ namespace CamelotEngine {
 		 */
 		 */
 		GpuParamDesc mParametersDesc;
 		GpuParamDesc mParametersDesc;
 
 
-		/**
-		 * @brief	Initializes the gpu program. This must be called right after the program is
-		 * 			constructed. Called by GpuManager upon creation, so usually you don't want
-		 * 			to call this manually.
-		 *		 
-		 * @note	Initialization is not done immediately, and is instead just scheduled on the
-		 * 			render thread. Unless called from render thread, in which case it is initialized
-		 * 			right away.
-		 */
-		void initialize();
-
-		/**
-		 * @copydoc Resource::destroy_internal.
-		 */
-		virtual void destroy_internal();
-
-        /** Internal method returns whether required capabilities for this program is supported.
-        */
-        bool isRequiredCapabilitiesSupported(void) const;
-
-		/// @copydoc Resource::calculateSize
-		size_t calculateSize(void) const { return 0; } // TODO 
-
-		void throwIfNotRenderThread() const;
-
-    protected:
-		friend class GpuProgramManager;
-
-		GpuProgram(const String& source, const String& entryPoint, const String& language, 
-			GpuProgramType gptype, GpuProgramProfile profile, bool isAdjacencyInfoRequired = false);
-
 		/************************************************************************/
 		/************************************************************************/
 		/* 								SERIALIZATION                      		*/
 		/* 								SERIALIZATION                      		*/
 		/************************************************************************/
 		/************************************************************************/

+ 11 - 22
CamelotRenderer/Include/CmHardwareBufferManager.h

@@ -48,20 +48,6 @@ namespace CamelotEngine {
 	*/
 	*/
 	class CM_EXPORT HardwareBufferManager : public Module<HardwareBufferManager>
 	class CM_EXPORT HardwareBufferManager : public Module<HardwareBufferManager>
 	{
 	{
-    protected:
-        /** WARNING: The following three members should place before all other members.
-            Members destruct order is very important here, because destructing other
-            members will cause notify back to this class, and then will access to this
-            two members.
-        */
-        typedef set<VertexBuffer*>::type VertexBufferList;
-        typedef set<IndexBuffer*>::type IndexBufferList;
-        VertexBufferList mVertexBuffers;
-        IndexBufferList mIndexBuffers;
-
-        /// Internal method for creates a new vertex declaration, may be overridden by certain rendering APIs
-        virtual VertexDeclarationPtr createVertexDeclarationImpl(void);
-
     public:
     public:
         HardwareBufferManager();
         HardwareBufferManager();
         virtual ~HardwareBufferManager();
         virtual ~HardwareBufferManager();
@@ -89,7 +75,7 @@ namespace CamelotEngine {
 			geometry shader.
 			geometry shader.
         */
         */
 		virtual VertexBufferPtr 
 		virtual VertexBufferPtr 
-            createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false) = 0;
+            createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut = false);
 
 
 		/** Create a hardware index buffer.
 		/** Create a hardware index buffer.
         @remarks Note that because buffers can be shared, they are reference
         @remarks Note that because buffers can be shared, they are reference
@@ -101,7 +87,7 @@ namespace CamelotEngine {
         @param usage One or more members of the HardwareBuffer::Usage enumeration.
         @param usage One or more members of the HardwareBuffer::Usage enumeration.
         */
         */
 		virtual IndexBufferPtr 
 		virtual IndexBufferPtr 
-            createIndexBuffer(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage) = 0;
+            createIndexBuffer(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage);
 
 
 		/**
 		/**
 		 * @brief	Creates an GPU parameter block that you can use for setting parameters
 		 * @brief	Creates an GPU parameter block that you can use for setting parameters
@@ -109,7 +95,7 @@ namespace CamelotEngine {
 		 *
 		 *
 		 * @return	The new GPU parameter block.
 		 * @return	The new GPU parameter block.
 		 */
 		 */
-		virtual GpuParamBlockPtr createGpuParamBlock(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage = GPBU_STATIC) = 0;
+		virtual GpuParamBlockPtr createGpuParamBlock(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage = GPBU_STATIC);
 
 
 		/**
 		/**
 		 * @brief	Creates a generic buffer that can be passed as a parameter to a shader.
 		 * @brief	Creates a generic buffer that can be passed as a parameter to a shader.
@@ -124,15 +110,18 @@ namespace CamelotEngine {
 		 * Be aware that some of these settings cannot be used together, and you will receive an assert if in debug mode.
 		 * Be aware that some of these settings cannot be used together, and you will receive an assert if in debug mode.
 		 */
 		 */
 		virtual GpuBufferPtr createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
 		virtual GpuBufferPtr createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
-			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false) = 0;
+			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
 
 
         /** Creates a new vertex declaration. */
         /** Creates a new vertex declaration. */
         virtual VertexDeclarationPtr createVertexDeclaration(void);
         virtual VertexDeclarationPtr createVertexDeclaration(void);
 
 
-		/// Notification that a hardware vertex buffer has been destroyed
-		void _notifyVertexBufferDestroyed(VertexBuffer* buf);
-		/// Notification that a hardware index buffer has been destroyed
-		void _notifyIndexBufferDestroyed(IndexBuffer* buf);
+	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, 
+			bool randomGpuWrite = false, bool useCounter = false) = 0;
 	};
 	};
 
 
 	/** @} */
 	/** @} */

+ 8 - 4
CamelotRenderer/Include/CmHighLevelGpuProgram.h

@@ -65,9 +65,6 @@ namespace CamelotEngine {
     public:
     public:
         virtual ~HighLevelGpuProgram();
         virtual ~HighLevelGpuProgram();
 
 
-		/** @copydoc GpuProgram::initialize_internal(). */
-		virtual void initialize_internal();
-
         /** @copydoc GpuProgram::getBindingDelegate */
         /** @copydoc GpuProgram::getBindingDelegate */
         virtual GpuProgram* getBindingDelegate(void) { return mAssemblerProgram.get(); }
         virtual GpuProgram* getBindingDelegate(void) { return mAssemblerProgram.get(); }
 
 
@@ -78,7 +75,14 @@ namespace CamelotEngine {
 		HighLevelGpuProgram(const String& source, const String& entryPoint, const String& language, 
 		HighLevelGpuProgram(const String& source, const String& entryPoint, const String& language, 
 			GpuProgramType gptype, GpuProgramProfile profile, bool isAdjacencyInfoRequired = false);
 			GpuProgramType gptype, GpuProgramProfile profile, bool isAdjacencyInfoRequired = false);
 
 
-		/** @copydoc GpuProgram::unload_internal() */
+		/**
+		 * @copydoc Resource::initialize_internal.
+		 */
+		virtual void initialize_internal();
+
+		/**
+		 * @copydoc Resource::destroy_internal.
+		 */
 		virtual void destroy_internal();
 		virtual void destroy_internal();
 
 
         /// The underlying assembler program
         /// The underlying assembler program

+ 1 - 7
CamelotRenderer/Include/CmIndexBuffer.h

@@ -50,9 +50,6 @@ namespace CamelotEngine
 			IT_32BIT
 			IT_32BIT
 		};
 		};
 
 
-		/// Should be called by HardwareBufferManager
-		IndexBuffer(HardwareBufferManager* mgr, IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage,
-			bool useSystemMemory);
 		~IndexBuffer();
 		~IndexBuffer();
 		/// Return the manager of this buffer, if any
 		/// Return the manager of this buffer, if any
 		HardwareBufferManager* getManager() const { return mMgr; }
 		HardwareBufferManager* getManager() const { return mMgr; }
@@ -69,10 +66,7 @@ namespace CamelotEngine
 		UINT32 mNumIndexes;
 		UINT32 mNumIndexes;
 		UINT32 mIndexSize;
 		UINT32 mIndexSize;
 
 
-		/**
-		* @copydoc CoreGpuObject::destroy_internal()
-		*/
-		virtual void destroy_internal();
+		IndexBuffer(HardwareBufferManager* mgr, IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage, bool useSystemMemory);
     };
     };
 	/** @} */
 	/** @} */
 }
 }

+ 5 - 3
CamelotRenderer/Include/CmMesh.h

@@ -28,8 +28,6 @@ namespace CamelotEngine
 	public:
 	public:
 		virtual ~Mesh();
 		virtual ~Mesh();
 
 
-		void initialize();
-
 		/**
 		/**
 		 * @brief	Mesh data that is used for initializing the mesh. Needs to be set before calling load.
 		 * @brief	Mesh data that is used for initializing the mesh. Needs to be set before calling load.
 		 */
 		 */
@@ -52,9 +50,13 @@ namespace CamelotEngine
 
 
 		vector<SubMesh>::type mSubMeshes;
 		vector<SubMesh>::type mSubMeshes;
 
 
-		virtual void initialize_internal();
 		void throwIfNotRenderThread() const;
 		void throwIfNotRenderThread() const;
 
 
+		/**
+		 * @copydoc Resource::initialize_internal()
+		 */
+		virtual void initialize_internal();
+
 		/**
 		/**
 		 * @copydoc Resource::destroy_internal()
 		 * @copydoc Resource::destroy_internal()
 		 */
 		 */

+ 0 - 1
CamelotRenderer/Include/CmMultiRenderTexture.h

@@ -20,7 +20,6 @@ namespace CamelotEngine
 		TextureView* mDepthStencilSurface;
 		TextureView* mDepthStencilSurface;
 
 
 		MultiRenderTexture();
 		MultiRenderTexture();
-		virtual void initialize() {}
 
 
 		virtual void setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0) = 0;
 		virtual void setColorSurfaceImpl(UINT32 surfaceIdx, TexturePtr texture, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0) = 0;
 		virtual void setDepthStencilImpl(TexturePtr depthStencilstencil, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0) = 0;
 		virtual void setDepthStencilImpl(TexturePtr depthStencilstencil, UINT32 face = 0, UINT32 numFaces = 1, UINT32 mipLevel = 0) = 0;

+ 1 - 0
CamelotRenderer/Include/CmPrerequisites.h

@@ -142,6 +142,7 @@ namespace CamelotEngine {
 	struct GpuParamObjectDesc;
 	struct GpuParamObjectDesc;
 	struct GpuParamBlockDesc;
 	struct GpuParamBlockDesc;
 	class TextureView;
 	class TextureView;
+	class CoreGpuObject;
 	// Asset import
 	// Asset import
 	class SpecificImporter;
 	class SpecificImporter;
 	class Importer;
 	class Importer;

+ 2 - 6
CamelotRenderer/Include/CmRenderTarget.h

@@ -71,7 +71,6 @@ namespace CamelotEngine
 			FB_AUTO
 			FB_AUTO
 		};
 		};
 
 
-        RenderTarget();
         virtual ~RenderTarget();
         virtual ~RenderTarget();
 
 
         /// Retrieve target's name.
         /// Retrieve target's name.
@@ -233,6 +232,8 @@ namespace CamelotEngine
 		virtual void _endUpdate();
 		virtual void _endUpdate();
 
 
     protected:
     protected:
+		RenderTarget();
+
         /// The name of this target.
         /// The name of this target.
         String mName;
         String mName;
 		/// The priority of the render target.
 		/// The priority of the render target.
@@ -248,11 +249,6 @@ namespace CamelotEngine
 		// FSAA performed?
 		// FSAA performed?
 		UINT32 mFSAA;
 		UINT32 mFSAA;
 		String mFSAAHint;
 		String mFSAAHint;
-			
-		/**
-		 * @copydoc CoreGpuObject::destroy_internal()
-		 */
-		virtual void destroy_internal();
     };
     };
 	/** @} */
 	/** @} */
 	/** @} */
 	/** @} */

+ 4 - 3
CamelotRenderer/Include/CmRenderTexture.h

@@ -56,9 +56,6 @@ namespace CamelotEngine
 		bool requiresTextureFlipping() const { return false; }
 		bool requiresTextureFlipping() const { return false; }
 
 
 	protected:
 	protected:
-		TextureView* mColorSurface;
-		TextureView* mDepthStencilSurface;
-
 		RenderTexture();
 		RenderTexture();
 
 
 		void createInternalResources();
 		void createInternalResources();
@@ -69,6 +66,10 @@ namespace CamelotEngine
 		 */
 		 */
 		virtual void destroy_internal();
 		virtual void destroy_internal();
 
 
+	protected:
+		TextureView* mColorSurface;
+		TextureView* mDepthStencilSurface;
+
 	private:
 	private:
 		void throwIfBuffersDontMatch() const;
 		void throwIfBuffersDontMatch() const;
 
 

+ 11 - 17
CamelotRenderer/Include/CmRenderWindow.h

@@ -95,17 +95,9 @@ namespace CamelotEngine
     */
     */
     class CM_EXPORT RenderWindow : public RenderTarget
     class CM_EXPORT RenderWindow : public RenderTarget
     {
     {
-
     public:
     public:
-        /** Default constructor.
-        */
-        RenderWindow();
 		virtual ~RenderWindow();
 		virtual ~RenderWindow();
 
 
-        /** Creates & displays a new window.
-        */
-		virtual void initialize(const RENDER_WINDOW_DESC& desc) = 0;
-
 		/** Alter fullscreen mode options. 
 		/** Alter fullscreen mode options. 
 		@note Nothing will happen unless the settings here are different from the
 		@note Nothing will happen unless the settings here are different from the
 			current settings.
 			current settings.
@@ -181,20 +173,22 @@ namespace CamelotEngine
 		static RenderWindowPtr create(const RENDER_WINDOW_DESC& desc);
 		static RenderWindowPtr create(const RENDER_WINDOW_DESC& desc);
 
 
     protected:
     protected:
-        bool mIsFullScreen;
-        bool mIsPrimary;
-        bool mAutoDeactivatedOnFocusChange;
-        int mLeft;
-        int mTop;
+        /** Default constructor.
+        */
+        RenderWindow(const RENDER_WINDOW_DESC& desc);
         
         
         /** Indicates that this is the primary window. 
         /** Indicates that this is the primary window. 
         */
         */
         void _setPrimary() { mIsPrimary = true; }
         void _setPrimary() { mIsPrimary = true; }
 
 
-		/**
-		 * @copydoc RenderTarget::destroy_internal()
-		 */
-		virtual void destroy_internal();
+	protected:
+		bool mIsFullScreen;
+		bool mIsPrimary;
+		bool mAutoDeactivatedOnFocusChange;
+		int mLeft;
+		int mTop;
+
+		RENDER_WINDOW_DESC mDesc;
     };
     };
 	/** @} */
 	/** @} */
 	/** @} */
 	/** @} */

+ 1 - 10
CamelotRenderer/Include/CmRenderWindowManager.h

@@ -10,19 +10,10 @@ namespace CamelotEngine
 	{
 	{
 	public:
 	public:
 		/** Creates a new rendering window.
 		/** Creates a new rendering window.
-		@remarks
-		This method creates a new rendering window as specified
-		by the parameters. The rendering system could be
-		responsible for only a single window (e.g. in the case
-		of a game), or could be in charge of multiple ones (in the
-		case of a level editor). The option to create the window
-		as a child of another is therefore given.
-		This method will create an appropriate subclass of
-		RenderWindow depending on the API and platform implementation.
 		*/
 		*/
 		RenderWindowPtr create(const RENDER_WINDOW_DESC& desc);
 		RenderWindowPtr create(const RENDER_WINDOW_DESC& desc);
 
 
 	protected:
 	protected:
-		virtual void createImpl(const RENDER_WINDOW_DESC& desc, AsyncOp& asyncOp) = 0;
+		virtual RenderWindowPtr createImpl(const RENDER_WINDOW_DESC& desc) = 0;
 	};
 	};
 }
 }

+ 0 - 34
CamelotRenderer/Include/CmResource.h

@@ -17,46 +17,12 @@ namespace CamelotEngine
 
 
 		const String& getUUID() const { return mUUID; }
 		const String& getUUID() const { return mUUID; }
 
 
-		/**
-		 * @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; }
-
-		/**
-		 * @brief	Blocks the current thread until the resource is fully initialized.
-		 */
-		void waitUntilInitialized();
-
 	protected:
 	protected:
 		friend class Resources;
 		friend class Resources;
-		
-		/**
-		 * @brief	Finishes up resource initialization. Usually called right after the resource is created.
-		 * 			Make sure that derived classes implement their own initialize_internal, and make sure
-		 * 			they call this implementation from it.
-		 */
-		virtual void initialize_internal();
-
-		/**
-		 * @copydoc CoreGpuObject::destroy_internal()
-		 */
-		virtual void destroy_internal();
-
-		/**
-		 * @brief	Marks the resource as initialized.
-		 */
-		void setInitialized() { mIsInitialized = true; }
 
 
 		String mUUID; 
 		String mUUID; 
 		UINT32 mSize;
 		UINT32 mSize;
 
 
-		// Transient
-		bool mIsInitialized;
-
-		CM_STATIC_THREAD_SYNCHRONISER(mResourceLoadedCondition)
-		CM_STATIC_MUTEX(mResourceLoadedMutex)
-
 	/************************************************************************/
 	/************************************************************************/
 	/* 								SERIALIZATION                      		*/
 	/* 								SERIALIZATION                      		*/
 	/************************************************************************/
 	/************************************************************************/

+ 9 - 0
CamelotRenderer/Include/CmResourceHandle.h

@@ -131,6 +131,15 @@ namespace CamelotEngine
 		T* operator->() const { return get(); }
 		T* operator->() const { return get(); }
 		T& operator*() const { return *get(); }
 		T& operator*() const { return *get(); }
 
 
+		/**
+		 * @brief	Releases the reference held by this handle.
+		 */
+		void reset()
+		{
+			mData->mPtr = nullptr;
+			mData->mIsCreated = false;
+		}
+
 		std::shared_ptr<T> getInternalPtr() 
 		std::shared_ptr<T> getInternalPtr() 
 		{ 
 		{ 
 			throwIfNotLoaded();
 			throwIfNotLoaded();

+ 4 - 4
CamelotRenderer/Include/CmTextureManager.h

@@ -58,9 +58,9 @@ namespace CamelotEngine {
     class CM_EXPORT TextureManager : public Module<TextureManager>
     class CM_EXPORT TextureManager : public Module<TextureManager>
     {
     {
 	protected:
 	protected:
-		virtual Texture* createTextureImpl() = 0;
-		virtual RenderTexture* createRenderTextureImpl() = 0;
-
+		virtual TexturePtr createTextureImpl() = 0;
+		virtual RenderTexturePtr createRenderTextureImpl() = 0;
+		virtual MultiRenderTexturePtr createMultiRenderTextureImpl() = 0;
     public:
     public:
 
 
         TextureManager(void);
         TextureManager(void);
@@ -187,7 +187,7 @@ namespace CamelotEngine {
 		 * @brief	Creates a new multi render texture. You may use this type of texture
 		 * @brief	Creates a new multi render texture. You may use this type of texture
 		 * 			to render to multiple output textures at once.
 		 * 			to render to multiple output textures at once.
 		 */
 		 */
-		virtual MultiRenderTexturePtr createMultiRenderTexture() = 0;
+		virtual MultiRenderTexturePtr createEmptyMultiRenderTexture();
 
 
 		/** Returns whether this render system can natively support the precise texture 
 		/** Returns whether this render system can natively support the precise texture 
 			format requested with the given usage options.
 			format requested with the given usage options.

+ 1 - 7
CamelotRenderer/Include/CmVertexBuffer.h

@@ -46,9 +46,6 @@ namespace CamelotEngine
     class CM_EXPORT VertexBuffer : public HardwareBuffer, public CoreGpuObject
     class CM_EXPORT VertexBuffer : public HardwareBuffer, public CoreGpuObject
     {
     {
 	public:
 	public:
-		/// Should be called by HardwareBufferManager
-		VertexBuffer(HardwareBufferManager* mgr, UINT32 vertexSize, UINT32 numVertices,
-            GpuBufferUsage usage, bool useSystemMemory);
         ~VertexBuffer();
         ~VertexBuffer();
 
 
 		/// Return the manager of this buffer, if any
 		/// Return the manager of this buffer, if any
@@ -62,10 +59,7 @@ namespace CamelotEngine
 		UINT32 mNumVertices;
 		UINT32 mNumVertices;
 		UINT32 mVertexSize;
 		UINT32 mVertexSize;
 
 
-		/**
-		 * @copydoc CoreGpuObject::destroy_internal()
-		 */
-		virtual void destroy_internal();
+		VertexBuffer(HardwareBufferManager* mgr, UINT32 vertexSize, UINT32 numVertices, GpuBufferUsage usage, bool useSystemMemory);
     };
     };
 }
 }
 #endif
 #endif

+ 6 - 8
CamelotRenderer/Include/CmVertexDeclaration.h

@@ -250,8 +250,6 @@ namespace CamelotEngine
         /// Sort routine for vertex elements
         /// Sort routine for vertex elements
         static bool vertexElementLess(const VertexElement& e1, const VertexElement& e2);
         static bool vertexElementLess(const VertexElement& e1, const VertexElement& e2);
 
 
-        /// Standard constructor, not you should use HardwareBufferManager::createVertexDeclaration
-        VertexDeclaration();
         virtual ~VertexDeclaration();
         virtual ~VertexDeclaration();
 
 
         /** Get the number of elements in the declaration. */
         /** Get the number of elements in the declaration. */
@@ -396,18 +394,18 @@ namespace CamelotEngine
         }
         }
 
 
     protected:
     protected:
-        VertexElementList mElementList;
-		size_t mHash;
+		friend class HardwareBufferManager;
+
+		VertexDeclaration();
 
 
 		/**
 		/**
 		 * @brief	Generates a hash value based on all elements in the declaration.
 		 * @brief	Generates a hash value based on all elements in the declaration.
 		 */
 		 */
 		void recalculateHash();
 		void recalculateHash();
 
 
-		/**
-		 * @copydoc CoreGpuObject::destroy_internal()
-		 */
-		virtual void destroy_internal();
+	protected:
+		VertexElementList mElementList;
+		size_t mHash;
 
 
 		/************************************************************************/
 		/************************************************************************/
 		/* 								SERIALIZATION                      		*/
 		/* 								SERIALIZATION                      		*/

+ 10 - 3
CamelotRenderer/Source/CmApplication.cpp

@@ -11,6 +11,7 @@
 #include "CmVector2.h"
 #include "CmVector2.h"
 #include "CmHighLevelGpuProgram.h"
 #include "CmHighLevelGpuProgram.h"
 #include "CmHighLevelGpuProgramManager.h"
 #include "CmHighLevelGpuProgramManager.h"
+#include "CmCoreGpuObjectManager.h"
 #include "CmDynLib.h"
 #include "CmDynLib.h"
 #include "CmDynLibManager.h"
 #include "CmDynLibManager.h"
 #include "CmSceneManager.h"
 #include "CmSceneManager.h"
@@ -42,6 +43,8 @@ namespace CamelotEngine
 		Time::startUp(new Time());
 		Time::startUp(new Time());
 		Input::startUp(new Input());
 		Input::startUp(new Input());
 		DynLibManager::startUp(new DynLibManager());
 		DynLibManager::startUp(new DynLibManager());
+		CoreGpuObjectManager::startUp(new CoreGpuObjectManager());
+		Resources::startUp(new Resources("D:\\CamelotResourceMetas"));
 		HighLevelGpuProgramManager::startUp(new HighLevelGpuProgramManager());
 		HighLevelGpuProgramManager::startUp(new HighLevelGpuProgramManager());
 
 
 		RenderSystemManager::startUp(renderSystemName);
 		RenderSystemManager::startUp(renderSystemName);
@@ -58,10 +61,14 @@ namespace CamelotEngine
 		renderWindowDesc.fullscreen = false;
 		renderWindowDesc.fullscreen = false;
 
 
 		mPrimaryRenderWindow = RenderWindow::create(renderWindowDesc);
 		mPrimaryRenderWindow = RenderWindow::create(renderWindowDesc);
+		mPrimaryRenderWindow->waitUntilInitialized(); // TODO: Created window is required for proper initialization of the render system so I need to wait
+		                                              // I plan on handling this differently. Either by somehow allowing the RS to be initialized without a window,
+		                                              // or forcing a window to be created with RenderSystemManager::startUp. Initializing OpenGL context without a window
+		                                              // is especially troublesome (apparently possible just poorly documented)
+
 		mPrimaryRenderContext = renderSystem->createDeferredContext();
 		mPrimaryRenderContext = renderSystem->createDeferredContext();
 
 
 		SceneManager::startUp(new SceneManager());
 		SceneManager::startUp(new SceneManager());
-		Resources::startUp(new Resources("D:\\CamelotResourceMetas"));
 
 
 		Importer::startUp(new Importer());
 		Importer::startUp(new Importer());
 		loadPlugin("CamelotFreeImgImporter"); // TODO - Load this automatically somehow
 		loadPlugin("CamelotFreeImgImporter"); // TODO - Load this automatically somehow
@@ -139,9 +146,9 @@ namespace CamelotEngine
 		RenderSystem::shutDown();
 		RenderSystem::shutDown();
 
 
 		HighLevelGpuProgramManager::shutDown();
 		HighLevelGpuProgramManager::shutDown();
-		//DynLibManager::shutDown(); // TODO - I never shut this down, because then I'd have to ensure I classes loaded from dynamic libraries
-		// are destroyed before shutting it down, which is too hard to ensure at the moment
 		Resources::shutDown();
 		Resources::shutDown();
+		CoreGpuObjectManager::shutDown(); // Must shut down before DynLibManager to ensure all objects are destroyed before unloading their libraries
+		DynLibManager::shutDown();
 		Input::shutDown();
 		Input::shutDown();
 		Time::shutDown();
 		Time::shutDown();
 	}
 	}

+ 62 - 4
CamelotRenderer/Source/CmCoreGpuObject.cpp

@@ -1,28 +1,86 @@
 #include "CmCoreGpuObject.h"
 #include "CmCoreGpuObject.h"
 #include "CmRenderSystem.h"
 #include "CmRenderSystem.h"
+#include "CmCoreGpuObjectManager.h"
 #include "CmDebug.h"
 #include "CmDebug.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
+	CM_STATIC_THREAD_SYNCHRONISER_CLASS_INSTANCE(mCoreGpuObjectLoadedCondition, CoreGpuObject)
+	CM_STATIC_MUTEX_CLASS_INSTANCE(mCoreGpuObjectLoadedMutex, CoreGpuObject)
+
 	CoreGpuObject::CoreGpuObject()
 	CoreGpuObject::CoreGpuObject()
-		:mDestroyed(false)
-	{ }
+		: mIsInitialized(false), mInternalID(0)
+	{
+		mInternalID = CoreGpuObjectManager::instance().registerObject(this);
+	}
 
 
 	CoreGpuObject::~CoreGpuObject() 
 	CoreGpuObject::~CoreGpuObject() 
 	{
 	{
-		if(!mDestroyed)
+		if(mIsInitialized)
 		{
 		{
 			LOGWRN("Destructor called but object is not destroyed. Object will leak.")
 			LOGWRN("Destructor called but object is not destroyed. Object will leak.")
 		}
 		}
+
+		CoreGpuObjectManager::instance().unregisterObject(this);
 	}
 	}
 
 
 	void CoreGpuObject::destroy()
 	void CoreGpuObject::destroy()
 	{
 	{
+#if CM_DEBUG_MODE
+		if(!mIsInitialized)
+			CM_EXCEPT(InternalErrorException, "Trying to destroy an object that is already destroyed (or it never was initialized).");
+#endif
+
+		CoreGpuObjectManager::instance().registerObjectToDestroy(mThis.lock());
 		RenderSystem::instancePtr()->queueCommand(boost::bind(&CoreGpuObject::destroy_internal, this));
 		RenderSystem::instancePtr()->queueCommand(boost::bind(&CoreGpuObject::destroy_internal, this));
 	}
 	}
 
 
 	void CoreGpuObject::destroy_internal()
 	void CoreGpuObject::destroy_internal()
 	{
 	{
-		mDestroyed = true;
+		mIsInitialized = false;
+
+		CoreGpuObjectManager::instance().unregisterObjectToDestroy(mThis.lock());
+	}
+
+	void CoreGpuObject::initialize()
+	{
+#if CM_DEBUG_MODE
+		if(mIsInitialized)
+			CM_EXCEPT(InternalErrorException, "Trying to initialize an object that is already initialized");
+#endif
+
+		RenderSystem::instancePtr()->queueCommand(boost::bind(&CoreGpuObject::initialize_internal, this));
+	}
+
+	void CoreGpuObject::initialize_internal()
+	{
+		{
+			CM_LOCK_MUTEX(mCoreGpuObjectLoadedMutex);
+			mIsInitialized = true;
+		}	
+
+		CM_THREAD_NOTIFY_ALL(mCoreGpuObjectLoadedCondition);
+	}
+
+	void CoreGpuObject::waitUntilInitialized()
+	{
+#if CM_DEBUG_MODE
+		if(CM_THREAD_CURRENT_ID == RenderSystem::instancePtr()->getRenderThreadId())
+			CM_EXCEPT(InternalErrorException, "You cannot call this method on the render thread. It will cause a deadlock!");
+#endif
+
+		if(!mIsInitialized)
+		{
+			CM_LOCK_MUTEX_NAMED(mCoreGpuObjectLoadedMutex, lock);
+			while(!mIsInitialized)
+			{
+				CM_THREAD_WAIT(mCoreGpuObjectLoadedCondition, mCoreGpuObjectLoadedMutex, lock);
+			}
+		}
+	}
+
+	void CoreGpuObject::setThisPtr(std::shared_ptr<CoreGpuObject> ptrThis)
+	{
+		mThis = ptrThis;
 	}
 	}
 }
 }

+ 67 - 0
CamelotRenderer/Source/CmCoreGpuObjectManager.cpp

@@ -0,0 +1,67 @@
+#include "CmCoreGpuObjectManager.h"
+#include "CmCoreGpuObject.h"
+#include "CmException.h"
+
+namespace CamelotEngine
+{
+	CoreGpuObjectManager::CoreGpuObjectManager()
+		:mNextAvailableID(1)
+	{
+
+	}
+
+	CoreGpuObjectManager::~CoreGpuObjectManager()
+	{
+		CM_LOCK_MUTEX(mObjectsMutex);
+
+		if(mObjects.size() > 0)
+		{
+			// All objects MUST be destroyed at this point, otherwise there might be memory corruption.
+			// (Reason: This is called on application shutdown and at that point we also unload any dynamic libraries, 
+			// which will invalidate any pointers to objects created from those libraries. Therefore we require of the user to 
+			// clean up all objects manually before shutting down the application).
+			CM_EXCEPT(InternalErrorException, "Core GPU object manager destroyed, but not all objects were released. User must release ALL " \
+				"engine objects before application shutdown.");
+		}
+
+		if(mObjectsToDestroy.size() > 0)
+		{
+			// This should never happen as higher levels of the engine make sure all scheduled objects are destroyed before shutdown is initialized.
+			CM_EXCEPT(InternalErrorException, "Objects scheduled for destruction, but shutdown initialized before destruction completed.");
+		}
+	}
+
+	UINT64 CoreGpuObjectManager::registerObject(CoreGpuObject* object)
+	{
+		assert(object != nullptr);
+
+		CM_LOCK_MUTEX(mObjectsMutex);
+
+		mObjects[mNextAvailableID] = object;
+
+		return mNextAvailableID++;
+	}
+
+	void CoreGpuObjectManager::unregisterObject(CoreGpuObject* object)
+	{
+		assert(object != nullptr);
+
+		CM_LOCK_MUTEX(mObjectsMutex);
+
+		mObjects.erase(object->getInternalID());
+	}
+
+	void CoreGpuObjectManager::registerObjectToDestroy(std::shared_ptr<CoreGpuObject> object)
+	{
+		CM_LOCK_MUTEX(mObjectsToDestroyMutex);
+
+		mObjectsToDestroy[object->getInternalID()] = object;
+	}
+
+	void CoreGpuObjectManager::unregisterObjectToDestroy(std::shared_ptr<CoreGpuObject> object)
+	{
+		CM_LOCK_MUTEX(mObjectsToDestroyMutex);
+
+		mObjectsToDestroy.erase(object->getInternalID());
+	}
+}

+ 0 - 16
CamelotRenderer/Source/CmGpuProgram.cpp

@@ -56,22 +56,6 @@ namespace CamelotEngine
 	GpuProgram::~GpuProgram()
 	GpuProgram::~GpuProgram()
 	{
 	{
 	}
 	}
-	//---------------------------------------------------------------------------
-	void GpuProgram::initialize()
-	{
-		RenderSystem::instancePtr()->queueCommand(boost::bind(&GpuProgram::initialize_internal, this));
-	}
-	//---------------------------------------------------------------------------
-    void GpuProgram::initialize_internal(void)
-    {
-		// Nothing to initialize
-		Resource::initialize_internal();
-    }
-	//---------------------------------------------------------------------------
-	void GpuProgram::destroy_internal()
-	{
-		CoreGpuObject::destroy_internal();
-	}
     //-----------------------------------------------------------------------------
     //-----------------------------------------------------------------------------
     bool GpuProgram::isSupported(void) const
     bool GpuProgram::isSupported(void) const
     {
     {

+ 5 - 0
CamelotRenderer/Source/CmGpuProgramManager.cpp

@@ -45,6 +45,11 @@ namespace CamelotEngine {
 	GpuProgramPtr GpuProgramManager::createProgram(const String& source, const String& entryPoint, const String& language, GpuProgramType gptype, GpuProgramProfile profile)
 	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));
+		prg->setThisPtr(prg);
+
+		// TODO: Gpu programs get initialized by their parent HighLevelGpuProgram. I might handle that more intuitively later but
+		// it works just fine as it is
+		//prg->initialize();
 
 
         return prg;
         return prg;
     }
     }

+ 33 - 18
CamelotRenderer/Source/CmHardwareBufferManager.cpp

@@ -29,6 +29,7 @@ THE SOFTWARE.
 #include "CmHardwareBufferManager.h"
 #include "CmHardwareBufferManager.h"
 #include "CmVertexData.h"
 #include "CmVertexData.h"
 #include "CmIndexData.h"
 #include "CmIndexData.h"
+#include "CmGpuBuffer.h"
 #include "CmVertexDeclaration.h"
 #include "CmVertexDeclaration.h"
 
 
 namespace CamelotEngine {
 namespace CamelotEngine {
@@ -39,39 +40,53 @@ namespace CamelotEngine {
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     HardwareBufferManager::~HardwareBufferManager()
     HardwareBufferManager::~HardwareBufferManager()
     {
     {
-        // Clear vertex/index buffer list first, avoid destroyed notify do
-        // unnecessary work, and we'll destroy everything here.
-		mVertexBuffers.clear();
-		mIndexBuffers.clear();
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     VertexDeclarationPtr HardwareBufferManager::createVertexDeclaration(void)
     VertexDeclarationPtr HardwareBufferManager::createVertexDeclaration(void)
     {
     {
         VertexDeclarationPtr decl = createVertexDeclarationImpl();
         VertexDeclarationPtr decl = createVertexDeclarationImpl();
+		decl->setThisPtr(decl);
+		decl->initialize();
         return decl;
         return decl;
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     VertexDeclarationPtr HardwareBufferManager::createVertexDeclarationImpl(void)
     VertexDeclarationPtr HardwareBufferManager::createVertexDeclarationImpl(void)
     {
     {
-        return VertexDeclarationPtr(new VertexDeclaration());
+		return VertexDeclarationPtr(new VertexDeclaration());
     }
     }
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------
-	void HardwareBufferManager::_notifyVertexBufferDestroyed(VertexBuffer* buf)
+	VertexBufferPtr HardwareBufferManager::createVertexBuffer(UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
 	{
 	{
-		VertexBufferList::iterator i = mVertexBuffers.find(buf);
-		if (i != mVertexBuffers.end())
-		{
-            // release vertex buffer copies
-			mVertexBuffers.erase(i);
-		}
+		assert (numVerts > 0);
+
+		VertexBufferPtr vbuf = createVertexBufferImpl(vertexSize, numVerts, usage, streamOut);
+		vbuf->setThisPtr(vbuf);
+		vbuf->initialize();
+		return vbuf;
+	}
+	//-----------------------------------------------------------------------
+	IndexBufferPtr HardwareBufferManager::createIndexBuffer(IndexBuffer::IndexType itype, UINT32 numIndexes, GpuBufferUsage usage)
+	{
+		assert (numIndexes > 0);
+
+		IndexBufferPtr ibuf = createIndexBufferImpl(itype, numIndexes, usage);
+		ibuf->setThisPtr(ibuf);
+		ibuf->initialize();
+		return ibuf;
+
+	}
+	//-----------------------------------------------------------------------
+	GpuParamBlockPtr HardwareBufferManager::createGpuParamBlock(const GpuParamBlockDesc& paramDesc, GpuParamBlockUsage usage)
+	{
+		return createGpuParamBlockImpl(paramDesc, usage);
 	}
 	}
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------
-	void HardwareBufferManager::_notifyIndexBufferDestroyed(IndexBuffer* buf)
+	GpuBufferPtr HardwareBufferManager::createGpuBuffer(UINT32 elementCount, UINT32 elementSize, 
+		GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite, bool useCounter)
 	{
 	{
-		IndexBufferList::iterator i = mIndexBuffers.find(buf);
-		if (i != mIndexBuffers.end())
-		{
-			mIndexBuffers.erase(i);
-		}
+		GpuBufferPtr gbuf = createGpuBufferImpl(elementCount, elementSize, type, usage, randomGpuWrite, useCounter);
+		gbuf->setThisPtr(gbuf);
+		gbuf->initialize();
+		return gbuf;
 	}
 	}
 }
 }

Some files were not shown because too many files changed in this diff