Ejemplo n.º 1
0
        /// <summary>
        /// Creates the default render states.
        /// </summary>
        private static void CreateDefaultRenderStates()
        {
            //*********************//
            //* Rasterizer States *//
            //*********************//

            RasterizerState cullNone = new RasterizerState();

            cullNone.Cull          = CullMode.None;
            cullNone.VertexWinding = VertexWinding.Clockwise;
            cullNone.BindRenderState();
            RasterizerState.CullNone = cullNone;

            RasterizerState cullBackCW = new RasterizerState();

            cullBackCW.Cull          = CullMode.Back;
            cullBackCW.VertexWinding = VertexWinding.Clockwise;
            cullBackCW.BindRenderState();
            RasterizerState.CullBackClockwiseFront = cullBackCW;

            RasterizerState cullBackCCW = new RasterizerState();

            cullBackCCW.Cull          = CullMode.Back;
            cullBackCCW.VertexWinding = VertexWinding.CounterClockwise;
            cullBackCCW.BindRenderState();
            RasterizerState.CullBackCounterClockwiseFront = cullBackCCW;

            RasterizerState cullNoneWireframe = new RasterizerState();

            cullNoneWireframe.Cull          = CullMode.None;
            cullNoneWireframe.Fill          = FillMode.WireFrame;
            cullNoneWireframe.VertexWinding = VertexWinding.Clockwise;
            cullNoneWireframe.BindRenderState();
            RasterizerState.CullNoneWireframe = cullNoneWireframe;

            //****************//
            //* Blend States *//
            //****************//
            BlendState opaque = new BlendState();

            opaque.SetBlendEnable(0, false);
            opaque.BindRenderState();
            BlendState.Opaque = opaque;

            BlendState pmAlphaBlend = new BlendState();

            pmAlphaBlend.AlphaSourceBlend      = Blend.One;
            pmAlphaBlend.AlphaDestinationBlend = Blend.InverseSourceAlpha;
            pmAlphaBlend.ColorSourceBlend      = Blend.One;
            pmAlphaBlend.ColorDestinationBlend = Blend.InverseSourceAlpha;
            pmAlphaBlend.BindRenderState();
            BlendState.AlphaBlendPremultiplied = pmAlphaBlend;

            BlendState npmAlphaBlend = new BlendState();

            npmAlphaBlend.AlphaSourceBlend      = Blend.SourceAlpha;
            npmAlphaBlend.AlphaDestinationBlend = Blend.InverseSourceAlpha;
            npmAlphaBlend.ColorSourceBlend      = Blend.SourceAlpha;
            npmAlphaBlend.ColorDestinationBlend = Blend.InverseSourceAlpha;
            npmAlphaBlend.BindRenderState();
            BlendState.AlphaBlendNonPremultiplied = npmAlphaBlend;

            BlendState additive = new BlendState();

            additive.AlphaSourceBlend      = Blend.SourceAlpha;
            additive.AlphaDestinationBlend = Blend.One;
            additive.ColorSourceBlend      = Blend.SourceAlpha;
            additive.ColorDestinationBlend = Blend.One;
            additive.BindRenderState();
            BlendState.AdditiveBlend = additive;

            //***********************//
            //* DepthStencil States *//
            //***********************//
            DepthStencilState none = new DepthStencilState();

            none.DepthEnable      = false;
            none.DepthWriteEnable = false;
            none.BindRenderState();
            DepthStencilState.None = none;

            DepthStencilState depthWriteOff = new DepthStencilState();

            depthWriteOff.DepthEnable      = true;
            depthWriteOff.DepthWriteEnable = false;
            depthWriteOff.BindRenderState();
            DepthStencilState.DepthWriteOff = depthWriteOff;

            DepthStencilState def = new DepthStencilState();

            def.DepthEnable      = true;
            def.DepthWriteEnable = true;
            def.BindRenderState();
            DepthStencilState.Default = def;


            //******************//
            //* Sampler States *//
            //******************//
            SamplerState pw = new SamplerState();

            pw.Filter   = TextureFilter.Point;
            pw.AddressU = pw.AddressV = pw.AddressW = TextureAddressMode.Wrap;
            pw.BindRenderState();
            SamplerState.PointWrap = pw;

            SamplerState pc = new SamplerState();

            pc.Filter   = TextureFilter.Point;
            pc.AddressU = pc.AddressV = pc.AddressW = TextureAddressMode.Clamp;
            pc.BindRenderState();
            SamplerState.PointClamp = pc;

            SamplerState lw = new SamplerState();

            lw.Filter   = TextureFilter.Linear;
            lw.AddressU = lw.AddressV = lw.AddressW = TextureAddressMode.Wrap;
            lw.BindRenderState();
            SamplerState.LinearWrap = lw;

            SamplerState lc = new SamplerState();

            lc.Filter   = TextureFilter.Linear;
            lc.AddressU = lc.AddressV = lc.AddressW = TextureAddressMode.Clamp;
            lc.BindRenderState();
            SamplerState.LinearClamp = lc;

            SamplerState aw = new SamplerState();

            aw.Filter   = TextureFilter.Anisotropic;
            aw.AddressU = aw.AddressV = aw.AddressW = TextureAddressMode.Wrap;
            aw.BindRenderState();
            SamplerState.AnisotropicWrap = aw;

            SamplerState ac = new SamplerState();

            ac.Filter   = TextureFilter.Anisotropic;
            ac.AddressU = ac.AddressV = ac.AddressW = TextureAddressMode.Clamp;
            ac.BindRenderState();
            SamplerState.AnisotropicClamp = ac;
        }