Browse Source

Re-enabled D3D9ResourceManager (still crashes on quit, but will fix with new way of resource management)

Marko Pintera 13 năm trước cách đây
mục cha
commit
5c64304d91

+ 48 - 48
CamelotClient/CamelotClient.cpp

@@ -32,8 +32,8 @@ int CALLBACK WinMain(
 	_In_  int nCmdShow
 	)
 {
-	gApplication().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer");
-	//gApplication().startUp("CamelotD3D9RenderSystem", "CamelotForwardRenderer");
+	//gApplication().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer");
+	gApplication().startUp("CamelotD3D9RenderSystem", "CamelotForwardRenderer");
 	//gApplication().startUp("CamelotD3D11RenderSystem", "CamelotForwardRenderer");
 
 	RenderSystem* renderSystem = RenderSystem::instancePtr();
@@ -57,27 +57,27 @@ int CALLBACK WinMain(
 	HighLevelGpuProgramPtr vertProg;
 
 	/////////////////// 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 //////////////////////////
 	//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);
 
 	///////////////// 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);
 

+ 0 - 2
CamelotD3D9Renderer/Source/CmD3D9GpuProgram.cpp

@@ -292,8 +292,6 @@ namespace CamelotEngine {
 		}
 		mMapDeviceToPixelShader.clear();	
 
-		D3D9RenderSystem::getResourceManager()->_notifyResourceDestroyed(static_cast<D3D9Resource*>(this));
-
 		D3D9GpuProgram::destroy_internal();
     }
 	//-----------------------------------------------------------------------------

+ 0 - 2
CamelotD3D9Renderer/Source/CmD3D9IndexBuffer.cpp

@@ -341,8 +341,6 @@ namespace CamelotEngine {
 		mMapDeviceToBufferResources.clear();   
 		SAFE_DELETE_ARRAY(mSystemMemoryBuffer);
 
-		D3D9RenderSystem::getResourceManager()->_notifyResourceDestroyed(static_cast<D3D9Resource*>(this));
-
 		IndexBuffer::destroy_internal();
 	}
 }

+ 1 - 1
CamelotD3D9Renderer/Source/CmD3D9Resource.cpp

@@ -40,7 +40,7 @@ namespace CamelotEngine
 
 	D3D9Resource::~D3D9Resource()
 	{		
-		
+		D3D9RenderSystem::getResourceManager()->_notifyResourceDestroyed(static_cast<D3D9Resource*>(this));	
 	}
 	
 	void D3D9Resource::lockDeviceAccess()

+ 20 - 20
CamelotD3D9Renderer/Source/CmD3D9ResourceManager.cpp

@@ -60,53 +60,53 @@ namespace CamelotEngine
 	 //-----------------------------------------------------------------------
 	void D3D9ResourceManager::notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device)
 	{				
-/*		CM_LOCK_MUTEX(mResourcesMutex)
+		CM_LOCK_MUTEX(mResourcesMutex)
 
 		ResourceContainerIterator it = mResources.begin();
 		while (it != mResources.end())
 		{
 			(*it)->notifyOnDeviceCreate(d3d9Device);
 			++it;
-		}		*/		
+		}				
 	}
 
 	 //-----------------------------------------------------------------------
 	void D3D9ResourceManager::notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device)
 	{
-		//CM_LOCK_MUTEX(mResourcesMutex)
-
-		//ResourceContainerIterator it = mResources.begin();
-		//while (it != mResources.end())
-		//{
-		//	(*it)->notifyOnDeviceDestroy(d3d9Device);
-		//	++it;
-		//}	
+		CM_LOCK_MUTEX(mResourcesMutex)
+
+		ResourceContainerIterator it = mResources.begin();
+		while (it != mResources.end())
+		{
+			(*it)->notifyOnDeviceDestroy(d3d9Device);
+			++it;
+		}	
 	}
 
 	 //-----------------------------------------------------------------------
 	void D3D9ResourceManager::notifyOnDeviceLost(IDirect3DDevice9* d3d9Device)
 	{
-		//CM_LOCK_MUTEX(mResourcesMutex)
-
-		//ResourceContainerIterator it = mResources.begin();
-		//while (it != mResources.end())
-		//{
-		//	(*it)->notifyOnDeviceLost(d3d9Device);
-		//	++it;
-		//}	
+		CM_LOCK_MUTEX(mResourcesMutex)
+
+		ResourceContainerIterator it = mResources.begin();
+		while (it != mResources.end())
+		{
+			(*it)->notifyOnDeviceLost(d3d9Device);
+			++it;
+		}	
 	}
 
 	 //-----------------------------------------------------------------------
 	void D3D9ResourceManager::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device)
 	{		
-/*		CM_LOCK_MUTEX(mResourcesMutex)
+		CM_LOCK_MUTEX(mResourcesMutex)
 
 		ResourceContainerIterator it = mResources.begin();
 		while (it != mResources.end())
 		{
 			(*it)->notifyOnDeviceReset(d3d9Device);
 			++it;			
-		}	*/	
+		}		
 	}
 
 	//-----------------------------------------------------------------------

+ 0 - 2
CamelotD3D9Renderer/Source/CmD3D9Texture.cpp

@@ -240,8 +240,6 @@ namespace CamelotEngine
 		
 		clearBufferViews();
 
-		D3D9RenderSystem::getResourceManager()->_notifyResourceDestroyed(static_cast<D3D9Resource*>(this));
-
 		IDestroyable::destroy();
 	}
 	/****************************************************************************************/

+ 0 - 2
CamelotD3D9Renderer/Source/CmD3D9VertexBuffer.cpp

@@ -340,8 +340,6 @@ namespace CamelotEngine {
 		mMapDeviceToBufferResources.clear();   
 		SAFE_DELETE_ARRAY(mSystemMemoryBuffer);
 
-		D3D9RenderSystem::getResourceManager()->_notifyResourceDestroyed(static_cast<D3D9Resource*>(this));
-
 		VertexBuffer::destroy_internal();
 	}
 }

+ 0 - 2
CamelotD3D9Renderer/Source/CmD3D9VertexDeclaration.cpp

@@ -189,8 +189,6 @@ namespace CamelotEngine {
 	{
 		releaseDeclaration();
 
-		D3D9RenderSystem::getResourceManager()->_notifyResourceDestroyed(static_cast<D3D9Resource*>(this));
-
 		VertexDeclaration::destroy_internal();
 	}
 }

+ 1 - 0
CamelotRenderer/TODO.txt

@@ -68,6 +68,7 @@ Plan today & saturday:
   - Make Resources::destroy() private
   - Have Resources::unload which calls destroy() internally
   - Have Resources::unloadUnused() which unloads all with reference count of 1
+  - Don't store heavyweight GUID in each ResourceHandle