Index: GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.h	(revision 863)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.h	(revision 1001)
@@ -15,5 +15,7 @@
   UnigraphicsParser(): Parser() {}
   
-  virtual bool ParseFile(const std::string filename, SceneGraphNode **root, const bool loadPolygonsAsMeshes = false);
+  virtual bool ParseFile(const std::string filename, 
+						 SceneGraphNode **root, 
+						 const bool loadPolygonsAsMeshes = false);
   
 };
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Material.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Material.h	(revision 860)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Material.h	(revision 1001)
@@ -33,11 +33,15 @@
   RgbColor mAmbientColor;
   
-  Material() 
+  Material(): mId(0)
   {
   }
   
+  Material(const int id): mId(id)
+  {
+  }
+
   Material(const RgbColor &color):mDiffuseColor(color),
 								  mAmbientColor(color),
-								  mSpecularColor(0,0,0)
+								  mSpecularColor(0,0,0), mId(0)
   {
   }
@@ -45,4 +49,15 @@
   friend Material RandomMaterial();
   
+  /** Returns unique material id.
+  */
+  int GetId() const
+  {
+	  return mId;
+  }
+
+protected:
+
+	// unique material id
+	int mId;
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp	(revision 863)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp	(revision 1001)
@@ -24,4 +24,5 @@
 }
 
+
 VrmlExporter::~VrmlExporter()
 {
@@ -31,6 +32,6 @@
 
 bool VrmlExporter::ExportRays(const RayContainer &rays,
-						const float length,
-						const RgbColor &color)
+							  const float length,
+							  const RgbColor &color)
 {
   RayContainer::const_iterator ri = rays.begin();
@@ -115,6 +116,6 @@
   for (; ri != rays.end(); ri++) {
     const Vector3 a = (*ri)->GetOrigin();
-	//const Vector3 b = (*ri)->mTerminationObject ? (*ri)->GetTermination() : a + 1000 * Normalize((*ri)->GetDir());
-	const Vector3 b = (*ri)->GetTermination(); // matt: change again!!
+	const Vector3 b = (*ri)->mTerminationObject ? (*ri)->GetTermination() : a + 1000 * Normalize((*ri)->GetDir());
+	//const Vector3 b = (*ri)->GetTermination(); // matt: change back!!
 
     stream<<a.x<<" "<<a.y<<" "<<a.z<<" ,";
@@ -152,12 +153,14 @@
 }
 
+
 void VrmlExporter::ExportIntersectable(Intersectable *object)
 {
 	switch (object->Type()) 
 	{
-	
 	case Intersectable::MESH_INSTANCE:
+		ExportMeshInstance((MeshInstance *)object);
+		break;
 	case Intersectable::TRANSFORMED_MESH_INSTANCE:
-		ExportMeshInstance((MeshInstance *)object);
+		ExportTransformedMeshInstance(dynamic_cast<TransformedMeshInstance *>(object));
 		break;
 	case Intersectable::VIEW_CELL:
@@ -180,4 +183,16 @@
 
 
+void VrmlExporter::ExportTransformedMeshInstance(TransformedMeshInstance *mi)
+{
+	Mesh mesh(*mi->GetMesh());
+
+	Matrix4x4 m;
+	mi->GetWorldTransform(m);
+	mesh.ApplyTransformation(m);
+
+	ExportMesh(&mesh);
+}
+
+
 void VrmlExporter::ExportViewCells(const ViewCellContainer &viewCells)
 {
@@ -189,4 +204,5 @@
 	}
 }
+
 
 void VrmlExporter::ExportBspLeaves(const BspTree &tree, const int maxPvs)
@@ -290,6 +306,5 @@
 	stream << "}" << endl; // end material
 	stream << "}" << endl; // end apperance
-	//stream << "}" << endl; // end shape
-
+	
 
 	// wireframe modes => set indexed lines
@@ -314,8 +329,8 @@
 	{
 		Face *face = *fi;
-	  
+	 
 		VertexIndexContainer::const_iterator vi = face->mVertexIndices.begin();
-	  
-		for (; vi != face->mVertexIndices.end(); vi++)
+	 
+		for (; vi != face->mVertexIndices.end(); ++ vi)
 		{
 			stream << *vi << " ";
@@ -331,5 +346,5 @@
 
 	stream << "]" << endl; // end coordIndex
-	
+
 
 	stream << "coord Coordinate {" << endl;
@@ -385,6 +400,5 @@
 	stream << "}" << endl; // end material
 	stream << "}" << endl; // end apperance
-	//stream << "}" << endl; // end shape
-
+	
 
 	// wireframe modes => set indexed lines
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Matrix4x4.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Matrix4x4.h	(revision 860)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Matrix4x4.h	(revision 1001)
@@ -34,6 +34,8 @@
 
   // Fundamental operations
-  int Invert();		      // Invert the matrix .. returns 0 = regular
-  void Transpose();				// Transpose the matrix
+  /// Invert the matrix .. returns 0 = regular
+  int Invert();		
+  /// Transpose the matrix
+  void Transpose();	
 
   void
Index: GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp	(revision 971)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp	(revision 1001)
@@ -29,4 +29,5 @@
 #include "Triangle3.h"
 #include "ViewCellsManager.h"
+#include "ResourceManager.h"
 
 namespace GtpVisibilityPreprocessor {
@@ -60,11 +61,13 @@
 #define ROTATE_SCENE 0
 
-
-static void RotateMesh(Mesh *mesh)
+static int sUniqueMeshIdx = 0;
+
+// hack: rotate mesh by n degrees
+static void RotateMesh(Mesh *mesh, const float angle)
 {
 	VertexContainer::iterator it, it_end = mesh->mVertices.end();
 
-	const float angle = 30.0f * PI / 180.0f;
-	const Matrix4x4 rot = RotationYMatrix(angle);
+	const float angleRad = angle * PI / 180.0f;
+	const Matrix4x4 rot = RotationYMatrix(angleRad);
 
 	for (it = mesh->mVertices.begin(); it != it_end; ++ it)
@@ -83,8 +86,10 @@
   , mSpaceCount(0)
   , mLoadPolygonsAsMeshes(loadPolygonsAsMeshes)
-{
-  mCurrentNode = root;
-  // this matrix should never be removed from stack
-  //mTransformations.push(IdentityMatrix());
+  , mCurrentMesh(NULL)
+{
+	mCurrentNode = root;
+
+	// this matrix should never be removed from stack
+	//mTransformations.push(IdentityMatrix());
 }
 
@@ -99,29 +104,16 @@
 //  StdInParseHandlers: Implementation of the SAX DocumentHandler interface
 // ---------------------------------------------------------------------------
+
 void X3dParseHandlers::endElement(const XMLCh* const name)
 {
-  StrX lname(name);
-  string element(lname.LocalForm());
-  
-  // only create new mesh instance if define mechanism was not used
-  if (element == "Shape")
-    EndShape();
-
-  if (element == "Transform")
-	  EndTransform();
-}
-
-
-
-
-void X3dParseHandlers::ApplyTransformation(Mesh *mesh, 
-										   const Matrix4x4 &m) const
-{
-	VertexContainer::iterator it, it_end = mesh->mVertices.end();
-
-	for (it = mesh->mVertices.begin(); it != it_end; ++ it)
-	{
-		(*it) = m * (*it);        
-	}
+	StrX lname(name);
+	string element(lname.LocalForm());
+
+	// only create new mesh instance if define mechanism was not used
+	if (element == "Shape")
+		EndShape();
+
+	if (element == "Transform")
+		EndTransform();
 }
 
@@ -134,7 +126,21 @@
 		trafos.pop();
 
-		ApplyTransformation(mesh, m);
-	}
-}
+		mesh->ApplyTransformation(m);
+	}
+}
+
+
+void X3dParseHandlers::ApplyTransformations(TrafoStack trafos, 
+											TransformedMeshInstance *mi) const
+{
+	while (!trafos.empty())
+	{
+		const Matrix4x4 m = trafos.top();
+		trafos.pop();
+
+		mi->ApplyWorldTransform(m);
+	}
+}
+
 
 void X3dParseHandlers::StartTransform(AttributeList&  attributes)
@@ -143,4 +149,5 @@
 
 	const int len = attributes.getLength();
+
     Matrix4x4 *rotm = NULL;
 	Matrix4x4 *scalem = NULL;
@@ -208,86 +215,102 @@
 void X3dParseHandlers::EndShape()
 {
-	// this shape is a definition => don't create mesh instance
-	if (mIsMeshDefinition) 
-{
-		mMeshDefinitions[mCurrentMeshName.c_str()] = mCurrentMesh;
-		//cout << "new definition: " << mCurrentMeshName << endl;
+	 //-- if shape is merely a definition => don't create particular mesh instance
+	 if (!mCurrentMesh || mIsMeshDefinition) 
+	 { 
+		 return;
+	 }
+
+	 //-- each polygon is one single mesh
+	 if (mLoadPolygonsAsMeshes)
+	 {
+		 FaceContainer::const_iterator fit, fit_end = mCurrentMesh->mFaces.end();
+
+		 cout << "m";
 		
-		return;
-	}
-
-	// each polygon is one single mesh
-	if (mLoadPolygonsAsMeshes)
-	{
-		//if (mCurrentMesh->mFaces.empty())	cout << "error!" << endl;
-
-		FaceContainer::const_iterator fit, fit_end = mCurrentMesh->mFaces.end();
-
-		cout << "m";
-		//cout << "m: " << mCurrentMesh->mFaces.size() << endl;
-		for (fit = mCurrentMesh->mFaces.begin(); fit != fit_end; ++ fit)
-		{
-			cout << "f";
-
-			Face *face = *fit;
-			// only one face per mesh
-			Mesh *mesh = new Mesh();
-			VertexIndexContainer vc;
-					
-			VertexIndexContainer::const_iterator vit, vit_end = face->mVertexIndices.end();
+		 for (fit = mCurrentMesh->mFaces.begin(); fit != fit_end; ++ fit)
+		 {
+			 cout << "f";
+
+			 Face *face = *fit;
+		
+			 // we create a new mesh for each face from the current mesh
+			 Mesh *mesh = MeshManager::GetSingleton()->CreateResource();
 			
-			int i = 0;
-			for (vit = face->mVertexIndices.begin(); vit != vit_end; ++ vit, ++ i)
+			 VertexIndexContainer::const_iterator vit, vit_end = face->mVertexIndices.end();
+		
+			 int i = 0;
+			 VertexIndexContainer vcIndices;
+
+			 for (vit = face->mVertexIndices.begin(); vit != vit_end; ++ vit, ++ i)
+			 {
+				 cout << "i";
+				 const int index = (*vit);
+
+				 // add vertices
+				 mesh->mVertices.push_back(mCurrentMesh->mVertices[index]);
+
+				 // indices don't make much sense if mesh = face, but
+				 // we need them anyway ...
+				 vcIndices.push_back(i);
+			 }
+
+			 mesh->mFaces.push_back(new Face(vcIndices));
+
+			 // NOTE: should rather be written into trafo of mesh instance
+			 ApplyTransformations(mTransformations, mesh);
+
+			 mesh->Preprocess();
+				
+			 // make an instance of this mesh
+			 MeshInstance *mi = new MeshInstance(mesh);
+			 mCurrentNode->mGeometry.push_back(mi);
+		 }
+
+		 // this mesh is not needed, unless it is used as a definition
+		 if (!mUsingMeshDefinition) 
+		 	 MeshManager::GetSingleton()->DestroyEntry(mCurrentMesh->GetId());
+	}
+	else // default usage: create a mesh instance from the current mesh
+	{ 
+		MeshInstance *mi;
+
+		if (0 && !mUsingMeshDefinition) 
+		{
+			// make an instance of this mesh
+            mi = new MeshInstance(mCurrentMesh);
+
+			// this mesh is used only once => write transformations directly into it
+			ApplyTransformations(mTransformations, mCurrentMesh);
+		}
+		else
+		{
+			 // make an instance of this mesh
+			 TransformedMeshInstance *tmi = new TransformedMeshInstance(mCurrentMesh);
+
+			 // apply transformation on the instance of the mesh 
+			 ApplyTransformations(mTransformations, tmi);
+
+			 mi = tmi;
+		}
+		
+		if (mCurrentMaterial)
+		{
+			// HACK: add the material to the mesh directly if no material yet
+			if (mCurrentMesh->mMaterial)
 			{
-				cout << "i";
-				int index = (*vit);
-				// add vertices
-				mesh->mVertices.push_back(mCurrentMesh->mVertices[index]);
-				vc.push_back(i);
+				mCurrentMesh->mMaterial = mCurrentMaterial;
 			}
-
-			mesh->mFaces.push_back(new Face(vc));
-
-			// NOTE: should rather be written into trafo of mesh instance
-			ApplyTransformations(mTransformations, mesh);
-
-			mesh->Preprocess();
-				
-			// make an instance of this mesh
-			MeshInstance *mi = new MeshInstance(mesh);
-			mCurrentNode->mGeometry.push_back(mi);
-		}
-
-		// LEAK!! TODO: delete if not defd
-		if (!mUsingMeshDefinition)
-			delete mCurrentMesh;
-
-		//mCurrentVertices.clear();
-		//mCurrentVertexIndices.clear();
-	}
-	else
-	{ 
-		if (!mCurrentMesh->mFaces.empty()) 
-		{
-			// should rather be written into the transformation
-			// of a mesh instance
-			ApplyTransformations(mTransformations, mCurrentMesh);
-
-			mCurrentMesh->Preprocess();
-			// make an instance of this mesh
-			MeshInstance *mi = new MeshInstance(mCurrentMesh);
-
-			mCurrentNode->mGeometry.push_back(mi);
-			// set the object id to a unique value
-			//mi->SetId(mCurrentObjectId ++);
-		} 
-		else 
-		{
-			// empty mesh => discard
-			cout<<"X";
-
-			delete mCurrentMesh;
-		}
-
+			else // add material to the instance
+			{
+				mi->SetMaterial(mCurrentMaterial);
+			}
+		}
+
+		// create local mesh kd tree
+		mCurrentMesh->Preprocess();
+		// add to scene graph
+		mCurrentNode->mGeometry.push_back(mi);
+	
+		// reset current mesh
 		mCurrentMesh = NULL;
 	}
@@ -297,46 +320,64 @@
 void X3dParseHandlers::StartIndexedFaceSet(AttributeList&  attributes)
 {
-  int len = attributes.getLength();
-
-  int i;
-  VertexIndexContainer vertices;
+	//-- indexedfaceset corresponds  to Mesh in our implementation
+	const int len = attributes.getLength();
+
+	VertexIndexContainer vertices;
   
 	mIsMeshDefinition = false;
 	mUsingMeshDefinition = false;
-	for (i = 0; i < len; ++ i) 
+
+	for (int i = 0; i < len; ++ i) 
 	{
-		string attrName(StrX(attributes.getName(i)).LocalForm());
-	  
-		// this is a definition of a mesh
-		if (attrName == "DEF")
-		{
+		const string attrName(StrX(attributes.getName(i)).LocalForm());
+	
+		//-- we use an already defined mesh
+		if (attrName == "USE")
+		{
+			StrX attrValue(attributes.getValue(i));
+			const char *meshName = attrValue.LocalForm();
+
+			mUsingMeshDefinition = true;
+
+            // retrieve mesh from mesh container
+			const int meshIdx = mMeshDefinitions[meshName];
+
+			mCurrentMesh = 
+				MeshManager::GetSingleton()->FindEntry(meshIdx);
+
+			//Debug << "retrieving mesh definition: " << mCurrentMeshName << endl;
+			cout << "u";
+		}
+		else if (attrName == "DEF") //-- a definition of a mesh
+		{
+			const StrX attrValue(attributes.getValue(i));
+			const char *meshName = attrValue.LocalForm();
+
+			// this is only a definition, don't create actual  instance
 			mIsMeshDefinition = true;
+			
+			//-- create new mesh definition
+			mCurrentMesh = MeshManager::GetSingleton()->CreateResource();
+			
+			// store the mesh defination in a lookup table
+			mMeshDefinitions[meshName] = mCurrentMesh->GetId();
+			cout << "d";
+		}
+		
+		//-- read coordinate indices for current mesh
+		else if (attrName == "coordIndex") 
+		{
 			StrX attrValue(attributes.getValue(i));
 			const char *ptr = attrValue.LocalForm();
-			mCurrentMeshName = ptr;
-
-			cout << "d";
-		}
-		
-		// we use an already defined mesh
-		if (attrName == "USE")
-		{
-			StrX attrValue(attributes.getValue(i));
-
-			// discard new mesh and assign defined mesh
-			DEL_PTR(mCurrentMesh);
-			const char *ptr = attrValue.LocalForm();
-
-			mCurrentMesh = mMeshDefinitions[ptr];
-			mUsingMeshDefinition = true;
-			cout << "u";
-		}
-		
-		if (attrName == "coordIndex") 
-		{
-			StrX attrValue(attributes.getValue(i));
+
+			//-- immediate use: create a new mesh using a generic name
+			if (!mCurrentMesh)
+			{
+				mCurrentMesh = MeshManager::GetSingleton()->CreateResource();
+			}
+
 			// handle coordIndex
 			vertices.clear();
-			const char *ptr = attrValue.LocalForm();
+			
 		  
 			char *endptr;
@@ -372,28 +413,60 @@
 
 void
-X3dParseHandlers::StartMaterial(
-				AttributeList&  attributes)
-{
-  int len = attributes.getLength();
-  int i;
-  if (!mCurrentMesh->mMaterial)
-    mCurrentMesh->mMaterial = new Material;
-  for (i=0; i < len; i++) {
-    string attrName(StrX(attributes.getName(i)).LocalForm());
-    StrX attrValue(attributes.getValue(i));
-    const char *ptr = attrValue.LocalForm();
-    if (attrName == "diffuseColor") {
-      float r, g, b;
-      if (sscanf(ptr, "%f %f %f", &r, &g, &b) == 3)
-	mCurrentMesh->mMaterial->mDiffuseColor = RgbColor(r, g, b);
-    }
-  }
-}
-
-void
-X3dParseHandlers::StartCoordinate(
-				  AttributeList&  attributes)
-{
-	int len = attributes.getLength();
+X3dParseHandlers::StartMaterial(AttributeList&  attributes)
+{
+	const int len = attributes.getLength();
+		
+	mCurrentMaterial = MaterialManager::GetSingleton()->CreateResource();
+  
+	for (int i = 0; i < len; ++ i) 
+	{
+		const string attrName(StrX(attributes.getName(i)).LocalForm());
+		
+		const StrX attrValue(attributes.getValue(i));
+		const char *ptr = attrValue.LocalForm();
+
+
+		//-- we use an already defined material
+		if (attrName == "USE")
+		{
+			//mUsingMaterialDefinition = true;
+			string matName(ptr);
+
+            // retrieve mesh from mesh container
+			const int matIdx = mMaterialDefinitions[matName];
+
+			mCurrentMaterial = 
+				MaterialManager::GetSingleton()->FindEntry(matIdx);
+
+			//Debug << "retrieving mesh definition: " << mCurrentMeshName << endl;
+			cout << "u";
+		}
+		else if (attrName == "DEF") //-- a definition of a material
+		{
+			//mIsMaterialDefinition = true;
+			string matName(ptr);
+		
+			//-- create new material definition
+			mCurrentMaterial = MaterialManager::GetSingleton()->CreateResource();
+			// store the mesh defination in a lookup table
+			mMaterialDefinitions[matName] = mCurrentMaterial->GetId();
+			cout << "d";
+		}
+		// TODO: support not only diffuse material
+		else if (attrName == "diffuseColor") 
+		{
+			float r, g, b;
+      
+			if (sscanf(ptr, "%f %f %f", &r, &g, &b) == 3)
+				mCurrentMaterial->mDiffuseColor = RgbColor(r, g, b);
+		}
+	}
+}
+
+
+void
+X3dParseHandlers::StartCoordinate(AttributeList&  attributes)
+{
+	const int len = attributes.getLength();
 	
 	int i;
@@ -402,5 +475,5 @@
 	for (i=0; i < len; i++) 
 	{
-		string attrName(StrX(attributes.getName(i)).LocalForm());
+		const string attrName(StrX(attributes.getName(i)).LocalForm());
 	  
 		if (attrName == "point") 
@@ -441,5 +514,6 @@
 				vertices.push_back(v);
 			}
-			
+	
+			// substitute vertices into current mesh
 			mCurrentMesh->mVertices = vertices;
 		}
@@ -456,21 +530,25 @@
   
   if (element == "IndexedFaceSet") {
-    // create a new mesh node in the scene graph
-    StartIndexedFaceSet(attributes);
+	  // create a new mesh node in the scene graph
+	  StartIndexedFaceSet(attributes);
   }
  
   if (element == "Shape") {
-    cout << "+";
-	mCurrentMesh = new Mesh;
+	  cout << "+"; 
+
+	  // reset current shape values
+	  mCurrentMesh = NULL;
+	  mCurrentMaterial = NULL;
+	  mCurrentVertexIndices.clear();
+	  //mCurrentVertices.clear();
   }
   
-  if (element == "Coordinate") 
-  {
-    if (mCurrentMesh)
-      StartCoordinate(attributes);
+  if (element == "Coordinate") {
+	  StartCoordinate(attributes);
   }
-  
-  if (element == "Material") {
-    StartMaterial(attributes);
+
+  // todo
+  if (0 && element == "Material") {
+	  StartMaterial(attributes);
   }
   
@@ -479,5 +557,5 @@
   }
 
-  mElementCount++;
+  ++ mElementCount;
   mAttrCount += attributes.getLength();
 }
@@ -485,5 +563,5 @@
 void
 X3dParseHandlers::characters(const XMLCh* const chars,
-			     const unsigned int length)
+							 const unsigned int length)
 {
   mCharacterCount += length;
@@ -492,5 +570,5 @@
 void
 X3dParseHandlers::ignorableWhitespace(const XMLCh* const chars,
-				      const unsigned int length)
+									  const unsigned int length)
 {
   mSpaceCount += length;
@@ -507,8 +585,9 @@
 
 
-
 // ---------------------------------------------------------------------------
 //  StdInParseHandlers: Overrides of the SAX ErrorHandler interface
 // ---------------------------------------------------------------------------
+
+
 void
 X3dParseHandlers::error(const SAXParseException& e)
@@ -600,4 +679,5 @@
 	const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
 	parser->parse(filename.c_str());
+	
 	const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
 	duration = endMillis - startMillis;
@@ -674,9 +754,10 @@
 void X3dViewCellsParseHandlers::endElement(const XMLCh* const name)
 {
-  StrX lname(name);
-  string element(lname.LocalForm());
- 
-  if (element == "Shape")
-    EndShape();
+	StrX lname(name);
+
+	string element(lname.LocalForm());
+
+	if (element == "Shape")
+		EndShape();
 }
 
@@ -694,8 +775,4 @@
 	int i;
 	
-	// clear previous vertex indices
-	mCurrentVertexIndices.clear();
-
-
 	for (i=0; i < len; i++) 
 	{
Index: GTP/trunk/Lib/Vis/Preprocessing/src/LogManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/LogManager.cpp	(revision 1001)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/LogManager.cpp	(revision 1001)
@@ -0,0 +1,31 @@
+#include "LogManager.h"
+using namespace std;
+
+namespace GtpVisibilityPreprocessor {
+
+LogManager *LogManager::sLogManager = NULL;
+
+
+LogManager *LogManager::GetSingleton()
+{
+	if (!sLogManager)
+	{
+		sLogManager = new LogManager();
+	}
+
+	return sLogManager;
+}
+
+
+LogManager::LogManager()
+{
+	mOutStream.open("preprocessor.log");
+}
+
+
+void LogManager::LogMessage(const string &str)
+{
+	mOutStream << str.c_str();
+}
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h	(revision 860)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h	(revision 1001)
@@ -248,6 +248,4 @@
 {
 	mEntries.clear();
-	
-
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/OcclusionQuery.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/OcclusionQuery.cpp	(revision 1001)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/OcclusionQuery.cpp	(revision 1001)
@@ -0,0 +1,146 @@
+//#include "glInterface.h"
+#include "OcclusionQuery.h"
+#include <iostream>
+//#include <GL/gl.h>
+//#include <QtOpenGL>
+#include <glInterface.h>
+
+
+using namespace std;
+
+namespace GtpVisibilityPreprocessor {
+
+bool OcclusionQuery::sUseArbQueries = true;
+
+
+OcclusionQuery::OcclusionQuery()
+{
+	GLuint id;
+
+	if (sUseArbQueries)
+	{
+		glGenQueriesARB(1, &id);
+	}
+	else
+	{		
+		glGenOcclusionQueriesNV(1, &id);
+	}
+}
+
+OcclusionQuery::OcclusionQuery(const unsigned int idx):
+mId(idx)
+{}
+
+
+OcclusionQuery::~OcclusionQuery()
+{
+	if (sUseArbQueries)
+	{
+		glDeleteQueriesARB(1, &mId);
+	}
+	else
+	{
+		glDeleteOcclusionQueriesNV(1, &mId);
+	}
+	
+}
+//-----------------------------------------------------------------------
+void OcclusionQuery::BeginQuery()
+{
+	if (sUseArbQueries)
+	{
+		glBeginQueryARB(GL_SAMPLES_PASSED_ARB, mId);
+	}
+	else
+	{
+		glBeginOcclusionQueryNV(mId);
+	}
+}
+//-----------------------------------------------------------------------
+void OcclusionQuery::EndQuery()
+{
+	if (sUseArbQueries)
+	{
+		glEndQueryARB(GL_SAMPLES_PASSED_ARB);
+	}
+	else
+	{
+		glEndOcclusionQueryNV();	
+	}
+}
+
+
+unsigned int OcclusionQuery::GetQueryId() const
+{
+	return mId;
+}
+
+bool OcclusionQuery::ResultAvailable() const
+{
+	GLuint available;
+
+	if (sUseArbQueries)
+	{
+		//GLint available;
+		glGetQueryObjectuivARB(mId,
+							   GL_QUERY_RESULT_AVAILABLE_ARB,
+                               &available);
+		return available == GL_TRUE;
+	}
+	else
+	{
+		
+		glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_AVAILABLE_NV, &available);
+
+		return available == GL_TRUE;
+	}
+
+}
+
+
+unsigned int OcclusionQuery::GetQueryResult() const
+{
+	GLuint sampleCount;
+
+	if (sUseArbQueries)
+	{
+//		GLint sampleCount;
+		glGetQueryObjectuivARB(mId, GL_QUERY_RESULT_ARB, &sampleCount);
+		return sampleCount;
+	}
+	else
+	{	
+
+		glGetOcclusionQueryuivNV(mId, GL_PIXEL_COUNT_NV, &sampleCount);
+		return sampleCount;
+	}	
+}
+
+
+void OcclusionQuery::GenQueries(std::vector<OcclusionQuery * > &queries, const int numQueries)
+{
+	if ((int)queries.size() < numQueries)
+	{
+		const int n = numQueries - (int)queries.size();
+		unsigned int *newQueries = new unsigned int[n];
+
+
+		if (sUseArbQueries)
+		{
+			glGenQueriesARB(n, (unsigned int *)newQueries);
+		}
+		else
+		{
+			glGenOcclusionQueriesNV(n, (unsigned int *)newQueries);
+		}
+
+		for (int i = 0; i < n; ++ i)
+		{
+			queries.push_back(new OcclusionQuery(newQueries[i]));
+			//cout << "q: " << i << " id: " << newQueries[i] << endl;
+		}
+
+		delete [] newQueries;
+	}
+}
+} // namespace
Index: GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp	(revision 863)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp	(revision 1001)
@@ -12,4 +12,6 @@
 #include "Material.h"
 #include "Environment.h"
+#include "ResourceManager.h"
+
 
 namespace GtpVisibilityPreprocessor {
@@ -60,5 +62,5 @@
 
   SceneGraphNode *root = new SceneGraphNode;
-  Mesh *currentMesh = new Mesh;
+  Mesh *currentMesh = MeshManager::GetSingleton()->CreateResource();
 
   int meshGrouping;
@@ -145,5 +147,5 @@
 	c = cht.find(str);
 	if (currentMesh->mMaterial == NULL) {
-	  Material *mat = new Material;
+		Material *mat = MaterialManager::GetSingleton()->CreateResource();
 	  if (c != cht.end()) {
 	    mat->mDiffuseColor = RgbColor((*c).second.x, (*c).second.y, (*c).second.z);
@@ -151,6 +153,5 @@
 	  }
 	  else
-	    *mat = RandomMaterial();
-	  currentMesh->mMaterial = mat;
+	    currentMesh->AssignRandomMaterial();
 	}
       }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 978)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 1001)
@@ -313,5 +313,20 @@
 			mesh = dynamic_cast<ViewCell *>(object)->GetMesh();
 			break;
-			// TODO: handle transformed mesh instances
+		case Intersectable::TRANSFORMED_MESH_INSTANCE:
+			{
+				TransformedMeshInstance *mi = dynamic_cast<TransformedMeshInstance *>(object);
+
+				if (!mi->GetMesh())
+					break;
+
+				mesh = new Mesh(*mi->GetMesh());
+
+				Matrix4x4 m;
+				mi->GetWorldTransform(m);
+
+				mesh->ApplyTransformation(m);
+
+                break;
+			}
 		default:
 			Debug << "intersectable type not supported" << endl;
@@ -323,4 +338,8 @@
 			mBox.Include(object->GetBox()); // add to BSP tree aabb
 			AddMeshToPolygons(mesh, polys, NULL);
+
+			// cleanup
+			if (object->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE)
+				DEL_PTR(mesh);
 		}
 	}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 991)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1001)
@@ -170,5 +170,6 @@
 	void AddViewCell(ViewCell *viewCell);
 
-	/** Derive view cells from objects.
+	/** Derive view cells from objects. The view ells are created by taking the object
+		geometry into account.
 	*/
 	void DeriveViewCells(const ObjectContainer &objects, 
@@ -597,6 +598,5 @@
 	/// the scene bounding box
 	AxisAlignedBox3 mViewSpaceBox;
-	/// holds the view cell meshes
-	MeshContainer mMeshContainer;
+	
 	/// if view cells should be exported
 	bool mExportViewCells;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h	(revision 991)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h	(revision 1001)
@@ -70,9 +70,8 @@
 
   /// Default constructor
-  Mesh():mVertices(), mFaces(), mMaterial(NULL), mKdTree(NULL) {}
-  
+  Mesh():mVertices(), mFaces(), mMaterial(NULL), mKdTree(NULL), mId(0) {}
+
   /// Constructor with container preallocation
-  Mesh(const int vertices,
-       const int faces):
+  Mesh(const int vertices, const int faces):
     mFaces(),
     mMaterial(NULL),
@@ -80,10 +79,29 @@
     mVertices(),
     mIsConvex(false),
-    mIsWatertight(false)
+    mIsWatertight(false),
+	mId(0)
   {
     mVertices.reserve(vertices);
     mFaces.reserve(faces);
   }
-  
+
+  /** Constructor setting a unqiue mesh id.
+  */
+  Mesh(const int id);
+
+  /** Setting unique mesh id and using preallocation.
+  */
+  Mesh(const int id, const int vertices, const int faces);
+
+  /** Copy constructor making a deep copy of the faces.
+  */
+  Mesh(const Mesh &rhs);
+
+  /** Assignement operator.
+	@note does not copy id
+	@note preprocess may be necessary
+  */
+  Mesh& operator=(const Mesh& m);
+
   ~Mesh() {
     for (int i=0; i < mFaces.size(); i++)
@@ -113,55 +131,68 @@
 
   void ComputeBoundingBox();
+
+  /** This function must be called after creating the mesh
+	because it creates the local kd tree and the bounding box.
+	*/
   void Preprocess();
 
-  /** Axis aligned bounding box of the mesh in local mesh coordinates */
+  /** Applies transformation to the mesh.
+	@note: meshkdtree will most likely be outdated after transformation, thus 
+	another preprocess might be necessary.	
+	*/
+  void ApplyTransformation(const Matrix4x4 &m);
+
+  /** Axis aligned bounding box of the mesh in local mesh coordinates.
+  */
   AxisAlignedBox3 mBox;
   
-  /** Vertices forming the mesh */
+  /** Vertices forming the mesh.
+  */
   VertexContainer mVertices;
   
-  /** Patches forming the mesh */
+  /** Patches forming the mesh.
+  */
   FaceContainer mFaces;
   
-  /** Global mesh material */
+  /** Global mesh material.
+  */
   Material *mMaterial;
   
-  /** true if the mesh is a convex mesh */
+  /** true if the mesh is a convex mesh.
+  */
   bool mIsConvex;
 
-  /** true if the mesh is a convex mesh */
+  /** true if the mesh is a convex mesh.
+  */
   bool mIsWatertight;
 
   MeshKdTree *mKdTree;
-  
-  int
-  CastRay(
-					Ray &ray,
-					MeshInstance *instance
+
+  int
+  CastRay(Ray &ray, MeshInstance *instance);
+	
+  int
+  CastRayToSelectedFaces(
+						 Ray &ray,
+						 const vector<int> &faces,
+						 Intersectable *instance
+						 );
+	
+  int
+  CastRayToFace(
+				const int faceIndex,
+				Ray &ray,
+				float &nearestT,
+				int &nearestFace,
+				Intersectable *instance
+				);
+	
+  
+  int
+  RayFaceIntersection(const int faceIndex,
+					const Ray &ray,
+					float &t,
+					const float nearestT
 					);
-	
-  int
-  CastRayToSelectedFaces(
-												 Ray &ray,
-												 const vector<int> &faces,
-												 Intersectable *instance
-												 );
-	
-  int
-  CastRayToFace(
-								const int faceIndex,
-								Ray &ray,
-								float &nearestT,
-								int &nearestFace,
-								Intersectable *instance
-								);
-	
-  
-  int
-  RayFaceIntersection(const int faceIndex,
-											const Ray &ray,
-											float &t,
-											const float nearestT
-											);
   
   Plane3 GetFacePlane(const int faceIndex);
@@ -177,21 +208,33 @@
 							   const int maxTries
 							   );
-  
+ 
+  /** Returns unique mesh id.
+  */
+  int GetId() const
+  {
+	  return mId;
+  }
+
   virtual ostream &Describe(ostream &s) {
 	return s<<"Mesh #vertices="<<(int)mVertices.size()<<" #faces="<<(int)mFaces.size();
   }
   
-  /** Creates a mesh from a axis aligned bounding box
+  /** Creates a mesh from a axis aligned bounding box.
+      The mesh is handled from the resource manager.
   */
   friend Mesh *CreateMeshFromBox(const AxisAlignedBox3 &box);
+
+ 
+protected:
+
+  /// Unique id of this mesh.
+  int mId;
 };
 
 
 class MeshInstance : public Intersectable {
-protected:
-  Mesh *mMesh;
-  
+
 public:
-  MeshInstance(Mesh *mesh):Intersectable(), mMesh(mesh)
+  MeshInstance(Mesh *mesh):Intersectable(), mMesh(mesh), mMaterial(NULL)
   {
   }
@@ -238,24 +281,35 @@
 	}
 	
+	/** Sets the material. this overrides the material from 
+		the mesh itself.
+	*/
+	void SetMaterial(Material *mat);
+
+	/** Returns the material of this mesh instance.
+		if not defined, returns the material of the mesh itself.
+	*/
+	Material *GetMaterial() const;
+
+protected:
+
+	Mesh *mMesh;
+	/** This material overrides the mesh material;
+	*/
+	Material *mMaterial;  
 };
 
 
+/** This mesh instance includes a world transform. Use this
+	class if the same mesh should be instantiated on different places.
+*/
 class TransformedMeshInstance : public MeshInstance
 {
 public:
-  TransformedMeshInstance(Mesh *mesh):MeshInstance(mesh)
-  {
-    mWorldTransform = IdentityMatrix();
-  }
-  
-  virtual AxisAlignedBox3 GetBox() {
-    return Transform(mMesh->mBox,
-		     mWorldTransform);
-  }
-  
-  virtual int
-  CastRay(
-	  Ray &ray
-	  );
+  TransformedMeshInstance(Mesh *mesh);
+  
+  virtual AxisAlignedBox3 GetBox();
+   
+  
+  virtual int CastRay(Ray &ray);
 
   virtual int Type() const { return TRANSFORMED_MESH_INSTANCE; }
@@ -263,6 +317,20 @@
   int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);
 
-private:
-  Matrix4x4 mWorldTransform;
+  /** Transforms this mesh instance by m.
+  */
+  void ApplyWorldTransform(const Matrix4x4 &m);
+
+  /** Loads the transformation matrix into this mesh instance.
+  */
+  void LoadWorldTransform(const Matrix4x4 &m);
+
+  /** The transformation is returned in m.
+  */
+  void GetWorldTransform(Matrix4x4 &m);
+
+protected:
+
+	/// the transformation matrix    
+	Matrix4x4 mWorldTransform;
   
 };
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 997)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1001)
@@ -1168,4 +1168,10 @@
 				 "1000");
 
+  RegisterOption("RenderSampler.visibleThreshold",
+				 optInt,
+				 "render_sampler_visible_threshold=",
+				 "0");
+
+
    RegisterOption("RenderSampler.useOcclusionQueries",
 				 optBool,
@@ -1178,5 +1184,8 @@
 				 "100000");
   
-  RegisterOption("VssPreprocessor.testBeamSampling", optBool, "beam_sampling", "false");
+  RegisterOption("VssPreprocessor.testBeamSampling", 
+				optBool, 
+				"beam_sampling", 
+				"false");
 
   RegisterOption("VssPreprocessor.vssSamples",
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp	(revision 882)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp	(revision 1001)
@@ -647,5 +647,6 @@
 	for (int i = 0; i < limit; ++i)
 	{
-		Intersectable *object = objects[i];//*it;
+		Intersectable *object = objects[i];
+
 		Mesh *mesh = NULL;
 
@@ -658,5 +659,20 @@
 			mesh = dynamic_cast<ViewCell *>(object)->GetMesh();
 			break;
-			// TODO: handle transformed mesh instances
+		case Intersectable::TRANSFORMED_MESH_INSTANCE:
+			{
+				TransformedMeshInstance *mi = 
+					dynamic_cast<TransformedMeshInstance *>(object);
+
+				if (!mi->GetMesh())
+					break;
+
+				mesh = new Mesh(*mi->GetMesh());
+
+				Matrix4x4 m;
+				mi->GetWorldTransform(m);
+				mesh->ApplyTransformation(m);
+				
+				break;
+			}
 		default:
 			Debug << "intersectable type not supported" << endl;
@@ -667,10 +683,12 @@
 		{
 			if (addToBbox)
-			{
 				mBox.Include(object->GetBox()); // add to BSP tree aabb
-			}
-		
+				
 			AddMeshToPolygons(mesh, polys, mOutOfBoundsCell);
-		}
+
+			// cleanup
+			if (object->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE)
+				DEL_PTR(mesh);
+		}	
 	}
 
@@ -2851,5 +2869,4 @@
 	mPolys.reserve(rhs.mPolys.size());
 	mPlanes.reserve(rhs.mPolys.size());
-
 
 	PolygonContainer::const_iterator it, it_end = rhs.mPolys.end();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/LogManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/LogManager.h	(revision 1001)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/LogManager.h	(revision 1001)
@@ -0,0 +1,52 @@
+#ifndef _LogManager_H__
+#define _LogManager_H__
+
+#include <vector>
+#include <fstream>
+#include <iostream>
+
+#include "Containers.h"
+
+
+namespace GtpVisibilityPreprocessor {
+
+
+/** Log manager controlling the debug output.
+	This class defines the pattern of singleton to assure that
+	there is always only one log manager.
+*/
+class LogManager {
+
+public:
+
+	/** Returns the resource manager as a singleton.
+	*/
+	static LogManager *GetSingleton();
+
+
+protected:
+
+	/** Default constructor. The constructor is protected
+		to have control over instantiation using the 
+		singleton pattern.
+	*/
+	LogManager();
+
+	~LogManager();
+  
+	void LogMessage(const std::string &str);
+
+protected:
+
+	std::ofstream mOutStream;
+
+private:
+
+	static LogManager *sLogManager;
+	
+};
+
+
+}
+
+#endif
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ResourceManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ResourceManager.cpp	(revision 1001)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ResourceManager.cpp	(revision 1001)
@@ -0,0 +1,109 @@
+#include "ResourceManager.h"
+#include "Mesh.h"
+
+namespace GtpVisibilityPreprocessor {
+
+ResourceManager *ResourceManager::sResourceManager = NULL;
+
+
+ResourceManager *ResourceManager::GetSingleton()
+{Debug << "here1" << endl;
+	if (!sResourceManager)
+	{
+		Debug << "here888" << endl;
+		sResourceManager = new ResourceManager();
+	}
+
+  Debug << "here999" << endl;
+	return sResourceManager;
+}
+
+
+ResourceManager::ResourceManager()
+{
+}
+
+ResourceManager::~ResourceManager()
+{
+	cout << "here839 " << mMeshes.size() << endl;
+
+	MeshMap::iterator mit, mit_end = mMeshes.end();
+	for (mit = mMeshes.begin(); mit != mMeshes.end(); ++ mit)
+	{
+		cout << "mesh: " << (*mit).first << " " << (*mit).second << endl;
+		DEL_PTR((*mit).second);
+	}
+}
+
+void ResourceManager::DelSingleton()
+{
+	cout << "here11" << endl;
+	DEL_PTR(sResourceManager);
+}
+
+/*Mesh *ResourceManager::CreateMesh(const string meshName)
+{
+	Mesh *mesh = new Mesh();
+	mMeshes[meshName] = mesh;
+	
+	return mesh;
+}*/
+
+
+Mesh *ResourceManager::GetOrCreateMesh(const string meshName)
+{Debug << "here2" << endl;
+	Mesh *mesh = NULL;
+
+	if (!(mesh = FindMesh(meshName.c_str())))
+	{
+		mesh = new Mesh();
+		mMeshes[meshName.c_str()] = mesh;
+	}
+
+	return mesh;
+}
+
+
+/*
+bool ResourceManager::InsertMesh(Mesh *mesh, const string meshName)
+{
+	Mesh *mesh = NULL;
+
+	if (FindMesh(meshName.c_str()))
+		return false;
+
+	mMeshes[meshName.c_str()] = mesh;
+	
+	return mesh;
+}
+*/
+
+Mesh *ResourceManager::FindMesh(const string &name) const
+{Debug << "here3" << endl;
+	MeshMap::const_iterator mit = mMeshes.find(name.c_str());
+
+	if (mit != mMeshes.end()) 
+	{
+		return (*mit).second;
+	}
+
+	return NULL;
+}
+
+
+bool ResourceManager::DestroyMesh(const string &meshName)
+{
+	if (!FindMesh(meshName))
+	{
+		Mesh *mesh = mMeshes[meshName.c_str()];
+
+		mMeshes.erase(meshName.c_str());
+		DEL_PTR(mesh);
+
+		return true;
+	}
+
+	return false;
+}
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 997)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1001)
@@ -20,5 +20,5 @@
 
 
-// HACK
+// HACK: Artificially modify scene to watch rendercost changes
 static void AddGeometry(SceneGraph *scene)
 {
Index: GTP/trunk/Lib/Vis/Preprocessing/src/glInterface.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/glInterface.h	(revision 1001)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/glInterface.h	(revision 1001)
@@ -0,0 +1,27 @@
+//Copyright and Disclaimer:
+//This code is copyright Vienna University of Technology, 2004.
+
+#ifndef NO_PRAGMA_ONCE
+#pragma once
+#endif
+
+#ifndef GLINTERFACE_H
+#define GLINTERFACE_H
+
+
+//includes an openGL extension header file
+//http://glew.sourceforge.net/
+#include "GL/glew.h"
+//includes the glut header file
+#include "GL/glut.h"
+
+//includes windows specific stuff
+#ifdef _WIN32
+	#include "GL/wglew.h"
+#else
+//include linux specific stuff
+	#include "GL/glxew.h"
+#endif	
+
+
+#endif // GLINTERFACE_H
Index: GTP/trunk/Lib/Vis/Preprocessing/src/OcclusionQuery.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/OcclusionQuery.h	(revision 1001)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/OcclusionQuery.h	(revision 1001)
@@ -0,0 +1,39 @@
+#ifndef _OcclusionQuery_H__
+#define _OcclusionQuery_H__
+
+#include <vector>
+
+
+namespace GtpVisibilityPreprocessor { 
+
+/** This class is an implementation for occlusion queries.
+	@remark the class encapsulates occlusion query calls.
+*/
+class OcclusionQuery
+{
+public:
+	
+	OcclusionQuery();
+
+	virtual ~OcclusionQuery();
+
+	virtual bool ResultAvailable() const;
+	virtual unsigned int GetQueryResult() const;
+	virtual void BeginQuery();
+	virtual void EndQuery();
+	
+	static void GenQueries(std::vector<OcclusionQuery *> &queries, const int numQueries);
+
+	unsigned int GetQueryId() const;
+
+
+protected:
+
+	OcclusionQuery(const unsigned int idx);
+	static bool sUseArbQueries;
+
+	unsigned int mId;
+};
+
+} // namespace 
+#endif // OcclusionQuery_H
Index: GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.h	(revision 863)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.h	(revision 1001)
@@ -85,4 +85,7 @@
 
   virtual void
+  ExportTransformedMeshInstance(TransformedMeshInstance *mi);
+
+  virtual void
   ExportIntersectable(Intersectable *object);
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp	(revision 1000)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp	(revision 1001)
@@ -19,8 +19,14 @@
 	int histoMaxVal = 0;
 	int histoIntervals = 0;
-	
+	int threshold;
+	bool useOcclusionQueries;
+
     environment->GetIntValue("Preprocessor.histogram.maxValue", histoMaxVal);
 	environment->GetIntValue("Preprocessor.histogram.intervals", histoIntervals);
+	environment->GetIntValue("RenderSampler.visibleThreshold", threshold);
+	environment->GetBoolValue("RenderSampler.useOcclusionQueries", useOcclusionQueries);
 
+	Debug << "************* render sampler ****************" << endl;
+	Debug << "threshold: " << threshold << endl;
 	const int intervals = histoIntervals;
 
@@ -28,8 +34,8 @@
 
 	vector<RenderCostSample> samples;
-  
+  	while (1){cout <<"q";}
 	if (renderer)
 	{
-		renderer->SampleRenderCost(mSamples, samples);
+		renderer->SampleRenderCost(mSamples, samples, useOcclusionQueries, threshold);
 	}
 
@@ -45,4 +51,5 @@
 	vector<int> histogram(intervals);
   
+
 	// initialise histogram
 	for (int i = 0; i < intervals; ++ i)
Index: GTP/trunk/Lib/Vis/Preprocessing/src/FromPointVisibilityTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/FromPointVisibilityTree.cpp	(revision 970)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/FromPointVisibilityTree.cpp	(revision 1001)
@@ -288,5 +288,5 @@
 	for (int i = 0; i < limit; ++i)
 	{
-		Intersectable *object = objects[i];//*it;
+		Intersectable *object = objects[i];
 		Mesh *mesh = NULL;
 
@@ -299,5 +299,20 @@
 			mesh = dynamic_cast<ViewCell *>(object)->GetMesh();
 			break;
-			// TODO: handle transformed mesh instances
+		case Intersectable::TRANSFORMED_MESH_INSTANCE:
+			{          
+				TransformedMeshInstance *mi = 
+					dynamic_cast<TransformedMeshInstance *>(object);
+
+				if (!mi->GetMesh())
+					break;
+
+				mesh = new Mesh(*mi->GetMesh());
+
+				Matrix4x4 m;
+				mi->GetWorldTransform(m);
+				mesh->ApplyTransformation(m);
+
+				break;
+			}
 		default:
 			Debug << "intersectable type not supported" << endl;
@@ -309,4 +324,8 @@
 			mBox.Include(object->GetBox()); // add to BSP tree aabb
 			AddMeshToPolygons(mesh, polys, NULL);
+
+			// cleanup
+			if (object->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE)
+				DEL_PTR(mesh);
 		}
 	}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GzBinFileInputStream.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GzBinFileInputStream.cpp	(revision 975)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GzBinFileInputStream.cpp	(revision 1001)
@@ -85,4 +85,6 @@
 	//mStream.open(myFileName, ios::binary);
 	mStream.open(myFileName);
+
+	delete [] myFileName;
 }
 
@@ -144,5 +146,5 @@
 	unsigned int result = mStream.gcount();
 	mCurrentPos = mStream.tellg();
-	//GtpVisibilityPreprocessor::Debug << "here1001 " << maxToRead << " haha " << toFill << " " << result << endl;
+	//GtpVisibilityPreprocessor::Debug << "stream: " << maxToRead << " " << toFill << " " << result << endl;
 
 	return result;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 997)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1001)
@@ -15,4 +15,5 @@
 #include "PreprocessorThread.h"
 #include "RenderSampler.h"
+#include "ResourceManager.h"
 
 #include <QApplication>
@@ -143,12 +144,17 @@
   
 
+  int returnCode = 0;
+
   if (app)
-	return app->exec();
+	 returnCode = app->exec();
 
-  // clean up
+   // clean up
   DEL_PTR(p);
   DEL_PTR(environment);
+  MeshManager::DelSingleton();
+  MaterialManager::DelSingleton();
 
-  return 0;
+
+  return returnCode;
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ResourceManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ResourceManager.h	(revision 1001)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ResourceManager.h	(revision 1001)
@@ -0,0 +1,156 @@
+#ifndef _ResourceManager_H__
+#define _ResourceManager_H__
+
+#include <vector>
+#include <string>
+
+//#include "Containers.h"
+#include "Mesh.h"
+#include "Material.h"
+
+namespace GtpVisibilityPreprocessor {
+
+
+/** Resource manager controlling loading and destroying of resources.
+	
+	@note Resources must be created using the manager to assure that
+	they are destroyed properly, otherwise the developer has the
+	responsibility to destroy them himself.
+
+	@note This class defines the pattern of singleton to assure that
+	there is always only one resource manager.
+*/
+template <typename T> class ResourceManager
+{
+
+public:
+
+	/** Returns the resource manager as a singleton.
+	*/
+	static ResourceManager<T> *GetSingleton()
+	{
+		if (!sResourceManager)
+		{
+			sResourceManager = new ResourceManager();
+		}
+
+		return sResourceManager;
+	}
+
+	static void DelSingleton()
+	{
+		DEL_PTR(sResourceManager);
+	}
+
+	/** Creates new entry with a unique id
+	*/
+	T *CreateResource()
+	{
+		const int id = CreateUniqueId();
+
+		T *resource = new T(id);
+		mEntries[id] = resource;
+		
+		return resource;
+	}
+
+	
+	/** Searches for the mesh with the given name.
+		@returns mesh or NULL if mesh was not found.
+	*/
+	T *FindEntry(const int id) const
+	{
+		std::map<int, T *>::const_iterator mit = mEntries.find(id);
+
+		if (mit != mEntries.end()) 
+		{
+			return (*mit).second;
+		}
+
+		return NULL;
+	}
+
+	/** Destroys mesh with the given name.
+		@returns true if the mesh was found, false if not
+	*/
+	bool DestroyEntry(const int id)
+	{	
+		if (!FindEntry(id))
+		{
+			T *resource = mEntries[id];
+
+			mEntries.erase(id);
+			DEL_PTR(resource);
+
+			return true;
+		}
+		
+		return false;
+	}
+	
+
+	/** Returns size of resource container.
+	*/
+	const int GetSize()
+	{
+		return (int)mEntries.size();
+	}
+
+protected:
+
+	/** Default constructor. The constructor is protected
+		to have control over instantiation using the 
+		singleton pattern.
+	*/
+	ResourceManager<T>()
+	{}
+
+	/** Release resources.
+	*/
+	~ResourceManager<T>()
+	{
+		std::map<int, T *>::iterator mit, mit_end = mEntries.end();
+
+		for (mit = mEntries.begin(); mit != mEntries.end(); ++ mit)
+		{
+			cout << "mesh: " << (*mit).first << " " << (*mit).second << endl;
+			DEL_PTR((*mit).second);
+		}
+	}
+  
+	/** Copy constructor.
+	*/
+    ResourceManager<T>(const ResourceManager<T>& source)
+    {
+    }
+
+	 /** Helper function returning unique id for resource.
+	 */
+	static int CreateUniqueId()
+	{
+		return sCurrentId ++;
+	}
+
+protected:
+
+	/// the resource container
+	std::map<int, T *> mEntries;
+
+private:
+
+	static ResourceManager<T> *sResourceManager;
+	static int sCurrentId;
+};
+
+// only instance of the resource manager
+template <typename T> ResourceManager<T> *ResourceManager<T>::sResourceManager = NULL;
+template <typename T> int ResourceManager<T>::sCurrentId = 0;
+
+/// This type is responsible for creation and disposal the meshes
+typedef ResourceManager<Mesh> MeshManager;
+/// This type is esponsible for creation and disposal of the materials.
+typedef ResourceManager<Material> MaterialManager;
+
+}
+
+#endif
Index: GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp	(revision 863)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp	(revision 1001)
@@ -198,16 +198,19 @@
 X3dExporter::ExportIntersectable(Intersectable *object)
 {
-  switch (object->Type()) {
-  case Intersectable::MESH_INSTANCE:
-  case Intersectable::TRANSFORMED_MESH_INSTANCE:
-    ExportMeshInstance((MeshInstance *)object);
-	break;
-  case Intersectable::VIEW_CELL:
-	ExportViewCell((ViewCell *)object);
-    break;
-  default:
-    cerr<<"Sorry the export for object not yet defined"<<endl;
-    break;
-  }
+	switch (object->Type()) 
+	{
+	case Intersectable::MESH_INSTANCE:
+		ExportMeshInstance((MeshInstance *)object);
+		break;
+	case Intersectable::TRANSFORMED_MESH_INSTANCE:
+		ExportTransformedMeshInstance(dynamic_cast<TransformedMeshInstance *>(object));
+		break;
+	case Intersectable::VIEW_CELL:
+		ExportViewCell((ViewCell *)object);
+		break;
+	default:
+		cerr << "Sorry the export for object not yet defined" << endl;
+		break;
+	}
 }
 
@@ -223,4 +226,17 @@
 
 
+void
+X3dExporter::ExportTransformedMeshInstance(TransformedMeshInstance *mi)
+{
+	Mesh mesh(*mi->GetMesh());
+
+	Matrix4x4 m;
+	mi->GetWorldTransform(m);
+	mesh.ApplyTransformation(m);
+
+	ExportMesh(&mesh);
+}
+
+
 void 
 X3dExporter::ExportViewCells(const ViewCellContainer &viewCells)
@@ -231,4 +247,5 @@
 		ExportViewCell(*it);
 }
+
 
 void 
@@ -321,4 +338,5 @@
       b = RandomValue(0.5, 1.0);
     }
+    
   stream<<"<Material diffuseColor=\""<<r<<" "<<g<<" "<<b<<
     "\" specularColor=\"0.0 0.0 0.0\"/>"<<endl;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 997)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 1001)
@@ -2,6 +2,8 @@
 #define __GLRENDERER_H
 
+//#include "glInterface.h"
 #include <QtOpenGL>
 #include <QWaitCondition>
+
 //#include <QGLPixelBuffer>
 
@@ -26,4 +28,6 @@
 class GlRendererBuffer;
 class BeamSampleStatistics;
+class OcclusionQuery;
+class TransformedMeshInstance;
 
 struct VssRayContainer;
@@ -107,5 +111,5 @@
   QWaitCondition mRenderingFinished;
   
-  vector<unsigned int> mOcclusionQueries;
+  vector<OcclusionQuery *> mOcclusionQueries;
   
   GlRenderer(SceneGraph *sceneGraph,
@@ -120,4 +124,5 @@
   void RenderViewCell(ViewCell *vc);
   void RenderMeshInstance(MeshInstance *mi);
+  void RenderTransformedMeshInstance(TransformedMeshInstance *mi);
   void RenderMesh(Mesh *m);
   void SetupMaterial(Material *m);
@@ -157,14 +162,25 @@
 
 
-  void
-  EvalRenderCostSample(
-					   RenderCostSample &sample
-					   );
-
-  void
-  SampleRenderCost(
-				   const int n,
-				   vector<RenderCostSample> &samples
-				   );
+	/** Evaluates render cost of a point sample.
+		@param sample the render cost sample to be evaluated
+		@param useOcclusionQueries if occlusion queries should be used or item buffer
+		@param threshold number of pixels / samples from where an object is considered visible.
+	*/
+	void EvalRenderCostSample(RenderCostSample &sample,
+							  const bool useOcclusionQueries,
+							  const int threshold);
+
+	/** Evaluates render cost of a number of point samples. The point samples
+		are distributed uniformly over the defined view space.
+
+		@param numSamples the number of point samples taken
+		@param samples stores the taken point samples in a container
+		@param useOcclusionQueries if occlusion queries should be used or item buffer
+		@param threshold number of pixels / samples from where an object is considered visible.
+	*/
+	void SampleRenderCost(const int numSamples, 
+						  vector<RenderCostSample> &samples,
+						  const bool useOcclusionQueries,
+						  const int threshold = 0);
 
 
@@ -234,5 +250,9 @@
 									 Intersectable *sourceObject);
 
+	/** Evaluates query for one direction using item buffer.
+	*/
 	void EvalQueryWithItemBuffer();
+	/** Evaluates query for one direction using occlusion queries.
+	*/
 	void EvalQueryWithOcclusionQueries();
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Containers.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Containers.h	(revision 863)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Containers.h	(revision 1001)
@@ -38,11 +38,7 @@
 typedef vector<ViewCell *> ViewCellContainer;
 
-/** Container for ViewCell pointers primarily for the use within the kDTree and
-    BSP hierarchies */
-//typedef vector<MeshInstance *> MeshInstanceContainer;
-
 /** Container for HierarchyNodes pointers primarily for the use within the kDTree and
-    BSP hierarchies */
-
+    BSP hierarchies 
+	*/
 typedef vector<HierarchyNode *> NodeContainer;
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.h	(revision 860)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.h	(revision 1001)
@@ -85,4 +85,7 @@
 
   virtual void
+  ExportTransformedMeshInstance(TransformedMeshInstance *mi);
+
+  virtual void
   ExportIntersectable(Intersectable *object);
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GL/glew.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GL/glew.h	(revision 498)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GL/glew.h	(revision 1001)
@@ -1,6 +1,6 @@
 /*
 ** The OpenGL Extension Wrangler Library
-** Copyright (C) 2004, 2003, 2002, Milan Ikits <milan ikits[at]ieee org>
-** Copyright (C) 2004, 2003, 2002, Marcelo E. Magallon <mmagallo[at]debian org>
+** Copyright (C) 2002-2006, Milan Ikits <milan ikits[]ieee org>
+** Copyright (C) 2002-2006, Marcelo E. Magallon <mmagallo[]debian org>
 ** Copyright (C) 2002, Lev Povalahev
 ** All rights reserved.
@@ -78,7 +78,6 @@
 #define __GLEXT_H_
 #define __gl_ATI_h_
-#define __GLX_glx_h__
-
-#if defined(_WIN32)
+
+#if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
 
 /*
@@ -92,5 +91,5 @@
 #  if defined(__CYGWIN__) || defined(__MINGW32__)
 #    define APIENTRY __stdcall
-#  elif (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED)
+#  elif (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) || defined(__BORLANDC__)
 #    define APIENTRY __stdcall
 #  else
@@ -120,5 +119,5 @@
 #endif
 /* <ctype.h> */
-#if defined(_MSC_VER) && !defined(_WCHAR_T_DEFINED)
+#if (defined(_MSC_VER) || defined(__BORLANDC__)) && !defined(_WCHAR_T_DEFINED)
 typedef unsigned short wchar_t;
 #  define _WCHAR_T_DEFINED
@@ -204,14 +203,22 @@
 #define GL_VERSION_1_1 1
 
+#if defined(__APPLE__)
+typedef unsigned long GLenum;
+typedef unsigned long GLbitfield;
+typedef unsigned long GLuint;
+typedef long GLint;
+typedef long GLsizei;
+#else
 typedef unsigned int GLenum;
+typedef unsigned int GLbitfield;
+typedef unsigned int GLuint;
+typedef int GLint;
+typedef int GLsizei;
+#endif
 typedef unsigned char GLboolean;
-typedef unsigned int GLbitfield;
 typedef signed char GLbyte;
 typedef short GLshort;
-typedef int GLint;
-typedef int GLsizei;
 typedef unsigned char GLubyte;
 typedef unsigned short GLushort;
-typedef unsigned int GLuint;
 typedef float GLfloat;
 typedef float GLclampf;
@@ -1580,5 +1587,5 @@
 typedef void (GLAPIENTRY * PFNGLGETQUERYOBJECTIVPROC) (GLuint id, GLenum pname, GLint* params);
 typedef void (GLAPIENTRY * PFNGLGETQUERYOBJECTUIVPROC) (GLuint id, GLenum pname, GLuint* params);
-typedef void (GLAPIENTRY * PFNGLGETQUERYIVPROC) (GLenum target, GLenum pname, GLint params);
+typedef void (GLAPIENTRY * PFNGLGETQUERYIVPROC) (GLenum target, GLenum pname, GLint* params);
 typedef GLboolean (GLAPIENTRY * PFNGLISBUFFERPROC) (GLuint buffer);
 typedef GLboolean (GLAPIENTRY * PFNGLISQUERYPROC) (GLuint id);
@@ -1615,4 +1622,279 @@
 #define GL_VERSION_2_0 1
 
+#define GL_BLEND_EQUATION_RGB GL_BLEND_EQUATION
+#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622
+#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623
+#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624
+#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625
+#define GL_CURRENT_VERTEX_ATTRIB 0x8626
+#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642
+#define GL_VERTEX_PROGRAM_TWO_SIDE 0x8643
+#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645
+#define GL_STENCIL_BACK_FUNC 0x8800
+#define GL_STENCIL_BACK_FAIL 0x8801
+#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802
+#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803
+#define GL_MAX_DRAW_BUFFERS 0x8824
+#define GL_DRAW_BUFFER0 0x8825
+#define GL_DRAW_BUFFER1 0x8826
+#define GL_DRAW_BUFFER2 0x8827
+#define GL_DRAW_BUFFER3 0x8828
+#define GL_DRAW_BUFFER4 0x8829
+#define GL_DRAW_BUFFER5 0x882A
+#define GL_DRAW_BUFFER6 0x882B
+#define GL_DRAW_BUFFER7 0x882C
+#define GL_DRAW_BUFFER8 0x882D
+#define GL_DRAW_BUFFER9 0x882E
+#define GL_DRAW_BUFFER10 0x882F
+#define GL_DRAW_BUFFER11 0x8830
+#define GL_DRAW_BUFFER12 0x8831
+#define GL_DRAW_BUFFER13 0x8832
+#define GL_DRAW_BUFFER14 0x8833
+#define GL_DRAW_BUFFER15 0x8834
+#define GL_BLEND_EQUATION_ALPHA 0x883D
+#define GL_POINT_SPRITE 0x8861
+#define GL_COORD_REPLACE 0x8862
+#define GL_MAX_VERTEX_ATTRIBS 0x8869
+#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A
+#define GL_MAX_TEXTURE_COORDS 0x8871
+#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872
+#define GL_FRAGMENT_SHADER 0x8B30
+#define GL_VERTEX_SHADER 0x8B31
+#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49
+#define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A
+#define GL_MAX_VARYING_FLOATS 0x8B4B
+#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C
+#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D
+#define GL_SHADER_TYPE 0x8B4F
+#define GL_FLOAT_VEC2 0x8B50
+#define GL_FLOAT_VEC3 0x8B51
+#define GL_FLOAT_VEC4 0x8B52
+#define GL_INT_VEC2 0x8B53
+#define GL_INT_VEC3 0x8B54
+#define GL_INT_VEC4 0x8B55
+#define GL_BOOL 0x8B56
+#define GL_BOOL_VEC2 0x8B57
+#define GL_BOOL_VEC3 0x8B58
+#define GL_BOOL_VEC4 0x8B59
+#define GL_FLOAT_MAT2 0x8B5A
+#define GL_FLOAT_MAT3 0x8B5B
+#define GL_FLOAT_MAT4 0x8B5C
+#define GL_SAMPLER_1D 0x8B5D
+#define GL_SAMPLER_2D 0x8B5E
+#define GL_SAMPLER_3D 0x8B5F
+#define GL_SAMPLER_CUBE 0x8B60
+#define GL_SAMPLER_1D_SHADOW 0x8B61
+#define GL_SAMPLER_2D_SHADOW 0x8B62
+#define GL_DELETE_STATUS 0x8B80
+#define GL_COMPILE_STATUS 0x8B81
+#define GL_LINK_STATUS 0x8B82
+#define GL_VALIDATE_STATUS 0x8B83
+#define GL_INFO_LOG_LENGTH 0x8B84
+#define GL_ATTACHED_SHADERS 0x8B85
+#define GL_ACTIVE_UNIFORMS 0x8B86
+#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87
+#define GL_SHADER_SOURCE_LENGTH 0x8B88
+#define GL_ACTIVE_ATTRIBUTES 0x8B89
+#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A
+#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT 0x8B8B
+#define GL_SHADING_LANGUAGE_VERSION 0x8B8C
+#define GL_CURRENT_PROGRAM 0x8B8D
+#define GL_POINT_SPRITE_COORD_ORIGIN 0x8CA0
+#define GL_LOWER_LEFT 0x8CA1
+#define GL_UPPER_LEFT 0x8CA2
+#define GL_STENCIL_BACK_REF 0x8CA3
+#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4
+#define GL_STENCIL_BACK_WRITEMASK 0x8CA5
+
+typedef char GLchar;
+
+typedef void (GLAPIENTRY * PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader);
+typedef void (GLAPIENTRY * PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar* name);
+typedef void (GLAPIENTRY * PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum, GLenum);
+typedef void (GLAPIENTRY * PFNGLCOMPILESHADERPROC) (GLuint shader);
+typedef GLuint (GLAPIENTRY * PFNGLCREATEPROGRAMPROC) (void);
+typedef GLuint (GLAPIENTRY * PFNGLCREATESHADERPROC) (GLenum type);
+typedef void (GLAPIENTRY * PFNGLDELETEPROGRAMPROC) (GLuint program);
+typedef void (GLAPIENTRY * PFNGLDELETESHADERPROC) (GLuint shader);
+typedef void (GLAPIENTRY * PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader);
+typedef void (GLAPIENTRY * PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint);
+typedef void (GLAPIENTRY * PFNGLDRAWBUFFERSPROC) (GLsizei n, const GLenum* bufs);
+typedef void (GLAPIENTRY * PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint);
+typedef void (GLAPIENTRY * PFNGLGETACTIVEATTRIBPROC) (GLuint program, GLuint index, GLsizei maxLength, GLsizei* length, GLint* size, GLenum* type, GLchar* name);
+typedef void (GLAPIENTRY * PFNGLGETACTIVEUNIFORMPROC) (GLuint program, GLuint index, GLsizei maxLength, GLsizei* length, GLint* size, GLenum* type, GLchar* name);
+typedef void (GLAPIENTRY * PFNGLGETATTACHEDSHADERSPROC) (GLuint program, GLsizei maxCount, GLsizei* count, GLuint* shaders);
+typedef GLint (GLAPIENTRY * PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar* name);
+typedef void (GLAPIENTRY * PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei* length, GLchar* infoLog);
+typedef void (GLAPIENTRY * PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint* param);
+typedef void (GLAPIENTRY * PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* infoLog);
+typedef void (GLAPIENTRY * PFNGLGETSHADERSOURCEPROC) (GLint obj, GLsizei maxLength, GLsizei* length, GLchar* source);
+typedef void (GLAPIENTRY * PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint* param);
+typedef GLint (GLAPIENTRY * PFNGLGETUNIFORMLOCATIONPROC) (GLint programObj, const GLchar* name);
+typedef void (GLAPIENTRY * PFNGLGETUNIFORMFVPROC) (GLuint program, GLint location, GLfloat* params);
+typedef void (GLAPIENTRY * PFNGLGETUNIFORMIVPROC) (GLuint program, GLint location, GLint* params);
+typedef void (GLAPIENTRY * PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint, GLenum, GLvoid*);
+typedef void (GLAPIENTRY * PFNGLGETVERTEXATTRIBDVPROC) (GLuint, GLenum, GLdouble*);
+typedef void (GLAPIENTRY * PFNGLGETVERTEXATTRIBFVPROC) (GLuint, GLenum, GLfloat*);
+typedef void (GLAPIENTRY * PFNGLGETVERTEXATTRIBIVPROC) (GLuint, GLenum, GLint*);
+typedef GLboolean (GLAPIENTRY * PFNGLISPROGRAMPROC) (GLuint program);
+typedef GLboolean (GLAPIENTRY * PFNGLISSHADERPROC) (GLuint shader);
+typedef void (GLAPIENTRY * PFNGLLINKPROGRAMPROC) (GLuint program);
+typedef void (GLAPIENTRY * PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar** strings, const GLint* lengths);
+typedef void (GLAPIENTRY * PFNGLSTENCILFUNCSEPARATEPROC) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask);
+typedef void (GLAPIENTRY * PFNGLSTENCILMASKSEPARATEPROC) (GLenum, GLuint);
+typedef void (GLAPIENTRY * PFNGLSTENCILOPSEPARATEPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
+typedef void (GLAPIENTRY * PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0);
+typedef void (GLAPIENTRY * PFNGLUNIFORM1FVPROC) (GLint location, GLsizei count, const GLfloat* value);
+typedef void (GLAPIENTRY * PFNGLUNIFORM1IPROC) (GLint location, GLint v0);
+typedef void (GLAPIENTRY * PFNGLUNIFORM1IVPROC) (GLint location, GLsizei count, const GLint* value);
+typedef void (GLAPIENTRY * PFNGLUNIFORM2FPROC) (GLint location, GLfloat v0, GLfloat v1);
+typedef void (GLAPIENTRY * PFNGLUNIFORM2FVPROC) (GLint location, GLsizei count, const GLfloat* value);
+typedef void (GLAPIENTRY * PFNGLUNIFORM2IPROC) (GLint location, GLint v0, GLint v1);
+typedef void (GLAPIENTRY * PFNGLUNIFORM2IVPROC) (GLint location, GLsizei count, const GLint* value);
+typedef void (GLAPIENTRY * PFNGLUNIFORM3FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+typedef void (GLAPIENTRY * PFNGLUNIFORM3FVPROC) (GLint location, GLsizei count, const GLfloat* value);
+typedef void (GLAPIENTRY * PFNGLUNIFORM3IPROC) (GLint location, GLint v0, GLint v1, GLint v2);
+typedef void (GLAPIENTRY * PFNGLUNIFORM3IVPROC) (GLint location, GLsizei count, const GLint* value);
+typedef void (GLAPIENTRY * PFNGLUNIFORM4FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+typedef void (GLAPIENTRY * PFNGLUNIFORM4FVPROC) (GLint location, GLsizei count, const GLfloat* value);
+typedef void (GLAPIENTRY * PFNGLUNIFORM4IPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+typedef void (GLAPIENTRY * PFNGLUNIFORM4IVPROC) (GLint location, GLsizei count, const GLint* value);
+typedef void (GLAPIENTRY * PFNGLUNIFORMMATRIX2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
+typedef void (GLAPIENTRY * PFNGLUNIFORMMATRIX3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
+typedef void (GLAPIENTRY * PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
+typedef void (GLAPIENTRY * PFNGLUSEPROGRAMPROC) (GLuint program);
+typedef void (GLAPIENTRY * PFNGLVALIDATEPROGRAMPROC) (GLuint program);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB1DPROC) (GLuint index, GLdouble x);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB1DVPROC) (GLuint index, const GLdouble* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB1FPROC) (GLuint index, GLfloat x);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB1FVPROC) (GLuint index, const GLfloat* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB1SPROC) (GLuint index, GLshort x);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB1SVPROC) (GLuint index, const GLshort* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB2DPROC) (GLuint index, GLdouble x, GLdouble y);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB2DVPROC) (GLuint index, const GLdouble* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB2FPROC) (GLuint index, GLfloat x, GLfloat y);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB2FVPROC) (GLuint index, const GLfloat* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB2SPROC) (GLuint index, GLshort x, GLshort y);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB2SVPROC) (GLuint index, const GLshort* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB3DVPROC) (GLuint index, const GLdouble* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB3FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB3FVPROC) (GLuint index, const GLfloat* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB3SPROC) (GLuint index, GLshort x, GLshort y, GLshort z);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB3SVPROC) (GLuint index, const GLshort* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4NBVPROC) (GLuint index, const GLbyte* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4NIVPROC) (GLuint index, const GLint* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4NSVPROC) (GLuint index, const GLshort* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4NUBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4NUBVPROC) (GLuint index, const GLubyte* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4NUIVPROC) (GLuint index, const GLuint* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4NUSVPROC) (GLuint index, const GLushort* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4BVPROC) (GLuint index, const GLbyte* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4DVPROC) (GLuint index, const GLdouble* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4FVPROC) (GLuint index, const GLfloat* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4IVPROC) (GLuint index, const GLint* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4SPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4SVPROC) (GLuint index, const GLshort* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4UBVPROC) (GLuint index, const GLubyte* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4UIVPROC) (GLuint index, const GLuint* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4USVPROC) (GLuint index, const GLushort* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer);
+
+#define glAttachShader GLEW_GET_FUN(__glewAttachShader)
+#define glBindAttribLocation GLEW_GET_FUN(__glewBindAttribLocation)
+#define glBlendEquationSeparate GLEW_GET_FUN(__glewBlendEquationSeparate)
+#define glCompileShader GLEW_GET_FUN(__glewCompileShader)
+#define glCreateProgram GLEW_GET_FUN(__glewCreateProgram)
+#define glCreateShader GLEW_GET_FUN(__glewCreateShader)
+#define glDeleteProgram GLEW_GET_FUN(__glewDeleteProgram)
+#define glDeleteShader GLEW_GET_FUN(__glewDeleteShader)
+#define glDetachShader GLEW_GET_FUN(__glewDetachShader)
+#define glDisableVertexAttribArray GLEW_GET_FUN(__glewDisableVertexAttribArray)
+#define glDrawBuffers GLEW_GET_FUN(__glewDrawBuffers)
+#define glEnableVertexAttribArray GLEW_GET_FUN(__glewEnableVertexAttribArray)
+#define glGetActiveAttrib GLEW_GET_FUN(__glewGetActiveAttrib)
+#define glGetActiveUniform GLEW_GET_FUN(__glewGetActiveUniform)
+#define glGetAttachedShaders GLEW_GET_FUN(__glewGetAttachedShaders)
+#define glGetAttribLocation GLEW_GET_FUN(__glewGetAttribLocation)
+#define glGetProgramInfoLog GLEW_GET_FUN(__glewGetProgramInfoLog)
+#define glGetProgramiv GLEW_GET_FUN(__glewGetProgramiv)
+#define glGetShaderInfoLog GLEW_GET_FUN(__glewGetShaderInfoLog)
+#define glGetShaderSource GLEW_GET_FUN(__glewGetShaderSource)
+#define glGetShaderiv GLEW_GET_FUN(__glewGetShaderiv)
+#define glGetUniformLocation GLEW_GET_FUN(__glewGetUniformLocation)
+#define glGetUniformfv GLEW_GET_FUN(__glewGetUniformfv)
+#define glGetUniformiv GLEW_GET_FUN(__glewGetUniformiv)
+#define glGetVertexAttribPointerv GLEW_GET_FUN(__glewGetVertexAttribPointerv)
+#define glGetVertexAttribdv GLEW_GET_FUN(__glewGetVertexAttribdv)
+#define glGetVertexAttribfv GLEW_GET_FUN(__glewGetVertexAttribfv)
+#define glGetVertexAttribiv GLEW_GET_FUN(__glewGetVertexAttribiv)
+#define glIsProgram GLEW_GET_FUN(__glewIsProgram)
+#define glIsShader GLEW_GET_FUN(__glewIsShader)
+#define glLinkProgram GLEW_GET_FUN(__glewLinkProgram)
+#define glShaderSource GLEW_GET_FUN(__glewShaderSource)
+#define glStencilFuncSeparate GLEW_GET_FUN(__glewStencilFuncSeparate)
+#define glStencilMaskSeparate GLEW_GET_FUN(__glewStencilMaskSeparate)
+#define glStencilOpSeparate GLEW_GET_FUN(__glewStencilOpSeparate)
+#define glUniform1f GLEW_GET_FUN(__glewUniform1f)
+#define glUniform1fv GLEW_GET_FUN(__glewUniform1fv)
+#define glUniform1i GLEW_GET_FUN(__glewUniform1i)
+#define glUniform1iv GLEW_GET_FUN(__glewUniform1iv)
+#define glUniform2f GLEW_GET_FUN(__glewUniform2f)
+#define glUniform2fv GLEW_GET_FUN(__glewUniform2fv)
+#define glUniform2i GLEW_GET_FUN(__glewUniform2i)
+#define glUniform2iv GLEW_GET_FUN(__glewUniform2iv)
+#define glUniform3f GLEW_GET_FUN(__glewUniform3f)
+#define glUniform3fv GLEW_GET_FUN(__glewUniform3fv)
+#define glUniform3i GLEW_GET_FUN(__glewUniform3i)
+#define glUniform3iv GLEW_GET_FUN(__glewUniform3iv)
+#define glUniform4f GLEW_GET_FUN(__glewUniform4f)
+#define glUniform4fv GLEW_GET_FUN(__glewUniform4fv)
+#define glUniform4i GLEW_GET_FUN(__glewUniform4i)
+#define glUniform4iv GLEW_GET_FUN(__glewUniform4iv)
+#define glUniformMatrix2fv GLEW_GET_FUN(__glewUniformMatrix2fv)
+#define glUniformMatrix3fv GLEW_GET_FUN(__glewUniformMatrix3fv)
+#define glUniformMatrix4fv GLEW_GET_FUN(__glewUniformMatrix4fv)
+#define glUseProgram GLEW_GET_FUN(__glewUseProgram)
+#define glValidateProgram GLEW_GET_FUN(__glewValidateProgram)
+#define glVertexAttrib1d GLEW_GET_FUN(__glewVertexAttrib1d)
+#define glVertexAttrib1dv GLEW_GET_FUN(__glewVertexAttrib1dv)
+#define glVertexAttrib1f GLEW_GET_FUN(__glewVertexAttrib1f)
+#define glVertexAttrib1fv GLEW_GET_FUN(__glewVertexAttrib1fv)
+#define glVertexAttrib1s GLEW_GET_FUN(__glewVertexAttrib1s)
+#define glVertexAttrib1sv GLEW_GET_FUN(__glewVertexAttrib1sv)
+#define glVertexAttrib2d GLEW_GET_FUN(__glewVertexAttrib2d)
+#define glVertexAttrib2dv GLEW_GET_FUN(__glewVertexAttrib2dv)
+#define glVertexAttrib2f GLEW_GET_FUN(__glewVertexAttrib2f)
+#define glVertexAttrib2fv GLEW_GET_FUN(__glewVertexAttrib2fv)
+#define glVertexAttrib2s GLEW_GET_FUN(__glewVertexAttrib2s)
+#define glVertexAttrib2sv GLEW_GET_FUN(__glewVertexAttrib2sv)
+#define glVertexAttrib3d GLEW_GET_FUN(__glewVertexAttrib3d)
+#define glVertexAttrib3dv GLEW_GET_FUN(__glewVertexAttrib3dv)
+#define glVertexAttrib3f GLEW_GET_FUN(__glewVertexAttrib3f)
+#define glVertexAttrib3fv GLEW_GET_FUN(__glewVertexAttrib3fv)
+#define glVertexAttrib3s GLEW_GET_FUN(__glewVertexAttrib3s)
+#define glVertexAttrib3sv GLEW_GET_FUN(__glewVertexAttrib3sv)
+#define glVertexAttrib4Nbv GLEW_GET_FUN(__glewVertexAttrib4Nbv)
+#define glVertexAttrib4Niv GLEW_GET_FUN(__glewVertexAttrib4Niv)
+#define glVertexAttrib4Nsv GLEW_GET_FUN(__glewVertexAttrib4Nsv)
+#define glVertexAttrib4Nub GLEW_GET_FUN(__glewVertexAttrib4Nub)
+#define glVertexAttrib4Nubv GLEW_GET_FUN(__glewVertexAttrib4Nubv)
+#define glVertexAttrib4Nuiv GLEW_GET_FUN(__glewVertexAttrib4Nuiv)
+#define glVertexAttrib4Nusv GLEW_GET_FUN(__glewVertexAttrib4Nusv)
+#define glVertexAttrib4bv GLEW_GET_FUN(__glewVertexAttrib4bv)
+#define glVertexAttrib4d GLEW_GET_FUN(__glewVertexAttrib4d)
+#define glVertexAttrib4dv GLEW_GET_FUN(__glewVertexAttrib4dv)
+#define glVertexAttrib4f GLEW_GET_FUN(__glewVertexAttrib4f)
+#define glVertexAttrib4fv GLEW_GET_FUN(__glewVertexAttrib4fv)
+#define glVertexAttrib4iv GLEW_GET_FUN(__glewVertexAttrib4iv)
+#define glVertexAttrib4s GLEW_GET_FUN(__glewVertexAttrib4s)
+#define glVertexAttrib4sv GLEW_GET_FUN(__glewVertexAttrib4sv)
+#define glVertexAttrib4ubv GLEW_GET_FUN(__glewVertexAttrib4ubv)
+#define glVertexAttrib4uiv GLEW_GET_FUN(__glewVertexAttrib4uiv)
+#define glVertexAttrib4usv GLEW_GET_FUN(__glewVertexAttrib4usv)
+#define glVertexAttribPointer GLEW_GET_FUN(__glewVertexAttribPointer)
+
 #define GLEW_VERSION_2_0 GLEW_GET_VAR(__GLEW_VERSION_2_0)
 
@@ -1747,4 +2029,15 @@
 
 #endif /* GL_APPLE_float_pixels */
+
+/* ------------------------- GL_APPLE_pixel_buffer ------------------------- */
+
+#ifndef GL_APPLE_pixel_buffer
+#define GL_APPLE_pixel_buffer 1
+
+#define GL_MIN_PBUFFER_VIEWPORT_DIMS_APPLE 0x8A10
+
+#define GLEW_APPLE_pixel_buffer GLEW_GET_VAR(__GLEW_APPLE_pixel_buffer)
+
+#endif /* GL_APPLE_pixel_buffer */
 
 /* ------------------------ GL_APPLE_specular_vector ----------------------- */
@@ -2330,4 +2623,18 @@
 #endif /* GL_ARB_occlusion_query */
 
+/* ----------------------- GL_ARB_pixel_buffer_object ---------------------- */
+
+#ifndef GL_ARB_pixel_buffer_object
+#define GL_ARB_pixel_buffer_object 1
+
+#define GL_PIXEL_PACK_BUFFER_ARB 0x88EB
+#define GL_PIXEL_UNPACK_BUFFER_ARB 0x88EC
+#define GL_PIXEL_PACK_BUFFER_BINDING_ARB 0x88ED
+#define GL_PIXEL_UNPACK_BUFFER_BINDING_ARB 0x88EF
+
+#define GLEW_ARB_pixel_buffer_object GLEW_GET_VAR(__GLEW_ARB_pixel_buffer_object)
+
+#endif /* GL_ARB_pixel_buffer_object */
+
 /* ------------------------ GL_ARB_point_parameters ------------------------ */
 
@@ -2403,5 +2710,5 @@
 
 typedef char GLcharARB;
-typedef int GLhandleARB;
+typedef unsigned int GLhandleARB;
 
 typedef void (GLAPIENTRY * PFNGLATTACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj);
@@ -2715,4 +3022,6 @@
 #define GL_PROXY_TEXTURE_RECTANGLE_ARB 0x84F7
 #define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8
+#define GL_SAMPLER_2D_RECT_ARB 0x8B63
+#define GL_SAMPLER_2D_RECT_SHADOW_ARB 0x8B64
 
 #define GLEW_ARB_texture_rectangle GLEW_GET_VAR(__GLEW_ARB_texture_rectangle)
@@ -2729,4 +3038,14 @@
 #define GL_TRANSPOSE_TEXTURE_MATRIX_ARB 0x84E5
 #define GL_TRANSPOSE_COLOR_MATRIX_ARB 0x84E6
+
+typedef void (GLAPIENTRY * PFNGLLOADTRANSPOSEMATRIXDARBPROC) (GLdouble m[16]);
+typedef void (GLAPIENTRY * PFNGLLOADTRANSPOSEMATRIXFARBPROC) (GLfloat m[16]);
+typedef void (GLAPIENTRY * PFNGLMULTTRANSPOSEMATRIXDARBPROC) (GLdouble m[16]);
+typedef void (GLAPIENTRY * PFNGLMULTTRANSPOSEMATRIXFARBPROC) (GLfloat m[16]);
+
+#define glLoadTransposeMatrixdARB GLEW_GET_FUN(__glewLoadTransposeMatrixdARB)
+#define glLoadTransposeMatrixfARB GLEW_GET_FUN(__glewLoadTransposeMatrixfARB)
+#define glMultTransposeMatrixdARB GLEW_GET_FUN(__glewMultTransposeMatrixdARB)
+#define glMultTransposeMatrixfARB GLEW_GET_FUN(__glewMultTransposeMatrixfARB)
 
 #define GLEW_ARB_transpose_matrix GLEW_GET_VAR(__GLEW_ARB_transpose_matrix)
@@ -3342,4 +3661,6 @@
 #define GL_SWIZZLE_STR_DR_ATI 0x8978
 #define GL_SWIZZLE_STQ_DQ_ATI 0x8979
+#define GL_SWIZZLE_STRQ_ATI 0x897A
+#define GL_SWIZZLE_STRQ_DQ_ATI 0x897B
 
 typedef void (GLAPIENTRY * PFNGLALPHAFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod);
@@ -4107,4 +4428,134 @@
 #endif /* GL_EXT_fragment_lighting */
 
+/* ------------------------ GL_EXT_framebuffer_blit ------------------------ */
+
+#ifndef GL_EXT_framebuffer_blit
+#define GL_EXT_framebuffer_blit 1
+
+#define GL_DRAW_FRAMEBUFFER_BINDING_EXT 0x8CA6
+#define GL_READ_FRAMEBUFFER_EXT 0x8CA8
+#define GL_DRAW_FRAMEBUFFER_EXT 0x8CA9
+#define GL_READ_FRAMEBUFFER_BINDING_EXT 0x8CAA
+
+typedef void (GLAPIENTRY * PFNGLBLITFRAMEBUFFEREXTPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+
+#define glBlitFramebufferEXT GLEW_GET_FUN(__glewBlitFramebufferEXT)
+
+#define GLEW_EXT_framebuffer_blit GLEW_GET_VAR(__GLEW_EXT_framebuffer_blit)
+
+#endif /* GL_EXT_framebuffer_blit */
+
+/* --------------------- GL_EXT_framebuffer_multisample -------------------- */
+
+#ifndef GL_EXT_framebuffer_multisample
+#define GL_EXT_framebuffer_multisample 1
+
+#define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB
+
+typedef void (GLAPIENTRY * PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+
+#define glRenderbufferStorageMultisampleEXT GLEW_GET_FUN(__glewRenderbufferStorageMultisampleEXT)
+
+#define GLEW_EXT_framebuffer_multisample GLEW_GET_VAR(__GLEW_EXT_framebuffer_multisample)
+
+#endif /* GL_EXT_framebuffer_multisample */
+
+/* ----------------------- GL_EXT_framebuffer_object ----------------------- */
+
+#ifndef GL_EXT_framebuffer_object
+#define GL_EXT_framebuffer_object 1
+
+#define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506
+#define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8
+#define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6
+#define GL_RENDERBUFFER_BINDING_EXT 0x8CA7
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4
+#define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5
+#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6
+#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7
+#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9
+#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA
+#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB
+#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC
+#define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD
+#define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF
+#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0
+#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1
+#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2
+#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3
+#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4
+#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5
+#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6
+#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7
+#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8
+#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9
+#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA
+#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB
+#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC
+#define GL_COLOR_ATTACHMENT13_EXT 0x8CED
+#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE
+#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF
+#define GL_DEPTH_ATTACHMENT_EXT 0x8D00
+#define GL_STENCIL_ATTACHMENT_EXT 0x8D20
+#define GL_FRAMEBUFFER_EXT 0x8D40
+#define GL_RENDERBUFFER_EXT 0x8D41
+#define GL_RENDERBUFFER_WIDTH_EXT 0x8D42
+#define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43
+#define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44
+#define GL_STENCIL_INDEX1_EXT 0x8D46
+#define GL_STENCIL_INDEX4_EXT 0x8D47
+#define GL_STENCIL_INDEX8_EXT 0x8D48
+#define GL_STENCIL_INDEX16_EXT 0x8D49
+#define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50
+#define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51
+#define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52
+#define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53
+#define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54
+#define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55
+
+typedef void (GLAPIENTRY * PFNGLBINDFRAMEBUFFEREXTPROC) (GLenum target, GLuint framebuffer);
+typedef void (GLAPIENTRY * PFNGLBINDRENDERBUFFEREXTPROC) (GLenum target, GLuint renderbuffer);
+typedef GLenum (GLAPIENTRY * PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) (GLenum target);
+typedef void (GLAPIENTRY * PFNGLDELETEFRAMEBUFFERSEXTPROC) (GLsizei n, const GLuint* framebuffers);
+typedef void (GLAPIENTRY * PFNGLDELETERENDERBUFFERSEXTPROC) (GLsizei n, const GLuint* renderbuffers);
+typedef void (GLAPIENTRY * PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
+typedef void (GLAPIENTRY * PFNGLFRAMEBUFFERTEXTURE1DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+typedef void (GLAPIENTRY * PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+typedef void (GLAPIENTRY * PFNGLFRAMEBUFFERTEXTURE3DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
+typedef void (GLAPIENTRY * PFNGLGENFRAMEBUFFERSEXTPROC) (GLsizei n, GLuint* framebuffers);
+typedef void (GLAPIENTRY * PFNGLGENRENDERBUFFERSEXTPROC) (GLsizei n, GLuint* renderbuffers);
+typedef void (GLAPIENTRY * PFNGLGENERATEMIPMAPEXTPROC) (GLenum target);
+typedef void (GLAPIENTRY * PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) (GLenum target, GLenum attachment, GLenum pname, GLint* params);
+typedef void (GLAPIENTRY * PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint* params);
+typedef GLboolean (GLAPIENTRY * PFNGLISFRAMEBUFFEREXTPROC) (GLuint framebuffer);
+typedef GLboolean (GLAPIENTRY * PFNGLISRENDERBUFFEREXTPROC) (GLuint renderbuffer);
+typedef void (GLAPIENTRY * PFNGLRENDERBUFFERSTORAGEEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
+
+#define glBindFramebufferEXT GLEW_GET_FUN(__glewBindFramebufferEXT)
+#define glBindRenderbufferEXT GLEW_GET_FUN(__glewBindRenderbufferEXT)
+#define glCheckFramebufferStatusEXT GLEW_GET_FUN(__glewCheckFramebufferStatusEXT)
+#define glDeleteFramebuffersEXT GLEW_GET_FUN(__glewDeleteFramebuffersEXT)
+#define glDeleteRenderbuffersEXT GLEW_GET_FUN(__glewDeleteRenderbuffersEXT)
+#define glFramebufferRenderbufferEXT GLEW_GET_FUN(__glewFramebufferRenderbufferEXT)
+#define glFramebufferTexture1DEXT GLEW_GET_FUN(__glewFramebufferTexture1DEXT)
+#define glFramebufferTexture2DEXT GLEW_GET_FUN(__glewFramebufferTexture2DEXT)
+#define glFramebufferTexture3DEXT GLEW_GET_FUN(__glewFramebufferTexture3DEXT)
+#define glGenFramebuffersEXT GLEW_GET_FUN(__glewGenFramebuffersEXT)
+#define glGenRenderbuffersEXT GLEW_GET_FUN(__glewGenRenderbuffersEXT)
+#define glGenerateMipmapEXT GLEW_GET_FUN(__glewGenerateMipmapEXT)
+#define glGetFramebufferAttachmentParameterivEXT GLEW_GET_FUN(__glewGetFramebufferAttachmentParameterivEXT)
+#define glGetRenderbufferParameterivEXT GLEW_GET_FUN(__glewGetRenderbufferParameterivEXT)
+#define glIsFramebufferEXT GLEW_GET_FUN(__glewIsFramebufferEXT)
+#define glIsRenderbufferEXT GLEW_GET_FUN(__glewIsRenderbufferEXT)
+#define glRenderbufferStorageEXT GLEW_GET_FUN(__glewRenderbufferStorageEXT)
+
+#define GLEW_EXT_framebuffer_object GLEW_GET_VAR(__GLEW_EXT_framebuffer_object)
+
+#endif /* GL_EXT_framebuffer_object */
+
 /* ---------------------------- GL_EXT_histogram --------------------------- */
 
@@ -4280,4 +4731,18 @@
 
 #endif /* GL_EXT_multisample */
+
+/* ---------------------- GL_EXT_packed_depth_stencil ---------------------- */
+
+#ifndef GL_EXT_packed_depth_stencil
+#define GL_EXT_packed_depth_stencil 1
+
+#define GL_DEPTH_STENCIL_EXT 0x84F9
+#define GL_UNSIGNED_INT_24_8_EXT 0x84FA
+#define GL_DEPTH24_STENCIL8_EXT 0x88F0
+#define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1
+
+#define GLEW_EXT_packed_depth_stencil GLEW_GET_VAR(__GLEW_EXT_packed_depth_stencil)
+
+#endif /* GL_EXT_packed_depth_stencil */
 
 /* -------------------------- GL_EXT_packed_pixels ------------------------- */
@@ -4541,4 +5006,16 @@
 
 #endif /* GL_EXT_shared_texture_palette */
+
+/* ------------------------ GL_EXT_stencil_clear_tag ----------------------- */
+
+#ifndef GL_EXT_stencil_clear_tag
+#define GL_EXT_stencil_clear_tag 1
+
+#define GL_STENCIL_TAG_BITS_EXT 0x88F2
+#define GL_STENCIL_CLEAR_TAG_VALUE_EXT 0x88F3
+
+#define GLEW_EXT_stencil_clear_tag GLEW_GET_VAR(__GLEW_EXT_stencil_clear_tag)
+
+#endif /* GL_EXT_stencil_clear_tag */
 
 /* ------------------------ GL_EXT_stencil_two_side ------------------------ */
@@ -4890,4 +5367,30 @@
 
 #endif /* GL_EXT_texture_rectangle */
+
+/* -------------------------- GL_EXT_texture_sRGB -------------------------- */
+
+#ifndef GL_EXT_texture_sRGB
+#define GL_EXT_texture_sRGB 1
+
+#define GL_SRGB_EXT 0x8C40
+#define GL_SRGB8_EXT 0x8C41
+#define GL_SRGB_ALPHA_EXT 0x8C42
+#define GL_SRGB8_ALPHA8_EXT 0x8C43
+#define GL_SLUMINANCE_ALPHA_EXT 0x8C44
+#define GL_SLUMINANCE8_ALPHA8_EXT 0x8C45
+#define GL_SLUMINANCE_EXT 0x8C46
+#define GL_SLUMINANCE8_EXT 0x8C47
+#define GL_COMPRESSED_SRGB_EXT 0x8C48
+#define GL_COMPRESSED_SRGB_ALPHA_EXT 0x8C49
+#define GL_COMPRESSED_SLUMINANCE_EXT 0x8C4A
+#define GL_COMPRESSED_SLUMINANCE_ALPHA_EXT 0x8C4B
+#define GL_COMPRESSED_SRGB_S3TC_DXT1_EXT 0x8C4C
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT 0x8C4D
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT 0x8C4E
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F
+
+#define GLEW_EXT_texture_sRGB GLEW_GET_VAR(__GLEW_EXT_texture_sRGB)
+
+#endif /* GL_EXT_texture_sRGB */
 
 /* -------------------------- GL_EXT_vertex_array -------------------------- */
@@ -5191,4 +5694,17 @@
 #endif /* GL_EXT_vertex_weighting */
 
+/* ------------------------ GL_GREMEDY_string_marker ----------------------- */
+
+#ifndef GL_GREMEDY_string_marker
+#define GL_GREMEDY_string_marker 1
+
+typedef void (GLAPIENTRY * PFNGLSTRINGMARKERGREMEDYPROC) (GLsizei len, const void* string);
+
+#define glStringMarkerGREMEDY GLEW_GET_FUN(__glewStringMarkerGREMEDY)
+
+#define GLEW_GREMEDY_string_marker GLEW_GET_VAR(__GLEW_GREMEDY_string_marker)
+
+#endif /* GL_GREMEDY_string_marker */
+
 /* --------------------- GL_HP_convolution_border_modes -------------------- */
 
@@ -5442,4 +5958,20 @@
 
 #endif /* GL_KTX_buffer_region */
+
+/* ------------------------- GL_MESAX_texture_stack ------------------------ */
+
+#ifndef GL_MESAX_texture_stack
+#define GL_MESAX_texture_stack 1
+
+#define GL_TEXTURE_1D_STACK_MESAX 0x8759
+#define GL_TEXTURE_2D_STACK_MESAX 0x875A
+#define GL_PROXY_TEXTURE_1D_STACK_MESAX 0x875B
+#define GL_PROXY_TEXTURE_2D_STACK_MESAX 0x875C
+#define GL_TEXTURE_1D_STACK_BINDING_MESAX 0x875D
+#define GL_TEXTURE_2D_STACK_BINDING_MESAX 0x875E
+
+#define GLEW_MESAX_texture_stack GLEW_GET_VAR(__GLEW_MESAX_texture_stack)
+
+#endif /* GL_MESAX_texture_stack */
 
 /* -------------------------- GL_MESA_pack_invert -------------------------- */
@@ -5755,50 +6287,50 @@
 typedef unsigned short GLhalf;
 
-typedef void (GLAPIENTRY * PFNGLCOLOR3HNVPROC) (GLuint red, GLuint green, GLuint blue);
-typedef void (GLAPIENTRY * PFNGLCOLOR3HVNVPROC) (const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLCOLOR4HNVPROC) (GLuint red, GLuint green, GLuint blue, GLuint alpha);
-typedef void (GLAPIENTRY * PFNGLCOLOR4HVNVPROC) (const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLFOGCOORDHNVPROC) (GLuint fog);
-typedef void (GLAPIENTRY * PFNGLFOGCOORDHVNVPROC) (const GLuint* fog);
-typedef void (GLAPIENTRY * PFNGLMULTITEXCOORD1HNVPROC) (GLenum target, GLuint s);
-typedef void (GLAPIENTRY * PFNGLMULTITEXCOORD1HVNVPROC) (GLenum target, const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLMULTITEXCOORD2HNVPROC) (GLenum target, GLuint s, GLuint t);
-typedef void (GLAPIENTRY * PFNGLMULTITEXCOORD2HVNVPROC) (GLenum target, const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLMULTITEXCOORD3HNVPROC) (GLenum target, GLuint s, GLuint t, GLuint r);
-typedef void (GLAPIENTRY * PFNGLMULTITEXCOORD3HVNVPROC) (GLenum target, const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLMULTITEXCOORD4HNVPROC) (GLenum target, GLuint s, GLuint t, GLuint r, GLuint q);
-typedef void (GLAPIENTRY * PFNGLMULTITEXCOORD4HVNVPROC) (GLenum target, const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLNORMAL3HNVPROC) (GLuint nx, GLuint ny, GLuint nz);
-typedef void (GLAPIENTRY * PFNGLNORMAL3HVNVPROC) (const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLSECONDARYCOLOR3HNVPROC) (GLuint red, GLuint green, GLuint blue);
-typedef void (GLAPIENTRY * PFNGLSECONDARYCOLOR3HVNVPROC) (const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLTEXCOORD1HNVPROC) (GLuint s);
-typedef void (GLAPIENTRY * PFNGLTEXCOORD1HVNVPROC) (const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLTEXCOORD2HNVPROC) (GLuint s, GLuint t);
-typedef void (GLAPIENTRY * PFNGLTEXCOORD2HVNVPROC) (const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLTEXCOORD3HNVPROC) (GLuint s, GLuint t, GLuint r);
-typedef void (GLAPIENTRY * PFNGLTEXCOORD3HVNVPROC) (const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLTEXCOORD4HNVPROC) (GLuint s, GLuint t, GLuint r, GLuint q);
-typedef void (GLAPIENTRY * PFNGLTEXCOORD4HVNVPROC) (const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLVERTEX2HNVPROC) (GLuint x, GLuint y);
-typedef void (GLAPIENTRY * PFNGLVERTEX2HVNVPROC) (const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLVERTEX3HNVPROC) (GLuint x, GLuint y, GLuint z);
-typedef void (GLAPIENTRY * PFNGLVERTEX3HVNVPROC) (const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLVERTEX4HNVPROC) (GLuint x, GLuint y, GLuint z, GLuint w);
-typedef void (GLAPIENTRY * PFNGLVERTEX4HVNVPROC) (const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB1HNVPROC) (GLuint index, GLuint x);
-typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB1HVNVPROC) (GLuint index, const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB2HNVPROC) (GLuint index, GLuint x, GLuint y);
-typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB2HVNVPROC) (GLuint index, const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB3HNVPROC) (GLuint index, GLuint x, GLuint y, GLuint z);
-typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB3HVNVPROC) (GLuint index, const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4HNVPROC) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
-typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4HVNVPROC) (GLuint index, const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLVERTEXATTRIBS1HVNVPROC) (GLuint index, GLsizei n, const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLVERTEXATTRIBS2HVNVPROC) (GLuint index, GLsizei n, const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLVERTEXATTRIBS3HVNVPROC) (GLuint index, GLsizei n, const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLVERTEXATTRIBS4HVNVPROC) (GLuint index, GLsizei n, const GLuint* v);
-typedef void (GLAPIENTRY * PFNGLVERTEXWEIGHTHNVPROC) (GLuint weight);
-typedef void (GLAPIENTRY * PFNGLVERTEXWEIGHTHVNVPROC) (const GLuint* weight);
+typedef void (GLAPIENTRY * PFNGLCOLOR3HNVPROC) (GLhalf red, GLhalf green, GLhalf blue);
+typedef void (GLAPIENTRY * PFNGLCOLOR3HVNVPROC) (const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLCOLOR4HNVPROC) (GLhalf red, GLhalf green, GLhalf blue, GLhalf alpha);
+typedef void (GLAPIENTRY * PFNGLCOLOR4HVNVPROC) (const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLFOGCOORDHNVPROC) (GLhalf fog);
+typedef void (GLAPIENTRY * PFNGLFOGCOORDHVNVPROC) (const GLhalf* fog);
+typedef void (GLAPIENTRY * PFNGLMULTITEXCOORD1HNVPROC) (GLenum target, GLhalf s);
+typedef void (GLAPIENTRY * PFNGLMULTITEXCOORD1HVNVPROC) (GLenum target, const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLMULTITEXCOORD2HNVPROC) (GLenum target, GLhalf s, GLhalf t);
+typedef void (GLAPIENTRY * PFNGLMULTITEXCOORD2HVNVPROC) (GLenum target, const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLMULTITEXCOORD3HNVPROC) (GLenum target, GLhalf s, GLhalf t, GLhalf r);
+typedef void (GLAPIENTRY * PFNGLMULTITEXCOORD3HVNVPROC) (GLenum target, const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLMULTITEXCOORD4HNVPROC) (GLenum target, GLhalf s, GLhalf t, GLhalf r, GLhalf q);
+typedef void (GLAPIENTRY * PFNGLMULTITEXCOORD4HVNVPROC) (GLenum target, const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLNORMAL3HNVPROC) (GLhalf nx, GLhalf ny, GLhalf nz);
+typedef void (GLAPIENTRY * PFNGLNORMAL3HVNVPROC) (const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLSECONDARYCOLOR3HNVPROC) (GLhalf red, GLhalf green, GLhalf blue);
+typedef void (GLAPIENTRY * PFNGLSECONDARYCOLOR3HVNVPROC) (const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLTEXCOORD1HNVPROC) (GLhalf s);
+typedef void (GLAPIENTRY * PFNGLTEXCOORD1HVNVPROC) (const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLTEXCOORD2HNVPROC) (GLhalf s, GLhalf t);
+typedef void (GLAPIENTRY * PFNGLTEXCOORD2HVNVPROC) (const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLTEXCOORD3HNVPROC) (GLhalf s, GLhalf t, GLhalf r);
+typedef void (GLAPIENTRY * PFNGLTEXCOORD3HVNVPROC) (const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLTEXCOORD4HNVPROC) (GLhalf s, GLhalf t, GLhalf r, GLhalf q);
+typedef void (GLAPIENTRY * PFNGLTEXCOORD4HVNVPROC) (const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLVERTEX2HNVPROC) (GLhalf x, GLhalf y);
+typedef void (GLAPIENTRY * PFNGLVERTEX2HVNVPROC) (const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLVERTEX3HNVPROC) (GLhalf x, GLhalf y, GLhalf z);
+typedef void (GLAPIENTRY * PFNGLVERTEX3HVNVPROC) (const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLVERTEX4HNVPROC) (GLhalf x, GLhalf y, GLhalf z, GLhalf w);
+typedef void (GLAPIENTRY * PFNGLVERTEX4HVNVPROC) (const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB1HNVPROC) (GLuint index, GLhalf x);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB1HVNVPROC) (GLuint index, const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB2HNVPROC) (GLuint index, GLhalf x, GLhalf y);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB2HVNVPROC) (GLuint index, const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB3HNVPROC) (GLuint index, GLhalf x, GLhalf y, GLhalf z);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB3HVNVPROC) (GLuint index, const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4HNVPROC) (GLuint index, GLhalf x, GLhalf y, GLhalf z, GLhalf w);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4HVNVPROC) (GLuint index, const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIBS1HVNVPROC) (GLuint index, GLsizei n, const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIBS2HVNVPROC) (GLuint index, GLsizei n, const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIBS3HVNVPROC) (GLuint index, GLsizei n, const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXATTRIBS4HVNVPROC) (GLuint index, GLsizei n, const GLhalf* v);
+typedef void (GLAPIENTRY * PFNGLVERTEXWEIGHTHNVPROC) (GLhalf weight);
+typedef void (GLAPIENTRY * PFNGLVERTEXWEIGHTHVNVPROC) (const GLhalf* weight);
 
 #define glColor3hNV GLEW_GET_FUN(__glewColor3hNV)
@@ -7192,4 +7724,9 @@
 #define GL_SGIX_shadow 1
 
+#define GL_TEXTURE_COMPARE_SGIX 0x819A
+#define GL_TEXTURE_COMPARE_OPERATOR_SGIX 0x819B
+#define GL_TEXTURE_LEQUAL_R_SGIX 0x819C
+#define GL_TEXTURE_GEQUAL_R_SGIX 0x819D
+
 #define GLEW_SGIX_shadow GLEW_GET_VAR(__GLEW_SGIX_shadow)
 
@@ -7841,4 +8378,98 @@
 GLEW_FUN_EXPORT PFNGLUNMAPBUFFERPROC __glewUnmapBuffer;
 
+GLEW_FUN_EXPORT PFNGLATTACHSHADERPROC __glewAttachShader;
+GLEW_FUN_EXPORT PFNGLBINDATTRIBLOCATIONPROC __glewBindAttribLocation;
+GLEW_FUN_EXPORT PFNGLBLENDEQUATIONSEPARATEPROC __glewBlendEquationSeparate;
+GLEW_FUN_EXPORT PFNGLCOMPILESHADERPROC __glewCompileShader;
+GLEW_FUN_EXPORT PFNGLCREATEPROGRAMPROC __glewCreateProgram;
+GLEW_FUN_EXPORT PFNGLCREATESHADERPROC __glewCreateShader;
+GLEW_FUN_EXPORT PFNGLDELETEPROGRAMPROC __glewDeleteProgram;
+GLEW_FUN_EXPORT PFNGLDELETESHADERPROC __glewDeleteShader;
+GLEW_FUN_EXPORT PFNGLDETACHSHADERPROC __glewDetachShader;
+GLEW_FUN_EXPORT PFNGLDISABLEVERTEXATTRIBARRAYPROC __glewDisableVertexAttribArray;
+GLEW_FUN_EXPORT PFNGLDRAWBUFFERSPROC __glewDrawBuffers;
+GLEW_FUN_EXPORT PFNGLENABLEVERTEXATTRIBARRAYPROC __glewEnableVertexAttribArray;
+GLEW_FUN_EXPORT PFNGLGETACTIVEATTRIBPROC __glewGetActiveAttrib;
+GLEW_FUN_EXPORT PFNGLGETACTIVEUNIFORMPROC __glewGetActiveUniform;
+GLEW_FUN_EXPORT PFNGLGETATTACHEDSHADERSPROC __glewGetAttachedShaders;
+GLEW_FUN_EXPORT PFNGLGETATTRIBLOCATIONPROC __glewGetAttribLocation;
+GLEW_FUN_EXPORT PFNGLGETPROGRAMINFOLOGPROC __glewGetProgramInfoLog;
+GLEW_FUN_EXPORT PFNGLGETPROGRAMIVPROC __glewGetProgramiv;
+GLEW_FUN_EXPORT PFNGLGETSHADERINFOLOGPROC __glewGetShaderInfoLog;
+GLEW_FUN_EXPORT PFNGLGETSHADERSOURCEPROC __glewGetShaderSource;
+GLEW_FUN_EXPORT PFNGLGETSHADERIVPROC __glewGetShaderiv;
+GLEW_FUN_EXPORT PFNGLGETUNIFORMLOCATIONPROC __glewGetUniformLocation;
+GLEW_FUN_EXPORT PFNGLGETUNIFORMFVPROC __glewGetUniformfv;
+GLEW_FUN_EXPORT PFNGLGETUNIFORMIVPROC __glewGetUniformiv;
+GLEW_FUN_EXPORT PFNGLGETVERTEXATTRIBPOINTERVPROC __glewGetVertexAttribPointerv;
+GLEW_FUN_EXPORT PFNGLGETVERTEXATTRIBDVPROC __glewGetVertexAttribdv;
+GLEW_FUN_EXPORT PFNGLGETVERTEXATTRIBFVPROC __glewGetVertexAttribfv;
+GLEW_FUN_EXPORT PFNGLGETVERTEXATTRIBIVPROC __glewGetVertexAttribiv;
+GLEW_FUN_EXPORT PFNGLISPROGRAMPROC __glewIsProgram;
+GLEW_FUN_EXPORT PFNGLISSHADERPROC __glewIsShader;
+GLEW_FUN_EXPORT PFNGLLINKPROGRAMPROC __glewLinkProgram;
+GLEW_FUN_EXPORT PFNGLSHADERSOURCEPROC __glewShaderSource;
+GLEW_FUN_EXPORT PFNGLSTENCILFUNCSEPARATEPROC __glewStencilFuncSeparate;
+GLEW_FUN_EXPORT PFNGLSTENCILMASKSEPARATEPROC __glewStencilMaskSeparate;
+GLEW_FUN_EXPORT PFNGLSTENCILOPSEPARATEPROC __glewStencilOpSeparate;
+GLEW_FUN_EXPORT PFNGLUNIFORM1FPROC __glewUniform1f;
+GLEW_FUN_EXPORT PFNGLUNIFORM1FVPROC __glewUniform1fv;
+GLEW_FUN_EXPORT PFNGLUNIFORM1IPROC __glewUniform1i;
+GLEW_FUN_EXPORT PFNGLUNIFORM1IVPROC __glewUniform1iv;
+GLEW_FUN_EXPORT PFNGLUNIFORM2FPROC __glewUniform2f;
+GLEW_FUN_EXPORT PFNGLUNIFORM2FVPROC __glewUniform2fv;
+GLEW_FUN_EXPORT PFNGLUNIFORM2IPROC __glewUniform2i;
+GLEW_FUN_EXPORT PFNGLUNIFORM2IVPROC __glewUniform2iv;
+GLEW_FUN_EXPORT PFNGLUNIFORM3FPROC __glewUniform3f;
+GLEW_FUN_EXPORT PFNGLUNIFORM3FVPROC __glewUniform3fv;
+GLEW_FUN_EXPORT PFNGLUNIFORM3IPROC __glewUniform3i;
+GLEW_FUN_EXPORT PFNGLUNIFORM3IVPROC __glewUniform3iv;
+GLEW_FUN_EXPORT PFNGLUNIFORM4FPROC __glewUniform4f;
+GLEW_FUN_EXPORT PFNGLUNIFORM4FVPROC __glewUniform4fv;
+GLEW_FUN_EXPORT PFNGLUNIFORM4IPROC __glewUniform4i;
+GLEW_FUN_EXPORT PFNGLUNIFORM4IVPROC __glewUniform4iv;
+GLEW_FUN_EXPORT PFNGLUNIFORMMATRIX2FVPROC __glewUniformMatrix2fv;
+GLEW_FUN_EXPORT PFNGLUNIFORMMATRIX3FVPROC __glewUniformMatrix3fv;
+GLEW_FUN_EXPORT PFNGLUNIFORMMATRIX4FVPROC __glewUniformMatrix4fv;
+GLEW_FUN_EXPORT PFNGLUSEPROGRAMPROC __glewUseProgram;
+GLEW_FUN_EXPORT PFNGLVALIDATEPROGRAMPROC __glewValidateProgram;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB1DPROC __glewVertexAttrib1d;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB1DVPROC __glewVertexAttrib1dv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB1FPROC __glewVertexAttrib1f;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB1FVPROC __glewVertexAttrib1fv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB1SPROC __glewVertexAttrib1s;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB1SVPROC __glewVertexAttrib1sv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB2DPROC __glewVertexAttrib2d;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB2DVPROC __glewVertexAttrib2dv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB2FPROC __glewVertexAttrib2f;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB2FVPROC __glewVertexAttrib2fv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB2SPROC __glewVertexAttrib2s;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB2SVPROC __glewVertexAttrib2sv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB3DPROC __glewVertexAttrib3d;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB3DVPROC __glewVertexAttrib3dv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB3FPROC __glewVertexAttrib3f;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB3FVPROC __glewVertexAttrib3fv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB3SPROC __glewVertexAttrib3s;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB3SVPROC __glewVertexAttrib3sv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB4NBVPROC __glewVertexAttrib4Nbv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB4NIVPROC __glewVertexAttrib4Niv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB4NSVPROC __glewVertexAttrib4Nsv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB4NUBPROC __glewVertexAttrib4Nub;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB4NUBVPROC __glewVertexAttrib4Nubv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB4NUIVPROC __glewVertexAttrib4Nuiv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB4NUSVPROC __glewVertexAttrib4Nusv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB4BVPROC __glewVertexAttrib4bv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB4DPROC __glewVertexAttrib4d;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB4DVPROC __glewVertexAttrib4dv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB4FPROC __glewVertexAttrib4f;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB4FVPROC __glewVertexAttrib4fv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB4IVPROC __glewVertexAttrib4iv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB4SPROC __glewVertexAttrib4s;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB4SVPROC __glewVertexAttrib4sv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB4UBVPROC __glewVertexAttrib4ubv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB4UIVPROC __glewVertexAttrib4uiv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIB4USVPROC __glewVertexAttrib4usv;
+GLEW_FUN_EXPORT PFNGLVERTEXATTRIBPOINTERPROC __glewVertexAttribPointer;
+
 GLEW_FUN_EXPORT PFNGLTBUFFERMASK3DFXPROC __glewTbufferMask3DFX;
 
@@ -8009,4 +8640,9 @@
 GLEW_FUN_EXPORT PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC __glewCompressedTexSubImage3DARB;
 GLEW_FUN_EXPORT PFNGLGETCOMPRESSEDTEXIMAGEARBPROC __glewGetCompressedTexImageARB;
+
+GLEW_FUN_EXPORT PFNGLLOADTRANSPOSEMATRIXDARBPROC __glewLoadTransposeMatrixdARB;
+GLEW_FUN_EXPORT PFNGLLOADTRANSPOSEMATRIXFARBPROC __glewLoadTransposeMatrixfARB;
+GLEW_FUN_EXPORT PFNGLMULTTRANSPOSEMATRIXDARBPROC __glewMultTransposeMatrixdARB;
+GLEW_FUN_EXPORT PFNGLMULTTRANSPOSEMATRIXFARBPROC __glewMultTransposeMatrixfARB;
 
 GLEW_FUN_EXPORT PFNGLVERTEXBLENDARBPROC __glewVertexBlendARB;
@@ -8276,4 +8912,26 @@
 GLEW_FUN_EXPORT PFNGLLIGHTENVIEXTPROC __glewLightEnviEXT;
 
+GLEW_FUN_EXPORT PFNGLBLITFRAMEBUFFEREXTPROC __glewBlitFramebufferEXT;
+
+GLEW_FUN_EXPORT PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC __glewRenderbufferStorageMultisampleEXT;
+
+GLEW_FUN_EXPORT PFNGLBINDFRAMEBUFFEREXTPROC __glewBindFramebufferEXT;
+GLEW_FUN_EXPORT PFNGLBINDRENDERBUFFEREXTPROC __glewBindRenderbufferEXT;
+GLEW_FUN_EXPORT PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC __glewCheckFramebufferStatusEXT;
+GLEW_FUN_EXPORT PFNGLDELETEFRAMEBUFFERSEXTPROC __glewDeleteFramebuffersEXT;
+GLEW_FUN_EXPORT PFNGLDELETERENDERBUFFERSEXTPROC __glewDeleteRenderbuffersEXT;
+GLEW_FUN_EXPORT PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC __glewFramebufferRenderbufferEXT;
+GLEW_FUN_EXPORT PFNGLFRAMEBUFFERTEXTURE1DEXTPROC __glewFramebufferTexture1DEXT;
+GLEW_FUN_EXPORT PFNGLFRAMEBUFFERTEXTURE2DEXTPROC __glewFramebufferTexture2DEXT;
+GLEW_FUN_EXPORT PFNGLFRAMEBUFFERTEXTURE3DEXTPROC __glewFramebufferTexture3DEXT;
+GLEW_FUN_EXPORT PFNGLGENFRAMEBUFFERSEXTPROC __glewGenFramebuffersEXT;
+GLEW_FUN_EXPORT PFNGLGENRENDERBUFFERSEXTPROC __glewGenRenderbuffersEXT;
+GLEW_FUN_EXPORT PFNGLGENERATEMIPMAPEXTPROC __glewGenerateMipmapEXT;
+GLEW_FUN_EXPORT PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC __glewGetFramebufferAttachmentParameterivEXT;
+GLEW_FUN_EXPORT PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC __glewGetRenderbufferParameterivEXT;
+GLEW_FUN_EXPORT PFNGLISFRAMEBUFFEREXTPROC __glewIsFramebufferEXT;
+GLEW_FUN_EXPORT PFNGLISRENDERBUFFEREXTPROC __glewIsRenderbufferEXT;
+GLEW_FUN_EXPORT PFNGLRENDERBUFFERSTORAGEEXTPROC __glewRenderbufferStorageEXT;
+
 GLEW_FUN_EXPORT PFNGLGETHISTOGRAMEXTPROC __glewGetHistogramEXT;
 GLEW_FUN_EXPORT PFNGLGETHISTOGRAMPARAMETERFVEXTPROC __glewGetHistogramParameterfvEXT;
@@ -8412,4 +9070,6 @@
 GLEW_FUN_EXPORT PFNGLVERTEXWEIGHTFEXTPROC __glewVertexWeightfEXT;
 GLEW_FUN_EXPORT PFNGLVERTEXWEIGHTFVEXTPROC __glewVertexWeightfvEXT;
+
+GLEW_FUN_EXPORT PFNGLSTRINGMARKERGREMEDYPROC __glewStringMarkerGREMEDY;
 
 GLEW_FUN_EXPORT PFNGLGETIMAGETRANSFORMPARAMETERFVHPPROC __glewGetImageTransformParameterfvHP;
@@ -8797,4 +9457,5 @@
 GLEW_VAR_EXPORT GLboolean __GLEW_APPLE_fence;
 GLEW_VAR_EXPORT GLboolean __GLEW_APPLE_float_pixels;
+GLEW_VAR_EXPORT GLboolean __GLEW_APPLE_pixel_buffer;
 GLEW_VAR_EXPORT GLboolean __GLEW_APPLE_specular_vector;
 GLEW_VAR_EXPORT GLboolean __GLEW_APPLE_texture_range;
@@ -8815,4 +9476,5 @@
 GLEW_VAR_EXPORT GLboolean __GLEW_ARB_multitexture;
 GLEW_VAR_EXPORT GLboolean __GLEW_ARB_occlusion_query;
+GLEW_VAR_EXPORT GLboolean __GLEW_ARB_pixel_buffer_object;
 GLEW_VAR_EXPORT GLboolean __GLEW_ARB_point_parameters;
 GLEW_VAR_EXPORT GLboolean __GLEW_ARB_point_sprite;
@@ -8879,4 +9541,7 @@
 GLEW_VAR_EXPORT GLboolean __GLEW_EXT_fog_coord;
 GLEW_VAR_EXPORT GLboolean __GLEW_EXT_fragment_lighting;
+GLEW_VAR_EXPORT GLboolean __GLEW_EXT_framebuffer_blit;
+GLEW_VAR_EXPORT GLboolean __GLEW_EXT_framebuffer_multisample;
+GLEW_VAR_EXPORT GLboolean __GLEW_EXT_framebuffer_object;
 GLEW_VAR_EXPORT GLboolean __GLEW_EXT_histogram;
 GLEW_VAR_EXPORT GLboolean __GLEW_EXT_index_array_formats;
@@ -8888,4 +9553,5 @@
 GLEW_VAR_EXPORT GLboolean __GLEW_EXT_multi_draw_arrays;
 GLEW_VAR_EXPORT GLboolean __GLEW_EXT_multisample;
+GLEW_VAR_EXPORT GLboolean __GLEW_EXT_packed_depth_stencil;
 GLEW_VAR_EXPORT GLboolean __GLEW_EXT_packed_pixels;
 GLEW_VAR_EXPORT GLboolean __GLEW_EXT_paletted_texture;
@@ -8901,4 +9567,5 @@
 GLEW_VAR_EXPORT GLboolean __GLEW_EXT_shadow_funcs;
 GLEW_VAR_EXPORT GLboolean __GLEW_EXT_shared_texture_palette;
+GLEW_VAR_EXPORT GLboolean __GLEW_EXT_stencil_clear_tag;
 GLEW_VAR_EXPORT GLboolean __GLEW_EXT_stencil_two_side;
 GLEW_VAR_EXPORT GLboolean __GLEW_EXT_stencil_wrap;
@@ -8920,7 +9587,9 @@
 GLEW_VAR_EXPORT GLboolean __GLEW_EXT_texture_perturb_normal;
 GLEW_VAR_EXPORT GLboolean __GLEW_EXT_texture_rectangle;
+GLEW_VAR_EXPORT GLboolean __GLEW_EXT_texture_sRGB;
 GLEW_VAR_EXPORT GLboolean __GLEW_EXT_vertex_array;
 GLEW_VAR_EXPORT GLboolean __GLEW_EXT_vertex_shader;
 GLEW_VAR_EXPORT GLboolean __GLEW_EXT_vertex_weighting;
+GLEW_VAR_EXPORT GLboolean __GLEW_GREMEDY_string_marker;
 GLEW_VAR_EXPORT GLboolean __GLEW_HP_convolution_border_modes;
 GLEW_VAR_EXPORT GLboolean __GLEW_HP_image_transform;
@@ -8938,4 +9607,5 @@
 GLEW_VAR_EXPORT GLboolean __GLEW_INTEL_texture_scissor;
 GLEW_VAR_EXPORT GLboolean __GLEW_KTX_buffer_region;
+GLEW_VAR_EXPORT GLboolean __GLEW_MESAX_texture_stack;
 GLEW_VAR_EXPORT GLboolean __GLEW_MESA_pack_invert;
 GLEW_VAR_EXPORT GLboolean __GLEW_MESA_resize_buffers;
@@ -9065,4 +9735,9 @@
 typedef struct GLEWContextStruct GLEWContext;
 GLEWAPI GLenum glewContextInit (GLEWContext* ctx);
+GLEWAPI GLboolean glewContextIsSupported (GLEWContext* ctx, const char* name);
+
+#define glewInit() glewContextInit(glewGetContext())
+#define glewIsSupported(x) glewContextIsSupported(glewGetContext(), x)
+#define glewIsExtensionSupported(x) glewIsSupported(x)
 
 #ifdef _WIN32
@@ -9077,4 +9752,6 @@
 
 GLEWAPI GLenum glewInit ();
+GLEWAPI GLboolean glewIsSupported (const char* name);
+#define glewIsExtensionSupported(x) glewIsSupported(x)
 
 #define GLEW_GET_VAR(x) x
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GL/wglew.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GL/wglew.h	(revision 498)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GL/wglew.h	(revision 1001)
@@ -1,6 +1,6 @@
 /*
 ** The OpenGL Extension Wrangler Library
-** Copyright (C) 2004, 2003, 2002, Milan Ikits <milan ikits[at]ieee org>
-** Copyright (C) 2004, 2003, 2002, Marcelo E. Magallon <mmagallo[at]debian org>
+** Copyright (C) 2002-2006, Milan Ikits <milan ikits[]ieee org>
+** Copyright (C) 2002-2006, Marcelo E. Magallon <mmagallo[]debian org>
 ** Copyright (C) 2002, Lev Povalahev
 ** All rights reserved.
@@ -30,33 +30,4 @@
 */
 
-/*
-** License Applicability. Except to the extent portions of this file are
-** made subject to an alternative license as permitted in the SGI Free
-** Software License B, Version 1.1 (the "License"), the contents of this
-** file are subject only to the provisions of the License. You may not use
-** this file except in compliance with the License. You may obtain a copy
-** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
-** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
-** 
-** http://oss.sgi.com/projects/FreeB
-** 
-** Note that, as provided in the License, the Software is distributed on an
-** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
-** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
-** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
-** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
-** 
-** Original Code. The Original Code is: OpenGL Sample Implementation,
-** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
-** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
-** Copyright in any portions created by third parties is as indicated
-** elsewhere herein. All Rights Reserved.
-** 
-** Additional Notice Provisions: This software was created using the
-** OpenGL(R) version 1.2.1 Sample Implementation published by SGI, but has
-** not been independently verified as being compliant with the OpenGL(R)
-** version 1.2.1 Specification.
-*/
-
 #ifndef __wglew_h__
 #define __wglew_h__
@@ -70,5 +41,7 @@
 
 #if !defined(APIENTRY) && !defined(__CYGWIN__)
-#define WIN32_LEAN_AND_MEAN 1
+#  ifndef WIN32_LEAN_AND_MEAN
+#    define WIN32_LEAN_AND_MEAN 1
+#  endif
 #include <windows.h>
 #endif
@@ -103,4 +76,22 @@
 
 #endif /* WGL_3DFX_multisample */
+
+/* ------------------------- WGL_3DL_stereo_control ------------------------ */
+
+#ifndef WGL_3DL_stereo_control
+#define WGL_3DL_stereo_control 1
+
+#define WGL_STEREO_EMITTER_ENABLE_3DL 0x2055
+#define WGL_STEREO_EMITTER_DISABLE_3DL 0x2056
+#define WGL_STEREO_POLARITY_NORMAL_3DL 0x2057
+#define WGL_STEREO_POLARITY_INVERT_3DL 0x2058
+
+typedef BOOL (WINAPI * PFNWGLSETSTEREOEMITTERSTATE3DLPROC) (HDC hDC, UINT uState);
+
+#define wglSetStereoEmitterState3DL WGLEW_GET_FUN(__wglewSetStereoEmitterState3DL)
+
+#define WGLEW_3DL_stereo_control WGLEW_GET_VAR(__WGLEW_3DL_stereo_control)
+
+#endif /* WGL_3DL_stereo_control */
 
 /* ------------------------- WGL_ARB_buffer_region ------------------------- */
@@ -342,4 +333,15 @@
 #endif /* WGL_ATI_pixel_format_float */
 
+/* -------------------- WGL_ATI_render_texture_rectangle ------------------- */
+
+#ifndef WGL_ATI_render_texture_rectangle
+#define WGL_ATI_render_texture_rectangle 1
+
+#define WGL_TEXTURE_RECTANGLE_ATI 0x21A5
+
+#define WGLEW_ATI_render_texture_rectangle WGLEW_GET_VAR(__WGLEW_ATI_render_texture_rectangle)
+
+#endif /* WGL_ATI_render_texture_rectangle */
+
 /* -------------------------- WGL_EXT_depth_float -------------------------- */
 
@@ -769,4 +771,6 @@
 #endif /* GLEW_MX */
 
+WGLEW_EXPORT PFNWGLSETSTEREOEMITTERSTATE3DLPROC __wglewSetStereoEmitterState3DL;
+
 WGLEW_EXPORT PFNWGLCREATEBUFFERREGIONARBPROC __wglewCreateBufferRegionARB;
 WGLEW_EXPORT PFNWGLDELETEBUFFERREGIONARBPROC __wglewDeleteBufferRegionARB;
@@ -862,4 +866,5 @@
 WGLEW_EXPORT PFNWGLWAITFORSBCOMLPROC __wglewWaitForSbcOML;
 WGLEW_EXPORT GLboolean __WGLEW_3DFX_multisample;
+WGLEW_EXPORT GLboolean __WGLEW_3DL_stereo_control;
 WGLEW_EXPORT GLboolean __WGLEW_ARB_buffer_region;
 WGLEW_EXPORT GLboolean __WGLEW_ARB_extensions_string;
@@ -871,4 +876,5 @@
 WGLEW_EXPORT GLboolean __WGLEW_ARB_render_texture;
 WGLEW_EXPORT GLboolean __WGLEW_ATI_pixel_format_float;
+WGLEW_EXPORT GLboolean __WGLEW_ATI_render_texture_rectangle;
 WGLEW_EXPORT GLboolean __WGLEW_EXT_depth_float;
 WGLEW_EXPORT GLboolean __WGLEW_EXT_display_color_table;
@@ -901,4 +907,8 @@
 typedef struct WGLEWContextStruct WGLEWContext;
 GLEWAPI GLenum wglewContextInit (WGLEWContext* ctx);
+GLEWAPI GLboolean wglewContextIsSupported (WGLEWContext* ctx, const char* name);
+
+#define wglewInit() wglewContextInit(wglewGetContext())
+#define wglewIsSupported(x) wglewContextIsSupported(wglewGetContext(), x)
 
 #define WGLEW_GET_VAR(x) wglewGetContext()->x
@@ -909,4 +919,6 @@
 #define WGLEW_GET_VAR(x) x
 #define WGLEW_GET_FUN(x) x
+
+GLEWAPI GLboolean wglewIsSupported (const char* name);
 
 #endif /* GLEW_MX */
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 997)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1001)
@@ -17,5 +17,5 @@
 #include "BoundingBoxConverter.h"
 #include "GlRenderer.h"
-
+#include "ResourceManager.h"
 
 
@@ -211,6 +211,4 @@
 	else
 		DEL_PTR(mViewCellsTree);
-
-	CLEAR_CONTAINER(mMeshContainer);
 }
 
@@ -942,5 +940,4 @@
 	mEnvironment->GetIntValue("ViewCells.Evaluation.histoStepSize", histoStepSize);
 
-	Debug << "here21 " << histoStepSize << endl;
 	const int numLeaves = mViewCellsTree->GetNumInitialViewCells(mViewCellsTree->GetRoot());
 
@@ -1442,5 +1439,26 @@
 			viewCells.push_back(viewCell);
 		}
-		//TODO: transformed meshes
+		else if (object->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE)
+		{
+			TransformedMeshInstance *mi = dynamic_cast<TransformedMeshInstance *>(object);
+
+			Mesh *mesh = MeshManager::GetSingleton()->CreateResource();
+
+			// copy mesh
+			*mesh = *mi->GetMesh();
+
+			// transform mesh
+			Matrix4x4 m;
+			mi->GetWorldTransform(m);
+			mesh->ApplyTransformation(m);
+			
+			// create bb + kd tree
+			mesh->Preprocess();
+
+			ViewCell *viewCell = GenerateViewCell(mi->GetMesh());
+			viewCells.push_back(viewCell);
+
+			break;
+		}
 	}
 }
@@ -1451,5 +1469,5 @@
 {
 	// one mesh per view cell
-	Mesh *mesh = new Mesh();
+	Mesh *mesh = MeshManager::GetSingleton()->CreateResource();
 
 	//-- construct prism
@@ -1501,4 +1519,5 @@
 	// implemented in subclasses
 }
+
 
 // fast way of merging 2 view cells
@@ -1964,5 +1983,7 @@
 	{
 		if (!(*it)->GetMesh())
+		{
 			CreateMesh(*it);
+		}
 	}
 }
@@ -2010,5 +2031,7 @@
 }
 
+
 static const bool USE_ASCII = true;
+
 
 bool ViewCellsManager::ExportBoundingBoxes(const string filename, 
@@ -2776,11 +2799,8 @@
 	mBspTree->ConstructGeometry(vc, geom);
 
-	Mesh *mesh = new Mesh();
+	Mesh *mesh = MeshManager::GetSingleton()->CreateResource();
 
 	IncludeNodeGeomInMesh(geom, *mesh);
 	vc->SetMesh(mesh);
-
-	// put mesh into mesh container so we can savely delete it
-	mMeshContainer.push_back(mesh);
 }
 
@@ -4712,5 +4732,5 @@
 	cout << "starting sampling of render cost ... ";
 	
-	preprocessor->GetRenderer()->SampleRenderCost(numSamples, samples);
+	preprocessor->GetRenderer()->SampleRenderCost(numSamples, samples, true);
 
 	cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
@@ -4725,9 +4745,8 @@
 	{
 		RenderCostSample sample = *rit;
-		
+
 		ViewCell *vc = GetViewCell(sample.mPosition);
 		
 		AxisAlignedBox3 box(sample.mPosition - Vector3(1, 1, 1), sample.mPosition + Vector3(1, 1, 1));
-	
 		Mesh *hMesh = CreateMeshFromBox(box);
 		
@@ -4791,14 +4810,15 @@
 	{
 		// export mesh if available
-	/*	if (vc->GetMesh())
+		// TODO: some bug here?
+		if (0 && vc->GetMesh())
 		{
 			exporter->ExportMesh(vc->GetMesh());
 		}
 		else
-		{*/
+		{
 			BspNodeGeometry geom;
 			mVspBspTree->ConstructGeometry(vc, geom);
 			exporter->ExportPolygons(geom.GetPolys());
-		//}
+		}
 	}
 }
@@ -4814,14 +4834,19 @@
 	// compute max height difference
 	for (int i = 0; i < (int)leaves.size(); ++ i)
+	{
 		for (int j = 0; j < (int)leaves.size(); ++ j)
-	{
-		BspLeaf *leaf = dynamic_cast<BspViewCell *>(leaves[i])->mLeaf;
-
-		if (i != j)
-		{
-			BspLeaf *leaf2 =dynamic_cast<BspViewCell *>(leaves[j])->mLeaf;
-			int dist = mVspBspTree->TreeDistance(leaf, leaf2);
-			if (dist > maxDist)
-				maxDist = dist;
+		{
+			BspLeaf *leaf = dynamic_cast<BspViewCell *>(leaves[i])->mLeaf;
+
+			if (i != j)
+			{
+
+				BspLeaf *leaf2 =dynamic_cast<BspViewCell *>(leaves[j])->mLeaf;
+				
+				int dist = mVspBspTree->TreeDistance(leaf, leaf2);
+				
+				if (dist > maxDist)
+					maxDist = dist;
+			}
 		}
 	}
@@ -4850,10 +4875,8 @@
 	mVspBspTree->ConstructGeometry(vc, geom);
 	
-	Mesh *mesh = new Mesh();
+	Mesh *mesh = MeshManager::GetSingleton()->CreateResource();
 	IncludeNodeGeomInMesh(geom, *mesh);
 
 	vc->SetMesh(mesh);
-	// put mesh into mesh container so we can savely delete it
-	mMeshContainer.push_back(mesh);
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 1000)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 1001)
@@ -1,3 +1,5 @@
 #include "Mesh.h"
+#include "glInterface.h"
+#include "OcclusionQuery.h"
 #include "GlRenderer.h"
 #include "ViewCellsManager.h"
@@ -9,8 +11,11 @@
 #include "Environment.h"
 
+
 //#define GL_GLEXT_PROTOTYPES
-#include <GL/glext.h>
+
+
 #include <Cg/cg.h>
 #include <Cg/cgGL.h>
+
 
 #include <QVBoxLayout>
@@ -26,21 +31,37 @@
 
 const int depthMapSize = 512;
-static vector<int> sQueries;
+static vector<OcclusionQuery *> sQueries;
 
 GlRendererWidget *rendererWidget = NULL;
 GlDebuggerWidget *debuggerWidget = NULL;
 
-
-#ifdef _WIN32
-PFNGLGENOCCLUSIONQUERIESNVPROC glGenOcclusionQueriesNV;
-PFNGLBEGINOCCLUSIONQUERYNVPROC glBeginOcclusionQueryNV;
-PFNGLENDOCCLUSIONQUERYNVPROC glEndOcclusionQueryNV;
-PFNGLGETOCCLUSIONQUERYUIVNVPROC glGetOcclusionQueryuivNV;
-
-//PFNGLGENQUERIESARBPROC glGenQueriesARB;
-//PFNGLBEGINQUERYARBPROC glBeginQueryARB;
-//PFNGLENDQUERYARBPROC glEndQueryARB;
-//PFNGLGETQUERYUIVARBPROC glGetQueryuivARB;
-#endif
+static bool arbQuerySupport = false;
+static bool nvQuerySupport = false;
+
+
+static void InitExtensions() 
+{
+	GLenum err = glewInit();
+
+	if (GLEW_OK != err) 
+	{
+		// problem: glewInit failed, something is seriously wrong
+		cerr << "Error: " << glewGetErrorString(err) << endl;
+		exit(1);
+	}
+
+	if (GLEW_ARB_occlusion_query) 
+		arbQuerySupport = true;
+	
+	if (GLEW_NV_occlusion_query) 
+		nvQuerySupport = true;
+	
+
+	if  (!arbQuerySupport && !nvQuerySupport)
+	{
+		cout << "I require the GL_ARB_occlusion_query or the GL_NV_occlusion_query OpenGL extension to work.\n";
+		exit(1);
+	}
+}
 
 
@@ -71,5 +92,5 @@
 
   mUseGlLists = true;
-  
+  //mUseGlLists = false;
 }
 
@@ -82,4 +103,7 @@
 	cgDestroyContext(sCgContext);
   cerr<<"done."<<endl;
+   
+  CLEAR_CONTAINER(sQueries);
+  CLEAR_CONTAINER(mOcclusionQueries);
 }
 
@@ -107,4 +131,7 @@
 	  RenderViewCell(dynamic_cast<ViewCell *>(object));
 	  break;
+  case Intersectable::TRANSFORMED_MESH_INSTANCE:
+	  RenderTransformedMeshInstance(dynamic_cast<TransformedMeshInstance *>(object));
+	  break;
   default:
 	cerr<<"Rendering this object not yet implemented\n";
@@ -151,4 +178,39 @@
 }
 
+
+void
+GlRenderer::RenderTransformedMeshInstance(TransformedMeshInstance *mi)
+{
+	// apply world transform before rendering
+	Matrix4x4 m;
+	mi->GetWorldTransform(m);
+
+	glPushMatrix();
+/*
+	cout << "\n*******" << endl;
+	for (int i = 0; i < 16; ++ i)
+		cout << (float *)(m.x)[i] << " ";
+	
+	cout << "\n*******" << endl;
+	for (int i = 0; i < 4; ++ i)
+		for (int j = 0; j < 4; ++ j)
+			cout << m.x[i][j] << " ";
+
+cout << "\n==" << endl;*/
+
+	glMultMatrixf((float *)m.x);
+	GLfloat dummy[16];
+
+	/*glGetFloatv(GL_MODELVIEW_MATRIX, dummy);
+
+	for (int i = 0; i < 16; ++ i)
+		cout << dummy[i] << " ";
+	cout << endl;*/
+	RenderMesh(mi->GetMesh());
+	
+	glPopMatrix();
+}
+
+
 void
 GlRenderer::SetupFalseColor(const int id)
@@ -207,27 +269,7 @@
   glEnable(GL_CULL_FACE);
   
-  glGenOcclusionQueriesNV = (PFNGLGENOCCLUSIONQUERIESNVPROC)
-	wglGetProcAddress("glGenOcclusionQueriesNV");
-  glBeginOcclusionQueryNV = (PFNGLBEGINOCCLUSIONQUERYNVPROC)
-	wglGetProcAddress("glBeginOcclusionQueryNV");
-  glEndOcclusionQueryNV = (PFNGLENDOCCLUSIONQUERYNVPROC)
-	wglGetProcAddress("glEndOcclusionQueryNV");
-  glGetOcclusionQueryuivNV = (PFNGLGETOCCLUSIONQUERYUIVNVPROC)
-	wglGetProcAddress("glGetOcclusionQueryuivNV");
-
-
-#if 0
-  glGenQueriesARB = (PFNGLGENDQUERIESARBPROC)
-	wglGetProcAddress("glGenQueriesARB");
-  glBeginQueryARB = (PFNGLBEGINQUERYARBPROC)
-	wglGetProcAddress("glBeginQueryARB");
-  glEndQueryARB = (PFNGLENDQUERYARBPROC)
-	wglGetProcAddress("glEndQueryARB");
-  glGetQueryuivARB = (PFNGLGETQUERYUIVARBPROC)
-	wglGetProcAddress("glGetQueryuivARB");
-
-#endif
-  
-
+  // HACK!! but using glew keeps crashing for some reason ...
+  InitExtensions();
+  
 #if 0
   GLfloat mat_ambient[]   = {  0.5, 0.5, 0.5, 1.0  };
@@ -445,5 +487,5 @@
 void
 GlRendererBuffer::EvalQueryWithItemBuffer(
-									   //RenderCostSample &sample
+										  //RenderCostSample &sample
 									   )
 {
@@ -470,5 +512,5 @@
 }
 
-std::ofstream outfile("try_100.txt");
+//std::ofstream outfile("try_arb.txt");
 void
 GlRendererBuffer::EvalQueryWithOcclusionQueries(
@@ -483,65 +525,80 @@
 
 	// simulate detectemptyviewspace using backface culling
-	/*if (mDetectEmptyViewSpace) 
+	if (mDetectEmptyViewSpace) 
 	{
 		glEnable(GL_CULL_FACE);
-		cout << "culling" << endl;
+		//cout << "culling" << endl;
 	}
 	else
 	{
-		cout << "not culling" << endl;
+		//cout << "not culling" << endl;
 		glDisable(GL_CULL_FACE);
-	}*/
-
-	
-	const int numQ = 500;//(int)mOcclusionQueries.size();
-	
-//outfile << "\n**************" << endl;
-glFinish();
+	}
+
+	
+	//const int numQ = 1;
+	const int numQ = (int)mOcclusionQueries.size();
+	
+	//glFinish();
+#if 0
 	//-- now issue queries for all objects
 	for (int j = 0; j < (int)mObjects.size(); ++ j) 
+	{
+		mOcclusionQueries[j]->BeginQuery();
+		RenderIntersectable(mObjects[j]);
+		mOcclusionQueries[j]->EndQuery();
+
+		unsigned int pixelCount;
+
+		pixelCount = mOcclusionQueries[j]->GetQueryResult();
+		mObjects[j]->mCounter += pixelCount;
+	}
+#else
+
+	int q = 0;
+
+	//-- now issue queries for all objects
+	for (int j = 0; j < (int)mObjects.size(); j += q) 
 	{	
-		for (int q = 0; ((j + q) < (int)mObjects.size()) && (q < numQ); ++ q) 
+		for (q = 0; ((j + q) < (int)mObjects.size()) && (q < numQ); ++ q) 
 		{
 			//glFinish();
-//			outfile << "queries: " << mOcclusionQueries[q] << " ";
-			glBeginOcclusionQueryNV(mOcclusionQueries[q]);
+			mOcclusionQueries[q]->BeginQuery();
 			
 			RenderIntersectable(mObjects[j + q]);
 		
-			glFlush();
-			glEndOcclusionQueryNV();
+			mOcclusionQueries[q]->EndQuery();
 			//glFinish();
 		}
-
-//		outfile << endl;
+		//cout << "q: " << q << endl;
 		// collect results of the queries
-		for (int q = 0; ((j + q) < (int)mObjects.size()) && (q < numQ); ++ q) 
+		for (int t = 0; t < q; ++ t) 
 		{
 			unsigned int pixelCount;
-					
+		
 			//-- reenable other state
-#if 1
+#if 0
+			bool available;
+
 			do 
 			{
-				glGetOcclusionQueryuivNV(mOcclusionQueries[q], GL_PIXEL_COUNT_AVAILABLE_NV, &pixelCount);
-					
-				if (pixelCount == 0) cout << "W";
+				available = mOcclusionQueries[t]->ResultAvailable();
+				
+				if (!available) cout << "W";
 			} 
-			while (!pixelCount);
+			while (!available);
 #endif
 
-			glGetOcclusionQueryuivNV(mOcclusionQueries[q], GL_PIXEL_COUNT_NV, &pixelCount);
-
-			if (pixelCount > 0)
-				outfile <<"o="<<j+q<<" q="<<mOcclusionQueries[q]<<" pc="<<pixelCount<<" ";
-			
-			mObjects[j + q]->mCounter += pixelCount;
+			pixelCount = mOcclusionQueries[t]->GetQueryResult();
+
+			//if (pixelCount > 0)
+			//	cout <<"o="<<j+q<<" q="<<mOcclusionQueries[q]->GetQueryId()<<" pc="<<pixelCount<<" ";
+			mObjects[j + t]->mCounter += pixelCount;
 		}
 
-		j += q;
-	}
-
-glFinish();
+		//j += q;
+	}
+#endif
+	//glFinish();
 	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
 	glDepthMask(GL_TRUE);
@@ -552,6 +609,7 @@
 
 void
-GlRendererBuffer::EvalRenderCostSample(
-									   RenderCostSample &sample
+GlRendererBuffer::EvalRenderCostSample(RenderCostSample &sample,
+									   const bool useOcclusionQueries,
+									   const int threshold
 									   )
 {
@@ -575,4 +633,5 @@
 	int i, j;
 
+	// reset object counters
 	ObjectContainer::const_iterator it, it_end = mObjects.end();
 
@@ -584,14 +643,10 @@
 	++ mFrame;
 
-	// either use occlusion queries or item buffer
-	bool useOcclusionQueries;
-	environment->GetBoolValue("RenderSampler.useOcclusionQueries", useOcclusionQueries);
-
-	//if (useOcclusionQueries) cout << "using occlusion queries" << endl;
-	//else cout << "using item buffer" << endl;
-	
 	//glCullFace(GL_FRONT);
 	glCullFace(GL_BACK);
-
+	glDisable(GL_CULL_FACE);
+	
+
+	// query all 6 directions for a full point sample
 	for (i = 0; i < 6; ++ i) 
 	{
@@ -601,8 +656,11 @@
 		glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
 		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+		//glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);	glDepthMask(GL_TRUE);
 		glDepthFunc(GL_LESS);
+
 		mUseFalseColors = true;
 
-		// the actual scene rendering
+		// the actual scene rendering fills the depth (for occlusion queries)
+		// and the frame buffer (for item buffer)
 		RenderScene();
 
@@ -616,4 +674,5 @@
 		}
          
+		// evaluate the sample
 		if (useOcclusionQueries) 
 		{
@@ -633,5 +692,5 @@
 	{
 		Intersectable *obj = *it;
-		if (obj->mCounter) 
+		if (obj->mCounter >= threshold) 
 		{
 			++ sample.mVisibleObjects;
@@ -640,12 +699,13 @@
 	}
 
-	outfile << "RS=" << sample.mVisibleObjects << " ";
-}
-
-
-void
-GlRendererBuffer::SampleRenderCost(
-								   const int n,
-								   vector<RenderCostSample> &samples
+	//cout << "RS=" << sample.mVisibleObjects << " ";
+}
+
+
+void
+GlRendererBuffer::SampleRenderCost(const int numSamples,
+								   vector<RenderCostSample> &samples,
+								   const bool useOcclusionQueries,
+								   const int threshold
 								   )
 {
@@ -655,47 +715,25 @@
 	  mPixelBuffer = new unsigned int[GetWidth()*GetHeight()];
   
+  // using 90 degree projection to capture 360 view with 6 samples
   SetupProjection(GetHeight(), GetHeight(), 90.0f);
 
-  samples.resize(n);
+  samples.resize(numSamples);
   halton.Reset();
   
-  // the number of queries simultanosly allocated
-  const int numQ = 400;
-  //const int numQ = 3;
-#if 1
-  for (int i = (int)mOcclusionQueries.size(); i < numQ; ++ i)
+  // the number of queries queried in batch mode
+  const int numQ = 500;
+  //const int numQ = (int)mObjects.size();
+  if (useOcclusionQueries)
   {
-	  unsigned int query;
-	  glGenOcclusionQueriesNV(1, &query);
-	  mOcclusionQueries.push_back(query);
-	  //mOcclusionQueries[i] = queries[i];
-  }
-#else
-  if ((int)mOcclusionQueries.size() < numQ)
+	  cout << "\ngenerating " << numQ << " queries ... ";
+	  OcclusionQuery::GenQueries(mOcclusionQueries, numQ);
+	  cout << "finished" << endl;
+  }
+
+  // sampling queries 
+  for (int i = 0; i < numSamples; ++ i)
   {
-	  cout << "allocating occ queries..." << endl;
-	
-	  unsigned int *queries = new unsigned int[numQ];
-	  
-	  // matt: ?
-	  for (int i = 0; i < numQ; ++ i)
-          queries[i] = 111;
-	
-	  glGenOcclusionQueriesNV(numQ, queries);
-	  mOcclusionQueries.resize(numQ);
-	  
-    
-	   for (int i = 0; i < numQ; ++ i)
-	   {
-		   mOcclusionQueries[i] = queries[i];
-	   }
-
-	   DEL_PTR(queries);
-  }
-#endif
-  
-  for (int i = 0; i < n; ++ i)
-  {
-	  EvalRenderCostSample(samples[i]);
+	  cout << ".";
+	  EvalRenderCostSample(samples[i], useOcclusionQueries, threshold);
   }
 
@@ -707,7 +745,5 @@
 void
 GlRendererBuffer::RandomViewPoint()
-{
-  
-  
+{ 
   // do not use this function since it could return different viewpoints for
   // different executions of the algorithm
@@ -770,10 +806,11 @@
   
   mUseFalseColors = false;
-
-  static int query = -1;
   unsigned int pixelCount;
 
-  if (query == -1)
-	glGenOcclusionQueriesNV(1, (unsigned int *)&query);
+  //static int query = -1;
+  //if (query == -1)
+//	  glGenOcclusionQueriesNV(1, (unsigned int *)&query);
+
+  OcclusionQuery query;
 
   if (mDetectEmptyViewSpace) {
@@ -789,9 +826,9 @@
 	glDisable( GL_CULL_FACE );
 	
-	glBeginOcclusionQueryNV(query);
+	query.BeginQuery();
 	
 	RenderScene();
 	
-	glEndOcclusionQueryNV();
+	query.EndQuery();
 	
 	// at this point, if possible, go and do some other computation
@@ -801,7 +838,5 @@
 	
 	// reenable other state
-	glGetOcclusionQueryuivNV(query,
-							 GL_PIXEL_COUNT_NV,
-							 &pixelCount);
+	pixelCount = query.GetQueryResult();
 	
 	if (pixelCount > 0)
@@ -842,5 +877,5 @@
 	mUseFalseColors = true;
 
-	glBeginOcclusionQueryNV(query);
+	query.BeginQuery();
 
 	SetupCamera();
@@ -848,12 +883,11 @@
 	RenderScene();
 	
-	glEndOcclusionQueryNV();
+	query.EndQuery();
 	
 
 	unsigned int pixelCount;
 	// reenable other state
-	glGetOcclusionQueryuivNV(query,
-							 GL_PIXEL_COUNT_NV,
-							 &pixelCount);
+	pixelCount = query.GetQueryResult();
+	
 	
 	pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight());
@@ -1117,4 +1151,5 @@
 {
   ObjectContainer::const_iterator oi = mObjects.begin();
+
   for (; oi != mObjects.end(); oi++)
 	RenderIntersectable(*oi);
@@ -1902,5 +1937,5 @@
 
 	// create new queries if necessary
-	GenQueries((int)beam.mViewCells.size());
+	OcclusionQuery::GenQueries(sQueries, (int)beam.mViewCells.size());
 
 	// check whether any backfacing polygon would pass the depth test?
@@ -1919,9 +1954,11 @@
 	for (vit = beam.mViewCells.begin(); vit != vit_end; ++ vit)
 	{
-		glBeginOcclusionQueryNV(sQueries[queryIdx ++]);
+		sQueries[queryIdx ++]->BeginQuery();
 
 		RenderIntersectable(*vit);
 		
-		glEndOcclusionQueryNV();
+		sQueries[queryIdx]->EndQuery();
+
+		++ queryIdx;
 	}
 
@@ -1937,12 +1974,10 @@
 
 	queryIdx = 0;
-	unsigned int pixelCount;
 
 	for (vit = beam.mViewCells.begin(); vit != vit_end; ++ vit)
 	{
 		// fetch queries
-		glGetOcclusionQueryuivNV(sQueries[queryIdx ++],
-								 GL_PIXEL_COUNT_NV,
-								 &pixelCount);
+		unsigned int pixelCount = sQueries[queryIdx ++]->GetQueryResult();
+
 		if (pixelCount)
 			Debug << "view cell " << (*vit)->GetId() << " visible pixels: " << pixelCount << endl;
@@ -1991,23 +2026,4 @@
 	if (beam.mFlags & !Beam::STORE_OBJECTS)
 		beam.mObjects.clear();
-}
-
-
-void GlRendererBuffer::GenQueries(const int numQueries)
-{
-	if ((int)sQueries.size() < numQueries)
-	{
-		const int n = numQueries - (int)sQueries.size();
-		unsigned int *newQueries = new unsigned int[n];
-
-		glGenOcclusionQueriesNV(n, (unsigned int *)newQueries);
-
-		for (int i = 0; i < n; ++ i)
-		{
-			sQueries.push_back(newQueries[i]);
-		}
-
-		delete [] newQueries;
-	}
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/X3dParserXerces.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/X3dParserXerces.h	(revision 971)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/X3dParserXerces.h	(revision 1001)
@@ -22,18 +22,20 @@
 
 
-struct ltstr
-{
-  bool operator()(const string &s1, const string &s2) const
-  {
-    return s1 < s2;
-  }
-};
-
-typedef map<string, Mesh *, ltstr> MeshDefinitions;
-typedef map<string, Material *, ltstr> MaterialDefinitions;
 
 class X3dParseHandlers : public HandlerBase
 {
 public:
+
+	// used for generating name / key pair
+	struct ltstr
+	{
+		bool operator()(const std::string &s1, const std::string &s2) const
+		{
+			return s1 < s2;
+		}
+	};
+
+	typedef map<string, int, ltstr> ResourceDefinitions;
+
   // -----------------------------------------------------------------------
   //  Constructors and Destructor
@@ -77,8 +79,10 @@
 
   SceneGraphNode *mCurrentNode;
-  Mesh *mCurrentMesh;
+ 
   vector<VertexIndexContainer> mCurrentVertexIndices;
   VertexContainer mCurrentVertices;
-  string mCurrentMeshName;
+
+  //string mCurrentMeshName;
+  Mesh *mCurrentMesh;
 
   Material *mCurrentMaterial;
@@ -89,13 +93,13 @@
 
   bool mUsingMeshDefinition;
+
   // stack of accumulated transformations
   TrafoStack mTransformations;
 
-  MaterialDefinitions mMaterialDefinitions;
-  MeshDefinitions mMeshDefinitions;
-
-  // TODO: for storing meshes
-  MeshContainer *mMeshes;
+  ResourceDefinitions mMaterialDefinitions;
+  ResourceDefinitions mMeshDefinitions;
+
   bool mIsMeshDefinition;
+
   // Handlers for X3D
   void
@@ -122,5 +126,7 @@
   /// transforms mesh using the given transformations
   void ApplyTransformations(TrafoStack trafos, Mesh *mesh) const;
-
+  void ApplyTransformations(TrafoStack trafos, TransformedMeshInstance *mi) const;
+
+  static int mUniqueMeshIdx;
 
   // -----------------------------------------------------------------------
@@ -200,5 +206,6 @@
 
   VertexIndexContainer mCurrentVertexIndices;
- 
+  VertexContainer mCurrentVertices;
+
   // Handlers for X3D
   void
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp	(revision 991)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp	(revision 1001)
@@ -3,4 +3,5 @@
 #include "MeshKdTree.h"
 #include "Triangle3.h"
+#include "ResourceManager.h"
 
 namespace GtpVisibilityPreprocessor {
@@ -432,8 +433,7 @@
 int
 Mesh::GetRandomVisibleSurfacePoint(Vector3 &point,
-																	 Vector3 &normal,
-																	 const Vector3 &viewpoint,
-																	 const int maxTries
-																	 )
+								   Vector3 &normal,
+								   const Vector3 &viewpoint,
+								   const int maxTries)
 {
   Plane3 plane;
@@ -463,50 +463,4 @@
 
 
-int
-MeshInstance::CastRay(
-					  Ray &ray
-					  )
-{
-  int res = mMesh->CastRay(ray, this);
-  return res;
-}
-
-int
-MeshInstance::CastRay(
-					  Ray &ray,
-					  const vector<int> &faces
-					  )
-{
-  return mMesh->CastRayToSelectedFaces(ray, faces, this);
-}
-
-
-
-int
-MeshInstance::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal)
-{
-  return mMesh->GetRandomSurfacePoint(point, normal);
-}
-
-int
-MeshInstance::GetRandomVisibleSurfacePoint(Vector3 &point,
-																					 Vector3 &normal,
-																					 const Vector3 &viewpoint,
-																					 const int maxTries
-																					 )
-{
-	return mMesh->GetRandomVisibleSurfacePoint(point, normal, viewpoint, maxTries);
-}
-
-
-int
-TransformedMeshInstance::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal)
-{
-  int index = mMesh->GetRandomSurfacePoint(point, normal);
-  point = mWorldTransform*point;
-  normal = TransformNormal(mWorldTransform, normal);
-  return index;
-}
-
 Plane3
 Mesh::GetFacePlane(const int faceIndex)
@@ -554,8 +508,211 @@
 }
 
-int
-TransformedMeshInstance::CastRay(
-								 Ray &ray
-								 )
+
+void
+Mesh::AddTriangle(const Triangle3 &triangle)
+{
+  int index = (int)mVertices.size();
+
+  for (int i=0; i < 3; i++) {
+    mVertices.push_back(triangle.mVertices[i]);
+  }
+  
+  AddFace(new Face(index + 0, index + 1, index + 2) );
+}
+
+void
+Mesh::AddRectangle(const Rectangle3 &rect)
+{
+  int index = (int)mVertices.size();
+
+  for (int i=0; i < 4; i++) {
+    mVertices.push_back(rect.mVertices[i]);
+  }
+  
+  AddFace(new Face(index + 0, index + 1, index + 2, index + 3) );
+}
+
+void
+Mesh::AssignRandomMaterial()
+{  
+	mMaterial = MaterialManager::GetSingleton()->CreateResource();
+  
+	Material randMat = RandomMaterial();
+
+	mMaterial->mDiffuseColor = randMat.mDiffuseColor;
+	mMaterial->mSpecularColor = randMat.mSpecularColor;
+	mMaterial->mAmbientColor = randMat.mAmbientColor;
+}
+
+
+Mesh *CreateMeshFromBox(const AxisAlignedBox3 &box)
+{
+	Mesh *mesh = MeshManager::GetSingleton()->CreateResource();
+
+	// add 8 vertices of the box
+	const int index = (int)mesh->mVertices.size();
+	
+	for (int i=0; i < 8; ++ i) 
+	{
+        Vector3 v;
+		box.GetVertex(i, v);
+		mesh->mVertices.push_back(v);
+	}
+
+	mesh->AddFace(new Face(index + 0, index + 1, index + 3, index + 2) );
+	mesh->AddFace(new Face(index + 0, index + 2, index + 6, index + 4) );
+	mesh->AddFace(new Face(index + 4, index + 6, index + 7, index + 5) );
+  
+	mesh->AddFace(new Face(index + 3, index + 1, index + 5, index + 7) );
+	mesh->AddFace(new Face(index + 0, index + 4, index + 5, index + 1) );
+	mesh->AddFace(new Face(index + 2, index + 3, index + 7, index + 6) );
+  
+	return mesh;
+}
+
+
+Mesh::Mesh(const int id, const int vertices, const int faces):
+mFaces(),
+mMaterial(NULL),
+mKdTree(NULL),
+mVertices(),
+mIsConvex(false),
+mIsWatertight(false),
+mId(id)
+{
+    mVertices.reserve(vertices);
+    mFaces.reserve(faces);
+}
+
+
+Mesh::Mesh(const int id): 
+mId(id), mVertices(), mFaces(), mMaterial(NULL), mKdTree(NULL) 
+{}
+
+
+// apply transformation to each vertex
+void Mesh::ApplyTransformation(const Matrix4x4 &m)
+{
+	VertexContainer::iterator it, it_end = mVertices.end();
+
+	for (it = mVertices.begin(); it != it_end; ++ it)
+	{
+		(*it) = m * (*it);        
+	}
+}
+
+
+Mesh::Mesh(const Mesh &rhs)
+{
+	mVertices = rhs.mVertices;
+	mFaces.reserve(rhs.mFaces.size());
+	mId = rhs.mId;
+
+	FaceContainer::const_iterator it, it_end = rhs.mFaces.end();
+
+	for (it = rhs.mFaces.begin(); it != it_end; ++ it)
+	{
+		Face *face = *it;
+		mFaces.push_back(new Face(*face));
+	}
+}
+
+
+Mesh& Mesh::operator=(const Mesh& m) 
+{
+    if (this == &m) 
+		return *this;
+ 
+	CLEAR_CONTAINER(mFaces);
+
+	mVertices = m.mVertices;
+	mFaces.reserve(m.mFaces.size());
+	//mId = m.mId;
+
+	FaceContainer::const_iterator it, it_end = m.mFaces.end();
+
+	for (it = m.mFaces.begin(); it != it_end; ++ it)
+	{
+		Face *face = *it;
+		mFaces.push_back(new Face(*face));
+	}
+
+	return *this;
+}
+
+
+
+/********************************************************/
+/*	    		MeshInstance implementation             */
+/********************************************************/
+
+int
+MeshInstance::CastRay(
+					  Ray &ray
+					  )
+{
+  int res = mMesh->CastRay(ray, this);
+  return res;
+}
+
+int
+MeshInstance::CastRay(
+					  Ray &ray,
+					  const vector<int> &faces
+					  )
+{
+  return mMesh->CastRayToSelectedFaces(ray, faces, this);
+}
+
+
+
+int
+MeshInstance::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal)
+{
+  return mMesh->GetRandomSurfacePoint(point, normal);
+}
+
+int
+MeshInstance::GetRandomVisibleSurfacePoint(Vector3 &point,
+										   Vector3 &normal,
+										   const Vector3 &viewpoint,
+										   const int maxTries)
+{
+	return mMesh->GetRandomVisibleSurfacePoint(point, normal, viewpoint, maxTries);
+}
+
+
+void MeshInstance::SetMaterial(Material *mat)
+{
+	mMaterial = mat;
+}
+
+Material *MeshInstance::GetMaterial() const
+{
+	return mMaterial;
+}
+
+
+/*************************************************************/
+/*	  		TransformedMeshInstance implementation		     */
+/*************************************************************/
+
+TransformedMeshInstance::TransformedMeshInstance(Mesh *mesh): 
+MeshInstance(mesh)
+{
+    mWorldTransform = IdentityMatrix();
+}
+
+
+int TransformedMeshInstance::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal)
+{
+  int index = mMesh->GetRandomSurfacePoint(point, normal);
+  point = mWorldTransform*point;
+  normal = TransformNormal(mWorldTransform, normal);
+  return index;
+}
+
+
+int TransformedMeshInstance::CastRay(Ray &ray)
 {
   ray.ApplyTransform(Invert(mWorldTransform));
@@ -567,59 +724,27 @@
 
 
-void
-Mesh::AddTriangle(const Triangle3 &triangle)
-{
-  int index = (int)mVertices.size();
-
-  for (int i=0; i < 3; i++) {
-    mVertices.push_back(triangle.mVertices[i]);
-  }
-  
-  AddFace(new Face(index + 0, index + 1, index + 2) );
-}
-
-void
-Mesh::AddRectangle(const Rectangle3 &rect)
-{
-  int index = (int)mVertices.size();
-
-  for (int i=0; i < 4; i++) {
-    mVertices.push_back(rect.mVertices[i]);
-  }
-  
-  AddFace(new Face(index + 0, index + 1, index + 2, index + 3) );
-}
-
-void
-Mesh::AssignRandomMaterial()
-{
-  if (!mMaterial)
-	mMaterial = new Material;
-  *mMaterial = RandomMaterial();
-
-}
-
-
-Mesh *CreateMeshFromBox(const AxisAlignedBox3 &box)
-{
-	Mesh *mesh = new Mesh;
-  // add 8 vertices of the box
-  int index = (int)mesh->mVertices.size();
-  for (int i=0; i < 8; i++) {
-    Vector3 v;
-    box.GetVertex(i, v);
-    mesh->mVertices.push_back(v);
-  }
-  
-  mesh->AddFace(new Face(index + 0, index + 1, index + 3, index + 2) );
-  mesh->AddFace(new Face(index + 0, index + 2, index + 6, index + 4) );
-  mesh->AddFace(new Face(index + 4, index + 6, index + 7, index + 5) );
-  
-  mesh->AddFace(new Face(index + 3, index + 1, index + 5, index + 7) );
-  mesh->AddFace(new Face(index + 0, index + 4, index + 5, index + 1) );
-  mesh->AddFace(new Face(index + 2, index + 3, index + 7, index + 6) );
-  
-  return mesh;
-}
-
-}
+void TransformedMeshInstance::ApplyWorldTransform(const Matrix4x4 &m)
+{
+	mWorldTransform = m * mWorldTransform;
+}
+
+
+void TransformedMeshInstance::LoadWorldTransform(const Matrix4x4 &m)
+{
+	mWorldTransform = m;
+}
+
+
+void TransformedMeshInstance::GetWorldTransform(Matrix4x4 &m)
+{
+	m = mWorldTransform;
+}
+
+
+AxisAlignedBox3 TransformedMeshInstance::GetBox() 
+{
+    return Transform(mMesh->mBox, mWorldTransform);
+}
+
+
+}
