Beispiel #1
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);
            }
        }
Beispiel #2
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);
                }
            }
        }