private void GetVariablesInformation(PropertyInfo[] proPS)
            {
                foreach (var p in proPS)
                {
                    VarInfo v;
                    ShaderReflectionVariable ud = program.GetUniformDescription(p.Name);

                    if (!_varlookup.TryGetValue(p.Name, out v))
                    {
                        v = new VarInfo()
                        {
                            Name    = p.Name,
                            NetProp = p,
                            Desc    = ud,
                            NetType = ud != null ? p.PropertyType : null,
                        };
                        if (v.Desc != null && v.NetType != null)
                        {
                            v.Variable        = CreateVariable(v.NetType, v.Desc);
                            v.Variable.Name   = ud.Name;
                            v.Variable.Binder = program.CreateUniformSetter(ud.Name);
                        }

                        _varlookup.Add(v.Name, v);
                    }
                }
            }
            private Type ResolveType(ShaderReflectionVariable cd)
            {
                var type = _ResolveType(cd);

                if (type != null && cd.Type.Elements > 1)
                {
                    return(type.MakeArrayType());
                }

                return(type);
            }
            private Type _ResolveType(ShaderReflectionVariable cd)
            {
                var type = cd.Type;

                switch (type.Class)
                {
                case TypeClass.Scalar:
                {
                    switch (type.Type)
                    {
                    case ShaderType.UserDefined: throw new InvalidOperationException();

                    case ShaderType.Bool: return(typeof(bool));

                    case ShaderType.Int: return(typeof(int));

                    case ShaderType.Float: return(typeof(float));
                    }
                }
                break;

                case TypeClass.Vector:
                    if (type.Columns == 2)
                    {
                        return(typeof(Vector2));
                    }
                    else if (type.Columns == 3)
                    {
                        return(typeof(Vector3));
                    }
                    else if (type.Type == ShaderType.Int)
                    {
                        return(typeof(Int4));
                    }
                    else
                    {
                        return(typeof(Vector4));
                    }

                case TypeClass.Matrix: return(typeof(Matrix));

                case TypeClass.Object:
                {
                    switch (type.Type)
                    {
                    case ShaderType.Texture:
                        return(typeof(Texture));

                    case ShaderType.Texture1D:
                        return(typeof(Texture1D));

                    case ShaderType.Texture2D:
                        return(typeof(Texture2D));

                    case ShaderType.Texture3D:
                        return(typeof(Texture3D));

                    case ShaderType.TextureCube:
                        return(typeof(Texture2D));

                    case ShaderType.Sampler:
                    case ShaderType.Sampler1D:
                    case ShaderType.Sampler2D:
                    case ShaderType.Sampler3D:
                    case ShaderType.SamplerCube:
                        return(typeof(SamplerState));
                    }
                    throw new InvalidOperationException("Type " + type.Name + " not Supported");
                }

                case TypeClass.Struct: return(null);
                }
                return(null);
            }
            private ShaderVariable CreateVariable(Type type, ShaderReflectionVariable desc)
            {
                var shaderType = desc.Type;

                if (type.IsArray)
                {
                    if (shaderType.Elements == 0)
                    {
                        throw new InvalidOperationException("The constant " + desc.Name + "is not an array");
                    }
                    var e = type.GetElementType();
                    if (e == typeof(int))
                    {
                        return new IntArrayVariable()
                               {
                                   Elements = shaderType.Elements
                               }
                    }
                    ;
                    else if (e == typeof(bool))
                    {
                        return new BoolArrayVariable()
                               {
                                   Elements = shaderType.Elements
                               }
                    }
                    ;
                    else if (e == typeof(float))
                    {
                        return new FloatArrayVariable()
                               {
                                   Elements = shaderType.Elements
                               }
                    }
                    ;
                    else if (e == typeof(Matrix))
                    {
                        return new MatrixArrayVariable()
                               {
                                   Elements = shaderType.Elements
                               }
                    }
                    ;
                    else if (e == typeof(Vector4))
                    {
                        return new Vector4ArrayVariable()
                               {
                                   Elements = shaderType.Elements
                               }
                    }
                    ;
                    else if (e == typeof(SamplerState))
                    {
                        return new SamplerStateVariableArray()
                               {
                                   Elements = shaderType.Elements
                               }
                    }
                    ;
                    else if (e.GetInterface(typeof(IShaderResource).Name) != null)
                    {
                        return new ResourceVariableArray {
                                   Elements = shaderType.Elements
                        }
                    }
                    ;
                    else if (e.IsValueType)
                    {
                        var insType = typeof(ShaderVariableArray <>).MakeGenericType(e);

                        var inst = (ShaderVariableArray)Activator.CreateInstance(insType);
                        inst.Elements = shaderType.Elements;
                        return(inst);
                    }
                    else
                    {
                        throw new InvalidOperationException("The type \"" + e.Name + "\" is not supported");
                    }
                }
                else
                {
                    if (type == typeof(int))
                    {
                        return(new IntVariable());
                    }
                    else if (type == typeof(bool))
                    {
                        return(new BoolVariable());
                    }
                    else if (type == typeof(float))
                    {
                        return(new FloatVariable());
                    }
                    else if (type == typeof(Matrix))
                    {
                        return(new MatrixVariable());
                    }
                    else if (type == typeof(Vector4))
                    {
                        return(new Vector4Variable());
                    }
                    else if (type.IsGenericType)
                    {
                        var genDef = type.GetGenericTypeDefinition();
                        if (genDef == typeof(SArray <>))
                        {
                            var arGS    = type.GetGenericArguments();
                            var insType = typeof(RangeVariable <>).MakeGenericType(arGS);
                            return((ShaderVariable)Activator.CreateInstance(insType));
                        }
                        else if (genDef == typeof(Sampler <>))
                        {
                            var arGS    = type.GetGenericArguments();
                            var insType = typeof(SamplerVariable <>).MakeGenericType(arGS);
                            return((ShaderVariable)Activator.CreateInstance(insType));
                        }
                        else if (genDef == typeof(SamplerArray <>))
                        {
                            var arGS    = type.GetGenericArguments();
                            var insType = typeof(SamplerVariableArray <>).MakeGenericType(arGS);
                            return((ShaderVariable)Activator.CreateInstance(insType));
                        }
                        else
                        {
                            throw new InvalidOperationException("The type \"" + type.Name + "\" is not supported");
                        }
                    }
                    else if (type == typeof(SamplerState))
                    {
                        return(new SamplerStateVariable());
                    }
                    else if (type.GetInterface(typeof(IShaderResource).Name) != null)
                    {
                        return(new ResourceVariable());
                    }
                    else if (type.IsValueType)
                    {
                        var insType = typeof(ShaderVariable <>).MakeGenericType(type);
                        return((ShaderVariable)Activator.CreateInstance(insType));
                    }
                    else
                    {
                        throw new InvalidOperationException("The type \"" + type.Name + "\" is not supported");
                    }
                }
            }