Exemple #1
0
        public static object GetValue(this EffectParameter parameter)
        {
            if (parameter.ParameterClass == EffectParameterClass.Object)
            {
                if (parameter.ParameterType == EffectParameterType.Texture2D)
                {
                    return(parameter.GetValueTexture2D());
                }
                if (parameter.ParameterType == EffectParameterType.Texture3D)
                {
                    return(parameter.GetValueTexture3D());
                }
                if (parameter.ParameterType == EffectParameterType.TextureCube)
                {
                    return(parameter.GetValueTextureCube());
                }
            }

            if (parameter.ParameterType == EffectParameterType.Int32)
            {
                return(parameter.GetValueInt32());
            }
            if (parameter.ParameterClass == EffectParameterClass.Matrix)
            {
                return(parameter.GetValueMatrix());
            }

            if (parameter.ParameterClass == EffectParameterClass.Vector)
            {
                if (parameter.ColumnCount == 1)
                {
                    return(parameter.GetValueSingle());
                }
                if (parameter.ColumnCount == 2)
                {
                    return(parameter.GetValueVector2());
                }
                if (parameter.ColumnCount == 3)
                {
                    return(parameter.GetValueVector3());
                }
                if (parameter.ColumnCount == 4)
                {
                    return(parameter.GetValueVector4());
                }
            }

            throw new NotSupportedException();
        }
        private void EffectParametersSerialization(System.Xml.XmlWriter writer, EffectParameter param)
        {
            switch (param.ParameterType)
            {
            case EffectParameterType.Bool:
                writer.WriteElementString("Value", XmlConvert.ToString(param.GetValueBoolean()));
                break;

            case EffectParameterType.Int32:
                writer.WriteElementString("Value", XmlConvert.ToString(param.GetValueInt32()));
                break;

            case EffectParameterType.Texture2D:
                writer.WriteElementString("Value", ResourceManager.Instance.Textures.FirstOrDefault(x => x.Value == param.GetValueTexture2D()).Key);
                break;

            case EffectParameterType.TextureCube:
                writer.WriteElementString("Value", ResourceManager.Instance.TexturesCube.FirstOrDefault(x => x.Value == param.GetValueTextureCube()).Key);
                break;

            case EffectParameterType.String:
                writer.WriteElementString("Value", param.GetValueString());
                break;

            case EffectParameterType.Single:
                CheckParameterClass(writer, param);
                break;

            default:
                writer.WriteElementString("Value", param.ParameterType.ToString());
                break;
            }
        }