Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3031)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3033)
@@ -7,4 +7,97 @@
 namespace CHCDemoEngine 
 { 
+
+
+GPUProgramParameters::GPUProgramParameters(ShaderProgram *p)
+: mProgram(p)
+{
+}
+
+void GPUProgramParameters::SetValue1f(int idx, float value)
+{
+}
+
+
+void GPUProgramParameters::SetValue2f(int idx, float val1, float val2)
+{
+}
+
+
+void GPUProgramParameters::SetValue3f(int idx, float val1, float val, float val3)
+{
+}
+
+
+void GPUProgramParameters::SetArray1f(int idx, float *vals, int numElements)
+{
+}
+
+
+void GPUProgramParameters::SetArray2f(int idx, float *vals, int numElements)
+{
+}
+
+
+void GPUProgramParameters::SetArray3f(int idx, float *vals, int numElements)
+{
+}
+
+
+void GPUProgramParameters::SetTexture(int idx, unsigned int tex)
+{
+}
+
+
+void GPUProgramParameters::SetMatrix(int idx, Matrix4x4 *mat)
+{
+}
+
+
+void GPUProgramParameters::SetValue1f(const string &name, float val)
+{
+	SetValue1f(mProgram->GetParameter(name), val);
+}
+
+
+void ShaderProgram::SetValue2f(const string &name, float val1, float val2)
+{
+	SetValue2f(mProgram->GetParameter(name), val1, val2);
+}
+
+
+void GPUProgramParameters::SetValue3f(const string &name, float val1, float val2, float val3)
+{
+	SetValue3f(mProgram->GetParameter(name), val1, val2, val3);
+}
+
+
+void GPUProgramParameters::SetArray1f(const string &name, float *vals, int numElements)
+{
+	SetArray1f(mProgram->GetParameter(name), numElements, (const float *)vals);
+}
+
+
+void GPUProgramParameters::GetParameter(const string &name, float *vals, int numElements)
+{
+	SetArray2f(mProgram->GetParameter(name, numElements, (const float *)vals);
+}
+
+
+void GPUProgramParameters::SetArray3f(const string &name, float *vals, int numElements)
+{
+	SetArray3f(mProgram->GetParameter(name), numElements, (const float *)vals);
+}
+
+
+void GPUProgramParameters::SetMatrix(const string &name, Matrix4x4 *mat)
+{
+	SetMatrix(mProgram->GetParameter(name), mat);
+}
+
+
+void GPUProgramParameters::SetTexture(const string &name, unsigned int tex)
+{
+	SetTexture(mProgram->GetOrCreateParameter(name), tex);
+}
 
 
@@ -22,4 +115,42 @@
 
 	if (mProgram) cgGLLoadProgram(mProgram);
+
+	mParameters.resize(64);
+
+	for (int i = 0; i < 64; ++ i)
+	{
+		mParameters[i] = NULL;
+	}
+}
+
+
+void ShaderProgram::Bind()
+{
+	cgGLBindProgram(mProgram);
+
+	// enable all texture parameters
+	CGParameterArray::const_iterator it, it_end = mTextureParams.end();
+
+	for (it = mTextureParams.begin(); it != it_end; ++ it) 
+		cgGLEnableTextureParameter(*it);
+}
+
+
+/*void ShaderProgram::Release()
+{
+	CGParameterArray::const_iterator it, it_end = mTextureParams.end();
+
+	// disable all texture parameters
+	for (it = mTextureParams.begin(); it != it_end; ++ it)
+		cgGLDisableTextureParameter(*it);
+}*/
+
+
+CGparameter ShaderProgram::AddParameter(const string &name, int idx)
+{
+	CGparameter p = GetOrCreateParameter(name);
+
+	mParameters[idx] = p;
+	return p;
 }
 
@@ -33,9 +164,9 @@
 	{
 		p = cgGetNamedParameter(mProgram, name.c_str());
-		mParamHash[name] = p;
+		mParamHash[name] = i;
 	}
 	else
 	{
-		p = (*it).second;
+		p = mParameters[(*it).second];
 	}
 
@@ -45,49 +176,56 @@
 
 
-void ShaderProgram::SetValue1f(const string &name, float val)
-{
-	cgGLSetParameter1f(GetOrCreateParameter(name), val);
-}
-
-
-void ShaderProgram::SetValue2f(const string &name, float val1, float val2)
-{
-	cgGLSetParameter2f(GetOrCreateParameter(name), val1, val2);
-}
-
-
-void ShaderProgram::SetValue3f(const string &name, float val1, float val2, float val3)
-{
-	cgGLSetParameter3f(GetOrCreateParameter(name), val1, val2, val3);
-}
-
-
-void ShaderProgram::SetArray1f(const string &name, float *vals, int numElements)
-{
-	cgGLSetParameterArray1f(GetOrCreateParameter(name), 0, numElements, (const float *)vals);
-}
-
-
-void ShaderProgram::SetArray2f(const string &name, float *vals, int numElements)
-{
-	cgGLSetParameterArray2f(GetOrCreateParameter(name), 0, numElements, (const float *)vals);
-}
-
-
-void ShaderProgram::SetArray3f(const string &name, float *vals, int numElements)
-{
-	cgGLSetParameterArray3f(GetOrCreateParameter(name), 0, numElements, (const float *)vals);
-}
-
-
-void ShaderProgram::SetMatrix(const string &name, const Matrix4x4 &mat)
-{
-	cgGLSetMatrixParameterfc(GetOrCreateParameter(name), (const float *)mat.x);
-}
-
-
-void ShaderProgram::SetTexture(const string &name, unsigned int tex)
-{
-	CGparameter p = GetOrCreateParameter(name);
+CGparameter ShaderProgram::GetParameter(int idx) const
+{
+	CGparameter p = mParameters[idx];
+	return p;
+}
+
+
+void ShaderProgram::SetValue1f(int idx, float val)
+{
+	cgGLSetParameter1f(GetParameter(idx), val);
+}
+
+
+void ShaderProgram::SetValue2f(int idx, float val1, float val2)
+{
+	cgGLSetParameter2f(GetParameter(idx), val1, val2);
+}
+
+
+void ShaderProgram::SetValue3f(int idx, float val1, float val2, float val3)
+{
+	cgGLSetParameter3f(GetParameter(idx), val1, val2, val3);
+}
+
+
+void ShaderProgram::SetArray1f(int idx, float *vals, int numElements)
+{
+	cgGLSetParameterArray1f(GetParameter(idx), 0, numElements, (const float *)vals);
+}
+
+
+void ShaderProgram::SetArray2f(int idx, float *vals, int numElements)
+{
+	cgGLSetParameterArray2f(GetParameter(idx), 0, numElements, (const float *)vals);
+}
+
+
+void ShaderProgram::SetArray3f(int idx, float *vals, int numElements)
+{
+	cgGLSetParameterArray3f(GetParameter(idx), 0, numElements, (const float *)vals);
+}
+
+
+void ShaderProgram::SetMatrix(int idx, const Matrix4x4 &mat)
+{
+	cgGLSetMatrixParameterfc(GetParameter(idx), (const float *)mat.x);
+}
+
+
+void ShaderProgram::SetTexture(int idx, unsigned int tex)
+{
+	CGparameter p = GetParameter(idx);
 
 	cgGLSetTextureParameter(p, tex);
@@ -98,25 +236,9 @@
 
 
-void ShaderProgram::Bind()
-{
-	cgGLBindProgram(mProgram);
-
-	// enable all texture parameters
-	CGParameterArray::const_iterator it, it_end = mTextureParams.end();
-
-	for (it = mTextureParams.begin(); it != it_end; ++ it) 
-		cgGLEnableTextureParameter(*it);
-}
-
-/*
-void ShaderProgram::Release()
-{
-	CGParameterArray::const_iterator it, it_end = mTextureParams.end();
-
-	// disable all texture parameters
-	for (it = mTextureParams.begin(); it != it_end; ++ it)
-		cgGLDisableTextureParameter(*it);
-}
-*/
+int ShaderProgram::GetParameter(const std::string &name)
+{
+	return mParamHash[name];
+}
+
 
 } // namespace 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3032)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3033)
@@ -20,6 +20,8 @@
 class ShadowMap;
 class DirectionalLight;
+class ShaderProgram;
 
-typedef std::map<std::string, CGparameter> CGParameterMap;
+
+typedef std::map<std::string, int> CGParameterMap;
 typedef std::vector<CGparameter> CGParameterArray;
 
@@ -32,23 +34,74 @@
 class GPUProgramParameters
 {
+	void SetValue1f(int idx, float value);
+	void SetValue2f(int idx, float val1, float val2);
+	void SetValue3f(int idx, float val1, float val, float val3);
+
+	void SetArray1f(int idx, float *vals, int numElements);
+	void SetArray2f(int idx, float *vals, int numElements);
+	void SetArray3f(int idx, float *vals, int numElements);
+
+	/** Sets the texture parameter.
+	*/
+	void SetTexture(int idx, unsigned int tex);
+	/** Sets the matrix parameter.
+	*/
+	void SetMatrix(int idx, Matrix4x4 *mat);
+
+	void SetValue1f(const std::string &name, float value);
+	void SetValue2f(const std::string &name, float val1, float val2);
+	void SetValue3f(const std::string &name, float val1, float val, float val3);
+
+	void SetArray1f(const std::string &name, float *vals, int numElements);
+	void SetArray2f(const std::string &name, float *vals, int numElements);
+	void SetArray3f(const std::string &name, float *vals, int numElements);
+	/** Sets the texture parameter.
+	*/
+	void SetTexture(const std::string &name, unsigned int tex);
+	/** Sets the matrix parameter.
+	*/
+	void SetMatrix(const std::string &name, Matrix4x4 *mat);
+
 	struct ParameterFloat
 	{
+		int mIndex;
 		float mValues[4];
-		int numEntries;
+		float mNumComponents;
+	};
+
+	struct ParameterValueInt
+	{
+		int mIndex;
+		float mValue;
+	};
+
+	struct ParameterValueMatrix
+	{
+		int mIndex;
+		Matrix4x4 *mValue;
 	};
 
 	struct ParameterValueArray
 	{
-		float mValues[256];
-		int numEntries;
+		int mIndex;
 
-		float numComponents;
+		float *mValues;
+		int mNumEntries;
+
+		float mNumComponents;
 	};
 
 
-	std::map<int, ParameterFloat> mParametersFloat;
+	GPUProgramParameters(ShaderProgram *p);
 
-	std::map<int, int> mParametersTex;
-	std::map<int, Matrix4x4 *> mParametersMatrix;
+
+protected:
+
+	ShaderProgram *mProgram;
+
+	std::vector<ParameterFloat> mFloats;
+
+	std::vector<ParameterValueInt> mTextures;
+	std::vector<ParameterValueMatrix> mMatrices;
 };
 
@@ -57,4 +110,6 @@
 class ShaderProgram
 {
+	friend class GPUProgramParameters;
+
 public:
 
@@ -68,22 +123,22 @@
 	~ShaderProgram() { if (mProgram != NULL) cgDestroyProgram(mProgram); }
 
-	void SetValue1f(const std::string &name, float value);
-	void SetValue2f(const std::string &name, float val1, float val2);
-	void SetValue3f(const std::string &name, float val1, float val, float val3);
+	void SetValue1f(int idx, float value);
+	void SetValue2f(int idx, float val1, float val2);
+	void SetValue3f(int idx, float val1, float val, float val3);
 
-	void SetArray1f(const std::string &name, float *vals, int numElements);
-	void SetArray2f(const std::string &name, float *vals, int numElements);
-	void SetArray3f(const std::string &name, float *vals, int numElements);
-	/** Sets the matrix parameter.
-	*/
-	void SetMatrix(const std::string &name, const Matrix4x4 &mat);
-	/** Sets the texture parameter.
-	*/
-	void SetTexture(const std::string &name, unsigned int tex);
+	void SetArray1f(int idx, float *vals, int numElements);
+	void SetArray2f(int idx, float *vals, int numElements);
+	void SetArray3f(int idx, float *vals, int numElements);
+	void SetMatrix(int idx, const Matrix4x4 &mat);
+
+	void SetTexture(int idx, unsigned int tex);
+
+	CGparameter AddParameter(const std::string &name, int idx);
+
 	/** Enable / disable a texture parameter.
 	*/
-	void EnableTexture(const std::string &name);
+	//void EnableTexture(const std::string &name);
+	//void DisableTexture(const std::string &name);
 
-	void DisableTexture(const std::string &name);
 	/** Binds the program.
 	*/
@@ -91,18 +146,23 @@
 	/** Returns true if this program is valid.
 	*/
-	inline bool IsValid() { return mProgram != NULL; }
+	inline bool IsValid() const { return mProgram != NULL; }
+
+	inline int GetParameter(const std::string &name);
 
 
 protected:
 
+	inline CGparameter GetParameter(int idx);
+
 	CGparameter GetOrCreateParameter(const std::string &name);
 
+
+	///////////////
+
 	CGParameterMap mParamHash;
-	//CGParameterArray mParameters;
+	
+	CGprogram mProgram;
 
 	CGParameterArray mTextureParams;
-
-	CGprogram mProgram;
-
 	CGParameterArray mParameters;
 };
