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; } }
private static void GetParameterValues(EffectParameter parameter, Dictionary<EffectParameter, object> values) { if (parameter.ParameterClass == EffectParameterClass.Struct) { if (parameter.Elements.Count > 0) { // ----- Effect parameter is an array of structs. foreach (EffectParameter element in parameter.Elements) GetParameterValues(element, values); } else { // ----- Effect parameter is a struct. foreach (EffectParameter member in parameter.StructureMembers) GetParameterValues(member, values); } return; } object value = null; if (parameter.Elements.Count == 0) { // ----- Parameter is not an array. if (parameter.ParameterClass == EffectParameterClass.Scalar) { // Scalar values. if (parameter.ParameterType == EffectParameterType.Bool) value = parameter.GetValueBoolean(); else if (parameter.ParameterType == EffectParameterType.Int32) value = parameter.GetValueInt32(); else if (parameter.ParameterType == EffectParameterType.Single) value = parameter.GetValueSingle(); } else if (parameter.ParameterClass == EffectParameterClass.Vector && parameter.ParameterType == EffectParameterType.Single) { // Vector values. if (parameter.ColumnCount == 2 || parameter.RowCount == 2) value = parameter.GetValueVector2(); else if (parameter.ColumnCount == 3 || parameter.RowCount == 3) value = parameter.GetValueVector3(); else if (parameter.ColumnCount == 4 || parameter.RowCount == 4) value = parameter.GetValueVector4(); } else if (parameter.ParameterClass == EffectParameterClass.Matrix && parameter.ParameterType == EffectParameterType.Single) { // Matrix value. value = parameter.GetValueMatrix(); #else // MonoGame throws exception if following condition is not met. if (parameter.RowCount == 4 || parameter.ColumnCount == 4) value = parameter.GetValueMatrix(); } else if (parameter.ParameterClass == EffectParameterClass.Object) { // Object values. if (parameter.ParameterType == EffectParameterType.String) { value = parameter.GetValueString(); } else { // Effect parameter is texture. (Value is always null.) } } } else { // ----- Parameter is array. int length = parameter.Elements.Count; Debug.Assert(length > 0, "Effect parameter should be an array."); if (parameter.ParameterClass == EffectParameterClass.Scalar) { // Scalar value bindings. if (parameter.ParameterType == EffectParameterType.Bool) value = parameter.GetValueBooleanArray(length); else if (parameter.ParameterType == EffectParameterType.Int32) value = parameter.GetValueInt32Array(length); else if (parameter.ParameterType == EffectParameterType.Single) value = parameter.GetValueSingleArray(length); } else if (parameter.ParameterClass == EffectParameterClass.Vector && parameter.ParameterType == EffectParameterType.Single) { if (parameter.ColumnCount == 2 || parameter.RowCount == 2) value = parameter.GetValueVector2Array(length); else if (parameter.ColumnCount == 3 || parameter.RowCount == 3) value = parameter.GetValueVector3Array(length); else if (parameter.ColumnCount == 4 || parameter.RowCount == 4) value = parameter.GetValueVector4Array(length); } else if (parameter.ParameterClass == EffectParameterClass.Matrix && parameter.ParameterType == EffectParameterType.Single) { value = parameter.GetValueMatrixArray(length); } else if (parameter.ParameterClass == EffectParameterClass.Object) { // Note: Arrays of strings or textures are not supported in XNA. } } if (value != null) values.Add(parameter, value); }
public override object GetValue(object component) { switch (mParameter.ParameterType) { case EffectParameterType.Bool: return(mParameter.GetValueBoolean()); break; case EffectParameterType.Int32: return(mParameter.GetValueInt32()); break; case EffectParameterType.Single: switch (mParameter.ParameterClass) { case EffectParameterClass.MatrixColumns: return(mParameter.GetValueMatrix()); break; case EffectParameterClass.MatrixRows: return(mParameter.GetValueMatrix()); break; case EffectParameterClass.Scalar: return(mParameter.GetValueSingle()); break; case EffectParameterClass.Vector: switch (mParameter.ColumnCount) { case 1: return(mParameter.GetValueSingle()); break; case 2: return(mParameter.GetValueVector2()); break; case 3: return(mParameter.GetValueVector3()); break; case 4: return(mParameter.GetValueVector4()); break; default: return(null); break; } break; default: return(mParameter.GetValueSingle()); break; } break; case EffectParameterType.String: return(mParameter.GetValueString()); break; case EffectParameterType.Texture: case EffectParameterType.Texture2D: Texture2D texture = mParameter.GetValueTexture2D(); return((texture != null && texture.Name != string.Empty) ? texture.Name.Replace('/', Path.DirectorySeparatorChar) : ((mTagString != null && mTagString != string.Empty) ? mTagString.Replace('/', Path.DirectorySeparatorChar) : String.Empty)); break; default: return(null); break; } return(null); }
public override object GetValue(object component) { switch (mParameter.ParameterType) { case EffectParameterType.Bool: return(mParameter.GetValueBoolean()); break; case EffectParameterType.Int32: return(mParameter.GetValueInt32()); break; case EffectParameterType.Single: switch (mParameter.ParameterClass) { case EffectParameterClass.MatrixColumns: return(mParameter.GetValueMatrix()); break; case EffectParameterClass.MatrixRows: return(mParameter.GetValueMatrix()); break; case EffectParameterClass.Scalar: return(mParameter.GetValueSingle()); break; case EffectParameterClass.Vector: switch (mParameter.ColumnCount) { case 1: return(mParameter.GetValueSingle()); break; case 2: return(mParameter.GetValueVector2()); break; case 3: return(mParameter.GetValueVector3()); break; case 4: return(mParameter.GetValueVector4()); break; default: return(null); break; } break; default: return(mParameter.GetValueSingle()); break; } break; case EffectParameterType.String: return(mParameter.GetValueString()); break; case EffectParameterType.Texture: return((mTagString != null) ? mTagString : String.Empty); break; default: return(null); break; } return(null); }
public StringParameter(EffectParameter Param) : base(Param) { this.Value = Param.GetValueString(); }