Пример #1
0
        }   // end of InitFromPart()

        /// <summary>
        /// Extracts a color from an EffectParameter.
        /// </summary>
        /// <param name="param"></param>
        /// <returns>The extracted color.</returns>
        private Vector4 GetColor(EffectParameter param)
        {
            float[] tmp = new float[3];
#if NETFX_CORE
            tmp = param.GetValueSingleArray();
#else
            tmp = param.GetValueSingleArray(3);
#endif

            Vector4 result = new Vector4(tmp[0], tmp[1], tmp[2], 1.0f);

            return(result);
        }   // end of PartInfo GetColor()
    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);
    }