Index: trunk/VUT/work/ogre_changes/OgreMain/include/OgreRenderQueueSortingGrouping.h
===================================================================
--- trunk/VUT/work/ogre_changes/OgreMain/include/OgreRenderQueueSortingGrouping.h	(revision 193)
+++ trunk/VUT/work/ogre_changes/OgreMain/include/OgreRenderQueueSortingGrouping.h	(revision 343)
@@ -202,8 +202,4 @@
 #ifdef GTP_VISIBILITY_MODIFIED_OGRE
 	
-		/** Clears solids in this group of renderables. Leaves transparents in group.
-        */
-        void clearSolids(void);
-
 		enum {SOLID_PASSES = 1,
 			  SOLID_PASSES_DECAL = 2,
@@ -221,4 +217,14 @@
 		*/
 		void clear(const int leavePassesInQueue);
+		/** Destroys passes determined by parameter.
+			@param passes can be one or several (combined by |) of:
+			SOLID_PASSES 
+			SOLID_PASSES_DECAL 
+			SOLID_PASSES_DIFFUSE_SPECULAR
+			SOLID_PASSES_NOSHADOW
+			TRANSPARENT_PASSES
+		*/
+		void destroyPassMaps(const int leavePassesInQueue);
+
 #endif // GTP_VISIBILITY_MODIFIED_OGRE		
         /** Sets whether or not the queue will split passes by their lighting type,
@@ -337,6 +343,6 @@
 
         }
-		/** Clears only solid renderables. Leaves transparents in queue. */
-		void clearSolids(void)
+	
+		void destroyPasses(int passes)
         {
             PriorityMap::iterator i, iend;
@@ -344,6 +350,7 @@
             for (i = mPriorityGroups.begin(); i != iend; ++i)
             {
-                i->second->clearSolids();
-            }
+                i->second->destroyPassMaps(passes);
+            }
+
         }
 #endif // GTP_VISIBILITY_MODIFIED_OGRE		
Index: trunk/VUT/work/ogre_changes/OgreMain/src/OgreRenderQueueSortingGrouping.cpp
===================================================================
--- trunk/VUT/work/ogre_changes/OgreMain/src/OgreRenderQueueSortingGrouping.cpp	(revision 139)
+++ trunk/VUT/work/ogre_changes/OgreMain/src/OgreRenderQueueSortingGrouping.cpp	(revision 343)
@@ -278,45 +278,7 @@
 #ifdef GTP_VISIBILITY_MODIFIED_OGRE	
 	//-----------------------------------------------------------------------
-    void RenderPriorityGroup::clearSolids(void)
-    {
-        /*SolidRenderablePassMap::iterator i, iend;
-        // Delete queue groups which are using passes which are to be
-        // deleted, we won't need these any more and they clutter up 
-        // the list and can cause problems with future clones
-        const Pass::PassSet& graveyardList = Pass::getPassGraveyard();
-        Pass::PassSet::const_iterator gi, giend;
-        giend = graveyardList.end();
-        for (gi = graveyardList.begin(); gi != giend; ++gi)
-        {
-            removeSolidPassEntry(*gi);
-        }
-
-        // Now remove any dirty passes, these will have their hashes recalculated
-        // by the parent queue after all groups have been processed
-        // If we don't do this, the std::map will become inconsistent for new insterts
-        const Pass::PassSet& dirtyList = Pass::getDirtyHashList();
-        Pass::PassSet::const_iterator di, diend;
-        diend = dirtyList.end();
-        for (di = dirtyList.begin(); di != diend; ++di)
-        {
-            removeSolidPassEntry(*di);
-        }*/
-        // NB we do NOT clear the graveyard or the dirty list here, because 
-        // it needs to be acted on for all groups, the parent queue takes 
-        // care of this afterwards
-
-        // We do not clear the unchanged solid pass maps, only the contents of each list
-        // This is because we assume passes are reused a lot and it saves resorting
-        clearSolidPassMap(mSolidPasses);
-        clearSolidPassMap(mSolidPassesDecal);
-        clearSolidPassMap(mSolidPassesDiffuseSpecular);
-        clearSolidPassMap(mSolidPassesNoShadow);
-    }
-	//-----------------------------------------------------------------------
     void RenderPriorityGroup::clear(const int leavePassesInQueue)
     {
-		SolidRenderablePassMap::iterator i, iend;
-       
-		// -- standard method if no passes are left in queue
+		//-- standard method if no passes are left in queue
 		if (leavePassesInQueue == 0)
 		{
@@ -328,15 +290,47 @@
         // This is because we assume passes are reused a lot and it saves resorting
 		if (!(leavePassesInQueue & SOLID_PASSES))
-			clearSolidPassMap(mSolidPasses);
+			destroySolidPassMap(mSolidPasses);
 		if (!(leavePassesInQueue & SOLID_PASSES_DECAL))
-			clearSolidPassMap(mSolidPassesDecal);
+			destroySolidPassMap(mSolidPassesDecal);
 		if (!(leavePassesInQueue & SOLID_PASSES_DIFFUSE_SPECULAR))
-			clearSolidPassMap(mSolidPassesDiffuseSpecular);
+			destroySolidPassMap(mSolidPassesDiffuseSpecular);
 		if (!(leavePassesInQueue & SOLID_PASSES_NOSHADOW))
-			clearSolidPassMap(mSolidPassesNoShadow);
+			destroySolidPassMap(mSolidPassesNoShadow);
 
         if (!(leavePassesInQueue & TRANSPARENT_PASSES))
 			mTransparentPasses.clear();
     }
+	//-----------------------------------------------------------------------
+    void RenderPriorityGroup::destroyPassMaps(const int leavePassesInQueue)
+    {
+		/*    
+        const Pass::PassSet& graveyardList = Pass::getPassGraveyard();
+        Pass::PassSet::const_iterator gi, giend;
+        giend = graveyardList.end();
+        for (gi = graveyardList.begin(); gi != giend; ++gi)
+        {
+            removeSolidPassEntry(*gi);
+        }
+
+        const Pass::PassSet& dirtyList = Pass::getDirtyHashList();
+        Pass::PassSet::const_iterator di, diend;
+        diend = dirtyList.end();
+        for (di = dirtyList.begin(); di != diend; ++di)
+        {
+            removeSolidPassEntry(*di);
+		}
+		*/
+
+        // We do not clear the unchanged solid pass maps, only the contents of each list
+        // This is because we assume passes are reused a lot and it saves resorting
+		if (!(leavePassesInQueue & SOLID_PASSES))
+			destroySolidPassMap(mSolidPasses);
+		if (!(leavePassesInQueue & SOLID_PASSES_DECAL))
+			destroySolidPassMap(mSolidPassesDecal);
+		if (!(leavePassesInQueue & SOLID_PASSES_DIFFUSE_SPECULAR))
+			destroySolidPassMap(mSolidPassesDiffuseSpecular);
+		if (!(leavePassesInQueue & SOLID_PASSES_NOSHADOW))
+			destroySolidPassMap(mSolidPassesNoShadow);
+    }
 #endif // GTP_VISIBILITY_MODIFIED_OGRE		
 //-----------------------------------------------------------------------
Index: trunk/VUT/work/ogre_changes/OgreMain/src/OgreSceneManager.cpp
===================================================================
--- trunk/VUT/work/ogre_changes/OgreMain/src/OgreSceneManager.cpp	(revision 316)
+++ trunk/VUT/work/ogre_changes/OgreMain/src/OgreSceneManager.cpp	(revision 343)
@@ -4226,8 +4226,5 @@
 		if (isRenderQueueToBeProcessed(qId))
 		{
-			/*if (leaveTransparentsInQueue)
-			{	pGroup->clearSolids();	}	else
-			{	pGroup->clear(); }*/
-			pGroup->clear(leavePassesInQueue);
+			pGroup->destroyPasses(leavePassesInQueue);
 		}
 	}
Index: trunk/VUT/work/ogre_changes/RenderSystems/GL/include/OgreGLHardwareOcclusionQuery.h
===================================================================
--- trunk/VUT/work/ogre_changes/RenderSystems/GL/include/OgreGLHardwareOcclusionQuery.h	(revision 115)
+++ trunk/VUT/work/ogre_changes/RenderSystems/GL/include/OgreGLHardwareOcclusionQuery.h	(revision 343)
@@ -111,4 +111,6 @@
 #ifdef GTP_VISIBILITY_MODIFIED_OGRE
 	bool pullOcclusionQuery( unsigned int* NumOfFragments, const bool waitForResult, const HW_OCCLUSIONQUERY flag = HWOCCLUSIONQUERY_FLUSH ); 
+
+	static bool sUseArbQueries;
 #endif // GTP_VISIBILITY_MODIFIED_OGRE
 //----------------------------------------------------------------------
@@ -122,5 +124,6 @@
 	int				mSkipCounter;
 	int				mSkipInterval;
-	bool			mHasOcclusionSupport;
+	bool			mHasOcclusionSupportNV;
+	bool			mHasOcclusionSupportARB;
 };
 
Index: trunk/VUT/work/ogre_changes/RenderSystems/GL/src/OgreGLHardwareOcclusionQuery.cpp
===================================================================
--- trunk/VUT/work/ogre_changes/RenderSystems/GL/src/OgreGLHardwareOcclusionQuery.cpp	(revision 193)
+++ trunk/VUT/work/ogre_changes/RenderSystems/GL/src/OgreGLHardwareOcclusionQuery.cpp	(revision 343)
@@ -29,4 +29,5 @@
 namespace Ogre {
 
+bool GLHardwareOcclusionQuery::sUseArbQueries = false;
 /**
   * This is a class that is the base class of the query class for 
@@ -51,25 +52,11 @@
 	// Check for hardware occlusion support
 	// This is a hack to see if hw occlusion is supported. pointer is 0 if it's not supported.
-#ifdef GTP_VISIBILITY_USE_ARB_QUERIES
-	if (glGenQueriesARB_ptr != 0)
-#else
-	if (glGenOcclusionQueriesNV_ptr != 0)
-#endif
-    {
-		mHasOcclusionSupport = true;
-	}
-	else
-	{
-		mHasOcclusionSupport = false;
-	}
+	mHasOcclusionSupportARB = (glGenQueriesARB_ptr != 0);
+	mHasOcclusionSupportNV = (glGenOcclusionQueriesNV_ptr != 0);
 
-	if(mHasOcclusionSupport)
-	{
-#ifdef GTP_VISIBILITY_USE_ARB_QUERIES
+	if (sUseArbQueries && mHasOcclusionSupportARB)
 		glGenQueriesARB_ptr(1, &mQueryID );	
-#else
+	else if (!sUseArbQueries && mHasOcclusionSupportNV)
 		glGenOcclusionQueriesNV_ptr(1, &mQueryID);
-#endif
-	}
 }
 
@@ -79,12 +66,8 @@
 GLHardwareOcclusionQuery::~GLHardwareOcclusionQuery() 
 { 
-	if( mHasOcclusionSupport )
-	{
-#ifdef GTP_VISIBILITY_USE_ARB_QUERIES
+	if (sUseArbQueries && mHasOcclusionSupportARB)
 		glDeleteQueriesARB_ptr(1, &mQueryID);
-#else
+	else if (!sUseArbQueries && mHasOcclusionSupportNV)
 		glDeleteOcclusionQueriesNV_ptr(1, &mQueryID);  
-#endif
-	}	
 }
 
@@ -94,63 +77,31 @@
 void GLHardwareOcclusionQuery::beginOcclusionQuery() 
 { 
-	// Make it fail silently if hardware occlusion isn't supported
-	if(mHasOcclusionSupport)
-	{
-		// Counter starts at 0 again at mSkipInterval 
-#ifndef GTP_VISIBILITY_MODIFIED_OGRE
-		if(mSkipCounter == mSkipInterval) 
-#else
-		if (mSkipCounter >= mSkipInterval)  // otherwise no query ever issued if mSkipInterval = 0 !
-#endif // GTP_VISIBILITY_MODIFIED_OGRE
-	{
-			mSkipCounter = 0; 
-		}
+	//if (mSkipCounter >= mSkipInterval)  // otherwise no query ever issued if mSkipInterval = 0 !
+	//	mSkipCounter = 0; if (mSkipCounter != 0) return;
 
-		if (mSkipCounter == 0)
-		{
-#ifdef GTP_VISIBILITY_USE_ARB_QUERIES
+	if (sUseArbQueries && mHasOcclusionSupportARB)
 			glBeginQueryARB_ptr(GL_SAMPLES_PASSED_ARB, mQueryID);
-#else
+	else if (!sUseArbQueries && mHasOcclusionSupportNV)
 			glBeginOcclusionQueryNV_ptr(mQueryID);
-#endif
-		}
-	}
 }
 	
 void GLHardwareOcclusionQuery::endOcclusionQuery() 
 { 
-	// Make it fail silently if hardware occlusion isn't supported
-	if(mHasOcclusionSupport)
-	{
-		if( mSkipCounter == 0)
-		{
-#ifdef GTP_VISIBILITY_USE_ARB_QUERIES
+	//if( mSkipCounter != 0) return;
+	if (sUseArbQueries && mHasOcclusionSupportARB)
 			glEndQueryARB_ptr(GL_SAMPLES_PASSED_ARB);
-#else
+	else if (!sUseArbQueries && mHasOcclusionSupportNV)
 			glEndOcclusionQueryNV_ptr();
-#endif
+//	mSkipCounter++;
 		}
 
-		mSkipCounter++;
-	} 
-}
-
-//------------------------------------------------------------------
-// OpenGL dosn't use the flag paramter.
-//------------------------------------------------------------------
 bool GLHardwareOcclusionQuery::pullOcclusionQuery( unsigned int* NumOfFragments, const HW_OCCLUSIONQUERY flag  ) 
 {
-	if( mHasOcclusionSupport )	// Make it fail silently if hardware occlusion isn't supported
-	{
-#ifdef GTP_VISIBILITY_USE_ARB_QUERIES
+	if (sUseArbQueries && mHasOcclusionSupportARB)
 		glGetQueryObjectuivARB_ptr(mQueryID, GL_QUERY_RESULT_ARB, NumOfFragments);
-#else
+	else if (!sUseArbQueries && mHasOcclusionSupportNV)
 glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_NV, NumOfFragments);
-#endif
-	}
 	else
-	{
-		*NumOfFragments = 100000;		// Fails quitlly -> every object tested is visable.
-	}
+		*NumOfFragments = 100000;		// Fails quietly
 
 	mPixelCount = *NumOfFragments; 
@@ -161,32 +112,42 @@
 #ifdef GTP_VISIBILITY_MODIFIED_OGRE
 	//------------------------------------------------------------------
-	bool GLHardwareOcclusionQuery::pullOcclusionQuery( unsigned int * NumOfFragments, const bool waitForResult, const HW_OCCLUSIONQUERY flag) 
+bool GLHardwareOcclusionQuery::pullOcclusionQuery(unsigned int * NumOfFragments, 
+												  const bool waitForResult, 
+												  const HW_OCCLUSIONQUERY flag) 
 {
-	unsigned int isAvailable = GL_TRUE;
+	if (sUseArbQueries && mHasOcclusionSupportARB)	
+	{
+		int isAvailable = GL_TRUE;
 
-		if (mHasOcclusionSupport)	
-	{
 		if (!waitForResult)
+			glGetQueryivARB_ptr(mQueryID, GL_QUERY_RESULT_AVAILABLE_ARB, &isAvailable);
+		
+		if (isAvailable == GL_TRUE)
+			glGetQueryObjectuivARB_ptr(mQueryID, GL_QUERY_RESULT_ARB, NumOfFragments);
+
+		mPixelCount = *NumOfFragments;
+
+		return isAvailable == GL_TRUE;
+	} 
+	else if (!sUseArbQueries && mHasOcclusionSupportNV)
 		{
-			// use nv queries rather that arb because they are faster (no flush)
-				//glGetQueryivARB_ptr(mQueryID, GL_QUERY_RESULT_AVAILABLE_ARB, &isAvailable);
+		unsigned int isAvailable = GL_TRUE;
+
+		if (!waitForResult)
 				glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_AVAILABLE_NV, &isAvailable);
-		}
 
 		if (isAvailable == GL_TRUE)
-		{
-				//glGetQueryObjectuivARB_ptr(mQueryID, GL_QUERY_RESULT_ARB, NumOfFragments);
 				glGetOcclusionQueryuivNV_ptr(mQueryID, GL_PIXEL_COUNT_NV, NumOfFragments);
-		}
-	} 
-	else
-	{
-		// In case hardware occlusion isn't supported, every object is set visible.
-		*NumOfFragments = 100000;		
-	}
 
 		mPixelCount = *NumOfFragments; 
 
-	return isAvailable == GL_TRUE;	
+		return isAvailable == GL_TRUE;
+		}
+	
+		// In case hardware occlusion isn't supported, every object is set visible.
+		*NumOfFragments = 100000;		
+		mPixelCount = *NumOfFragments; 
+
+	return GL_TRUE;	
 }
 
Index: trunk/VUT/work/ogre_changes/RenderSystems/GL/src/OgreGLRenderSystem.cpp
===================================================================
--- trunk/VUT/work/ogre_changes/RenderSystems/GL/src/OgreGLRenderSystem.cpp	(revision 316)
+++ trunk/VUT/work/ogre_changes/RenderSystems/GL/src/OgreGLRenderSystem.cpp	(revision 343)
@@ -281,4 +281,20 @@
     void GLRenderSystem::setConfigOption(const String &name, const String &value)
     {
+		// set occlusion query
+#ifdef GTP_VISIBILITY_MODIFIED_OGRE
+		if ( name == "ArbQueries" )
+		{
+			if ( value == "No" )
+			{
+				GLHardwareOcclusionQuery::sUseArbQueries = false;
+			}
+			else if  ( value == "Yes" )
+			{
+				GLHardwareOcclusionQuery::sUseArbQueries = true;
+			}
+			return;
+		}
+#endif
+
         mGLSupport->setConfigOption(name, value);
     }
