Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        public void Begin(PipelineState ps, SamplerState ss = null, DepthStencilState dss = null, Matrix?transform = null, Rectangle?clip = null)
        {
            if (ps == null)
            {
                throw new ArgumentNullException("ps");
            }

            pipelineState     = ps;
            samplerState      = ss ?? SamplerState.LinearWrap;
            depthStencilState = dss ?? DepthStencilState.Readonly;

            int w   = device.DisplayBounds.Width;
            int h   = device.DisplayBounds.Height;
            var ofs = 0.0f;

            Matrix sbTransform;

            if (transform.HasValue)
            {
                sbTransform = transform.Value;
            }
            else
            {
                sbTransform = Matrix.OrthoOffCenterRH(ofs, w + ofs, h + ofs, ofs, -9999, 9999);
            }

            Vector4 clipRect = new Vector4(0, 0, w, h);

            if (clip.HasValue)
            {
                clipRect.X = clip.Value.X;
                clipRect.Y = clip.Value.Y;
                clipRect.Z = clip.Value.Width;
                clipRect.W = clip.Value.Height;
            }

            device.PipelineState          = pipelineState;
            device.PixelShaderSamplers[0] = samplerState;

            constData.Transform     = sbTransform;
            constData.ClipRectangle = clipRect;
            constBuffer.SetData(constData);
        }
Exemplo n.º 2
0
        void EnumAction( PipelineState ps, Flags flag )
        {
            ps.Primitive			=	Primitive.PointList;
            ps.VertexInputElements	=	VertexInputElement.FromStructure<ParticleVertex>();
            ps.DepthStencilState	=	DepthStencilState.None;

            var outputElements = new[]{
                new VertexOutputElement("SV_POSITION", 0, 0, 4),
                new VertexOutputElement("COLOR"		 , 0, 0, 4),
                new VertexOutputElement("COLOR"		 , 1, 0, 4),
                new VertexOutputElement("TEXCOORD"	 , 0, 0, 4),
                new VertexOutputElement("TEXCOORD"	 , 1, 0, 4),
                new VertexOutputElement("TEXCOORD"	 , 2, 0, 4),
            };

            if (flag==Flags.INJECTION || flag==Flags.SIMULATION) {
                ps.VertexOutputElements	=	outputElements;
            }

            if (flag==Flags.RENDER) {
                ps.BlendState	=	BlendState.Screen;
                ps.RasterizerState	=	RasterizerState.CullNone;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="ps"></param>
 /// <param name="flags"></param>
 void StateEnum( PipelineState ps, Flags flags )
 {
     ps.BlendState			=	BlendState.Additive;
     ps.DepthStencilState	=	DepthStencilState.None;
     ps.Primitive			=	Primitive.PointList;
 }
Exemplo n.º 4
0
 void EnumFunc(PipelineState p, RenderFlags f)
 {
     p.BlendState			= BlendState.Opaque;
     p.DepthStencilState		= DepthStencilState.Default;
     p.Primitive				= Primitive.PatchList3CP;
     p.VertexInputElements	= VertexColorTextureTBN.Elements;
     p.RasterizerState		= f.HasFlag(RenderFlags.Wireframe) ? RasterizerState.Wireframe : RasterizerState.CullCW;
 }
Exemplo n.º 5
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ps"></param>
		/// <param name="flags"></param>
		void EnumFunc ( PipelineState ps, SkyFlags flags )
		{
			ps.VertexInputElements	=	VertexInputElement.FromStructure<VertexColorTextureTBN>();
			ps.RasterizerState		=	RasterizerState.CullNone;
			ps.BlendState			=	BlendState.Opaque;
			ps.DepthStencilState	=	flags.HasFlag(SkyFlags.FOG) ? DepthStencilState.None : DepthStencilState.Readonly;

			if (flags.HasFlag(SkyFlags.CLOUDS)) {
				ps.BlendState	=	BlendState.AlphaBlend;
			}
		}
Exemplo n.º 6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="?"></param>
        void Enumerate( Type enumType, Ubershader ubershader, Action<PipelineState,int> enumAction )
        {
            pipelineStates	=	new Dictionary<int,PipelineState>();

            combinerEnum	=	enumType;

            //
            //	validate enum :
            //
            if (Enum.GetUnderlyingType(enumType)!=typeof(int)) {
                throw new ArgumentException("Underlying type should be Int32");
            }

            Dictionary<string,int> enumDict = new Dictionary<string,int>();

            foreach ( var enumValue in Enum.GetValues( enumType ) ) {
                if ( !MathUtil.IsPowerOfTwo( (int)enumValue ) && (int)enumValue!=0 ) {
                    throw new ArgumentException("Each value must be zero or power of two");
                }
                enumDict.Add( enumValue.ToString(), (int)enumValue );
            }

            //
            //	Enumerate :
            //
            var defineList = ubershader.Defines;

            foreach ( var defines in defineList ) {

                int combination = 0;

                if ( GetCombinerSet( enumDict, defines, out combination ) ) {

                    var ps = new PipelineState( device );

                    ps.PixelShader		=	ubershader.GetPixelShader		( defines );
                    ps.VertexShader		=	ubershader.GetVertexShader		( defines );
                    ps.GeometryShader	=	ubershader.GetGeometryShader	( defines );
                    ps.HullShader		=	ubershader.GetHullShader		( defines );
                    ps.DomainShader		=	ubershader.GetDomainShader		( defines );
                    ps.ComputeShader	=	ubershader.GetComputeShader		( defines );

                    enumAction( ps, combination );

                    pipelineStates.Add( combination, ps );
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="bs"></param>
 /// <param name="ss"></param>
 /// <param name="rs"></param>
 /// <param name="dss"></param>
 /// <param name="transform"></param>
 /// <param name="clip"></param>
 public void Restart(PipelineState ps, SamplerState ss = null, DepthStencilState dss = null, Matrix?transform = null, Rectangle?clip = null)
 {
     End();
     Begin(ps, ss, dss, transform, clip);
 }
Exemplo n.º 8
0
        void LoadContent()
        {
            fontTexture		=	device.Game.Content.Load<Texture2D>( @"debugFont.tga" );

             			shader			=	Game.Content.Load<Ubershader>(@"spriteBatch.hlsl");

            DisposePSO();

            foreach (SpriteBlend blend in Enum.GetValues(typeof(SpriteBlend))) {

                var ps = new PipelineState( Game.GraphicsDevice );

                ps.RasterizerState		=	RasterizerState.CullNone;
                ps.DepthStencilState	=	DepthStencilState.None;

                if (blend==SpriteBlend.Opaque			) ps.BlendState	=	BlendState.Opaque;
                if (blend==SpriteBlend.AlphaBlend		) ps.BlendState	=	BlendState.AlphaBlend;
                if (blend==SpriteBlend.AlphaBlendPreMul	) ps.BlendState	=	BlendState.AlphaBlendPreMul;
                if (blend==SpriteBlend.Additive			) ps.BlendState	=	BlendState.Additive;
                if (blend==SpriteBlend.Screen			) ps.BlendState	=	BlendState.Screen;
                if (blend==SpriteBlend.Multiply			) ps.BlendState	=	BlendState.Multiply;
                if (blend==SpriteBlend.NegMultiply		) ps.BlendState	=	BlendState.NegMultiply;
                if (blend==SpriteBlend.ClearAlpha		) ps.BlendState =	BlendState.ClearAlpha;

                ps.VertexInputElements	=	VertexInputElement.FromStructure( typeof(SpriteVertex) );

                ps.PixelShader	=	shader.GetPixelShader("");
                ps.VertexShader	=	shader.GetVertexShader("");
                ps.Primitive	=	Primitive.TriangleList;

                pipelineStates.Add( blend, ps );

            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="bs"></param>
 /// <param name="ss"></param>
 /// <param name="rs"></param>
 /// <param name="dss"></param>
 /// <param name="transform"></param>
 /// <param name="clip"></param>
 public void Restart( PipelineState ps, SamplerState ss = null, DepthStencilState dss = null, Matrix? transform = null, Rectangle? clip = null )
 {
     End();
     Begin( ps, ss, dss, transform, clip );
 }
Exemplo n.º 10
0
        /// <summary>
        /// 
        /// </summary>
        public void Begin( PipelineState ps, SamplerState ss = null, DepthStencilState dss = null, Matrix? transform = null, Rectangle? clip = null )
        {
            if (ps==null) {
                throw new ArgumentNullException("ps");
            }

            pipelineState		=	ps;
            samplerState		=	ss	?? SamplerState.LinearWrap;
            depthStencilState	=	dss	?? DepthStencilState.Readonly;

            int	w	=	device.DisplayBounds.Width;
            int h	=	device.DisplayBounds.Height;
            var ofs	=	0.0f;

            Matrix sbTransform;
            if (transform.HasValue) {
                sbTransform = transform.Value;
            } else {
                sbTransform = Matrix.OrthoOffCenterRH(ofs, w + ofs, h + ofs, ofs, -9999, 9999);
            }

            Vector4 clipRect  = new Vector4(0,0,w,h);

            if ( clip.HasValue ) {
                clipRect.X = clip.Value.X;
                clipRect.Y = clip.Value.Y;
                clipRect.Z = clip.Value.Width;
                clipRect.W = clip.Value.Height;
            }

            device.PipelineState			=	pipelineState;
            device.PixelShaderSamplers[0]	=	samplerState;

            constData.Transform		=	sbTransform;
            constData.ClipRectangle	=	clipRect;
            constBuffer.SetData( constData );
        }
Exemplo n.º 11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ps"></param>
        /// <param name="flags"></param>
        void EnumFunc( PipelineState ps, SkyFlags flags )
        {
            ps.VertexInputElements	=	VertexInputElement.FromStructure<VertexColorTextureTBN>();
            ps.RasterizerState		=	RasterizerState.CullNone;
            ps.BlendState			=	BlendState.Opaque;
            ps.DepthStencilState	=	flags.HasFlag(SkyFlags.FOG) ? DepthStencilState.None : DepthStencilState.Readonly;

            if (flags.HasFlag(SkyFlags.CLOUDS)) {
                ps.BlendState	=	BlendState.AlphaBlend;
            }
            //if (flags.HasFlag(SkyFlags.RED)) {
            //	ps.BlendState	=	BlendState.Create(ColorChannels.Red);
            //}
            //if (flags.HasFlag(SkyFlags.BLUE)) {
            //	ps.BlendState	=	BlendState.Create(ColorChannels.Blue);
            //}
            //if (flags.HasFlag(SkyFlags.GREEN)) {
            //	ps.BlendState	=	BlendState.Create(ColorChannels.Green);
            //}
            if ( flags.HasFlag( SkyFlags.BLUR_CLOUD ) ) {
                ps.BlendState = BlendState.AlphaBlend;
            }
        }
Exemplo n.º 12
0
        void Enum( PipelineState plState, RenderFlags flag )
        {
            plState.RasterizerState		= RasterizerState.CullNone;
                plState.BlendState			= BlendMode;
                plState.DepthStencilState	= DepthStencilState.Default;
                plState.Primitive			= Primitive.PointList;

                if (flag.HasFlag(RenderFlags.LINE))
                {
                    //plState.BlendState = BlendState.Screen;
                    //plState.DepthStencilState = DepthStencilState.Readonly;
                }
        }