Index: trunk/VUT/Ogre/include/OgreOcclusionQueriesQueryManager.h
===================================================================
--- trunk/VUT/Ogre/include/OgreOcclusionQueriesQueryManager.h	(revision 154)
+++ trunk/VUT/Ogre/include/OgreOcclusionQueriesQueryManager.h	(revision 159)
@@ -7,5 +7,5 @@
   
 /**
-	Class which implements the QueryManager for Ogre scene queries.
+	Class which implements the QueryManager for Ogre scene queries using occlusion queries.
 */
 class __declspec(dllexport) OcclusionQueriesQueryManager: public PlatformQueryManager
@@ -13,5 +13,5 @@
 public:
     /** Constructor taking a hierarchy interface as an argument. This allows to operate
-	onm different hierarchy types, while reusing the implementation of the query methods.
+		on different hierarchy types, while reusing the implementation of the query methods.
     */
 	OcclusionQueriesQueryManager(PlatformHierarchyInterface *hierarchyInterface, Viewport *vp);
@@ -20,4 +20,5 @@
 			    InfoContainer<GtpVisibility::NodeInfo> *visibleNodes,
 			    InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry,
+				InfoContainer<GtpVisibility::PatchInfo> *visiblePatches,
 			    bool relativeVisibility = false);
     
@@ -29,4 +30,5 @@
 			       InfoContainer<GtpVisibility::NodeInfo> *visibleNodes,
 			       InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry,
+				   InfoContainer<GtpVisibility::PatchInfo> *visiblePatches,
 			       bool relativeVisibility = false);
     
Index: trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h
===================================================================
--- trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h	(revision 158)
+++ trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h	(revision 159)
@@ -75,5 +75,5 @@
 	/** Override from SceneManager so that sub entities can be assigned an id for item buffer.
 	*/
-	Entity* createEntity(const String& entityName, const String& meshName);
+	//Entity* createEntity(const String& entityName, const String& meshName);
 
 	/** Returns pointer to visibility manager.
@@ -84,4 +84,7 @@
 	*/
 	OctreeHierarchyInterface *GetHierarchyInterface();
+
+	void endFrame();
+
 
 protected:
@@ -142,4 +145,9 @@
 	int mLeavePassesInQueue;
 	ShadowTechnique mSavedShadowTechnique;
+
+	/// if transparent object are considered for item buffer visibility
+	bool mRenderTransparentsForItemBuffer;
+	/// Always execute the vertex program of a pass, e.g., for the depth pass or item buffer
+	bool mExecuteVertexProgramForAllPasses;
 };
 
Index: trunk/VUT/Ogre/include/OgreVisibilityOctreeSceneManager.h
===================================================================
--- trunk/VUT/Ogre/include/OgreVisibilityOctreeSceneManager.h	(revision 139)
+++ trunk/VUT/Ogre/include/OgreVisibilityOctreeSceneManager.h	(revision 159)
@@ -17,5 +17,5 @@
 	occlusion queries for visibility culling.
 */
-class VisibilityOctreeSceneManager: public OctreeSceneManager
+class __declspec(dllexport) VisibilityOctreeSceneManager: public OctreeSceneManager
 {
 public:
@@ -59,27 +59,91 @@
 	void WriteLog();
 
-	/** Override pass so we can do the z-fail pass */
+	/** Override pass so we can do the z-fail pass. 
+	*/
 	Pass* setPass(Pass* pass);
 
+	/** Override from SceneManager so we can skip all but first pass for depth pass. 
+	*/
+	bool validatePassForRendering(Pass* pass);
+
+	void RenderItemBuffer(RenderPriorityGroup* pGroup);
+	void RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass);
+	void renderQueueGroupObjects(RenderQueueGroup* pGroup);
+
+	/** Override from SceneManager so that sub entities can be assigned an id for item buffer.
+	*/
+	//Entity* createEntity(const String& entityName, const String& meshName);
+
+	/** Returns pointer to visibility manager.
+	*/
+	GtpVisibility::VisibilityManager *GetVisibilityManager();
+
+	/** Returns hierarchy interface.
+	*/
+	OctreeHierarchyInterface *GetHierarchyInterface();
+
+
 protected:
-	/** Creates material for depth pass, e.g., a pass that only fills the depth buffer */
+	
+	/** Creates material for depth pass, e.g., a pass that only fills the depth buffer. 
+	*/
 	void InitDepthPass();
+	/** Creates material for item buffer. 
+	*/
+	void InitItemBufferPass();
+	/** Fills render queue so that a visualization can be rendered. 
+	*/
+	void PrepareVisualization(Camera *cam);
+	/** Initialises necessary parameters for hierarchical visibility culling.
+	*/
+	void InitVisibilityCulling(Camera *cam);
 	
-	/** Prepares visualization of hierarchical culling. */
-	void PrepareVisualization(Camera *cam);
+	/// the interface to the scene hierarchy.
 	OctreeHierarchyInterface *mHierarchyInterface;
+	/// manages all visibility options
 	GtpVisibility::VisibilityManager *mVisibilityManager;
 	
+	/// if a visualization of the hierarchical culling is shown
 	bool mShowVisualization;
-	bool mSkipTransparents;
+
+	/// if the culled nodes are indicated in the visualization
 	bool mVisualizeCulledNodes;
 
+	/// if symbols for the nodes are shown in the visualization
 	bool mRenderNodesForViz;
+	/// if content of the nodes is shown in the visualization
 	bool mRenderNodesContentForViz;
+
+	/// render transparents after the hierarchical traversal
 	bool mDelayRenderTransparents;
+
+	/// use a depth pass (i.e., fill only the depth buffer in the first pass)
 	bool mUseDepthPass;
+	/// flag indicating if we currently render the depth pass
 	bool mRenderDepthPass;
 
+	/// if we use an item buffer for rendering (i.e., object ids as color codes
+	bool mUseItemBuffer;
+	/// if we currently render the item buffer 
+	bool mRenderItemBuffer;
+
+	/// if depth write should be enabled
+	bool mEnableDepthWrite;
+	/// if transparents are skipped during rendering
+	bool mSkipTransparents;
+
+	/// the depth pass (no lighting, just filling the depth buffer)
 	Pass *mDepthPass;
+	Pass *mItemBufferPass;
+
+	int mCurrentEntityId;
+	/// flag for passes which should not be deleted from queue during first traversal
+	int mLeavePassesInQueue;
+	ShadowTechnique mSavedShadowTechnique;
+
+	/// if transparent object are considered for item buffer visibility
+	bool mRenderTransparentsForItemBuffer;
+	/// Always execute the vertex program of a pass, e.g., for the depth pass or item buffer
+	bool mExecuteVertexProgramForAllPasses;
 };
 
Index: trunk/VUT/Ogre/include/OgrePlatformQueryManager.h
===================================================================
--- trunk/VUT/Ogre/include/OgrePlatformQueryManager.h	(revision 154)
+++ trunk/VUT/Ogre/include/OgrePlatformQueryManager.h	(revision 159)
@@ -26,4 +26,5 @@
 			       InfoContainer<GtpVisibility::NodeInfo> *visibleNodes,
 			       InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry,
+				   InfoContainer<GtpVisibility::PatchInfo> *visiblePatches,
 			       bool relativeVisibility = false);
     
Index: trunk/VUT/Ogre/include/OgreItemBufferQueryManager.h
===================================================================
--- trunk/VUT/Ogre/include/OgreItemBufferQueryManager.h	(revision 154)
+++ trunk/VUT/Ogre/include/OgreItemBufferQueryManager.h	(revision 159)
@@ -7,5 +7,7 @@
   
 /**
-	Class which implements the QueryManager for Ogre scene queries.
+	Class which implements the QueryManager for Ogre scene queries using an item buffer,
+	i.e., the objects are rendered with their id used as unique color code. After reading
+	back the frame buffer, the visibility information can be established for each object.
 */
 class __declspec(dllexport) ItemBufferQueryManager: public PlatformQueryManager
@@ -13,11 +15,14 @@
 public:
     /** Constructor taking a hierarchy interface as an argument. This allows to operate
-	onm different hierarchy types, while reusing the implementation of the query methods.
+		on different hierarchy types, while reusing the implementation of the query methods.
+		@param renderPatches determines if the visibility of either patches or meshes is computed.
     */
-	ItemBufferQueryManager(PlatformHierarchyInterface *hierarchyInterface, Viewport *vp);
+	ItemBufferQueryManager(PlatformHierarchyInterface *hierarchyInterface, Viewport *vp,
+						   const bool renderPatches);
     
     void ComputeCameraVisibility(const Camera &camera,
 			    InfoContainer<GtpVisibility::NodeInfo> *visibleNodes,
 			    InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry,
+				InfoContainer<GtpVisibility::PatchInfo> *visiblePatches,
 			    bool relativeVisibility = false);
     
@@ -25,7 +30,13 @@
 	
 protected:
-	void InitItemBuffer( InfoContainer<GtpVisibility::NodeInfo> *visibleNodes,
-			    InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry);
+	/** Helper function used to initialise item buffer.
+	*/
+	void InitItemBuffer( 
+				InfoContainer<GtpVisibility::NodeInfo> *visibleNodes,
+			    InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry,
+				InfoContainer<GtpVisibility::PatchInfo> *visiblePatches);
 	
+	/// if patches are used instead of meshes (only one at a time)
+	bool mRenderPatchesForItemBuffer;
 };
 
