Marko Pintera 13 лет назад
Родитель
Сommit
4701151ba0

+ 7 - 0
CamelotRenderer/CamelotRenderer.vcxproj

@@ -94,6 +94,8 @@
     <ClInclude Include="OgreDefaultHardwareBufferManager.h" />
     <ClInclude Include="OgreException.h" />
     <ClInclude Include="OgreFrustum.h" />
+    <ClInclude Include="OgreGpuProgram.h" />
+    <ClInclude Include="OgreGpuProgramParams.h" />
     <ClInclude Include="OgreHardwareBuffer.h" />
     <ClInclude Include="OgreHardwareBufferManager.h" />
     <ClInclude Include="OgreHardwareIndexBuffer.h" />
@@ -111,6 +113,7 @@
     <ClInclude Include="OgrePrerequisites.h" />
     <ClInclude Include="OgreQuaternion.h" />
     <ClInclude Include="OgreRay.h" />
+    <ClInclude Include="OgreRenderOperation.h" />
     <ClInclude Include="OgreRenderSystemCapabilities.h" />
     <ClInclude Include="OgreRenderTarget.h" />
     <ClInclude Include="OgreSharedPtr.h" />
@@ -119,6 +122,7 @@
     <ClInclude Include="OgreStdHeaders.h" />
     <ClInclude Include="OgreString.h" />
     <ClInclude Include="OgreStringConverter.h" />
+    <ClInclude Include="OgreStringInterface.h" />
     <ClInclude Include="OgreStringVector.h" />
     <ClInclude Include="OgreThreadDefines.h" />
     <ClInclude Include="OgreVector2.h" />
@@ -139,6 +143,8 @@
     <ClCompile Include="OgreDefaultHardwareBufferManager.cpp" />
     <ClCompile Include="OgreException.cpp" />
     <ClCompile Include="OgreFrustum.cpp" />
+    <ClCompile Include="OgreGpuProgram.cpp" />
+    <ClCompile Include="OgreGpuProgramParams.cpp" />
     <ClCompile Include="OgreHardwareBufferManager.cpp" />
     <ClCompile Include="OgreHardwareIndexBuffer.cpp" />
     <ClCompile Include="OgreHardwareVertexBuffer.cpp" />
@@ -152,6 +158,7 @@
     <ClCompile Include="OgreRenderTarget.cpp" />
     <ClCompile Include="OgreString.cpp" />
     <ClCompile Include="OgreStringConverter.cpp" />
+    <ClCompile Include="OgreStringInterface.cpp" />
     <ClCompile Include="OgreVector2.cpp" />
     <ClCompile Include="OgreVector3.cpp" />
     <ClCompile Include="OgreVector4.cpp" />

+ 21 - 0
CamelotRenderer/CamelotRenderer.vcxproj.filters

@@ -180,6 +180,18 @@
     <ClInclude Include="OgrePixelFormat.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="OgreGpuProgram.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="OgreRenderOperation.h">
+      <Filter>Header Files\ForRemoval</Filter>
+    </ClInclude>
+    <ClInclude Include="OgreGpuProgramParams.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="OgreStringInterface.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="stdafx.cpp">
@@ -266,5 +278,14 @@
     <ClCompile Include="OgrePixelFormat.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="OgreGpuProgram.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="OgreGpuProgramParams.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="OgreStringInterface.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 432 - 0
CamelotRenderer/OgreGpuProgram.cpp

@@ -0,0 +1,432 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+(Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2011 Torus Knot Software Ltd
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+-----------------------------------------------------------------------------
+*/
+#include "OgreGpuProgram.h"
+//#include "OgreHighLevelGpuProgram.h"
+#include "OgreVector3.h"
+#include "OgreVector4.h"
+#include "OgreRenderSystemCapabilities.h"
+#include "OgreStringConverter.h"
+#include "OgreException.h"
+
+namespace Ogre
+{
+    //-----------------------------------------------------------------------------
+    GpuProgram::CmdType GpuProgram::msTypeCmd;
+    GpuProgram::CmdSyntax GpuProgram::msSyntaxCmd;
+    GpuProgram::CmdSkeletal GpuProgram::msSkeletalCmd;
+	GpuProgram::CmdMorph GpuProgram::msMorphCmd;
+	GpuProgram::CmdPose GpuProgram::msPoseCmd;
+	GpuProgram::CmdVTF GpuProgram::msVTFCmd;
+	GpuProgram::CmdManualNamedConstsFile GpuProgram::msManNamedConstsFileCmd;
+	GpuProgram::CmdAdjacency GpuProgram::msAdjacencyCmd;
+	
+
+    //-----------------------------------------------------------------------------
+    GpuProgram::GpuProgram() 
+        :mType(GPT_VERTEX_PROGRAM), mLoadFromFile(true), mSkeletalAnimation(false),
+		mMorphAnimation(false), mPoseAnimation(0),
+        mVertexTextureFetch(false), mNeedsAdjacencyInfo(false),
+		mCompileError(false), mLoadedManualNamedConstants(false)
+    {
+		createParameterMappingStructures();
+    }
+    //-----------------------------------------------------------------------------
+    void GpuProgram::setType(GpuProgramType t)
+    {
+        mType = t;
+    }
+    //-----------------------------------------------------------------------------
+    void GpuProgram::setSyntaxCode(const String& syntax)
+    {
+        mSyntaxCode = syntax;
+    }
+    //-----------------------------------------------------------------------------
+    void GpuProgram::setSourceFile(const String& filename)
+    {
+        mFilename = filename;
+        mSource.clear();
+        mLoadFromFile = true;
+		mCompileError = false;
+    }
+    //-----------------------------------------------------------------------------
+    void GpuProgram::setSource(const String& source)
+    {
+        mSource = source;
+        mFilename.clear();
+        mLoadFromFile = false;
+		mCompileError = false;
+    }
+		
+
+    //-----------------------------------------------------------------------------
+    void GpuProgram::loadImpl(void)
+    {
+        // Call polymorphic load
+		try 
+		{
+			loadFromSource();
+
+			if (!mDefaultParams.isNull())
+			{
+				// Keep a reference to old ones to copy
+				GpuProgramParametersSharedPtr savedParams = mDefaultParams;
+				// reset params to stop them being referenced in the next create
+				mDefaultParams.setNull();
+
+				// Create new params
+				mDefaultParams = createParameters();
+
+				// Copy old (matching) values across
+				// Don't use copyConstantsFrom since program may be different
+				mDefaultParams->copyMatchingNamedConstantsFrom(*savedParams.get());
+
+			}
+		}
+		catch (const Exception&)
+		{
+			// will already have been logged
+			//LogManager::getSingleton().stream()
+			//	<< "Gpu program " << mName << " encountered an error "
+			//	<< "during loading and is thus not supported.";
+
+			mCompileError = true;
+		}
+
+    }
+    //-----------------------------------------------------------------------------
+    bool GpuProgram::isRequiredCapabilitiesSupported(void) const
+    {
+		// TODO PORT- Enable once I port rendersystem. Right now just assume everything is supported and return true
+		return true;
+
+		//const RenderSystemCapabilities* caps = 
+		//	Root::getSingleton().getRenderSystem()->getCapabilities();
+
+  //      // If skeletal animation is being done, we need support for UBYTE4
+  //      if (isSkeletalAnimationIncluded() && 
+  //          !caps->hasCapability(RSC_VERTEX_FORMAT_UBYTE4))
+  //      {
+  //          return false;
+  //      }
+
+		//// Vertex texture fetch required?
+		//if (isVertexTextureFetchRequired() && 
+		//	!caps->hasCapability(RSC_VERTEX_TEXTURE_FETCH))
+		//{
+		//	return false;
+		//}
+
+  //      return true;
+    }
+    //-----------------------------------------------------------------------------
+    bool GpuProgram::isSupported(void) const
+    {
+        if (mCompileError || !isRequiredCapabilitiesSupported())
+            return false;
+
+		// TODO PORT - Enable this once I have ported the render system, for now just return true
+		//RenderSystem* rs = Root::getSingleton().getRenderSystem();
+		//return rs->getCapabilities()->isShaderProfileSupported(mSyntaxCode);
+
+        return true;
+    }
+	//---------------------------------------------------------------------
+	void GpuProgram::createParameterMappingStructures(bool recreateIfExists) const
+	{
+		createLogicalParameterMappingStructures(recreateIfExists);
+		createNamedParameterMappingStructures(recreateIfExists);
+	}
+	//---------------------------------------------------------------------
+	void GpuProgram::createLogicalParameterMappingStructures(bool recreateIfExists) const
+	{
+		if (recreateIfExists || mFloatLogicalToPhysical.isNull())
+			mFloatLogicalToPhysical = GpuLogicalBufferStructPtr(OGRE_NEW GpuLogicalBufferStruct());
+		if (recreateIfExists || mIntLogicalToPhysical.isNull())
+			mIntLogicalToPhysical = GpuLogicalBufferStructPtr(OGRE_NEW GpuLogicalBufferStruct());
+	}
+	//---------------------------------------------------------------------
+	void GpuProgram::createNamedParameterMappingStructures(bool recreateIfExists) const
+	{
+		if (recreateIfExists || mConstantDefs.isNull())
+			mConstantDefs = GpuNamedConstantsPtr(OGRE_NEW GpuNamedConstants());
+	}
+	//---------------------------------------------------------------------
+	void GpuProgram::setManualNamedConstantsFile(const String& paramDefFile)
+	{
+		mManualNamedConstantsFile = paramDefFile;
+		mLoadedManualNamedConstants = false;
+	}
+	//---------------------------------------------------------------------
+	void GpuProgram::setManualNamedConstants(const GpuNamedConstants& namedConstants)
+	{
+		createParameterMappingStructures();
+		*mConstantDefs.get() = namedConstants;
+
+		mFloatLogicalToPhysical->bufferSize = mConstantDefs->floatBufferSize;
+		mIntLogicalToPhysical->bufferSize = mConstantDefs->intBufferSize;
+		mFloatLogicalToPhysical->map.clear();
+		mIntLogicalToPhysical->map.clear();
+		// need to set up logical mappings too for some rendersystems
+		for (GpuConstantDefinitionMap::const_iterator i = mConstantDefs->map.begin();
+			i != mConstantDefs->map.end(); ++i)
+		{
+			const String& name = i->first;
+			const GpuConstantDefinition& def = i->second;
+			// only consider non-array entries
+			if (name.find("[") == String::npos)
+			{
+				GpuLogicalIndexUseMap::value_type val(def.logicalIndex, 
+					GpuLogicalIndexUse(def.physicalIndex, def.arraySize * def.elementSize, def.variability));
+				if (def.isFloat())
+				{
+					mFloatLogicalToPhysical->map.insert(val);
+				}
+				else
+				{
+					mIntLogicalToPhysical->map.insert(val);
+				}
+			}
+		}
+
+
+	}
+    //-----------------------------------------------------------------------------
+    GpuProgramParametersSharedPtr GpuProgram::createParameters(void)
+    {
+        // Default implementation simply returns standard parameters.
+        GpuProgramParametersSharedPtr ret = GpuProgramParametersSharedPtr(OGRE_NEW GpuProgramParameters());	
+		
+		// set up named parameters, if any
+		if (!mConstantDefs.isNull() && !mConstantDefs->map.empty())
+		{
+			ret->_setNamedConstants(mConstantDefs);
+		}
+		// link shared logical / physical map for low-level use
+		ret->_setLogicalIndexes(mFloatLogicalToPhysical, mIntLogicalToPhysical);
+
+        // Copy in default parameters if present
+        if (!mDefaultParams.isNull())
+            ret->copyConstantsFrom(*(mDefaultParams.get()));
+        
+        return ret;
+    }
+    //-----------------------------------------------------------------------------
+    GpuProgramParametersSharedPtr GpuProgram::getDefaultParameters(void)
+    {
+        if (mDefaultParams.isNull())
+        {
+            mDefaultParams = createParameters();
+        }
+        return mDefaultParams;
+    }
+    //-----------------------------------------------------------------------------
+    void GpuProgram::setupBaseParamDictionary(void)
+    {
+		// TODO PORT - I'm not really sure what this will do and will it be needed in my port, but its calling a method from Resource, and we don't inherit from it
+  //      ParamDictionary* dict = getParamDictionary();
+
+  //      dict->addParameter(
+  //          ParameterDef("type", "'vertex_program', 'geometry_program' or 'fragment_program'",
+  //              PT_STRING), &msTypeCmd);
+  //      dict->addParameter(
+  //          ParameterDef("syntax", "Syntax code, e.g. vs_1_1", PT_STRING), &msSyntaxCmd);
+  //      dict->addParameter(
+  //          ParameterDef("includes_skeletal_animation", 
+  //          "Whether this vertex program includes skeletal animation", PT_BOOL), 
+  //          &msSkeletalCmd);
+		//dict->addParameter(
+		//	ParameterDef("includes_morph_animation", 
+		//	"Whether this vertex program includes morph animation", PT_BOOL), 
+		//	&msMorphCmd);
+		//dict->addParameter(
+		//	ParameterDef("includes_pose_animation", 
+		//	"The number of poses this vertex program supports for pose animation", PT_INT), 
+		//	&msPoseCmd);
+		//dict->addParameter(
+		//	ParameterDef("uses_vertex_texture_fetch", 
+		//	"Whether this vertex program requires vertex texture fetch support.", PT_BOOL), 
+		//	&msVTFCmd);
+		//dict->addParameter(
+		//	ParameterDef("manual_named_constants", 
+		//	"File containing named parameter mappings for low-level programs.", PT_BOOL), 
+		//	&msManNamedConstsFileCmd);
+		//dict->addParameter(
+		//	ParameterDef("uses_adjacency_information",
+		//	"Whether this geometry program requires adjacency information from the input primitives.", PT_BOOL),
+		//	&msAdjacencyCmd);
+    }
+
+    //-----------------------------------------------------------------------
+    const String& GpuProgram::getLanguage(void) const
+    {
+        static const String language = "asm";
+
+        return language;
+    }
+    //-----------------------------------------------------------------------
+    //-----------------------------------------------------------------------
+    String GpuProgram::CmdType::doGet(const void* target) const
+    {
+        const GpuProgram* t = static_cast<const GpuProgram*>(target);
+        if (t->getType() == GPT_VERTEX_PROGRAM)
+        {
+            return "vertex_program";
+        }
+		else if (t->getType() == GPT_GEOMETRY_PROGRAM)
+		{
+			return "geometry_program";
+		}
+		else
+        {
+            return "fragment_program";
+        }
+    }
+    void GpuProgram::CmdType::doSet(void* target, const String& val)
+    {
+        GpuProgram* t = static_cast<GpuProgram*>(target);
+        if (val == "vertex_program")
+        {
+            t->setType(GPT_VERTEX_PROGRAM);
+        }
+        else if (val == "geometry_program")
+		{
+			t->setType(GPT_GEOMETRY_PROGRAM);
+		}
+		else
+        {
+            t->setType(GPT_FRAGMENT_PROGRAM);
+        }
+    }
+    //-----------------------------------------------------------------------
+    String GpuProgram::CmdSyntax::doGet(const void* target) const
+    {
+        const GpuProgram* t = static_cast<const GpuProgram*>(target);
+        return t->getSyntaxCode();
+    }
+    void GpuProgram::CmdSyntax::doSet(void* target, const String& val)
+    {
+        GpuProgram* t = static_cast<GpuProgram*>(target);
+        t->setSyntaxCode(val);
+    }
+    //-----------------------------------------------------------------------
+    String GpuProgram::CmdSkeletal::doGet(const void* target) const
+    {
+        const GpuProgram* t = static_cast<const GpuProgram*>(target);
+        return StringConverter::toString(t->isSkeletalAnimationIncluded());
+    }
+    void GpuProgram::CmdSkeletal::doSet(void* target, const String& val)
+    {
+        GpuProgram* t = static_cast<GpuProgram*>(target);
+        t->setSkeletalAnimationIncluded(StringConverter::parseBool(val));
+    }
+	//-----------------------------------------------------------------------
+	String GpuProgram::CmdMorph::doGet(const void* target) const
+	{
+		const GpuProgram* t = static_cast<const GpuProgram*>(target);
+		return StringConverter::toString(t->isMorphAnimationIncluded());
+	}
+	void GpuProgram::CmdMorph::doSet(void* target, const String& val)
+	{
+		GpuProgram* t = static_cast<GpuProgram*>(target);
+		t->setMorphAnimationIncluded(StringConverter::parseBool(val));
+	}
+	//-----------------------------------------------------------------------
+	String GpuProgram::CmdPose::doGet(const void* target) const
+	{
+		const GpuProgram* t = static_cast<const GpuProgram*>(target);
+		return StringConverter::toString(t->getNumberOfPosesIncluded());
+	}
+	void GpuProgram::CmdPose::doSet(void* target, const String& val)
+	{
+		GpuProgram* t = static_cast<GpuProgram*>(target);
+		t->setPoseAnimationIncluded((ushort)StringConverter::parseUnsignedInt(val));
+	}
+	//-----------------------------------------------------------------------
+	String GpuProgram::CmdVTF::doGet(const void* target) const
+	{
+		const GpuProgram* t = static_cast<const GpuProgram*>(target);
+		return StringConverter::toString(t->isVertexTextureFetchRequired());
+	}
+	void GpuProgram::CmdVTF::doSet(void* target, const String& val)
+	{
+		GpuProgram* t = static_cast<GpuProgram*>(target);
+		t->setVertexTextureFetchRequired(StringConverter::parseBool(val));
+	}
+	//-----------------------------------------------------------------------
+	String GpuProgram::CmdManualNamedConstsFile::doGet(const void* target) const
+	{
+		const GpuProgram* t = static_cast<const GpuProgram*>(target);
+		return t->getManualNamedConstantsFile();
+	}
+	void GpuProgram::CmdManualNamedConstsFile::doSet(void* target, const String& val)
+	{
+		GpuProgram* t = static_cast<GpuProgram*>(target);
+		t->setManualNamedConstantsFile(val);
+	}
+    //-----------------------------------------------------------------------
+	String GpuProgram::CmdAdjacency::doGet(const void* target) const
+	{
+		const GpuProgram* t = static_cast<const GpuProgram*>(target);
+		return StringConverter::toString(t->isAdjacencyInfoRequired());
+	}
+	void GpuProgram::CmdAdjacency::doSet(void* target, const String& val)
+	{
+		GpuProgram* t = static_cast<GpuProgram*>(target);
+		t->setAdjacencyInfoRequired(StringConverter::parseBool(val));
+	}
+	// TODO PORT - I've hidden this cast until it will be needed
+  //  //-----------------------------------------------------------------------
+  //  GpuProgramPtr& GpuProgramPtr::operator=(const HighLevelGpuProgramPtr& r)
+  //  {
+  //      // Can assign direct
+  //      if (pRep == r.getPointer())
+  //          return *this;
+  //      release();
+		//// lock & copy other mutex pointer
+  //      OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
+  //      {
+		//    OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
+		//    OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
+  //          pRep = r.getPointer();
+  //          pUseCount = r.useCountPointer();
+  //          if (pUseCount)
+  //          {
+  //              ++(*pUseCount);
+  //          }
+  //      }
+		//else
+		//{
+		//	// RHS must be a null pointer
+		//	assert(r.isNull() && "RHS must be null if it has no mutex!");
+		//	setNull();
+		//}
+  //      return *this;
+  //  }
+
+}
+

+ 444 - 0
CamelotRenderer/OgreGpuProgram.h

@@ -0,0 +1,444 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+    (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org
+
+Copyright (c) 2000-2011 Torus Knot Software Ltd
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+-----------------------------------------------------------------------------
+*/
+#ifndef __GpuProgram_H_
+#define __GpuProgram_H_
+
+// Precompiler options
+#include "OgrePrerequisites.h"
+#include "OgreSharedPtr.h"
+#include "OgreRenderOperation.h"
+#include "OgreStringInterface.h"
+#include "OgreGpuProgramParams.h"
+
+namespace Ogre {
+
+	/** \addtogroup Core
+	*  @{
+	*/
+	/** \addtogroup Resources
+	*  @{
+	*/
+	/** Enumerates the types of programs which can run on the GPU. */
+	enum GpuProgramType
+	{
+		GPT_VERTEX_PROGRAM,
+		GPT_FRAGMENT_PROGRAM,
+		GPT_GEOMETRY_PROGRAM
+	};
+
+
+    // Forward declaration 
+    class GpuProgramPtr;
+
+	/** Defines a program which runs on the GPU such as a vertex or fragment program. 
+	@remarks
+		This class defines the low-level program in assembler code, the sort used to
+		directly assemble into machine instructions for the GPU to execute. By nature,
+		this means that the assembler source is rendersystem specific, which is why this
+		is an abstract class - real instances are created through the RenderSystem. 
+		If you wish to use higher level shading languages like HLSL and Cg, you need to 
+		use the HighLevelGpuProgram class instead.
+	*/
+	class _OgreExport GpuProgram
+	{
+	protected:
+		/// Command object - see ParamCommand 
+		class _OgreExport CmdType : public ParamCommand
+		{
+		public:
+			String doGet(const void* target) const;
+			void doSet(void* target, const String& val);
+		};
+		class _OgreExport CmdSyntax : public ParamCommand
+		{
+		public:
+			String doGet(const void* target) const;
+			void doSet(void* target, const String& val);
+		};
+		class _OgreExport CmdSkeletal : public ParamCommand
+		{
+		public:
+			String doGet(const void* target) const;
+			void doSet(void* target, const String& val);
+		};
+		class _OgreExport CmdMorph : public ParamCommand
+		{
+		public:
+			String doGet(const void* target) const;
+			void doSet(void* target, const String& val);
+		};
+		class _OgreExport CmdPose : public ParamCommand
+		{
+		public:
+			String doGet(const void* target) const;
+			void doSet(void* target, const String& val);
+		};
+		class _OgreExport CmdVTF : public ParamCommand
+		{
+		public:
+			String doGet(const void* target) const;
+			void doSet(void* target, const String& val);
+		};
+		class _OgreExport CmdManualNamedConstsFile : public ParamCommand
+		{
+		public:
+			String doGet(const void* target) const;
+			void doSet(void* target, const String& val);
+		};
+		class _OgreExport CmdAdjacency : public ParamCommand
+		{
+		public:
+			String doGet(const void* target) const;
+			void doSet(void* target, const String& val);
+		};
+		// Command object for setting / getting parameters
+		static CmdType msTypeCmd;
+		static CmdSyntax msSyntaxCmd;
+		static CmdSkeletal msSkeletalCmd;
+		static CmdMorph msMorphCmd;
+		static CmdPose msPoseCmd;
+		static CmdVTF msVTFCmd;
+		static CmdManualNamedConstsFile msManNamedConstsFileCmd;
+		static CmdAdjacency msAdjacencyCmd;
+		/// The type of the program
+		GpuProgramType mType;
+		/// The name of the file to load source from (may be blank)
+		String mFilename;
+        /// The assembler source of the program (may be blank until file loaded)
+        String mSource;
+        /// Whether we need to load source from file or not
+        bool mLoadFromFile;
+        /// Syntax code e.g. arbvp1, vs_2_0 etc
+        String mSyntaxCode;
+        /// Does this (vertex) program include skeletal animation?
+        bool mSkeletalAnimation;
+		/// Does this (vertex) program include morph animation?
+		bool mMorphAnimation;
+		/// Does this (vertex) program include pose animation (count of number of poses supported)
+		ushort mPoseAnimation;
+		/// Does this (vertex) program require support for vertex texture fetch?
+		bool mVertexTextureFetch;
+		/// Does this (geometry) program require adjacency information?
+		bool mNeedsAdjacencyInfo;
+		/// The default parameters for use with this object
+		GpuProgramParametersSharedPtr mDefaultParams;
+		/// Did we encounter a compilation error?
+		bool mCompileError;
+		/** Record of logical to physical buffer maps. Mandatory for low-level
+			programs or high-level programs which set their params the same way. 
+			This is a shared pointer because if the program is recompiled and the parameters
+			change, this definition will alter, but previous params may reference the old def. */
+		mutable GpuLogicalBufferStructPtr mFloatLogicalToPhysical;
+		/** Record of logical to physical buffer maps. Mandatory for low-level
+			programs or high-level programs which set their params the same way. 
+			This is a shared pointer because if the program is recompiled and the parameters
+			change, this definition will alter, but previous params may reference the old def.*/
+		mutable GpuLogicalBufferStructPtr mIntLogicalToPhysical;
+		/** Parameter name -> ConstantDefinition map, shared instance used by all parameter objects.
+		This is a shared pointer because if the program is recompiled and the parameters
+		change, this definition will alter, but previous params may reference the old def.
+		*/
+		mutable GpuNamedConstantsPtr mConstantDefs;
+		/// File from which to load named constants manually
+		String mManualNamedConstantsFile;
+		bool mLoadedManualNamedConstants;
+
+
+		/** Internal method for setting up the basic parameter definitions for a subclass. 
+		@remarks
+		Because StringInterface holds a dictionary of parameters per class, subclasses need to
+		call this to ask the base class to add it's parameters to their dictionary as well.
+		Can't do this in the constructor because that runs in a non-virtual context.
+		@par
+		The subclass must have called it's own createParamDictionary before calling this method.
+		*/
+		void setupBaseParamDictionary(void);
+
+        /** Internal method returns whether required capabilities for this program is supported.
+        */
+        bool isRequiredCapabilitiesSupported(void) const;
+
+		/// @copydoc Resource::calculateSize
+		size_t calculateSize(void) const { return 0; } // TODO 
+
+		/// @copydoc Resource::loadImpl
+		void loadImpl(void);
+
+		/// Create the internal params logical & named mapping structures
+		void createParameterMappingStructures(bool recreateIfExists = true) const;
+		/// Create the internal params logical mapping structures
+		void createLogicalParameterMappingStructures(bool recreateIfExists = true) const;
+		/// Create the internal params named mapping structures
+		void createNamedParameterMappingStructures(bool recreateIfExists = true) const;
+
+	public:
+
+		GpuProgram();
+
+		virtual ~GpuProgram() {}
+
+        /** Sets the filename of the source assembly for this program.
+        @remarks
+            Setting this will have no effect until you (re)load the program.
+        */
+        virtual void setSourceFile(const String& filename);
+
+		/** Sets the source assembly for this program from an in-memory string.
+        @remarks
+            Setting this will have no effect until you (re)load the program.
+        */
+        virtual void setSource(const String& source);
+
+        /** Gets the syntax code for this program e.g. arbvp1, fp20, vs_1_1 etc */
+        virtual const String& getSyntaxCode(void) const { return mSyntaxCode; }
+
+		/** Sets the syntax code for this program e.g. arbvp1, fp20, vs_1_1 etc */
+		virtual void setSyntaxCode(const String& syntax);
+
+		/** Gets the name of the file used as source for this program. */
+		virtual const String& getSourceFile(void) const { return mFilename; }
+        /** Gets the assembler source for this program. */
+        virtual const String& getSource(void) const { return mSource; }
+		/// Set the program type (only valid before load)
+		virtual void setType(GpuProgramType t);
+        /// Get the program type
+        virtual GpuProgramType getType(void) const { return mType; }
+
+        /** Returns the GpuProgram which should be bound to the pipeline.
+        @remarks
+            This method is simply to allow some subclasses of GpuProgram to delegate
+            the program which is bound to the pipeline to a delegate, if required. */
+        virtual GpuProgram* _getBindingDelegate(void) { return this; }
+
+        /** Returns whether this program can be supported on the current renderer and hardware. */
+        virtual bool isSupported(void) const;
+
+        /** Creates a new parameters object compatible with this program definition. 
+        @remarks
+            It is recommended that you use this method of creating parameters objects
+            rather than going direct to GpuProgramManager, because this method will
+            populate any implementation-specific extras (like named parameters) where
+            they are appropriate.
+        */
+        virtual GpuProgramParametersSharedPtr createParameters(void);
+
+        /** Sets whether a vertex program includes the required instructions
+        to perform skeletal animation. 
+        @remarks
+        If this is set to true, OGRE will not blend the geometry according to 
+        skeletal animation, it will expect the vertex program to do it.
+        */
+        virtual void setSkeletalAnimationIncluded(bool included) 
+        { mSkeletalAnimation = included; }
+
+        /** Returns whether a vertex program includes the required instructions
+            to perform skeletal animation. 
+        @remarks
+            If this returns true, OGRE will not blend the geometry according to 
+            skeletal animation, it will expect the vertex program to do it.
+        */
+        virtual bool isSkeletalAnimationIncluded(void) const { return mSkeletalAnimation; }
+
+        /** Sets whether a vertex program includes the required instructions
+        to perform morph animation. 
+        @remarks
+        If this is set to true, OGRE will not blend the geometry according to 
+        morph animation, it will expect the vertex program to do it.
+        */
+        virtual void setMorphAnimationIncluded(bool included) 
+		{ mMorphAnimation = included; }
+
+        /** Sets whether a vertex program includes the required instructions
+        to perform pose animation. 
+        @remarks
+        If this is set to true, OGRE will not blend the geometry according to 
+        pose animation, it will expect the vertex program to do it.
+		@param poseCount The number of simultaneous poses the program can blend
+        */
+        virtual void setPoseAnimationIncluded(ushort poseCount) 
+		{ mPoseAnimation = poseCount; }
+
+		/** Returns whether a vertex program includes the required instructions
+            to perform morph animation. 
+        @remarks
+            If this returns true, OGRE will not blend the geometry according to 
+            morph animation, it will expect the vertex program to do it.
+        */
+        virtual bool isMorphAnimationIncluded(void) const { return mMorphAnimation; }
+
+		/** Returns whether a vertex program includes the required instructions
+            to perform pose animation. 
+        @remarks
+            If this returns true, OGRE will not blend the geometry according to 
+            pose animation, it will expect the vertex program to do it.
+        */
+        virtual bool isPoseAnimationIncluded(void) const { return mPoseAnimation > 0; }
+		/** Returns the number of simultaneous poses the vertex program can 
+			blend, for use in pose animation.
+        */
+        virtual ushort getNumberOfPosesIncluded(void) const { return mPoseAnimation; }
+		/** Sets whether this vertex program requires support for vertex 
+			texture fetch from the hardware.
+		*/
+		virtual void setVertexTextureFetchRequired(bool r) { mVertexTextureFetch = r; }
+		/** Returns whether this vertex program requires support for vertex 
+			texture fetch from the hardware.
+		*/
+		virtual bool isVertexTextureFetchRequired(void) const { return mVertexTextureFetch; }
+
+		/** Sets whether this geometry program requires adjacency information
+			from the input primitives.
+		*/
+		virtual void setAdjacencyInfoRequired(bool r) { mNeedsAdjacencyInfo = r; }
+		/** Returns whether this geometry program requires adjacency information 
+			from the input primitives.
+		*/
+		virtual bool isAdjacencyInfoRequired(void) const { return mNeedsAdjacencyInfo; }
+		
+		/** Get a reference to the default parameters which are to be used for all
+			uses of this program.
+		@remarks
+			A program can be set up with a list of default parameters, which can save time when 
+			using a program many times in a material with roughly the same settings. By 
+			retrieving the default parameters and populating it with the most used options, 
+			any new parameter objects created from this program afterwards will automatically include
+			the default parameters; thus users of the program need only change the parameters
+			which are unique to their own usage of the program.
+		*/
+		virtual GpuProgramParametersSharedPtr getDefaultParameters(void);
+
+        /** Returns true if default parameters have been set up.  
+        */
+        virtual bool hasDefaultParameters(void) const { return !mDefaultParams.isNull(); }
+
+		/** Returns whether a vertex program wants light and material states to be passed
+		through fixed pipeline low level API rendering calls (default false, subclasses can override)
+		@remarks
+			Most vertex programs do not need this material information, however GLSL
+			shaders can refer to this material and lighting state so enable this option
+		*/
+		virtual bool getPassSurfaceAndLightStates(void) const { return false; }
+
+		/** Returns whether a fragment program wants fog state to be passed
+		through fixed pipeline low level API rendering calls (default true, subclasses can override)
+		@remarks
+		On DirectX, shader model 2 and earlier continues to have fixed-function fog
+		applied to it, so fog state is still passed (you should disable fog on the
+		pass if you want to perform fog in the shader). In OpenGL it is also
+		common to be able to access the fixed-function fog state inside the shader. 
+		*/
+		virtual bool getPassFogStates(void) const { return true; }
+
+		/** Returns whether a vertex program wants transform state to be passed
+		through fixed pipeline low level API rendering calls
+		@remarks
+		Most vertex programs do not need fixed-function transform information, however GLSL
+		shaders can refer to this state so enable this option
+		*/
+		virtual bool getPassTransformStates(void) const { return false; }
+
+		/** Returns a string that specifies the language of the gpu programs as specified
+        in a material script. ie: asm, cg, hlsl, glsl
+        */
+        virtual const String& getLanguage(void) const;
+
+		/** Did this program encounter a compile error when loading?
+		*/
+		virtual bool hasCompileError(void) const { return mCompileError; }
+
+		/** Reset a compile error if it occurred, allowing the load to be retried
+		*/
+		virtual void resetCompileError(void) { mCompileError = false; }
+
+		/** Allows you to manually provide a set of named parameter mappings
+			to a program which would not be able to derive named parameters itself.
+		@remarks
+			You may wish to use this if you have assembler programs that were compiled
+			from a high-level source, and want the convenience of still being able
+			to use the named parameters from the original high-level source.
+		@see setManualNamedConstantsFile
+		*/
+		virtual void setManualNamedConstants(const GpuNamedConstants& namedConstants);
+
+		/// Get a read-only reference to the named constants registered for this program (manually or automatically)
+		virtual const GpuNamedConstants& getNamedConstants() const { return *mConstantDefs.get(); }
+
+		/** Specifies the name of a file from which to load named parameters mapping
+			for a program which would not be able to derive named parameters itself.
+		@remarks
+			You may wish to use this if you have assembler programs that were compiled
+			from a high-level source, and want the convenience of still being able
+			to use the named parameters from the original high-level source. This
+			method will make a low-level program search in the resource group of the
+			program for the named file from which to load parameter names from. 
+			The file must be in the format produced by GpuNamedConstants::save.
+		*/
+		virtual void setManualNamedConstantsFile(const String& paramDefFile);
+
+		/** Gets the name of a file from which to load named parameters mapping
+			for a program which would not be able to derive named parameters itself.
+		*/
+		virtual const String& getManualNamedConstantsFile() const { return mManualNamedConstantsFile; }
+		/** Get the full list of named constants.
+		@note
+		Only available if this parameters object has named parameters, which means either
+		a high-level program which loads them, or a low-level program which has them
+		specified manually.
+		*/
+		virtual const GpuNamedConstants& getConstantDefinitions() const { return *mConstantDefs.get(); }
+
+
+    protected:
+        /// Virtual method which must be implemented by subclasses, load from mSource
+        virtual void loadFromSource(void) = 0;
+
+	};
+
+
+	/** Specialisation of SharedPtr to allow SharedPtr to be assigned to GpuProgramPtr 
+	@note Has to be a subclass since we need operator=.
+	We could templatise this instead of repeating per Resource subclass, 
+	except to do so requires a form VC6 does not support i.e.
+	ResourceSubclassPtr<T> : public SharedPtr<T>
+	*/
+	class _OgreExport GpuProgramPtr : public SharedPtr<GpuProgram> 
+	{
+	public:
+		GpuProgramPtr() : SharedPtr<GpuProgram>() {}
+		explicit GpuProgramPtr(GpuProgram* rep) : SharedPtr<GpuProgram>(rep) {}
+		GpuProgramPtr(const GpuProgramPtr& r) : SharedPtr<GpuProgram>(r) {} 
+
+		// TODO PORT - I've hidden this cast until it will be needed
+        ///// Operator used to convert a HighLevelGpuProgramPtr to a GpuProgramPtr
+        //GpuProgramPtr& operator=(const HighLevelGpuProgramPtr& r);
+	};
+	/** @} */
+	/** @} */
+}
+
+#endif

+ 1935 - 0
CamelotRenderer/OgreGpuProgramParams.cpp

@@ -0,0 +1,1935 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+(Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org
+
+Copyright (c) 2000-2011 Torus Knot Software Ltd
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+-----------------------------------------------------------------------------
+*/
+#include "OgreGpuProgramParams.h"
+//#include "OgreHighLevelGpuProgram.h"
+#include "OgreVector3.h"
+#include "OgreVector4.h"
+#include "OgreRenderSystemCapabilities.h"
+#include "OgreStringConverter.h"
+#include "OgreException.h"
+
+
+namespace Ogre
+{
+
+	//---------------------------------------------------------------------
+	GpuProgramParameters::AutoConstantDefinition GpuProgramParameters::AutoConstantDictionary[] = {
+		AutoConstantDefinition(ACT_WORLD_MATRIX,                  "world_matrix",                16, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_INVERSE_WORLD_MATRIX,          "inverse_world_matrix",        16, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_TRANSPOSE_WORLD_MATRIX,             "transpose_world_matrix",            16, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_INVERSE_TRANSPOSE_WORLD_MATRIX, "inverse_transpose_world_matrix", 16, ET_REAL, ACDT_NONE),
+
+		AutoConstantDefinition(ACT_WORLD_MATRIX_ARRAY_3x4,        "world_matrix_array_3x4",      12, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_WORLD_MATRIX_ARRAY,            "world_matrix_array",          16, ET_REAL, ACDT_NONE),
+
+		AutoConstantDefinition(ACT_VIEW_MATRIX,                   "view_matrix",                 16, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_INVERSE_VIEW_MATRIX,           "inverse_view_matrix",         16, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_TRANSPOSE_VIEW_MATRIX,              "transpose_view_matrix",             16, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_INVERSE_TRANSPOSE_VIEW_MATRIX,       "inverse_transpose_view_matrix",     16, ET_REAL, ACDT_NONE),
+
+		AutoConstantDefinition(ACT_PROJECTION_MATRIX,             "projection_matrix",           16, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_INVERSE_PROJECTION_MATRIX,          "inverse_projection_matrix",         16, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_TRANSPOSE_PROJECTION_MATRIX,        "transpose_projection_matrix",       16, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_INVERSE_TRANSPOSE_PROJECTION_MATRIX, "inverse_transpose_projection_matrix", 16, ET_REAL, ACDT_NONE),
+
+		AutoConstantDefinition(ACT_VIEWPROJ_MATRIX,               "viewproj_matrix",             16, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_INVERSE_VIEWPROJ_MATRIX,       "inverse_viewproj_matrix",     16, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_TRANSPOSE_VIEWPROJ_MATRIX,          "transpose_viewproj_matrix",         16, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_INVERSE_TRANSPOSE_VIEWPROJ_MATRIX,   "inverse_transpose_viewproj_matrix", 16, ET_REAL, ACDT_NONE),
+
+		AutoConstantDefinition(ACT_WORLDVIEW_MATRIX,              "worldview_matrix",            16, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_INVERSE_WORLDVIEW_MATRIX,      "inverse_worldview_matrix",    16, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_TRANSPOSE_WORLDVIEW_MATRIX,         "transpose_worldview_matrix",        16, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_INVERSE_TRANSPOSE_WORLDVIEW_MATRIX, "inverse_transpose_worldview_matrix", 16, ET_REAL, ACDT_NONE),
+
+		AutoConstantDefinition(ACT_WORLDVIEWPROJ_MATRIX,          "worldviewproj_matrix",        16, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_INVERSE_WORLDVIEWPROJ_MATRIX,       "inverse_worldviewproj_matrix",      16, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_TRANSPOSE_WORLDVIEWPROJ_MATRIX,     "transpose_worldviewproj_matrix",    16, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_INVERSE_TRANSPOSE_WORLDVIEWPROJ_MATRIX, "inverse_transpose_worldviewproj_matrix", 16, ET_REAL, ACDT_NONE),
+
+		AutoConstantDefinition(ACT_RENDER_TARGET_FLIPPING,          "render_target_flipping",         1, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_VERTEX_WINDING,          "vertex_winding",         1, ET_REAL, ACDT_NONE),
+
+		AutoConstantDefinition(ACT_FOG_COLOUR,                    "fog_colour",                   4, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_FOG_PARAMS,                    "fog_params",                   4, ET_REAL, ACDT_NONE),
+
+		AutoConstantDefinition(ACT_SURFACE_AMBIENT_COLOUR,          "surface_ambient_colour",           4, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_SURFACE_DIFFUSE_COLOUR,          "surface_diffuse_colour",           4, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_SURFACE_SPECULAR_COLOUR,         "surface_specular_colour",          4, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_SURFACE_EMISSIVE_COLOUR,         "surface_emissive_colour",          4, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_SURFACE_SHININESS,               "surface_shininess",                1, ET_REAL, ACDT_NONE),
+
+		AutoConstantDefinition(ACT_LIGHT_COUNT,                   "light_count",                  1, ET_REAL, ACDT_NONE),
+
+		AutoConstantDefinition(ACT_AMBIENT_LIGHT_COLOUR,          "ambient_light_colour",         4, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_LIGHT_DIFFUSE_COLOUR,          "light_diffuse_colour",         4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_SPECULAR_COLOUR,         "light_specular_colour",        4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_ATTENUATION,             "light_attenuation",            4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_SPOTLIGHT_PARAMS,              "spotlight_params",             4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_POSITION,                "light_position",               4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_POSITION_OBJECT_SPACE,   "light_position_object_space",  4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_POSITION_VIEW_SPACE,          "light_position_view_space",    4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_DIRECTION,               "light_direction",              4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_DIRECTION_OBJECT_SPACE,  "light_direction_object_space", 4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_DIRECTION_VIEW_SPACE,         "light_direction_view_space",   4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_DISTANCE_OBJECT_SPACE,   "light_distance_object_space",  1, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_POWER_SCALE,   		  "light_power",  1, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED, "light_diffuse_colour_power_scaled",         4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED, "light_specular_colour_power_scaled",        4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_DIFFUSE_COLOUR_ARRAY,          "light_diffuse_colour_array",         4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_SPECULAR_COLOUR_ARRAY,         "light_specular_colour_array",        4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED_ARRAY, "light_diffuse_colour_power_scaled_array",         4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED_ARRAY, "light_specular_colour_power_scaled_array",        4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_ATTENUATION_ARRAY,             "light_attenuation_array",            4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_POSITION_ARRAY,                "light_position_array",               4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_POSITION_OBJECT_SPACE_ARRAY,   "light_position_object_space_array",  4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_POSITION_VIEW_SPACE_ARRAY,          "light_position_view_space_array",    4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_DIRECTION_ARRAY,               "light_direction_array",              4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_DIRECTION_OBJECT_SPACE_ARRAY,  "light_direction_object_space_array", 4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_DIRECTION_VIEW_SPACE_ARRAY,         "light_direction_view_space_array",   4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_DISTANCE_OBJECT_SPACE_ARRAY,   "light_distance_object_space_array",  1, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_POWER_SCALE_ARRAY,   		  "light_power_array",  1, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_SPOTLIGHT_PARAMS_ARRAY,              "spotlight_params_array",             4, ET_REAL, ACDT_INT),
+
+		AutoConstantDefinition(ACT_DERIVED_AMBIENT_LIGHT_COLOUR,    "derived_ambient_light_colour",     4, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_DERIVED_SCENE_COLOUR,            "derived_scene_colour",             4, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_DERIVED_LIGHT_DIFFUSE_COLOUR,    "derived_light_diffuse_colour",     4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_DERIVED_LIGHT_SPECULAR_COLOUR,   "derived_light_specular_colour",    4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_DERIVED_LIGHT_DIFFUSE_COLOUR_ARRAY,  "derived_light_diffuse_colour_array",   4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_DERIVED_LIGHT_SPECULAR_COLOUR_ARRAY, "derived_light_specular_colour_array",  4, ET_REAL, ACDT_INT),
+
+		AutoConstantDefinition(ACT_LIGHT_NUMBER,   					  "light_number",  1, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LIGHT_CASTS_SHADOWS, 			  "light_casts_shadows",  1, ET_REAL, ACDT_INT),
+
+		AutoConstantDefinition(ACT_SHADOW_EXTRUSION_DISTANCE,     "shadow_extrusion_distance",    1, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_CAMERA_POSITION,               "camera_position",              3, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_CAMERA_POSITION_OBJECT_SPACE,  "camera_position_object_space", 3, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_TEXTURE_VIEWPROJ_MATRIX,       "texture_viewproj_matrix",     16, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_TEXTURE_VIEWPROJ_MATRIX_ARRAY, "texture_viewproj_matrix_array", 16, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_TEXTURE_WORLDVIEWPROJ_MATRIX,  "texture_worldviewproj_matrix",16, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_TEXTURE_WORLDVIEWPROJ_MATRIX_ARRAY, "texture_worldviewproj_matrix_array",16, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_SPOTLIGHT_VIEWPROJ_MATRIX,       "spotlight_viewproj_matrix",     16, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_SPOTLIGHT_VIEWPROJ_MATRIX_ARRAY, "spotlight_viewproj_matrix_array", 16, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_SPOTLIGHT_WORLDVIEWPROJ_MATRIX,  "spotlight_worldviewproj_matrix",16, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_CUSTOM,                        "custom",                       4, ET_REAL, ACDT_INT),  // *** needs to be tested
+		AutoConstantDefinition(ACT_TIME,                               "time",                               1, ET_REAL, ACDT_REAL),
+		AutoConstantDefinition(ACT_TIME_0_X,                      "time_0_x",                     4, ET_REAL, ACDT_REAL),
+		AutoConstantDefinition(ACT_COSTIME_0_X,                   "costime_0_x",                  4, ET_REAL, ACDT_REAL),
+		AutoConstantDefinition(ACT_SINTIME_0_X,                   "sintime_0_x",                  4, ET_REAL, ACDT_REAL),
+		AutoConstantDefinition(ACT_TANTIME_0_X,                   "tantime_0_x",                  4, ET_REAL, ACDT_REAL),
+		AutoConstantDefinition(ACT_TIME_0_X_PACKED,               "time_0_x_packed",              4, ET_REAL, ACDT_REAL),
+		AutoConstantDefinition(ACT_TIME_0_1,                      "time_0_1",                     4, ET_REAL, ACDT_REAL),
+		AutoConstantDefinition(ACT_COSTIME_0_1,                   "costime_0_1",                  4, ET_REAL, ACDT_REAL),
+		AutoConstantDefinition(ACT_SINTIME_0_1,                   "sintime_0_1",                  4, ET_REAL, ACDT_REAL),
+		AutoConstantDefinition(ACT_TANTIME_0_1,                   "tantime_0_1",                  4, ET_REAL, ACDT_REAL),
+		AutoConstantDefinition(ACT_TIME_0_1_PACKED,               "time_0_1_packed",              4, ET_REAL, ACDT_REAL),
+		AutoConstantDefinition(ACT_TIME_0_2PI,                    "time_0_2pi",                   4, ET_REAL, ACDT_REAL),
+		AutoConstantDefinition(ACT_COSTIME_0_2PI,                 "costime_0_2pi",                4, ET_REAL, ACDT_REAL),
+		AutoConstantDefinition(ACT_SINTIME_0_2PI,                 "sintime_0_2pi",                4, ET_REAL, ACDT_REAL),
+		AutoConstantDefinition(ACT_TANTIME_0_2PI,                 "tantime_0_2pi",                4, ET_REAL, ACDT_REAL),
+		AutoConstantDefinition(ACT_TIME_0_2PI_PACKED,             "time_0_2pi_packed",            4, ET_REAL, ACDT_REAL),
+		AutoConstantDefinition(ACT_FRAME_TIME,                    "frame_time",                   1, ET_REAL, ACDT_REAL),
+		AutoConstantDefinition(ACT_FPS,                           "fps",                          1, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_VIEWPORT_WIDTH,                "viewport_width",               1, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_VIEWPORT_HEIGHT,               "viewport_height",              1, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_INVERSE_VIEWPORT_WIDTH,        "inverse_viewport_width",       1, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_INVERSE_VIEWPORT_HEIGHT,       "inverse_viewport_height",      1, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_VIEWPORT_SIZE,                 "viewport_size",                4, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_VIEW_DIRECTION,                "view_direction",               3, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_VIEW_SIDE_VECTOR,              "view_side_vector",             3, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_VIEW_UP_VECTOR,                "view_up_vector",               3, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_FOV,                           "fov",                          1, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_NEAR_CLIP_DISTANCE,            "near_clip_distance",           1, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_FAR_CLIP_DISTANCE,             "far_clip_distance",            1, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_PASS_NUMBER,                        "pass_number",                        1, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_PASS_ITERATION_NUMBER,              "pass_iteration_number",              1, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_ANIMATION_PARAMETRIC,               "animation_parametric",               4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_TEXEL_OFFSETS,               "texel_offsets",				  4, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_SCENE_DEPTH_RANGE,           "scene_depth_range",			  4, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_SHADOW_SCENE_DEPTH_RANGE,    "shadow_scene_depth_range",		  4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_SHADOW_COLOUR,				"shadow_colour",				  4, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_TEXTURE_SIZE,                "texture_size",                   4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_INVERSE_TEXTURE_SIZE,        "inverse_texture_size",           4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_PACKED_TEXTURE_SIZE,         "packed_texture_size",            4, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_TEXTURE_MATRIX,  "texture_matrix", 16, ET_REAL, ACDT_INT),
+		AutoConstantDefinition(ACT_LOD_CAMERA_POSITION,               "lod_camera_position",              3, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_LOD_CAMERA_POSITION_OBJECT_SPACE,  "lod_camera_position_object_space", 3, ET_REAL, ACDT_NONE),
+		AutoConstantDefinition(ACT_LIGHT_CUSTOM,	"light_custom", 4, ET_REAL, ACDT_INT)
+	};
+
+	bool GpuNamedConstants::msGenerateAllConstantDefinitionArrayEntries = false;
+
+	//---------------------------------------------------------------------
+	void GpuNamedConstants::generateConstantDefinitionArrayEntries(
+		const String& paramName, const GpuConstantDefinition& baseDef)
+	{
+		// Copy definition for use with arrays
+		GpuConstantDefinition arrayDef = baseDef;
+		arrayDef.arraySize = 1;
+		String arrayName;
+
+		// Add parameters for array accessors
+		// [0] will refer to the same location, [1+] will increment
+		// only populate others individually up to 16 array slots so as not to get out of hand,
+		// unless the system has been explicitly configured to allow all the parameters to be added
+
+		// paramName[0] version will always exist 
+		size_t maxArrayIndex = 1;
+		if (baseDef.arraySize <= 16 || msGenerateAllConstantDefinitionArrayEntries)
+			maxArrayIndex = baseDef.arraySize;
+
+		for (size_t i = 0; i < maxArrayIndex; i++)
+		{
+			arrayName = paramName + "[" + StringConverter::toString(i) + "]";
+			map.insert(GpuConstantDefinitionMap::value_type(arrayName, arrayDef));
+			// increment location
+			arrayDef.physicalIndex += arrayDef.elementSize;
+		}
+		// note no increment of buffer sizes since this is shared with main array def
+
+	}
+
+	//---------------------------------------------------------------------
+	bool GpuNamedConstants::getGenerateAllConstantDefinitionArrayEntries()
+	{
+		return msGenerateAllConstantDefinitionArrayEntries;
+	}
+
+	//---------------------------------------------------------------------
+	void GpuNamedConstants::setGenerateAllConstantDefinitionArrayEntries(bool generateAll)
+	{
+		msGenerateAllConstantDefinitionArrayEntries = generateAll;
+	}    
+	//-----------------------------------------------------------------------------
+	//      GpuSharedParameters Methods
+	//-----------------------------------------------------------------------------
+	GpuSharedParameters::GpuSharedParameters(const String& name)
+		:mName(name)
+		// TODO PORT - Commented out because I don't have root in port. But I dont think this will be needed in final version
+		/*, mFrameLastUpdated(Root::getSingleton().getNextFrameNumber())*/
+		, mFrameLastUpdated(0)
+		, mVersion(0)
+	{
+
+	}
+	//---------------------------------------------------------------------
+	GpuSharedParameters::~GpuSharedParameters()
+	{
+
+	}
+	//---------------------------------------------------------------------
+	void GpuSharedParameters::addConstantDefinition(const String& name, GpuConstantType constType, size_t arraySize)
+	{
+		if (mNamedConstants.map.find(name) != mNamedConstants.map.end())
+		{
+			OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
+				"Constant entry with name '" + name + "' already exists. ", 
+				"GpuSharedParameters::addConstantDefinition");
+		}
+		GpuConstantDefinition def;
+		def.arraySize = arraySize;
+		def.constType = constType;
+		// for compatibility we do not pad values to multiples of 4
+		// when it comes to arrays, user is responsible for creating matching defs
+		def.elementSize = GpuConstantDefinition::getElementSize(constType, false);
+
+		// not used
+		def.logicalIndex = 0;
+		def.variability = (uint16)GPV_GLOBAL;
+
+		if (def.isFloat())
+		{
+			def.physicalIndex = mFloatConstants.size();
+			mFloatConstants.resize(mFloatConstants.size() + def.arraySize * def.elementSize);
+		}
+		else
+		{
+			def.physicalIndex = mIntConstants.size();
+			mIntConstants.resize(mIntConstants.size() + def.arraySize * def.elementSize);
+		}
+
+		mNamedConstants.map[name] = def;
+
+		++mVersion;
+	}
+	//---------------------------------------------------------------------
+	void GpuSharedParameters::removeConstantDefinition(const String& name)
+	{
+		GpuConstantDefinitionMap::iterator i = mNamedConstants.map.find(name);
+		if (i != mNamedConstants.map.end())
+		{
+			GpuConstantDefinition& def = i->second;
+			bool isFloat = def.isFloat();
+			size_t numElems = def.elementSize * def.arraySize;
+
+			for (GpuConstantDefinitionMap::iterator j = mNamedConstants.map.begin();
+				j != mNamedConstants.map.end(); ++j)
+			{
+				GpuConstantDefinition& otherDef = j->second;
+				bool otherIsFloat = otherDef.isFloat();
+
+				// same type, and comes after in the buffer
+				if ( ((isFloat && otherIsFloat) || (!isFloat && !otherIsFloat)) && 
+					otherDef.physicalIndex > def.physicalIndex)
+				{
+					// adjust index
+					otherDef.physicalIndex -= numElems;
+				}
+			}
+
+			// remove floats and reduce buffer
+			if (isFloat)
+			{
+				mNamedConstants.floatBufferSize -= numElems;
+
+				FloatConstantList::iterator beg = mFloatConstants.begin();
+				std::advance(beg, def.physicalIndex);
+				FloatConstantList::iterator en = beg;
+				std::advance(en, numElems);
+				mFloatConstants.erase(beg, en);
+			}
+			else
+			{
+				mNamedConstants.intBufferSize -= numElems;
+
+				IntConstantList::iterator beg = mIntConstants.begin();
+				std::advance(beg, def.physicalIndex);
+				IntConstantList::iterator en = beg;
+				std::advance(en, numElems);
+				mIntConstants.erase(beg, en);
+
+			}
+
+			++mVersion;
+			
+		}
+
+	}
+	//---------------------------------------------------------------------
+	void GpuSharedParameters::removeAllConstantDefinitions()
+	{
+		mNamedConstants.map.clear();
+		mNamedConstants.floatBufferSize = 0;
+		mNamedConstants.intBufferSize = 0;
+		mFloatConstants.clear();
+		mIntConstants.clear();
+	}
+	//---------------------------------------------------------------------
+	GpuConstantDefinitionIterator GpuSharedParameters::getConstantDefinitionIterator(void) const
+	{
+		return mNamedConstants.map.begin();
+	}
+	//---------------------------------------------------------------------
+	const GpuConstantDefinition& GpuSharedParameters::getConstantDefinition(const String& name) const
+	{
+		GpuConstantDefinitionMap::const_iterator i = mNamedConstants.map.find(name);
+		if (i == mNamedConstants.map.end())
+		{
+			OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
+				"Constant entry with name '" + name + "' does not exist. ", 
+				"GpuSharedParameters::getConstantDefinition");
+		}
+		return i->second;
+	}
+	//---------------------------------------------------------------------
+	const GpuNamedConstants& GpuSharedParameters::getConstantDefinitions() const
+	{
+		return mNamedConstants;
+	}
+	//---------------------------------------------------------------------
+	void GpuSharedParameters::setNamedConstant(const String& name, Real val)
+	{
+		setNamedConstant(name, &val, 1);
+	}
+	//---------------------------------------------------------------------
+	void GpuSharedParameters::setNamedConstant(const String& name, int val)
+	{
+		setNamedConstant(name, &val, 1);
+	}
+	//---------------------------------------------------------------------
+	void GpuSharedParameters::setNamedConstant(const String& name, const Vector4& vec)
+	{
+		setNamedConstant(name, vec.ptr(), 4);
+	}
+	//---------------------------------------------------------------------
+	void GpuSharedParameters::setNamedConstant(const String& name, const Vector3& vec)
+	{
+		setNamedConstant(name, vec.ptr(), 3);
+	}
+	//---------------------------------------------------------------------
+	void GpuSharedParameters::setNamedConstant(const String& name, const Matrix4& m)
+	{
+		setNamedConstant(name, m[0], 16);
+	}
+	//---------------------------------------------------------------------
+	void GpuSharedParameters::setNamedConstant(const String& name, const Matrix4* m, size_t numEntries)
+	{
+		setNamedConstant(name, m[0][0], 16 * numEntries);
+	}
+	//---------------------------------------------------------------------
+	void GpuSharedParameters::setNamedConstant(const String& name, const float *val, size_t count)
+	{
+		GpuConstantDefinitionMap::const_iterator i = mNamedConstants.map.find(name);
+		if (i != mNamedConstants.map.end())
+		{
+			const GpuConstantDefinition& def = i->second;
+			memcpy(&mFloatConstants[def.physicalIndex], val, 
+				sizeof(float) * std::min(count, def.elementSize * def.arraySize));
+		}
+
+		_markDirty();
+
+	}
+	//---------------------------------------------------------------------
+	void GpuSharedParameters::setNamedConstant(const String& name, const double *val, size_t count)
+	{
+		GpuConstantDefinitionMap::const_iterator i = mNamedConstants.map.find(name);
+		if (i != mNamedConstants.map.end())
+		{
+			const GpuConstantDefinition& def = i->second;
+
+			count = std::min(count, def.elementSize * def.arraySize);
+			const double* src = val;
+			float* dst = &mFloatConstants[def.physicalIndex];
+			for (size_t v = 0; v < count; ++v)
+			{
+				*dst++ = static_cast<float>(*src++);
+			}
+		}
+
+		_markDirty();
+
+	}
+	//---------------------------------------------------------------------
+	void GpuSharedParameters::setNamedConstant(const String& name, const ColourValue& colour)
+	{
+		setNamedConstant(name, colour.ptr(), 4);
+	}
+	//---------------------------------------------------------------------
+	void GpuSharedParameters::setNamedConstant(const String& name, const int *val, size_t count)
+	{
+		GpuConstantDefinitionMap::const_iterator i = mNamedConstants.map.find(name);
+		if (i != mNamedConstants.map.end())
+		{
+			const GpuConstantDefinition& def = i->second;
+			memcpy(&mIntConstants[def.physicalIndex], val, 
+				sizeof(int) * std::min(count, def.elementSize * def.arraySize));
+		}
+
+		_markDirty();
+
+	}
+	//---------------------------------------------------------------------
+	void GpuSharedParameters::_markDirty()
+	{
+		// TODO PORT - Don't have access to Root in port. Set it to 0 for now. Will probably be able to remove this completely
+		mFrameLastUpdated = 0;
+		/*mFrameLastUpdated = Root::getSingleton().getNextFrameNumber();*/
+	}
+
+	//-----------------------------------------------------------------------------
+	//      GpuSharedParametersUsage Methods
+	//-----------------------------------------------------------------------------
+	GpuSharedParametersUsage::GpuSharedParametersUsage(GpuSharedParametersPtr sharedParams, 
+		GpuProgramParameters* params)
+		: mSharedParams(sharedParams)
+		, mParams(params)
+	{
+		initCopyData();
+	}
+	//---------------------------------------------------------------------
+	void GpuSharedParametersUsage::initCopyData()
+	{
+
+		mCopyDataList.clear();
+
+		const GpuConstantDefinitionMap& sharedmap = mSharedParams->getConstantDefinitions().map;
+		for (GpuConstantDefinitionMap::const_iterator i = sharedmap.begin(); i != sharedmap.end(); ++i)
+		{
+			const String& pName = i->first;
+			const GpuConstantDefinition& shareddef = i->second;
+
+			const GpuConstantDefinition* instdef = mParams->_findNamedConstantDefinition(pName, false);
+			if (instdef)
+			{
+				// Check that the definitions are the same 
+				if (instdef->constType == shareddef.constType && 
+					instdef->arraySize == shareddef.arraySize)
+				{
+					CopyDataEntry e;
+					e.srcDefinition = &shareddef;
+					e.dstDefinition = instdef;
+					mCopyDataList.push_back(e);
+				}
+			}
+
+		}
+
+		mCopyDataVersion = mSharedParams->getVersion();
+
+	}
+	//---------------------------------------------------------------------
+	void GpuSharedParametersUsage::_copySharedParamsToTargetParams()
+	{
+		// check copy data version
+		if (mCopyDataVersion != mSharedParams->getVersion())
+			initCopyData();
+
+		for (CopyDataList::iterator i = mCopyDataList.begin(); i != mCopyDataList.end(); ++i)
+		{
+			CopyDataEntry& e = *i;
+
+			if (e.dstDefinition->isFloat())
+			{	
+				const float* pSrc = mSharedParams->getFloatPointer(e.srcDefinition->physicalIndex);
+				float* pDst = mParams->getFloatPointer(e.dstDefinition->physicalIndex);
+
+				// Deal with matrix transposition here!!!
+				// transposition is specific to the dest param set, shared params don't do it
+				if (mParams->getTransposeMatrices() && e.dstDefinition->constType == GCT_MATRIX_4X4)
+				{
+					for (int row = 0; row < 4; ++row)
+						for (int col = 0; col < 4; ++col)
+							pDst[row * 4 + col] = pSrc[col * 4 + row];
+				}
+				else
+				{
+					if (e.dstDefinition->elementSize == e.srcDefinition->elementSize)
+					{
+						// simple copy
+						memcpy(pDst, pSrc, sizeof(float) * e.dstDefinition->elementSize * e.dstDefinition->arraySize);
+					}
+					else
+					{
+						// target params may be padded to 4 elements, shared params are packed
+						assert(e.dstDefinition->elementSize % 4 == 0);
+						size_t iterations = e.dstDefinition->elementSize / 4 
+							* e.dstDefinition->arraySize;
+						size_t valsPerIteration = e.srcDefinition->elementSize / iterations;
+						for (size_t l = 0; l < iterations; ++l)
+						{
+							memcpy(pDst, pSrc, sizeof(float) * valsPerIteration);
+							pSrc += valsPerIteration;
+							pDst += 4;
+						}
+					}
+				}
+			}
+			else
+			{
+				const int* pSrc = mSharedParams->getIntPointer(e.srcDefinition->physicalIndex);
+				int* pDst = mParams->getIntPointer(e.dstDefinition->physicalIndex);
+
+				if (e.dstDefinition->elementSize == e.srcDefinition->elementSize)
+				{
+					// simple copy
+					memcpy(pDst, pSrc, sizeof(int) * e.dstDefinition->elementSize * e.dstDefinition->arraySize);
+				}
+				else
+				{
+					// target params may be padded to 4 elements, shared params are packed
+					assert(e.dstDefinition->elementSize % 4 == 0);
+					size_t iterations = (e.dstDefinition->elementSize / 4)
+						* e.dstDefinition->arraySize;
+					size_t valsPerIteration = e.srcDefinition->elementSize / iterations;
+					for (size_t l = 0; l < iterations; ++l)
+					{
+						memcpy(pDst, pSrc, sizeof(int) * valsPerIteration);
+						pSrc += valsPerIteration;
+						pDst += 4;
+					}
+				}
+			}
+		}
+	}
+
+
+
+	//-----------------------------------------------------------------------------
+	//      GpuProgramParameters Methods
+	//-----------------------------------------------------------------------------
+	GpuProgramParameters::GpuProgramParameters() :
+		mCombinedVariability(GPV_GLOBAL)
+		, mTransposeMatrices(false)
+		, mIgnoreMissingParams(false)
+		, mActivePassIterationIndex(std::numeric_limits<size_t>::max())	
+	{
+	}
+	//-----------------------------------------------------------------------------
+
+	GpuProgramParameters::GpuProgramParameters(const GpuProgramParameters& oth)
+	{
+		*this = oth;
+	}
+
+	//-----------------------------------------------------------------------------
+	GpuProgramParameters& GpuProgramParameters::operator=(const GpuProgramParameters& oth)
+	{
+		// let compiler perform shallow copies of structures 
+		// AutoConstantEntry, RealConstantEntry, IntConstantEntry
+		mFloatConstants = oth.mFloatConstants;
+		mIntConstants  = oth.mIntConstants;
+		mAutoConstants = oth.mAutoConstants;
+		mFloatLogicalToPhysical = oth.mFloatLogicalToPhysical;
+		mIntLogicalToPhysical = oth.mIntLogicalToPhysical;
+		mNamedConstants = oth.mNamedConstants;
+		copySharedParamSetUsage(oth.mSharedParamSets);
+
+		mCombinedVariability = oth.mCombinedVariability;
+		mTransposeMatrices = oth.mTransposeMatrices;
+		mIgnoreMissingParams  = oth.mIgnoreMissingParams;
+		mActivePassIterationIndex = oth.mActivePassIterationIndex;
+
+		return *this;
+	}
+	//---------------------------------------------------------------------
+	void GpuProgramParameters::copySharedParamSetUsage(const GpuSharedParamUsageList& srcList)
+	{
+		mSharedParamSets.clear();
+		for (GpuSharedParamUsageList::const_iterator i = srcList.begin(); i != srcList.end(); ++i)
+		{
+			mSharedParamSets.push_back(GpuSharedParametersUsage(i->getSharedParams(), this));
+		}
+
+	}
+	//---------------------------------------------------------------------
+	void GpuProgramParameters::_setNamedConstants(
+		const GpuNamedConstantsPtr& namedConstants)
+	{
+		mNamedConstants = namedConstants;
+
+		// Determine any extension to local buffers
+
+		// Size and reset buffer (fill with zero to make comparison later ok)
+		if (namedConstants->floatBufferSize > mFloatConstants.size())
+		{
+			mFloatConstants.insert(mFloatConstants.end(), 
+				namedConstants->floatBufferSize - mFloatConstants.size(), 0.0f);
+		}
+		if (namedConstants->intBufferSize > mIntConstants.size())
+		{
+			mIntConstants.insert(mIntConstants.end(), 
+				namedConstants->intBufferSize - mIntConstants.size(), 0);
+		}
+	}
+	//---------------------------------------------------------------------
+	void GpuProgramParameters::_setLogicalIndexes(
+		const GpuLogicalBufferStructPtr& floatIndexMap, 
+		const GpuLogicalBufferStructPtr& intIndexMap)
+	{
+		mFloatLogicalToPhysical = floatIndexMap;
+		mIntLogicalToPhysical = intIndexMap;
+
+		// resize the internal buffers
+		// Note that these will only contain something after the first parameter
+		// set has set some parameters
+
+		// Size and reset buffer (fill with zero to make comparison later ok)
+		if (!floatIndexMap.isNull() && floatIndexMap->bufferSize > mFloatConstants.size())
+		{
+			mFloatConstants.insert(mFloatConstants.end(), 
+				floatIndexMap->bufferSize - mFloatConstants.size(), 0.0f);
+		}
+		if (!intIndexMap.isNull() &&  intIndexMap->bufferSize > mIntConstants.size())
+		{
+			mIntConstants.insert(mIntConstants.end(), 
+				intIndexMap->bufferSize - mIntConstants.size(), 0);
+		}
+
+	}
+	//---------------------------------------------------------------------()
+	void GpuProgramParameters::setConstant(size_t index, const Vector4& vec)
+	{
+		setConstant(index, vec.ptr(), 1);
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::setConstant(size_t index, Real val)
+	{
+		setConstant(index, Vector4(val, 0.0f, 0.0f, 0.0f));
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::setConstant(size_t index, const Vector3& vec)
+	{
+		setConstant(index, Vector4(vec.x, vec.y, vec.z, 1.0f));
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::setConstant(size_t index, const Matrix4& m)
+	{
+		// set as 4x 4-element floats
+		if (mTransposeMatrices)
+		{
+			Matrix4 t = m.transpose();
+			GpuProgramParameters::setConstant(index, t[0], 4);
+		}
+		else
+		{
+			GpuProgramParameters::setConstant(index, m[0], 4);
+		}
+
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::setConstant(size_t index, const Matrix4* pMatrix, 
+		size_t numEntries)
+	{
+		if (mTransposeMatrices)
+		{
+			for (size_t i = 0; i < numEntries; ++i)
+			{
+				Matrix4 t = pMatrix[i].transpose();
+				GpuProgramParameters::setConstant(index, t[0], 4);
+				index += 4;
+			}
+		}
+		else
+		{
+			GpuProgramParameters::setConstant(index, pMatrix[0][0], 4 * numEntries);
+		}
+
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::setConstant(size_t index, const ColourValue& colour)
+	{
+		setConstant(index, colour.ptr(), 1);
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::setConstant(size_t index, const float *val, size_t count)
+	{
+		// Raw buffer size is 4x count
+		size_t rawCount = count * 4;
+		// get physical index
+		assert(!mFloatLogicalToPhysical.isNull() && "GpuProgram hasn't set up the logical -> physical map!");
+
+		size_t physicalIndex = _getFloatConstantPhysicalIndex(index, rawCount, GPV_GLOBAL);
+
+		// Copy 
+		_writeRawConstants(physicalIndex, val, rawCount);
+
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::setConstant(size_t index, const double *val, size_t count)
+	{
+		// Raw buffer size is 4x count
+		size_t rawCount = count * 4;
+		// get physical index
+		assert(!mFloatLogicalToPhysical.isNull() && "GpuProgram hasn't set up the logical -> physical map!");
+
+		size_t physicalIndex = _getFloatConstantPhysicalIndex(index, rawCount, GPV_GLOBAL);
+		assert(physicalIndex + rawCount <= mFloatConstants.size());
+		// Copy manually since cast required
+		for (size_t i = 0; i < rawCount; ++i)
+		{
+			mFloatConstants[physicalIndex + i] = 
+				static_cast<float>(val[i]);
+		}
+
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::setConstant(size_t index, const int *val, size_t count)
+	{
+		// Raw buffer size is 4x count
+		size_t rawCount = count * 4;
+		// get physical index
+		assert(!mIntLogicalToPhysical.isNull() && "GpuProgram hasn't set up the logical -> physical map!");
+
+		size_t physicalIndex = _getIntConstantPhysicalIndex(index, rawCount, GPV_GLOBAL);
+		// Copy 
+		_writeRawConstants(physicalIndex, val, rawCount);
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::_writeRawConstant(size_t physicalIndex, const Vector4& vec,
+		size_t count)
+	{
+		// remember, raw content access uses raw float count rather than float4
+		// write either the number requested (for packed types) or up to 4
+		_writeRawConstants(physicalIndex, vec.ptr(), std::min(count, (size_t)4));
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::_writeRawConstant(size_t physicalIndex, Real val)
+	{
+		_writeRawConstants(physicalIndex, &val, 1);
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::_writeRawConstant(size_t physicalIndex, int val)
+	{
+		_writeRawConstants(physicalIndex, &val, 1);
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::_writeRawConstant(size_t physicalIndex, const Vector3& vec)
+	{
+		_writeRawConstants(physicalIndex, vec.ptr(), 3);		
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::_writeRawConstant(size_t physicalIndex, const Matrix4& m,size_t elementCount)
+	{
+
+		// remember, raw content access uses raw float count rather than float4
+		if (mTransposeMatrices)
+		{
+			Matrix4 t = m.transpose();
+			_writeRawConstants(physicalIndex, t[0], elementCount>16?16:elementCount);
+		}
+		else
+		{
+			_writeRawConstants(physicalIndex, m[0], elementCount>16?16:elementCount);
+		}
+
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::_writeRawConstant(size_t physicalIndex, const Matrix4* pMatrix, size_t numEntries)
+	{
+		// remember, raw content access uses raw float count rather than float4
+		if (mTransposeMatrices)
+		{
+			for (size_t i = 0; i < numEntries; ++i)
+			{
+				Matrix4 t = pMatrix[i].transpose();
+				_writeRawConstants(physicalIndex, t[0], 16);
+				physicalIndex += 16;
+			}
+		}
+		else
+		{
+			_writeRawConstants(physicalIndex, pMatrix[0][0], 16 * numEntries);
+		}
+
+
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::_writeRawConstant(size_t physicalIndex, 
+		const ColourValue& colour, size_t count)
+	{
+		// write either the number requested (for packed types) or up to 4
+		_writeRawConstants(physicalIndex, colour.ptr(), std::min(count, (size_t)4));
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::_writeRawConstants(size_t physicalIndex, const double* val, size_t count)
+	{
+		assert(physicalIndex + count <= mFloatConstants.size());
+		for (size_t i = 0; i < count; ++i)
+		{
+			mFloatConstants[physicalIndex+i] = static_cast<float>(val[i]);
+		}
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::_writeRawConstants(size_t physicalIndex, const float* val, size_t count)
+	{
+		assert(physicalIndex + count <= mFloatConstants.size());
+		memcpy(&mFloatConstants[physicalIndex], val, sizeof(float) * count);
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::_writeRawConstants(size_t physicalIndex, const int* val, size_t count)
+	{
+		assert(physicalIndex + count <= mIntConstants.size());
+		memcpy(&mIntConstants[physicalIndex], val, sizeof(int) * count);
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::_readRawConstants(size_t physicalIndex, size_t count, float* dest)
+	{
+		assert(physicalIndex + count <= mFloatConstants.size());
+		memcpy(dest, &mFloatConstants[physicalIndex], sizeof(float) * count);
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::_readRawConstants(size_t physicalIndex, size_t count, int* dest)
+	{
+		assert(physicalIndex + count <= mIntConstants.size());
+		memcpy(dest, &mIntConstants[physicalIndex], sizeof(int) * count);
+	}
+	//---------------------------------------------------------------------
+	uint16 GpuProgramParameters::deriveVariability(GpuProgramParameters::AutoConstantType act)
+	{
+		switch(act)
+		{
+		case ACT_VIEW_MATRIX:
+		case ACT_INVERSE_VIEW_MATRIX:
+		case ACT_TRANSPOSE_VIEW_MATRIX:
+		case ACT_INVERSE_TRANSPOSE_VIEW_MATRIX:
+		case ACT_PROJECTION_MATRIX:
+		case ACT_INVERSE_PROJECTION_MATRIX:
+		case ACT_TRANSPOSE_PROJECTION_MATRIX:
+		case ACT_INVERSE_TRANSPOSE_PROJECTION_MATRIX:
+		case ACT_VIEWPROJ_MATRIX:
+		case ACT_INVERSE_VIEWPROJ_MATRIX:
+		case ACT_TRANSPOSE_VIEWPROJ_MATRIX:
+		case ACT_INVERSE_TRANSPOSE_VIEWPROJ_MATRIX:
+		case ACT_RENDER_TARGET_FLIPPING:
+		case ACT_VERTEX_WINDING:
+		case ACT_AMBIENT_LIGHT_COLOUR: 
+		case ACT_DERIVED_AMBIENT_LIGHT_COLOUR:
+		case ACT_DERIVED_SCENE_COLOUR:
+		case ACT_FOG_COLOUR:
+		case ACT_FOG_PARAMS:
+		case ACT_SURFACE_AMBIENT_COLOUR:
+		case ACT_SURFACE_DIFFUSE_COLOUR:
+		case ACT_SURFACE_SPECULAR_COLOUR:
+		case ACT_SURFACE_EMISSIVE_COLOUR:
+		case ACT_SURFACE_SHININESS:
+		case ACT_CAMERA_POSITION:
+		case ACT_TIME:
+		case ACT_TIME_0_X:
+		case ACT_COSTIME_0_X:
+		case ACT_SINTIME_0_X:
+		case ACT_TANTIME_0_X:
+		case ACT_TIME_0_X_PACKED:
+		case ACT_TIME_0_1:
+		case ACT_COSTIME_0_1:
+		case ACT_SINTIME_0_1:
+		case ACT_TANTIME_0_1:
+		case ACT_TIME_0_1_PACKED:
+		case ACT_TIME_0_2PI:
+		case ACT_COSTIME_0_2PI:
+		case ACT_SINTIME_0_2PI:
+		case ACT_TANTIME_0_2PI:
+		case ACT_TIME_0_2PI_PACKED:
+		case ACT_FRAME_TIME:
+		case ACT_FPS:
+		case ACT_VIEWPORT_WIDTH:
+		case ACT_VIEWPORT_HEIGHT:
+		case ACT_INVERSE_VIEWPORT_WIDTH:
+		case ACT_INVERSE_VIEWPORT_HEIGHT:
+		case ACT_VIEWPORT_SIZE:
+		case ACT_TEXEL_OFFSETS:
+		case ACT_TEXTURE_SIZE:
+		case ACT_INVERSE_TEXTURE_SIZE:
+		case ACT_PACKED_TEXTURE_SIZE:
+		case ACT_SCENE_DEPTH_RANGE:
+		case ACT_VIEW_DIRECTION:
+		case ACT_VIEW_SIDE_VECTOR:
+		case ACT_VIEW_UP_VECTOR:
+		case ACT_FOV:
+		case ACT_NEAR_CLIP_DISTANCE:
+		case ACT_FAR_CLIP_DISTANCE:
+		case ACT_PASS_NUMBER:
+		case ACT_TEXTURE_MATRIX:
+		case ACT_LOD_CAMERA_POSITION:
+
+			return (uint16)GPV_GLOBAL;
+
+		case ACT_WORLD_MATRIX:
+		case ACT_INVERSE_WORLD_MATRIX:
+		case ACT_TRANSPOSE_WORLD_MATRIX:
+		case ACT_INVERSE_TRANSPOSE_WORLD_MATRIX:
+		case ACT_WORLD_MATRIX_ARRAY_3x4:
+		case ACT_WORLD_MATRIX_ARRAY:
+		case ACT_WORLDVIEW_MATRIX:
+		case ACT_INVERSE_WORLDVIEW_MATRIX:
+		case ACT_TRANSPOSE_WORLDVIEW_MATRIX:
+		case ACT_INVERSE_TRANSPOSE_WORLDVIEW_MATRIX:
+		case ACT_WORLDVIEWPROJ_MATRIX:
+		case ACT_INVERSE_WORLDVIEWPROJ_MATRIX:
+		case ACT_TRANSPOSE_WORLDVIEWPROJ_MATRIX:
+		case ACT_INVERSE_TRANSPOSE_WORLDVIEWPROJ_MATRIX:
+		case ACT_CAMERA_POSITION_OBJECT_SPACE:
+		case ACT_LOD_CAMERA_POSITION_OBJECT_SPACE:
+		case ACT_CUSTOM:
+		case ACT_ANIMATION_PARAMETRIC:
+
+			return (uint16)GPV_PER_OBJECT;
+
+		case ACT_LIGHT_POSITION_OBJECT_SPACE:
+		case ACT_LIGHT_DIRECTION_OBJECT_SPACE:
+		case ACT_LIGHT_DISTANCE_OBJECT_SPACE:
+		case ACT_LIGHT_POSITION_OBJECT_SPACE_ARRAY:
+		case ACT_LIGHT_DIRECTION_OBJECT_SPACE_ARRAY:
+		case ACT_LIGHT_DISTANCE_OBJECT_SPACE_ARRAY:
+		case ACT_TEXTURE_WORLDVIEWPROJ_MATRIX:
+		case ACT_TEXTURE_WORLDVIEWPROJ_MATRIX_ARRAY:
+		case ACT_SPOTLIGHT_WORLDVIEWPROJ_MATRIX:
+
+			// These depend on BOTH lights and objects
+			return ((uint16)GPV_PER_OBJECT) | ((uint16)GPV_LIGHTS);
+
+		case ACT_LIGHT_COUNT:
+		case ACT_LIGHT_DIFFUSE_COLOUR:
+		case ACT_LIGHT_SPECULAR_COLOUR:
+		case ACT_LIGHT_POSITION:
+		case ACT_LIGHT_DIRECTION:
+		case ACT_LIGHT_POSITION_VIEW_SPACE:
+		case ACT_LIGHT_DIRECTION_VIEW_SPACE:
+		case ACT_SHADOW_EXTRUSION_DISTANCE:
+		case ACT_SHADOW_SCENE_DEPTH_RANGE:
+		case ACT_SHADOW_COLOUR:
+		case ACT_LIGHT_POWER_SCALE:
+		case ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED:
+		case ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED:
+		case ACT_LIGHT_NUMBER:
+		case ACT_LIGHT_CASTS_SHADOWS:
+		case ACT_LIGHT_ATTENUATION:
+		case ACT_SPOTLIGHT_PARAMS:
+		case ACT_LIGHT_DIFFUSE_COLOUR_ARRAY:
+		case ACT_LIGHT_SPECULAR_COLOUR_ARRAY:
+		case ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED_ARRAY:
+		case ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED_ARRAY:
+		case ACT_LIGHT_POSITION_ARRAY:
+		case ACT_LIGHT_DIRECTION_ARRAY:
+		case ACT_LIGHT_POSITION_VIEW_SPACE_ARRAY:
+		case ACT_LIGHT_DIRECTION_VIEW_SPACE_ARRAY:
+		case ACT_LIGHT_POWER_SCALE_ARRAY:
+		case ACT_LIGHT_ATTENUATION_ARRAY:
+		case ACT_SPOTLIGHT_PARAMS_ARRAY:
+		case ACT_TEXTURE_VIEWPROJ_MATRIX:
+		case ACT_TEXTURE_VIEWPROJ_MATRIX_ARRAY:
+		case ACT_SPOTLIGHT_VIEWPROJ_MATRIX:
+		case ACT_SPOTLIGHT_VIEWPROJ_MATRIX_ARRAY:
+		case ACT_LIGHT_CUSTOM:
+
+			return (uint16)GPV_LIGHTS;
+
+		case ACT_DERIVED_LIGHT_DIFFUSE_COLOUR:
+		case ACT_DERIVED_LIGHT_SPECULAR_COLOUR:
+		case ACT_DERIVED_LIGHT_DIFFUSE_COLOUR_ARRAY:
+		case ACT_DERIVED_LIGHT_SPECULAR_COLOUR_ARRAY:
+
+			return ((uint16)GPV_GLOBAL | (uint16)GPV_LIGHTS);
+
+		case ACT_PASS_ITERATION_NUMBER:
+
+			return (uint16)GPV_PASS_ITERATION_NUMBER;
+
+		default:
+			return (uint16)GPV_GLOBAL;
+		};
+
+	}
+	//---------------------------------------------------------------------
+	GpuLogicalIndexUse* GpuProgramParameters::_getFloatConstantLogicalIndexUse(
+		size_t logicalIndex, size_t requestedSize, uint16 variability)
+	{
+		if (mFloatLogicalToPhysical.isNull())
+			return 0;
+
+		GpuLogicalIndexUse* indexUse = 0;
+		OGRE_LOCK_MUTEX(mFloatLogicalToPhysical->mutex)
+
+			GpuLogicalIndexUseMap::iterator logi = mFloatLogicalToPhysical->map.find(logicalIndex);
+		if (logi == mFloatLogicalToPhysical->map.end())
+		{
+			if (requestedSize)
+			{
+				size_t physicalIndex = mFloatConstants.size();
+
+				// Expand at buffer end
+				mFloatConstants.insert(mFloatConstants.end(), requestedSize, 0.0f);
+
+				// Record extended size for future GPU params re-using this information
+				mFloatLogicalToPhysical->bufferSize = mFloatConstants.size();
+
+				// low-level programs will not know about mapping ahead of time, so 
+				// populate it. Other params objects will be able to just use this
+				// accepted mapping since the constant structure will be the same
+
+				// Set up a mapping for all items in the count
+				size_t currPhys = physicalIndex;
+				size_t count = requestedSize / 4;
+				GpuLogicalIndexUseMap::iterator insertedIterator;
+
+				for (size_t logicalNum = 0; logicalNum < count; ++logicalNum)
+				{
+					GpuLogicalIndexUseMap::iterator it = 
+						mFloatLogicalToPhysical->map.insert(
+						GpuLogicalIndexUseMap::value_type(
+						logicalIndex + logicalNum, 
+						GpuLogicalIndexUse(currPhys, requestedSize, variability))).first;
+					currPhys += 4;
+
+					if (logicalNum == 0)
+						insertedIterator = it;
+				}
+
+				indexUse = &(insertedIterator->second);
+			}
+			else
+			{
+				// no match & ignore
+				return 0;
+			}
+
+		}
+		else
+		{
+			size_t physicalIndex = logi->second.physicalIndex;
+			indexUse = &(logi->second);
+			// check size
+			if (logi->second.currentSize < requestedSize)
+			{
+				// init buffer entry wasn't big enough; could be a mistake on the part
+				// of the original use, or perhaps a variable length we can't predict
+				// until first actual runtime use e.g. world matrix array
+				size_t insertCount = requestedSize - logi->second.currentSize;
+				FloatConstantList::iterator insertPos = mFloatConstants.begin();
+				std::advance(insertPos, physicalIndex);
+				mFloatConstants.insert(insertPos, insertCount, 0.0f);
+				// shift all physical positions after this one
+				for (GpuLogicalIndexUseMap::iterator i = mFloatLogicalToPhysical->map.begin();
+					i != mFloatLogicalToPhysical->map.end(); ++i)
+				{
+					if (i->second.physicalIndex > physicalIndex)
+						i->second.physicalIndex += insertCount;
+				}
+				mFloatLogicalToPhysical->bufferSize += insertCount;
+				for (AutoConstantList::iterator i = mAutoConstants.begin();
+					i != mAutoConstants.end(); ++i)
+				{
+					if (i->physicalIndex > physicalIndex &&
+						getAutoConstantDefinition(i->paramType)->elementType == ET_REAL)
+					{
+						i->physicalIndex += insertCount;
+					}
+				}
+				if (!mNamedConstants.isNull())
+				{
+					for (GpuConstantDefinitionMap::iterator i = mNamedConstants->map.begin();
+						i != mNamedConstants->map.end(); ++i)
+					{
+						if (i->second.isFloat() && i->second.physicalIndex > physicalIndex)
+							i->second.physicalIndex += insertCount;
+					}
+					mNamedConstants->floatBufferSize += insertCount;
+				}
+
+				logi->second.currentSize += insertCount;
+			}
+		}
+
+		if (indexUse)
+			indexUse->variability = variability;
+
+		return indexUse;
+
+	}
+	//---------------------------------------------------------------------()
+	GpuLogicalIndexUse* GpuProgramParameters::_getIntConstantLogicalIndexUse(size_t logicalIndex, size_t requestedSize, uint16 variability)
+	{
+		if (mIntLogicalToPhysical.isNull())
+			OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
+			"This is not a low-level parameter parameter object",
+			"GpuProgramParameters::_getIntConstantPhysicalIndex");
+
+		GpuLogicalIndexUse* indexUse = 0;
+		OGRE_LOCK_MUTEX(mIntLogicalToPhysical->mutex)
+
+			GpuLogicalIndexUseMap::iterator logi = mIntLogicalToPhysical->map.find(logicalIndex);
+		if (logi == mIntLogicalToPhysical->map.end())
+		{
+			if (requestedSize)
+			{
+				size_t physicalIndex = mIntConstants.size();
+
+				// Expand at buffer end
+				mIntConstants.insert(mIntConstants.end(), requestedSize, 0);
+
+				// Record extended size for future GPU params re-using this information
+				mIntLogicalToPhysical->bufferSize = mIntConstants.size();
+
+				// low-level programs will not know about mapping ahead of time, so 
+				// populate it. Other params objects will be able to just use this
+				// accepted mapping since the constant structure will be the same
+
+				// Set up a mapping for all items in the count
+				size_t currPhys = physicalIndex;
+				size_t count = requestedSize / 4;
+				GpuLogicalIndexUseMap::iterator insertedIterator;
+				for (size_t logicalNum = 0; logicalNum < count; ++logicalNum)
+				{
+					GpuLogicalIndexUseMap::iterator it = 
+						mIntLogicalToPhysical->map.insert(
+						GpuLogicalIndexUseMap::value_type(
+						logicalIndex + logicalNum, 
+						GpuLogicalIndexUse(currPhys, requestedSize, variability))).first;
+					if (logicalNum == 0)
+						insertedIterator = it;
+					currPhys += 4;
+				}
+				indexUse = &(insertedIterator->second);
+
+			}
+			else
+			{
+				// no match
+				return 0;
+			}
+
+		}
+		else
+		{
+			size_t physicalIndex = logi->second.physicalIndex;
+			indexUse = &(logi->second);
+
+			// check size
+			if (logi->second.currentSize < requestedSize)
+			{
+				// init buffer entry wasn't big enough; could be a mistake on the part
+				// of the original use, or perhaps a variable length we can't predict
+				// until first actual runtime use e.g. world matrix array
+				size_t insertCount = requestedSize - logi->second.currentSize;
+				IntConstantList::iterator insertPos = mIntConstants.begin();
+				std::advance(insertPos, physicalIndex);
+				mIntConstants.insert(insertPos, insertCount, 0);
+				// shift all physical positions after this one
+				for (GpuLogicalIndexUseMap::iterator i = mIntLogicalToPhysical->map.begin();
+					i != mIntLogicalToPhysical->map.end(); ++i)
+				{
+					if (i->second.physicalIndex > physicalIndex)
+						i->second.physicalIndex += insertCount;
+				}
+				mIntLogicalToPhysical->bufferSize += insertCount;
+				for (AutoConstantList::iterator i = mAutoConstants.begin();
+					i != mAutoConstants.end(); ++i)
+				{
+					if (i->physicalIndex > physicalIndex &&
+						getAutoConstantDefinition(i->paramType)->elementType == ET_INT)
+					{
+						i->physicalIndex += insertCount;
+					}
+				}
+				if (!mNamedConstants.isNull())
+				{
+					for (GpuConstantDefinitionMap::iterator i = mNamedConstants->map.begin();
+						i != mNamedConstants->map.end(); ++i)
+					{
+						if (!i->second.isFloat() && i->second.physicalIndex > physicalIndex)
+							i->second.physicalIndex += insertCount;
+					}
+					mNamedConstants->intBufferSize += insertCount;
+				}
+
+				logi->second.currentSize += insertCount;
+			}
+		}
+
+		if (indexUse)
+			indexUse->variability = variability;
+
+		return indexUse;
+
+	}
+	//-----------------------------------------------------------------------------
+	size_t GpuProgramParameters::_getFloatConstantPhysicalIndex(
+		size_t logicalIndex, size_t requestedSize, uint16 variability) 
+	{
+		GpuLogicalIndexUse* indexUse = _getFloatConstantLogicalIndexUse(logicalIndex, requestedSize, variability);
+		return indexUse ? indexUse->physicalIndex : 0;
+	}
+	//-----------------------------------------------------------------------------
+	size_t GpuProgramParameters::_getIntConstantPhysicalIndex(
+		size_t logicalIndex, size_t requestedSize, uint16 variability)
+	{
+		GpuLogicalIndexUse* indexUse = _getIntConstantLogicalIndexUse(logicalIndex, requestedSize, variability);
+		return indexUse ? indexUse->physicalIndex : 0;
+	}
+	//-----------------------------------------------------------------------------
+	size_t GpuProgramParameters::getFloatLogicalIndexForPhysicalIndex(size_t physicalIndex)
+	{
+		// perhaps build a reverse map of this sometime (shared in GpuProgram)
+		for (GpuLogicalIndexUseMap::iterator i = mFloatLogicalToPhysical->map.begin();
+			i != mFloatLogicalToPhysical->map.end(); ++i)
+		{
+			if (i->second.physicalIndex == physicalIndex)
+				return i->first;
+		}
+		return std::numeric_limits<size_t>::max();
+
+	}
+	//-----------------------------------------------------------------------------
+	size_t GpuProgramParameters::getIntLogicalIndexForPhysicalIndex(size_t physicalIndex)
+	{
+		// perhaps build a reverse map of this sometime (shared in GpuProgram)
+		for (GpuLogicalIndexUseMap::iterator i = mIntLogicalToPhysical->map.begin();
+			i != mIntLogicalToPhysical->map.end(); ++i)
+		{
+			if (i->second.physicalIndex == physicalIndex)
+				return i->first;
+		}
+		return std::numeric_limits<size_t>::max();
+
+	}
+	//-----------------------------------------------------------------------------
+	GpuConstantDefinitionIterator GpuProgramParameters::getConstantDefinitionIterator(void) const
+	{
+		if (mNamedConstants.isNull())
+			OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
+			"This params object is not based on a program with named parameters.",
+			"GpuProgramParameters::getConstantDefinitionIterator");
+
+		return mNamedConstants->map.begin();
+
+	}
+	//-----------------------------------------------------------------------------
+	const GpuNamedConstants& GpuProgramParameters::getConstantDefinitions() const
+	{
+		if (mNamedConstants.isNull())
+			OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
+			"This params object is not based on a program with named parameters.",
+			"GpuProgramParameters::getConstantDefinitionIterator");
+
+		return *mNamedConstants;
+	}
+	//-----------------------------------------------------------------------------
+	const GpuConstantDefinition& GpuProgramParameters::getConstantDefinition(const String& name) const
+	{
+		if (mNamedConstants.isNull())
+			OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
+			"This params object is not based on a program with named parameters.",
+			"GpuProgramParameters::getConstantDefinitionIterator");
+
+
+		// locate, and throw exception if not found
+		const GpuConstantDefinition* def = _findNamedConstantDefinition(name, true);
+
+		return *def;
+
+	}
+	//-----------------------------------------------------------------------------
+	const GpuConstantDefinition* 
+		GpuProgramParameters::_findNamedConstantDefinition(const String& name, 
+		bool throwExceptionIfNotFound) const
+	{
+		if (mNamedConstants.isNull())
+		{
+			if (throwExceptionIfNotFound)
+				OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
+				"Named constants have not been initialised, perhaps a compile error.",
+				"GpuProgramParameters::_findNamedConstantDefinition");
+			return 0;
+		}
+
+		GpuConstantDefinitionMap::const_iterator i = mNamedConstants->map.find(name);
+		if (i == mNamedConstants->map.end())
+		{
+			if (throwExceptionIfNotFound)
+				OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
+				"Parameter called " + name + " does not exist. ",
+				"GpuProgramParameters::_findNamedConstantDefinition");
+			return 0;
+		}
+		else
+		{
+			return &(i->second);
+		}
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::setAutoConstant(size_t index, AutoConstantType acType, size_t extraInfo)
+	{
+		// Get auto constant definition for sizing
+		const AutoConstantDefinition* autoDef = getAutoConstantDefinition(acType);
+		// round up to nearest multiple of 4
+		size_t sz = autoDef->elementCount;
+		if (sz % 4 > 0)
+		{
+			sz += 4 - (sz % 4);
+		}
+
+		GpuLogicalIndexUse* indexUse = _getFloatConstantLogicalIndexUse(index, sz, deriveVariability(acType));
+
+		_setRawAutoConstant(indexUse->physicalIndex, acType, extraInfo, indexUse->variability, sz);
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::_setRawAutoConstant(size_t physicalIndex, 
+		AutoConstantType acType, size_t extraInfo, uint16 variability, size_t elementSize)
+	{
+		// update existing index if it exists
+		bool found = false;
+		for (AutoConstantList::iterator i = mAutoConstants.begin(); 
+			i != mAutoConstants.end(); ++i)
+		{
+			if (i->physicalIndex == physicalIndex)
+			{
+				i->paramType = acType;
+				i->data = extraInfo;
+				i->elementCount = elementSize;
+				i->variability = variability;
+				found = true;
+				break;
+			}
+		}
+		if (!found)
+			mAutoConstants.push_back(AutoConstantEntry(acType, physicalIndex, extraInfo, variability, elementSize));
+
+		mCombinedVariability |= variability;
+
+
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::setAutoConstant(size_t index, AutoConstantType acType, uint16 extraInfo1, uint16 extraInfo2)
+	{
+		size_t extraInfo = (size_t)extraInfo1 | ((size_t)extraInfo2) << 16;
+
+		// Get auto constant definition for sizing
+		const AutoConstantDefinition* autoDef = getAutoConstantDefinition(acType);
+		// round up to nearest multiple of 4
+		size_t sz = autoDef->elementCount;
+		if (sz % 4 > 0)
+		{
+			sz += 4 - (sz % 4);
+		}
+
+		GpuLogicalIndexUse* indexUse = _getFloatConstantLogicalIndexUse(index, sz, deriveVariability(acType));
+
+		_setRawAutoConstant(indexUse->physicalIndex, acType, extraInfo, indexUse->variability, sz);
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::_setRawAutoConstantReal(size_t physicalIndex, 
+		AutoConstantType acType, Real rData, uint16 variability, size_t elementSize)
+	{
+		// update existing index if it exists
+		bool found = false;
+		for (AutoConstantList::iterator i = mAutoConstants.begin(); 
+			i != mAutoConstants.end(); ++i)
+		{
+			if (i->physicalIndex == physicalIndex)
+			{
+				i->paramType = acType;
+				i->fData = rData;
+				i->elementCount = elementSize;
+				i->variability = variability;
+				found = true;
+				break;
+			}
+		}
+		if (!found)
+			mAutoConstants.push_back(AutoConstantEntry(acType, physicalIndex, rData, variability, elementSize));
+
+		mCombinedVariability |= variability;
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::clearAutoConstant(size_t index)
+	{
+		GpuLogicalIndexUse* indexUse = _getFloatConstantLogicalIndexUse(index, 0, GPV_GLOBAL);
+
+		if (indexUse)
+		{
+			indexUse->variability = GPV_GLOBAL;
+			size_t physicalIndex = indexUse->physicalIndex;
+			// update existing index if it exists
+			for (AutoConstantList::iterator i = mAutoConstants.begin(); 
+				i != mAutoConstants.end(); ++i)
+			{
+				if (i->physicalIndex == physicalIndex)
+				{
+					mAutoConstants.erase(i);
+					break;
+				}
+			}
+		}
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::clearNamedAutoConstant(const String& name)
+	{
+		const GpuConstantDefinition* def = _findNamedConstantDefinition(name);
+		if (def)
+		{
+			def->variability = GPV_GLOBAL;
+
+			// Autos are always floating point
+			if (def->isFloat())
+			{
+				for (AutoConstantList::iterator i = mAutoConstants.begin(); 
+					i != mAutoConstants.end(); ++i)
+				{
+					if (i->physicalIndex == def->physicalIndex)
+					{
+						mAutoConstants.erase(i);
+						break;
+					}
+				}
+			}
+
+		}
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::clearAutoConstants(void)
+	{
+		mAutoConstants.clear();
+		mCombinedVariability = GPV_GLOBAL;
+	}
+	//-----------------------------------------------------------------------------
+	GpuProgramParameters::AutoConstantIterator GpuProgramParameters::getAutoConstantIterator(void) const
+	{
+		return mAutoConstants.begin();
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::setAutoConstantReal(size_t index, AutoConstantType acType, Real rData)
+	{
+		// Get auto constant definition for sizing
+		const AutoConstantDefinition* autoDef = getAutoConstantDefinition(acType);
+		// round up to nearest multiple of 4
+		size_t sz = autoDef->elementCount;
+		if (sz % 4 > 0)
+		{
+			sz += 4 - (sz % 4);
+		}
+
+		GpuLogicalIndexUse* indexUse = _getFloatConstantLogicalIndexUse(index, sz, deriveVariability(acType));
+
+		_setRawAutoConstantReal(indexUse->physicalIndex, acType, rData, indexUse->variability, sz);
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::setNamedConstant(const String& name, Real val)
+	{
+		// look up, and throw an exception if we're not ignoring missing
+		const GpuConstantDefinition* def = 
+			_findNamedConstantDefinition(name, !mIgnoreMissingParams);
+		if (def)
+			_writeRawConstant(def->physicalIndex, val);
+	}
+	//---------------------------------------------------------------------------
+	void GpuProgramParameters::setNamedConstant(const String& name, int val)
+	{
+		// look up, and throw an exception if we're not ignoring missing
+		const GpuConstantDefinition* def = 
+			_findNamedConstantDefinition(name, !mIgnoreMissingParams);
+		if (def)
+			_writeRawConstant(def->physicalIndex, val);
+	}
+	//---------------------------------------------------------------------------
+	void GpuProgramParameters::setNamedConstant(const String& name, const Vector4& vec)
+	{
+		// look up, and throw an exception if we're not ignoring missing
+		const GpuConstantDefinition* def = 
+			_findNamedConstantDefinition(name, !mIgnoreMissingParams);
+		if (def)
+			_writeRawConstant(def->physicalIndex, vec, def->elementSize);
+	}
+	//---------------------------------------------------------------------------
+	void GpuProgramParameters::setNamedConstant(const String& name, const Vector3& vec)
+	{
+		// look up, and throw an exception if we're not ignoring missing
+		const GpuConstantDefinition* def = 
+			_findNamedConstantDefinition(name, !mIgnoreMissingParams);
+		if (def)
+			_writeRawConstant(def->physicalIndex, vec);
+	}
+	//---------------------------------------------------------------------------
+	void GpuProgramParameters::setNamedConstant(const String& name, const Matrix4& m)
+	{
+		// look up, and throw an exception if we're not ignoring missing
+		const GpuConstantDefinition* def = 
+			_findNamedConstantDefinition(name, !mIgnoreMissingParams);
+		if (def)
+			_writeRawConstant(def->physicalIndex, m, def->elementSize);
+	}
+	//---------------------------------------------------------------------------
+	void GpuProgramParameters::setNamedConstant(const String& name, const Matrix4* m, 
+		size_t numEntries)
+	{
+		// look up, and throw an exception if we're not ignoring missing
+		const GpuConstantDefinition* def = 
+			_findNamedConstantDefinition(name, !mIgnoreMissingParams);
+		if (def)
+			_writeRawConstant(def->physicalIndex, m, numEntries);
+	}
+	//---------------------------------------------------------------------------
+	void GpuProgramParameters::setNamedConstant(const String& name, 
+		const float *val, size_t count, size_t multiple)
+	{
+		size_t rawCount = count * multiple;
+		// look up, and throw an exception if we're not ignoring missing
+		const GpuConstantDefinition* def = 
+			_findNamedConstantDefinition(name, !mIgnoreMissingParams);
+		if (def)
+			_writeRawConstants(def->physicalIndex, val, rawCount);
+	}
+	//---------------------------------------------------------------------------
+	void GpuProgramParameters::setNamedConstant(const String& name, 
+		const double *val, size_t count, size_t multiple)
+	{
+		size_t rawCount = count * multiple;
+		// look up, and throw an exception if we're not ignoring missing
+		const GpuConstantDefinition* def = 
+			_findNamedConstantDefinition(name, !mIgnoreMissingParams);
+		if (def)
+			_writeRawConstants(def->physicalIndex, val, rawCount);
+	}
+	//---------------------------------------------------------------------------
+	void GpuProgramParameters::setNamedConstant(const String& name, const ColourValue& colour)
+	{
+		// look up, and throw an exception if we're not ignoring missing
+		const GpuConstantDefinition* def = 
+			_findNamedConstantDefinition(name, !mIgnoreMissingParams);
+		if (def)
+			_writeRawConstant(def->physicalIndex, colour, def->elementSize);
+	}
+	//---------------------------------------------------------------------------
+	void GpuProgramParameters::setNamedConstant(const String& name, 
+		const int *val, size_t count, size_t multiple)
+	{
+		size_t rawCount = count * multiple;
+		// look up, and throw an exception if we're not ignoring missing
+		const GpuConstantDefinition* def = 
+			_findNamedConstantDefinition(name, !mIgnoreMissingParams);
+		if (def)
+			_writeRawConstants(def->physicalIndex, val, rawCount);
+	}
+	//---------------------------------------------------------------------------
+	void GpuProgramParameters::setNamedAutoConstant(const String& name, 
+		AutoConstantType acType, size_t extraInfo)
+	{
+		// look up, and throw an exception if we're not ignoring missing
+		const GpuConstantDefinition* def = 
+			_findNamedConstantDefinition(name, !mIgnoreMissingParams);
+		if (def)
+		{
+			def->variability = deriveVariability(acType);
+			// make sure we also set variability on the logical index map
+			GpuLogicalIndexUse* indexUse = _getFloatConstantLogicalIndexUse(def->logicalIndex, def->elementSize * def->arraySize, def->variability);
+			if (indexUse)
+				indexUse->variability = def->variability;
+
+			_setRawAutoConstant(def->physicalIndex, acType, extraInfo, def->variability, def->elementSize);
+		}
+
+	}
+	//---------------------------------------------------------------------------
+	void GpuProgramParameters::setNamedAutoConstantReal(const String& name, 
+		AutoConstantType acType, Real rData)
+	{
+		// look up, and throw an exception if we're not ignoring missing
+		const GpuConstantDefinition* def = 
+			_findNamedConstantDefinition(name, !mIgnoreMissingParams);
+		if (def)
+		{
+			def->variability = deriveVariability(acType);
+			// make sure we also set variability on the logical index map
+			GpuLogicalIndexUse* indexUse = _getFloatConstantLogicalIndexUse(def->logicalIndex, def->elementSize * def->arraySize, def->variability);
+			if (indexUse)
+				indexUse->variability = def->variability;
+			_setRawAutoConstantReal(def->physicalIndex, acType, rData, def->variability, def->elementSize);
+		}
+	}
+	//---------------------------------------------------------------------------
+	void GpuProgramParameters::setNamedAutoConstant(const String& name, 
+		AutoConstantType acType, uint16 extraInfo1, uint16 extraInfo2)
+	{
+		size_t extraInfo = (size_t)extraInfo1 | ((size_t)extraInfo2) << 16;
+
+		// look up, and throw an exception if we're not ignoring missing
+		const GpuConstantDefinition* def = 
+			_findNamedConstantDefinition(name, !mIgnoreMissingParams);
+		if (def)
+		{
+			def->variability = deriveVariability(acType);
+			// make sure we also set variability on the logical index map
+			GpuLogicalIndexUse* indexUse = _getFloatConstantLogicalIndexUse(def->logicalIndex, def->elementSize * def->arraySize, def->variability);
+			if (indexUse)
+				indexUse->variability = def->variability;
+
+			_setRawAutoConstant(def->physicalIndex, acType, extraInfo, def->variability, def->elementSize);
+		}
+
+	}
+	//---------------------------------------------------------------------------
+	void GpuProgramParameters::setConstantFromTime(size_t index, Real factor)
+	{
+		setAutoConstantReal(index, ACT_TIME, factor);
+	}
+	//---------------------------------------------------------------------------
+	void GpuProgramParameters::setNamedConstantFromTime(const String& name, Real factor)
+	{
+		setNamedAutoConstantReal(name, ACT_TIME, factor);
+	}
+	//---------------------------------------------------------------------------
+	GpuProgramParameters::AutoConstantEntry* GpuProgramParameters::getAutoConstantEntry(const size_t index)
+	{
+		if (index < mAutoConstants.size())
+		{
+			return &(mAutoConstants[index]);
+		}
+		else
+		{
+			return NULL;
+		}
+	}
+	//---------------------------------------------------------------------------
+	const GpuProgramParameters::AutoConstantEntry* 
+		GpuProgramParameters::findFloatAutoConstantEntry(size_t logicalIndex)
+	{
+		if (mFloatLogicalToPhysical.isNull())
+			OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
+			"This is not a low-level parameter parameter object",
+			"GpuProgramParameters::findFloatAutoConstantEntry");
+
+		return _findRawAutoConstantEntryFloat(
+			_getFloatConstantPhysicalIndex(logicalIndex, 0, GPV_GLOBAL));
+
+	}
+	//---------------------------------------------------------------------------
+	const GpuProgramParameters::AutoConstantEntry* 
+		GpuProgramParameters::findIntAutoConstantEntry(size_t logicalIndex)
+	{
+		if (mIntLogicalToPhysical.isNull())
+			OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
+			"This is not a low-level parameter parameter object",
+			"GpuProgramParameters::findIntAutoConstantEntry");
+
+		return _findRawAutoConstantEntryInt(
+			_getIntConstantPhysicalIndex(logicalIndex, 0, GPV_GLOBAL));
+
+
+	}
+	//---------------------------------------------------------------------------
+	const GpuProgramParameters::AutoConstantEntry* 
+		GpuProgramParameters::findAutoConstantEntry(const String& paramName)
+	{
+		if (mNamedConstants.isNull())
+			OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
+			"This params object is not based on a program with named parameters.",
+			"GpuProgramParameters::findAutoConstantEntry");
+
+		const GpuConstantDefinition& def = getConstantDefinition(paramName);
+		if (def.isFloat())
+		{
+			return _findRawAutoConstantEntryFloat(def.physicalIndex);
+		}
+		else
+		{
+			return _findRawAutoConstantEntryInt(def.physicalIndex);
+		}
+	}
+	//---------------------------------------------------------------------------
+	const GpuProgramParameters::AutoConstantEntry* 
+		GpuProgramParameters::_findRawAutoConstantEntryFloat(size_t physicalIndex)
+	{
+		for(AutoConstantList::iterator i = mAutoConstants.begin();
+			i != mAutoConstants.end(); ++i)
+		{
+			AutoConstantEntry& ac = *i;
+			// should check that auto is float and not int so that physicalIndex
+			// doesn't have any ambiguity
+			// However, all autos are float I think so no need
+			if (ac.physicalIndex == physicalIndex)
+				return &ac;
+		}
+
+		return 0;
+
+	}
+	//---------------------------------------------------------------------------
+	const GpuProgramParameters::AutoConstantEntry* 
+		GpuProgramParameters::_findRawAutoConstantEntryInt(size_t physicalIndex)
+	{
+		// No autos are float?
+		return 0;
+	}
+	//---------------------------------------------------------------------------
+	void GpuProgramParameters::copyConstantsFrom(const GpuProgramParameters& source)
+	{
+		// Pull buffers & auto constant list over directly
+		mFloatConstants = source.getFloatConstantList();
+		mIntConstants = source.getIntConstantList();
+		mAutoConstants = source.getAutoConstantList();
+		mCombinedVariability = source.mCombinedVariability;
+		copySharedParamSetUsage(source.mSharedParamSets);
+	}
+	//---------------------------------------------------------------------
+	void GpuProgramParameters::copyMatchingNamedConstantsFrom(const GpuProgramParameters& source)
+	{
+		if (!mNamedConstants.isNull() && !source.mNamedConstants.isNull())
+		{
+			std::map<size_t, String> srcToDestNamedMap;
+			for (GpuConstantDefinitionMap::const_iterator i = source.mNamedConstants->map.begin(); 
+				i != source.mNamedConstants->map.end(); ++i)
+			{
+				const String& paramName = i->first;
+				const GpuConstantDefinition& olddef = i->second;
+				const GpuConstantDefinition* newdef = _findNamedConstantDefinition(paramName, false);
+				if (newdef)
+				{
+					// Copy data across, based on smallest common definition size
+					size_t srcsz = olddef.elementSize * olddef.arraySize;
+					size_t destsz = newdef->elementSize * newdef->arraySize;
+					size_t sz = std::min(srcsz, destsz);
+					if (newdef->isFloat())
+					{
+
+						memcpy(getFloatPointer(newdef->physicalIndex), 
+							source.getFloatPointer(olddef.physicalIndex),
+							sz * sizeof(float));
+					}
+					else
+					{
+						memcpy(getIntPointer(newdef->physicalIndex), 
+							source.getIntPointer(olddef.physicalIndex),
+							sz * sizeof(int));
+					}
+					// we'll use this map to resolve autos later
+					// ignore the [0] aliases
+					if (!StringUtil::endsWith(paramName, "[0]"))
+						srcToDestNamedMap[olddef.physicalIndex] = paramName;
+				}
+			}
+
+			for (AutoConstantList::const_iterator i = source.mAutoConstants.begin(); 
+				i != source.mAutoConstants.end(); ++i)
+			{
+				const GpuProgramParameters::AutoConstantEntry& autoEntry = *i;
+				// find dest physical index
+				std::map<size_t, String>::iterator mi = srcToDestNamedMap.find(autoEntry.physicalIndex);
+				if (mi != srcToDestNamedMap.end())
+				{
+					if (autoEntry.fData)
+					{
+						setNamedAutoConstantReal(mi->second, autoEntry.paramType, autoEntry.fData);
+					}
+					else
+					{
+						setNamedAutoConstant(mi->second, autoEntry.paramType, autoEntry.data);
+					}
+				}
+
+			}
+
+			// Copy shared param sets
+			for (GpuSharedParamUsageList::const_iterator i = source.mSharedParamSets.begin();
+				i != source.mSharedParamSets.end(); ++i)
+			{
+				const GpuSharedParametersUsage& usage = *i;
+				if (!isUsingSharedParameters(usage.getName()))
+				{
+					addSharedParameters(usage.getSharedParams());
+				}
+			}
+		}
+	}
+	//-----------------------------------------------------------------------
+	const GpuProgramParameters::AutoConstantDefinition* 
+		GpuProgramParameters::getAutoConstantDefinition(const String& name)
+	{
+		// find a constant definition that matches name by iterating through the 
+		// constant definition array
+		bool nameFound = false;
+		size_t i = 0;
+		const size_t numDefs = getNumAutoConstantDefinitions();
+		while (!nameFound && (i < numDefs))
+		{
+			if (name == AutoConstantDictionary[i].name) 
+				nameFound = true;
+			else
+				++i;
+		}
+
+		if (nameFound)
+			return &AutoConstantDictionary[i];
+		else
+			return 0;
+	}
+
+	//-----------------------------------------------------------------------
+	const GpuProgramParameters::AutoConstantDefinition* 
+		GpuProgramParameters::getAutoConstantDefinition(const size_t idx) 
+	{
+
+		if (idx < getNumAutoConstantDefinitions())
+		{
+			// verify index is equal to acType
+			// if they are not equal then the dictionary was not setup properly
+			assert(idx == static_cast<size_t>(AutoConstantDictionary[idx].acType));
+			return &AutoConstantDictionary[idx];
+		}
+		else
+			return 0;
+	}
+	//-----------------------------------------------------------------------
+	size_t GpuProgramParameters::getNumAutoConstantDefinitions(void)
+	{
+		return sizeof(AutoConstantDictionary)/sizeof(AutoConstantDefinition);
+	}
+
+	//-----------------------------------------------------------------------
+	void GpuProgramParameters::incPassIterationNumber(void)
+	{
+		if (mActivePassIterationIndex != std::numeric_limits<size_t>::max())
+		{
+			// This is a physical index
+			++mFloatConstants[mActivePassIterationIndex];
+		}
+	}
+	//---------------------------------------------------------------------
+	void GpuProgramParameters::addSharedParameters(GpuSharedParametersPtr sharedParams)
+	{
+		if (!isUsingSharedParameters(sharedParams->getName()))
+		{
+			mSharedParamSets.push_back(GpuSharedParametersUsage(sharedParams, this));
+		}
+	}
+	//---------------------------------------------------------------------
+	void GpuProgramParameters::addSharedParameters(const String& sharedParamsName)
+	{
+		// TODO PORT - I don't think I'll be needing this. I dont plan on including GpuProgramManager in the port
+		//addSharedParameters(GpuProgramManager::getSingleton().getSharedParameters(sharedParamsName));
+	}
+	//---------------------------------------------------------------------
+	bool GpuProgramParameters::isUsingSharedParameters(const String& sharedParamsName) const
+	{
+		for (GpuSharedParamUsageList::const_iterator i = mSharedParamSets.begin();
+			i != mSharedParamSets.end(); ++i)
+		{
+			if (i->getName() == sharedParamsName)
+				return true;
+		}
+		return false;
+	}
+	//---------------------------------------------------------------------
+	void GpuProgramParameters::removeSharedParameters(const String& sharedParamsName)
+	{
+		for (GpuSharedParamUsageList::iterator i = mSharedParamSets.begin();
+			i != mSharedParamSets.end(); ++i)
+		{
+			if (i->getName() == sharedParamsName)
+			{
+				mSharedParamSets.erase(i);
+				break;
+			}
+		}
+	}
+	//---------------------------------------------------------------------
+	void GpuProgramParameters::removeAllSharedParameters()
+	{
+		mSharedParamSets.clear();
+	}
+	//---------------------------------------------------------------------
+	const GpuProgramParameters::GpuSharedParamUsageList& 
+	GpuProgramParameters::getSharedParameters() const
+	{
+		return mSharedParamSets;
+	}
+	//---------------------------------------------------------------------
+	void GpuProgramParameters::_copySharedParams()
+	{
+		for (GpuSharedParamUsageList::iterator i = mSharedParamSets.begin(); 
+			i != mSharedParamSets.end(); ++i )
+		{
+			i->_copySharedParamsToTargetParams();
+		}
+
+	}
+
+
+
+
+
+}
+

+ 1806 - 0
CamelotRenderer/OgreGpuProgramParams.h

@@ -0,0 +1,1806 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+(Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org
+
+Copyright (c) 2000-2011 Torus Knot Software Ltd
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+-----------------------------------------------------------------------------
+*/
+#ifndef __GpuProgramParams_H_
+#define __GpuProgramParams_H_
+
+// Precompiler options
+#include "OgrePrerequisites.h"
+#include "OgreSharedPtr.h"
+#include "OgreRenderOperation.h"
+
+namespace Ogre {
+
+	/** \addtogroup Core
+	*  @{
+	*/
+	/** \addtogroup Materials
+	*  @{
+	*/
+	/** Enumeration of the types of constant we may encounter in programs. 
+	@note Low-level programs, by definition, will always use either
+	float4 or int4 constant types since that is the fundamental underlying
+	type in assembler.
+	*/
+	enum GpuConstantType
+	{
+		GCT_FLOAT1 = 1,
+		GCT_FLOAT2 = 2,
+		GCT_FLOAT3 = 3,
+		GCT_FLOAT4 = 4,
+		GCT_SAMPLER1D = 5,
+		GCT_SAMPLER2D = 6,
+		GCT_SAMPLER3D = 7,
+		GCT_SAMPLERCUBE = 8,
+		GCT_SAMPLER1DSHADOW = 9,
+		GCT_SAMPLER2DSHADOW = 10,
+		GCT_MATRIX_2X2 = 11,
+		GCT_MATRIX_2X3 = 12,
+		GCT_MATRIX_2X4 = 13,
+		GCT_MATRIX_3X2 = 14,
+		GCT_MATRIX_3X3 = 15,
+		GCT_MATRIX_3X4 = 16,
+		GCT_MATRIX_4X2 = 17,
+		GCT_MATRIX_4X3 = 18,
+		GCT_MATRIX_4X4 = 19,
+		GCT_INT1 = 20,
+		GCT_INT2 = 21,
+		GCT_INT3 = 22,
+		GCT_INT4 = 23,
+		GCT_UNKNOWN = 99
+	};
+
+	/** The variability of a GPU parameter, as derived from auto-params targetting it.
+	These values must be powers of two since they are used in masks.
+	*/
+	enum GpuParamVariability
+	{
+		/// No variation except by manual setting - the default
+		GPV_GLOBAL = 1, 
+		/// Varies per object (based on an auto param usually), but not per light setup
+		GPV_PER_OBJECT = 2, 
+		/// Varies with light setup
+		GPV_LIGHTS = 4, 
+		/// Varies with pass iteration number
+		GPV_PASS_ITERATION_NUMBER = 8,
+
+
+		/// Full mask (16-bit)
+		GPV_ALL = 0xFFFF
+
+	};
+
+	/** Information about predefined program constants. 
+	@note Only available for high-level programs but is referenced generically
+	by GpuProgramParameters.
+	*/
+	struct _OgreExport GpuConstantDefinition
+	{
+		/// Data type
+		GpuConstantType constType;
+		/// Physical start index in buffer (either float or int buffer)
+		size_t physicalIndex;
+		/// Logical index - used to communicate this constant to the rendersystem
+		size_t logicalIndex;
+		/** Number of raw buffer slots per element 
+		(some programs pack each array element to float4, some do not) */
+		size_t elementSize;
+		/// Length of array
+		size_t arraySize;
+		/// How this parameter varies (bitwise combination of GpuProgramVariability)
+		mutable uint16 variability;
+
+		bool isFloat() const
+		{
+			return isFloat(constType);
+		}
+
+		static bool isFloat(GpuConstantType c)
+		{
+			switch(c)
+			{
+			case GCT_INT1:
+			case GCT_INT2:
+			case GCT_INT3:
+			case GCT_INT4:
+			case GCT_SAMPLER1D:
+			case GCT_SAMPLER2D:
+			case GCT_SAMPLER3D:
+			case GCT_SAMPLERCUBE:
+			case GCT_SAMPLER1DSHADOW:
+			case GCT_SAMPLER2DSHADOW:
+				return false;
+			default:
+				return true;
+			};
+
+		}
+
+		bool isSampler() const
+		{
+			return isSampler(constType);
+		}
+
+		static bool isSampler(GpuConstantType c)
+		{
+			switch(c)
+			{
+			case GCT_SAMPLER1D:
+			case GCT_SAMPLER2D:
+			case GCT_SAMPLER3D:
+			case GCT_SAMPLERCUBE:
+			case GCT_SAMPLER1DSHADOW:
+			case GCT_SAMPLER2DSHADOW:
+				return true;
+			default:
+				return false;
+			};
+
+		}
+
+
+		/** Get the element size of a given type, including whether to pad the 
+			elements into multiples of 4 (e.g. SM1 and D3D does, GLSL doesn't)
+		*/
+		static size_t getElementSize(GpuConstantType ctype, bool padToMultiplesOf4)
+		{
+			if (padToMultiplesOf4)
+			{
+				switch(ctype)
+				{
+				case GCT_FLOAT1:
+				case GCT_INT1:
+				case GCT_SAMPLER1D:
+				case GCT_SAMPLER2D:
+				case GCT_SAMPLER3D:
+				case GCT_SAMPLERCUBE:
+				case GCT_SAMPLER1DSHADOW:
+				case GCT_SAMPLER2DSHADOW:
+				case GCT_FLOAT2:
+				case GCT_INT2:
+				case GCT_FLOAT3:
+				case GCT_INT3:
+				case GCT_FLOAT4:
+				case GCT_INT4:
+					return 4;
+				case GCT_MATRIX_2X2:
+				case GCT_MATRIX_2X3:
+				case GCT_MATRIX_2X4:
+					return 8; // 2 float4s
+				case GCT_MATRIX_3X2:
+				case GCT_MATRIX_3X3:
+				case GCT_MATRIX_3X4:
+					return 12; // 3 float4s
+				case GCT_MATRIX_4X2:
+				case GCT_MATRIX_4X3:
+				case GCT_MATRIX_4X4:
+					return 16; // 4 float4s
+				default:
+					return 4;
+				};
+			}
+			else
+			{
+				switch(ctype)
+				{
+				case GCT_FLOAT1:
+				case GCT_INT1:
+				case GCT_SAMPLER1D:
+				case GCT_SAMPLER2D:
+				case GCT_SAMPLER3D:
+				case GCT_SAMPLERCUBE:
+				case GCT_SAMPLER1DSHADOW:
+				case GCT_SAMPLER2DSHADOW:
+					return 1;
+				case GCT_FLOAT2:
+				case GCT_INT2:
+					return 2;
+				case GCT_FLOAT3:
+				case GCT_INT3:
+					return 3;
+				case GCT_FLOAT4:
+				case GCT_INT4:
+					return 4;
+				case GCT_MATRIX_2X2:
+					return 4;
+				case GCT_MATRIX_2X3:
+				case GCT_MATRIX_3X2:
+					return 6;
+				case GCT_MATRIX_2X4:
+				case GCT_MATRIX_4X2:
+					return 8; 
+				case GCT_MATRIX_3X3:
+					return 9;
+				case GCT_MATRIX_3X4:
+				case GCT_MATRIX_4X3:
+					return 12; 
+				case GCT_MATRIX_4X4:
+					return 16; 
+				default:
+					return 4;
+				};
+
+			}
+		}
+
+		GpuConstantDefinition()
+			: constType(GCT_UNKNOWN)
+			, physicalIndex((std::numeric_limits<size_t>::max)())
+			, elementSize(0)
+			, arraySize(1)
+			, variability(GPV_GLOBAL) {}
+	};
+	typedef map<String, GpuConstantDefinition>::type GpuConstantDefinitionMap;
+	typedef GpuConstantDefinitionMap::const_iterator GpuConstantDefinitionIterator;
+
+	/// Struct collecting together the information for named constants.
+	struct _OgreExport GpuNamedConstants
+	{
+		/// Total size of the float buffer required
+		size_t floatBufferSize;
+		/// Total size of the int buffer required
+		size_t intBufferSize;
+		/// Map of parameter names to GpuConstantDefinition
+		GpuConstantDefinitionMap map;
+
+		GpuNamedConstants() : floatBufferSize(0), intBufferSize(0) {}
+
+		/** Generate additional constant entries for arrays based on a base definition.
+		@remarks
+		Array uniforms will be added just with their base name with no array
+		suffix. This method will add named entries for array suffixes too
+		so individual array entries can be addressed. Note that we only 
+		individually index array elements if the array size is up to 16
+		entries in size. Anything larger than that only gets a [0] entry
+		as well as the main entry, to save cluttering up the name map. After
+		all, you can address the larger arrays in a bulk fashion much more
+		easily anyway. 
+		*/
+		void generateConstantDefinitionArrayEntries(const String& paramName, 
+			const GpuConstantDefinition& baseDef);
+
+		/// Indicates whether all array entries will be generated and added to the definitions map
+		static bool getGenerateAllConstantDefinitionArrayEntries();
+
+		/** Sets whether all array entries will be generated and added to the definitions map.
+		@remarks
+		Usually, array entries can only be individually indexed if they're up to 16 entries long,
+		to save memory - arrays larger than that can be set but only via the bulk setting
+		methods. This option allows you to choose to individually index every array entry. 
+		*/
+		static void setGenerateAllConstantDefinitionArrayEntries(bool generateAll);
+
+	protected:
+		/** Indicates whether all array entries will be generated and added to the definitions map
+		@remarks
+		Normally, the number of array entries added to the definitions map is capped at 16
+		to save memory. Setting this value to <code>true</code> allows all of the entries
+		to be generated and added to the map.
+		*/
+		static bool msGenerateAllConstantDefinitionArrayEntries;
+	};
+	typedef SharedPtr<GpuNamedConstants> GpuNamedConstantsPtr;
+
+	/** Structure recording the use of a physical buffer by a logical parameter
+	index. Only used for low-level programs.
+	*/
+	struct _OgreExport GpuLogicalIndexUse
+	{
+		/// Physical buffer index
+		size_t physicalIndex;
+		/// Current physical size allocation
+		size_t currentSize;
+		/// How the contents of this slot vary
+		mutable uint16 variability;
+
+		GpuLogicalIndexUse() 
+			: physicalIndex(99999), currentSize(0), variability(GPV_GLOBAL) {}
+		GpuLogicalIndexUse(size_t bufIdx, size_t curSz, uint16 v) 
+			: physicalIndex(bufIdx), currentSize(curSz), variability(v) {}
+	};
+	typedef map<size_t, GpuLogicalIndexUse>::type GpuLogicalIndexUseMap;
+	/// Container struct to allow params to safely & update shared list of logical buffer assignments
+	struct _OgreExport GpuLogicalBufferStruct
+	{
+		OGRE_MUTEX(mutex)
+			/// Map from logical index to physical buffer location
+			GpuLogicalIndexUseMap map;
+		/// Shortcut to know the buffer size needs
+		size_t bufferSize;
+		GpuLogicalBufferStruct() : bufferSize(0) {}
+	};
+	typedef SharedPtr<GpuLogicalBufferStruct> GpuLogicalBufferStructPtr;
+
+	/** Definition of container that holds the current float constants.
+	@note Not necessarily in direct index order to constant indexes, logical
+	to physical index map is derived from GpuProgram
+	*/
+	typedef vector<float>::type FloatConstantList;
+	/** Definition of container that holds the current float constants.
+	@note Not necessarily in direct index order to constant indexes, logical
+	to physical index map is derived from GpuProgram
+	*/
+	typedef vector<int>::type IntConstantList;
+
+	/** A group of manually updated parameters that are shared between many parameter sets.
+	@remarks
+		Sometimes you want to set some common parameters across many otherwise 
+		different parameter sets, and keep them all in sync together. This class
+		allows you to define a set of parameters that you can share across many
+		parameter sets and have the parameters that match automatically be pulled
+		from the shared set, rather than you having to set them on all the parameter
+		sets individually.
+	@par
+		Parameters in a shared set are matched up with instances in a GpuProgramParameters
+		structure by matching names. It is up to you to define the named parameters
+		that a shared set contains, and ensuring the definition matches.
+	@note
+		Shared parameter sets can be named, and looked up using the GpuProgramManager.
+	*/
+	class _OgreExport GpuSharedParameters
+	{
+	protected:
+		GpuNamedConstants mNamedConstants;
+		FloatConstantList mFloatConstants;
+		IntConstantList mIntConstants;
+		String mName;
+
+		// Optional data the rendersystem might want to store
+		// TODO PORT - Commented out because I don't think anything uses this and it requires an extra include 
+		//mutable Any mRenderSystemData;
+
+		/// Not used when copying data, but might be useful to RS using shared buffers
+		size_t mFrameLastUpdated;
+
+		/// Version number of the definitions in this buffer
+		unsigned long mVersion; 
+
+	public:
+		GpuSharedParameters(const String& name);
+		virtual ~GpuSharedParameters();
+
+		/// Get the name of this shared parameter set
+		const String& getName() { return mName; }
+
+		/** Add a new constant definition to this shared set of parameters.
+		@remarks
+			Unlike GpuProgramParameters, where the parameter list is defined by the
+			program being compiled, this shared parameter set is defined by the
+			user. Only parameters which have been predefined here may be later
+			updated.
+		*/
+		void addConstantDefinition(const String& name, GpuConstantType constType, size_t arraySize = 1);
+
+		/** Remove a constant definition from this shared set of parameters.
+		*/
+		void removeConstantDefinition(const String& name);
+
+		/** Remove a constant definition from this shared set of parameters.
+		*/
+		void removeAllConstantDefinitions();
+
+		/** Get the version number of this shared parameter set, can be used to identify when 
+			changes have occurred. 
+		*/
+		unsigned long getVersion() const { return mVersion; }
+
+		/** Mark the shared set as being dirty (values modified).
+		@remarks
+		You do not need to call this yourself, set is marked as dirty whenever
+		setNamedConstant or (non const) getFloatPointer et al are called.
+		*/
+		void _markDirty();
+		/// Get the frame in which this shared parameter set was last updated
+		size_t getFrameLastUpdated() const { return mFrameLastUpdated; }
+
+		/** Gets an iterator over the named GpuConstantDefinition instances as defined
+			by the user. 
+		*/
+		GpuConstantDefinitionIterator getConstantDefinitionIterator(void) const;
+
+		/** Get a specific GpuConstantDefinition for a named parameter.
+		*/
+		const GpuConstantDefinition& getConstantDefinition(const String& name) const;
+
+		/** Get the full list of GpuConstantDefinition instances.
+		*/
+		const GpuNamedConstants& getConstantDefinitions() const;
+	
+		/** @copydoc GpuProgramParameters::setNamedConstant */
+		void setNamedConstant(const String& name, Real val);
+		/** @copydoc GpuProgramParameters::setNamedConstant */
+		void setNamedConstant(const String& name, int val);
+		/** @copydoc GpuProgramParameters::setNamedConstant */
+		void setNamedConstant(const String& name, const Vector4& vec);
+		/** @copydoc GpuProgramParameters::setNamedConstant */
+		void setNamedConstant(const String& name, const Vector3& vec);
+		/** @copydoc GpuProgramParameters::setNamedConstant */
+		void setNamedConstant(const String& name, const Matrix4& m);
+		/** @copydoc GpuProgramParameters::setNamedConstant */
+		void setNamedConstant(const String& name, const Matrix4* m, size_t numEntries);
+		/** @copydoc GpuProgramParameters::setNamedConstant */
+		void setNamedConstant(const String& name, const float *val, size_t count);
+		/** @copydoc GpuProgramParameters::setNamedConstant */
+		void setNamedConstant(const String& name, const double *val, size_t count);
+			/** @copydoc GpuProgramParameters::setNamedConstant */
+		void setNamedConstant(const String& name, const ColourValue& colour);
+		/** @copydoc GpuProgramParameters::setNamedConstant */
+		void setNamedConstant(const String& name, const int *val, size_t count);
+
+		/// Get a pointer to the 'nth' item in the float buffer
+		float* getFloatPointer(size_t pos) { _markDirty(); return &mFloatConstants[pos]; }
+		/// Get a pointer to the 'nth' item in the float buffer
+		const float* getFloatPointer(size_t pos) const { return &mFloatConstants[pos]; }
+		/// Get a pointer to the 'nth' item in the int buffer
+		int* getIntPointer(size_t pos) { _markDirty(); return &mIntConstants[pos]; }
+		/// Get a pointer to the 'nth' item in the int buffer
+		const int* getIntPointer(size_t pos) const { return &mIntConstants[pos]; }
+
+
+		// TODO PORT - Commented out for the same reason as mRenderSystemData (see above)
+		///** Internal method that the RenderSystem might use to store optional data. */
+		//void _setRenderSystemData(const Any& data) const { mRenderSystemData = data; }
+		///** Internal method that the RenderSystem might use to store optional data. */
+		//const Any& _getRenderSystemData() const { return mRenderSystemData; }
+
+	};
+
+	/// Shared pointer used to hold references to GpuProgramParameters instances
+	typedef SharedPtr<GpuSharedParameters> GpuSharedParametersPtr;
+
+	class GpuProgramParameters;
+
+	/** This class records the usage of a set of shared parameters in a concrete
+		set of GpuProgramParameters.
+	*/
+	class _OgreExport GpuSharedParametersUsage
+	{
+	protected:
+		GpuSharedParametersPtr mSharedParams;
+		// Not a shared pointer since this is also parent
+		GpuProgramParameters* mParams;
+		// list of physical mappings that we are going to bring in
+		struct CopyDataEntry
+		{
+			const GpuConstantDefinition* srcDefinition;
+			const GpuConstantDefinition* dstDefinition;
+		};
+		typedef vector<CopyDataEntry>::type CopyDataList;
+
+		CopyDataList mCopyDataList;
+
+		// Optional data the rendersystem might want to store
+		// TODO PORT - Commented out because I don't think its used
+		//mutable Any mRenderSystemData;
+
+		/// Version of shared params we based the copydata on
+		unsigned long mCopyDataVersion;
+
+		void initCopyData();
+
+
+	public:
+		/// Construct usage
+		GpuSharedParametersUsage(GpuSharedParametersPtr sharedParams, 
+			GpuProgramParameters* params);
+
+		/** Update the target parameters by copying the data from the shared
+			parameters.
+		@note This method  may not actually be called if the RenderSystem
+			supports using shared parameters directly in their own shared buffer; in
+			which case the values should not be copied out of the shared area
+			into the individual parameter set, but bound separately.
+		*/
+		void _copySharedParamsToTargetParams();
+
+		/// Get the name of the shared parameter set
+		const String& getName() const { return mSharedParams->getName(); }
+
+		GpuSharedParametersPtr getSharedParams() const { return mSharedParams; }
+		GpuProgramParameters* getTargetParams() const { return mParams; }
+
+		// TODO PORT - Commented out for the same reason as mRenderSystemData (see above)
+		///** Internal method that the RenderSystem might use to store optional data. */
+		//void _setRenderSystemData(const Any& data) const { mRenderSystemData = data; }
+		///** Internal method that the RenderSystem might use to store optional data. */
+		//const Any& _getRenderSystemData() const { return mRenderSystemData; }
+
+
+	};
+
+	/** Collects together the program parameters used for a GpuProgram.
+	@remarks
+	Gpu program state includes constant parameters used by the program, and
+	bindings to render system state which is propagated into the constants 
+	by the engine automatically if requested.
+	@par
+	GpuProgramParameters objects should be created through the GpuProgram and
+	may be shared between multiple Pass instances. For this reason they
+	are managed using a shared pointer, which will ensure they are automatically
+	deleted when no Pass is using them anymore. 
+	@par
+	High-level programs use named parameters (uniforms), low-level programs 
+	use indexed constants. This class supports both, but you can tell whether 
+	named constants are supported by calling hasNamedParameters(). There are
+	references in the documentation below to 'logical' and 'physical' indexes;
+	logical indexes are the indexes used by low-level programs and represent 
+	indexes into an array of float4's, some of which may be settable, some of
+	which may be predefined constants in the program. We only store those
+	constants which have actually been set, therefore our buffer could have 
+	gaps if we used the logical indexes in our own buffers. So instead we map
+	these logical indexes to physical indexes in our buffer. When using 
+	high-level programs, logical indexes don't necessarily exist, although they
+	might if the high-level program has a direct, exposed mapping from parameter
+	names to logical indexes. In addition, high-level languages may or may not pack
+	arrays of elements that are smaller than float4 (e.g. float2/vec2) contiguously.
+	This kind of information is held in the ConstantDefinition structure which 
+	is only populated for high-level programs. You don't have to worry about
+	any of this unless you intend to read parameters back from this structure
+	rather than just setting them.
+	*/
+	class _OgreExport GpuProgramParameters
+	{
+	public:
+		/** Defines the types of automatically updated values that may be bound to GpuProgram
+		parameters, or used to modify parameters on a per-object basis.
+		*/
+		enum AutoConstantType
+		{
+			/// The current world matrix
+			ACT_WORLD_MATRIX,
+			/// The current world matrix, inverted
+			ACT_INVERSE_WORLD_MATRIX,
+			/** Provides transpose of world matrix.
+			Equivalent to RenderMonkey's "WorldTranspose".
+			*/
+			ACT_TRANSPOSE_WORLD_MATRIX,
+			/// The current world matrix, inverted & transposed
+			ACT_INVERSE_TRANSPOSE_WORLD_MATRIX,
+
+
+			/// The current array of world matrices, as a 3x4 matrix, used for blending
+			ACT_WORLD_MATRIX_ARRAY_3x4,
+			/// The current array of world matrices, used for blending
+			ACT_WORLD_MATRIX_ARRAY,
+
+			/// The current view matrix
+			ACT_VIEW_MATRIX,
+			/// The current view matrix, inverted
+			ACT_INVERSE_VIEW_MATRIX,
+			/** Provides transpose of view matrix.
+			Equivalent to RenderMonkey's "ViewTranspose".
+			*/
+			ACT_TRANSPOSE_VIEW_MATRIX,
+			/** Provides inverse transpose of view matrix.
+			Equivalent to RenderMonkey's "ViewInverseTranspose".
+			*/
+			ACT_INVERSE_TRANSPOSE_VIEW_MATRIX,
+
+
+			/// The current projection matrix
+			ACT_PROJECTION_MATRIX,
+			/** Provides inverse of projection matrix.
+			Equivalent to RenderMonkey's "ProjectionInverse".
+			*/
+			ACT_INVERSE_PROJECTION_MATRIX,
+			/** Provides transpose of projection matrix.
+			Equivalent to RenderMonkey's "ProjectionTranspose".
+			*/
+			ACT_TRANSPOSE_PROJECTION_MATRIX,
+			/** Provides inverse transpose of projection matrix.
+			Equivalent to RenderMonkey's "ProjectionInverseTranspose".
+			*/
+			ACT_INVERSE_TRANSPOSE_PROJECTION_MATRIX,
+
+
+			/// The current view & projection matrices concatenated
+			ACT_VIEWPROJ_MATRIX,
+			/** Provides inverse of concatenated view and projection matrices.
+			Equivalent to RenderMonkey's "ViewProjectionInverse".
+			*/
+			ACT_INVERSE_VIEWPROJ_MATRIX,
+			/** Provides transpose of concatenated view and projection matrices.
+			Equivalent to RenderMonkey's "ViewProjectionTranspose".
+			*/
+			ACT_TRANSPOSE_VIEWPROJ_MATRIX,
+			/** Provides inverse transpose of concatenated view and projection matrices.
+			Equivalent to RenderMonkey's "ViewProjectionInverseTranspose".
+			*/
+			ACT_INVERSE_TRANSPOSE_VIEWPROJ_MATRIX,
+
+
+			/// The current world & view matrices concatenated
+			ACT_WORLDVIEW_MATRIX,
+			/// The current world & view matrices concatenated, then inverted
+			ACT_INVERSE_WORLDVIEW_MATRIX,
+			/** Provides transpose of concatenated world and view matrices.
+			Equivalent to RenderMonkey's "WorldViewTranspose".
+			*/
+			ACT_TRANSPOSE_WORLDVIEW_MATRIX,
+			/// The current world & view matrices concatenated, then inverted & transposed
+			ACT_INVERSE_TRANSPOSE_WORLDVIEW_MATRIX,
+			/// view matrices.
+
+
+			/// The current world, view & projection matrices concatenated
+			ACT_WORLDVIEWPROJ_MATRIX,
+			/** Provides inverse of concatenated world, view and projection matrices.
+			Equivalent to RenderMonkey's "WorldViewProjectionInverse".
+			*/
+			ACT_INVERSE_WORLDVIEWPROJ_MATRIX,
+			/** Provides transpose of concatenated world, view and projection matrices.
+			Equivalent to RenderMonkey's "WorldViewProjectionTranspose".
+			*/
+			ACT_TRANSPOSE_WORLDVIEWPROJ_MATRIX,
+			/** Provides inverse transpose of concatenated world, view and projection
+			matrices. Equivalent to RenderMonkey's "WorldViewProjectionInverseTranspose".
+			*/
+			ACT_INVERSE_TRANSPOSE_WORLDVIEWPROJ_MATRIX,
+
+
+			/// render target related values
+			/** -1 if requires texture flipping, +1 otherwise. It's useful when you bypassed
+			projection matrix transform, still able use this value to adjust transformed y position.
+			*/
+			ACT_RENDER_TARGET_FLIPPING,
+
+			/** -1 if the winding has been inverted (e.g. for reflections), +1 otherwise.
+			*/
+			ACT_VERTEX_WINDING,
+
+			/// Fog colour
+			ACT_FOG_COLOUR,
+			/// Fog params: density, linear start, linear end, 1/(end-start)
+			ACT_FOG_PARAMS,
+
+
+			/// Surface ambient colour, as set in Pass::setAmbient
+			ACT_SURFACE_AMBIENT_COLOUR,
+			/// Surface diffuse colour, as set in Pass::setDiffuse
+			ACT_SURFACE_DIFFUSE_COLOUR,
+			/// Surface specular colour, as set in Pass::setSpecular
+			ACT_SURFACE_SPECULAR_COLOUR,
+			/// Surface emissive colour, as set in Pass::setSelfIllumination
+			ACT_SURFACE_EMISSIVE_COLOUR,
+			/// Surface shininess, as set in Pass::setShininess
+			ACT_SURFACE_SHININESS,
+
+
+			/// The number of active light sources (better than gl_MaxLights)
+			ACT_LIGHT_COUNT,
+
+
+			/// The ambient light colour set in the scene
+			ACT_AMBIENT_LIGHT_COLOUR, 
+
+			/// Light diffuse colour (index determined by setAutoConstant call)
+			ACT_LIGHT_DIFFUSE_COLOUR,
+			/// Light specular colour (index determined by setAutoConstant call)
+			ACT_LIGHT_SPECULAR_COLOUR,
+			/// Light attenuation parameters, Vector4(range, constant, linear, quadric)
+			ACT_LIGHT_ATTENUATION,
+			/** Spotlight parameters, Vector4(innerFactor, outerFactor, falloff, isSpot)
+			innerFactor and outerFactor are cos(angle/2)
+			The isSpot parameter is 0.0f for non-spotlights, 1.0f for spotlights.
+			Also for non-spotlights the inner and outer factors are 1 and nearly 1 respectively
+			*/ 
+			ACT_SPOTLIGHT_PARAMS,
+			/// A light position in world space (index determined by setAutoConstant call)
+			ACT_LIGHT_POSITION,
+			/// A light position in object space (index determined by setAutoConstant call)
+			ACT_LIGHT_POSITION_OBJECT_SPACE,
+			/// A light position in view space (index determined by setAutoConstant call)
+			ACT_LIGHT_POSITION_VIEW_SPACE,
+			/// A light direction in world space (index determined by setAutoConstant call)
+			ACT_LIGHT_DIRECTION,
+			/// A light direction in object space (index determined by setAutoConstant call)
+			ACT_LIGHT_DIRECTION_OBJECT_SPACE,
+			/// A light direction in view space (index determined by setAutoConstant call)
+			ACT_LIGHT_DIRECTION_VIEW_SPACE,
+			/** The distance of the light from the center of the object
+			a useful approximation as an alternative to per-vertex distance
+			calculations.
+			*/
+			ACT_LIGHT_DISTANCE_OBJECT_SPACE,
+			/** Light power level, a single scalar as set in Light::setPowerScale  (index determined by setAutoConstant call) */
+			ACT_LIGHT_POWER_SCALE,
+			/// Light diffuse colour pre-scaled by Light::setPowerScale (index determined by setAutoConstant call)
+			ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED,
+			/// Light specular colour pre-scaled by Light::setPowerScale (index determined by setAutoConstant call)
+			ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED,
+			/// Array of light diffuse colours (count set by extra param)
+			ACT_LIGHT_DIFFUSE_COLOUR_ARRAY,
+			/// Array of light specular colours (count set by extra param)
+			ACT_LIGHT_SPECULAR_COLOUR_ARRAY,
+			/// Array of light diffuse colours scaled by light power (count set by extra param)
+			ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED_ARRAY,
+			/// Array of light specular colours scaled by light power (count set by extra param)
+			ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED_ARRAY,
+			/// Array of light attenuation parameters, Vector4(range, constant, linear, quadric) (count set by extra param)
+			ACT_LIGHT_ATTENUATION_ARRAY,
+			/// Array of light positions in world space (count set by extra param)
+			ACT_LIGHT_POSITION_ARRAY,
+			/// Array of light positions in object space (count set by extra param)
+			ACT_LIGHT_POSITION_OBJECT_SPACE_ARRAY,
+			/// Array of light positions in view space (count set by extra param)
+			ACT_LIGHT_POSITION_VIEW_SPACE_ARRAY,
+			/// Array of light directions in world space (count set by extra param)
+			ACT_LIGHT_DIRECTION_ARRAY,
+			/// Array of light directions in object space (count set by extra param)
+			ACT_LIGHT_DIRECTION_OBJECT_SPACE_ARRAY,
+			/// Array of light directions in view space (count set by extra param)
+			ACT_LIGHT_DIRECTION_VIEW_SPACE_ARRAY,
+			/** Array of distances of the lights from the center of the object
+			a useful approximation as an alternative to per-vertex distance
+			calculations. (count set by extra param)
+			*/
+			ACT_LIGHT_DISTANCE_OBJECT_SPACE_ARRAY,
+			/** Array of light power levels, a single scalar as set in Light::setPowerScale 
+			(count set by extra param)
+			*/
+			ACT_LIGHT_POWER_SCALE_ARRAY,
+			/** Spotlight parameters array of Vector4(innerFactor, outerFactor, falloff, isSpot)
+			innerFactor and outerFactor are cos(angle/2)
+			The isSpot parameter is 0.0f for non-spotlights, 1.0f for spotlights.
+			Also for non-spotlights the inner and outer factors are 1 and nearly 1 respectively.
+			(count set by extra param)
+			*/ 
+			ACT_SPOTLIGHT_PARAMS_ARRAY,
+
+			/** The derived ambient light colour, with 'r', 'g', 'b' components filled with
+			product of surface ambient colour and ambient light colour, respectively,
+			and 'a' component filled with surface ambient alpha component.
+			*/
+			ACT_DERIVED_AMBIENT_LIGHT_COLOUR,
+			/** The derived scene colour, with 'r', 'g' and 'b' components filled with sum
+			of derived ambient light colour and surface emissive colour, respectively,
+			and 'a' component filled with surface diffuse alpha component.
+			*/
+			ACT_DERIVED_SCENE_COLOUR,
+
+			/** The derived light diffuse colour (index determined by setAutoConstant call),
+			with 'r', 'g' and 'b' components filled with product of surface diffuse colour,
+			light power scale and light diffuse colour, respectively, and 'a' component filled with surface
+			diffuse alpha component.
+			*/
+			ACT_DERIVED_LIGHT_DIFFUSE_COLOUR,
+			/** The derived light specular colour (index determined by setAutoConstant call),
+			with 'r', 'g' and 'b' components filled with product of surface specular colour
+			and light specular colour, respectively, and 'a' component filled with surface
+			specular alpha component.
+			*/
+			ACT_DERIVED_LIGHT_SPECULAR_COLOUR,
+
+			/// Array of derived light diffuse colours (count set by extra param)
+			ACT_DERIVED_LIGHT_DIFFUSE_COLOUR_ARRAY,
+			/// Array of derived light specular colours (count set by extra param)
+			ACT_DERIVED_LIGHT_SPECULAR_COLOUR_ARRAY,
+			/** The absolute light number of a local light index. Each pass may have
+			a number of lights passed to it, and each of these lights will have
+			an index in the overall light list, which will differ from the local
+			light index due to factors like setStartLight and setIteratePerLight.
+			This binding provides the global light index for a local index.
+			*/
+			ACT_LIGHT_NUMBER,
+			/// Returns (int) 1 if the  given light casts shadows, 0 otherwise (index set in extra param)
+			ACT_LIGHT_CASTS_SHADOWS,
+
+
+			/** The distance a shadow volume should be extruded when using
+			finite extrusion programs.
+			*/
+			ACT_SHADOW_EXTRUSION_DISTANCE,
+			/// The current camera's position in world space
+			ACT_CAMERA_POSITION,
+			/// The current camera's position in object space 
+			ACT_CAMERA_POSITION_OBJECT_SPACE,
+			/// The view/projection matrix of the assigned texture projection frustum
+			ACT_TEXTURE_VIEWPROJ_MATRIX,
+			/// Array of view/projection matrices of the first n texture projection frustums
+			ACT_TEXTURE_VIEWPROJ_MATRIX_ARRAY,
+			/** The view/projection matrix of the assigned texture projection frustum, 
+			combined with the current world matrix
+			*/
+			ACT_TEXTURE_WORLDVIEWPROJ_MATRIX,
+			/// Array of world/view/projection matrices of the first n texture projection frustums
+			ACT_TEXTURE_WORLDVIEWPROJ_MATRIX_ARRAY,
+			/// The view/projection matrix of a given spotlight
+			ACT_SPOTLIGHT_VIEWPROJ_MATRIX,
+			/// Array of view/projection matrix of a given spotlight
+			ACT_SPOTLIGHT_VIEWPROJ_MATRIX_ARRAY,
+			/** The view/projection matrix of a given spotlight projection frustum, 
+			combined with the current world matrix
+			*/
+			ACT_SPOTLIGHT_WORLDVIEWPROJ_MATRIX,
+			/// A custom parameter which will come from the renderable, using 'data' as the identifier
+			ACT_CUSTOM,
+			/** provides current elapsed time
+			*/
+			ACT_TIME,
+			/** Single float value, which repeats itself based on given as
+			parameter "cycle time". Equivalent to RenderMonkey's "Time0_X".
+			*/
+			ACT_TIME_0_X,
+			/// Cosine of "Time0_X". Equivalent to RenderMonkey's "CosTime0_X".
+			ACT_COSTIME_0_X,
+			/// Sine of "Time0_X". Equivalent to RenderMonkey's "SinTime0_X".
+			ACT_SINTIME_0_X,
+			/// Tangent of "Time0_X". Equivalent to RenderMonkey's "TanTime0_X".
+			ACT_TANTIME_0_X,
+			/** Vector of "Time0_X", "SinTime0_X", "CosTime0_X", 
+			"TanTime0_X". Equivalent to RenderMonkey's "Time0_X_Packed".
+			*/
+			ACT_TIME_0_X_PACKED,
+			/** Single float value, which represents scaled time value [0..1],
+			which repeats itself based on given as parameter "cycle time".
+			Equivalent to RenderMonkey's "Time0_1".
+			*/
+			ACT_TIME_0_1,
+			/// Cosine of "Time0_1". Equivalent to RenderMonkey's "CosTime0_1".
+			ACT_COSTIME_0_1,
+			/// Sine of "Time0_1". Equivalent to RenderMonkey's "SinTime0_1".
+			ACT_SINTIME_0_1,
+			/// Tangent of "Time0_1". Equivalent to RenderMonkey's "TanTime0_1".
+			ACT_TANTIME_0_1,
+			/** Vector of "Time0_1", "SinTime0_1", "CosTime0_1",
+			"TanTime0_1". Equivalent to RenderMonkey's "Time0_1_Packed".
+			*/
+			ACT_TIME_0_1_PACKED,
+			/**	Single float value, which represents scaled time value [0..2*Pi],
+			which repeats itself based on given as parameter "cycle time".
+			Equivalent to RenderMonkey's "Time0_2PI".
+			*/
+			ACT_TIME_0_2PI,
+			/// Cosine of "Time0_2PI". Equivalent to RenderMonkey's "CosTime0_2PI".
+			ACT_COSTIME_0_2PI,
+			/// Sine of "Time0_2PI". Equivalent to RenderMonkey's "SinTime0_2PI".
+			ACT_SINTIME_0_2PI,
+			/// Tangent of "Time0_2PI". Equivalent to RenderMonkey's "TanTime0_2PI".
+			ACT_TANTIME_0_2PI,
+			/** Vector of "Time0_2PI", "SinTime0_2PI", "CosTime0_2PI",
+			"TanTime0_2PI". Equivalent to RenderMonkey's "Time0_2PI_Packed".
+			*/
+			ACT_TIME_0_2PI_PACKED,
+			/// provides the scaled frame time, returned as a floating point value.
+			ACT_FRAME_TIME,
+			/// provides the calculated frames per second, returned as a floating point value.
+			ACT_FPS,
+			/// viewport-related values
+			/** Current viewport width (in pixels) as floating point value.
+			Equivalent to RenderMonkey's "ViewportWidth".
+			*/
+			ACT_VIEWPORT_WIDTH,
+			/** Current viewport height (in pixels) as floating point value.
+			Equivalent to RenderMonkey's "ViewportHeight".
+			*/
+			ACT_VIEWPORT_HEIGHT,
+			/** This variable represents 1.0/ViewportWidth. 
+			Equivalent to RenderMonkey's "ViewportWidthInverse".
+			*/
+			ACT_INVERSE_VIEWPORT_WIDTH,
+			/** This variable represents 1.0/ViewportHeight.
+			Equivalent to RenderMonkey's "ViewportHeightInverse".
+			*/
+			ACT_INVERSE_VIEWPORT_HEIGHT,
+			/** Packed of "ViewportWidth", "ViewportHeight", "ViewportWidthInverse",
+			"ViewportHeightInverse".
+			*/
+			ACT_VIEWPORT_SIZE,
+
+			/// view parameters
+			/** This variable provides the view direction vector (world space).
+			Equivalent to RenderMonkey's "ViewDirection".
+			*/
+			ACT_VIEW_DIRECTION,
+			/** This variable provides the view side vector (world space).
+			Equivalent to RenderMonkey's "ViewSideVector".
+			*/
+			ACT_VIEW_SIDE_VECTOR,
+			/** This variable provides the view up vector (world space).
+			Equivalent to RenderMonkey's "ViewUpVector".
+			*/
+			ACT_VIEW_UP_VECTOR,
+			/** This variable provides the field of view as a floating point value.
+			Equivalent to RenderMonkey's "FOV".
+			*/
+			ACT_FOV,
+			/**	This variable provides the near clip distance as a floating point value.
+			Equivalent to RenderMonkey's "NearClipPlane".
+			*/
+			ACT_NEAR_CLIP_DISTANCE,
+			/**	This variable provides the far clip distance as a floating point value.
+			Equivalent to RenderMonkey's "FarClipPlane".
+			*/
+			ACT_FAR_CLIP_DISTANCE,
+
+			/** provides the pass index number within the technique
+			of the active materil.
+			*/
+			ACT_PASS_NUMBER,
+
+			/** provides the current iteration number of the pass. The iteration
+			number is the number of times the current render operation has
+			been drawn for the active pass.
+			*/
+			ACT_PASS_ITERATION_NUMBER,
+
+
+			/** Provides a parametric animation value [0..1], only available
+			where the renderable specifically implements it.
+			*/
+			ACT_ANIMATION_PARAMETRIC,
+
+			/** Provides the texel offsets required by this rendersystem to map
+			texels to pixels. Packed as 
+			float4(absoluteHorizontalOffset, absoluteVerticalOffset, 
+			horizontalOffset / viewportWidth, verticalOffset / viewportHeight)
+			*/
+			ACT_TEXEL_OFFSETS,
+
+			/** Provides information about the depth range of the scene as viewed
+			from the current camera. 
+			Passed as float4(minDepth, maxDepth, depthRange, 1 / depthRange)
+			*/
+			ACT_SCENE_DEPTH_RANGE,
+
+			/** Provides information about the depth range of the scene as viewed
+			from a given shadow camera. Requires an index parameter which maps
+			to a light index relative to the current light list.
+			Passed as float4(minDepth, maxDepth, depthRange, 1 / depthRange)
+			*/
+			ACT_SHADOW_SCENE_DEPTH_RANGE,
+
+			/** Provides the fixed shadow colour as configured via SceneManager::setShadowColour;
+			useful for integrated modulative shadows.
+			*/
+			ACT_SHADOW_COLOUR,
+			/** Provides texture size of the texture unit (index determined by setAutoConstant
+			call). Packed as float4(width, height, depth, 1)
+			*/
+			ACT_TEXTURE_SIZE,
+			/** Provides inverse texture size of the texture unit (index determined by setAutoConstant
+			call). Packed as float4(1 / width, 1 / height, 1 / depth, 1)
+			*/
+			ACT_INVERSE_TEXTURE_SIZE,
+			/** Provides packed texture size of the texture unit (index determined by setAutoConstant
+			call). Packed as float4(width, height, 1 / width, 1 / height)
+			*/
+			ACT_PACKED_TEXTURE_SIZE,
+
+			/** Provides the current transform matrix of the texture unit (index determined by setAutoConstant
+			call), as seen by the fixed-function pipeline. 
+			*/
+			ACT_TEXTURE_MATRIX, 
+
+			/** Provides the position of the LOD camera in world space, allowing you 
+			to perform separate LOD calculations in shaders independent of the rendering
+			camera. If there is no separate LOD camera then this is the real camera
+			position. See Camera::setLodCamera.
+			*/
+			ACT_LOD_CAMERA_POSITION, 
+			/** Provides the position of the LOD camera in object space, allowing you 
+			to perform separate LOD calculations in shaders independent of the rendering
+			camera. If there is no separate LOD camera then this is the real camera
+			position. See Camera::setLodCamera.
+			*/
+			ACT_LOD_CAMERA_POSITION_OBJECT_SPACE, 
+			/** Binds custom per-light constants to the shaders. */
+			ACT_LIGHT_CUSTOM
+		};
+
+		/** Defines the type of the extra data item used by the auto constant.
+
+		*/
+		enum ACDataType {
+			/// no data is required
+			ACDT_NONE,
+			/// the auto constant requires data of type int
+			ACDT_INT,
+			/// the auto constant requires data of type real
+			ACDT_REAL
+		};
+
+		/** Defines the base element type of the auto constant
+		*/
+		enum ElementType {
+			ET_INT,
+			ET_REAL
+		};
+
+		/** Structure defining an auto constant that's available for use in 
+		a parameters object.
+		*/
+		struct AutoConstantDefinition
+		{
+			AutoConstantType acType;
+			String name;
+			size_t elementCount;
+			/// The type of the constant in the program
+			ElementType elementType;
+			/// The type of any extra data
+			ACDataType dataType;
+
+			AutoConstantDefinition(AutoConstantType _acType, const String& _name, 
+				size_t _elementCount, ElementType _elementType, 
+				ACDataType _dataType)
+				:acType(_acType), name(_name), elementCount(_elementCount), 
+				elementType(_elementType), dataType(_dataType)
+			{
+
+			}
+		};
+
+		/** Structure recording the use of an automatic parameter. */
+		class AutoConstantEntry
+		{
+		public:
+			/// The type of parameter
+			AutoConstantType paramType;
+			/// The target (physical) constant index
+			size_t physicalIndex;
+			/** The number of elements per individual entry in this constant
+			Used in case people used packed elements smaller than 4 (e.g. GLSL)
+			and bind an auto which is 4-element packed to it */
+			size_t elementCount;
+			/// Additional information to go with the parameter
+			union{
+				size_t data;
+				Real fData;
+			};
+			/// The variability of this parameter (see GpuParamVariability)
+			uint16 variability;
+
+			AutoConstantEntry(AutoConstantType theType, size_t theIndex, size_t theData, 
+				uint16 theVariability, size_t theElemCount = 4)
+				: paramType(theType), physicalIndex(theIndex), elementCount(theElemCount), 
+				data(theData), variability(theVariability) {}
+
+			AutoConstantEntry(AutoConstantType theType, size_t theIndex, Real theData, 
+				uint16 theVariability, size_t theElemCount = 4)
+				: paramType(theType), physicalIndex(theIndex), elementCount(theElemCount), 
+				fData(theData), variability(theVariability) {}
+
+		};
+		// Auto parameter storage
+		typedef vector<AutoConstantEntry>::type AutoConstantList;
+
+		typedef vector<GpuSharedParametersUsage>::type GpuSharedParamUsageList;
+
+	protected:
+		static AutoConstantDefinition AutoConstantDictionary[];
+		/// Packed list of floating-point constants (physical indexing)
+		FloatConstantList mFloatConstants;
+		/// Packed list of integer constants (physical indexing)
+		IntConstantList mIntConstants;
+		/** Logical index to physical index map - for low-level programs
+		or high-level programs which pass params this way. */
+		GpuLogicalBufferStructPtr mFloatLogicalToPhysical;
+		/** Logical index to physical index map - for low-level programs
+		or high-level programs which pass params this way. */
+		GpuLogicalBufferStructPtr mIntLogicalToPhysical;
+		/// Mapping from parameter names to def - high-level programs are expected to populate this
+		GpuNamedConstantsPtr mNamedConstants;
+		/// List of automatically updated parameters
+		AutoConstantList mAutoConstants;
+		/// The combined variability masks of all parameters
+		uint16 mCombinedVariability;
+		/// Do we need to transpose matrices?
+		bool mTransposeMatrices;
+		/// flag to indicate if names not found will be ignored
+		bool mIgnoreMissingParams;
+		/// physical index for active pass iteration parameter real constant entry;
+		size_t mActivePassIterationIndex;
+
+		/** Gets the low-level structure for a logical index. 
+		*/
+		GpuLogicalIndexUse* _getFloatConstantLogicalIndexUse(size_t logicalIndex, size_t requestedSize, uint16 variability);
+		/** Gets the physical buffer index associated with a logical int constant index. 
+		*/
+		GpuLogicalIndexUse* _getIntConstantLogicalIndexUse(size_t logicalIndex, size_t requestedSize, uint16 variability);
+
+		/// Return the variability for an auto constant
+		uint16 deriveVariability(AutoConstantType act);
+
+		void copySharedParamSetUsage(const GpuSharedParamUsageList& srcList);
+
+		GpuSharedParamUsageList mSharedParamSets;
+
+		//// Optional data the rendersystem might want to store
+		// TODO PORT - Commented out because I dont think its used
+		//mutable Any mRenderSystemData;
+
+
+
+	public:
+		GpuProgramParameters();
+		~GpuProgramParameters() {}
+
+		/// Copy constructor
+		GpuProgramParameters(const GpuProgramParameters& oth);
+		/// Operator = overload
+		GpuProgramParameters& operator=(const GpuProgramParameters& oth);
+
+		/** Internal method for providing a link to a name->definition map for parameters. */
+		void _setNamedConstants(const GpuNamedConstantsPtr& constantmap);
+
+		/** Internal method for providing a link to a logical index->physical index map for parameters. */
+		void _setLogicalIndexes(const GpuLogicalBufferStructPtr& floatIndexMap, 
+			const GpuLogicalBufferStructPtr&  intIndexMap);
+
+
+		/// Does this parameter set include named parameters?
+		bool hasNamedParameters() const { return !mNamedConstants.isNull(); }
+		/** Does this parameter set include logically indexed parameters?
+		@note Not mutually exclusive with hasNamedParameters since some high-level
+		programs still use logical indexes to set the parameters on the 
+		rendersystem.
+		*/
+		bool hasLogicalIndexedParameters() const { return !mFloatLogicalToPhysical.isNull(); }
+
+		/** Sets a 4-element floating-point parameter to the program.
+		@param index The logical constant index at which to place the parameter 
+		(each constant is a 4D float)
+		@param vec The value to set
+		*/
+		void setConstant(size_t index, const Vector4& vec);
+		/** Sets a single floating-point parameter to the program.
+		@note This is actually equivalent to calling 
+		setConstant(index Vector4(val, 0, 0, 0)) since all constants are 4D.
+		@param index The logical constant index at which to place the parameter (each constant is
+		a 4D float)
+		@param val The value to set
+		*/
+		void setConstant(size_t index, Real val);
+		/** Sets a 4-element floating-point parameter to the program via Vector3.
+		@param index The logical constant index at which to place the parameter (each constant is
+		a 4D float).
+		Note that since you're passing a Vector3, the last element of the 4-element
+		value will be set to 1 (a homogeneous vector)
+		@param vec The value to set
+		*/
+		void setConstant(size_t index, const Vector3& vec);
+		/** Sets a Matrix4 parameter to the program.
+		@param index The logical constant index at which to place the parameter (each constant is
+		a 4D float).
+		NB since a Matrix4 is 16 floats long, this parameter will take up 4 indexes.
+		@param m The value to set
+		*/
+		void setConstant(size_t index, const Matrix4& m);
+		/** Sets a list of Matrix4 parameters to the program.
+		@param index The logical constant index at which to start placing the parameter (each constant is
+		a 4D float).
+		NB since a Matrix4 is 16 floats long, so each entry will take up 4 indexes.
+		@param m Pointer to an array of matrices to set
+		@param numEntries Number of Matrix4 entries
+		*/
+		void setConstant(size_t index, const Matrix4* m, size_t numEntries);
+		/** Sets a multiple value constant floating-point parameter to the program.
+		@param index The logical constant index at which to start placing parameters (each constant is
+		a 4D float)
+		@param val Pointer to the values to write, must contain 4*count floats
+		@param count The number of groups of 4 floats to write
+		*/
+		void setConstant(size_t index, const float *val, size_t count);
+		/** Sets a multiple value constant floating-point parameter to the program.
+		@param index The logical constant index at which to start placing parameters (each constant is
+		a 4D float)
+		@param val Pointer to the values to write, must contain 4*count floats
+		@param count The number of groups of 4 floats to write
+		*/
+		void setConstant(size_t index, const double *val, size_t count);
+		/** Sets a ColourValue parameter to the program.
+		@param index The logical constant index at which to place the parameter (each constant is
+		a 4D float)
+		@param colour The value to set
+		*/
+		void setConstant(size_t index, const ColourValue& colour);
+
+		/** Sets a multiple value constant integer parameter to the program.
+		@remarks
+		Different types of GPU programs support different types of constant parameters.
+		For example, it's relatively common to find that vertex programs only support
+		floating point constants, and that fragment programs only support integer (fixed point)
+		parameters. This can vary depending on the program version supported by the
+		graphics card being used. You should consult the documentation for the type of
+		low level program you are using, or alternatively use the methods
+		provided on RenderSystemCapabilities to determine the options.
+		@param index The logical constant index at which to place the parameter (each constant is
+		a 4D integer)
+		@param val Pointer to the values to write, must contain 4*count ints
+		@param count The number of groups of 4 ints to write
+		*/
+		void setConstant(size_t index, const int *val, size_t count);
+
+		/** Write a series of floating point values into the underlying float 
+		constant buffer at the given physical index.
+		@param physicalIndex The buffer position to start writing
+		@param val Pointer to a list of values to write
+		@param count The number of floats to write
+		*/
+		void _writeRawConstants(size_t physicalIndex, const float* val, size_t count);
+		/** Write a series of floating point values into the underlying float 
+		constant buffer at the given physical index.
+		@param physicalIndex The buffer position to start writing
+		@param val Pointer to a list of values to write
+		@param count The number of floats to write
+		*/
+		void _writeRawConstants(size_t physicalIndex, const double* val, size_t count);
+		/** Write a series of integer values into the underlying integer
+		constant buffer at the given physical index.
+		@param physicalIndex The buffer position to start writing
+		@param val Pointer to a list of values to write
+		@param count The number of ints to write
+		*/
+		void _writeRawConstants(size_t physicalIndex, const int* val, size_t count);
+		/** Read a series of floating point values from the underlying float 
+		constant buffer at the given physical index.
+		@param physicalIndex The buffer position to start reading
+		@param count The number of floats to read
+		@param dest Pointer to a buffer to receive the values
+		*/
+		void _readRawConstants(size_t physicalIndex, size_t count, float* dest);
+		/** Read a series of integer values from the underlying integer 
+		constant buffer at the given physical index.
+		@param physicalIndex The buffer position to start reading
+		@param count The number of ints to read
+		@param dest Pointer to a buffer to receive the values
+		*/
+		void _readRawConstants(size_t physicalIndex, size_t count, int* dest);
+
+		/** Write a 4-element floating-point parameter to the program directly to 
+		the underlying constants buffer.
+		@note You can use these methods if you have already derived the physical
+		constant buffer location, for a slight speed improvement over using
+		the named / logical index versions.
+		@param physicalIndex The physical buffer index at which to place the parameter 
+		@param vec The value to set
+		@param count The number of floats to write; if for example
+		the uniform constant 'slot' is smaller than a Vector4
+		*/
+		void _writeRawConstant(size_t physicalIndex, const Vector4& vec, 
+			size_t count = 4);
+		/** Write a single floating-point parameter to the program.
+		@note You can use these methods if you have already derived the physical
+		constant buffer location, for a slight speed improvement over using
+		the named / logical index versions.
+		@param physicalIndex The physical buffer index at which to place the parameter 
+		@param val The value to set
+		*/
+		void _writeRawConstant(size_t physicalIndex, Real val);
+		/** Write a single integer parameter to the program.
+		@note You can use these methods if you have already derived the physical
+		constant buffer location, for a slight speed improvement over using
+		the named / logical index versions.
+		@param physicalIndex The physical buffer index at which to place the parameter 
+		@param val The value to set
+		*/
+		void _writeRawConstant(size_t physicalIndex, int val);
+		/** Write a 3-element floating-point parameter to the program via Vector3.
+		@note You can use these methods if you have already derived the physical
+		constant buffer location, for a slight speed improvement over using
+		the named / logical index versions.
+		@param physicalIndex The physical buffer index at which to place the parameter 
+		@param vec The value to set
+		*/
+		void _writeRawConstant(size_t physicalIndex, const Vector3& vec);
+		/** Write a Matrix4 parameter to the program.
+		@note You can use these methods if you have already derived the physical
+		constant buffer location, for a slight speed improvement over using
+		the named / logical index versions.
+		@param physicalIndex The physical buffer index at which to place the parameter 
+		@param m The value to set
+		@param elementCount actual element count used with shader
+		*/
+		void _writeRawConstant(size_t physicalIndex, const Matrix4& m, size_t elementCount);
+		/** Write a list of Matrix4 parameters to the program.
+		@note You can use these methods if you have already derived the physical
+		constant buffer location, for a slight speed improvement over using
+		the named / logical index versions.
+		@param physicalIndex The physical buffer index at which to place the parameter 
+		@param numEntries Number of Matrix4 entries
+		*/
+		void _writeRawConstant(size_t physicalIndex, const Matrix4* m, size_t numEntries);
+		/** Write a ColourValue parameter to the program.
+		@note You can use these methods if you have already derived the physical
+		constant buffer location, for a slight speed improvement over using
+		the named / logical index versions.
+		@param physicalIndex The physical buffer index at which to place the parameter 
+		@param colour The value to set
+		@param count The number of floats to write; if for example
+		the uniform constant 'slot' is smaller than a Vector4
+		*/
+		void _writeRawConstant(size_t physicalIndex, const ColourValue& colour, 
+			size_t count = 4);
+
+
+		/** Gets an iterator over the named GpuConstantDefinition instances as defined
+		by the program for which these parameters exist.
+		@note
+		Only available if this parameters object has named parameters.
+		*/
+		GpuConstantDefinitionIterator getConstantDefinitionIterator(void) const;
+
+		/** Get a specific GpuConstantDefinition for a named parameter.
+		@note
+		Only available if this parameters object has named parameters.
+		*/
+		const GpuConstantDefinition& getConstantDefinition(const String& name) const;
+
+		/** Get the full list of GpuConstantDefinition instances.
+		@note
+		Only available if this parameters object has named parameters.
+		*/
+		const GpuNamedConstants& getConstantDefinitions() const;
+
+		/** Get the current list of mappings from low-level logical param indexes
+		to physical buffer locations in the float buffer.
+		@note
+		Only applicable to low-level programs.
+		*/
+		const GpuLogicalBufferStructPtr& getFloatLogicalBufferStruct() const { return mFloatLogicalToPhysical; }
+
+		/** Retrieves the logical index relating to a physical index in the float
+		buffer, for programs which support that (low-level programs and 
+		high-level programs which use logical parameter indexes).
+		@returns std::numeric_limits<size_t>::max() if not found
+		*/
+		size_t getFloatLogicalIndexForPhysicalIndex(size_t physicalIndex);
+		/** Retrieves the logical index relating to a physical index in the int
+		buffer, for programs which support that (low-level programs and 
+		high-level programs which use logical parameter indexes).
+		@returns std::numeric_limits<size_t>::max() if not found
+		*/
+		size_t getIntLogicalIndexForPhysicalIndex(size_t physicalIndex);
+
+		/** Get the current list of mappings from low-level logical param indexes
+		to physical buffer locations in the integer buffer.
+		@note
+		Only applicable to low-level programs.
+		*/
+		const GpuLogicalBufferStructPtr& getIntLogicalBufferStruct() const { return mIntLogicalToPhysical; }
+		/// Get a reference to the list of float constants
+		const FloatConstantList& getFloatConstantList() const { return mFloatConstants; }
+		/// Get a pointer to the 'nth' item in the float buffer
+		float* getFloatPointer(size_t pos) { return &mFloatConstants[pos]; }
+		/// Get a pointer to the 'nth' item in the float buffer
+		const float* getFloatPointer(size_t pos) const { return &mFloatConstants[pos]; }
+		/// Get a reference to the list of int constants
+		const IntConstantList& getIntConstantList() const { return mIntConstants; }
+		/// Get a pointer to the 'nth' item in the int buffer
+		int* getIntPointer(size_t pos) { return &mIntConstants[pos]; }
+		/// Get a pointer to the 'nth' item in the int buffer
+		const int* getIntPointer(size_t pos) const { return &mIntConstants[pos]; }
+		/// Get a reference to the list of auto constant bindings
+		const AutoConstantList& getAutoConstantList() const { return mAutoConstants; }
+
+		/** Sets up a constant which will automatically be updated by the system.
+		@remarks
+		Vertex and fragment programs often need parameters which are to do with the
+		current render state, or particular values which may very well change over time,
+		and often between objects which are being rendered. This feature allows you 
+		to set up a certain number of predefined parameter mappings that are kept up to 
+		date for you.
+		@param index The location in the constant list to place this updated constant every time
+		it is changed. Note that because of the nature of the types, we know how big the 
+		parameter details will be so you don't need to set that like you do for manual constants.
+		@param acType The type of automatic constant to set
+		@param extraInfo If the constant type needs more information (like a light index) put it here.
+		*/
+		void setAutoConstant(size_t index, AutoConstantType acType, size_t extraInfo = 0);
+		void setAutoConstantReal(size_t index, AutoConstantType acType, Real rData);
+
+		/** Sets up a constant which will automatically be updated by the system.
+		@remarks
+		Vertex and fragment programs often need parameters which are to do with the
+		current render state, or particular values which may very well change over time,
+		and often between objects which are being rendered. This feature allows you 
+		to set up a certain number of predefined parameter mappings that are kept up to 
+		date for you.
+		@param index The location in the constant list to place this updated constant every time
+		it is changed. Note that because of the nature of the types, we know how big the 
+		parameter details will be so you don't need to set that like you do for manual constants.
+		@param acType The type of automatic constant to set
+		@param extraInfo1 The first extra parameter required by the auto constant type
+		@param extraInfo2 The first extra parameter required by the auto constant type
+		*/
+		void setAutoConstant(size_t index, AutoConstantType acType, uint16 extraInfo1, uint16 extraInfo2);
+
+		/** As setAutoConstant, but sets up the auto constant directly against a
+		physical buffer index.
+		*/
+		void _setRawAutoConstant(size_t physicalIndex, AutoConstantType acType, size_t extraInfo, 
+			uint16 variability, size_t elementSize = 4);
+		/** As setAutoConstantReal, but sets up the auto constant directly against a
+		physical buffer index.
+		*/
+		void _setRawAutoConstantReal(size_t physicalIndex, AutoConstantType acType, Real rData, 
+			uint16 variability, size_t elementSize = 4);
+
+
+		/** Unbind an auto constant so that the constant is manually controlled again. */
+		void clearAutoConstant(size_t index);
+
+		/** Sets a named parameter up to track a derivation of the current time.
+		@param index The index of the parameter
+		@param factor The amount by which to scale the time value
+		*/  
+		void setConstantFromTime(size_t index, Real factor);
+
+		/** Clears all the existing automatic constants. */
+		void clearAutoConstants(void);
+		typedef AutoConstantList::const_iterator AutoConstantIterator;
+		/** Gets an iterator over the automatic constant bindings currently in place. */
+		AutoConstantIterator getAutoConstantIterator(void) const;
+		/// Gets the number of int constants that have been set
+		size_t getAutoConstantCount(void) const { return mAutoConstants.size(); }
+		/** Gets a specific Auto Constant entry if index is in valid range
+		otherwise returns a NULL
+		@param index which entry is to be retrieved
+		*/
+		AutoConstantEntry* getAutoConstantEntry(const size_t index);
+		/** Returns true if this instance has any automatic constants. */
+		bool hasAutoConstants(void) const { return !(mAutoConstants.empty()); }
+		/** Finds an auto constant that's affecting a given logical parameter 
+		index for floating-point values.
+		@note Only applicable for low-level programs.
+		*/
+		const AutoConstantEntry* findFloatAutoConstantEntry(size_t logicalIndex);
+		/** Finds an auto constant that's affecting a given logical parameter 
+		index for integer values.
+		@note Only applicable for low-level programs.
+		*/
+		const AutoConstantEntry* findIntAutoConstantEntry(size_t logicalIndex);
+		/** Finds an auto constant that's affecting a given named parameter index.
+		@note Only applicable to high-level programs.
+		*/
+		const AutoConstantEntry* findAutoConstantEntry(const String& paramName);
+		/** Finds an auto constant that's affecting a given physical position in 
+		the floating-point buffer
+		*/
+		const AutoConstantEntry* _findRawAutoConstantEntryFloat(size_t physicalIndex);
+		/** Finds an auto constant that's affecting a given physical position in 
+		the integer buffer
+		*/
+		const AutoConstantEntry* _findRawAutoConstantEntryInt(size_t physicalIndex);
+
+		/** Tells the program whether to ignore missing parameters or not.
+		*/
+		void setIgnoreMissingParams(bool state) { mIgnoreMissingParams = state; }
+
+		/** Sets a single value constant floating-point parameter to the program.
+		@remarks
+		Different types of GPU programs support different types of constant parameters.
+		For example, it's relatively common to find that vertex programs only support
+		floating point constants, and that fragment programs only support integer (fixed point)
+		parameters. This can vary depending on the program version supported by the
+		graphics card being used. You should consult the documentation for the type of
+		low level program you are using, or alternatively use the methods
+		provided on RenderSystemCapabilities to determine the options.
+		@par
+		Another possible limitation is that some systems only allow constants to be set
+		on certain boundaries, e.g. in sets of 4 values for example. Again, see
+		RenderSystemCapabilities for full details.
+		@note
+		This named option will only work if you are using a parameters object created
+		from a high-level program (HighLevelGpuProgram).
+		@param name The name of the parameter
+		@param val The value to set
+		*/
+		void setNamedConstant(const String& name, Real val);
+		/** Sets a single value constant integer parameter to the program.
+		@remarks
+		Different types of GPU programs support different types of constant parameters.
+		For example, it's relatively common to find that vertex programs only support
+		floating point constants, and that fragment programs only support integer (fixed point)
+		parameters. This can vary depending on the program version supported by the
+		graphics card being used. You should consult the documentation for the type of
+		low level program you are using, or alternatively use the methods
+		provided on RenderSystemCapabilities to determine the options.
+		@par
+		Another possible limitation is that some systems only allow constants to be set
+		on certain boundaries, e.g. in sets of 4 values for example. Again, see
+		RenderSystemCapabilities for full details.
+		@note
+		This named option will only work if you are using a parameters object created
+		from a high-level program (HighLevelGpuProgram).
+		@param name The name of the parameter
+		@param val The value to set
+		*/
+		void setNamedConstant(const String& name, int val);
+		/** Sets a Vector4 parameter to the program.
+		@param name The name of the parameter
+		@param vec The value to set
+		*/
+		void setNamedConstant(const String& name, const Vector4& vec);
+		/** Sets a Vector3 parameter to the program.
+		@note
+		This named option will only work if you are using a parameters object created
+		from a high-level program (HighLevelGpuProgram).
+		@param index The index at which to place the parameter
+		NB this index refers to the number of floats, so a Vector3 is 3. Note that many 
+		rendersystems & programs assume that every floating point parameter is passed in
+		as a vector of 4 items, so you are strongly advised to check with 
+		RenderSystemCapabilities before using this version - if in doubt use Vector4
+		or ColourValue instead (both are 4D).
+		@param vec The value to set
+		*/
+		void setNamedConstant(const String& name, const Vector3& vec);
+		/** Sets a Matrix4 parameter to the program.
+		@param name The name of the parameter
+		@param m The value to set
+		*/
+		void setNamedConstant(const String& name, const Matrix4& m);
+		/** Sets a list of Matrix4 parameters to the program.
+		@param name The name of the parameter; this must be the first index of an array,
+		for examples 'matrices[0]'
+		NB since a Matrix4 is 16 floats long, so each entry will take up 4 indexes.
+		@param m Pointer to an array of matrices to set
+		@param numEntries Number of Matrix4 entries
+		*/
+		void setNamedConstant(const String& name, const Matrix4* m, size_t numEntries);
+		/** Sets a multiple value constant floating-point parameter to the program.
+		@par
+		Some systems only allow constants to be set on certain boundaries, 
+		e.g. in sets of 4 values for example. The 'multiple' parameter allows
+		you to control that although you should only change it if you know
+		your chosen language supports that (at the time of writing, only
+		GLSL allows constants which are not a multiple of 4).
+		@note
+		This named option will only work if you are using a parameters object created
+		from a high-level program (HighLevelGpuProgram).
+		@param name The name of the parameter
+		@param val Pointer to the values to write
+		@param count The number of 'multiples' of floats to write
+		@param multiple The number of raw entries in each element to write, 
+		the default is 4 so count = 1 would write 4 floats.
+		*/
+		void setNamedConstant(const String& name, const float *val, size_t count, 
+			size_t multiple = 4);
+		/** Sets a multiple value constant floating-point parameter to the program.
+		@par
+		Some systems only allow constants to be set on certain boundaries, 
+		e.g. in sets of 4 values for example. The 'multiple' parameter allows
+		you to control that although you should only change it if you know
+		your chosen language supports that (at the time of writing, only
+		GLSL allows constants which are not a multiple of 4).
+		@note
+		This named option will only work if you are using a parameters object created
+		from a high-level program (HighLevelGpuProgram).
+		@param name The name of the parameter
+		@param val Pointer to the values to write
+		@param count The number of 'multiples' of floats to write
+		@param multiple The number of raw entries in each element to write, 
+		the default is 4 so count = 1 would write 4 floats.
+		*/
+		void setNamedConstant(const String& name, const double *val, size_t count, 
+			size_t multiple = 4);
+		/** Sets a ColourValue parameter to the program.
+		@param name The name of the parameter
+		@param colour The value to set
+		*/
+		void setNamedConstant(const String& name, const ColourValue& colour);
+
+		/** Sets a multiple value constant floating-point parameter to the program.
+		@par
+		Some systems only allow constants to be set on certain boundaries, 
+		e.g. in sets of 4 values for example. The 'multiple' parameter allows
+		you to control that although you should only change it if you know
+		your chosen language supports that (at the time of writing, only
+		GLSL allows constants which are not a multiple of 4).
+		@note
+		This named option will only work if you are using a parameters object created
+		from a high-level program (HighLevelGpuProgram).
+		@param name The name of the parameter
+		@param val Pointer to the values to write
+		@param count The number of 'multiples' of floats to write
+		@param multiple The number of raw entries in each element to write, 
+		the default is 4 so count = 1 would write 4 floats.
+		*/
+		void setNamedConstant(const String& name, const int *val, size_t count, 
+			size_t multiple = 4);
+
+		/** Sets up a constant which will automatically be updated by the system.
+		@remarks
+		Vertex and fragment programs often need parameters which are to do with the
+		current render state, or particular values which may very well change over time,
+		and often between objects which are being rendered. This feature allows you 
+		to set up a certain number of predefined parameter mappings that are kept up to 
+		date for you.
+		@note
+		This named option will only work if you are using a parameters object created
+		from a high-level program (HighLevelGpuProgram).
+		@param name The name of the parameter
+		@param acType The type of automatic constant to set
+		@param extraInfo If the constant type needs more information (like a light index) put it here.
+		*/
+		void setNamedAutoConstant(const String& name, AutoConstantType acType, size_t extraInfo = 0);
+		void setNamedAutoConstantReal(const String& name, AutoConstantType acType, Real rData);
+
+		/** Sets up a constant which will automatically be updated by the system.
+		@remarks
+		Vertex and fragment programs often need parameters which are to do with the
+		current render state, or particular values which may very well change over time,
+		and often between objects which are being rendered. This feature allows you 
+		to set up a certain number of predefined parameter mappings that are kept up to 
+		date for you.
+		@note
+		This named option will only work if you are using a parameters object created
+		from a high-level program (HighLevelGpuProgram).
+		@param name The name of the parameter
+		@param acType The type of automatic constant to set
+		@param extraInfo1 The first extra info required by this auto constant type
+		@param extraInfo2 The first extra info required by this auto constant type
+		*/
+		void setNamedAutoConstant(const String& name, AutoConstantType acType, uint16 extraInfo1, uint16 extraInfo2);
+
+		/** Sets a named parameter up to track a derivation of the current time.
+		@note
+		This named option will only work if you are using a parameters object created
+		from a high-level program (HighLevelGpuProgram).
+		@param name The name of the parameter
+		@param factor The amount by which to scale the time value
+		*/  
+		void setNamedConstantFromTime(const String& name, Real factor);
+
+		/** Unbind an auto constant so that the constant is manually controlled again. */
+		void clearNamedAutoConstant(const String& name);
+
+		/** Find a constant definition for a named parameter.
+		@remarks
+		This method returns null if the named parameter did not exist, unlike
+		getConstantDefinition which is more strict; unless you set the 
+		last parameter to true.
+		@param name The name to look up
+		@param throwExceptionIfMissing If set to true, failure to find an entry
+		will throw an exception.
+		*/
+		const GpuConstantDefinition* _findNamedConstantDefinition(
+			const String& name, bool throwExceptionIfMissing = false) const;
+		/** Gets the physical buffer index associated with a logical float constant index. 
+		@note Only applicable to low-level programs.
+		@param logicalIndex The logical parameter index
+		@param requestedSize The requested size - pass 0 to ignore missing entries
+		and return std::numeric_limits<size_t>::max() 
+		*/
+		size_t _getFloatConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize, uint16 variability);
+		/** Gets the physical buffer index associated with a logical int constant index. 
+		@note Only applicable to low-level programs.
+		@param logicalIndex The logical parameter index
+		@param requestedSize The requested size - pass 0 to ignore missing entries
+		and return std::numeric_limits<size_t>::max() 
+		*/
+		size_t _getIntConstantPhysicalIndex(size_t logicalIndex, size_t requestedSize, uint16 variability);
+
+		/** Sets whether or not we need to transpose the matrices passed in from the rest of OGRE.
+		@remarks
+		D3D uses transposed matrices compared to GL and OGRE; this is not important when you
+		use programs which are written to process row-major matrices, such as those generated
+		by Cg, but if you use a program written to D3D's matrix layout you will need to enable
+		this flag.
+		*/
+		void setTransposeMatrices(bool val) { mTransposeMatrices = val; } 
+		/// Gets whether or not matrices are to be transposed when set
+		bool getTransposeMatrices(void) const { return mTransposeMatrices; } 
+
+		/** Copies the values of all constants (including auto constants) from another
+		GpuProgramParameters object.
+		@note This copes the internal storage of the paarameters object and therefore
+		can only be used for parameters objects created from the same GpuProgram.
+		To merge parameters that match from different programs, use copyMatchingNamedConstantsFrom.
+		*/
+		void copyConstantsFrom(const GpuProgramParameters& source);
+
+		/** Copies the values of all matching named constants (including auto constants) from 
+		another GpuProgramParameters object. 
+		@remarks
+		This method iterates over the named constants in another parameters object
+		and copies across the values where they match. This method is safe to
+		use when the 2 parameters objects came from different programs, but only
+		works for named parameters.
+		*/
+		void copyMatchingNamedConstantsFrom(const GpuProgramParameters& source);
+
+		/** gets the auto constant definition associated with name if found else returns NULL
+		@param name The name of the auto constant
+		*/
+		static const AutoConstantDefinition* getAutoConstantDefinition(const String& name);
+		/** gets the auto constant definition using an index into the auto constant definition array.
+		If the index is out of bounds then NULL is returned;
+		@param idx The auto constant index
+		*/
+		static const AutoConstantDefinition* getAutoConstantDefinition(const size_t idx);
+		/** Returns the number of auto constant definitions
+		*/
+		static size_t getNumAutoConstantDefinitions(void);
+
+
+		/** increments the multipass number entry by 1 if it exists
+		*/
+		void incPassIterationNumber(void);
+		/** Does this parameters object have a pass iteration number constant? */
+		bool hasPassIterationNumber() const 
+		{ return mActivePassIterationIndex != (std::numeric_limits<size_t>::max)(); }
+		/** Get the physical buffer index of the pass iteration number constant */
+		size_t getPassIterationNumberIndex() const 
+		{ return mActivePassIterationIndex; }
+
+
+		/** Use a set of shared parameters in this parameters object.
+		@remarks
+			Allows you to use a set of shared parameters to automatically update 
+			this parameter set.
+		*/
+		void addSharedParameters(GpuSharedParametersPtr sharedParams);
+
+		/** Use a set of shared parameters in this parameters object.
+		@remarks
+			Allows you to use a set of shared parameters to automatically update 
+			this parameter set.
+		@param sharedParamsName The name of a shared parameter set as defined in
+			GpuProgramManager
+		*/
+		void addSharedParameters(const String& sharedParamsName);
+
+		/** Returns whether this parameter set is using the named shared parameter set. */
+		bool isUsingSharedParameters(const String& sharedParamsName) const;
+
+		/** Stop using the named shared parameter set. */
+		void removeSharedParameters(const String& sharedParamsName);
+
+		/** Stop using all shared parameter sets. */
+		void removeAllSharedParameters();
+
+		/** Get the list of shared parameter sets. */
+		const GpuSharedParamUsageList& getSharedParameters() const;
+
+		// TODO PORT - Commented out for the same reason as mRenderSystemData (see above)
+		///** Internal method that the RenderSystem might use to store optional data. */
+		//void _setRenderSystemData(const Any& data) const { mRenderSystemData = data; }
+		///** Internal method that the RenderSystem might use to store optional data. */
+		//const Any& _getRenderSystemData() const { return mRenderSystemData; }
+
+		/** Update the parameters by copying the data from the shared
+		parameters.
+		@note This method  may not actually be called if the RenderSystem
+		supports using shared parameters directly in their own shared buffer; in
+		which case the values should not be copied out of the shared area
+		into the individual parameter set, but bound separately.
+		*/
+		void _copySharedParams();
+
+
+
+	};
+
+	/// Shared pointer used to hold references to GpuProgramParameters instances
+	typedef SharedPtr<GpuProgramParameters> GpuProgramParametersSharedPtr;
+
+	/** @} */
+	/** @} */
+}
+#endif
+

+ 93 - 0
CamelotRenderer/OgreRenderOperation.h

@@ -0,0 +1,93 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+    (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2011 Torus Knot Software Ltd
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+-----------------------------------------------------------------------------
+*/
+#ifndef _RenderOperation_H__
+#define _RenderOperation_H__
+
+#include "OgrePrerequisites.h"
+#include "OgreVertexIndexData.h"
+
+namespace Ogre {
+
+
+	/** \addtogroup Core
+	*  @{
+	*/
+	/** \addtogroup RenderSystem
+	*  @{
+	*/
+	/** 'New' rendering operation using vertex buffers. */
+	class _OgrePrivate RenderOperation {
+	public:
+		/// The rendering operation type to perform
+		enum OperationType {
+			/// A list of points, 1 vertex per point
+            OT_POINT_LIST = 1,
+			/// A list of lines, 2 vertices per line
+            OT_LINE_LIST = 2,
+			/// A strip of connected lines, 1 vertex per line plus 1 start vertex
+            OT_LINE_STRIP = 3,
+			/// A list of triangles, 3 vertices per triangle
+            OT_TRIANGLE_LIST = 4,
+			/// A strip of triangles, 3 vertices for the first triangle, and 1 per triangle after that 
+            OT_TRIANGLE_STRIP = 5,
+			/// A fan of triangles, 3 vertices for the first triangle, and 1 per triangle after that
+            OT_TRIANGLE_FAN = 6
+        };
+
+		/// Vertex source data
+		VertexData *vertexData;
+
+		/// The type of operation to perform
+		OperationType operationType;
+
+		/** Specifies whether to use indexes to determine the vertices to use as input. If false, the vertices are
+		 simply read in sequence to define the primitives. If true, indexes are used instead to identify vertices
+		 anywhere in the buffer, and allowing vertices to be used more than once.
+	   	 If true, then the indexBuffer, indexStart and numIndexes properties must be valid. */
+		bool useIndexes;
+
+		/// Index data - only valid if useIndexes is true
+		IndexData *indexData;
+		/// Debug pointer back to renderable which created this
+		const Renderable* srcRenderable;
+
+
+
+        RenderOperation() :
+            vertexData(0), operationType(OT_TRIANGLE_LIST), useIndexes(true),
+                indexData(0), srcRenderable(0) {}
+
+
+	};
+	/** @} */
+	/** @} */
+}
+
+
+
+#endif

+ 83 - 0
CamelotRenderer/OgreStringInterface.cpp

@@ -0,0 +1,83 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+    (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2011 Torus Knot Software Ltd
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+-----------------------------------------------------------------------------
+*/
+
+#include "OgreStringInterface.h"
+
+namespace Ogre {
+	OGRE_STATIC_MUTEX_INSTANCE( StringInterface::msDictionaryMutex )
+    ParamDictionaryMap StringInterface::msDictionary;
+
+
+    const ParameterList& StringInterface::getParameters(void) const
+    {
+        static ParameterList emptyList;
+
+        const ParamDictionary* dict = getParamDictionary();
+        if (dict)
+            return dict->getParameters();
+        else
+            return emptyList;
+
+    }
+
+    bool StringInterface::setParameter(const String& name, const String& value)
+    {
+        // Get dictionary
+        ParamDictionary* dict = getParamDictionary();
+
+        if (dict)
+        {
+            // Look up command object
+            ParamCommand* cmd = dict->getParamCommand(name);
+            if (cmd)
+            {
+                cmd->doSet(this, value);
+                return true;
+            }
+        }
+        // Fallback
+        return false;
+    }
+	//-----------------------------------------------------------------------
+	void StringInterface::setParameterList(const NameValuePairList& paramList)
+	{
+		NameValuePairList::const_iterator i, iend;
+		iend = paramList.end();
+		for (i = paramList.begin(); i != iend; ++i)
+		{
+			setParameter(i->first, i->second);
+		}
+	}
+    //-----------------------------------------------------------------------
+	void StringInterface::cleanupDictionary ()
+	{
+		OGRE_LOCK_MUTEX( msDictionaryMutex )
+
+		msDictionary.clear();
+	}
+}

+ 335 - 0
CamelotRenderer/OgreStringInterface.h

@@ -0,0 +1,335 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+    (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2011 Torus Knot Software Ltd
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+-----------------------------------------------------------------------------
+*/
+
+#ifndef __StringInterface_H__
+#define __StringInterface_H__
+
+#include "OgrePrerequisites.h"
+#include "OgreString.h"
+#include "OgreCommon.h"
+
+namespace Ogre {
+
+	/** \addtogroup Core
+	*  @{
+	*/
+	/** \addtogroup General
+	*  @{
+	*/
+
+    /// List of parameter types available
+    enum ParameterType
+    {
+        PT_BOOL,
+        PT_REAL,
+        PT_INT,
+        PT_UNSIGNED_INT,
+        PT_SHORT,
+        PT_UNSIGNED_SHORT,
+        PT_LONG,
+        PT_UNSIGNED_LONG,
+        PT_STRING,
+        PT_VECTOR3,
+        PT_MATRIX3,
+        PT_MATRIX4,
+        PT_QUATERNION,
+        PT_COLOURVALUE
+    };
+
+    /// Definition of a parameter supported by a StringInterface class, for introspection
+    class _OgreExport ParameterDef
+    {
+    public:
+        String name;
+        String description;
+        ParameterType paramType;
+        ParameterDef(const String& newName, const String& newDescription, ParameterType newType)
+            : name(newName), description(newDescription), paramType(newType) {}
+    };
+    typedef vector<ParameterDef>::type ParameterList;
+
+    /** Abstract class which is command object which gets/sets parameters.*/
+    class _OgreExport ParamCommand
+    {
+    public:
+        virtual String doGet(const void* target) const = 0;
+        virtual void doSet(void* target, const String& val) = 0;
+
+        virtual ~ParamCommand() { }
+    };
+    typedef map<String, ParamCommand* >::type ParamCommandMap;
+
+    /** Class to hold a dictionary of parameters for a single class. */
+    class _OgreExport ParamDictionary
+    {
+        friend class StringInterface;
+    protected:
+        /// Definitions of parameters
+        ParameterList mParamDefs;
+
+        /// Command objects to get/set
+        ParamCommandMap mParamCommands;
+
+        /** Retrieves the parameter command object for a named parameter. */
+        ParamCommand* getParamCommand(const String& name)
+        {
+            ParamCommandMap::iterator i = mParamCommands.find(name);
+            if (i != mParamCommands.end())
+            {
+                return i->second;
+            }
+            else
+            {
+                return 0;
+            }
+        }
+
+		const ParamCommand* getParamCommand(const String& name) const
+        {
+            ParamCommandMap::const_iterator i = mParamCommands.find(name);
+            if (i != mParamCommands.end())
+            {
+                return i->second;
+            }
+            else
+            {
+                return 0;
+            }
+        }
+    public:
+        ParamDictionary()  {}
+        /** Method for adding a parameter definition for this class. 
+        @param paramDef A ParameterDef object defining the parameter
+        @param paramCmd Pointer to a ParamCommand subclass to handle the getting / setting of this parameter.
+            NB this class will not destroy this on shutdown, please ensure you do
+
+        */
+        void addParameter(const ParameterDef& paramDef, ParamCommand* paramCmd)
+        {
+            mParamDefs.push_back(paramDef);
+            mParamCommands[paramDef.name] = paramCmd;
+        }
+        /** Retrieves a list of parameters valid for this object. 
+        @returns
+            A reference to a static list of ParameterDef objects.
+
+        */
+        const ParameterList& getParameters(void) const
+        {
+            return mParamDefs;
+        }
+
+
+
+    };
+    typedef map<String, ParamDictionary>::type ParamDictionaryMap;
+    
+    /** Class defining the common interface which classes can use to 
+        present a reflection-style, self-defining parameter set to callers.
+    @remarks
+        This class also holds a static map of class name to parameter dictionaries
+        for each subclass to use. See ParamDictionary for details. 
+    @remarks
+        In order to use this class, each subclass must call createParamDictionary in their constructors
+        which will create a parameter dictionary for the class if it does not exist yet.
+    */
+    class _OgreExport StringInterface 
+    {
+    private:
+		OGRE_STATIC_MUTEX( msDictionaryMutex )
+
+        /// Dictionary of parameters
+        static ParamDictionaryMap msDictionary;
+
+        /// Class name for this instance to be used as a lookup (must be initialised by subclasses)
+        String mParamDictName;
+		ParamDictionary* mParamDict;
+
+	protected:
+        /** Internal method for creating a parameter dictionary for the class, if it does not already exist.
+        @remarks
+            This method will check to see if a parameter dictionary exist for this class yet,
+            and if not will create one. NB you must supply the name of the class (RTTI is not 
+            used or performance).
+        @param
+            className the name of the class using the dictionary
+        @returns
+            true if a new dictionary was created, false if it was already there
+        */
+        bool createParamDictionary(const String& className)
+        {
+			OGRE_LOCK_MUTEX( msDictionaryMutex )
+
+			ParamDictionaryMap::iterator it = msDictionary.find(className);
+
+			if ( it == msDictionary.end() )
+			{
+				mParamDict = &msDictionary.insert( std::make_pair( className, ParamDictionary() ) ).first->second;
+				mParamDictName = className;
+				return true;
+			}
+			else
+			{
+				mParamDict = &it->second;
+				mParamDictName = className;
+				return false;
+			}
+        }
+
+    public:
+		StringInterface() : mParamDict(NULL) { }
+
+        /** Virtual destructor, see Effective C++ */
+        virtual ~StringInterface() {}
+
+        /** Retrieves the parameter dictionary for this class. 
+        @remarks
+            Only valid to call this after createParamDictionary.
+        @returns
+            Pointer to ParamDictionary shared by all instances of this class
+            which you can add parameters to, retrieve parameters etc.
+        */
+        ParamDictionary* getParamDictionary(void)
+        {
+			return mParamDict;
+        }
+
+		const ParamDictionary* getParamDictionary(void) const
+        {
+			return mParamDict;
+        }
+
+        /** Retrieves a list of parameters valid for this object. 
+        @returns
+            A reference to a static list of ParameterDef objects.
+
+        */
+        const ParameterList& getParameters(void) const;
+
+        /** Generic parameter setting method.
+        @remarks
+            Call this method with the name of a parameter and a string version of the value
+            to set. The implementor will convert the string to a native type internally.
+            If in doubt, check the parameter definition in the list returned from 
+            StringInterface::getParameters.
+        @param
+            name The name of the parameter to set
+        @param
+            value String value. Must be in the right format for the type specified in the parameter definition.
+            See the StringConverter class for more information.
+        @returns
+            true if set was successful, false otherwise (NB no exceptions thrown - tolerant method)
+        */
+        virtual bool setParameter(const String& name, const String& value);
+        /** Generic multiple parameter setting method.
+        @remarks
+            Call this method with a list of name / value pairs
+            to set. The implementor will convert the string to a native type internally.
+            If in doubt, check the parameter definition in the list returned from 
+            StringInterface::getParameters.
+        @param
+            paramList Name/value pair list
+        */
+        virtual void setParameterList(const NameValuePairList& paramList);
+        /** Generic parameter retrieval method.
+        @remarks
+            Call this method with the name of a parameter to retrieve a string-format value of
+            the parameter in question. If in doubt, check the parameter definition in the
+            list returned from getParameters for the type of this parameter. If you
+            like you can use StringConverter to convert this string back into a native type.
+        @param
+            name The name of the parameter to get
+        @returns
+            String value of parameter, blank if not found
+        */
+        virtual String getParameter(const String& name) const
+        {
+            // Get dictionary
+            const ParamDictionary* dict = getParamDictionary();
+
+            if (dict)
+            {
+                // Look up command object
+                const ParamCommand* cmd = dict->getParamCommand(name);
+
+                if (cmd)
+                {
+                    return cmd->doGet(this);
+                }
+            }
+
+            // Fallback
+            return "";
+        }
+        /** Method for copying this object's parameters to another object.
+        @remarks
+            This method takes the values of all the object's parameters and tries to set the
+            same values on the destination object. This provides a completely type independent
+            way to copy parameters to other objects. Note that because of the String manipulation 
+            involved, this should not be regarded as an efficient process and should be saved for
+            times outside of the rendering loop.
+        @par
+            Any unrecognised parameters will be ignored as with setParameter method.
+        @param dest Pointer to object to have it's parameters set the same as this object.
+
+        */
+        virtual void copyParametersTo(StringInterface* dest) const
+        {
+            // Get dictionary
+            const ParamDictionary* dict = getParamDictionary();
+
+            if (dict)
+            {
+                // Iterate through own parameters
+                ParameterList::const_iterator i;
+            
+                for (i = dict->mParamDefs.begin(); 
+                i != dict->mParamDefs.end(); ++i)
+                {
+                    dest->setParameter(i->name, getParameter(i->name));
+                }
+            }
+
+
+        }
+
+        /** Cleans up the static 'msDictionary' required to reset Ogre,
+        otherwise the containers are left with invalid pointers, which will lead to a crash
+        as soon as one of the ResourceManager implementers (e.g. MaterialManager) initializes.*/
+        static void cleanupDictionary () ;
+
+    };
+
+	/** @} */
+	/** @} */
+
+
+}
+
+#endif
+