Example #1
0
        public static BlendFunction Convert(SceneBlendOperation op)
        {
            switch (op)
            {
            case SceneBlendOperation.Add:
                return(BlendFunction.Add);

            case SceneBlendOperation.Subtract:
                return(BlendFunction.Subtract);

            case SceneBlendOperation.Min:
                return(BlendFunction.Min);

            case SceneBlendOperation.Max:
                return(BlendFunction.Max);

            case SceneBlendOperation.ReverseSubtract:
                return(BlendFunction.ReverseSubtract);
            }
            return(0);
        }
Example #2
0
        public static D3D9.BlendOperation ConvertEnum(SceneBlendOperation op)
        {
            switch (op)
            {
            case SceneBlendOperation.Add:
                return(D3D9.BlendOperation.Add);

            case SceneBlendOperation.Subtract:
                return(D3D9.BlendOperation.Subtract);

            case SceneBlendOperation.ReverseSubtract:
                return(D3D9.BlendOperation.ReverseSubtract);

            case SceneBlendOperation.Min:
                return(D3D9.BlendOperation.Minimum);

            case SceneBlendOperation.Max:
                return(D3D9.BlendOperation.Maximum);
            }
            ;

            return((D3D9.BlendOperation) 0x7fffffff);           //D3DBLENDOP_FORCE_DWORD
        }
Example #3
0
        public override void SetSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha,
            SceneBlendFactor destFactorAlpha, SceneBlendOperation op = SceneBlendOperation.Add, SceneBlendOperation alphaOp = SceneBlendOperation.Add )
        {
            if ( sourceFactor == SceneBlendFactor.One && destFactor == SceneBlendFactor.Zero &&
                 sourceFactorAlpha == SceneBlendFactor.One && destFactorAlpha == SceneBlendFactor.Zero )
            {
                SetRenderState( RenderState.AlphaBlendEnable, false );
            }
            else
            {
                SetRenderState( RenderState.AlphaBlendEnable, true );
                SetRenderState( RenderState.SeparateAlphaBlendEnable, true );
                SetRenderState( RenderState.SourceBlend, (int)D3DHelper.ConvertEnum( sourceFactor ) );
                SetRenderState( RenderState.DestinationBlend, (int)D3DHelper.ConvertEnum( destFactor ) );
                SetRenderState( RenderState.SourceBlendAlpha, (int)D3DHelper.ConvertEnum( sourceFactorAlpha ) );
                SetRenderState( RenderState.DestinationBlendAlpha, (int)D3DHelper.ConvertEnum( destFactorAlpha ) );
            }

            SetRenderState(RenderState.BlendOperation, (int)D3DHelper.ConvertEnum(op));
            SetRenderState(RenderState.BlendOperationAlpha, (int)D3DHelper.ConvertEnum(alphaOp));
        }
Example #4
0
        public override void SetSceneBlending(SceneBlendFactor src, SceneBlendFactor dest, SceneBlendOperation op = SceneBlendOperation.Add)
        {
            // set the render states after converting the incoming values to D3D.Blend
            if ( src == SceneBlendFactor.One && dest == SceneBlendFactor.Zero )
            {
                SetRenderState( RenderState.AlphaBlendEnable, false );
            }
            else
            {
                SetRenderState( RenderState.AlphaBlendEnable, true );
                SetRenderState( RenderState.SeparateAlphaBlendEnable, false );
                SetRenderState( RenderState.SourceBlend, (int)D3DHelper.ConvertEnum( src ) );
                SetRenderState( RenderState.DestinationBlend, (int)D3DHelper.ConvertEnum( dest ) );
            }

            SetRenderState( RenderState.BlendOperation, (int)D3DHelper.ConvertEnum( op ) );
            SetRenderState( RenderState.BlendOperationAlpha, (int)D3DHelper.ConvertEnum( op ) );
        }
Example #5
0
		public void SetSeparateSceneBlendingOperation( SceneBlendOperation op, SceneBlendOperation alphaOp )
		{
		}
Example #6
0
		public void SetSceneBlendingOperation( SceneBlendOperation op )
		{
		}
Example #7
0
		public override void SetSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp )
		{
			var sourceBlend = this.GetBlendMode( sourceFactor );
			var destBlend = this.GetBlendMode( destFactor );
			var sourceBlendAlpha = this.GetBlendMode( sourceFactorAlpha );
			var destBlendAlpha = this.GetBlendMode( destFactorAlpha );

			if ( sourceFactor == SceneBlendFactor.One && destFactor == SceneBlendFactor.Zero && sourceFactorAlpha == SceneBlendFactor.One && destFactorAlpha == SceneBlendFactor.Zero )
			{
				GL.Disable( All.Blend );
				GLES2Config.GlCheckError( this );
			}
			else
			{
				GL.Enable( All.Blend );
				GLES2Config.GlCheckError( this );
				GL.BlendFuncSeparate( sourceBlend, destBlend, sourceBlendAlpha, destBlendAlpha );
				GLES2Config.GlCheckError( this );
			}
			All func = All.FuncAdd, alphaFunc = All.FuncAdd;

			switch ( op )
			{
				case SceneBlendOperation.Add:
					func = All.FuncAdd;
					break;
				case SceneBlendOperation.Subtract:
					func = All.FuncSubtract;
					break;
				case SceneBlendOperation.ReverseSubtract:
					func = All.FuncReverseSubtract;
					break;
				case SceneBlendOperation.Min:
					//#if GL_EXT_blend_minmax
					//func = Alll.MinExt;
					//#endif
					break;
				case SceneBlendOperation.Max:
					//#if GL_EXT_blend_minmax
					//func = Alll.MaxExt;
					//#endif
					break;
			}

			switch ( alphaOp )
			{
				case SceneBlendOperation.Add:
					alphaFunc = All.FuncAdd;
					break;
				case SceneBlendOperation.Subtract:
					alphaFunc = All.FuncSubtract;
					break;
				case SceneBlendOperation.ReverseSubtract:
					alphaFunc = All.FuncReverseSubtract;
					break;
				case SceneBlendOperation.Min:
					//#if GL_EXT_blend_minmax
					//func = Alll.MinExt;
					//#endif
					break;
				case SceneBlendOperation.Max:
					//#if GL_EXT_blend_minmax
					//func = Alll.MaxExt;
					//#endif
					break;
				default:
					break;
			}

			GL.BlendEquationSeparate( func, alphaFunc );
			GLES2Config.GlCheckError( this );
		}
Example #8
0
		public override void SetSceneBlending( SceneBlendFactor src, SceneBlendFactor dest, SceneBlendOperation op )
		{
			var sourceBlend = this.GetBlendMode( src );
			var destBlend = this.GetBlendMode( dest );

			if ( src == SceneBlendFactor.One && dest == SceneBlendFactor.Zero )
			{
				GL.Disable( All.Blend );
				GLES2Config.GlCheckError( this );
			}
			else
			{
				GL.Enable( All.Blend );
				GLES2Config.GlCheckError( this );
				GL.BlendFunc( sourceBlend, destBlend );
				GLES2Config.GlCheckError( this );
			}

			var func = All.FuncAdd;
			switch ( op )
			{
				case SceneBlendOperation.Add:
					func = All.FuncAdd;
					break;
				case SceneBlendOperation.Subtract:
					func = All.FuncSubtract;
					break;
				case SceneBlendOperation.ReverseSubtract:
					func = All.FuncReverseSubtract;
					break;
				case SceneBlendOperation.Min:
					//#if GL_EXT_blend_minmax
					//func = Alll.MinExt;
					//#endif
					break;
				case SceneBlendOperation.Max:
					//#if GL_EXT_blend_minmax
					//func = Alll.MaxExt;
					//#endif
					break;
			}

			GL.BlendEquation( func );
			GLES2Config.GlCheckError( this );
		}
Example #9
0
		/// <summary>
		/// Sets the global blending factors for combining subsequent renders with the existing frame contents.
		/// The result of the blending operation is:
		/// <p align="center">final = (texture * src) + (pixel * dest)</p>
		/// Each of the factors is specified as one of a number of options, as specified in the SceneBlendFactor
		/// enumerated type.
		/// </summary>
		/// <param name="src">The source factor in the above calculation, i.e. multiplied by the texture color components.</param>
		/// <param name="dest">The destination factor in the above calculation, i.e. multiplied by the pixel color components.</param>
		/// <param name="op">The blend operation mode for combining pixels</param>
		public override void SetSceneBlending(SceneBlendFactor src, SceneBlendFactor dest, SceneBlendOperation op)
		{
			StateManager.BlendState.AlphaSourceBlend = XnaHelper.Convert(src);
			StateManager.BlendState.AlphaDestinationBlend = XnaHelper.Convert(dest);
			StateManager.BlendState.AlphaBlendFunction = XnaHelper.Convert(op);
			/**/
			StateManager.BlendState.ColorSourceBlend = XnaHelper.Convert( src );
			StateManager.BlendState.ColorDestinationBlend = XnaHelper.Convert( dest );
			/**/
			StateManager.BlendState.ColorSourceBlend = StateManager.BlendState.AlphaSourceBlend;
			StateManager.BlendState.ColorDestinationBlend = StateManager.BlendState.AlphaDestinationBlend;
			/**/
			//TODO use SceneBlendOperation
			StateManager.BlendState.ColorBlendFunction = StateManager.BlendState.AlphaBlendFunction;
		}

		#endregion

		#region SetSeparateSceneBlending

		/// <summary>
		/// Sets the global blending factors for combining subsequent renders with the existing frame contents.
		/// The result of the blending operation is:
		/// final = (texture * sourceFactor) + (pixel * destFactor).
		/// Each of the factors is specified as one of a number of options, as specified in the SceneBlendFactor
		/// enumerated type.
		/// </summary>
		/// <param name="sourceFactor">The source factor in the above calculation, i.e. multiplied by the texture color components.</param>
		/// <param name="destFactor">The destination factor in the above calculation, i.e. multiplied by the pixel color components.</param>
		/// <param name="sourceFactorAlpha">The source factor in the above calculation for the alpha channel, i.e. multiplied by the texture alpha components.</param>
		/// <param name="destFactorAlpha">The destination factor in the above calculation for the alpha channel, i.e. multiplied by the pixel alpha components.</param>
		/// <param name="op">The blend operation mode for combining pixels</param>
		/// <param name="alphaOp">The blend operation mode for combining pixel alpha values</param>
		public override void SetSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor,
													   SceneBlendFactor sourceFactorAlpha,
													   SceneBlendFactor destFactorAlpha, SceneBlendOperation op,
													   SceneBlendOperation alphaOp)
		{
			StateManager.BlendState.ColorSourceBlend = XnaHelper.Convert(sourceFactor);
			StateManager.BlendState.ColorDestinationBlend = XnaHelper.Convert(destFactor);
			StateManager.BlendState.AlphaSourceBlend = XnaHelper.Convert(sourceFactorAlpha);
			StateManager.BlendState.AlphaDestinationBlend = XnaHelper.Convert(destFactorAlpha);
			StateManager.BlendState.ColorBlendFunction = XnaHelper.Convert(op);
			StateManager.BlendState.AlphaBlendFunction = XnaHelper.Convert(alphaOp);
		}

		#endregion

		#region SetScissorTest

		/// <summary>
		/// Sets the 'scissor region' ie the region of the target in which rendering can take place.
		/// </summary>
		/// <remarks>
		/// This method allows you to 'mask off' rendering in all but a given rectangular area
		/// as identified by the parameters to this method.
		/// <p/>
		/// Not all systems support this method. Check the <see cref="Capabilities"/> enum for the
		/// ScissorTest capability to see if it is supported.
		/// </remarks>
		/// <param name="enable">True to enable the scissor test, false to disable it.</param>
		/// <param name="left">Left corner (in pixels).</param>
		/// <param name="top">Top corner (in pixels).</param>
		/// <param name="right">Right corner (in pixels).</param>
		/// <param name="bottom">Bottom corner (in pixels).</param>
		public override void SetScissorTest(bool enable, int left, int top, int right, int bottom)
		{
			if (enable)
			{
				_device.ScissorRectangle = new Rectangle(left, top, right - left, bottom - top);
				StateManager.RasterizerState.ScissorTestEnable = true;
			}
			else
			{
				StateManager.RasterizerState.ScissorTestEnable = false;
			}
		}

		#endregion

		#region SetStencilBufferParams

		/// <summary>
		/// This method allows you to set all the stencil buffer parameters in one call.
		/// </summary>
		/// <remarks>
		/// <para>
		/// The stencil buffer is used to mask out pixels in the render target, allowing
		/// you to do effects like mirrors, cut-outs, stencil shadows and more. Each of
		/// your batches of rendering is likely to ignore the stencil buffer, 
		/// update it with new values, or apply it to mask the output of the render.
		/// The stencil test is:<PRE>
		/// (Reference Value &amp; Mask) CompareFunction (Stencil Buffer Value &amp; Mask)</PRE>
		/// The result of this will cause one of 3 actions depending on whether the test fails,
		/// succeeds but with the depth buffer check still failing, or succeeds with the
		/// depth buffer check passing too.</para>
		/// <para>
		/// Unlike other render states, stencilling is left for the application to turn
		/// on and off when it requires. This is because you are likely to want to change
		/// parameters between batches of arbitrary objects and control the ordering yourself.
		/// In order to batch things this way, you'll want to use OGRE's separate render queue
		/// groups (see RenderQueue) and register a RenderQueueListener to get notifications
		/// between batches.</para>
		/// <para>
		/// There are individual state change methods for each of the parameters set using 
		/// this method. 
		/// Note that the default values in this method represent the defaults at system 
		/// start up too.</para>
		/// </remarks>
		/// <param name="function">The comparison function applied.</param>
		/// <param name="refValue">The reference value used in the comparison.</param>
		/// <param name="mask">
		/// The bitmask applied to both the stencil value and the reference value 
		/// before comparison.
		/// </param>
		/// <param name="stencilFailOp">The action to perform when the stencil check fails.</param>
		/// <param name="depthFailOp">
		/// The action to perform when the stencil check passes, but the depth buffer check still fails.
		/// </param>
		/// <param name="passOp">The action to take when both the stencil and depth check pass.</param>
		/// <param name="twoSidedOperation">
		/// If set to true, then if you render both back and front faces 
		/// (you'll have to turn off culling) then these parameters will apply for front faces, 
		/// and the inverse of them will happen for back faces (keep remains the same).
		/// </param>
		public override void SetStencilBufferParams(CompareFunction function, int refValue, int mask,
													 StencilOperation stencilFailOp, StencilOperation depthFailOp,
													 StencilOperation passOp, bool twoSidedOperation)
		{
			bool flip;
			// 2 sided operation?
			if (twoSidedOperation)
			{
				//if ( !HardwareCapabilities.HasCapability( Capabilities.TwoSidedStencil ) )
				//{
				//    throw new AxiomException( "2-sided stencils are not supported on this hardware!" );
				//}
				StateManager.DepthStencilState.TwoSidedStencilMode = true;
				flip = (invertVertexWinding && activeRenderTarget.RequiresTextureFlipping) ||
					   (!invertVertexWinding && !activeRenderTarget.RequiresTextureFlipping);

				StateManager.DepthStencilState.StencilFail = XnaHelper.Convert(stencilFailOp, !flip);
				StateManager.DepthStencilState.StencilDepthBufferFail = XnaHelper.Convert(depthFailOp, !flip);
				StateManager.DepthStencilState.StencilPass = XnaHelper.Convert(passOp, !flip);
			}
			else
			{
				StateManager.DepthStencilState.TwoSidedStencilMode = false;
				flip = false;
			}

			// configure standard version of the stencil operations
			StateManager.DepthStencilState.StencilFunction = XnaHelper.Convert(function);
			StateManager.DepthStencilState.ReferenceStencil = refValue;
			StateManager.DepthStencilState.StencilMask = mask;
			StateManager.DepthStencilState.StencilFail = XnaHelper.Convert(stencilFailOp, flip);
			StateManager.DepthStencilState.StencilDepthBufferFail = XnaHelper.Convert(depthFailOp, flip);
			StateManager.DepthStencilState.StencilPass = XnaHelper.Convert(passOp, flip);
			StateManager.BlendState.ColorWriteChannels = ColorWriteChannels.None;
		}

		#endregion

		#region SetSurfaceParams

		/// <summary>
		/// Sets the surface properties to be used for future rendering.
		/// 
		/// This method sets the the properties of the surfaces of objects
		/// to be rendered after it. In this context these surface properties
		/// are the amount of each type of light the object reflects (determining
		/// it's color under different types of light), whether it emits light
		/// itself, and how shiny it is. Textures are not dealt with here,
		/// <see cref="SetTexture(int, bool, Texture)"/> method for details.
		/// This method is used by SetMaterial so does not need to be called
		/// direct if that method is being used.
		/// </summary>
		/// <param name="ambient">
		/// The amount of ambient (sourceless and directionless)
		/// light an object reflects. Affected by the color/amount of ambient light in the scene.
		/// </param>
		/// <param name="diffuse">
		/// The amount of light from directed sources that is
		/// reflected (affected by color/amount of point, directed and spot light sources)
		/// </param>
		/// <param name="specular">
		/// The amount of specular light reflected. This is also
		/// affected by directed light sources but represents the color at the
		/// highlights of the object.
		/// </param>
		/// <param name="emissive">
		/// The color of light emitted from the object. Note that
		/// this will make an object seem brighter and not dependent on lights in
		/// the scene, but it will not act as a light, so will not illuminate other
		/// objects. Use a light attached to the same SceneNode as the object for this purpose.
		/// </param>
		/// <param name="shininess">
		/// A value which only has an effect on specular highlights (so
		/// specular must be non-black). The higher this value, the smaller and crisper the
		/// specular highlights will be, imitating a more highly polished surface.
		/// This value is not constrained to 0.0-1.0, in fact it is likely to
		/// be more (10.0 gives a modest sheen to an object).
		/// </param>
		/// <param name="tracking">
		/// A bit field that describes which of the ambient, diffuse, specular
		/// and emissive colors follow the vertex color of the primitive. When a bit in this field is set
		/// its colorValue is ignored. This is a combination of TVC_AMBIENT, TVC_DIFFUSE, TVC_SPECULAR(note that the shininess value is still
		/// taken from shininess) and TVC_EMISSIVE. TVC_NONE means that there will be no material property
		/// tracking the vertex colors.
		/// </param>
		public override void SetSurfaceParams(ColorEx ambient, ColorEx diffuse, ColorEx specular, ColorEx emissive, Real shininess, TrackVertexColor tracking)
		{
			/*/
			//basicEffect.Alpha;
			//basicEffect.AmbientLightColor;
			//basicEffect.DiffuseColor;
			basicEffect.DirectionalLight0;
			basicEffect.DirectionalLight1;
			basicEffect.DirectionalLight2;
			//basicEffect.EmissiveColor;
			basicEffect.EnableDefaultLighting();
			//basicEffect.FogColor;
			//basicEffect.FogEnabled;
			//basicEffect.FogEnd;
			//basicEffect.FogStart;
			//basicEffect.LightingEnabled;
			basicEffect.PreferPerPixelLighting;
			//basicEffect.Projection;
			//basicEffect.SpecularColor;
			//basicEffect.SpecularPower;
			//basicEffect.Texture;
			//basicEffect.TextureEnabled;
			//basicEffect.VertexColorEnabled;
			//basicEffect.View;
			//basicEffect.World;
			/**/

			//basicEffect.EnableDefaultLighting();
			//basicEffect.PreferPerPixelLighting = true;

			if (ambient == ColorEx.White &&
				diffuse == ColorEx.Black &&
				emissive == ColorEx.Black &&
				specular == ColorEx.Black &&
				shininess == 0
				)
			{
				//_fixedFunctionState.MaterialEnabled = false;
				basicEffect.AmbientLightColor = Color.White.ToVector3();
				basicEffect.DiffuseColor = Color.White.ToVector3();
			}
			else
			{
				//_fixedFunctionState.MaterialEnabled = true;
				basicEffect.AmbientLightColor = XnaHelper.Convert( ambient ).ToVector3();
				basicEffect.DiffuseColor = XnaHelper.Convert( diffuse ).ToVector3();
			}
			basicEffect.SpecularColor = XnaHelper.Convert(specular).ToVector3();
			basicEffect.EmissiveColor = XnaHelper.Convert(emissive).ToVector3();
			basicEffect.SpecularPower = shininess;
			try
			{

				skinnedEffect.AmbientLightColor = basicEffect.AmbientLightColor;
				skinnedEffect.DiffuseColor = basicEffect.DiffuseColor;
				skinnedEffect.SpecularColor = basicEffect.SpecularColor;
				skinnedEffect.EmissiveColor = basicEffect.EmissiveColor;
				skinnedEffect.SpecularPower = basicEffect.SpecularPower;
			}
			catch ( Exception ex )
			{
			}
#if AXIOM_FF_EMULATION
			if (//ambient == ColorEx.White &&
				diffuse == ColorEx.Black //&&
				//emissive == ColorEx.Black &&
				//specular == ColorEx.Black &&
				//shininess == 0
				)
			{
				//_fixedFunctionState.MaterialEnabled = false;
				_ffProgramParameters.MaterialAmbient = new ColorEx( 0, 1, 1, 1 );
				_ffProgramParameters.MaterialDiffuse = ColorEx.White;
				_ffProgramParameters.MaterialSpecular = ColorEx.Black;
			}
			else
			{
				//_fixedFunctionState.MaterialEnabled = true;
				_ffProgramParameters.MaterialAmbient = ambient;
				_ffProgramParameters.MaterialDiffuse = diffuse;
				_ffProgramParameters.MaterialSpecular = specular;
				//_ffProgramParameters.MaterialEmissive = emissive;
				//_ffProgramParameters.MaterialShininess = shininess;
			}
#endif
		}

		#endregion

		#region SetPointParameters

		/// <summary>
		/// Sets the size of points and how they are attenuated with distance.
		/// <remarks>
		/// When performing point rendering or point sprite rendering,
		/// point size can be attenuated with distance. The equation for
		/// doing this is attenuation = 1 / (constant + linear * dist + quadratic * d^2) .
		/// </remarks>
		/// </summary>
		public override void SetPointParameters(Real size, bool attenuationEnabled, Real constant, Real linear,
												 Real quadratic, Real minSize, Real maxSize)
		{
			throw new AxiomException("XNA does not support PointSprites.");
		}

		#endregion

		#region SetTexture

		/// <summary>
		/// Sets the texture to bind to a given texture unit.
		/// 
		/// User processes would not normally call this direct unless rendering
		/// primitives themselves.
		/// </summary>
		/// <param name="unit">
		/// The index of the texture unit to modify. Multitexturing
		/// hardware can support multiple units <see cref="RenderSystemCapabilities.TextureUnitCount"/> 
		/// </param>
		/// <param name="enabled"></param>
		/// <param name="texture"></param>
		public override void SetTexture(int stage, bool enabled, Texture texture)
		{
			var xnaTexture = (XnaTexture)texture;
			var compensateNPOT = false;

			if ((texture != null) && (!Bitwise.IsPow2(texture.Width) || !Bitwise.IsPow2(texture.Height)))
			{
				if (Capabilities.HasCapability(Graphics.Capabilities.NonPowerOf2Textures))
				{
					if (Capabilities.NonPOW2TexturesLimited)
						compensateNPOT = true;
				}
				else
					compensateNPOT = true;

				if (compensateNPOT)
				{
					SetTextureAddressingMode(stage, new UVWAddressing(TextureAddressing.Clamp));
				}
			}

			texStageDesc[stage].Enabled = enabled;
			if (enabled && xnaTexture != null)
			{
				_device.Textures[stage] = xnaTexture.DXTexture;
				// TODO: NRSC: Solve cast problem for non Texture2D 
				basicEffect.Texture = xnaTexture.DXTexture as Texture2D;
				try
				{

					basicEffect.TextureEnabled = basicEffect.Texture != null;
				}
				catch ( Exception ex )
				{
					SetTextureAddressingMode( stage, new UVWAddressing( TextureAddressing.Clamp ) );
				}
				finally
				{
					basicEffect.TextureEnabled = basicEffect.Texture != null;
				}

				skinnedEffect.Texture = basicEffect.Texture;

				// set stage description
				texStageDesc[stage].tex = xnaTexture.DXTexture;
				texStageDesc[stage].texType = xnaTexture.TextureType;

				var state = StateManager.SamplerStates[stage];
				if (
#if !SILVERLIGHT
					_device.GraphicsProfile == GraphicsProfile.Reach && 
#endif
					!( (XnaTexture)texture ).IsPowerOfTwo )
				{
					state.AddressU = TextureAddressMode.Clamp;
					state.AddressV = TextureAddressMode.Clamp;
					state.AddressW = TextureAddressMode.Clamp;
				}
				else
				{
					state.AddressU = TextureAddressMode.Wrap;
					state.AddressV = TextureAddressMode.Wrap;
					state.AddressW = TextureAddressMode.Wrap;
				}
			}
			else
			{
				if (texStageDesc[stage].tex != null)
				{
					_device.Textures[stage] = null;
				}
				// set stage description to defaults
				texStageDesc[stage].tex = null;
				texStageDesc[stage].autoTexCoordType = TexCoordCalcMethod.None;
				texStageDesc[stage].coordIndex = 0;
				texStageDesc[stage].texType = TextureType.OneD;
			}
#if AXIOM_FF_EMULATION
			_ffProgramParameters.SetTextureEnabled( stage, enabled );
#endif
		}

		#endregion

		#region SetTextureAddressingMode

		/// <summary>
		/// Tells the hardware how to treat texture coordinates.
		/// </summary>
		public override void SetTextureAddressingMode(int stage, UVWAddressing uvw)
		{
			if (_device.GetVertexBuffers().Length == 0)
			{
				return;
			}
			if (
				!(from VertexElement vde in
					  _device.GetVertexBuffers()[0].VertexBuffer.VertexDeclaration.GetVertexElements()
				  where vde.VertexElementUsage == VertexElementUsage.Normal
				  select vde).Any())
			{
				return;
			}

			var xnaTexture = _device.Textures[stage] as Texture2D;
			var compensateNPOT = false;

			if ((xnaTexture != null) &&
				 (!Bitwise.IsPow2(xnaTexture.Width) || !Bitwise.IsPow2(xnaTexture.Height)))
			{
				if (Capabilities.HasCapability(Graphics.Capabilities.NonPowerOf2Textures))
				{
					if (Capabilities.NonPOW2TexturesLimited)
						compensateNPOT = true;
					}
				else
					compensateNPOT = true;

				if (compensateNPOT)
				{
					uvw = new UVWAddressing( TextureAddressing.Clamp );
				}
			}

			// set the device sampler states accordingly
			StateManager.SamplerStates[ stage ].AddressU = XnaHelper.Convert( uvw.U );
			StateManager.SamplerStates[ stage ].AddressV = XnaHelper.Convert( uvw.V );
			StateManager.SamplerStates[ stage ].AddressW = XnaHelper.Convert( uvw.W );
		}

		#endregion

		#region SetTextureMipmapBias

		/// <summary>
		/// Sets the mipmap bias value for a given texture unit.
		/// </summary>
		/// <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.
		/// </remarks>
		/// <note>Only does something if render system has capability RSC_MIPMAP_LOD_BIAS.</note>
		public override void SetTextureMipmapBias(int unit, float bias)
		{
			if (currentCapabilities.HasCapability(Graphics.Capabilities.MipmapLODBias))
			{
				var ss = _device.SamplerStates[unit];
				_device.SamplerStates[unit] = new SamplerState
				{
					MipMapLevelOfDetailBias = bias,
					MaxMipLevel = ss.MaxMipLevel,
					MaxAnisotropy = ss.MaxAnisotropy,
#if ! SILVERLIGHT
					AddressW = ss.AddressW,
#endif
					AddressV = ss.AddressV,
					AddressU = ss.AddressU,
					Filter = ss.Filter,
				};
			}
		}

		#endregion

		#region SetTextureBorderColor

		/// <summary>
		/// Tells the hardware what border color to use when texture addressing mode is set to Border
		/// </summary>
		/// <param name="unit"></param>
		/// <param name="borderColor"></param>
		public override void SetTextureBorderColor(int stage, ColorEx borderColor)
		{
			//texStageDesc[ stage ].borderColor = borderColor;
		}

		#endregion

		#region SetTextureBlendMode

		/// <summary>
		/// Sets the texture blend modes from a TextureLayer record.
		/// Meant for use internally only - apps should use the Material
		/// and TextureLayer classes.
		/// </summary>
		/// <param name="unit">Texture unit.</param>
		/// <param name="bm">Details of the blending modes.</param>
		public override void SetTextureBlendMode(int stage, LayerBlendModeEx blendMode)
		{
			basicEffect.Alpha = 1.0f;
			skinnedEffect.Alpha = 1.0f;

			if (blendMode.blendType == LayerBlendType.Color)
			{
				texStageDesc[stage].layerBlendMode = blendMode;
			}
			/* TODO: use StateManager.BlendState */

			if (blendMode.operation == LayerBlendOperationEx.BlendManual)
			{
				StateManager.BlendState.BlendFactor = new Color(blendMode.blendFactor, 0, 0, 0);
			}
			if (blendMode.blendType == LayerBlendType.Color)
			{
				//_device.RenderState.AlphaBlendEnable = false;
			}
			else if (blendMode.blendType == LayerBlendType.Alpha)
			{
				//_device.RenderState.AlphaBlendEnable = true;
			}

			var manualD3D = XnaHelper.Convert(StateManager.BlendState.BlendFactor);
			if (blendMode.blendType == LayerBlendType.Color)
			{
				manualD3D = new ColorEx(blendMode.blendFactor, blendMode.colorArg1.r, blendMode.colorArg1.g,
										 blendMode.colorArg1.b);
			}
			else if (blendMode.blendType == LayerBlendType.Alpha)
			{
				manualD3D = new ColorEx(blendMode.alphaArg1, blendMode.blendFactor, blendMode.blendFactor,
										 blendMode.blendFactor);
			}

			var blendSource = blendMode.source1;
			for (var i = 0; i < 2; i++)
			{
				// set the texture blend factor if this is manual blending
				if (blendSource == LayerBlendSource.Manual)
				{
					StateManager.BlendState.BlendFactor = XnaHelper.Convert(manualD3D);
				}
				// pick proper argument settings
				if (blendMode.blendType == LayerBlendType.Color)
				{
					if (i == 0)
					{
						texStageDesc[stage].layerBlendMode.colorArg1 = blendMode.colorArg1;
					}
					else if (i == 1)
					{
						texStageDesc[stage].layerBlendMode.colorArg2 = blendMode.colorArg2;
					}
				}
				else if (blendMode.blendType == LayerBlendType.Alpha)
				{
					if (i == 0)
					{
						texStageDesc[stage].layerBlendMode.alphaArg1 = blendMode.alphaArg1;
						basicEffect.Alpha = blendMode.alphaArg1;
					}
					else if (i == 1)
					{
						texStageDesc[stage].layerBlendMode.alphaArg2 = blendMode.alphaArg2;
						basicEffect.Alpha = blendMode.alphaArg2;
					}
					skinnedEffect.Alpha = basicEffect.Alpha;
				}
				// Source2
				blendSource = blendMode.source2;
				if (blendMode.blendType == LayerBlendType.Color)
				{
					manualD3D = new ColorEx(manualD3D.a, blendMode.colorArg2.r, blendMode.colorArg2.g,
											 blendMode.colorArg2.b);
				}
				else if (blendMode.blendType == LayerBlendType.Alpha)
				{
					manualD3D = new ColorEx(blendMode.alphaArg2, manualD3D.r, manualD3D.g, manualD3D.b);
				}
			}
		}
Example #10
0
	    public static D3D.BlendOperation ConvertEnum( SceneBlendOperation op )
	    {
            switch (op)
            {
                case SceneBlendOperation.Add:
                    return D3D.BlendOperation.Add;
                case SceneBlendOperation.Max:
                    return D3D.BlendOperation.Maximum;
                case SceneBlendOperation.Min:
                    return D3D.BlendOperation.Minimum;
                case SceneBlendOperation.ReverseSubtract:
                    return D3D.BlendOperation.ReverseSubtract;
                case SceneBlendOperation.Subtract:
                    return D3D.BlendOperation.Subtract;
                default:
                    throw new NotImplementedException();
            }
	    }
Example #11
0
        public override void SetSeparateSceneBlending( 
            SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, 
            SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha,
            SceneBlendOperation op, SceneBlendOperation alphaOp)
		{
			int sourceBlend = GLHelper.ConvertEnum( sourceFactor );
			int destBlend = GLHelper.ConvertEnum( destFactor );
			int sourceBlendAlpha = GLHelper.ConvertEnum( sourceFactorAlpha );
			int destBlendAlpha = GLHelper.ConvertEnum( destFactorAlpha );

			if ( sourceFactor == SceneBlendFactor.One && destFactor == SceneBlendFactor.Zero &&
				sourceFactorAlpha == SceneBlendFactor.One && destFactorAlpha == SceneBlendFactor.Zero )
			{
				Gl.glDisable( Gl.GL_BLEND );
			}
			else
			{
				Gl.glEnable( Gl.GL_BLEND );
				Gl.glBlendFuncSeparate( sourceBlend, destBlend, sourceBlendAlpha, destBlendAlpha );
			}

            var func = Gl.GL_FUNC_ADD;
            var alphaFunc = Gl.GL_FUNC_ADD;

            switch (op)
            {
                case SceneBlendOperation.Add:
                    func = Gl.GL_FUNC_ADD;
                    break;
                case SceneBlendOperation.Subtract:
                    func = Gl.GL_FUNC_SUBTRACT;
                    break;
                case SceneBlendOperation.ReverseSubtract:
                    func = Gl.GL_FUNC_REVERSE_SUBTRACT;
                    break;
                case SceneBlendOperation.Min:
                    func = Gl.GL_MIN;
                    break;
                case SceneBlendOperation.Max:
                    func = Gl.GL_MAX;
                    break;
            }

            switch (alphaOp)
            {
                case SceneBlendOperation.Add:
                    alphaFunc = Gl.GL_FUNC_ADD;
                    break;
                case SceneBlendOperation.Subtract:
                    alphaFunc = Gl.GL_FUNC_SUBTRACT;
                    break;
                case SceneBlendOperation.ReverseSubtract:
                    alphaFunc = Gl.GL_FUNC_REVERSE_SUBTRACT;
                    break;
                case SceneBlendOperation.Min:
                    alphaFunc = Gl.GL_MIN;
                    break;
                case SceneBlendOperation.Max:
                    alphaFunc = Gl.GL_MAX;
                    break;
            }

            if (GLEW_VERSION_2_0)
            {
                Gl.glBlendEquationSeparate(func, alphaFunc);
            }
            else if (GLEW_EXT_blend_equation_separate)
            {
                Gl.glBlendEquationSeparateEXT(func, alphaFunc);
            }
		}
Example #12
0
		public override void SetSceneBlending( SceneBlendFactor src, SceneBlendFactor dest,
            SceneBlendOperation op)
		{
            int srcFactor = GLHelper.ConvertEnum( src );
            int destFactor = GLHelper.ConvertEnum( dest );

            if ( src == SceneBlendFactor.One && dest == SceneBlendFactor.Zero )
            {
                Gl.glDisable( Gl.GL_BLEND );
            }
            else
            {
                // enable blending and set the blend function
                Gl.glEnable( Gl.GL_BLEND );
                Gl.glBlendFunc( srcFactor, destFactor );
            }

            var func = Gl.GL_FUNC_ADD;
            switch (op)
            {
                case SceneBlendOperation.Add:
                    func = Gl.GL_FUNC_ADD;
                    break;
                case SceneBlendOperation.Subtract:
                    func = Gl.GL_FUNC_SUBTRACT;
                    break;
                case SceneBlendOperation.ReverseSubtract:
                    func = Gl.GL_FUNC_REVERSE_SUBTRACT;
                    break;
                case SceneBlendOperation.Min:
                    func = Gl.GL_MIN;
                    break;
                case SceneBlendOperation.Max:
                    func = Gl.GL_MAX;
                    break;
            }

            if (GLEW_VERSION_1_4 || GLEW_ARB_imaging)
            {
                Gl.glBlendEquation(func);
            }
            else if (GLEW_EXT_blend_minmax && (func == Gl.GL_MIN || func == Gl.GL_MAX))
            {
                Gl.glBlendEquationEXT(func);
            }
		}
Example #13
0
		public static BlendFunction Convert(SceneBlendOperation op)
		{
			switch (op)
			{
				case SceneBlendOperation.Add:
					return BlendFunction.Add;
				case SceneBlendOperation.Subtract:
					return BlendFunction.Subtract;
				case SceneBlendOperation.Min:
					return BlendFunction.Min;
				case SceneBlendOperation.Max:
					return BlendFunction.Max;
				case SceneBlendOperation.ReverseSubtract:
					return BlendFunction.ReverseSubtract;
			}
			return 0;
		}
Example #14
0
		public static D3D9.BlendOperation ConvertEnum( SceneBlendOperation op )
		{
			switch ( op )
			{
				case SceneBlendOperation.Add:
					return D3D9.BlendOperation.Add;

				case SceneBlendOperation.Subtract:
					return D3D9.BlendOperation.Subtract;

				case SceneBlendOperation.ReverseSubtract:
					return D3D9.BlendOperation.ReverseSubtract;

				case SceneBlendOperation.Min:
					return D3D9.BlendOperation.Minimum;

				case SceneBlendOperation.Max:
					return D3D9.BlendOperation.Maximum;
			}
			;

			return (D3D9.BlendOperation)0x7fffffff; //D3DBLENDOP_FORCE_DWORD
		}
Example #15
0
		public void SetSeparateSceneBlendingOperation( SceneBlendOperation op, SceneBlendOperation alphaOp )
		{
			this.blendOperation = op;
			this.slphaBlendOperation = alphaOp;
			this.separateBlendOperation = true;
		}