Exemplo n.º 1
0
        protected virtual object EvalSampler_State_Expression(ParseTree tree, params object[] paramlist)
        {
            var sampler = paramlist[0] as SamplerStateInfo;
            var name    = this.GetValue(tree, TokenType.Identifier, 0) as string;
            var value   = (this.GetValue(tree, TokenType.Identifier, 1) ?? (this.GetValue(tree, TokenType.Identifier, 2) ?? this.GetValue(tree, TokenType.Number, 0))) as string;

            switch (name.ToLower())
            {
            case "texture":
                sampler.textureName = value;
                break;

            case "minfilter":
                sampler.MinFilter = ParseTreeTools.ParseTextureFilterType(value);
                break;

            case "magfilter":
                sampler.MagFilter = ParseTreeTools.ParseTextureFilterType(value);
                break;

            case "mipfilter":
                sampler.MipFilter = ParseTreeTools.ParseTextureFilterType(value);
                break;

            case "filter":
                sampler.MinFilter = sampler.MagFilter = sampler.MipFilter = ParseTreeTools.ParseTextureFilterType(value);
                break;

            case "addressu":
                sampler.state.AddressU = ParseTreeTools.ParseAddressMode(value);
                break;

            case "addressv":
                sampler.state.AddressV = ParseTreeTools.ParseAddressMode(value);
                break;

            case "addressw":
                sampler.state.AddressW = ParseTreeTools.ParseAddressMode(value);
                break;

            case "maxanisotropy":
                sampler.state.MaxAnisotropy = int.Parse(value);
                break;

            case "maxlod":
                sampler.state.MaxMipLevel = int.Parse(value);
                break;

            case "miplodbias":
                sampler.state.MipMapLevelOfDetailBias = float.Parse(value);
                break;

            default:
                break;
            }

            return(null);
        }
Exemplo n.º 2
0
        public void Parse(string name, string value)
        {
            switch (name.ToLower())
            {
            case "texture":
                TextureName = value;
                break;

            case "minfilter":
                MinFilter = ParseTreeTools.ParseTextureFilterType(value);
                break;

            case "magfilter":
                MagFilter = ParseTreeTools.ParseTextureFilterType(value);
                break;

            case "mipfilter":
                MipFilter = ParseTreeTools.ParseTextureFilterType(value);
                break;

            case "filter":
                MinFilter = MagFilter = MipFilter = ParseTreeTools.ParseTextureFilterType(value);
                break;

            case "addressu":
                AddressU = ParseTreeTools.ParseAddressMode(value);
                break;

            case "addressv":
                AddressV = ParseTreeTools.ParseAddressMode(value);
                break;

            case "addressw":
                AddressW = ParseTreeTools.ParseAddressMode(value);
                break;

            case "maxanisotropy":
                MaxAnisotropy = int.Parse(value);
                break;

            case "maxlod":
                MaxMipLevel = int.Parse(value);
                break;

            case "miplodbias":
                MipMapLevelOfDetailBias = float.Parse(value);
                break;
            }
        }
Exemplo n.º 3
0
        public void ParseRenderState(string name, string value)
        {
            Blend blend;

            switch (name.ToLower())
            {
            case "alphablendenable":
                if (!ParseTreeTools.ParseBool(value))
                {
                    if (blendState == null)
                    {
                        blendState = new BlendState();
                    }
                    blendState.ColorSourceBlend      = Blend.One;
                    blendState.AlphaSourceBlend      = Blend.One;
                    blendState.ColorDestinationBlend = Blend.Zero;
                    blendState.AlphaDestinationBlend = Blend.Zero;
                }
                break;

            case "srcblend":
                blend = ParseTreeTools.ParseBlend(value);
                if (blendState == null)
                {
                    blendState = new BlendState();
                }
                blendState.ColorSourceBlend = blend;
                blendState.AlphaSourceBlend = ToAlphaBlend(blend);
                break;

            case "destblend":
                blend = ParseTreeTools.ParseBlend(value);
                if (blendState == null)
                {
                    blendState = new BlendState();
                }
                blendState.ColorDestinationBlend = blend;
                blendState.AlphaDestinationBlend = ToAlphaBlend(blend);
                break;

            case "blendop":
                if (blendState == null)
                {
                    blendState = new BlendState();
                }
                blendState.AlphaBlendFunction = ParseTreeTools.ParseBlendFunction(value);
                break;

            case "zenable":
                if (depthStencilState == null)
                {
                    depthStencilState = new DepthStencilState();
                }
                depthStencilState.DepthBufferEnable = ParseTreeTools.ParseBool(value);
                break;

            case "zwriteenable":
                if (depthStencilState == null)
                {
                    depthStencilState = new DepthStencilState();
                }
                depthStencilState.DepthBufferWriteEnable = ParseTreeTools.ParseBool(value);
                break;

            case "depthbias":
                if (rasterizerState == null)
                {
                    rasterizerState = new RasterizerState();
                }
                rasterizerState.DepthBias = float.Parse(value);
                break;

            case "cullmode":
                if (rasterizerState == null)
                {
                    rasterizerState = new RasterizerState();
                }
                rasterizerState.CullMode = ParseTreeTools.ParseCullMode(value);
                break;

            case "fillmode":
                if (rasterizerState == null)
                {
                    rasterizerState = new RasterizerState();
                }
                rasterizerState.FillMode = ParseTreeTools.ParseFillMode(value);
                break;

            case "multisampleantialias":
                if (rasterizerState == null)
                {
                    rasterizerState = new RasterizerState();
                }
                rasterizerState.MultiSampleAntiAlias = ParseTreeTools.ParseBool(value);
                break;

            case "slopescaledepthbias":
                if (rasterizerState == null)
                {
                    rasterizerState = new RasterizerState();
                }
                rasterizerState.SlopeScaleDepthBias = float.Parse(value);
                break;
            }
        }
Exemplo n.º 4
0
        static public ShaderInfo FromString(string effectSource, string filePath, Options options, IEffectCompilerOutput output)
        {
            var macros = new Dictionary <string, string>();

            macros.Add("MGFX", "1");

            options.Profile.AddMacros(macros);

            // If we're building shaders for debug set that flag too.
            if (options.Debug)
            {
                macros.Add("DEBUG", "1");
            }

            if (!string.IsNullOrEmpty(options.Defines))
            {
                var defines = options.Defines.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var define in defines)
                {
                    macros.Add(define, "1");
                }
            }

            // Use the D3DCompiler to pre-process the file resolving
            // all #includes and macros.... this even works for GLSL.
            string newFile;
            var    fullPath     = Path.GetFullPath(filePath);
            var    dependencies = new List <string>();

            newFile = Preprocessor.Preprocess(effectSource, fullPath, macros, dependencies, output);

            // Parse the resulting file for techniques and passes.
            var tree = new Parser(new Scanner()).Parse(newFile, fullPath);

            if (tree.Errors.Count > 0)
            {
                var errors = String.Empty;
                foreach (var error in tree.Errors)
                {
                    errors += string.Format("{0}({1},{2}) : {3}\r\n", error.File, error.Line, error.Column, error.Message);
                }

                throw new Exception(errors);
            }

            // Evaluate the results of the parse tree.
            var result = tree.Eval() as ShaderInfo;

            // Remove the samplers and techniques so that the shader compiler
            // gets a clean file without any FX file syntax in it.
            var cleanFile = newFile;

            ParseTreeTools.WhitespaceNodes(TokenType.Technique_Declaration, tree.Nodes, ref cleanFile);
            ParseTreeTools.WhitespaceNodes(TokenType.Sampler_Declaration_States, tree.Nodes, ref cleanFile);

            // Setup the rest of the shader info.
            result.Dependencies = dependencies;
            result.FilePath     = fullPath;
            result.FileContent  = cleanFile;
            if (!string.IsNullOrEmpty(options.OutputFile))
            {
                result.OutputFilePath = Path.GetFullPath(options.OutputFile);
            }
            result.AdditionalOutputFiles = new List <string>();

            // Remove empty techniques.
            for (var i = 0; i < result.Techniques.Count; i++)
            {
                var tech = result.Techniques[i];
                if (tech.Passes.Count <= 0)
                {
                    result.Techniques.RemoveAt(i);
                    i--;
                }
            }

            // We must have at least one technique.
            if (result.Techniques.Count <= 0)
            {
                throw new Exception("The effect must contain at least one technique and pass!");
            }

            result.Profile = options.Profile;
            result.Debug   = options.Debug;

            return(result);
        }
Exemplo n.º 5
0
 protected virtual object EvalRender_State_ZEnable(ParseTree tree, params object[] paramlist)
 {
     (paramlist[0] as PassInfo).ZEnable = ParseTreeTools.ParseBool((string)this.GetValue(tree, TokenType.Boolean, 0)); return(null);
 }
Exemplo n.º 6
0
 protected virtual object EvalRender_State_SlopeScaleDepthBias(ParseTree tree, params object[] paramlist)
 {
     (paramlist[0] as PassInfo).SlopeScaleDepthBias = ParseTreeTools.ParseFloat((string)this.GetValue(tree, TokenType.Number, 0)); return(null);
 }
Exemplo n.º 7
0
 protected virtual object EvalColors_Boolean(ParseTree tree, params object[] paramlist)
 {
     return(ParseTreeTools.ParseBool((string)this.GetValue(tree, TokenType.Boolean, 0)) ?  ColorWriteChannels.All : ColorWriteChannels.None);
 }
Exemplo n.º 8
0
 protected virtual object EvalSampler_State_MipLodBias(ParseTree tree, params object[] paramlist)
 {
     (paramlist[0] as SamplerStateInfo).MipMapLevelOfDetailBias = ParseTreeTools.ParseFloat((string)this.GetValue(tree, TokenType.Number, 0)); return(null);
 }
Exemplo n.º 9
0
 protected virtual object EvalSampler_State_MaxAnisotropy(ParseTree tree, params object[] paramlist)
 {
     (paramlist[0] as SamplerStateInfo).MaxAnisotropy = ParseTreeTools.ParseInt((string)this.GetValue(tree, TokenType.Number, 0)); return(null);
 }
Exemplo n.º 10
0
 protected virtual object EvalSampler_State_BorderColor(ParseTree tree, params object[] paramlist)
 {
     (paramlist[0] as SamplerStateInfo).BorderColor = ParseTreeTools.ParseColor((string)this.GetValue(tree, TokenType.HexColor, 0)); return(null);
 }
Exemplo n.º 11
0
 protected virtual object EvalRender_State_StencilWriteMask(ParseTree tree, params object[] paramlist)
 {
     (paramlist[0] as PassInfo).StencilWriteMask = ParseTreeTools.ParseInt((string)this.GetValue(tree, TokenType.Number, 0)); return(null);
 }
Exemplo n.º 12
0
 protected virtual object EvalRender_State_MultiSampleAntiAlias(ParseTree tree, params object[] paramlist)
 {
     (paramlist[0] as PassInfo).MultiSampleAntiAlias = ParseTreeTools.ParseBool((string)this.GetValue(tree, TokenType.Boolean, 0)); return(null);
 }
Exemplo n.º 13
0
        protected virtual object EvalRender_State_Expression(ParseTree tree, params object[] paramlist)
        {
            var pass  = paramlist[0] as PassInfo;
            var name  = this.GetValue(tree, TokenType.Identifier, 0) as string;
            var value = (this.GetValue(tree, TokenType.Identifier, 1) ?? this.GetValue(tree, TokenType.Number, 0)) as string;

            Microsoft.Xna.Framework.Graphics.Blend blend;

            switch (name.ToLower())
            {
            case "alphablendenable":
                if (!ParseTreeTools.ParseBool(value))
                {
                    if (pass.blendState == null)
                    {
                        pass.blendState = new Microsoft.Xna.Framework.Graphics.BlendState();
                    }
                    pass.blendState.AlphaSourceBlend      = Microsoft.Xna.Framework.Graphics.Blend.One;
                    pass.blendState.ColorSourceBlend      = Microsoft.Xna.Framework.Graphics.Blend.One;
                    pass.blendState.ColorDestinationBlend = Microsoft.Xna.Framework.Graphics.Blend.Zero;
                    pass.blendState.AlphaDestinationBlend = Microsoft.Xna.Framework.Graphics.Blend.Zero;
                }
                break;

            case "srcblend":
                blend = ParseTreeTools.ParseBlend(value);
                if (pass.blendState == null)
                {
                    pass.blendState = new Microsoft.Xna.Framework.Graphics.BlendState();
                }
                pass.blendState.AlphaSourceBlend = blend;
                pass.blendState.ColorSourceBlend = blend;
                break;

            case "destblend":
                blend = ParseTreeTools.ParseBlend(value);
                if (pass.blendState == null)
                {
                    pass.blendState = new Microsoft.Xna.Framework.Graphics.BlendState();
                }
                pass.blendState.AlphaDestinationBlend = blend;
                pass.blendState.ColorDestinationBlend = blend;
                break;

            case "blendop":
                if (pass.blendState == null)
                {
                    pass.blendState = new Microsoft.Xna.Framework.Graphics.BlendState();
                }
                pass.blendState.AlphaBlendFunction = ParseTreeTools.ParseBlendFunction(value);
                break;

            case "zenable":
                if (pass.depthStencilState == null)
                {
                    pass.depthStencilState = new Microsoft.Xna.Framework.Graphics.DepthStencilState();
                }
                pass.depthStencilState.DepthBufferEnable = ParseTreeTools.ParseBool(value);
                break;

            case "zwriteenable":
                if (pass.depthStencilState == null)
                {
                    pass.depthStencilState = new Microsoft.Xna.Framework.Graphics.DepthStencilState();
                }
                pass.depthStencilState.DepthBufferWriteEnable = ParseTreeTools.ParseBool(value);
                break;

            case "depthbias":
                if (pass.rasterizerState == null)
                {
                    pass.rasterizerState = new Microsoft.Xna.Framework.Graphics.RasterizerState();
                }
                pass.rasterizerState.DepthBias = float.Parse(value);
                break;

            case "cullmode":
                if (pass.rasterizerState == null)
                {
                    pass.rasterizerState = new Microsoft.Xna.Framework.Graphics.RasterizerState();
                }
                pass.rasterizerState.CullMode = ParseTreeTools.ParseCullMode(value);
                break;

            case "fillmode":
                if (pass.rasterizerState == null)
                {
                    pass.rasterizerState = new Microsoft.Xna.Framework.Graphics.RasterizerState();
                }
                pass.rasterizerState.FillMode = ParseTreeTools.ParseFillMode(value);
                break;

            case "multisampleantialias":
                if (pass.rasterizerState == null)
                {
                    pass.rasterizerState = new Microsoft.Xna.Framework.Graphics.RasterizerState();
                }
                pass.rasterizerState.MultiSampleAntiAlias = ParseTreeTools.ParseBool(value);
                break;

            case "slopescaledepthbias":
                if (pass.rasterizerState == null)
                {
                    pass.rasterizerState = new Microsoft.Xna.Framework.Graphics.RasterizerState();
                }
                pass.rasterizerState.SlopeScaleDepthBias = float.Parse(value);
                break;

            default:
                break;
            }

            return(null);
        }