Example #1
0
        public StructExpression(params Object[] symbols) : base(symbols)
        {
            TextPart namePart = this.ConstituentSymbols[1] as TextPart;

            this.Name = namePart.TextValue;
        }
Example #2
0
        public ConstantExpression(params Object[] inputSymbols) : base(inputSymbols)
        {
            // Get data
            IEnumerable <Symbol> symbols = this.ConstituentSymbols;

            // Get type part
            TextPart typePart = symbols.ElementAt(0) as TextPart;
            string   type     = typePart.ToString();

            // Init type
            foreach (string s in _allType)
            {
                if (type.StartsWith(s))
                {
                    this.Type = s;
                    break;
                }
            }

            if (string.IsNullOrEmpty(this.Type))
            {
                throw new ArgumentException("Invalid type");
            }

            // Init dimension
            this.Dimension = new int[] { 1, 1 };
            string dimension = type.Replace(this.Type, "");

            if (!string.IsNullOrEmpty(dimension))
            {
                if (dimension.Contains('x'))
                {
                    string[] value = dimension.Split('x');
                    this.Dimension[0] = int.Parse(value[0], CultureInfo.InvariantCulture);
                    this.Dimension[1] = int.Parse(value[1], CultureInfo.InvariantCulture);
                }
                else
                {
                    this.Dimension[0] = int.Parse(dimension, CultureInfo.InvariantCulture);
                }
            }

            // Get name part
            TextPart namePart = symbols.ElementAt(1) as TextPart;
            string   name     = namePart.ToString();

            // Init name and array
            if (name.Contains('[') && name.Contains(']'))
            {
                // Extract data
                string[] value = name.Split(new char[] { '[', ']' });

                // Set data
                this.Name      = value[0];
                this.ArraySize = int.Parse(value[1], CultureInfo.InvariantCulture);
            }
            else
            {
                // Set data
                this.Name      = name;
                this.ArraySize = 0;
            }

            // Set value
            this.Value = string.Empty;
        }
Example #3
0
        public SamplerExpression(params Object[] inputSymbols) : base(inputSymbols)
        {
            // Set default data
            this.Resource = string.Empty;
            this.Filter   = "Linear";
            this.AddressU = "Clamp";
            this.AddressV = "Clamp";
            this.AddressV = "Clamp";

            // Get data
            IEnumerable <Symbol> symbols = this.ConstituentSymbols;

            // Get type part
            TextPart typePart = symbols.ElementAt(0) as TextPart;
            string   type     = typePart.ToString();

            // Init type
            foreach (string s in _allType)
            {
                if (type.StartsWith(s))
                {
                    this.Type = s;
                    break;
                }
            }

            if (string.IsNullOrEmpty(this.Type))
            {
                throw new ArgumentException("Invalid sampler type \"" + type + "\"");
            }

            // Get name part
            TextPart namePart = symbols.ElementAt(1) as TextPart;

            this.Name = namePart.ToString();

            // Get members
            IEnumerable <Symbol> memberExpr = symbols.Where(s => s is TextPart);

            if (memberExpr != null && memberExpr.Count() > 1)
            {
                int count = memberExpr.Count();
                for (int i = 0; i < count; i += 2)
                {
                    TextPart key   = memberExpr.ElementAt(i) as TextPart;
                    TextPart value = memberExpr.ElementAt(i + 1) as TextPart;

                    if (!(key != null && value != null))
                    {
                        throw new ArgumentException("Invalid get sampler member");
                    }

                    if (key.TextValue == "Texture")
                    {
                        this.Resource = value.TextValue;
                    }
                    else if (key.TextValue == "Filter")
                    {
                        this.Filter = value.TextValue;
                    }
                    else if (key.TextValue == "AddressU")
                    {
                        this.AddressU = value.TextValue;
                    }
                    else if (key.TextValue == "AddressV")
                    {
                        this.AddressV = value.TextValue;
                    }
                    else if (key.TextValue == "AddressW")
                    {
                        this.AddressW = value.TextValue;
                    }
                }
            }
            else
            {
                throw new ArgumentException("Invalid sampler members");
            }
        }