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(); }
public Vector2Parameter(EffectParameter Param) : base(Param) { this.Value = Param.GetValueVector2(); }
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); }
private void CheckParameterClass(System.Xml.XmlWriter writer, EffectParameter param) { switch (param.ParameterClass) { case EffectParameterClass.Vector: if (param.RowCount == 1) { if (param.Elements.Count > 0) { writer.WriteStartElement("VectorValues"); for (int i = 0; i < param.Elements.Count; ++i) { writer.WriteElementString("Value", XmlConvert.ToString(param.Elements[i].GetValueVector3().X)); } writer.WriteEndElement(); } else { writer.WriteElementString("Value", XmlConvert.ToString(param.GetValueVector3().X)); } } if (param.RowCount == 2) { writer.WriteStartElement("Vector2Values"); writer.WriteElementString("Value", XmlConvert.ToString(param.GetValueVector2().X)); writer.WriteElementString("Value", XmlConvert.ToString(param.GetValueVector2().Y)); writer.WriteEndElement(); } if (param.RowCount == 3) { writer.WriteStartElement("Vector3Values"); writer.WriteElementString("Value", XmlConvert.ToString(param.GetValueVector3().X)); writer.WriteElementString("Value", XmlConvert.ToString(param.GetValueVector3().Y)); writer.WriteElementString("Value", XmlConvert.ToString(param.GetValueVector3().Z)); writer.WriteEndElement(); } if (param.RowCount == 4) { writer.WriteStartElement("Vector4Values"); writer.WriteElementString("Value", XmlConvert.ToString(param.GetValueVector4().X)); writer.WriteElementString("Value", XmlConvert.ToString(param.GetValueVector4().Y)); writer.WriteElementString("Value", XmlConvert.ToString(param.GetValueVector4().Z)); writer.WriteElementString("Value", XmlConvert.ToString(param.GetValueVector4().W)); writer.WriteEndElement(); } break; case EffectParameterClass.Scalar: if (param.Elements.Count > 0) { writer.WriteStartElement("ArrayValues"); for (int i = 0; i < param.Elements.Count; ++i) { writer.WriteElementString("Value", XmlConvert.ToString(param.Elements[i].GetValueSingle())); } writer.WriteEndElement(); } else { writer.WriteElementString("Value", XmlConvert.ToString(param.GetValueSingle())); } break; case EffectParameterClass.Matrix: writer.WriteElementString("Value", "Matrix"); break; default: writer.WriteElementString("Value", param.ParameterClass.ToString()); break; } }
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 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); }