2
0
Эх сурвалжийг харах

Ability to set textures in gpu params

Marko Pintera 13 жил өмнө
parent
commit
339335ef7f

+ 2 - 2
CamelotClient/CamelotClient.cpp

@@ -13,8 +13,8 @@ using namespace CamelotEngine;
 
 
 int _tmain(int argc, _TCHAR* argv[])
 int _tmain(int argc, _TCHAR* argv[])
 {
 {
-	//gApplication().startUp("CamelotGLRenderer.dll");
-	gApplication().startUp("CamelotD3D9Renderer.dll");
+	//gApplication().startUp("CamelotGLRenderer");
+	gApplication().startUp("CamelotD3D9Renderer");
 
 
 	//RTTITypeBase* st = DbgSrlzTest::getRTTIStatic();
 	//RTTITypeBase* st = DbgSrlzTest::getRTTIStatic();
 
 

+ 28 - 14
CamelotD3D9Renderer/Source/CmD3D9HLSLProgram.cpp

@@ -328,25 +328,39 @@ namespace CamelotEngine {
 				def.logicalIndex = paramIndex;
 				def.logicalIndex = paramIndex;
 				// populate type, array size & element size
 				// populate type, array size & element size
 				populateDef(desc, def);
 				populateDef(desc, def);
-				if (def.isFloat())
+
+				if(def.isSampler())
 				{
 				{
-					def.physicalIndex = mFloatLogicalToPhysical->bufferSize;
-					CM_LOCK_MUTEX(mFloatLogicalToPhysical->mutex)
-					mFloatLogicalToPhysical->map.insert(
+					def.physicalIndex = mSamplerLogicalToPhysical->bufferSize;
+					CM_LOCK_MUTEX(mSamplerLogicalToPhysical->mutex)
+						mSamplerLogicalToPhysical->map.insert(
 						GpuLogicalIndexUseMap::value_type(paramIndex, 
 						GpuLogicalIndexUseMap::value_type(paramIndex, 
-						GpuLogicalIndexUse(def.physicalIndex, def.arraySize * def.elementSize, GPV_GLOBAL)));
-					mFloatLogicalToPhysical->bufferSize += def.arraySize * def.elementSize;
-					mConstantDefs->floatBufferSize = mFloatLogicalToPhysical->bufferSize;
+						GpuLogicalIndexUse(def.physicalIndex, def.arraySize, GPV_GLOBAL)));
+					mSamplerLogicalToPhysical->bufferSize += def.arraySize;
+					mConstantDefs->samplerCount = mSamplerLogicalToPhysical->bufferSize;
 				}
 				}
 				else
 				else
 				{
 				{
-					def.physicalIndex = mIntLogicalToPhysical->bufferSize;
-					CM_LOCK_MUTEX(mIntLogicalToPhysical->mutex)
-					mIntLogicalToPhysical->map.insert(
-						GpuLogicalIndexUseMap::value_type(paramIndex, 
-						GpuLogicalIndexUse(def.physicalIndex, def.arraySize * def.elementSize, GPV_GLOBAL)));
-					mIntLogicalToPhysical->bufferSize += def.arraySize * def.elementSize;
-					mConstantDefs->intBufferSize = mIntLogicalToPhysical->bufferSize;
+					if (def.isFloat())
+					{
+						def.physicalIndex = mFloatLogicalToPhysical->bufferSize;
+						CM_LOCK_MUTEX(mFloatLogicalToPhysical->mutex)
+							mFloatLogicalToPhysical->map.insert(
+							GpuLogicalIndexUseMap::value_type(paramIndex, 
+							GpuLogicalIndexUse(def.physicalIndex, def.arraySize * def.elementSize, GPV_GLOBAL)));
+						mFloatLogicalToPhysical->bufferSize += def.arraySize * def.elementSize;
+						mConstantDefs->floatBufferSize = mFloatLogicalToPhysical->bufferSize;
+					}
+					else
+					{
+						def.physicalIndex = mIntLogicalToPhysical->bufferSize;
+						CM_LOCK_MUTEX(mIntLogicalToPhysical->mutex)
+							mIntLogicalToPhysical->map.insert(
+							GpuLogicalIndexUseMap::value_type(paramIndex, 
+							GpuLogicalIndexUse(def.physicalIndex, def.arraySize * def.elementSize, GPV_GLOBAL)));
+						mIntLogicalToPhysical->bufferSize += def.arraySize * def.elementSize;
+						mConstantDefs->intBufferSize = mIntLogicalToPhysical->bufferSize;
+					}
 				}
 				}
 
 
                 mConstantDefs->map.insert(GpuConstantDefinitionMap::value_type(name, def));
                 mConstantDefs->map.insert(GpuConstantDefinitionMap::value_type(name, def));

+ 21 - 8
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -2757,16 +2757,29 @@ namespace CamelotEngine
 			return;
 			return;
 		}
 		}
 		
 		
-		if (variability & (UINT16)GPV_GLOBAL)
-		{
-			// D3D9 doesn't support shared constant buffers, so use copy routine
-			params->_copySharedParams();
-		}
-
 		HRESULT hr;
 		HRESULT hr;
 		GpuLogicalBufferStructPtr floatLogical = params->getFloatLogicalBufferStruct();
 		GpuLogicalBufferStructPtr floatLogical = params->getFloatLogicalBufferStruct();
 		GpuLogicalBufferStructPtr intLogical = params->getIntLogicalBufferStruct();
 		GpuLogicalBufferStructPtr intLogical = params->getIntLogicalBufferStruct();
 
 
+		GpuLogicalBufferStructPtr samplerLogical = params->getSamplerLogicalBufferStruct();
+
+		// Set texture sampler
+		{
+			CM_LOCK_MUTEX(samplerLogical->mutex)
+
+			for (GpuLogicalIndexUseMap::const_iterator i = samplerLogical->map.begin();
+				i != samplerLogical->map.end(); ++i)
+			{
+				if (i->second.variability & variability)
+				{
+					size_t logicalIndex = i->first;
+					TexturePtr texture = params->getTexture(i->second.physicalIndex);
+
+					_setTexture(logicalIndex, true, texture);
+				}
+			}
+		}
+
 		switch(gptype)
 		switch(gptype)
 		{
 		{
 		case GPT_VERTEX_PROGRAM:
 		case GPT_VERTEX_PROGRAM:
@@ -2785,8 +2798,8 @@ namespace CamelotEngine
 							assert (i->second.currentSize % 4 == 0 && "Should not have any "
 							assert (i->second.currentSize % 4 == 0 && "Should not have any "
 								"elements less than 4 wide for D3D9");
 								"elements less than 4 wide for D3D9");
 
 
-						if (FAILED(hr = getActiveD3D9Device()->SetVertexShaderConstantF(
-							(UINT)logicalIndex, pFloat, (UINT)slotCount)))
+						if (FAILED(hr = getActiveD3D9Device()->SetVertexShaderConstantF( // TODO Low priority. Binding parameters 1 by 1 is slow. It would be better to keep them in a sequential
+							(UINT)logicalIndex, pFloat, (UINT)slotCount)))               // buffer and then only call this method once
 							{
 							{
 								CM_EXCEPT(RenderingAPIException, "Unable to upload vertex shader float parameters");
 								CM_EXCEPT(RenderingAPIException, "Unable to upload vertex shader float parameters");
 							}
 							}

+ 14 - 5
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -2518,12 +2518,21 @@ namespace CamelotEngine {
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
 	void GLRenderSystem::bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, UINT16 mask)
 	void GLRenderSystem::bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, UINT16 mask)
 	{
 	{
-		if (mask & (UINT16)GPV_GLOBAL)
+		// Set textures
+		const GpuNamedConstants& consts = params->getConstantDefinitions();
+		for(auto iter = consts.map.begin(); iter != consts.map.end(); ++iter)
 		{
 		{
-			// We could maybe use GL_EXT_bindable_uniform here to produce Dx10-style
-			// shared constant buffers, but GPU support seems fairly weak?
-			// for now, just copy
-			params->_copySharedParams();
+			const GpuConstantDefinition& def = iter->second;
+
+			if(def.variability & mask)
+			{
+				if(def.constType == GCT_SAMPLER2D || def.constType == GCT_SAMPLERCUBE || def.constType == GCT_SAMPLER1D 
+					|| def.constType == GCT_SAMPLER2DSHADOW || def.constType == GCT_SAMPLER3D || def.constType == GCT_SAMPLER1DSHADOW)
+				{
+					TexturePtr curTexture = params->getTexture(def.physicalIndex);
+					_setTexture(def.physicalIndex, true, curTexture);
+				}
+			}
 		}
 		}
 
 
 		switch (gptype)
 		switch (gptype)

+ 2 - 2
CamelotGLRenderer/Source/GLSL/src/CmGLSLLinkProgram.cpp

@@ -415,8 +415,8 @@ namespace CamelotEngine {
 					case GCT_SAMPLER3D:
 					case GCT_SAMPLER3D:
 					case GCT_SAMPLERCUBE:
 					case GCT_SAMPLERCUBE:
 						// samplers handled like 1-element ints
 						// samplers handled like 1-element ints
-						glUniform1ivARB(currentUniform->mLocation, 1, 
-							(GLint*)params->getIntPointer(def->physicalIndex));
+						glUniform1iARB(currentUniform->mLocation, def->physicalIndex);
+						
 						break;
 						break;
                     case GCT_UNKNOWN:
                     case GCT_UNKNOWN:
                         break;
                         break;

+ 16 - 8
CamelotGLRenderer/Source/GLSL/src/CmGLSLLinkProgramManager.cpp

@@ -478,18 +478,26 @@ namespace CamelotEngine {
 							break;
 							break;
 						}
 						}
 
 
-						// Complete def and add
-						// increment physical buffer location
-						def.logicalIndex = 0; // not valid in GLSL
-						if (def.isFloat())
+						if(def.isSampler())
 						{
 						{
-							def.physicalIndex = defs.floatBufferSize;
-							defs.floatBufferSize += def.arraySize * def.elementSize;
+							def.physicalIndex = defs.samplerCount;
+							defs.samplerCount++;
 						}
 						}
 						else
 						else
 						{
 						{
-							def.physicalIndex = defs.intBufferSize;
-							defs.intBufferSize += def.arraySize * def.elementSize;
+							// Complete def and add
+							// increment physical buffer location
+							def.logicalIndex = 0; // not valid in GLSL
+							if (def.isFloat())
+							{
+								def.physicalIndex = defs.floatBufferSize;
+								defs.floatBufferSize += def.arraySize * def.elementSize;
+							}
+							else
+							{
+								def.physicalIndex = defs.intBufferSize;
+								defs.intBufferSize += def.arraySize * def.elementSize;
+							}
 						}
 						}
 						defs.map.insert(GpuConstantDefinitionMap::value_type(paramName, def));
 						defs.map.insert(GpuConstantDefinitionMap::value_type(paramName, def));
 
 

+ 5 - 0
CamelotRenderer/Include/CmGpuProgram.h

@@ -88,6 +88,11 @@ namespace CamelotEngine {
 			This is a shared pointer because if the program is recompiled and the parameters
 			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.*/
 			change, this definition will alter, but previous params may reference the old def.*/
 		mutable GpuLogicalBufferStructPtr mIntLogicalToPhysical;
 		mutable GpuLogicalBufferStructPtr mIntLogicalToPhysical;
+		/** 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 mSamplerLogicalToPhysical;
 		/** Parameter name -> ConstantDefinition map, shared instance used by all parameter objects.
 		/** 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
 		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.
 		change, this definition will alter, but previous params may reference the old def.

+ 0 - 21
CamelotRenderer/Include/CmGpuProgramManager.h

@@ -47,13 +47,8 @@ namespace CamelotEngine {
 	public:
 	public:
 
 
 		typedef set<String>::type SyntaxCodes;
 		typedef set<String>::type SyntaxCodes;
-		typedef map<String, GpuSharedParametersPtr>::type SharedParametersMap;
-
 
 
 	protected:
 	protected:
-
-		SharedParametersMap mSharedParametersMap;
-
 		/** General create method
 		/** General create method
         */
         */
         virtual GpuProgram* create(GpuProgramType gptype, const String& syntaxCode) = 0;
         virtual GpuProgram* create(GpuProgramType gptype, const String& syntaxCode) = 0;
@@ -113,22 +108,6 @@ namespace CamelotEngine {
 		*/
 		*/
 		virtual GpuProgramPtr createProgram(const String& code, 
 		virtual GpuProgramPtr createProgram(const String& code, 
             GpuProgramType gptype, const String& syntaxCode);
             GpuProgramType gptype, const String& syntaxCode);
-
-		/** Create a new set of shared parameters, which can be used across many 
-			GpuProgramParameters objects of different structures.
-		@param name The name to give the shared parameters so you can refer to them
-			later.
-		*/
-		virtual GpuSharedParametersPtr createSharedParameters(const String& name);
-
-		/** Retrieve a set of shared parameters, which can be used across many 
-		GpuProgramParameters objects of different structures.
-		*/
-		virtual GpuSharedParametersPtr getSharedParameters(const String& name) const;
-
-		/** Get (const) access to the available shared parameter sets. 
-		*/
-		virtual const SharedParametersMap& getAvailableSharedParameters() const;
 	};
 	};
 
 
 	/** @} */
 	/** @} */

+ 38 - 220
CamelotRenderer/Include/CmGpuProgramParams.h

@@ -263,10 +263,12 @@ namespace CamelotEngine {
 		size_t floatBufferSize;
 		size_t floatBufferSize;
 		/// Total size of the int buffer required
 		/// Total size of the int buffer required
 		size_t intBufferSize;
 		size_t intBufferSize;
+		/// Total number of samplers referenced
+		size_t samplerCount;
 		/// Map of parameter names to GpuConstantDefinition
 		/// Map of parameter names to GpuConstantDefinition
 		GpuConstantDefinitionMap map;
 		GpuConstantDefinitionMap map;
 
 
-		GpuNamedConstants() : floatBufferSize(0), intBufferSize(0) {}
+		GpuNamedConstants() : floatBufferSize(0), intBufferSize(0), samplerCount(0) {}
 
 
 		/** Generate additional constant entries for arrays based on a base definition.
 		/** Generate additional constant entries for arrays based on a base definition.
 		@remarks
 		@remarks
@@ -344,168 +346,11 @@ namespace CamelotEngine {
 	to physical index map is derived from GpuProgram
 	to physical index map is derived from GpuProgram
 	*/
 	*/
 	typedef vector<int>::type IntConstantList;
 	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 CM_EXPORT GpuSharedParameters
-	{
-	protected:
-		GpuNamedConstants mNamedConstants;
-		FloatConstantList mFloatConstants;
-		IntConstantList mIntConstants;
-		String mName;
-
-		/// 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, float 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 Color& 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]; }
-	};
-
-	/// Shared pointer used to hold references to GpuProgramParameters instances
-	typedef std::shared_ptr<GpuSharedParameters> GpuSharedParametersPtr;
-
-	class GpuProgramParameters;
-
-	/** This class records the usage of a set of shared parameters in a concrete
-		set of GpuProgramParameters.
+	/** 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
 	*/
 	*/
-	class CM_EXPORT 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;
-
-		/// 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; }
-	};
+	typedef vector<TexturePtr>::type TextureList;
 
 
 	/** Collects together the program parameters used for a GpuProgram.
 	/** Collects together the program parameters used for a GpuProgram.
 	@remarks
 	@remarks
@@ -559,19 +404,22 @@ namespace CamelotEngine {
 			ET_REAL
 			ET_REAL
 		};
 		};
 
 
-		typedef vector<GpuSharedParametersUsage>::type GpuSharedParamUsageList;
-
 	protected:
 	protected:
 		/// Packed list of floating-point constants (physical indexing)
 		/// Packed list of floating-point constants (physical indexing)
 		FloatConstantList mFloatConstants;
 		FloatConstantList mFloatConstants;
 		/// Packed list of integer constants (physical indexing)
 		/// Packed list of integer constants (physical indexing)
 		IntConstantList mIntConstants;
 		IntConstantList mIntConstants;
+		/// List of all texture parameters
+		TextureList mTextures;
 		/** Logical index to physical index map - for low-level programs
 		/** Logical index to physical index map - for low-level programs
 		or high-level programs which pass params this way. */
 		or high-level programs which pass params this way. */
 		GpuLogicalBufferStructPtr mFloatLogicalToPhysical;
 		GpuLogicalBufferStructPtr mFloatLogicalToPhysical;
 		/** Logical index to physical index map - for low-level programs
 		/** Logical index to physical index map - for low-level programs
 		or high-level programs which pass params this way. */
 		or high-level programs which pass params this way. */
 		GpuLogicalBufferStructPtr mIntLogicalToPhysical;
 		GpuLogicalBufferStructPtr mIntLogicalToPhysical;
+		/** Logical index to physical index map - for low-level programs
+		or high-level programs which pass params this way. */
+		GpuLogicalBufferStructPtr mSamplerLogicalToPhysical;
 		/// Mapping from parameter names to def - high-level programs are expected to populate this
 		/// Mapping from parameter names to def - high-level programs are expected to populate this
 		GpuNamedConstantsPtr mNamedConstants;
 		GpuNamedConstantsPtr mNamedConstants;
 		/// The combined variability masks of all parameters
 		/// The combined variability masks of all parameters
@@ -590,10 +438,6 @@ namespace CamelotEngine {
 		*/
 		*/
 		GpuLogicalIndexUse* _getIntConstantLogicalIndexUse(size_t logicalIndex, size_t requestedSize, UINT16 variability);
 		GpuLogicalIndexUse* _getIntConstantLogicalIndexUse(size_t logicalIndex, size_t requestedSize, UINT16 variability);
 
 
-		void copySharedParamSetUsage(const GpuSharedParamUsageList& srcList);
-
-		GpuSharedParamUsageList mSharedParamSets;
-
 	public:
 	public:
 		GpuProgramParameters();
 		GpuProgramParameters();
 		~GpuProgramParameters() {}
 		~GpuProgramParameters() {}
@@ -608,7 +452,7 @@ namespace CamelotEngine {
 
 
 		/** Internal method for providing a link to a logical index->physical index map for parameters. */
 		/** Internal method for providing a link to a logical index->physical index map for parameters. */
 		void _setLogicalIndexes(const GpuLogicalBufferStructPtr& floatIndexMap, 
 		void _setLogicalIndexes(const GpuLogicalBufferStructPtr& floatIndexMap, 
-			const GpuLogicalBufferStructPtr&  intIndexMap);
+			const GpuLogicalBufferStructPtr&  intIndexMap, const GpuLogicalBufferStructPtr& samplerIndexMap);
 
 
 
 
 		/// Does this parameter set include named parameters?
 		/// Does this parameter set include named parameters?
@@ -853,11 +697,36 @@ namespace CamelotEngine {
 		int* getIntPointer(size_t pos) { return &mIntConstants[pos]; }
 		int* getIntPointer(size_t pos) { return &mIntConstants[pos]; }
 		/// Get a pointer to the 'nth' item in the int buffer
 		/// Get a pointer to the 'nth' item in the int buffer
 		const int* getIntPointer(size_t pos) const { return &mIntConstants[pos]; }
 		const int* getIntPointer(size_t pos) const { return &mIntConstants[pos]; }
+		const GpuLogicalBufferStructPtr& getSamplerLogicalBufferStruct() const { return mSamplerLogicalToPhysical; }
+		TexturePtr getTexture(size_t pos) const { return mTextures[pos];}
+		/// Get a reference to the list of textures
+		const TextureList& getTextureList() const { return mTextures; }
 
 
 		/** Tells the program whether to ignore missing parameters or not.
 		/** Tells the program whether to ignore missing parameters or not.
 		*/
 		*/
 		void setIgnoreMissingParams(bool state) { mIgnoreMissingParams = state; }
 		void setIgnoreMissingParams(bool state) { mIgnoreMissingParams = state; }
 
 
+		/** Sets a texture 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, TexturePtr val);
+
 		/** Sets a single value constant floating-point parameter to the program.
 		/** Sets a single value constant floating-point parameter to the program.
 		@remarks
 		@remarks
 		Different types of GPU programs support different types of constant parameters.
 		Different types of GPU programs support different types of constant parameters.
@@ -1035,16 +904,6 @@ namespace CamelotEngine {
 		*/
 		*/
 		void copyConstantsFrom(const GpuProgramParameters& source);
 		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);
-
 		/** increments the multipass number entry by 1 if it exists
 		/** increments the multipass number entry by 1 if it exists
 		*/
 		*/
 		void incPassIterationNumber(void);
 		void incPassIterationNumber(void);
@@ -1054,47 +913,6 @@ namespace CamelotEngine {
 		/** Get the physical buffer index of the pass iteration number constant */
 		/** Get the physical buffer index of the pass iteration number constant */
 		size_t getPassIterationNumberIndex() const 
 		size_t getPassIterationNumberIndex() const 
 		{ return mActivePassIterationIndex; }
 		{ 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;
-
-		/** 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
 	/// Shared pointer used to hold references to GpuProgramParameters instances

+ 4 - 4
CamelotRenderer/Source/CmApplication.cpp

@@ -56,10 +56,10 @@ namespace CamelotEngine
 		mCamera->setAspectRatio(800.0f / 600.0f);
 		mCamera->setAspectRatio(800.0f / 600.0f);
 
 
 		/////////////////// HLSL SHADERS //////////////////////////
 		/////////////////// HLSL SHADERS //////////////////////////
-		String fragShaderCode = "sampler2D diffuseMap;			\
+		String fragShaderCode = "sampler2D tex;			\
 								float4 ps_main(float2 uv : TEXCOORD0) : COLOR0		\
 								float4 ps_main(float2 uv : TEXCOORD0) : COLOR0		\
 								{														\
 								{														\
-								float4 color = tex2D(diffuseMap, uv);				\
+								float4 color = tex2D(tex, uv);				\
 								return color;										\
 								return color;										\
 								}";
 								}";
 
 
@@ -387,10 +387,10 @@ namespace CamelotEngine
 		renderSystem->_beginFrame();
 		renderSystem->_beginFrame();
 
 
 		mVertProg->getDefaultParameters()->setNamedConstant("matViewProjection", viewProjMatrix);
 		mVertProg->getDefaultParameters()->setNamedConstant("matViewProjection", viewProjMatrix);
-
+		mFragProg->getDefaultParameters()->setNamedConstant("tex", mDbgTexture);
 		//renderSystem->bindGpuProgramParameters(GPT_VERTEX_PROGRAM, mVertProg->getDefaultParameters(), GPV_ALL);
 		//renderSystem->bindGpuProgramParameters(GPT_VERTEX_PROGRAM, mVertProg->getDefaultParameters(), GPV_ALL);
 
 
-		renderSystem->_setTexture(0, true, mDbgTexture);
+		//renderSystem->_setTexture(0, true, mDbgTexture);
 
 
 		renderSystem->bindGpuProgram(mFragProg->_getBindingDelegate()); // TODO - I don't like this. Shader should be able to be bound directly!
 		renderSystem->bindGpuProgram(mFragProg->_getBindingDelegate()); // TODO - I don't like this. Shader should be able to be bound directly!
 		renderSystem->bindGpuProgram(mVertProg->_getBindingDelegate()); // TODO - I don't like this. Shader should be able to be bound directly!
 		renderSystem->bindGpuProgram(mVertProg->_getBindingDelegate()); // TODO - I don't like this. Shader should be able to be bound directly!

+ 33 - 15
CamelotRenderer/Source/CmCgProgram.cpp

@@ -294,38 +294,56 @@ namespace CamelotEngine {
 					else
 					else
 					{
 					{
 						// base position on existing buffer contents
 						// base position on existing buffer contents
-						if (def.isFloat())
+						if(def.isSampler())
 						{
 						{
-							def.physicalIndex = mFloatLogicalToPhysical->bufferSize;
+							def.physicalIndex = mSamplerLogicalToPhysical->bufferSize;
 						}
 						}
 						else
 						else
 						{
 						{
-							def.physicalIndex = mIntLogicalToPhysical->bufferSize;
+							if (def.isFloat())
+							{
+								def.physicalIndex = mFloatLogicalToPhysical->bufferSize;
+							}
+							else
+							{
+								def.physicalIndex = mIntLogicalToPhysical->bufferSize;
+							}
 						}
 						}
 					}
 					}
 
 
-
 					def.logicalIndex = logicalIndex;
 					def.logicalIndex = logicalIndex;
 					mConstantDefs->map.insert(GpuConstantDefinitionMap::value_type(paramName, def));
 					mConstantDefs->map.insert(GpuConstantDefinitionMap::value_type(paramName, def));
 
 
 					// Record logical / physical mapping
 					// Record logical / physical mapping
-					if (def.isFloat())
+					if(def.isSampler())
 					{
 					{
-						CM_LOCK_MUTEX(mFloatLogicalToPhysical->mutex)
-						mFloatLogicalToPhysical->map.insert(
+						CM_LOCK_MUTEX(mSamplerLogicalToPhysical->mutex)
+							mSamplerLogicalToPhysical->map.insert(
 							GpuLogicalIndexUseMap::value_type(logicalIndex, 
 							GpuLogicalIndexUseMap::value_type(logicalIndex, 
-								GpuLogicalIndexUse(def.physicalIndex, def.arraySize * def.elementSize, GPV_GLOBAL)));
-						mFloatLogicalToPhysical->bufferSize += def.arraySize * def.elementSize;
-						mConstantDefs->floatBufferSize = mFloatLogicalToPhysical->bufferSize;
+							GpuLogicalIndexUse(def.physicalIndex, def.arraySize, GPV_GLOBAL)));
+						mSamplerLogicalToPhysical->bufferSize += def.arraySize;
+						mConstantDefs->samplerCount = mSamplerLogicalToPhysical->bufferSize;
 					}
 					}
 					else
 					else
 					{
 					{
-						CM_LOCK_MUTEX(mIntLogicalToPhysical->mutex)
-						mIntLogicalToPhysical->map.insert(
-							GpuLogicalIndexUseMap::value_type(logicalIndex, 
+						if (def.isFloat())
+						{
+							CM_LOCK_MUTEX(mFloatLogicalToPhysical->mutex)
+								mFloatLogicalToPhysical->map.insert(
+								GpuLogicalIndexUseMap::value_type(logicalIndex, 
 								GpuLogicalIndexUse(def.physicalIndex, def.arraySize * def.elementSize, GPV_GLOBAL)));
 								GpuLogicalIndexUse(def.physicalIndex, def.arraySize * def.elementSize, GPV_GLOBAL)));
-						mIntLogicalToPhysical->bufferSize += def.arraySize * def.elementSize;
-						mConstantDefs->intBufferSize = mIntLogicalToPhysical->bufferSize;
+							mFloatLogicalToPhysical->bufferSize += def.arraySize * def.elementSize;
+							mConstantDefs->floatBufferSize = mFloatLogicalToPhysical->bufferSize;
+						}
+						else
+						{
+							CM_LOCK_MUTEX(mIntLogicalToPhysical->mutex)
+								mIntLogicalToPhysical->map.insert(
+								GpuLogicalIndexUseMap::value_type(logicalIndex, 
+								GpuLogicalIndexUse(def.physicalIndex, def.arraySize * def.elementSize, GPV_GLOBAL)));
+							mIntLogicalToPhysical->bufferSize += def.arraySize * def.elementSize;
+							mConstantDefs->intBufferSize = mIntLogicalToPhysical->bufferSize;
+						}
 					}
 					}
 
 
 					// Deal with array indexing
 					// Deal with array indexing

+ 3 - 1
CamelotRenderer/Source/CmGpuProgram.cpp

@@ -111,6 +111,8 @@ namespace CamelotEngine
 			mFloatLogicalToPhysical = GpuLogicalBufferStructPtr(new GpuLogicalBufferStruct());
 			mFloatLogicalToPhysical = GpuLogicalBufferStructPtr(new GpuLogicalBufferStruct());
 		if (recreateIfExists || (mIntLogicalToPhysical == nullptr))
 		if (recreateIfExists || (mIntLogicalToPhysical == nullptr))
 			mIntLogicalToPhysical = GpuLogicalBufferStructPtr(new GpuLogicalBufferStruct());
 			mIntLogicalToPhysical = GpuLogicalBufferStructPtr(new GpuLogicalBufferStruct());
+		if (recreateIfExists || (mSamplerLogicalToPhysical == nullptr))
+			mSamplerLogicalToPhysical = GpuLogicalBufferStructPtr(new GpuLogicalBufferStruct());
 	}
 	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
 	void GpuProgram::createNamedParameterMappingStructures(bool recreateIfExists) const
 	void GpuProgram::createNamedParameterMappingStructures(bool recreateIfExists) const
@@ -130,7 +132,7 @@ namespace CamelotEngine
 			ret->_setNamedConstants(mConstantDefs);
 			ret->_setNamedConstants(mConstantDefs);
 		}
 		}
 		// link shared logical / physical map for low-level use
 		// link shared logical / physical map for low-level use
-		ret->_setLogicalIndexes(mFloatLogicalToPhysical, mIntLogicalToPhysical);
+		ret->_setLogicalIndexes(mFloatLogicalToPhysical, mIntLogicalToPhysical, mSamplerLogicalToPhysical);
 
 
         // Copy in default parameters if present
         // Copy in default parameters if present
         if (mDefaultParams != nullptr)
         if (mDefaultParams != nullptr)

+ 0 - 30
CamelotRenderer/Source/CmGpuProgramManager.cpp

@@ -99,34 +99,4 @@ namespace CamelotEngine {
 		return GpuProgramParametersSharedPtr(new GpuProgramParameters());
 		return GpuProgramParametersSharedPtr(new GpuProgramParameters());
 	}
 	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
-	GpuSharedParametersPtr GpuProgramManager::createSharedParameters(const String& name)
-	{
-		if (mSharedParametersMap.find(name) != mSharedParametersMap.end())
-		{
-			CM_EXCEPT(InvalidParametersException, 
-				"The shared parameter set '" + name + "' already exists!");
-		}
-		GpuSharedParametersPtr ret(new GpuSharedParameters(name));
-		mSharedParametersMap[name] = ret;
-		return ret;
-	}
-	//---------------------------------------------------------------------
-	GpuSharedParametersPtr GpuProgramManager::getSharedParameters(const String& name) const
-	{
-		SharedParametersMap::const_iterator i = mSharedParametersMap.find(name);
-		if (i == mSharedParametersMap.end())
-		{
-			CM_EXCEPT(InvalidParametersException, 
-				"No shared parameter set with name '" + name + "'!");
-		}
-		return i->second;
-	}
-	//---------------------------------------------------------------------
-	const GpuProgramManager::SharedParametersMap& 
-	GpuProgramManager::getAvailableSharedParameters() const
-	{
-		return mSharedParametersMap;
-	}
-	//---------------------------------------------------------------------
-
 }
 }

+ 26 - 471
CamelotRenderer/Source/CmGpuProgramParams.cpp

@@ -29,6 +29,7 @@ THE SOFTWARE.
 #include "CmMatrix4.h"
 #include "CmMatrix4.h"
 #include "CmVector3.h"
 #include "CmVector3.h"
 #include "CmVector4.h"
 #include "CmVector4.h"
+#include "CmTexture.h"
 #include "CmRenderSystemCapabilities.h"
 #include "CmRenderSystemCapabilities.h"
 #include "CmException.h"
 #include "CmException.h"
 
 
@@ -79,349 +80,6 @@ namespace CamelotEngine
 	{
 	{
 		msGenerateAllConstantDefinitionArrayEntries = 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())
-		{
-			CM_EXCEPT(InvalidParametersException, 
-				"Constant entry with name '" + name + "' already exists. ");
-		}
-		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())
-		{
-			CM_EXCEPT(InvalidParametersException, 
-				"Constant entry with name '" + name + "' does not exist. ");
-		}
-		return i->second;
-	}
-	//---------------------------------------------------------------------
-	const GpuNamedConstants& GpuSharedParameters::getConstantDefinitions() const
-	{
-		return mNamedConstants;
-	}
-	//---------------------------------------------------------------------
-	void GpuSharedParameters::setNamedConstant(const String& name, float 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 Color& 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 Methods
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
@@ -443,13 +101,13 @@ namespace CamelotEngine
 	GpuProgramParameters& GpuProgramParameters::operator=(const GpuProgramParameters& oth)
 	GpuProgramParameters& GpuProgramParameters::operator=(const GpuProgramParameters& oth)
 	{
 	{
 		// let compiler perform shallow copies of structures 
 		// let compiler perform shallow copies of structures 
-		// AutoConstantEntry, RealConstantEntry, IntConstantEntry
+		// RealConstantEntry, IntConstantEntry
 		mFloatConstants = oth.mFloatConstants;
 		mFloatConstants = oth.mFloatConstants;
 		mIntConstants  = oth.mIntConstants;
 		mIntConstants  = oth.mIntConstants;
 		mFloatLogicalToPhysical = oth.mFloatLogicalToPhysical;
 		mFloatLogicalToPhysical = oth.mFloatLogicalToPhysical;
 		mIntLogicalToPhysical = oth.mIntLogicalToPhysical;
 		mIntLogicalToPhysical = oth.mIntLogicalToPhysical;
+		mSamplerLogicalToPhysical = oth.mSamplerLogicalToPhysical;
 		mNamedConstants = oth.mNamedConstants;
 		mNamedConstants = oth.mNamedConstants;
-		copySharedParamSetUsage(oth.mSharedParamSets);
 
 
 		mCombinedVariability = oth.mCombinedVariability;
 		mCombinedVariability = oth.mCombinedVariability;
 		mTransposeMatrices = oth.mTransposeMatrices;
 		mTransposeMatrices = oth.mTransposeMatrices;
@@ -459,16 +117,6 @@ namespace CamelotEngine
 		return *this;
 		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(
 	void GpuProgramParameters::_setNamedConstants(
 		const GpuNamedConstantsPtr& namedConstants)
 		const GpuNamedConstantsPtr& namedConstants)
 	{
 	{
@@ -487,14 +135,21 @@ namespace CamelotEngine
 			mIntConstants.insert(mIntConstants.end(), 
 			mIntConstants.insert(mIntConstants.end(), 
 				namedConstants->intBufferSize - mIntConstants.size(), 0);
 				namedConstants->intBufferSize - mIntConstants.size(), 0);
 		}
 		}
+		if (namedConstants->samplerCount > mTextures.size())
+		{
+			mTextures.insert(mTextures.end(), 
+				namedConstants->samplerCount - mTextures.size(), nullptr);
+		}
 	}
 	}
 	//---------------------------------------------------------------------
 	//---------------------------------------------------------------------
 	void GpuProgramParameters::_setLogicalIndexes(
 	void GpuProgramParameters::_setLogicalIndexes(
 		const GpuLogicalBufferStructPtr& floatIndexMap, 
 		const GpuLogicalBufferStructPtr& floatIndexMap, 
-		const GpuLogicalBufferStructPtr& intIndexMap)
+		const GpuLogicalBufferStructPtr& intIndexMap,
+		const GpuLogicalBufferStructPtr& samplerIndexMap)
 	{
 	{
 		mFloatLogicalToPhysical = floatIndexMap;
 		mFloatLogicalToPhysical = floatIndexMap;
 		mIntLogicalToPhysical = intIndexMap;
 		mIntLogicalToPhysical = intIndexMap;
+		mSamplerLogicalToPhysical = samplerIndexMap;
 
 
 		// resize the internal buffers
 		// resize the internal buffers
 		// Note that these will only contain something after the first parameter
 		// Note that these will only contain something after the first parameter
@@ -512,6 +167,11 @@ namespace CamelotEngine
 				intIndexMap->bufferSize - mIntConstants.size(), 0);
 				intIndexMap->bufferSize - mIntConstants.size(), 0);
 		}
 		}
 
 
+		if ((samplerIndexMap != nullptr) &&  samplerIndexMap->bufferSize > mTextures.size())
+		{
+			mTextures.insert(mTextures.end(), 
+				samplerIndexMap->bufferSize - mTextures.size(), nullptr);
+		}
 	}
 	}
 	//---------------------------------------------------------------------()
 	//---------------------------------------------------------------------()
 	void GpuProgramParameters::setConstant(size_t index, const Vector4& vec)
 	void GpuProgramParameters::setConstant(size_t index, const Vector4& vec)
@@ -1016,6 +676,16 @@ namespace CamelotEngine
 			return &(i->second);
 			return &(i->second);
 		}
 		}
 	}
 	}
+	//----------------------------------------------------------------------------
+	void GpuProgramParameters::setNamedConstant(const String& name, TexturePtr val)
+	{
+		// look up, and throw an exception if we're not ignoring missing
+		const GpuConstantDefinition* def = 
+			_findNamedConstantDefinition(name, !mIgnoreMissingParams);
+
+		if (def)
+			mTextures[def->physicalIndex] = val;
+	}
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
 	void GpuProgramParameters::setNamedConstant(const String& name, float val)
 	void GpuProgramParameters::setNamedConstant(const String& name, float val)
 	{
 	{
@@ -1120,57 +790,6 @@ namespace CamelotEngine
 		mFloatConstants = source.getFloatConstantList();
 		mFloatConstants = source.getFloatConstantList();
 		mIntConstants = source.getIntConstantList();
 		mIntConstants = source.getIntConstantList();
 		mCombinedVariability = source.mCombinedVariability;
 		mCombinedVariability = source.mCombinedVariability;
-		copySharedParamSetUsage(source.mSharedParamSets);
-	}
-	//---------------------------------------------------------------------
-	void GpuProgramParameters::copyMatchingNamedConstantsFrom(const GpuProgramParameters& source)
-	{
-		if ((mNamedConstants != nullptr) && (source.mNamedConstants != nullptr))
-		{
-			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;
-				}
-			}
-
-			// 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());
-				}
-			}
-		}
 	}
 	}
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------
 	void GpuProgramParameters::incPassIterationNumber(void)
 	void GpuProgramParameters::incPassIterationNumber(void)
@@ -1181,69 +800,5 @@ namespace CamelotEngine
 			++mFloatConstants[mActivePassIterationIndex];
 			++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();
-		}
-
-	}
-
-
-
-
-
 }
 }
 
 

+ 1 - 1
CamelotRenderer/Source/CmHighLevelGpuProgram.cpp

@@ -154,6 +154,6 @@ namespace CamelotEngine
 		getConstantDefinitions();
 		getConstantDefinitions();
 		params->_setNamedConstants(mConstantDefs);
 		params->_setNamedConstants(mConstantDefs);
 		// also set logical / physical maps for programs which use this
 		// also set logical / physical maps for programs which use this
-		params->_setLogicalIndexes(mFloatLogicalToPhysical, mIntLogicalToPhysical);
+		params->_setLogicalIndexes(mFloatLogicalToPhysical, mIntLogicalToPhysical, mSamplerLogicalToPhysical);
 	}
 	}
 }
 }

+ 1 - 0
CamelotRenderer/Source/CmMaterial.cpp

@@ -69,6 +69,7 @@ namespace CamelotEngine
 	{
 	{
 		throwIfNotInitialized();
 		throwIfNotInitialized();
 
 
+		// TODO - It's going to be very important to minimize the amount of texture (and less importantly) constant changes
 
 
 	}
 	}
 }
 }