Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Timer/PerfTimer.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Timer/PerfTimer.h	(revision 2777)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Timer/PerfTimer.h	(revision 2801)
@@ -13,7 +13,5 @@
 //
 //  15-jul-99 14:00:00  mw      created
-// ===========================================================================
-//  $Header: /usr/local/cvsyare/cvsyare/include/yareutils/PerfTimer.h,v 1.1 2002/09/24 16:53:47 wimmer Exp $ 
-// ===========================================================================
+
 
 #ifndef NO_PRAGMA_ONCE
@@ -24,5 +22,6 @@
 #define _PERFTIMER_H
 
-//#define NO_RDTSC_TIMER
+// RDTSC timer does not work with modern CPUs
+#define NO_RDTSC_TIMER
 
 #ifdef WIN32
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Timer/BenchTimer.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Timer/BenchTimer.h	(revision 2777)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Timer/BenchTimer.h	(revision 2801)
@@ -33,7 +33,8 @@
 // we definitely want timers to be inlined!
 #define PERFTIMER_INLINE __forceinline
-
-
+    
+    #ifndef WIN32_LEAN_AND_MEAN
 	#define WIN32_LEAN_AND_MEAN
+    #endif
 	#define NOMINMAX
 	#include <windows.h>	// for LARGE_INTEGER
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp	(revision 2800)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp	(revision 2801)
@@ -29,5 +29,4 @@
 	mNumBatches = 0;
 
-	mRenderTime = 0;
 	mWaitTime = 0;
 	mQueryTime = 0;
@@ -50,5 +49,7 @@
 mAssumedVisibleFrames(10),
 mMaxBatchSize(50),
-mUseTightBounds(false), mShowBounds(false)
+mUseTightBounds(false), 
+mShowBounds(false),
+mRenderQueue(NULL)
 {
 }
@@ -111,7 +112,11 @@
 
 			if (mUseRenderQueue)
-				mRenderQueue.Enqueue(ent);
+				mRenderQueue->Enqueue(ent);
 			else
 				ent->Render(mRenderState);
+
+			// store the visible entities for rendering in the second pass
+			if (mUseDepthPass)
+				mVisibleObjects.push_back(ent);
 		}		
 	}
@@ -128,5 +133,4 @@
 {
 	mRenderState = state;
-	mRenderQueue.SetRenderState(state);
 }
 
@@ -134,12 +138,10 @@
 void RenderTraverser::RenderScene()
 {
-	PerfTimer timer;
-	
-	glFinish();
-
-	timer.Start();
+	mVisibleObjects.clear();
 
 	glEnableClientState(GL_VERTEX_ARRAY);
-	glEnableClientState(GL_NORMAL_ARRAY);
+	
+	if (!mUseDepthPass)
+		glEnableClientState(GL_NORMAL_ARRAY);
 
 	++ mFrameId;
@@ -166,17 +168,16 @@
 	glDisableClientState(GL_VERTEX_ARRAY);
 	glDisableClientState(GL_NORMAL_ARRAY);
-
-	glFinish();
-
-
-	mStats.mRenderTime = timer.Elapsedms();
-	
-	//Debug << "type: " << GetType() << endl;
-	//if (mUseRenderQueue) Debug << "rq sort: " << 1e3f * mRenderQueue.sortTimer.TotalTime() << " ms" << endl;
-	/*
+	
+
+#ifdef PRINT_VERBOSE_BENCHMARKS
+
+	Debug << "traversal type: " << GetType() << endl;
+	if (mUseRenderQueue) Debug << "rq sort: " << 1e3f * mRenderQueue.sortTimer.TotalTime() << " ms" << endl;
+	
 	Debug << "wait time: " << 1e3f * waitTimer.TotalTime() << " ms" << endl;
 	Debug << "query time: " << 1e3f * queryTimer.TotalTime() << " ms" << endl;
 	Debug << "rest time: " << 1e3f * restTimer.TotalTime() << " ms" << endl;
-	*/
+
+#endif
 }
 
@@ -186,4 +187,10 @@
 	mUseRenderQueue = useRenderQueue;
 	//std::cout << "using render queue: " << mUseRenderQueue << std::endl;
+}
+
+
+void RenderTraverser::SetUseDepthPass(bool b)
+{
+	mUseDepthPass = b;
 }
 
@@ -275,10 +282,10 @@
 		++ mStats.mNumStateChanges;
 		 
-	if (mRenderQueue.GetSize() > 0)
+	if (mRenderQueue->GetSize() > 0)
 		++ mStats.mNumBatches;
 
-	mRenderQueue.Apply();
-}
-
-
-}
+	mRenderQueue->Apply();
+}
+
+
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 2800)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 2801)
@@ -48,4 +48,6 @@
 	inline int GetCurrentVboId() { return mCurrentVboId; }
 
+	void SetDepthPass(bool depthPass) { mIsDepthPass = depthPass; }
+	bool IsDepthPass() { return mIsDepthPass; }
 
 protected:
@@ -57,4 +59,6 @@
 
 	int mCurrentVboId;
+
+	bool mIsDepthPass;
 };
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h	(revision 2795)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h	(revision 2801)
@@ -39,18 +39,15 @@
 	/** Returns the number entities currently in the queue.
 	*/
-	int GetSize() const { return (int)mEntities.size(); }
+	inline int GetSize() const { return (int)mEntities.size(); }
 	/** Renders and clears the queue.
 	*/
 	void Apply();
-	/** Prints the ordering in the render queue.
+	/** Prints the current state of the render queue.
 	*/
 	void Print();
 
-	PerfTimer sortTimer;
-
-
 protected:
 
-	/** Sorts the render queue according to some parameters.
+	/** Sorts the render queue by materials / textures.
 	*/
 	void Sort();
@@ -64,4 +61,8 @@
 };
 
+/// measures sort time for detailed benchmarks
+static PerfTimer sortTimer;
+
+
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2800)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2801)
@@ -22,4 +22,5 @@
 #include "Timer/PerfTimer.h"
 #include "SceneQuery.h"
+#include "RenderQueue.h"
 
 
@@ -60,4 +61,6 @@
 
 SceneQuery *sceneQuery = NULL;
+RenderQueue *renderQueue = NULL;
+
 
 /// these values get scaled with the frame rate
@@ -66,4 +69,5 @@
 /// elapsed time in seconds
 double elapsedTime = 1.0f;
+double algTime = 1.0f;
 
 int winWidth = 1024;
@@ -99,9 +103,7 @@
 bool useRenderQueue = true;
 bool useMultiQueries = true;
-
 bool flyMode = true;
-
-/// the accumulated z axis rotation
-float rotation = 0;
+bool depthPass = false;
+
 
 SceneEntityContainer skyGeometry;
@@ -126,4 +128,5 @@
 void DrawHelpMessage();
 void RenderSky();
+void RenderVisibleObjects();
 
 void Begin2D();
@@ -146,4 +149,6 @@
 void KeyVerticalMotion(float shift);
 
+void PlaceViewer(const Vector3 &oldPos);
+
 
 inline float KeyRotationAngle() { return keyRotation * elapsedTime; }
@@ -162,4 +167,6 @@
 	visCamera->SetNear(0.0f);
 	visCamera->Yaw(.5 * M_PI);
+
+	renderQueue = new RenderQueue(&state);
 
 	glutInitWindowSize(winWidth, winHeight);
@@ -268,5 +275,5 @@
 	//glEnable(GL_ALPHA_TEST);
 	glDisable(GL_ALPHA_TEST);
-	glAlphaFunc(GL_GEQUAL, 0.1f);
+	glAlphaFunc(GL_GEQUAL, 0.5f);
 
 	glFrontFace(GL_CCW);
@@ -283,4 +290,6 @@
 	glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseColor);
 	glMaterialfv(GL_FRONT, GL_SPECULAR, specularColor);
+
+	glDepthFunc(GL_LESS);
 }
 
@@ -298,4 +307,5 @@
 		"'F5',          - toggles between fly / walkmode",
 		"'F6',          - shows/hides parameters",
+		"'F7',          - depth pass",
 		"'SPACE'        - cycles through occlusion culling algorithms",
 		"",
@@ -380,4 +390,5 @@
 	traverser->SetCamera(camera);
 	traverser->SetHierarchy(bvh);
+	traverser->SetRenderQueue(renderQueue);
 	traverser->SetRenderState(&state);
 	traverser->SetUseOptimization(useOptimization);
@@ -388,4 +399,6 @@
 	traverser->SetUseMultiQueries(useMultiQueries);
 	traverser->SetUseTightBounds(useTightBounds);
+	traverser->SetUseDepthPass(depthPass);
+	traverser->SetRenderQueue(renderQueue);
 }
 
@@ -430,6 +443,6 @@
 
 	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
-	//glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
-	glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
+	glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
+	//glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
 	//glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SEPARATE_SPECULAR_COLOR_EXT);
 	glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SINGLE_COLOR_EXT);
@@ -481,9 +494,9 @@
 
 void Display() 
-{
+{	
+	PerfTimer frameTimer, algTimer;
+	frameTimer.Start();
+
 	Vector3 oldPos = camera->GetPosition();
-
-	PerfTimer frameTimer;
-	frameTimer.Start();
 
 	if (leftKeyPressed)
@@ -500,20 +513,30 @@
 		KeyVerticalMotion(KeyShift());
 
-	Vector3 playerPos = camera->GetPosition();
-	
-	if (!flyMode)
-	{
-	Vector3 playerPos = camera->GetPosition();
-
-		bool validIntersect = sceneQuery->CalcIntersection(playerPos);
-
-		if (validIntersect &&
-			(( playerPos.z - oldPos.z) < bvh->GetBox().Size(2) * 1e-1f))
-		{
-	camera->SetPosition(playerPos);
-		}
-	}
+	// place view on ground
+	if (!flyMode) PlaceViewer(oldPos);
+
+	// note: have to flush queue in order to get reliable timings
+	// for optimal performance, remove this
+	glFinish();
+
+	algTimer.Start();
 
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+	glDepthFunc(GL_LESS);
+	glDisable(GL_TEXTURE_2D);
+	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+
+	// render without shading
+	if (depthPass) 
+	{
+		state.SetDepthPass(true);
+		glDisable(GL_LIGHTING);
+	}
+	else
+	{
+		state.SetDepthPass(false);
+		glEnable(GL_LIGHTING);
+	}
 
 	// bring eye modelview matrix up-to-date
@@ -523,10 +546,38 @@
 	traverser->RenderScene();
 
-	
+
+	//////
+	//-- other rendering
+
+	glEnableClientState(GL_VERTEX_ARRAY);
+	glEnableClientState(GL_NORMAL_ARRAY);
+
+
+	// reset depth pass and render visible objects
+	if (depthPass) 
+	{
+		RenderVisibleObjects();
+	}
+	
+
 	///////////////
 	//-- render sky
 
 	RenderSky();
-	
+
+	state.Reset();
+
+	glDisableClientState(GL_VERTEX_ARRAY);
+	glDisableClientState(GL_NORMAL_ARRAY);
+
+
+	
+	// note: have to flush queue in order to get reliable timings
+	// for optimal performance, remove this
+	glFinish();
+	algTime = algTimer.Elapsedms();
+
+	///////////
+
 	if (visMode) DisplayVisualization();
 	
@@ -719,4 +770,8 @@
 		flyMode = !flyMode;
 		break;
+	case GLUT_KEY_F7:
+		depthPass = !depthPass;
+		traverser->SetUseDepthPass(depthPass);
+		break;
 	case GLUT_KEY_LEFT:
 		{
@@ -988,4 +1043,5 @@
 	DEL_PTR(camera);
 	DEL_PTR(loader);
+	DEL_PTR(renderQueue);
 }
 
@@ -1032,7 +1088,10 @@
 
 
-	static double renderTime = traverser->GetStats().mRenderTime;
+	static double renderTime = algTime;
 	const float expFactor = 0.3f;
-	renderTime = traverser->GetStats().mRenderTime * expFactor + (1.0f - expFactor) * renderTime;
+
+	// if there was something fishy going on in this frame => don't count
+	if (algTime < 1000) 
+		renderTime = algTime * expFactor + (1.0f - expFactor) * algTime;
 
 	accumulatedTime += renderTime;
@@ -1058,6 +1117,6 @@
 		      assumedVisibleFrames, maxBatchSize);
 
-	sprintf(msg3, "render queue: %d, multiqueries: %d, tight bounds: %d", 
-		      useRenderQueue, useMultiQueries, useTightBounds);
+	sprintf(msg3, "render queue: %d, depth pass: %d, multiqueries: %d, tight bounds: %d", 
+		      useRenderQueue, depthPass, useMultiQueries, useTightBounds);
 
 	string str;
@@ -1088,6 +1147,6 @@
 	else
 	{
-	//	glColor3f(1.0f, 1.0f, 1.0f);
-		glColor3f(1.0f, 0.0f, 0.0f);
+		glColor3f(1.0f, 1.0f, 1.0f);
+		//glColor3f(1.0f, 0.0f, 0.0f);
 		Output(850, 30, msg[renderMode]);
 
@@ -1115,15 +1174,43 @@
 void RenderSky()
 {
-	glEnableClientState(GL_VERTEX_ARRAY);
-	glEnableClientState(GL_NORMAL_ARRAY);
-
 	SceneEntityContainer::const_iterator sit, sit_end = skyGeometry.end();
 
 	for (sit = skyGeometry.begin(); sit != sit_end; ++ sit)
 		(*sit)->Render(&state);
-
-	glDisableClientState(GL_VERTEX_ARRAY);
-	glDisableClientState(GL_NORMAL_ARRAY);
-
+}
+
+
+void RenderVisibleObjects()
+{
+	state.SetDepthPass(false);
 	state.Reset();
-}
+
+	glEnable(GL_LIGHTING);
+	glDepthFunc(GL_LEQUAL);
+
+	//cout << "visible: " << (int)traverser->GetVisibleObjects().size() << endl;
+
+	SceneEntityContainer::const_iterator sit, 
+		sit_end = traverser->GetVisibleObjects().end();
+
+	for (sit = traverser->GetVisibleObjects().begin(); sit != sit_end; ++ sit)
+		renderQueue->Enqueue(*sit);
+		
+	renderQueue->Apply();
+
+	glDepthFunc(GL_LESS);
+}
+
+
+void PlaceViewer(const Vector3 &oldPos)
+{
+	Vector3 playerPos = camera->GetPosition();
+
+	bool validIntersect = sceneQuery->CalcIntersection(playerPos);
+
+	if (validIntersect &&
+		(( playerPos.z - oldPos.z) < bvh->GetBox().Size(2) * 1e-1f))
+	{
+		camera->SetPosition(playerPos);
+	}
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 2800)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 2801)
@@ -12,5 +12,6 @@
 mAlphaTestEnabled(false), 
 mTexturesEnabled(false), 
-mMode(RENDER) 
+mMode(RENDER),
+mIsDepthPass(false)
 {
 	Reset(); 
@@ -29,7 +30,10 @@
 	if (mode == QUERY)
 	{
-		//glDisableClientState(GL_NORMAL_ARRAY);
-		glDisable(GL_LIGHTING);
-		glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+		if (!mIsDepthPass)
+		{
+			glDisable(GL_LIGHTING);
+			glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+		}
+
 		glDepthMask(GL_FALSE);
 
@@ -41,7 +45,11 @@
 		//-- restore render state
 
-		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+		if (!mIsDepthPass)
+		{
+			glEnable(GL_LIGHTING);
+			glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+		}
+
 		glDepthMask(GL_TRUE);
-		glEnable(GL_LIGHTING);
 	}
 
@@ -52,17 +60,4 @@
 void RenderState::SetState(bool texturing, bool alphaTest)
 {
-	if (mTexturesEnabled && !texturing) 
-	{
-		mTexturesEnabled = false;
-		glDisable(GL_TEXTURE_2D);
-		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-	}
-	else if (!mTexturesEnabled && texturing)
-	{
-		mTexturesEnabled = true;
-		//glEnable(GL_TEXTURE_2D);
-		//glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-	}
-
 	if (mAlphaTestEnabled && !alphaTest) 
 	{
@@ -73,6 +68,23 @@
 	{
 		mAlphaTestEnabled = true;
-		//glEnable(GL_ALPHA_TEST);
-		//glAlphaFunc(GL_GEQUAL, 0.5f);
+		glEnable(GL_ALPHA_TEST);
+	}
+
+	// allow only alpha textures in depth pass
+	if (mTexturesEnabled && 
+		(!texturing || mIsDepthPass && !mAlphaTestEnabled))
+	{
+		mTexturesEnabled = false;
+		glDisable(GL_TEXTURE_2D);
+		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+	}
+	else if (!mTexturesEnabled && texturing)
+	{
+		if (!mIsDepthPass || mAlphaTestEnabled)
+		{
+			mTexturesEnabled = true;
+			glEnable(GL_TEXTURE_2D);
+			glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+		}
 	}
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h	(revision 2800)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h	(revision 2801)
@@ -39,6 +39,4 @@
 	int mNumStateChanges;
 	int mNumBatches;
-	
-	double mRenderTime;
 
 	double mWaitTime;
@@ -53,13 +51,18 @@
 {
 public:
-	
+
+	/** Default constructor.
+	*/
+	RenderTraverser();
+	/** Virtual constructor, has to be redefined in subclasses
+	*/
+	virtual ~RenderTraverser();
+	/** Abstract method that traverses and renders the scene
+	*/
+	void RenderScene();
+
 	enum {CULL_FRUSTUM, STOP_AND_WAIT, CHC, CHCPLUSPLUS, NUM_TRAVERSAL_TYPES};
-
-	RenderTraverser();
-	~RenderTraverser();
-
-	//! Renders the scene with the specified method
-	/**
-		The method is one of
+	/** Returns the type of the traversal.
+   	    The type is one of
 		CULL_FRUSTUM: view frustum culling only
 		STOP_AND_WAIT: hierarchical stop and wait algorithm
@@ -67,5 +70,5 @@
 		CHCPLUSPLUS: coherent hierarchical algorithm revisited
 	*/
-	void RenderScene();
+	virtual int GetType() const = 0;
 	/** Sets the scene hierarchy.
 	*/
@@ -74,4 +77,7 @@
 	*/
 	void SetCamera(Camera *cam)  {mCamera = cam;}
+	/** Sets the render queue.
+	*/
+	void SetRenderQueue(RenderQueue *rq) {mRenderQueue =rq;}
 	/** Renders a visualization of the hierarchy
 	*/
@@ -86,6 +92,5 @@
 	*/
 	int GetCurrentFrameId() const { return mFrameId; }
-
-
+	
 	//////////////////
 	//-- options for the different rendering algorithms
@@ -95,13 +100,15 @@
 	*/
 	void SetUseRenderQueue(bool useRenderQueue);
+	/** If depth pass should be used.
+		If true, the entities found visible in the current pass are stored
+	*/
+	void SetUseDepthPass(bool storeVisibleObjects);
 	/** Sets visible pixels threshold for visibility classification
 	*/
 	void SetVisibilityThreshold(int threshold);
-
 
 	///////////////////
 	//-- CHC / CHC ++ related options
 
-
 	/** CHC optimization to query the geometry itself instead of the bounding box.
 	*/
@@ -122,7 +129,9 @@
 	*/
 	void SetShowBounds(bool showBounds);
-
-	virtual int GetType() const = 0;
-	
+	/** Returns the entities found visible in current frame
+	    (only if StoreVisibleObjects is set)
+	*/
+	const SceneEntityContainer &GetVisibleObjects() const { return mVisibleObjects; }
+
 protected:
 
@@ -172,5 +181,8 @@
 	TraversalStatistics mStats;
 	
-	RenderQueue mRenderQueue;
+	RenderQueue *mRenderQueue;
+
+	/// the objects found visible in current frame
+	SceneEntityContainer mVisibleObjects;
 
 
@@ -194,8 +206,5 @@
 	bool mShowBounds;
 
-	// timers
-	PerfTimer restTimer;
-	PerfTimer waitTimer;
-	PerfTimer queryTimer;
+	bool mUseDepthPass;
 };
 
@@ -207,4 +216,9 @@
 
 
+/// timers for detailed benchmarks
+static PerfTimer restTimer;
+static PerfTimer waitTimer;
+static PerfTimer queryTimer;
+
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp	(revision 2800)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp	(revision 2801)
@@ -7,4 +7,6 @@
 using namespace std;
 
+// sort by alpha, in second instance per texture
+//#define SORT_ALPHA
 
 namespace CHCDemoEngine
@@ -12,5 +14,5 @@
 
 
-inline static bool IsLower(SceneEntity *ent1, SceneEntity *ent2)
+inline static bool CompTexture(SceneEntity *ent1, SceneEntity *ent2)
 {
 	// group by texture size
@@ -25,8 +27,19 @@
 
 
-inline static bool IsLower2(SceneEntity *ent1, SceneEntity *ent2)
+#ifdef SORT_ALPHA
+
+inline static bool CompMat(SceneEntity *ent1, SceneEntity *ent2)
+{ 
+	return ent1->GetMaterial()->IsAlphaTestEnabled() < ent2->GetMaterial()->IsAlphaTestEnabled();
+}
+
+#else
+
+inline static bool CompMat(SceneEntity *ent1, SceneEntity *ent2)
 {
 	return ent1->GetMaterial() < ent2->GetMaterial();
 }
+
+#endif
 
 
@@ -37,5 +50,5 @@
 
 RenderQueue::RenderQueue(RenderState *state):
-mState(state)
+mState(state), mMinSizeForSorting(3)
 {
 }
@@ -100,9 +113,13 @@
 
 	// show ordering by material
-	Debug << "\nmaterial ptr: " << endl;
+	Debug << "\nmaterial: " << endl;
 	
 	for (sit = mEntities.begin(); sit != sit_end; ++ sit)
 	{
+#ifdef SORT_ALPHA
+		Debug << (*sit)->GetMaterial()->IsAlphaTestEnabled() << " ";
+#else
 		Debug << (*sit)->GetMaterial() << " ";
+#endif
 	}
 }
@@ -118,8 +135,15 @@
 void RenderQueue::Sort()
 {
+#ifdef SORT_ALPHA
+	// sort by texture size
+	sort(mEntities.begin(), mEntities.end(), CompTexture);
+	// sort by alpha test enabled
+	stable_sort(mEntities.begin(), mEntities.end(), CompMat);
+#else
 	// sort by material
-	sort(mEntities.begin(), mEntities.end(), IsLower2);
+	sort(mEntities.begin(), mEntities.end(), CompMat);
 	// sort by texture size
-	stable_sort(mEntities.begin(), mEntities.end(), IsLower);
+	stable_sort(mEntities.begin(), mEntities.end(), CompTexture);
+#endif
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h	(revision 2800)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h	(revision 2801)
@@ -494,13 +494,14 @@
 #define INITIAL_TRIANGLES_PER_VIRTUAL_LEAVES 1000
 
-}
-
-#endif
-
-
-
-
-
-
-
-
+// #define PRINT_VERBOSE_BENCHMARKS
+}
+
+#endif
+
+
+
+
+
+
+
+
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2800)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2801)
@@ -153,4 +153,6 @@
 				LinkIncremental="1"
 				AdditionalLibraryDirectories="libs/GL;libs/Devil/lib;libs/Zlib/lib"
+				IgnoreAllDefaultLibraries="false"
+				IgnoreDefaultLibraryNames="LIBCMT"
 				GenerateDebugInformation="false"
 				SubSystem="1"
@@ -473,4 +475,8 @@
 				<File
 					RelativePath=".\src\Geometry.h"
+					>
+				</File>
+				<File
+					RelativePath=".\src\Material.h"
 					>
 				</File>
