Просмотр исходного кода

Serialize/Deserialize sampler states

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

+ 2 - 1
CamelotClient/CamelotClient.cpp

@@ -153,7 +153,8 @@ int _tmain(int argc, _TCHAR* argv[])
 	MaterialRef testMaterial = MaterialPtr(new Material());
 	testMaterial->setShader(testShader);
 
-	TextureRef testTex = static_resource_cast<Texture>(Importer::instance().import("C:\\ImportTest.tga"));
+	/*TextureRef testTex = static_resource_cast<Texture>(Importer::instance().import("C:\\ImportTest.tga"));*/
+	TextureRef testTex = static_resource_cast<Texture>(Importer::instance().import("C:\\ArenaTowerDFS.psd"));
 	MeshRef dbgMesh = static_resource_cast<Mesh>(Importer::instance().import("C:\\X_Arena_Tower.FBX"));
 
 	gResources().create(testTex, "C:\\ExportTest.tex", true);

+ 1 - 1
CamelotD3D9Renderer/Include/CmD3D9Mappings.h

@@ -68,7 +68,7 @@ namespace CamelotEngine
 		/// return a D3D9 equivalent for a Ogre TexCoordCalsMethod value
 		static DWORD get(TexCoordCalcMethod m, const D3DCAPS9& caps);
 		/// return a D3D9 equivalent for a Ogre TextureAddressingMode value
-		static D3DTEXTUREADDRESS get(TextureState::TextureAddressingMode tam, const D3DCAPS9& devCaps);
+		static D3DTEXTUREADDRESS get(SamplerState::TextureAddressingMode tam, const D3DCAPS9& devCaps);
 		/// return a D3D9 equivalent for a Ogre SceneBlendFactor value
 		static D3DBLEND get(SceneBlendFactor sbf);
 		/// return a D3D9 equivlalent for a Ogre SceneBlendOperation value

+ 1 - 1
CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h

@@ -231,7 +231,7 @@ namespace CamelotEngine
 		void _setVertexTexture(size_t unit, const TexturePtr& tex);
 		void _disableTextureUnit(size_t texUnit);
 		void _setTextureCoordSet( size_t unit, size_t index );
-        void _setTextureAddressingMode(size_t stage, const TextureState::UVWAddressingMode& uvw);
+        void _setTextureAddressingMode(size_t stage, const SamplerState::UVWAddressingMode& uvw);
         void _setTextureBorderColour(size_t stage, const Color& colour);
 		void _setTextureMipmapBias(size_t unit, float bias);
 		void _setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );

+ 5 - 5
CamelotD3D9Renderer/Source/CmD3D9Mappings.cpp

@@ -84,17 +84,17 @@ namespace CamelotEngine
 		return 0;
 	}
 	//---------------------------------------------------------------------
-	D3DTEXTUREADDRESS D3D9Mappings::get(TextureState::TextureAddressingMode tam, const D3DCAPS9& devCaps)
+	D3DTEXTUREADDRESS D3D9Mappings::get(SamplerState::TextureAddressingMode tam, const D3DCAPS9& devCaps)
 	{
 		switch( tam )
 		{
-		case TextureState::TAM_WRAP:
+		case SamplerState::TAM_WRAP:
 			return D3DTADDRESS_WRAP;
-		case TextureState::TAM_MIRROR:
+		case SamplerState::TAM_MIRROR:
 			return D3DTADDRESS_MIRROR;
-		case TextureState::TAM_CLAMP:
+		case SamplerState::TAM_CLAMP:
 			return D3DTADDRESS_CLAMP;
-        case TextureState::TAM_BORDER:
+        case SamplerState::TAM_BORDER:
             if (devCaps.TextureAddressCaps & D3DPTADDRESSCAPS_BORDER)
                 return D3DTADDRESS_BORDER;
             else

+ 1 - 1
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -1833,7 +1833,7 @@ namespace CamelotEngine
 	}
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::_setTextureAddressingMode( size_t stage, 
-		const TextureState::UVWAddressingMode& uvw )
+		const SamplerState::UVWAddressingMode& uvw )
 	{
 		HRESULT hr;
 		if( FAILED( hr = __SetSamplerState( static_cast<DWORD>(stage), D3DSAMP_ADDRESSU, D3D9Mappings::get(uvw.u, mDeviceManager->getActiveDevice()->getD3D9DeviceCaps()) ) ) )

+ 1 - 1
CamelotForwardRenderer/Include/CmForwardRenderer.h

@@ -11,7 +11,7 @@ namespace CamelotEngine
 		virtual const String& getName() const;
 
 		virtual void renderAll();
-		virtual void render(CameraPtr camera);
+		virtual void render(const CameraPtr camera);
 
 	protected:
 		/**

+ 2 - 2
CamelotGLRenderer/Include/CmGLRenderSystem.h

@@ -72,7 +72,7 @@ namespace CamelotEngine {
         void makeGLMatrix(GLfloat gl_matrix[16], const Matrix4& m);
  
         GLint getBlendMode(SceneBlendFactor ogreBlend) const;
-		GLint getTextureAddressingMode(TextureState::TextureAddressingMode tam) const;
+		GLint getTextureAddressingMode(SamplerState::TextureAddressingMode tam) const;
 				void initialiseContext(RenderWindow* primary);
 
         void setLights();
@@ -257,7 +257,7 @@ namespace CamelotEngine {
         /** See
           RenderSystem
          */
-        void _setTextureAddressingMode(size_t stage, const TextureState::UVWAddressingMode& uvw);
+        void _setTextureAddressingMode(size_t stage, const SamplerState::UVWAddressingMode& uvw);
         /** See
           RenderSystem
          */

+ 6 - 6
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -1354,24 +1354,24 @@ namespace CamelotEngine {
 	}
 	//-----------------------------------------------------------------------------
 	GLint GLRenderSystem::getTextureAddressingMode(
-		TextureState::TextureAddressingMode tam) const
+		SamplerState::TextureAddressingMode tam) const
 	{
 		switch(tam)
 		{
 		default:
-		case TextureState::TAM_WRAP:
+		case SamplerState::TAM_WRAP:
 			return GL_REPEAT;
-		case TextureState::TAM_MIRROR:
+		case SamplerState::TAM_MIRROR:
 			return GL_MIRRORED_REPEAT;
-		case TextureState::TAM_CLAMP:
+		case SamplerState::TAM_CLAMP:
 			return GL_CLAMP_TO_EDGE;
-		case TextureState::TAM_BORDER:
+		case SamplerState::TAM_BORDER:
 			return GL_CLAMP_TO_BORDER;
 		}
 
 	}
 	//-----------------------------------------------------------------------------
-	void GLRenderSystem::_setTextureAddressingMode(size_t stage, const TextureState::UVWAddressingMode& uvw)
+	void GLRenderSystem::_setTextureAddressingMode(size_t stage, const SamplerState::UVWAddressingMode& uvw)
 	{
 		if (!activateGLTextureUnit(stage))
 			return;

+ 2 - 2
CamelotRenderer/CamelotRenderer.vcxproj

@@ -153,7 +153,7 @@
     <ClInclude Include="Include\CmTexture.h" />
     <ClInclude Include="Include\CmTextureManager.h" />
     <ClInclude Include="Include\CmTextureRTTI.h" />
-    <ClInclude Include="Include\CmTextureState.h" />
+    <ClInclude Include="Include\CmSamplerState.h" />
     <ClInclude Include="Include\CmVertexIndexData.h" />
     <ClInclude Include="Include\CmViewport.h" />
     <ClInclude Include="Include\CmWindowEventUtilities.h" />
@@ -208,7 +208,7 @@
     <ClCompile Include="Source\CmTechnique.cpp" />
     <ClCompile Include="Source\CmTexture.cpp" />
     <ClCompile Include="Source\CmTextureManager.cpp" />
-    <ClCompile Include="Source\CmTextureState.cpp" />
+    <ClCompile Include="Source\CmSamplerState.cpp" />
     <ClCompile Include="Source\CmVertexIndexData.cpp" />
     <ClCompile Include="Source\CmViewport.cpp" />
     <ClCompile Include="Source\CmWindowEventUtilities.cpp" />

+ 6 - 6
CamelotRenderer/CamelotRenderer.vcxproj.filters

@@ -118,9 +118,6 @@
     <ClInclude Include="Include\CmVertexIndexData.h">
       <Filter>Header Files\RenderSystem</Filter>
     </ClInclude>
-    <ClInclude Include="Include\CmTextureState.h">
-      <Filter>Header Files\RenderSystem</Filter>
-    </ClInclude>
     <ClInclude Include="Include\CmRenderWindow.h">
       <Filter>Header Files\RenderSystem</Filter>
     </ClInclude>
@@ -307,6 +304,9 @@
     <ClInclude Include="Include\Win32\CmOSCursorImpl.h">
       <Filter>Header Files\Win32</Filter>
     </ClInclude>
+    <ClInclude Include="Include\CmSamplerState.h">
+      <Filter>Header Files\RenderSystem</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CamelotRenderer.cpp">
@@ -378,9 +378,6 @@
     <ClCompile Include="Source\CmRenderWindow.cpp">
       <Filter>Source Files\RenderSystem</Filter>
     </ClCompile>
-    <ClCompile Include="Source\CmTextureState.cpp">
-      <Filter>Source Files\RenderSystem</Filter>
-    </ClCompile>
     <ClCompile Include="Source\CmVertexIndexData.cpp">
       <Filter>Source Files\RenderSystem</Filter>
     </ClCompile>
@@ -450,5 +447,8 @@
     <ClCompile Include="Source\Win32\CmOSCursorImpl.cpp">
       <Filter>Source Files\Win32</Filter>
     </ClCompile>
+    <ClCompile Include="Source\CmSamplerState.cpp">
+      <Filter>Source Files\RenderSystem</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 37 - 2
CamelotRenderer/Include/CmGpuProgramParams.h

@@ -31,6 +31,7 @@ THE SOFTWARE.
 // Precompiler options
 #include "CmPrerequisites.h"
 #include "CmRenderOperation.h"
+#include "CmSamplerState.h"
 
 namespace CamelotEngine {
 
@@ -336,6 +337,17 @@ namespace CamelotEngine {
 	};
 	typedef std::shared_ptr<GpuLogicalBufferStruct> GpuLogicalBufferStructPtr;
 
+	/**
+	 * @brief	Contains a reference to a texture together with it's sampler properties
+	 */
+	struct GpuTextureEntry
+	{
+		TextureRef texture;
+		SamplerState samplerState;
+	};
+
+	typedef std::shared_ptr<GpuTextureEntry> GpuTextureEntryPtr;
+
 	/** 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
@@ -350,7 +362,7 @@ namespace CamelotEngine {
 	@note Not necessarily in direct index order to constant indexes, logical
 	to physical index map is derived from GpuProgram
 	*/
-	typedef vector<TextureRef>::type TextureList;
+	typedef vector<GpuTextureEntryPtr>::type TextureList;
 
 	/** Collects together the program parameters used for a GpuProgram.
 	@remarks
@@ -720,7 +732,8 @@ namespace CamelotEngine {
 		/// Get a pointer to the 'nth' item in the int buffer
 		const int* getIntPointer(size_t pos) const { return &mIntConstants[pos]; }
 		const GpuLogicalBufferStructPtr& getSamplerLogicalBufferStruct() const { return mSamplerLogicalToPhysical; }
-		TextureRef getTexture(size_t pos) const { return mTextures[pos];}
+		TextureRef getTexture(size_t pos) const;
+		const SamplerState& getSamplerState(size_t pos) const;
 		/// Get a reference to the list of textures
 		const TextureList& getTextureList() const { return mTextures; }
 
@@ -749,6 +762,28 @@ namespace CamelotEngine {
 		*/
 		void setNamedConstant(const String& name, TextureRef val);
 
+		/** Sets a sampler state to the program. Name of the sampler should be the same
+		as the name of the texture parameter it is being set for.
+		@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, const SamplerState& val);
+
 		/** Sets a single value constant floating-point parameter to the program.
 		@remarks
 		Different types of GPU programs support different types of constant parameters.

+ 80 - 1
CamelotRenderer/Include/CmMaterialRTTI.h

@@ -113,12 +113,50 @@ namespace CamelotEngine
 			}
 		};
 
+		class SamplerStateParamKVPRTTI;
+		typedef KeyValuePair<String, SamplerState, SamplerStateParamKVPRTTI> SamplerStateKVP;
+
+		class SamplerStateParamKVPRTTI : public RTTIType<SamplerStateKVP, IReflectable, SamplerStateParamKVPRTTI>
+		{
+		private:
+			String& getKey(SamplerStateKVP* obj) { return obj->mKey; }
+			void setKey(SamplerStateKVP* obj,  String& val) { obj->mKey = val; }
+
+			SamplerState& getValue(SamplerStateKVP* obj) { return obj->mValue; }
+			void setValue(SamplerStateKVP* obj,  SamplerState& val) { obj->mValue = val; }
+
+		public:
+			SamplerStateParamKVPRTTI()
+			{
+				addPlainField("mKey", 0, &SamplerStateParamKVPRTTI::getKey, &SamplerStateParamKVPRTTI::setKey);
+				addPlainField("mValue", 1, &SamplerStateParamKVPRTTI::getValue, &SamplerStateParamKVPRTTI::setValue);
+			}
+
+		public:
+			virtual const String& getRTTIName()
+			{
+				static String name = "SamplerStateKVP";
+				return name;
+			}
+
+			virtual UINT32 getRTTIId()
+			{
+				return TID_SamplerStateParamKVP;
+			}
+
+			virtual std::shared_ptr<IReflectable> newRTTIObject()
+			{
+				return std::shared_ptr<SamplerStateKVP>(new SamplerStateKVP());
+			}
+		};
+
 		class MaterialParamsRTTI;
 
 		struct MaterialParams : public IReflectable
 		{
 			map<String, FloatParam>::type mFloatParams;
 			map<String, TextureRef>::type mTextureParams;
+			map<String, SamplerState>::type mSamplerStateParams;
 
 			vector<float>::type mFloatBuffer;
 
@@ -140,6 +178,7 @@ namespace CamelotEngine
 			{
 				vector<std::shared_ptr<FloatParamKVP>>::type mFloatParams;
 				vector<std::shared_ptr<TexParamKVP>>::type mTexParams;
+				vector<std::shared_ptr<SamplerStateKVP>>::type mSamplerStateParams;
 			};
 
 			std::shared_ptr<FloatParamKVP> getFloatParam(MaterialParams* obj, UINT32 idx)
@@ -206,6 +245,38 @@ namespace CamelotEngine
 				return obj->mTextureParams.size();
 			}
 
+			std::shared_ptr<SamplerStateKVP> getSamplerStateParam(MaterialParams* obj, UINT32 idx)
+			{
+				UINT32 curIdx = 0;
+				for(auto iter = obj->mSamplerStateParams.begin(); iter != obj->mSamplerStateParams.end(); ++iter)
+				{
+					if(curIdx == idx)
+					{
+						return std::shared_ptr<SamplerStateKVP>(new SamplerStateKVP(iter->first, iter->second));
+					}
+
+					curIdx++;
+				}
+
+				CM_EXCEPT(InternalErrorException, "Invalid index.");
+			}
+
+			void setSamplerStateParam(MaterialParams* obj, UINT32 idx, std::shared_ptr<SamplerStateKVP> value)
+			{
+				TempParams* tempParams = boost::any_cast<TempParams*>(obj->mRTTIData);
+				tempParams->mSamplerStateParams.push_back(value);
+			}
+
+			void setNumSamplerStateParams(MaterialParams* obj, UINT32 size)
+			{
+				// Do nothing. Map is expanded automatically as entries are added
+			}
+
+			UINT32 getNumSamplerStateParams(MaterialParams* obj)
+			{
+				return obj->mSamplerStateParams.size();
+			}
+
 			ManagedDataBlock getFloatBuffer(MaterialParams* obj)
 			{
 				size_t bufferSize = obj->mFloatBuffer.size();
@@ -235,7 +306,9 @@ namespace CamelotEngine
 					&MaterialParamsRTTI::setFloatParam, &MaterialParamsRTTI::setNumFloatParams);
 				addReflectablePtrArrayField("mTexParams", 1, &MaterialParamsRTTI::getTexParam, &MaterialParamsRTTI::getNumTexParams, 
 					&MaterialParamsRTTI::setTexParam, &MaterialParamsRTTI::setNumTexParams);
-				addDataBlockField("mFloatBuffer", 2, &MaterialParamsRTTI::getFloatBuffer, &MaterialParamsRTTI::setFloatBuffer);
+				addReflectablePtrArrayField("mSamplerStateParams", 2, &MaterialParamsRTTI::getSamplerStateParam, &MaterialParamsRTTI::getNumSamplerStateParams, 
+					&MaterialParamsRTTI::setSamplerStateParam, &MaterialParamsRTTI::setNumSamplerStateParams);
+				addDataBlockField("mFloatBuffer", 3, &MaterialParamsRTTI::getFloatBuffer, &MaterialParamsRTTI::setFloatBuffer);
 			}
 
 			virtual void onDeserializationStarted(IReflectable* obj)
@@ -270,6 +343,12 @@ namespace CamelotEngine
 					materialParams->mTextureParams[texParam->mKey] = texParam->mValue;
 				}
 
+				for(auto iter = tempParams->mSamplerStateParams.begin(); iter != tempParams->mSamplerStateParams.end(); ++iter)
+				{
+					std::shared_ptr<SamplerStateKVP> samplerStateParam = *iter;
+					materialParams->mSamplerStateParams[samplerStateParam->mKey] = samplerStateParam->mValue;
+				}
+
 				materialParams->mRTTIData = nullptr;
 			}
 

+ 4 - 2
CamelotRenderer/Include/CmPrerequisites.h

@@ -91,7 +91,7 @@ namespace CamelotEngine {
     class RenderWindow;
     class RenderOperation;
     class StringInterface;
-    class TextureState;
+    class SamplerState;
     class TextureManager;
     class Viewport;
     class VertexBufferBinding;
@@ -168,7 +168,9 @@ namespace CamelotEngine
 		TID_Material = 1017,
 		TID_MaterialParams = 1018,
 		TID_FloatParamKVP = 1019,
-		TID_MaterialTexParamKVP = 1020
+		TID_MaterialTexParamKVP = 1020,
+		TID_SamplerState = 1021,
+		TID_SamplerStateParamKVP = 1022
 	};
 }
 

+ 3 - 3
CamelotRenderer/Include/CmRenderSystem.h

@@ -35,7 +35,7 @@ THE SOFTWARE.
 
 #include "CmString.h"
 
-#include "CmTextureState.h"
+#include "CmSamplerState.h"
 #include "CmCommon.h"
 
 #include "CmRenderOperation.h"
@@ -540,7 +540,7 @@ namespace CamelotEngine
 		only sets those settings which are different from the current settings for this
 		unit, thus minimising render state changes.
 		*/
-		virtual void _setTextureUnitSettings(size_t texUnit, const TexturePtr& texture, TextureState& tl);
+		virtual void _setTextureUnitSettings(size_t texUnit, const TexturePtr& texture, SamplerState& tl);
 		/** Turns off a texture unit. */
 		virtual void _disableTextureUnit(size_t texUnit);
 		/** Disables all texture units from the given unit upwards */
@@ -661,7 +661,7 @@ namespace CamelotEngine
 		virtual void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy) = 0;
 
 		/** Sets the texture addressing mode for a texture unit.*/
-		virtual void _setTextureAddressingMode(size_t unit, const TextureState::UVWAddressingMode& uvw) = 0;
+		virtual void _setTextureAddressingMode(size_t unit, const SamplerState::UVWAddressingMode& uvw) = 0;
 
 		/** Sets the texture border colour for a texture unit.*/
 		virtual void _setTextureBorderColour(size_t unit, const Color& colour) = 0;

+ 1 - 1
CamelotRenderer/Include/CmRenderer.h

@@ -23,6 +23,6 @@ namespace CamelotEngine
 		/**
 		 * @brief	Sets the currently active pass.
 		 */
-		virtual void setPass(PassPtr pass) = 0;
+		virtual void setPass(const PassPtr pass) = 0;
 	};
 }

+ 12 - 74
CamelotRenderer/Include/CmTextureState.h → CamelotRenderer/Include/CmSamplerState.h

@@ -25,8 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 -----------------------------------------------------------------------------
 */
-#ifndef __TextureState_H__
-#define __TextureState_H__
+#pragma once
 
 #include "CmPrerequisites.h"
 #include "CmCommon.h"
@@ -42,25 +41,18 @@ namespace CamelotEngine {
 	/** \addtogroup Materials
 	*  @{
 	*/
-	/** Class representing the state of a single texture unit during a Pass of a
+	/** Class representing the state of a single sampler unit during a Pass of a
         Technique, of a Material.
     @remarks
-        Texture units are pipelines for retrieving texture data for rendering onto
-        your objects in the world. Using them is common to both the fixed-function and 
-        the programmable (vertex and fragment program) pipeline, but some of the 
-        settings will only have an effect in the fixed-function pipeline (for example, 
-        setting a texture rotation will have no effect if you use the programmable
-        pipeline, because this is overridden by the fragment program). The effect
-        of each setting as regards the 2 pipelines is commented in each setting.
-    @par
-        When I use the term 'fixed-function pipeline' I mean traditional rendering
-        where you do not use vertex or fragment programs (shaders). Programmable 
-        pipeline means that for this pass you are using vertex or fragment programs.
+        Sampler units are pipelines for retrieving texture data for rendering onto
+        your objects in the world. 
     */
-	class CM_EXPORT TextureState
+	class CM_EXPORT SamplerState
     {
     public:
 
+		static SamplerState EMPTY;
+
         /** Texture addressing modes - default is TAM_WRAP.
         @note
             These settings are relevant in both the fixed-function and the
@@ -98,15 +90,15 @@ namespace CamelotEngine {
 
         /** Default constructor.
         */
-        TextureState(TextureType type);
+        SamplerState();
 
-        TextureState(const TextureState& oth );
+        SamplerState(const SamplerState& oth );
 
-        TextureState & operator = ( const TextureState& oth );
+        SamplerState & operator = ( const SamplerState& oth );
 
         /** Default destructor.
         */
-        ~TextureState();
+        ~SamplerState();
 
 		/** The type of unit to bind the texture settings to. */
 		enum BindingType
@@ -134,50 +126,6 @@ namespace CamelotEngine {
 		*/
 		BindingType getBindingType(void) const;
 
-        /** Returns true if this texture unit is either a series of 6 2D textures, each
-            in it's own frame, or is a full 3D cube map. You can tell which by checking
-            getTextureType.
-        @note
-        Applies to both fixed-function and programmable pipeline.
-        */
-        bool isCubic(void) const;
-
-        /** Returns true if this texture layer uses a composite 3D cubic texture.
-        @note
-        Applies to both fixed-function and programmable pipeline.
-        */
-        bool is3D(void) const;
-
-        /** Returns the type of this texture.
-        @note
-        Applies to both fixed-function and programmable pipeline.
-        */
-        TextureType getTextureType(void) const;
-
-        /** Sets the desired pixel format when load the texture.
-        */
-        void setDesiredFormat(PixelFormat desiredFormat);
-
-        /** Gets the desired pixel format when load the texture.
-        */
-        PixelFormat getDesiredFormat(void) const;
-
-        /** Sets how many mipmaps have been requested for the texture.
-		*/
-        void setNumMipmaps(int numMipmaps);
-
-        /** Gets how many mipmaps have been requested for the texture.
-		*/
-        int getNumMipmaps(void) const;
-
-		/** Sets whether this texture is requested to be loaded as alpha if single channel
-		*/
-        void setIsAlpha(bool isAlpha);
-
-		/** Gets whether this texture is requested to be loaded as alpha if single channel
-		*/
-        bool getIsAlpha(void) const;
-
 		/// @copydoc Texture::setHardwareGammaEnabled
 		void setHardwareGammaEnabled(bool enabled);
 		/// @copydoc Texture::isHardwareGammaEnabled
@@ -272,14 +220,8 @@ namespace CamelotEngine {
 		*/
 		float getTextureMipmapBias(void) const { return mMipmapBias; }
 protected:
-        // State
-        TextureType mTextureType; 
-        PixelFormat mDesiredFormat;
-		int mTextureSrcMipmaps; // Request number of mipmaps
-
         UVWAddressingMode mAddressMode;
 
-        bool mIsAlpha;
 		bool mHwGamma;
 
         /// Texture filtering - minification
@@ -293,8 +235,6 @@ protected:
 		/// Mipmap bias (always float, not float)
 		float mMipmapBias;
 
-        bool mIsDefaultAniso;
-        bool mIsDefaultFiltering;
 		/// Binding type (fragment or vertex pipeline)
 		BindingType mBindingType;
     };
@@ -302,6 +242,4 @@ protected:
 	/** @} */
 	/** @} */
 
-}
-
-#endif
+}

+ 41 - 2
CamelotRenderer/Source/CmGpuProgramParams.cpp

@@ -396,7 +396,7 @@ namespace CamelotEngine
 	void GpuProgramParameters::_readTexture(size_t physicalIndex, TextureRef& dest)
 	{
 		assert(physicalIndex < mTextures.size());
-		dest = mTextures[physicalIndex];
+		dest = mTextures[physicalIndex]->texture;
 	}
 	//---------------------------------------------------------------------
 	GpuLogicalIndexUse* GpuProgramParameters::_getFloatConstantLogicalIndexUse(
@@ -670,7 +670,26 @@ namespace CamelotEngine
 		const GpuConstantDefinition* def = _findNamedConstantDefinition(name, true);
 
 		return *def;
+	}
+	//----------------------------------------------------------------------------
+	TextureRef GpuProgramParameters::getTexture(size_t pos) const 
+	{ 
+		if(mTextures[pos] == nullptr)
+		{
+			return TextureRef();
+		}
+
+		return mTextures[pos]->texture; 
+	}
+	//----------------------------------------------------------------------------
+	const SamplerState& GpuProgramParameters::getSamplerState(size_t pos) const 
+	{ 
+		if(mTextures[pos] == nullptr)
+		{
+			return SamplerState::EMPTY;
+		}
 
+		return mTextures[pos]->samplerState; 
 	}
 	//-----------------------------------------------------------------------------
 	bool GpuProgramParameters::hasNamedConstant(const String& name) const
@@ -717,7 +736,27 @@ namespace CamelotEngine
 			_findNamedConstantDefinition(name, !mIgnoreMissingParams);
 
 		if (def)
-			mTextures[def->physicalIndex] = val;
+		{
+			if(mTextures[def->physicalIndex] == nullptr)
+				mTextures[def->physicalIndex] = GpuTextureEntryPtr(new GpuTextureEntry());
+
+			mTextures[def->physicalIndex]->texture = val;
+		}
+	}
+	//-----------------------------------------------------------------------------
+	void GpuProgramParameters::setNamedConstant(const String& name, const SamplerState& val)
+	{
+		// look up, and throw an exception if we're not ignoring missing
+		const GpuConstantDefinition* def = 
+			_findNamedConstantDefinition(name, !mIgnoreMissingParams);
+
+		if (def)
+		{
+			if(mTextures[def->physicalIndex] == nullptr)
+				mTextures[def->physicalIndex] = GpuTextureEntryPtr(new GpuTextureEntry());
+
+			mTextures[def->physicalIndex]->samplerState = val;
+		}
 	}
 	//-----------------------------------------------------------------------------
 	void GpuProgramParameters::setNamedConstant(const String& name, float val)

+ 11 - 3
CamelotRenderer/Source/CmMaterialRTTI.cpp

@@ -41,9 +41,12 @@ namespace CamelotEngine
 
 				if(def.constType == GCT_SAMPLER2D)
 				{
-					TextureRef value;
-					allParams[i]->_readTexture(iter->second.physicalIndex, value);
-					params->mTextureParams[iter->first] = value;
+					TextureRef texture;
+					allParams[i]->_readTexture(iter->second.physicalIndex, texture);
+					params->mTextureParams[iter->first] = texture;
+
+					SamplerState samplerState = allParams[i]->getSamplerState(iter->second.physicalIndex);
+					params->mSamplerStateParams[iter->first] = samplerState;
 				}
 				else
 				{
@@ -134,6 +137,11 @@ namespace CamelotEngine
 
 					if(iterFind != params->mTextureParams.end())
 						allParams[i]->setNamedConstant(iter->first, iterFind->second);
+
+					auto iterFind2 = params->mSamplerStateParams.find(iter->first);
+
+					if(iterFind2 != params->mSamplerStateParams.end())
+						allParams[i]->setNamedConstant(iter->first, iterFind2->second);
 				}
 				else
 				{

+ 3 - 3
CamelotRenderer/Source/CmRenderSystem.cpp

@@ -278,7 +278,7 @@ namespace CamelotEngine {
         return mActiveViewport;
     }
     //-----------------------------------------------------------------------
-    void RenderSystem::_setTextureUnitSettings(size_t texUnit, const TexturePtr& tex, TextureState& tl)
+    void RenderSystem::_setTextureUnitSettings(size_t texUnit, const TexturePtr& tex, SamplerState& tl)
     {
         // This method is only ever called to set a texture unit to valid details
         // The method _disableTextureUnit is called to turn a unit off
@@ -287,7 +287,7 @@ namespace CamelotEngine {
 		if (mCurrentCapabilities->hasCapability(RSC_VERTEX_TEXTURE_FETCH) &&
 			!mCurrentCapabilities->getVertexTextureUnitsShared())
 		{
-			if (tl.getBindingType() == TextureState::BT_VERTEX)
+			if (tl.getBindingType() == SamplerState::BT_VERTEX)
 			{
 				// Bind vertex texture
 				_setVertexTexture(texUnit, tex);
@@ -322,7 +322,7 @@ namespace CamelotEngine {
 		_setTextureMipmapBias(texUnit, tl.getTextureMipmapBias());
 
         // Texture addressing mode
-        const TextureState::UVWAddressingMode& uvw = tl.getTextureAddressingMode();
+        const SamplerState::UVWAddressingMode& uvw = tl.getTextureAddressingMode();
         _setTextureAddressingMode(texUnit, uvw);
     }
 	//-----------------------------------------------------------------------

+ 28 - 82
CamelotRenderer/Source/CmTextureState.cpp → CamelotRenderer/Source/CmSamplerState.cpp

@@ -25,144 +25,94 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 -----------------------------------------------------------------------------
 */
-#include "CmTextureState.h"
+#include "CmSamplerState.h"
 #include "CmException.h"
 
 namespace CamelotEngine {
 
+	SamplerState SamplerState::EMPTY;
     //-----------------------------------------------------------------------
-    TextureState::TextureState(TextureType type)
-		: mTextureType(type)
-        , mDesiredFormat(PF_UNKNOWN)
-		, mTextureSrcMipmaps(MIP_DEFAULT)
-		, mIsAlpha(false)
-		, mHwGamma(false)
+    SamplerState::SamplerState()
+		: mHwGamma(false)
 		, mMinFilter(FO_LINEAR)
 		, mMagFilter(FO_LINEAR)
 		, mMipFilter(FO_POINT)
 		, mMaxAniso(0)
 		, mMipmapBias(0)
-		, mIsDefaultAniso(true)
-		, mIsDefaultFiltering(true)
 		, mBindingType(BT_FRAGMENT)
     {
 		setTextureAddressingMode(TAM_WRAP);
     }
 
     //-----------------------------------------------------------------------
-    TextureState::TextureState(const TextureState& oth )
+    SamplerState::SamplerState(const SamplerState& oth )
     {
         *this = oth;
     }
 
     //-----------------------------------------------------------------------
-    TextureState::~TextureState()
+    SamplerState::~SamplerState()
     {
     }
     //-----------------------------------------------------------------------
-    TextureState & TextureState::operator = ( 
-        const TextureState &oth )
+    SamplerState & SamplerState::operator = ( 
+        const SamplerState &oth )
     {
         return *this;
     }
 	//-----------------------------------------------------------------------
-	void TextureState::setBindingType(TextureState::BindingType bt)
+	void SamplerState::setBindingType(SamplerState::BindingType bt)
 	{
 		mBindingType = bt;
 
 	}
 	//-----------------------------------------------------------------------
-	TextureState::BindingType TextureState::getBindingType(void) const
+	SamplerState::BindingType SamplerState::getBindingType(void) const
 	{
 		return mBindingType;
 	}
-    //-----------------------------------------------------------------------
-    bool TextureState::isCubic(void) const
-    {
-        return mTextureType == TEX_TYPE_CUBE_MAP;
-    }
-    //-----------------------------------------------------------------------
-    bool TextureState::is3D(void) const
-    {
-        return mTextureType == TEX_TYPE_3D;
-    }
-    //-----------------------------------------------------------------------
-    TextureType TextureState::getTextureType(void) const
-    {
-        return mTextureType;
-	}
-    //-----------------------------------------------------------------------
-    void TextureState::setDesiredFormat(PixelFormat desiredFormat)
-    {
-        mDesiredFormat = desiredFormat;
-    }
-    //-----------------------------------------------------------------------
-    PixelFormat TextureState::getDesiredFormat(void) const
-    {
-        return mDesiredFormat;
-    }
-    //-----------------------------------------------------------------------
-    void TextureState::setNumMipmaps(int numMipmaps)
-    {
-        mTextureSrcMipmaps = numMipmaps;
-    }
-    //-----------------------------------------------------------------------
-    int TextureState::getNumMipmaps(void) const
-    {
-        return mTextureSrcMipmaps;
-    }
-    //-----------------------------------------------------------------------
-    void TextureState::setIsAlpha(bool isAlpha)
-    {
-        mIsAlpha = isAlpha;
-    }
-    //-----------------------------------------------------------------------
-    bool TextureState::getIsAlpha(void) const
-    {
-        return mIsAlpha;
-    }
 	//-----------------------------------------------------------------------
-	void TextureState::setHardwareGammaEnabled(bool g)
+	void SamplerState::setHardwareGammaEnabled(bool g)
 	{
 		mHwGamma = g;
 	}
 	//-----------------------------------------------------------------------
-	bool TextureState::isHardwareGammaEnabled() const
+	bool SamplerState::isHardwareGammaEnabled() const
 	{
 		return mHwGamma;
 	}
     //-----------------------------------------------------------------------
-    const TextureState::UVWAddressingMode& 
-	TextureState::getTextureAddressingMode(void) const
+    const SamplerState::UVWAddressingMode& 
+	SamplerState::getTextureAddressingMode(void) const
     {
         return mAddressMode;
     }
     //-----------------------------------------------------------------------
-    void TextureState::setTextureAddressingMode(
-		TextureState::TextureAddressingMode tam)
+    void SamplerState::setTextureAddressingMode(
+		SamplerState::TextureAddressingMode tam)
     {
         mAddressMode.u = tam;
         mAddressMode.v = tam;
         mAddressMode.w = tam;
     }
     //-----------------------------------------------------------------------
-    void TextureState::setTextureAddressingMode(
-		TextureState::TextureAddressingMode u, 
-		TextureState::TextureAddressingMode v,
-		TextureState::TextureAddressingMode w)
+    void SamplerState::setTextureAddressingMode(
+		SamplerState::TextureAddressingMode u, 
+		SamplerState::TextureAddressingMode v,
+		SamplerState::TextureAddressingMode w)
     {
         mAddressMode.u = u;
         mAddressMode.v = v;
         mAddressMode.w = w;
     }
     //-----------------------------------------------------------------------
-    void TextureState::setTextureAddressingMode(
-		const TextureState::UVWAddressingMode& uvw)
+    void SamplerState::setTextureAddressingMode(
+		const SamplerState::UVWAddressingMode& uvw)
     {
         mAddressMode = uvw;
     }
 	//-----------------------------------------------------------------------
-	void TextureState::setTextureFiltering(TextureFilterOptions filterType)
+	void SamplerState::setTextureFiltering(TextureFilterOptions filterType)
 	{
         switch (filterType)
         {
@@ -179,10 +129,9 @@ namespace CamelotEngine {
             setTextureFiltering(FO_ANISOTROPIC, FO_ANISOTROPIC, FO_LINEAR);
             break;
         }
-        mIsDefaultFiltering = false;
 	}
 	//-----------------------------------------------------------------------
-    void TextureState::setTextureFiltering(FilterType ft, FilterOptions fo)
+    void SamplerState::setTextureFiltering(FilterType ft, FilterOptions fo)
     {
         switch (ft)
         {
@@ -196,19 +145,17 @@ namespace CamelotEngine {
             mMipFilter = fo;
             break;
         }
-        mIsDefaultFiltering = false;
     }
 	//-----------------------------------------------------------------------
-    void TextureState::setTextureFiltering(FilterOptions minFilter, 
+    void SamplerState::setTextureFiltering(FilterOptions minFilter, 
         FilterOptions magFilter, FilterOptions mipFilter)
     {
         mMinFilter = minFilter;
         mMagFilter = magFilter;
         mMipFilter = mipFilter;
-        mIsDefaultFiltering = false;
     }
 	//-----------------------------------------------------------------------
-	FilterOptions TextureState::getTextureFiltering(FilterType ft) const
+	FilterOptions SamplerState::getTextureFiltering(FilterType ft) const
 	{
         switch (ft)
         {
@@ -224,13 +171,12 @@ namespace CamelotEngine {
 	}
 
 	//-----------------------------------------------------------------------
-	void TextureState::setTextureAnisotropy(unsigned int maxAniso)
+	void SamplerState::setTextureAnisotropy(unsigned int maxAniso)
 	{
 		mMaxAniso = maxAniso;
-        mIsDefaultAniso = false;
 	}
 	//-----------------------------------------------------------------------
-	unsigned int TextureState::getTextureAnisotropy() const
+	unsigned int SamplerState::getTextureAnisotropy() const
 	{
         return mMaxAniso;
 	}