Index: GTP/trunk/App/Demos/Vis/CHC_revisited/SceneEntity.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/SceneEntity.h	(revision 2767)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/SceneEntity.h	(revision 2768)
@@ -58,5 +58,5 @@
 	int GetLastRendered() const;
 
-	Material *GetMaterial() const  { return mMaterial; }
+	inline Material *GetMaterial() const  { return mMaterial; }
 
 protected:
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Texture.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Texture.cpp	(revision 2767)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Texture.cpp	(revision 2768)
@@ -1,5 +1,8 @@
 #include "Texture.h"
+#include "glInterface.h"
+#include "common.h"
+
+
 #include <IL/il.h>
-#include "glInterface.h"
 #include <assert.h>
 #include <iostream>
@@ -30,8 +33,14 @@
 {
 	startil();
-	
-	if (!ilLoadImage(ILstring(filename.c_str())))
+	string dummy=filename;
+	 
+	string::size_type posOfSpace = filename.find("bmp");
+
+  if (posOfSpace < filename.size()) 
+		dummy=string("../textures/trees/bark8.png");
+
+	if (!ilLoadImage(ILstring(dummy.c_str())))
 	{
-		cerr << "Image load error " << ilGetError() << ": " << filename << endl;
+		cerr << "Image load error " << ilGetError() << ": " << dummy << endl;
 	}
 	else
@@ -41,7 +50,9 @@
 
 		mFormat = FORMAT_RGBA;
+		mByteSize = mHeight * GetRowLength();
 		mImage = malloc(GetByteSize());
 
-		cout << "successfully loaded texture " << filename << endl;
+		Debug << "successfully loaded texture " << filename << " w " << mWidth << " h " << mHeight << endl;
+
 		ilCopyPixels(0, 0, 0, mWidth, mHeight, 1, IL_RGBA, IL_UNSIGNED_BYTE, mImage);
 		assert(ilGetError() == IL_NO_ERROR);
@@ -62,13 +73,15 @@
 	//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
 	//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
+	
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
+
+	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
+
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 
-	gluBuild2DMipmaps(GL_TEXTURE_2D, 3, mWidth, mHeight,
-					  GL_RGBA, GL_UNSIGNED_BYTE, mImage);
-
+	gluBuild2DMipmaps(GL_TEXTURE_2D, 3, mWidth, mHeight, GL_RGBA, GL_UNSIGNED_BYTE, mImage);
 	//glTexImage2D(GL_TEXTURE_2D, 0, 3, mWidth, mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, mImage);
 }
@@ -129,10 +142,4 @@
 
 
-int Texture::GetByteSize() const
-{
-	return mHeight * GetRowLength();
-}
-
-
 void Texture::Bind() const
 {
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Material.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Material.h	(revision 2767)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Material.h	(revision 2768)
@@ -62,5 +62,5 @@
   friend Material RandomMaterial();
 
-  Texture *GetTexture() const { return mTexture; }
+  inline Texture *GetTexture() const { return mTexture; }
 
   void SetTexture(Texture *texture) { mTexture = texture; }
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp	(revision 2767)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp	(revision 2768)
@@ -35,5 +35,6 @@
 mIsQueryMode(false),
 mUseOptimization(true),
-mFrameId(-1)
+mFrameId(-1),
+mUseRenderQueue(false)
 {
 }
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Texture.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Texture.h	(revision 2757)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Texture.h	(revision 2768)
@@ -44,8 +44,10 @@
 	int GetPixelSize() const;
 	
-	int GetByteSize() const;
+	inline int GetByteSize() const;
 	/** Bind the texture.
 	*/
 	void Bind() const;
+
+
 
 protected:
@@ -61,6 +63,13 @@
 	std::string mName;
 
+	int mByteSize;
 	void *mImage;
 };
+
+
+inline int Texture::GetByteSize() const
+{
+	return mByteSize;
+}
 
 }
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/RenderQueue.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/RenderQueue.cpp	(revision 2767)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/RenderQueue.cpp	(revision 2768)
@@ -5,4 +5,6 @@
 #include "Material.h"
 
+
+using namespace std;
 
 
@@ -13,19 +15,15 @@
 inline static bool IsLower(SceneEntity *ent1, SceneEntity *ent2)
 {
-	if (ent1->GetGeometry()->HasTexture() && ent2->GetGeometry()->HasTexture())
-	{
-		Texture *t1 = ent1->GetMaterial()->GetTexture();
-		Texture *t2 = ent1->GetMaterial()->GetTexture();
+	Texture *t1 = ent1->GetMaterial()->GetTexture();
+	Texture *t2 = ent2->GetMaterial()->GetTexture();
 
-		return t1->GetByteSize() < t2->GetByteSize();
-	}
-	else if (ent2->GetGeometry()->HasTexture())
-	{
-		return true;
-	}
+	int tsize1 = t1 ? t1->GetByteSize() : 0;
+	int tsize2 = t2 ? t2->GetByteSize() : 0;
 
-	return false;
+	if (tsize1 == tsize2)
+		return ent1->GetMaterial() < ent2->GetMaterial();
+
+	return tsize1 < tsize2;
 }
-
 
 
@@ -65,5 +63,6 @@
 {
 	Sort();
-
+	
+	//if (!mEntities.empty()) Debug << "rendering render queue" << endl;
 	SceneEntityContainer::const_iterator sit, sit_end = mEntities.end();
 
@@ -72,12 +71,23 @@
 		SceneEntity *ent = *sit;
 		ent->Render(mState);
+
+		/*if (ent->GetMaterial()->GetTexture())
+			Debug << " " << ent->GetMaterial()->GetTexture()->GetWidth();
+		else
+			Debug << " 0";*/
 	}
 }
-
 	
 
 void RenderQueue::Sort()
 {
-	sort(mEntities.begin(), mEntities.end());
+	//InitTiming();
+	//long t1, t2;
+	//t1 = GetTime();
+
+	sort(mEntities.begin(), mEntities.end(), IsLower);
+
+	//t2 = GetTime();
+	//cout << "sort: " << TimeDiff(t1, t2) << endl;
 }
 
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/chc_revisited.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/chc_revisited.vcproj	(revision 2767)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/chc_revisited.vcproj	(revision 2768)
@@ -253,12 +253,4 @@
 			</File>
 			<File
-				RelativePath=".\Timers.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\Timers.h"
-				>
-			</File>
-			<File
 				RelativePath=".\Triangle3.cpp"
 				>
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp	(revision 2767)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp	(revision 2768)
@@ -852,7 +852,7 @@
 	static long renderTime = traverser->GetStats().mRenderTime;
 
-	const float expFactor = 0.9f;
-
-	renderTime = renderTime * expFactor + (1.0f - expFactor) * traverser->GetStats().mRenderTime;
+	const float expFactor = 0.5f;
+
+	renderTime = traverser->GetStats().mRenderTime * expFactor + (1.0f - expFactor) * renderTime;
 
 	if (renderTime) fps /= (float)renderTime;
