Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.h	(revision 3056)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.h	(revision 3057)
@@ -27,5 +27,5 @@
 	/** Returns the resource manager as a singleton.
 	*/
-	static ShaderManager *GetSingleton();
+	inline static ShaderManager *GetSingleton();
 	/** We also want full control over the delete.
 	*/
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.cpp	(revision 3056)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderManager.cpp	(revision 3057)
@@ -179,11 +179,9 @@
 		                  isFragment ? sCgFragmentProfile : sCgVertexProfile, funcName);
 
-	ShaderMap::const_iterator it = mShaderMap.find(name);
-
-	if (it == mShaderMap.end())
+	if (GetShaderProgram(name))
 	{
+		cerr << "Program name " << name << "already chosen" << endl;
+
 		DEL_PTR(p);
-
-		cerr << "Program name " << name << "already chosen" << endl;
 		return p;
 	}
@@ -191,9 +189,12 @@
 	if (!p->IsValid())
 	{
+		cerr << "Program " << funcName << " in " << fullName << " failed to load" << endl;
+
 		DEL_PTR(p);
-		cerr << "Program " << funcName << " in " << fullName << " failed to load" << endl;
 		return p;
 	}
 
+	
+	// everything ok
 	cout << "Program " << funcName << " in " << fullName << " loaded" << endl;
 		
@@ -205,4 +206,15 @@
 
 
-}
-
+ShaderProgram *ShaderManager::GetShaderProgram(const std::string &name)
+{
+	ShaderMap::const_iterator it = mShaderMap.find(name);
+
+	if (it == mShaderMap.end())
+		return NULL;
+	
+	return (*it).second;
+}
+
+
+}
+
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3050)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3057)
@@ -4,5 +4,5 @@
 #include "ShaderProgram.h"
 #include "Texture.h"
-#include "ResourceManager.h"
+#include "ShaderManager.h"
 
 
@@ -67,6 +67,6 @@
 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 
-	ResourceManager::GetSingleton()->DisableFragmentProfile();
-	ResourceManager::GetSingleton()->DisableVertexProfile();
+	ShaderManager::GetSingleton()->DisableFragmentProfile();
+	ShaderManager::GetSingleton()->DisableVertexProfile();
 
 	mFragmentProgramEnabled = false;
@@ -219,5 +219,5 @@
 		{
 			mFragmentProgramEnabled = true;
-			ResourceManager::GetSingleton()->EnableFragmentProfile();
+			ShaderManager::GetSingleton()->EnableFragmentProfile();
 		}
 
@@ -235,5 +235,5 @@
 		{
 			mFragmentProgramEnabled = false;
-			ResourceManager::GetSingleton()->DisableFragmentProfile();
+			ShaderManager::GetSingleton()->DisableFragmentProfile();
 		}
 	}
@@ -246,5 +246,5 @@
 		{
 			mVertexProgramEnabled = true;
-			ResourceManager::GetSingleton()->EnableVertexProfile();
+			ShaderManager::GetSingleton()->EnableVertexProfile();
 		}
 
@@ -262,5 +262,5 @@
 		{
 			mVertexProgramEnabled = false;
-			ResourceManager::GetSingleton()->DisableVertexProfile();
+			ShaderManager::GetSingleton()->DisableVertexProfile();
 		}
 	}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3055)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3057)
@@ -12,6 +12,5 @@
 #include "RenderState.h"
 #include "ShaderProgram.h"
-#include <Cg/cg.h>
-#include <Cg/cgGL.h>
+#include "ShaderManager.h"
 
 
@@ -34,39 +33,10 @@
 
 
-/////////
-//-- cg stuff
-
-static CGcontext sCgContext = NULL;
-
-static CGprofile sCgFragmentProfile;
-static CGprofile sCgVertexProfile; 
-
-static ShaderProgram *sTreeAnimationProgramMrt;
-static ShaderProgram *sTreeAnimationProgram;
-
-
 // only instance of the resource manager
 ResourceManager *ResourceManager::sResourceManager = NULL;
 
 
-static void cgErrorCallback()
-{
-	CGerror lastError = cgGetError();
-
-	if(lastError)
-	{
-		printf("%s\n\n", cgGetErrorString(lastError));
-		printf("%s\n", cgGetLastListing(sCgContext));
-		
-		printf("Cg error, exiting...\n");
-
-		exit(0);
-	}
-}
-
-
 ResourceManager::ResourceManager()
 { 
-	InitCg(); 
 }
 
@@ -82,9 +52,4 @@
 	CLEAR_CONTAINER(mShapes);
 	CLEAR_CONTAINER(mLODs);
-	CLEAR_CONTAINER(mGPUParameters);
-	CLEAR_CONTAINER(mShaders);
-	
-	if (sCgContext)
-		cgDestroyContext(sCgContext);
 }
 
@@ -160,4 +125,7 @@
 		sceneGeom->AddLODLevel(lodLevel);
 	}
+
+	static ShaderProgram *sTreeAnimationProgram = ShaderManager::GetSingleton()->GetShaderProgram("treeAnimation");
+	static ShaderProgram *sTreeAnimationProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("treeAnimationMrt");
 
 	///////////
@@ -310,9 +278,13 @@
 	//-- add technique for deferred shading
 
+	static ShaderProgram *sDefaultFragmentProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("defaultFragmentMrt");
+	static ShaderProgram *sDefaultFragmentTexProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("defaultFragmentTexMrt");
+	static ShaderProgram *sDefaultVertexProgramMrt = ShaderManager::GetSingleton()->GetShaderProgram("defaultVertexMrt");
+
 	Technique *deferred = new Technique(*tech);
 
 	if (deferred->GetTexture())
 	{
-		deferred->SetFragmentProgram(mMrtDefaultFragmentTexProgram);
+		deferred->SetFragmentProgram(sDefaultFragmentTexProgramMrt);
 		deferred->GetFragmentProgramParameters()->SetViewMatrixParam(0);
 		deferred->GetFragmentProgramParameters()->SetTexture(1, tech->GetTexture()->GetId());
@@ -320,9 +292,9 @@
 	else
 	{
-		deferred->SetFragmentProgram(mMrtDefaultFragmentProgram);
+		deferred->SetFragmentProgram(sDefaultFragmentTexProgramMrt);
 		deferred->GetFragmentProgramParameters()->SetViewMatrixParam(0);
 	}
 
-	deferred->SetVertexProgram(mMrtDefaultVertexProgram);
+	deferred->SetVertexProgram(sDefaultVertexProgramMrt);
 	mat->AddTechnique(deferred);
 	
@@ -435,119 +407,4 @@
 }
 
-
-ShaderProgram *ResourceManager::CreateFragmentProgram(const std::string &filename, 
-													  const std::string &funcName)
-{
-	const string fullName = "src/shaders/" + filename + ".cg";
-
-	ShaderProgram *p = new ShaderProgram(sCgContext, fullName, sCgFragmentProfile, funcName);
-	mShaders.push_back(p);
-
-	if (!p->IsValid())
-	{
-		DEL_PTR(p);
-		cerr << "Program " << funcName << " in " << fullName << " failed to load" << endl;
-	}
-	
-	cout << "Program " << funcName << " in " << fullName << " loaded" << endl;
-
-	return p;
-}
-
-
-ShaderProgram *ResourceManager::CreateVertexProgram(const std::string &filename, const std::string &funcName)
-{
-	const string fullName = "src/shaders/" + filename + ".cg";
-	
-	ShaderProgram *p = new ShaderProgram(sCgContext, fullName, sCgVertexProfile, funcName);
-	mShaders.push_back(p);
-
-	if (!p->IsValid())
-	{
-		DEL_PTR(p);
-		cerr << "Program " << funcName << " in " << fullName << " failed to load" << endl;
-	}
-	else
-		cout << "Program " << funcName << " in " << fullName << " loaded" << endl;
-
-	return p;
-}
-
-
-void ResourceManager::InitCg() 
-{
-	// setup cg
-	cgSetErrorCallback(cgErrorCallback);
-	// create context.
-	sCgContext = cgCreateContext();
-	// get the optimal fragment profile
-	sCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
-	cgGLSetOptimalOptions(sCgFragmentProfile);
-	// get the optimal vertex profile
-	sCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);
-	cgGLSetOptimalOptions(sCgVertexProfile);
-
-	// set textures to auto load
-	cgGLSetManageTextureParameters(sCgContext, false);
-
-	mMrtDefaultVertexProgram = CreateVertexProgram("mrt", "vtx");
-	mMrtDefaultFragmentProgram = CreateFragmentProgram("mrt", "frag");
-	mMrtDefaultFragmentTexProgram = CreateFragmentProgram("mrt", "fragtex");
-
-	// provide the current view matrix
-	mMrtDefaultFragmentProgram->AddParameter("viewMatrix", 0);
-	mMrtDefaultFragmentTexProgram->AddParameter("viewMatrix", 0);
-	// add a texture parameter
-	mMrtDefaultFragmentTexProgram->AddParameter("tex", 1);
-
-
-	////////////
-	//-- hack: apply hardcoded tree animation (should be provided with a material script!)
-
-	sTreeAnimationProgram = CreateVertexProgram("treeanimation", "animateVtx");
-	sTreeAnimationProgramMrt = CreateVertexProgram("treeanimation", "animateVtxMrt");
-
-	sTreeAnimationProgram->AddParameter("timer", 0);
-	sTreeAnimationProgram->AddParameter("windDir", 1);
-	sTreeAnimationProgram->AddParameter("windStrength", 2);
-	sTreeAnimationProgram->AddParameter("minMaxPos", 3);
-	sTreeAnimationProgram->AddParameter("frequency", 4);
-	sTreeAnimationProgram->AddParameter("lightDir", 5);
-
-	sTreeAnimationProgramMrt->AddParameter("timer", 0);
-	sTreeAnimationProgramMrt->AddParameter("windDir", 1);
-	sTreeAnimationProgramMrt->AddParameter("windStrength", 2);
-	sTreeAnimationProgramMrt->AddParameter("minMaxPos", 3);
-	sTreeAnimationProgramMrt->AddParameter("frequency", 4);
-
-	cout << "cg initialization successful" << endl;
-}
-
-
-void ResourceManager::EnableFragmentProfile()
-{
-	cgGLEnableProfile(sCgFragmentProfile);
-}
-
-
-void ResourceManager::EnableVertexProfile()
-{
-	cgGLEnableProfile(sCgVertexProfile);
-}
-
-
-void ResourceManager::DisableFragmentProfile()
-{
-	cgGLDisableProfile(sCgFragmentProfile);
-}
-
-
-void ResourceManager::DisableVertexProfile()
-{
-	cgGLDisableProfile(sCgVertexProfile);
-	
-}
-
-
-}
-
+}
+
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 3054)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 3057)
@@ -9,5 +9,5 @@
 #include "Shape.h"
 #include "Material.h"
-#include "ResourceManager.h"
+#include "ShaderManager.h"
 
 
@@ -46,5 +46,5 @@
 {	
 	mSkyVtxProgram = 
-		ResourceManager::GetSingleton()->CreateVertexProgram("sky_preetham", "default_vs");
+		ShaderManager::GetSingleton()->CreateVertexProgram("sky_preetham", "default_vs", "skyVtx");
 		
 	if (mSkyVtxProgram->IsValid())
@@ -64,5 +64,5 @@
 
 	mSkyFragProgram = 
-		ResourceManager::GetSingleton()->CreateFragmentProgram("sky_preetham", "frag_skydome");
+		ShaderManager::GetSingleton()->CreateFragmentProgram("sky_preetham", "frag_skydome", "skyFragMrt");
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h	(revision 3054)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h	(revision 3057)
@@ -1,4 +1,4 @@
-#ifndef __ResourceManager_H__
-#define __ResourceManager_H__
+#ifndef __RESOURCEMANAGER_H__
+#define __RESOURCEMANAGER_H__
 
 
@@ -38,17 +38,4 @@
 	*/
 	int GetNumEntities() const { return (int)mSceneEntities.size(); }
-	/** Creates new gpu program parameters.
-	*/
-	GPUProgramParameters *CreateGPUProgramParameters(ShaderProgram *p);
-	/** Creates a new shader program.
-	*/
-	ShaderProgram *CreateFragmentProgram(const std::string &filename, const std::string &funcName);
-	ShaderProgram *CreateVertexProgram(const std::string &filename, const std::string &funcName);
-
-	void EnableFragmentProfile();
-	void EnableVertexProfile();
-
-	void DisableFragmentProfile();
-	void DisableVertexProfile();
 	/** Returns pointer to shape container.
 	*/
@@ -57,5 +44,4 @@
 	*/
 	const SceneEntityContainer * const GetSceneEntities() const { return &mSceneEntities; }
-
 	/** Returns the resource manager as a singleton.
 	*/
@@ -74,7 +60,4 @@
 
 	~ResourceManager();
-
-
-	void InitCg();
 
 	void LoadTextures(igzstream &str);
@@ -99,19 +82,8 @@
 	GeometryContainer mGeometry;
 	TransformContainer mTrafos;
-	GPUParamContainer mGPUParameters;
-	ShaderContainer mShaders;
 	ShapeContainer mShapes;
 	LODContainer mLODs;
 	/// the scene entities
 	SceneEntityContainer mSceneEntities;
-
-
-	////////////
-	//-- default shader programs
-
-	ShaderProgram *mMrtDefaultVertexProgram;
-	ShaderProgram *mMrtDefaultFragmentProgram;
-	ShaderProgram *mMrtDefaultFragmentTexProgram;
-
 
 private:
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3054)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3057)
@@ -53,5 +53,6 @@
 #include "SkyPreetham.h"
 #include "Texture.h"
-#include "EntityMerger.h"
+//#include "EntityMerger.h"
+#include "ShaderManager.h"
 
 using namespace std;
@@ -75,4 +76,6 @@
 /// handles scene loading
 ResourceManager *loader = NULL;
+/// handles scene loading
+ShaderManager *shaderManager = NULL;
 /// the scene camera
 Camera *camera = NULL;
@@ -419,4 +422,5 @@
 
 	loader = ResourceManager::GetSingleton();
+	shaderManager = ShaderManager::GetSingleton();
 
 	const string filename = string(model_path + "city.dem");
@@ -829,6 +833,6 @@
 	state.SetRenderTechnique(RenderState::DEFERRED);
 
-	loader->EnableVertexProfile();
-	loader->EnableFragmentProfile();
+	shaderManager->EnableVertexProfile();
+	shaderManager->EnableFragmentProfile();
 
 	const Vector3 pos = camera->GetPosition();
@@ -1655,5 +1659,8 @@
 
 	ResourceManager::DelSingleton();
+	ShaderManager::DelSingleton();
+
 	loader = NULL;
+	shaderManager = NULL;
 }
 
@@ -1955,6 +1962,6 @@
 void RenderShadowMap(float newfar)
 {
-	loader->DisableVertexProfile();
-	loader->DisableFragmentProfile();
+	shaderManager->DisableVertexProfile();
+	shaderManager->DisableFragmentProfile();
 
 	glDisableClientState(GL_NORMAL_ARRAY);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3038)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3057)
@@ -9,6 +9,5 @@
 #include "ShadowMapping.h"
 #include "Light.h"
-#include "ResourceManager.h"
-
+#include "ShaderManager.h"
 
 #include <IL/il.h>
@@ -283,17 +282,16 @@
 void DeferredRenderer::InitCg()
 {	
-	ResourceManager *rm = ResourceManager::GetSingleton();
-
-	sCgDeferredProgram = rm->CreateFragmentProgram("deferred", "main");
-	sCgDeferredShadowProgram = rm->CreateFragmentProgram("deferred", "main_shadow");
-	sCgSsaoProgram = rm->CreateFragmentProgram("ssao", "main");
-	sCgGiProgram = rm->CreateFragmentProgram("globillum", "main");
-	sCgCombineIllumProgram = rm->CreateFragmentProgram("globillum", "combine");
-	sCgCombineSsaoProgram = rm->CreateFragmentProgram("ssao", "combine");
-	sCgAntiAliasingProgram = rm->CreateFragmentProgram("antialiasing", "main");
-	sCgToneProgram = rm->CreateFragmentProgram("tonemap", "ToneMap");
-	sCgDownSampleProgram = rm->CreateFragmentProgram("tonemap", "DownSample");
-	sCgToneProgram = rm->CreateFragmentProgram("tonemap", "ToneMap");
-	sCgLogLumProgram = rm->CreateFragmentProgram("tonemap", "CalcAvgLogLum");
+	ShaderManager *sm = ShaderManager::GetSingleton();
+
+	sCgDeferredProgram = sm->CreateFragmentProgram("deferred", "main", "deferredFrag");
+	sCgDeferredShadowProgram = sm->CreateFragmentProgram("deferred", "main_shadow", "deferredFragShader");
+	sCgSsaoProgram = sm->CreateFragmentProgram("ssao", "main", "ssaoFrag");
+	sCgGiProgram = sm->CreateFragmentProgram("globillum", "main", "giFrag");
+	sCgCombineIllumProgram = sm->CreateFragmentProgram("globillum", "combine", "combineGi");
+	sCgCombineSsaoProgram = sm->CreateFragmentProgram("ssao", "combine", "combineSsao");
+	sCgAntiAliasingProgram = sm->CreateFragmentProgram("antialiasing", "main", "antiAliasing");
+	sCgToneProgram = sm->CreateFragmentProgram("tonemap", "ToneMap", "toneMap");
+	sCgDownSampleProgram = sm->CreateFragmentProgram("tonemap", "DownSample", "downSample");
+	sCgLogLumProgram = sm->CreateFragmentProgram("tonemap", "CalcAvgLogLum", "avgLogLum");
 
 	int i;
@@ -403,5 +401,5 @@
 	
 
-	ResourceManager::GetSingleton()->EnableFragmentProfile();
+	ShaderManager::GetSingleton()->EnableFragmentProfile();
 
 	glDisable(GL_ALPHA_TEST);
@@ -475,5 +473,5 @@
 
 	FrameBufferObject::Release();
-	ResourceManager::GetSingleton()->DisableFragmentProfile();
+	ShaderManager::GetSingleton()->DisableFragmentProfile();
 }
 
