Index: trunk/VUT/work/ogre_changes/RenderSystem/Direct3D9/include/OgreD3D9HardwareOcclusionQuery.h
===================================================================
--- trunk/VUT/work/ogre_changes/RenderSystem/Direct3D9/include/OgreD3D9HardwareOcclusionQuery.h	(revision 61)
+++ trunk/VUT/work/ogre_changes/RenderSystem/Direct3D9/include/OgreD3D9HardwareOcclusionQuery.h	(revision 88)
@@ -71,11 +71,11 @@
 	void beginOcclusionQuery();	
 	void endOcclusionQuery();
-	bool pullOcclusionQuery( unsigned int* NumOfFragments);
-	bool pullOcclusionQuery( unsigned int* NumOfFragments, const HW_OCCLUSIONQUERY flag  );
+	bool pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult );
+	bool pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult,
+							 const HW_OCCLUSIONQUERY flag  ); 
+
 	unsigned int getLastQuerysPixelcount() { return m_uintPixelCount; }
-#ifdef GTP_VISIBILITY_MODIFIED_OGRE
-	bool resultAvailable();
-#endif
-	// This functions are optional, it's a simple filter that simply skipps some hardware occlusion tests on visable objects only
+	
+	// This functions are optional, it's a simple filter that simply skips some hardware occlusion tests on visable objects only
 	// It's easy to use if you don't have to keep track on which objects are visable (can be skipped) and what objects arn't visable..
 	// (None visable objects and object you introduce for the first time have allways to be tested allthough the cheepest possible 
@@ -93,5 +93,5 @@
 
 
-	void setSkipRate( int skip ) { m_Skip = skip; }			// Using 2 only 50 % of the tests are actully made and 3 results in only 33% of the tests. So on.
+	void setSkipRate( int skip ) { m_Skip = skip; }			// Using 2 only 50 % of the tests are actually made and 3 results in only 33% of the tests. So on.
 	int	 getSkipRate() { return m_Skip; } 
 
@@ -100,4 +100,7 @@
 //--
 protected:
+
+	bool pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult, 
+						     const DWORD queryFlag );
 
 	unsigned int		m_uintPixelCount;		
Index: trunk/VUT/work/ogre_changes/RenderSystem/Direct3D9/src/OgreD3D9HardwareOcclusionQuery.cpp
===================================================================
--- trunk/VUT/work/ogre_changes/RenderSystem/Direct3D9/src/OgreD3D9HardwareOcclusionQuery.cpp	(revision 61)
+++ trunk/VUT/work/ogre_changes/RenderSystem/Direct3D9/src/OgreD3D9HardwareOcclusionQuery.cpp	(revision 88)
@@ -78,22 +78,13 @@
 	if( m_bHWOcclusionSupport )		// Make it fail silently if hardware occlusion isn't supported
 	{
-		if  ( m_SkipCounter ==  m_Skip ) { m_SkipCounter = 0; };		// Counter starts at 0 again at m_Skip 
-		
-		if ( m_SkipCounter == 0 && m_uintPixelCount != 0 )	// New or none visable objects must allways be tested but visable objects can be skiped
-		{
-			m_pD3DQuery->Issue(D3DISSUE_BEGIN); 
-		}
+		m_pD3DQuery->Issue(D3DISSUE_BEGIN); 
 	}
 }
-	
+//------------------------------------------------------------------
 void D3D9HardwareOcclusionQuery::endOcclusionQuery() 
 { 
 	if( m_bHWOcclusionSupport )	// Make it fail silently if hardware occlusion isn't supported
 	{
-		if (m_SkipCounter == 0 && m_uintPixelCount != 0 ) // New or none visable objects must allways be tested but visable objects can be skiped
-		{
-			m_pD3DQuery->Issue(D3DISSUE_END); 
-		}
-		m_SkipCounter++;								 // The skip counter is increased 
+		m_pD3DQuery->Issue(D3DISSUE_END); 
 	}
 }
@@ -104,27 +95,7 @@
 // Note: OpenGL dosn't use this flag at all so the application running OpenGL won't display any different behaviour.
 //--
-bool D3D9HardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments) 
+bool D3D9HardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult ) 
 {
-	HRESULT hr;
-	
-	if( m_bHWOcclusionSupport )	// Make it fail silently if hardware occlusion isn't supported
-	{
-		hr = m_pD3DQuery->GetData( NumOfFragments, sizeof( NumOfFragments ), D3DGETDATA_FLUSH );
-
-		if ( hr != S_OK ) 
-			{
-				return false; 
-			}
-			else 
-			{ 
-				m_uintPixelCount = *NumOfFragments; 
-				return true; 
-			}
-	}
-	else
-	{
-		m_uintPixelCount = 100000; // Fails quitlly if hardware occlusion is not supported - every object is visable
-		return true;
-	}
+	return pullOcclusionQuery(NumOfFragments, waitForResult, HWOCCLUSIONQUERY_FLUSH);
 }
 
@@ -135,59 +106,34 @@
 // Note: OpenGL dosn't use this flag at all so the application running OpenGL won't display any different behaviour.
 //--
-bool D3D9HardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const HW_OCCLUSIONQUERY flag  ) 
+bool D3D9HardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult, 
+												     const HW_OCCLUSIONQUERY flag  ) 
 {
-	HRESULT hr;
-
+	DWORD queryFlag = flag == HWOCCLUSIONQUERY_FLUSH ? D3DGETDATA_FLUSH : 0;
 	// TO DO: USE lockOpts= D3D9Mappings::get(options); instead of RS_OCCLUSIONQUERY enum
 
-	if( m_bHWOcclusionSupport )	// Make it fail silently if hardware occlusion isn't supported
+	return pullOcclusionQuery(NumOfFragments, waitForResult, queryFlag);
+}
+//------------------------------------------------------------------
+bool D3D9HardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult, 
+												     const DWORD queryFlag ) 
+{
+	HRESULT hr = S_OK;
+
+	if( m_bHWOcclusionSupport )	// In case hardware occlusion isn't supported
+	{	
+		do
+		{
+			hr = m_pD3DQuery->GetData( NumOfFragments, sizeof( NumOfFragments ), queryFlag );
+	    	}
+		while(waitForResult && (hr == S_FALSE));
+		
+		m_uintPixelCount = *NumOfFragments; 
+	}
+	else
 	{
+		m_uintPixelCount = 100000; // every object is visible
+	}
 	
-		switch( flag )
-		{
-			case HWOCCLUSIONQUERY_FLUSH : 	
-				hr = m_pD3DQuery->GetData( NumOfFragments, sizeof( NumOfFragments ), D3DGETDATA_FLUSH );
-			break;
-
-			case HWOCCLUSIONQUERY_NOFLUSH :	
-				hr = m_pD3DQuery->GetData( NumOfFragments, sizeof( NumOfFragments ), 0 );
-			break;
-		};
-
-
-
-		if ( hr != S_OK ) 
-			{
-				return false; 
-			}
-			else 
-			{ 
-				m_uintPixelCount = *NumOfFragments; 
-				return true; 
-			}
-	}
-	else 
-	{
-		m_uintPixelCount = 100000; // Fails quitlly if hardware occlusion is not supported - every object is visable
-		return true;
-	}
+	return hr == S_OK;
 }
-
-
-#ifdef GTP_VISIBILITY_MODIFIED_OGRE
-
-bool D3D9HardwareOcclusionQuery::resultAvailable()
-{
-	bool result = true;
-
-	if( m_bHWOcclusionSupport )	// Make it fail silently if hardware occlusion isn't supported
-	{	//TODO: implement
-		//glGetOcclusionQueryuivNV_ptr( m_uintQuery[0], GL_PIXEL_COUNT_NV, &result );
-	}
-
-	return result;
-}
-
-#endif // GTP_VISIBILITY_MODIFIED_OGRE
-
-}
+} // namespace OGre
