Browse Source

Sampler state gets applied only through SamplerState object

Marko Pintera 13 years ago
parent
commit
74fe12325f

+ 2 - 2
CamelotClient/CamelotClient.cpp

@@ -27,8 +27,8 @@ using namespace CamelotEngine;
 
 int _tmain(int argc, _TCHAR* argv[])
 {
-	gApplication().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer");
-	//gApplication().startUp("CamelotD3D9RenderSystem", "CamelotForwardRenderer");
+	//gApplication().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer");
+	gApplication().startUp("CamelotD3D9RenderSystem", "CamelotForwardRenderer");
 
 	RenderSystem* renderSystem = RenderSystemManager::getActive();
 	RenderWindow* renderWindow = gApplication().getPrimaryRenderWindow();

+ 32 - 5
CamelotD3D9Renderer/Include/CmD3D9RenderSystem.h

@@ -218,6 +218,32 @@ namespace CamelotEngine
 		/// Take in some requested FSAA settings and output supported D3D settings
 		void determineFSAASettings(IDirect3DDevice9* d3d9Device, UINT32 fsaa, const String& fsaaHint, D3DFORMAT d3dPixelFormat, 
 			bool fullScreen, D3DMULTISAMPLE_TYPE *outMultisampleType, DWORD *outMultisampleQuality);
+	
+		/** Sets the texture addressing mode for a texture unit.*/	
+		void setTextureAddressingMode(UINT16 stage, const UVWAddressingMode& uvw);
+
+		/** Sets a single filter for a given texture unit.
+		@param unit The texture unit to set the filtering options for
+		@param ftype The filter type
+		@param filter The filter to be used
+		*/
+		void setTextureFiltering(UINT16 unit, FilterType ftype, FilterOptions filter);
+
+		/** Sets the maximal anisotropy for the specified texture unit.*/
+		void setTextureAnisotropy(UINT16 unit, unsigned int maxAnisotropy);
+
+		/** Sets the texture border colour for a texture unit.*/
+		void setTextureBorderColor(UINT16 stage, const Color& color);
+
+		/** Sets the mipmap bias value for a given texture unit.
+		@remarks
+		This allows you to adjust the mipmap calculation up or down for a
+		given texture unit. Negative values force a larger mipmap to be used, 
+		positive values force a smaller mipmap to be used. Units are in numbers
+		of levels, so +1 forces the mipmaps to one smaller level.
+		@note Only does something if render system has capability RSC_MIPMAP_LOD_BIAS.
+		*/
+		void setTextureMipmapBias(UINT16 unit, float bias);
 	public:
 		// constructor
 		D3D9RenderSystem( HINSTANCE hInstance );
@@ -248,10 +274,13 @@ namespace CamelotEngine
 		void setPointParameters(float size, bool attenuationEnabled, 
 			float constant, float linear, float quadratic, float minSize, float maxSize);
 		void setTexture(UINT16 unit, bool enabled, const TexturePtr &texPtr);
+
+		/**
+		 * @copydoc RenderSystem::setSamplerState()
+		 */
+		void setSamplerState(UINT16 unit, const SamplerState& state);
+
 		void disableTextureUnit(UINT16 texUnit);
-        void setTextureAddressingMode(UINT16 stage, const UVWAddressingMode& uvw);
-        void setTextureBorderColor(UINT16 stage, const Color& colour);
-		void setTextureMipmapBias(UINT16 unit, float bias);
 		void setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
 		void setSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
 		void setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage );
@@ -267,8 +296,6 @@ namespace CamelotEngine
 		void setDepthBias(float constantBias, float slopeScaleBias);
 		void convertProjectionMatrix(const Matrix4& matrix, Matrix4& dest, bool forGpuProgram = false);
 		void setPolygonMode(PolygonMode level);
-        void setTextureFiltering(UINT16 unit, FilterType ftype, FilterOptions filter);
-		void setTextureAnisotropy(UINT16 unit, unsigned int maxAnisotropy);
 		void setVertexDeclaration(VertexDeclarationPtr decl);
 		void setVertexBufferBinding(VertexBufferBinding* binding);
         void render(const RenderOperation& op);

+ 23 - 0
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -581,6 +581,29 @@ namespace CamelotEngine
 
 		RenderSystem::disableTextureUnit(texUnit);
 	}
+	//-----------------------------------------------------------------------
+	void D3D9RenderSystem::setSamplerState(UINT16 unit, const SamplerState& state)
+	{
+		THROW_IF_NOT_RENDER_THREAD;
+
+		// Set texture layer filtering
+		setTextureFiltering(unit, FT_MIN, state.getTextureFiltering(FT_MIN));
+		setTextureFiltering(unit, FT_MAG, state.getTextureFiltering(FT_MAG));
+		setTextureFiltering(unit, FT_MIP, state.getTextureFiltering(FT_MIP));
+
+		// Set texture layer filtering
+		setTextureAnisotropy(unit, state.getTextureAnisotropy());
+
+		// Set mipmap biasing
+		setTextureMipmapBias(unit, state.getTextureMipmapBias());
+
+		// Texture addressing mode
+		const UVWAddressingMode& uvw = state.getTextureAddressingMode();
+		setTextureAddressingMode(unit, uvw);
+
+		// Set border color
+		setTextureBorderColor(unit, state.getBorderColor(0));
+	}
 	//---------------------------------------------------------------------
 	void D3D9RenderSystem::setTextureMipmapBias(UINT16 unit, float bias)
 	{

+ 31 - 22
CamelotGLRenderer/Include/CmGLRenderSystem.h

@@ -157,6 +157,32 @@ namespace CamelotEngine {
          */
         void enableClipPlane (UINT16 index, bool enable);
 
+		/** Sets the texture addressing mode for a texture unit.*/
+        void setTextureAddressingMode(UINT16 stage, const UVWAddressingMode& uvw);
+
+		/** Sets the texture border color for a texture unit.*/
+        void setTextureBorderColor(UINT16 stage, const Color& color);
+
+		/** Sets the mipmap bias value for a given texture unit.
+		@remarks
+		This allows you to adjust the mipmap calculation up or down for a
+		given texture unit. Negative values force a larger mipmap to be used, 
+		positive values force a smaller mipmap to be used. Units are in numbers
+		of levels, so +1 forces the mipmaps to one smaller level.
+		@note Only does something if render system has capability RSC_MIPMAP_LOD_BIAS.
+		*/
+		void setTextureMipmapBias(UINT16 unit, float bias);
+
+		/** Sets a single filter for a given texture unit.
+		@param unit The texture unit to set the filtering options for
+		@param ftype The filter type
+		@param filter The filter to be used
+		*/
+        void setTextureFiltering(UINT16 unit, FilterType ftype, FilterOptions filter);
+
+		/** Sets the maximal anisotropy for the specified texture unit.*/
+		void setTextureAnisotropy(UINT16 unit, unsigned int maxAnisotropy);
+
 		// ----------------------------------
         // GLRenderSystem specific members
         // ----------------------------------
@@ -224,21 +250,12 @@ namespace CamelotEngine {
           RenderSystem
          */
         void setTexture(UINT16 unit, bool enabled, const TexturePtr &tex);
-        /** See
-          RenderSystem
-         */
-        void setTextureAddressingMode(UINT16 stage, const UVWAddressingMode& uvw);
-        /** See
-          RenderSystem
-         */
-        void setTextureBorderColor(UINT16 stage, const Color& colour);
-		/** See
-		  RenderSystem
+        
+		/**
+		 * @copydoc RenderSystem::setSamplerState()
 		 */
-		void setTextureMipmapBias(UINT16 unit, float bias);
-        /** See
-          RenderSystem
-         */
+		void setSamplerState(UINT16 unit, const SamplerState& state);
+
         void setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
         /** See
           RenderSystem
@@ -318,14 +335,6 @@ namespace CamelotEngine {
             StencilOperation depthFailOp = SOP_KEEP,
             StencilOperation passOp = SOP_KEEP, 
             bool twoSidedOperation = false);
-        /** See
-          RenderSystem
-         */
-        void setTextureFiltering(UINT16 unit, FilterType ftype, FilterOptions filter);
-        /** See
-          RenderSystem
-         */
-		void setTextureAnisotropy(UINT16 unit, unsigned int maxAnisotropy);
         /** See
           RenderSystem
          */

+ 23 - 0
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -503,6 +503,29 @@ namespace CamelotEngine {
 
 		activateGLTextureUnit(0);
 	}
+	//-----------------------------------------------------------------------
+	void GLRenderSystem::setSamplerState(UINT16 unit, const SamplerState& state)
+	{
+		THROW_IF_NOT_RENDER_THREAD;
+
+		// Set texture layer filtering
+		setTextureFiltering(unit, FT_MIN, state.getTextureFiltering(FT_MIN));
+		setTextureFiltering(unit, FT_MAG, state.getTextureFiltering(FT_MAG));
+		setTextureFiltering(unit, FT_MIP, state.getTextureFiltering(FT_MIP));
+
+		// Set texture anisotropy
+		setTextureAnisotropy(unit, state.getTextureAnisotropy());
+
+		// Set mipmap biasing
+		setTextureMipmapBias(unit, state.getTextureMipmapBias());
+
+		// Texture addressing mode
+		const UVWAddressingMode& uvw = state.getTextureAddressingMode();
+		setTextureAddressingMode(unit, uvw);
+
+		// Set border color
+		setTextureBorderColor(unit, state.getBorderColor(0));
+	}
 	//-----------------------------------------------------------------------------
 	void GLRenderSystem::setTextureAddressingMode(UINT16 stage, const UVWAddressingMode& uvw)
 	{

+ 2 - 15
CamelotRenderer/Include/CmDeferredRenderContext.h

@@ -25,9 +25,6 @@ namespace CamelotEngine
 		/** @copydoc RenderSystem::getWaitForVerticalBlank() */
 		bool getWaitForVerticalBlank(void) const;
 
-
-		/** @copydoc RenderSystem::setTextureUnitSettings() */
-		void setSamplerState(UINT16 texUnit, const SamplerState& samplerState);
 		/** @copydoc RenderSystem::disableTextureUnit() */
 		void disableTextureUnit(UINT16 texUnit);
 		/** @copydoc RenderSystem::disableTextureUnitsFrom() */
@@ -39,18 +36,8 @@ namespace CamelotEngine
 		/** @copydoc RenderSystem::setTexture() */
 		void setTexture(UINT16 unit, bool enabled, const TexturePtr &texPtr);
 
-		/** @copydoc RenderSystem::setTextureFiltering() */
-		void setTextureFiltering(UINT16 unit, FilterOptions minFilter, FilterOptions magFilter, FilterOptions mipFilter);
-		/** @copydoc RenderSystem::setTextureFiltering() */
-		void setTextureFiltering(UINT16 unit, FilterType ftype, FilterOptions filter);
-		/** @copydoc RenderSystem::setTextureAnisotropy() */
-		void setTextureAnisotropy(UINT16 unit, unsigned int maxAnisotropy);
-		/** @copydoc RenderSystem::setTextureAddressingMode() */
-		void setTextureAddressingMode(UINT16 unit, const UVWAddressingMode& uvw);
-		/** @copydoc RenderSystem::setTextureBorderColor() */
-		void setTextureBorderColor(UINT16 unit, const Color& color);
-		/** @copydoc RenderSystem::setTextureMipmapBias() */
-		void setTextureMipmapBias(UINT16 unit, float bias);
+		/** @copydoc RenderSystem::setTextureUnitSettings() */
+		void setSamplerState(UINT16 texUnit, const SamplerState& samplerState);
 
 		/** @copydoc RenderSystem::setSceneBlending() */
 		void setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op = SBO_ADD);

+ 1 - 36
CamelotRenderer/Include/CmRenderSystem.h

@@ -360,7 +360,7 @@ namespace CamelotEngine
 		/**
 		 * @brief	Sets a sampler state for the specified texture unit.
 		 */
-		virtual void setSamplerState(UINT16 texUnit, const SamplerState& samplerState);
+		virtual void setSamplerState(UINT16 texUnit, const SamplerState& samplerState) = 0;
 		/** Turns off a texture unit. */
 		virtual void disableTextureUnit(UINT16 texUnit);
 		/** Disables all texture units from the given unit upwards */
@@ -395,41 +395,6 @@ namespace CamelotEngine
 		virtual void setTexture(UINT16 unit, bool enabled, 
 			const TexturePtr &texPtr) = 0;
 
-		/** Sets the filtering options for a given texture unit.
-		@param unit The texture unit to set the filtering options for
-		@param minFilter The filter used when a texture is reduced in size
-		@param magFilter The filter used when a texture is magnified
-		@param mipFilter The filter used between mipmap levels, FO_NONE disables mipmapping
-		*/
-		virtual void setTextureFiltering(UINT16 unit, FilterOptions minFilter,
-			FilterOptions magFilter, FilterOptions mipFilter);
-
-		/** Sets a single filter for a given texture unit.
-		@param unit The texture unit to set the filtering options for
-		@param ftype The filter type
-		@param filter The filter to be used
-		*/
-		virtual void setTextureFiltering(UINT16 unit, FilterType ftype, FilterOptions filter) = 0;
-
-		/** Sets the maximal anisotropy for the specified texture unit.*/
-		virtual void setTextureAnisotropy(UINT16 unit, unsigned int maxAnisotropy) = 0;
-
-		/** Sets the texture addressing mode for a texture unit.*/
-		virtual void setTextureAddressingMode(UINT16 unit, const UVWAddressingMode& uvw) = 0;
-
-		/** Sets the texture border color for a texture unit.*/
-		virtual void setTextureBorderColor(UINT16 unit, const Color& color) = 0;
-
-		/** Sets the mipmap bias value for a given texture unit.
-		@remarks
-		This allows you to adjust the mipmap calculation up or down for a
-		given texture unit. Negative values force a larger mipmap to be used, 
-		positive values force a smaller mipmap to be used. Units are in numbers
-		of levels, so +1 forces the mipmaps to one smaller level.
-		@note Only does something if render system has capability RSC_MIPMAP_LOD_BIAS.
-		*/
-		virtual void setTextureMipmapBias(UINT16 unit, float bias) = 0;
-
 		/** Sets the global blending factors for combining subsequent renders with the existing frame contents.
 		The result of the blending operation is:</p>
 		<p align="center">final = (texture * sourceFactor) + (pixel * destFactor)</p>

+ 1 - 1
CamelotRenderer/Include/CmSamplerState.h

@@ -92,7 +92,7 @@ namespace CamelotEngine
 		/**
 		 * @brief	Gets a border color for the specified side. Index must be >= 0 and < 4.
 		 */
-		const Color& getBorderColor(UINT32 idx);
+		const Color& getBorderColor(UINT32 idx) const;
 
 		static SamplerStatePtr create(const SAMPLER_STATE_DESC& desc);
 

+ 1 - 1
CamelotRenderer/Source/CmBlendState.cpp

@@ -46,7 +46,7 @@ namespace CamelotEngine
 	SceneBlendFactor BlendState::getAlphaDstBlend(UINT32 renderTargetIdx) const
 	{
 		assert(renderTargetIdx >= 0 && renderTargetIdx < CM_MAX_MULTIPLE_RENDER_TARGETS);
-
+		
 		return mData.renderTargetDesc[renderTargetIdx].dstBlendAlpha;
 	}
 

+ 0 - 26
CamelotRenderer/Source/CmDeferredRenderContext.cpp

@@ -50,32 +50,6 @@ namespace CamelotEngine
 		mCommandQueue->queue(boost::bind(&RenderSystem::disableTextureUnitsFrom, mRenderSystem, texUnit));
 	}
 
-	void DeferredRenderContext::setTextureFiltering(UINT16 unit, FilterOptions minFilter,
-		FilterOptions magFilter, FilterOptions mipFilter)
-	{
-		mCommandQueue->queue(boost::bind(&RenderSystem::setTextureFiltering, mRenderSystem, unit, minFilter, magFilter, mipFilter));
-	}
-
-	void DeferredRenderContext::setTextureAnisotropy(UINT16 unit, unsigned int maxAnisotropy)
-	{
-		mCommandQueue->queue(boost::bind(&RenderSystem::setTextureAnisotropy, mRenderSystem, unit, maxAnisotropy));
-	}
-
-	void DeferredRenderContext::setTextureAddressingMode(UINT16 unit, const UVWAddressingMode& uvw)
-	{
-		mCommandQueue->queue(boost::bind(&RenderSystem::setTextureAddressingMode, mRenderSystem, unit, uvw));
-	}
-
-	void DeferredRenderContext::setTextureBorderColor(UINT16 unit, const Color& color)
-	{
-		mCommandQueue->queue(boost::bind(&RenderSystem::setTextureBorderColor, mRenderSystem, unit, color));
-	}
-
-	void DeferredRenderContext::setTextureMipmapBias(UINT16 unit, float bias)
-	{
-		mCommandQueue->queue(boost::bind(&RenderSystem::setTextureMipmapBias, mRenderSystem, unit, bias));
-	}
-
 	void DeferredRenderContext::setPointParameters(float size, bool attenuationEnabled, 
 		float constant, float linear, float quadratic, float minSize, float maxSize)
 	{

+ 0 - 34
CamelotRenderer/Source/CmRenderSystem.cpp

@@ -243,30 +243,6 @@ namespace CamelotEngine {
 		THROW_IF_NOT_RENDER_THREAD;
 
         return mActiveViewport;
-    }
-	//-----------------------------------------------------------------------
-    void RenderSystem::setSamplerState(UINT16 texUnit, const SamplerState& tl)
-    {
-		THROW_IF_NOT_RENDER_THREAD;
-
-        // This method is only ever called to set a texture unit to valid details
-        // The method _disableTextureUnit is called to turn a unit off
-
-        // Set texture layer filtering
-        setTextureFiltering(texUnit, 
-            tl.getTextureFiltering(FT_MIN), 
-            tl.getTextureFiltering(FT_MAG), 
-            tl.getTextureFiltering(FT_MIP));
-
-        // Set texture layer filtering
-        setTextureAnisotropy(texUnit, tl.getTextureAnisotropy());
-
-		// Set mipmap biasing
-		setTextureMipmapBias(texUnit, tl.getTextureMipmapBias());
-
-        // Texture addressing mode
-        const UVWAddressingMode& uvw = tl.getTextureAddressingMode();
-        setTextureAddressingMode(texUnit, uvw);
     }
     //-----------------------------------------------------------------------
     void RenderSystem::disableTextureUnit(UINT16 texUnit)
@@ -288,16 +264,6 @@ namespace CamelotEngine {
         {
             disableTextureUnit(i);
         }
-    }
-    //-----------------------------------------------------------------------
-    void RenderSystem::setTextureFiltering(UINT16 unit, FilterOptions minFilter,
-            FilterOptions magFilter, FilterOptions mipFilter)
-    {
-		THROW_IF_NOT_RENDER_THREAD;
-
-        setTextureFiltering(unit, FT_MIN, minFilter);
-        setTextureFiltering(unit, FT_MAG, magFilter);
-        setTextureFiltering(unit, FT_MIP, mipFilter);
     }
 	//-----------------------------------------------------------------------
 	bool RenderSystem::getWaitForVerticalBlank(void) const

+ 1 - 1
CamelotRenderer/Source/CmSamplerState.cpp

@@ -27,7 +27,7 @@ namespace CamelotEngine
 		return mData.minFilter;
 	}
 
-	const Color& SamplerState::getBorderColor(UINT32 idx)
+	const Color& SamplerState::getBorderColor(UINT32 idx) const
 	{
 		assert(idx >= 0 && idx < 4);