فهرست منبع

Creating a resource will return a handle instead of a pointer

Marko Pintera 13 سال پیش
والد
کامیت
f6f19866d5
37فایلهای تغییر یافته به همراه172 افزوده شده و 120 حذف شده
  1. 18 42
      CamelotClient/CamelotClient.cpp
  2. 1 1
      CamelotFBXImporter/Include/CmFBXImporter.h
  3. 3 3
      CamelotFBXImporter/Source/CmFBXImporter.cpp
  4. 1 1
      CamelotFreeImgImporter/Include/CmFreeImgImporter.h
  5. 4 4
      CamelotFreeImgImporter/Source/CmFreeImgImporter.cpp
  6. 2 0
      CamelotRenderer/CamelotRenderer.vcxproj
  7. 6 0
      CamelotRenderer/CamelotRenderer.vcxproj.filters
  8. 1 1
      CamelotRenderer/Include/CmBlendState.h
  9. 1 1
      CamelotRenderer/Include/CmDepthStencilState.h
  10. 1 1
      CamelotRenderer/Include/CmHighLevelGpuProgram.h
  11. 1 2
      CamelotRenderer/Include/CmImporter.h
  12. 8 1
      CamelotRenderer/Include/CmMaterial.h
  13. 14 0
      CamelotRenderer/Include/CmMaterialManager.cpp
  14. 13 0
      CamelotRenderer/Include/CmMaterialManager.h
  15. 1 4
      CamelotRenderer/Include/CmMaterialRTTI.h
  16. 1 1
      CamelotRenderer/Include/CmMesh.h
  17. 1 1
      CamelotRenderer/Include/CmRasterizerState.h
  18. 5 0
      CamelotRenderer/Include/CmResource.h
  19. 20 10
      CamelotRenderer/Include/CmResourceHandle.h
  20. 2 4
      CamelotRenderer/Include/CmResources.h
  21. 1 1
      CamelotRenderer/Include/CmSamplerState.h
  22. 1 1
      CamelotRenderer/Include/CmSpecificImporter.h
  23. 2 2
      CamelotRenderer/Include/CmTexture.h
  24. 3 0
      CamelotRenderer/Source/CmApplication.cpp
  25. 4 2
      CamelotRenderer/Source/CmBlendState.cpp
  26. 4 2
      CamelotRenderer/Source/CmDepthStencilState.cpp
  27. 4 2
      CamelotRenderer/Source/CmHighLevelGpuProgram.cpp
  28. 4 4
      CamelotRenderer/Source/CmImporter.cpp
  29. 4 5
      CamelotRenderer/Source/CmMaterial.cpp
  30. 6 0
      CamelotRenderer/Source/CmMaterialRTTI.cpp
  31. 4 2
      CamelotRenderer/Source/CmMesh.cpp
  32. 4 2
      CamelotRenderer/Source/CmRasterizerState.cpp
  33. 5 0
      CamelotRenderer/Source/CmResource.cpp
  34. 8 9
      CamelotRenderer/Source/CmResources.cpp
  35. 4 2
      CamelotRenderer/Source/CmSamplerState.cpp
  36. 8 4
      CamelotRenderer/Source/CmTexture.cpp
  37. 2 5
      CamelotRenderer/TODO.txt

+ 18 - 42
CamelotClient/CamelotClient.cpp

@@ -25,11 +25,6 @@
 
 
 using namespace CamelotEngine;
 using namespace CamelotEngine;
 
 
-void doNothing()
-{
-
-}
-
 int CALLBACK WinMain(
 int CALLBACK WinMain(
 	_In_  HINSTANCE hInstance,
 	_In_  HINSTANCE hInstance,
 	_In_  HINSTANCE hPrevInstance,
 	_In_  HINSTANCE hPrevInstance,
@@ -58,9 +53,6 @@ int CALLBACK WinMain(
 	GameObjectPtr testModelGO = GameObject::create("TestMesh");
 	GameObjectPtr testModelGO = GameObject::create("TestMesh");
 	RenderablePtr testRenderable = testModelGO->addComponent<Renderable>();
 	RenderablePtr testRenderable = testModelGO->addComponent<Renderable>();
 
 
-	HighLevelGpuProgramPtr fragProg;
-	HighLevelGpuProgramPtr vertProg;
-
 	/////////////////// HLSL 9 SHADERS //////////////////////////
 	/////////////////// HLSL 9 SHADERS //////////////////////////
 	//String fragShaderCode = "sampler2D tex;			\
 	//String fragShaderCode = "sampler2D tex;			\
 	//						float4 ps_main(float2 uv : TEXCOORD0) : COLOR0		\
 	//						float4 ps_main(float2 uv : TEXCOORD0) : COLOR0		\
@@ -69,7 +61,7 @@ int CALLBACK WinMain(
 	//						return color;										\
 	//						return color;										\
 	//						}";
 	//						}";
 
 
-	//fragProg =  HighLevelGpuProgram::create(fragShaderCode, "ps_main", "hlsl", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
+	//HighLevelGpuProgramHandle fragProgRef =  HighLevelGpuProgram::create(fragShaderCode, "ps_main", "hlsl", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
 
 
 	//String vertShaderCode = "float4x4 matViewProjection;	\
 	//String vertShaderCode = "float4x4 matViewProjection;	\
 	//						void vs_main(										\
 	//						void vs_main(										\
@@ -82,7 +74,7 @@ int CALLBACK WinMain(
 	//						oUv = uv;											\
 	//						oUv = uv;											\
 	//						}";
 	//						}";
 
 
-	//vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "hlsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
+	//HighLevelGpuProgramHandle vertProgRef =  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);			\
@@ -93,7 +85,7 @@ int CALLBACK WinMain(
 							return color;										\
 							return color;										\
 							}";
 							}";
 
 
-	fragProg =  HighLevelGpuProgram::create(fragShaderCode, "ps_main", "hlsl", GPT_FRAGMENT_PROGRAM, GPP_PS_4_0);
+	HighLevelGpuProgramHandle fragProgRef =  HighLevelGpuProgram::create(fragShaderCode, "ps_main", "hlsl", GPT_FRAGMENT_PROGRAM, GPP_PS_4_0);
 
 
 	String vertShaderCode = "float4x4 matViewProjection;	\
 	String vertShaderCode = "float4x4 matViewProjection;	\
 							void vs_main(										\
 							void vs_main(										\
@@ -106,7 +98,7 @@ int CALLBACK WinMain(
 							oUv = uv;											\
 							oUv = uv;											\
 							}";
 							}";
 
 
-	vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "hlsl", GPT_VERTEX_PROGRAM, GPP_VS_4_0);
+	HighLevelGpuProgramHandle vertProgRef =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "hlsl", GPT_VERTEX_PROGRAM, GPP_VS_4_0);
 
 
 	/////////////////// CG SHADERS //////////////////////////
 	/////////////////// CG SHADERS //////////////////////////
 	//String fragShaderCode = "sampler2D tex;					\
 	//String fragShaderCode = "sampler2D tex;					\
@@ -116,7 +108,7 @@ int CALLBACK WinMain(
 	//						return color;										\
 	//						return color;										\
 	//						}";
 	//						}";
 
 
-	//fragProg =  HighLevelGpuProgram::create(fragShaderCode, "ps_main", "cg", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
+	//HighLevelGpuProgramHandle fragProgRef =  HighLevelGpuProgram::create(fragShaderCode, "ps_main", "cg", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
 
 
 	//String vertShaderCode = "float4x4 matViewProjection;	\
 	//String vertShaderCode = "float4x4 matViewProjection;	\
 	//						void vs_main(										\
 	//						void vs_main(										\
@@ -129,7 +121,7 @@ int CALLBACK WinMain(
 	//						oUv = cm_texcoord0;											\
 	//						oUv = cm_texcoord0;											\
 	//						}";
 	//						}";
 
 
-	//vertProg =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "cg", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
+	//HighLevelGpuProgramHandle vertProgRef =  HighLevelGpuProgram::create(vertShaderCode, "vs_main", "cg", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 
 
 	///////////////// GLSL SHADERS ////////////////////////////
 	///////////////// GLSL SHADERS ////////////////////////////
 	//String fragShaderCode = " #version 400 \n \
 	//String fragShaderCode = " #version 400 \n \
@@ -142,7 +134,7 @@ int CALLBACK WinMain(
 	//							  fragColor = texColor; \
 	//							  fragColor = texColor; \
 	//						  }";
 	//						  }";
 
 
-	//fragProg = HighLevelGpuProgram::create(fragShaderCode, "main", "glsl", GPT_FRAGMENT_PROGRAM, GPP_PS_2_0);
+	//HighLevelGpuProgramHandle fragProgRef = 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)
 	//// TODO - Make sure to document the strict input parameter naming. (Exact supported names are in GLSLParamParser)
 	//String vertShaderCode = "#version 400 \n \
 	//String vertShaderCode = "#version 400 \n \
@@ -156,13 +148,13 @@ int CALLBACK WinMain(
 	//							gl_Position = cm_position * matViewProjection; \
 	//							gl_Position = cm_position * matViewProjection; \
 	//						 }";
 	//						 }";
 
 
-	//vertProg = HighLevelGpuProgram::create(vertShaderCode, "main", "glsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
+	//HighLevelGpuProgramHandle vertProgRef= HighLevelGpuProgram::create(vertShaderCode, "main", "glsl", GPT_VERTEX_PROGRAM, GPP_VS_2_0);
 
 
-	HighLevelGpuProgramHandle vertProgRef = gResources().create(vertProg, "C:\\vertProgCg.vprog", true);
+	gResources().create(vertProgRef, "C:\\vertProgCg.vprog", true);
 	gResources().unload(vertProgRef);
 	gResources().unload(vertProgRef);
 	vertProgRef = gResources().load("C:\\vertProgCg.vprog");
 	vertProgRef = gResources().load("C:\\vertProgCg.vprog");
 
 
-	HighLevelGpuProgramHandle fragProgRef = gResources().create(fragProg, "C:\\fragProgCg.vprog", true);
+	gResources().create(fragProgRef, "C:\\fragProgCg.vprog", true);
 	gResources().unload(fragProgRef);
 	gResources().unload(fragProgRef);
 	fragProgRef = gResources().load("C:\\fragProgCg.vprog");
 	fragProgRef = gResources().load("C:\\fragProgCg.vprog");
 
 
@@ -175,7 +167,6 @@ int CALLBACK WinMain(
 	newPassGL->setVertexProgram(vertProgRef);
 	newPassGL->setVertexProgram(vertProgRef);
 	newPassGL->setFragmentProgram(fragProgRef);
 	newPassGL->setFragmentProgram(fragProgRef);
 
 
-
 	// TODO - I need to create different techniques for different render systems (and renderers, if there were any),
 	// TODO - I need to create different techniques for different render systems (and renderers, if there were any),
 	// which is redundant as some techniques can be reused. I should add a functionality that supports multiple
 	// which is redundant as some techniques can be reused. I should add a functionality that supports multiple
 	// render systems/renderers per technique
 	// render systems/renderers per technique
@@ -189,37 +180,29 @@ int CALLBACK WinMain(
 	newPassDX11->setVertexProgram(vertProgRef);
 	newPassDX11->setVertexProgram(vertProgRef);
 	newPassDX11->setFragmentProgram(fragProgRef);
 	newPassDX11->setFragmentProgram(fragProgRef);
 
 
-	MaterialPtr testMaterial = Material::create();
-	testMaterial->waitUntilInitialized(); // TODO - Material doesn't do anything GPU specific, so technically it should be possible to initialize on the spot
+	MaterialHandle testMaterial = Material::create();
+	testMaterial.waitUntilLoaded(); // TODO - Material doesn't do anything GPU specific, so technically it should be possible to initialize on the spot
 	// but is that a good idea?
 	// but is that a good idea?
 	testMaterial->setShader(testShader);
 	testMaterial->setShader(testShader);
 
 
 	testMaterial->setMat4("matViewProjection", Matrix4::IDENTITY);
 	testMaterial->setMat4("matViewProjection", Matrix4::IDENTITY);
-
-	RenderSystem::instance().queueCommand(&doNothing, true);
-
-	MaterialHandle testMaterialRef = gResources().create(testMaterial, "C:\\testMaterial.mat", true);
 	//testMaterialRef = gResources().load("C:\\testMaterial.mat");
 	//testMaterialRef = gResources().load("C:\\testMaterial.mat");
 	//testMaterialRef.waitUntilLoaded();
 	//testMaterialRef.waitUntilLoaded();
 
 
 	/*TextureRef testTex = static_resource_cast<Texture>(Importer::instance().import("C:\\ImportTest.tga"));*/
 	/*TextureRef testTex = static_resource_cast<Texture>(Importer::instance().import("C:\\ImportTest.tga"));*/
-	TexturePtr testTex = std::static_pointer_cast<Texture>(Importer::instance().import("C:\\ArenaTowerDFS.psd"));
-	MeshPtr dbgMesh = std::static_pointer_cast<Mesh>(Importer::instance().import("C:\\X_Arena_Tower.FBX"));
+	TextureHandle testTexRef = static_resource_cast<Texture>(Importer::instance().import("C:\\ArenaTowerDFS.psd"));
+	MeshHandle dbgMeshRef = static_resource_cast<Mesh>(Importer::instance().import("C:\\X_Arena_Tower.FBX"));
 
 
 	//int tmpFlag = _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_CRT_DF | _CRTDBG_DELAY_FREE_MEM_DF);
 	//int tmpFlag = _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_CRT_DF | _CRTDBG_DELAY_FREE_MEM_DF);
 
 
-	TextureHandle testTexRef = gResources().create(testTex, "C:\\ExportTest.tex", true);
-	MeshHandle dbgMeshRef = gResources().create(dbgMesh, "C:\\ExportMesh.mesh", true);
+	gResources().create(testTexRef, "C:\\ExportTest.tex", true);
+	gResources().create(dbgMeshRef, "C:\\ExportMesh.mesh", true);
 
 
 	gResources().unload(testTexRef);
 	gResources().unload(testTexRef);
 	gResources().unload(dbgMeshRef);
 	gResources().unload(dbgMeshRef);
 
 
 	testTexRef = static_resource_cast<Texture>(gResources().load("C:\\ExportTest.tex"));
 	testTexRef = static_resource_cast<Texture>(gResources().load("C:\\ExportTest.tex"));
-	RenderSystem::instance().queueCommand(&doNothing, true);
-
 	dbgMeshRef = static_resource_cast<Mesh>(gResources().load("C:\\ExportMesh.mesh"));
 	dbgMeshRef = static_resource_cast<Mesh>(gResources().load("C:\\ExportMesh.mesh"));
-	RenderSystem::instance().queueCommand(&doNothing, true);
-
 
 
 	testMaterial->setTexture("tex", testTexRef);
 	testMaterial->setTexture("tex", testTexRef);
 	//gResources().create(testMaterial, "C:\\ExportMaterial.mat", true);
 	//gResources().create(testMaterial, "C:\\ExportMaterial.mat", true);
@@ -231,7 +214,7 @@ int CALLBACK WinMain(
 	//dbgMeshRef.waitUntilLoaded();
 	//dbgMeshRef.waitUntilLoaded();
 
 
 	testRenderable->setMesh(dbgMeshRef);
 	testRenderable->setMesh(dbgMeshRef);
-	testRenderable->setMaterial(testMaterialRef);
+	testRenderable->setMaterial(testMaterial);
 
 
 	//// Set the new state for the flag
 	//// Set the new state for the flag
 	//_CrtSetDbgFlag( tmpFlag );
 	//_CrtSetDbgFlag( tmpFlag );
@@ -241,20 +224,13 @@ int CALLBACK WinMain(
 	// Release everything before shutdown
 	// Release everything before shutdown
 	
 	
 	//testMaterial->destroy();
 	//testMaterial->destroy();
-	testMaterial = nullptr;
+	testMaterial.reset();
 
 
-	gResources().unload(testMaterialRef);
 	gResources().unload(testTexRef);
 	gResources().unload(testTexRef);
 	gResources().unload(dbgMeshRef);
 	gResources().unload(dbgMeshRef);
 	gResources().unload(fragProgRef);
 	gResources().unload(fragProgRef);
 	gResources().unload(vertProgRef);
 	gResources().unload(vertProgRef);
 
 
-	fragProg = nullptr;
-	vertProg = nullptr;
-
-	testTex = nullptr;
-	dbgMesh = nullptr;
-
 	testModelGO->destroy();
 	testModelGO->destroy();
 	testModelGO = nullptr;
 	testModelGO = nullptr;
 	testRenderable = nullptr;
 	testRenderable = nullptr;

+ 1 - 1
CamelotFBXImporter/Include/CmFBXImporter.h

@@ -35,7 +35,7 @@ namespace CamelotEngine
 		virtual bool isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const; 
 		virtual bool isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const; 
 
 
 		/** Inherited from SpecificImporter */
 		/** Inherited from SpecificImporter */
-		virtual ResourcePtr import(const String& filePath);
+		virtual BaseResourceHandle import(const String& filePath);
 	private:
 	private:
 		vector<String>::type mExtensions;
 		vector<String>::type mExtensions;
 
 

+ 3 - 3
CamelotFBXImporter/Source/CmFBXImporter.cpp

@@ -35,7 +35,7 @@ namespace CamelotEngine
 		return true; // FBX files can be plain-text so I don't even check for magic number
 		return true; // FBX files can be plain-text so I don't even check for magic number
 	}
 	}
 
 
-	ResourcePtr FBXImporter::import(const String& filePath)
+	BaseResourceHandle FBXImporter::import(const String& filePath)
 	{
 	{
 		FbxManager* fbxManager = nullptr;
 		FbxManager* fbxManager = nullptr;
 		FbxScene* fbxScene = nullptr;
 		FbxScene* fbxScene = nullptr;
@@ -47,9 +47,9 @@ namespace CamelotEngine
 
 
 		shutDownSdk(fbxManager);
 		shutDownSdk(fbxManager);
 
 
-		MeshPtr mesh = Mesh::create();
+		MeshHandle mesh = Mesh::create();
 
 
-		mesh->waitUntilInitialized();
+		mesh.waitUntilLoaded();
 		mesh->setMeshData(meshData);
 		mesh->setMeshData(meshData);
 
 
 		return mesh;
 		return mesh;

+ 1 - 1
CamelotFreeImgImporter/Include/CmFreeImgImporter.h

@@ -34,7 +34,7 @@ namespace CamelotEngine
 		virtual bool isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const; 
 		virtual bool isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const; 
 
 
 		/** Inherited from SpecificImporter */
 		/** Inherited from SpecificImporter */
-		virtual ResourcePtr import(const String& filePath);
+		virtual BaseResourceHandle import(const String& filePath);
 	private:
 	private:
 		vector<String>::type mExtensions;
 		vector<String>::type mExtensions;
 		std::unordered_map<String, int> mExtensionToFID;
 		std::unordered_map<String, int> mExtensionToFID;

+ 4 - 4
CamelotFreeImgImporter/Source/CmFreeImgImporter.cpp

@@ -127,18 +127,18 @@ namespace CamelotEngine
 		}
 		}
 	}
 	}
 
 
-	ResourcePtr FreeImgImporter::import(const String& filePath)
+	BaseResourceHandle FreeImgImporter::import(const String& filePath)
 	{
 	{
 		DataStreamPtr fileData = FileSystem::open(filePath, true);
 		DataStreamPtr fileData = FileSystem::open(filePath, true);
 
 
 		TextureDataPtr imgData = importRawImage(fileData);
 		TextureDataPtr imgData = importRawImage(fileData);
 		if(imgData == nullptr || imgData->getData() == nullptr)
 		if(imgData == nullptr || imgData->getData() == nullptr)
-			return nullptr;
+			return TextureHandle();
 
 
-		TexturePtr newTexture = Texture::create(TEX_TYPE_2D, 
+		TextureHandle newTexture = Texture::create(TEX_TYPE_2D, 
 			imgData->getWidth(), imgData->getHeight(), imgData->getNumMipmaps(), imgData->getFormat());
 			imgData->getWidth(), imgData->getHeight(), imgData->getNumMipmaps(), imgData->getFormat());
 
 
-		newTexture->waitUntilInitialized();
+		newTexture.waitUntilLoaded();
 
 
 		for(UINT32 mip = 0; mip <= imgData->getNumMipmaps(); ++mip)
 		for(UINT32 mip = 0; mip <= imgData->getNumMipmaps(); ++mip)
 		{
 		{

+ 2 - 0
CamelotRenderer/CamelotRenderer.vcxproj

@@ -208,6 +208,7 @@
     <ClInclude Include="Include\CmHardwareBuffer.h" />
     <ClInclude Include="Include\CmHardwareBuffer.h" />
     <ClInclude Include="Include\CmHardwareBufferManager.h" />
     <ClInclude Include="Include\CmHardwareBufferManager.h" />
     <ClInclude Include="Include\CmIndexBuffer.h" />
     <ClInclude Include="Include\CmIndexBuffer.h" />
+    <ClInclude Include="Include\CmMaterialManager.h" />
     <ClInclude Include="Include\CmMeshManager.h" />
     <ClInclude Include="Include\CmMeshManager.h" />
     <ClInclude Include="Include\CmOcclusionQuery.h" />
     <ClInclude Include="Include\CmOcclusionQuery.h" />
     <ClInclude Include="Include\CmPixelBuffer.h" />
     <ClInclude Include="Include\CmPixelBuffer.h" />
@@ -277,6 +278,7 @@
     <ClInclude Include="Source\CmMeshRTTI.h" />
     <ClInclude Include="Source\CmMeshRTTI.h" />
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
+    <ClCompile Include="Include\CmMaterialManager.cpp" />
     <ClCompile Include="Source\CamelotRenderer.cpp" />
     <ClCompile Include="Source\CamelotRenderer.cpp" />
     <ClCompile Include="Source\CmApplication.cpp" />
     <ClCompile Include="Source\CmApplication.cpp" />
     <ClCompile Include="Source\CmBlendState.cpp" />
     <ClCompile Include="Source\CmBlendState.cpp" />

+ 6 - 0
CamelotRenderer/CamelotRenderer.vcxproj.filters

@@ -374,6 +374,9 @@
     <ClInclude Include="Include\CmMeshManager.h">
     <ClInclude Include="Include\CmMeshManager.h">
       <Filter>Header Files\RenderSystem</Filter>
       <Filter>Header Files\RenderSystem</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="Include\CmMaterialManager.h">
+      <Filter>Header Files\Material</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CamelotRenderer.cpp">
     <ClCompile Include="Source\CamelotRenderer.cpp">
@@ -571,5 +574,8 @@
     <ClCompile Include="Source\CmMeshManager.cpp">
     <ClCompile Include="Source\CmMeshManager.cpp">
       <Filter>Source Files\RenderSystem</Filter>
       <Filter>Source Files\RenderSystem</Filter>
     </ClCompile>
     </ClCompile>
+    <ClCompile Include="Include\CmMaterialManager.cpp">
+      <Filter>Source Files\Material</Filter>
+    </ClCompile>
   </ItemGroup>
   </ItemGroup>
 </Project>
 </Project>

+ 1 - 1
CamelotRenderer/Include/CmBlendState.h

@@ -60,7 +60,7 @@ namespace CamelotEngine
 		SceneBlendOperation getAlphaBlendOperation(UINT32 renderTargetIdx) const;
 		SceneBlendOperation getAlphaBlendOperation(UINT32 renderTargetIdx) const;
 		UINT8 getRenderTargetWriteMask(UINT32 renderTargetIdx) const;
 		UINT8 getRenderTargetWriteMask(UINT32 renderTargetIdx) const;
 
 
-		static BlendStatePtr create(const BLEND_STATE_DESC& desc);
+		static BlendStateHandle create(const BLEND_STATE_DESC& desc);
 
 
 		/**
 		/**
 		 * @brief	Returns the default blend state;
 		 * @brief	Returns the default blend state;

+ 1 - 1
CamelotRenderer/Include/CmDepthStencilState.h

@@ -68,7 +68,7 @@ namespace CamelotEngine
 		StencilOperation getStencilBackPassOp() const { return mData.backStencilPassOp; }
 		StencilOperation getStencilBackPassOp() const { return mData.backStencilPassOp; }
 		CompareFunction getStencilBackCompFunc() const { return mData.backStencilComparisonFunc; }
 		CompareFunction getStencilBackCompFunc() const { return mData.backStencilComparisonFunc; }
 
 
-		static DepthStencilStatePtr create(const DEPTH_STENCIL_STATE_DESC& desc);
+		static DepthStencilStateHandle create(const DEPTH_STENCIL_STATE_DESC& desc);
 
 
 		/**
 		/**
 		 * @brief	Returns the default depth stencil state;
 		 * @brief	Returns the default depth stencil state;

+ 1 - 1
CamelotRenderer/Include/CmHighLevelGpuProgram.h

@@ -92,7 +92,7 @@ namespace CamelotEngine {
 		/* 								STATICS		                     		*/
 		/* 								STATICS		                     		*/
 		/************************************************************************/
 		/************************************************************************/
 	public:
 	public:
-		static HighLevelGpuProgramPtr create(const String& source, const String& entryPoint, 
+		static HighLevelGpuProgramHandle create(const String& source, const String& entryPoint, 
 			const String& language, GpuProgramType gptype, GpuProgramProfile profile);
 			const String& language, GpuProgramType gptype, GpuProgramProfile profile);
     };
     };
 
 

+ 1 - 2
CamelotRenderer/Include/CmImporter.h

@@ -23,8 +23,7 @@ namespace CamelotEngine
 		 *
 		 *
 		 * @param	inputFilePath 	Pathname of the input file.
 		 * @param	inputFilePath 	Pathname of the input file.
 		 */
 		 */
-		ResourcePtr import(const String& inputFilePath);
-
+		BaseResourceHandle import(const String& inputFilePath);
 
 
 		/**
 		/**
 		 * @brief	Checks if we can import a file with the specified extension.
 		 * @brief	Checks if we can import a file with the specified extension.

+ 8 - 1
CamelotRenderer/Include/CmMaterial.h

@@ -2,6 +2,11 @@
 
 
 #include "CmPrerequisites.h"
 #include "CmPrerequisites.h"
 #include "CmResource.h"
 #include "CmResource.h"
+#include "CmVector2.h"
+#include "CmVector3.h"
+#include "CmVector4.h"
+#include "CmMatrix3.h"
+#include "CmMatrix4.h"
 #include "CmCommonEnums.h"
 #include "CmCommonEnums.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
@@ -63,8 +68,10 @@ namespace CamelotEngine
 
 
 		PassParametersPtr getPassParameters(UINT32 passIdx) const;
 		PassParametersPtr getPassParameters(UINT32 passIdx) const;
 
 
-		static MaterialPtr create();
+		static MaterialHandle create();
 	private:
 	private:
+		friend class MaterialManager;
+
 		ShaderPtr mShader;
 		ShaderPtr mShader;
 		TechniquePtr mBestTechnique;
 		TechniquePtr mBestTechnique;
 
 

+ 14 - 0
CamelotRenderer/Include/CmMaterialManager.cpp

@@ -0,0 +1,14 @@
+#include "CmMaterialManager.h"
+#include "CmMaterial.h"
+
+namespace CamelotEngine
+{
+	MaterialPtr MaterialManager::create() const
+	{
+		MaterialPtr newMat(new Material(), &CoreGpuObject::_deleteDelayed);
+		newMat->setThisPtr(newMat);
+		newMat->initialize();
+
+		return newMat;
+	}
+}

+ 13 - 0
CamelotRenderer/Include/CmMaterialManager.h

@@ -0,0 +1,13 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmModule.h"
+
+namespace CamelotEngine
+{
+	class CM_EXPORT MaterialManager : public Module<MaterialManager>
+	{
+	public:
+		MaterialPtr create() const;
+	};
+}

+ 1 - 4
CamelotRenderer/Include/CmMaterialRTTI.h

@@ -492,9 +492,6 @@ namespace CamelotEngine
 			return TID_Material;
 			return TID_Material;
 		}
 		}
 
 
-		virtual std::shared_ptr<IReflectable> newRTTIObject()
-		{
-			return Material::create();
-		}
+		virtual std::shared_ptr<IReflectable> newRTTIObject();
 	};
 	};
 }
 }

+ 1 - 1
CamelotRenderer/Include/CmMesh.h

@@ -77,6 +77,6 @@ namespace CamelotEngine
 		/************************************************************************/
 		/************************************************************************/
 		
 		
 	public:
 	public:
-		static MeshPtr create();
+		static MeshHandle create();
 	};
 	};
 }
 }

+ 1 - 1
CamelotRenderer/Include/CmRasterizerState.h

@@ -51,7 +51,7 @@ namespace CamelotEngine
 		bool getMultisampleEnable() const { return mData.multisampleEnable; }
 		bool getMultisampleEnable() const { return mData.multisampleEnable; }
 		bool getAntialiasedLineEnable() const { return mData.antialiasedLineEnable; }
 		bool getAntialiasedLineEnable() const { return mData.antialiasedLineEnable; }
 
 
-		static RasterizerStatePtr create(const RASTERIZER_STATE_DESC& desc);
+		static RasterizerStateHandle create(const RASTERIZER_STATE_DESC& desc);
 
 
 		/**
 		/**
 		 * @brief	Returns the default rasterizer state;
 		 * @brief	Returns the default rasterizer state;

+ 5 - 0
CamelotRenderer/Include/CmResource.h

@@ -17,6 +17,11 @@ namespace CamelotEngine
 
 
 		const String& getUUID() const { return mUUID; }
 		const String& getUUID() const { return mUUID; }
 
 
+		/**
+		 * @brief	Creates a new resource handle. Should only be called by internal methods.
+		 */
+		static BaseResourceHandle _createResourceHandle(ResourcePtr obj);
+
 	protected:
 	protected:
 		friend class Resources;
 		friend class Resources;
 
 

+ 20 - 10
CamelotRenderer/Include/CmResourceHandle.h

@@ -131,6 +131,25 @@ namespace CamelotEngine
 			return std::static_pointer_cast<T>(mData->mPtr); 
 			return std::static_pointer_cast<T>(mData->mPtr); 
 		}
 		}
 
 
+		/**
+		 * @brief	Releases the reference held by this handle.
+		 */
+		void reset()
+		{
+			mData = std::shared_ptr<ResourceHandleData>(new ResourceHandleData());
+		}
+
+		/**
+		 * @brief	Clears the data this handle (and all copies of it) points to
+		 * 			
+		 * @note	Should only be called by internal methods
+		 */
+		void _invalidate()
+		{
+			mData->mPtr = nullptr;
+			mData->mIsCreated = false;
+		}
+
 		template<class _Ty>
 		template<class _Ty>
 		struct CM_Bool_struct
 		struct CM_Bool_struct
 		{
 		{
@@ -145,7 +164,7 @@ namespace CamelotEngine
 		}
 		}
 
 
 	private:
 	private:
-		friend class Resources;
+		friend class Resource;
 
 
 		explicit ResourceHandle(T* ptr)
 		explicit ResourceHandle(T* ptr)
 			:ResourceHandleBase()
 			:ResourceHandleBase()
@@ -158,15 +177,6 @@ namespace CamelotEngine
 		{
 		{
 			init(ptr);
 			init(ptr);
 		}
 		}
-
-		/**
-		 * @brief	Releases the reference held by this handle.
-		 */
-		void reset()
-		{
-			mData->mPtr = nullptr;
-			mData->mIsCreated = false;
-		}
 	};
 	};
 
 
 	template<class _Ty1, class _Ty2>
 	template<class _Ty1, class _Ty2>

+ 2 - 4
CamelotRenderer/Include/CmResources.h

@@ -125,14 +125,12 @@ namespace CamelotEngine
 		 * @brief	Creates a new resource at the specified location. Throws an exception if resource
 		 * @brief	Creates a new resource at the specified location. Throws an exception if resource
 		 * 			already exists. Automatically calls Resources::save.
 		 * 			already exists. Automatically calls Resources::save.
 		 *
 		 *
-		 * @param	resource 	Pointer to the resource.
+		 * @param	resource 	Handle to the resource.
 		 * @param	filePath 	Full pathname of the file.
 		 * @param	filePath 	Full pathname of the file.
 		 * @param	overwrite	(optional) If true, any existing resource at the specified location will
 		 * @param	overwrite	(optional) If true, any existing resource at the specified location will
 		 * 						be overwritten.
 		 * 						be overwritten.
-		 *
-		 * @return	Handle to the resource. 
 		 */
 		 */
-		BaseResourceHandle create(ResourcePtr resource, const String& filePath, bool overwrite = false);
+		void create(BaseResourceHandle resource, const String& filePath, bool overwrite = false);
 
 
 	public:
 	public:
 		struct ResourceMetaData : public IReflectable
 		struct ResourceMetaData : public IReflectable

+ 1 - 1
CamelotRenderer/Include/CmSamplerState.h

@@ -92,7 +92,7 @@ namespace CamelotEngine
 		 */
 		 */
 		const Color& getBorderColor() const;
 		const Color& getBorderColor() const;
 
 
-		static SamplerStatePtr create(const SAMPLER_STATE_DESC& desc);
+		static SamplerStateHandle create(const SAMPLER_STATE_DESC& desc);
 
 
 		/**
 		/**
 		 * @brief	Returns the default sampler state;
 		 * @brief	Returns the default sampler state;

+ 1 - 1
CamelotRenderer/Include/CmSpecificImporter.h

@@ -28,6 +28,6 @@ namespace CamelotEngine
 		 *
 		 *
 		 * @return	null if it fails, otherwise the loaded object.
 		 * @return	null if it fails, otherwise the loaded object.
 		 */
 		 */
-		virtual ResourcePtr import(const String& filePath) = 0;
+		virtual BaseResourceHandle import(const String& filePath) = 0;
 	};
 	};
 }
 }

+ 2 - 2
CamelotRenderer/Include/CmTexture.h

@@ -275,11 +275,11 @@ namespace CamelotEngine {
 		/* 								STATICS		                     		*/
 		/* 								STATICS		                     		*/
 		/************************************************************************/
 		/************************************************************************/
 	public:
 	public:
-		static TexturePtr create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, 
+		static TextureHandle create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, 
 			int num_mips, PixelFormat format, int usage = TU_DEFAULT,
 			int num_mips, PixelFormat format, int usage = TU_DEFAULT,
 			bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
 			bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
 
 
-		static TexturePtr create(TextureType texType, UINT32 width, UINT32 height, int num_mips,
+		static TextureHandle create(TextureType texType, UINT32 width, UINT32 height, int num_mips,
 			PixelFormat format, int usage = TU_DEFAULT,
 			PixelFormat format, int usage = TU_DEFAULT,
 			bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
 			bool hwGammaCorrection = false, UINT32 fsaa = 0, const String& fsaaHint = StringUtil::BLANK);
     };
     };

+ 3 - 0
CamelotRenderer/Source/CmApplication.cpp

@@ -23,6 +23,7 @@
 #include "CmInput.h"
 #include "CmInput.h"
 #include "CmRendererManager.h"
 #include "CmRendererManager.h"
 #include "CmMeshManager.h"
 #include "CmMeshManager.h"
+#include "CmMaterialManager.h"
 #include "CmRenderer.h"
 #include "CmRenderer.h"
 #include "CmDeferredRenderContext.h"
 #include "CmDeferredRenderContext.h"
 
 
@@ -75,6 +76,7 @@ namespace CamelotEngine
 		SceneManager::startUp(new SceneManager());
 		SceneManager::startUp(new SceneManager());
 
 
 		MeshManager::startUp(new MeshManager());
 		MeshManager::startUp(new MeshManager());
+		MaterialManager::startUp(new MaterialManager());
 		Importer::startUp(new Importer());
 		Importer::startUp(new Importer());
 		loadPlugin("CamelotFreeImgImporter"); // TODO - Load this automatically somehow
 		loadPlugin("CamelotFreeImgImporter"); // TODO - Load this automatically somehow
 		loadPlugin("CamelotFBXImporter"); // TODO - Load this automatically somehow
 		loadPlugin("CamelotFBXImporter"); // TODO - Load this automatically somehow
@@ -150,6 +152,7 @@ namespace CamelotEngine
 		mPrimaryRenderWindow = nullptr;
 		mPrimaryRenderWindow = nullptr;
 
 
 		Importer::shutDown();
 		Importer::shutDown();
+		MaterialManager::shutDown();
 		MeshManager::shutDown();
 		MeshManager::shutDown();
 
 
 		SceneManager::shutDown();
 		SceneManager::shutDown();

+ 4 - 2
CamelotRenderer/Source/CmBlendState.cpp

@@ -73,9 +73,11 @@ namespace CamelotEngine
 		return mData.renderTargetDesc[renderTargetIdx].renderTargetWriteMask;
 		return mData.renderTargetDesc[renderTargetIdx].renderTargetWriteMask;
 	}
 	}
 
 
-	BlendStatePtr BlendState::create(const BLEND_STATE_DESC& desc)
+	BlendStateHandle BlendState::create(const BLEND_STATE_DESC& desc)
 	{
 	{
-		return RenderStateManager::instance().createBlendState(desc);
+		BlendStatePtr blendStatePtr = RenderStateManager::instance().createBlendState(desc);
+
+		return static_resource_cast<BlendState>(Resource::_createResourceHandle(blendStatePtr));
 	}
 	}
 
 
 	/************************************************************************/
 	/************************************************************************/

+ 4 - 2
CamelotRenderer/Source/CmDepthStencilState.cpp

@@ -18,9 +18,11 @@ namespace CamelotEngine
 		return RenderStateManager::instance().getDefaultDepthStencilState();
 		return RenderStateManager::instance().getDefaultDepthStencilState();
 	}
 	}
 
 
-	DepthStencilStatePtr DepthStencilState::create(const DEPTH_STENCIL_STATE_DESC& desc)
+	DepthStencilStateHandle DepthStencilState::create(const DEPTH_STENCIL_STATE_DESC& desc)
 	{
 	{
-		return RenderStateManager::instance().createDepthStencilState(desc);
+		DepthStencilStatePtr depthStencilPtr = RenderStateManager::instance().createDepthStencilState(desc);
+
+		return static_resource_cast<DepthStencilState>(Resource::_createResourceHandle(depthStencilPtr));
 	}
 	}
 
 
 	/************************************************************************/
 	/************************************************************************/

+ 4 - 2
CamelotRenderer/Source/CmHighLevelGpuProgram.cpp

@@ -74,10 +74,12 @@ namespace CamelotEngine
 		GpuProgram::destroy_internal();
 		GpuProgram::destroy_internal();
     }
     }
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
-	HighLevelGpuProgramPtr HighLevelGpuProgram::create(const String& source, const String& entryPoint, 
+	HighLevelGpuProgramHandle HighLevelGpuProgram::create(const String& source, const String& entryPoint, 
 		const String& language, GpuProgramType gptype, GpuProgramProfile profile)
 		const String& language, GpuProgramType gptype, GpuProgramProfile profile)
 	{
 	{
-		return HighLevelGpuProgramManager::instance().create(source, entryPoint, language, gptype, profile);
+		HighLevelGpuProgramPtr programPtr = HighLevelGpuProgramManager::instance().create(source, entryPoint, language, gptype, profile);
+
+		return static_resource_cast<HighLevelGpuProgram>(Resource::_createResourceHandle(programPtr));
 	}
 	}
 }
 }
 
 

+ 4 - 4
CamelotRenderer/Source/CmImporter.cpp

@@ -47,12 +47,12 @@ namespace CamelotEngine
 		return false;
 		return false;
 	}
 	}
 
 
-	ResourcePtr Importer::import(const String& inputFilePath)
+	BaseResourceHandle Importer::import(const String& inputFilePath)
 	{
 	{
 		if(!FileSystem::fileExists(inputFilePath))
 		if(!FileSystem::fileExists(inputFilePath))
 		{
 		{
 			LOGWRN("Trying to import asset that doesn't exists. Asset path: " + inputFilePath);
 			LOGWRN("Trying to import asset that doesn't exists. Asset path: " + inputFilePath);
-			return nullptr;
+			return BaseResourceHandle();
 		}
 		}
 
 
 		String ext = Path::getExtension(inputFilePath);
 		String ext = Path::getExtension(inputFilePath);
@@ -60,7 +60,7 @@ namespace CamelotEngine
 		if(!supportsFileType(ext))
 		if(!supportsFileType(ext))
 		{
 		{
 			LOGWRN("There is no importer for the provided file type. (" + inputFilePath + ")");
 			LOGWRN("There is no importer for the provided file type. (" + inputFilePath + ")");
-			return nullptr;
+			return BaseResourceHandle();
 		}
 		}
 
 
 		SpecificImporter* importer = nullptr;
 		SpecificImporter* importer = nullptr;
@@ -72,7 +72,7 @@ namespace CamelotEngine
 			}
 			}
 		}
 		}
 
 
-		ResourcePtr importedResource = importer->import(inputFilePath);
+		BaseResourceHandle importedResource = importer->import(inputFilePath);
 
 
 		return importedResource;
 		return importedResource;
 	}
 	}

+ 4 - 5
CamelotRenderer/Source/CmMaterial.cpp

@@ -9,6 +9,7 @@
 #include "CmGpuProgram.h"
 #include "CmGpuProgram.h"
 #include "CmGpuParamDesc.h"
 #include "CmGpuParamDesc.h"
 #include "CmMaterialRTTI.h"
 #include "CmMaterialRTTI.h"
+#include "CmMaterialManager.h"
 #include "CmDebug.h"
 #include "CmDebug.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
@@ -817,13 +818,11 @@ namespace CamelotEngine
 		return iterFind->second.at(arrayIdx);
 		return iterFind->second.at(arrayIdx);
 	}
 	}
 
 
-	MaterialPtr Material::create()
+	MaterialHandle Material::create()
 	{
 	{
-		MaterialPtr newMat(new Material(), &CoreGpuObject::_deleteDelayed);
-		newMat->setThisPtr(newMat);
-		newMat->initialize();
+		MaterialPtr materialPtr = MaterialManager::instance().create();
 
 
-		return newMat;
+		return static_resource_cast<Material>(Resource::_createResourceHandle(materialPtr));
 	}
 	}
 
 
 	RTTITypeBase* Material::getRTTIStatic()
 	RTTITypeBase* Material::getRTTIStatic()

+ 6 - 0
CamelotRenderer/Source/CmMaterialRTTI.cpp

@@ -1,4 +1,5 @@
 #include "CmMaterialRTTI.h"
 #include "CmMaterialRTTI.h"
+#include "CmMaterialManager.h"
 #include "CmGpuParamDesc.h"
 #include "CmGpuParamDesc.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
@@ -298,4 +299,9 @@ namespace CamelotEngine
 
 
 		material->mRTTIData = nullptr; // This will delete temporary data as it's stored in a unique ptr
 		material->mRTTIData = nullptr; // This will delete temporary data as it's stored in a unique ptr
 	}
 	}
+
+	std::shared_ptr<IReflectable> MaterialRTTI::newRTTIObject()
+	{
+		return MaterialManager::instance().create();
+	}
 }
 }

+ 4 - 2
CamelotRenderer/Source/CmMesh.cpp

@@ -351,9 +351,11 @@ namespace CamelotEngine
 	/* 								STATICS		                     		*/
 	/* 								STATICS		                     		*/
 	/************************************************************************/
 	/************************************************************************/
 
 
-	MeshPtr Mesh::create()
+	MeshHandle Mesh::create()
 	{
 	{
-		return MeshManager::instance().create();
+		MeshPtr meshPtr = MeshManager::instance().create();
+
+		return static_resource_cast<Mesh>(Resource::_createResourceHandle(meshPtr));
 	}
 	}
 }
 }
 
 

+ 4 - 2
CamelotRenderer/Source/CmRasterizerState.cpp

@@ -17,9 +17,11 @@ namespace CamelotEngine
 		return RenderStateManager::instance().getDefaultRasterizerState();
 		return RenderStateManager::instance().getDefaultRasterizerState();
 	}
 	}
 
 
-	RasterizerStatePtr RasterizerState::create(const RASTERIZER_STATE_DESC& desc)
+	RasterizerStateHandle RasterizerState::create(const RASTERIZER_STATE_DESC& desc)
 	{
 	{
-		return RenderStateManager::instance().createRasterizerState(desc);
+		RasterizerStatePtr rasterizerPtr = RenderStateManager::instance().createRasterizerState(desc);
+
+		return static_resource_cast<RasterizerState>(Resource::_createResourceHandle(rasterizerPtr));
 	}
 	}
 
 
 	/************************************************************************/
 	/************************************************************************/

+ 5 - 0
CamelotRenderer/Source/CmResource.cpp

@@ -13,6 +13,11 @@ namespace CamelotEngine
 		mUUID = UUIDGenerator::generateRandom();
 		mUUID = UUIDGenerator::generateRandom();
 	}
 	}
 
 
+	BaseResourceHandle Resource::_createResourceHandle(ResourcePtr obj)
+	{
+		return BaseResourceHandle(obj);
+	}
+
 	RTTITypeBase* Resource::getRTTIStatic()
 	RTTITypeBase* Resource::getRTTIStatic()
 	{
 	{
 		return ResourceRTTI::instance();
 		return ResourceRTTI::instance();

+ 8 - 9
CamelotRenderer/Source/CmResources.cpp

@@ -127,7 +127,7 @@ namespace CamelotEngine
 		if(!metaExists_UUID(uuid))
 		if(!metaExists_UUID(uuid))
 		{
 		{
 			gDebug().logWarning("Cannot load resource. Resource with UUID '" + uuid + "' doesn't exist.");
 			gDebug().logWarning("Cannot load resource. Resource with UUID '" + uuid + "' doesn't exist.");
-			return nullptr;
+			return BaseResourceHandle();
 		}
 		}
 
 
 		ResourceMetaDataPtr metaEntry = mResourceMetaData[uuid];
 		ResourceMetaDataPtr metaEntry = mResourceMetaData[uuid];
@@ -140,7 +140,7 @@ namespace CamelotEngine
 		if(!metaExists_UUID(uuid))
 		if(!metaExists_UUID(uuid))
 		{
 		{
 			gDebug().logWarning("Cannot load resource. Resource with UUID '" + uuid + "' doesn't exist.");
 			gDebug().logWarning("Cannot load resource. Resource with UUID '" + uuid + "' doesn't exist.");
-			return nullptr;
+			return BaseResourceHandle();
 		}
 		}
 
 
 		ResourceMetaDataPtr metaEntry = mResourceMetaData[uuid];
 		ResourceMetaDataPtr metaEntry = mResourceMetaData[uuid];
@@ -186,7 +186,7 @@ namespace CamelotEngine
 		if(!FileSystem::fileExists(filePath))
 		if(!FileSystem::fileExists(filePath))
 		{
 		{
 			gDebug().logWarning("Specified file: " + filePath + " doesn't exist.");
 			gDebug().logWarning("Specified file: " + filePath + " doesn't exist.");
-			return nullptr;
+			return BaseResourceHandle();
 		}
 		}
 
 
 		BaseResourceHandle newResource;
 		BaseResourceHandle newResource;
@@ -228,7 +228,7 @@ namespace CamelotEngine
 			resource.waitUntilLoaded(); // TODO - What if resource isn't being loaded at all, or has already been unloaded?
 			resource.waitUntilLoaded(); // TODO - What if resource isn't being loaded at all, or has already been unloaded?
 
 
 		resource->destroy();
 		resource->destroy();
-		resource.reset();
+		resource._invalidate();
 
 
 		mLoadedResources.erase(resource.getUUID());
 		mLoadedResources.erase(resource.getUUID());
 	}
 	}
@@ -249,12 +249,12 @@ namespace CamelotEngine
 		}
 		}
 	}
 	}
 
 
-	BaseResourceHandle Resources::create(ResourcePtr resource, const String& filePath, bool overwrite)
+	void Resources::create(BaseResourceHandle resource, const String& filePath, bool overwrite)
 	{
 	{
 		if(resource == nullptr)
 		if(resource == nullptr)
 			CM_EXCEPT(InvalidParametersException, "Trying to save an uninitialized resource.");
 			CM_EXCEPT(InvalidParametersException, "Trying to save an uninitialized resource.");
 
 
-		resource->waitUntilInitialized();
+		resource.waitUntilLoaded();
 
 
 		if(metaExists_UUID(resource->getUUID()))
 		if(metaExists_UUID(resource->getUUID()))
 			CM_EXCEPT(InvalidParametersException, "Specified resource already exists.");
 			CM_EXCEPT(InvalidParametersException, "Specified resource already exists.");
@@ -276,10 +276,9 @@ namespace CamelotEngine
 
 
 		addMetaData(resource->getUUID(), filePath);
 		addMetaData(resource->getUUID(), filePath);
 
 
-		BaseResourceHandle handle = resource;
-		save(handle);
+		save(resource);
 
 
-		return handle;
+		mLoadedResources[resource->getUUID()] = resource;
 	}
 	}
 
 
 	void Resources::save(BaseResourceHandle resource)
 	void Resources::save(BaseResourceHandle resource)

+ 4 - 2
CamelotRenderer/Source/CmSamplerState.cpp

@@ -38,9 +38,11 @@ namespace CamelotEngine
 		return mData.borderColor;
 		return mData.borderColor;
 	}
 	}
 
 
-	SamplerStatePtr SamplerState::create(const SAMPLER_STATE_DESC& desc)
+	SamplerStateHandle SamplerState::create(const SAMPLER_STATE_DESC& desc)
 	{
 	{
-		return RenderStateManager::instance().createSamplerState(desc);
+		SamplerStatePtr samplerPtr = RenderStateManager::instance().createSamplerState(desc);
+
+		return static_resource_cast<SamplerState>(Resource::_createResourceHandle(samplerPtr));
 	}
 	}
 
 
 	/************************************************************************/
 	/************************************************************************/

+ 8 - 4
CamelotRenderer/Source/CmTexture.cpp

@@ -305,18 +305,22 @@ namespace CamelotEngine {
 	/************************************************************************/
 	/************************************************************************/
 	/* 								STATICS	                      			*/
 	/* 								STATICS	                      			*/
 	/************************************************************************/
 	/************************************************************************/
-	TexturePtr Texture::create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, 
+	TextureHandle Texture::create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth, 
 		int num_mips, PixelFormat format, int usage, bool hwGammaCorrection, UINT32 fsaa, const String& fsaaHint)
 		int num_mips, PixelFormat format, int usage, bool hwGammaCorrection, UINT32 fsaa, const String& fsaaHint)
 	{
 	{
-		return TextureManager::instance().createTexture(texType, 
+		TexturePtr texturePtr = TextureManager::instance().createTexture(texType, 
 			width, height, depth, num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
 			width, height, depth, num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
+
+		return static_resource_cast<Texture>(Resource::_createResourceHandle(texturePtr));
 	}
 	}
 	
 	
-	TexturePtr Texture::create(TextureType texType, UINT32 width, UINT32 height, 
+	TextureHandle Texture::create(TextureType texType, UINT32 width, UINT32 height, 
 		int num_mips, PixelFormat format, int usage, bool hwGammaCorrection, UINT32 fsaa, const String& fsaaHint)
 		int num_mips, PixelFormat format, int usage, bool hwGammaCorrection, UINT32 fsaa, const String& fsaaHint)
 	{
 	{
-		return TextureManager::instance().createTexture(texType, 
+		TexturePtr texturePtr = TextureManager::instance().createTexture(texType, 
 			width, height, num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
 			width, height, num_mips, format, usage, hwGammaCorrection, fsaa, fsaaHint);
+
+		return static_resource_cast<Texture>(Resource::_createResourceHandle(texturePtr));
 	}
 	}
 }
 }
 
 

+ 2 - 5
CamelotRenderer/TODO.txt

@@ -20,16 +20,13 @@ Pass
 GpuParamBlock - Needs to derive from CoreGpuObject and needs to be initialized better
 GpuParamBlock - Needs to derive from CoreGpuObject and needs to be initialized better
  - HardwareBufferManager::createGpuParamBlock needs &CoreGpuObject::_deleteDelayed added as a deleted to shared_ptr
  - HardwareBufferManager::createGpuParamBlock needs &CoreGpuObject::_deleteDelayed added as a deleted to shared_ptr
 
 
-Having ResourceHandle closely tied in with Resources creates a problem when user just wants to create a resource in memory and use it? How to do it without saving it? e.g. material setTexture
- - create() methods return a ResourceHandle.
- - However those won't be released using unload() which is confusing.
-   - creating a resource should add it to mLoaded
+Seems there is a possible deadlock when starting the render thread, while waiting for the thread to be started
 
 
 RenderTextures and MultiRenderTextures will only work properly if used directly from render thread, as setting each surface calls render methods, so its impossible to set one outside of render thread
 RenderTextures and MultiRenderTextures will only work properly if used directly from render thread, as setting each surface calls render methods, so its impossible to set one outside of render thread
  - also they don't have initialize_internal
  - also they don't have initialize_internal
  - I should probably make these immutable. Once they are set they can't be changed, so everything can be initialized when calling initialize()
  - I should probably make these immutable. Once they are set they can't be changed, so everything can be initialized when calling initialize()
 
 
- - Support loading of compound objects:
+Support loading of compound objects:
    - Loading Material also loads attached Shader and Textures/Samplers
    - Loading Material also loads attached Shader and Textures/Samplers
 
 
 Add support for include file resource
 Add support for include file resource