Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the StateFactory
        /// </summary>
        /// <param name="device"></param>
        /// <param name="enumType"></param>
        /// <param name="ubershader"></param>
        /// <param name="vertexInputElements"></param>
        /// <param name="blendState"></param>
        /// <param name="rasterizerState"></param>
        public StateFactory(Ubershader ubershader, Type enumType, Primitive primitive, VertexInputElement[] vertexInputElements)
            : base(ubershader.GraphicsDevice)
        {
            this.ubershader = ubershader;

            Enumerate(enumType, ubershader, (ps, i) => { ps.VertexInputElements = vertexInputElements; ps.Primitive = primitive; });
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the StateFactory
        /// </summary>
        /// <param name="device"></param>
        /// <param name="ubershader"></param>
        public StateFactory(Ubershader ubershader, Type enumType, Primitive primitive, VertexInputElement[] vertexInputElements, BlendState blendState, RasterizerState rasterizerState)
            : base(ubershader.GraphicsDevice)
        {
            this.ubershader = ubershader;

            Enumerate(enumType, ubershader, (ps, i) => {
                ps.Primitive           = primitive;
                ps.VertexInputElements = vertexInputElements;
                ps.BlendState          = blendState;
                ps.RasterizerState     = rasterizerState;
            });
        }
Ejemplo n.º 4
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);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initialization
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

            var dev = Game.GraphicsDevice;

            effect  = Game.Content.Load <Ubershader>("debugRender.hlsl");
            factory = new StateFactory(effect, typeof(RenderFlags), Primitive.LineList, VertexInputElement.FromStructure(typeof(LineVertex)), BlendState.AlphaBlend, RasterizerState.CullNone);

            constData   = new ConstData();
            constBuffer = new ConstantBuffer(dev, typeof(ConstData));


            //	create vertex buffer :
            vertexBuffer             = new VertexBuffer(dev, typeof(LineVertex), vertexBufferSize, VertexBufferOptions.Dynamic);
            vertexDataAccum.Capacity = vertexBufferSize;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the StateFactory
        /// </summary>
        /// <param name="ubershader"></param>
        /// <param name="enumType"></param>
        /// <param name="enumAction"></param>
        public StateFactory(Ubershader ubershader, Type enumType, Action <PipelineState, int> enumAction) : base(ubershader.GraphicsDevice)
        {
            this.ubershader = ubershader;

            Enumerate(enumType, ubershader, enumAction);
        }