Ejemplo n.º 1
0
        private object ReadParamData(ShaderParamType type, BinaryDataReader reader)
        {
            switch (type)
            {
            case ShaderParamType.Bool: return(reader.ReadBoolean());

            case ShaderParamType.Bool2: return(reader.ReadBooleans(2));

            case ShaderParamType.Bool3: return(reader.ReadBooleans(3));

            case ShaderParamType.Bool4: return(reader.ReadBooleans(4));

            case ShaderParamType.Float: return(reader.ReadSingle());

            case ShaderParamType.Float2: return(reader.ReadSingles(2));

            case ShaderParamType.Float2x2: return(reader.ReadSingles(2 * 2));

            case ShaderParamType.Float2x3: return(reader.ReadSingles(2 * 3));

            case ShaderParamType.Float2x4: return(reader.ReadSingles(2 * 4));

            case ShaderParamType.Float3: return(reader.ReadSingles(3));

            case ShaderParamType.Float3x2: return(reader.ReadSingles(3 * 2));

            case ShaderParamType.Float3x3: return(reader.ReadSingles(3 * 3));

            case ShaderParamType.Float3x4: return(reader.ReadSingles(3 * 4));

            case ShaderParamType.Float4: return(reader.ReadSingles(4));

            case ShaderParamType.Float4x2: return(reader.ReadSingles(4 * 2));

            case ShaderParamType.Float4x3: return(reader.ReadSingles(4 * 3));

            case ShaderParamType.Float4x4: return(reader.ReadSingles(4 * 4));

            case ShaderParamType.Int: return(reader.ReadInt32());

            case ShaderParamType.Int2: return(reader.ReadInt32s(2));

            case ShaderParamType.Int3: return(reader.ReadInt32s(3));

            case ShaderParamType.Int4: return(reader.ReadInt32s(4));

            case ShaderParamType.UInt: return(reader.ReadInt32());

            case ShaderParamType.UInt2: return(reader.ReadInt32s(2));

            case ShaderParamType.UInt3: return(reader.ReadInt32s(3));

            case ShaderParamType.UInt4: return(reader.ReadInt32s(4));

            case ShaderParamType.Reserved2: return(reader.ReadBytes(2));

            case ShaderParamType.Reserved3: return(reader.ReadBytes(3));

            case ShaderParamType.Reserved4: return(reader.ReadBytes(4));

            case ShaderParamType.Srt2D:
                return(new Srt2D()
                {
                    Scaling = reader.ReadVector2F(),
                    Rotation = reader.ReadSingle(),
                    Translation = reader.ReadVector2F(),
                });

            case ShaderParamType.Srt3D:
                return(new Srt3D()
                {
                    Scaling = reader.ReadVector3F(),
                    Rotation = reader.ReadVector3F(),
                    Translation = reader.ReadVector3F(),
                });

            case ShaderParamType.TexSrt:
                return(new TexSrt()
                {
                    Mode = (TexSrtMode)reader.ReadInt32(),
                    Scaling = reader.ReadVector2F(),
                    Rotation = reader.ReadSingle(),
                    Translation = reader.ReadVector2F(),
                });

            case ShaderParamType.TexSrtEx:
                return(new TexSrtEx()
                {
                    Mode = (TexSrtMode)reader.ReadInt32(),
                    Scaling = reader.ReadVector2F(),
                    Rotation = reader.ReadSingle(),
                    Translation = reader.ReadVector2F(),
                    MatrixPointer = reader.ReadUInt32(),
                });
            }
            return(0);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="reader"></param>
        /// <param name="Size"></param>
        /// <param name="type"></param>
        public static void WriteValue(XmlWriter writer, BinaryDataReader reader, int Size, ShaderParamType type)
        {
            switch (type)
            {
            case ShaderParamType.Bool:
            case ShaderParamType.Bool2:
            case ShaderParamType.Bool3:
            case ShaderParamType.Bool4:
                ValueBool = reader.ReadBooleans(Size / sizeof(bool));
                string tempBools = "";
                foreach (bool value in ValueBool)
                {
                    tempBools += (value.ToString() + ',');
                }
                tempBools = tempBools.Trim(',');
                writer.WriteAttributeString("Value", tempBools);
                break;

            case ShaderParamType.Float:
            case ShaderParamType.Float2:
            case ShaderParamType.Float3:
            case ShaderParamType.Float4:
            case ShaderParamType.Float2x2:
            case ShaderParamType.Float2x3:
            case ShaderParamType.Float2x4:
            case ShaderParamType.Float4x2:
            case ShaderParamType.Float4x3:
            case ShaderParamType.Float4x4:
                ValueFloat = reader.ReadSingles(Size / sizeof(float));
                string tempFloat = "";
                foreach (float value in ValueFloat)
                {
                    tempFloat += (value.ToString() + ',');
                }
                tempFloat = tempFloat.Trim(',');
                writer.WriteAttributeString("Value", tempFloat);
                break;

            case ShaderParamType.Int:
            case ShaderParamType.Int2:
            case ShaderParamType.Int3:
            case ShaderParamType.Int4:
                ValueInt = reader.ReadInt32s(Size / sizeof(int));
                string tempInts = "";
                foreach (int value in ValueInt)
                {
                    tempInts += (value.ToString() + ',');
                }
                tempInts = tempInts.Trim(',');
                writer.WriteAttributeString("Value", tempInts);
                break;

            case ShaderParamType.Reserved2:
            case ShaderParamType.Reserved3:
            case ShaderParamType.Reserved4:
                ValueReserved = reader.ReadBytes(Size / sizeof(byte));
                string tempBytes = "";
                foreach (byte value in ValueReserved)
                {
                    tempBytes += (value.ToString() + ',');
                }
                tempBytes = tempBytes.Trim(',');
                writer.WriteAttributeString("Value", tempBytes);
                break;

            case ShaderParamType.Srt2D:
                ReadSRT2D(reader);
                string srt2DScaling = "";
                srt2DScaling += (ValueSrt2D.Scaling.X.ToString() + ',');
                srt2DScaling += (ValueSrt2D.Scaling.Y.ToString());
                writer.WriteAttributeString("ValueScaleXY", srt2DScaling);
                string srt2DRot = "";
                srt2DRot += (ValueSrt2D.Rotation.ToString());
                writer.WriteAttributeString("ValueRotationX", srt2DRot);
                string srt2DTranslation = "";
                srt2DTranslation += (ValueSrt2D.Translation.X.ToString() + ',');
                srt2DTranslation += (ValueSrt2D.Translation.Y.ToString());
                writer.WriteAttributeString("ValueTranslationXY", srt2DTranslation);
                break;

            case ShaderParamType.Srt3D:
                ReadSRT3D(reader);
                string srt3DScaling = "";
                srt3DScaling += (ValueSrt3D.Scaling.X.ToString() + ',');
                srt3DScaling += (ValueSrt3D.Scaling.Y.ToString() + ',');
                srt3DScaling += (ValueSrt3D.Scaling.Z.ToString());
                writer.WriteAttributeString("ValueScaleXYZ", srt3DScaling);
                string srt3DRot = "";
                srt3DRot += (ValueSrt3D.Rotation.X.ToString() + ',');
                srt3DRot += (ValueSrt3D.Rotation.Y.ToString() + ',');
                srt3DRot += (ValueSrt3D.Rotation.Z.ToString());
                writer.WriteAttributeString("ValueRotationXYZ", srt3DRot);
                string srt3DTranslation = "";
                srt3DTranslation += (ValueSrt3D.Translation.X.ToString() + ',');
                srt3DTranslation += (ValueSrt3D.Translation.Y.ToString() + ',');
                srt3DTranslation += (ValueSrt3D.Translation.Z.ToString());
                writer.WriteAttributeString("ValueTranslationXYZ", srt3DTranslation);
                break;

            case ShaderParamType.TexSrt:
                ReadTexSrt(reader);
                writer.WriteAttributeString("Mode", ValueTexSrt.Mode.ToString());
                string texScaling = "";
                texScaling += (ValueTexSrt.Scaling.X.ToString() + ',');
                texScaling += (ValueTexSrt.Scaling.Y.ToString());
                writer.WriteAttributeString("ValueScaleXY", texScaling);
                string texRot = "";
                texRot += (ValueTexSrt.Rotation.ToString());
                writer.WriteAttributeString("ValueRotationX", texRot);
                string texTranslation = "";
                texTranslation += (ValueTexSrt.Translation.X.ToString() + ',');
                texTranslation += (ValueTexSrt.Translation.Y.ToString());
                writer.WriteAttributeString("ValueTranslationXY", texTranslation);
                break;

            case ShaderParamType.TexSrtEx:
                ReadTexSrtEx(reader);
                writer.WriteAttributeString("Mode", ValueTexSrtEx.Mode.ToString());
                string texExScaling = "";
                texExScaling += (ValueTexSrtEx.Scaling.X.ToString() + ',');
                texExScaling += (ValueTexSrtEx.Scaling.Y.ToString());
                writer.WriteAttributeString("ValueScaleXY", texExScaling);
                string texExRot = "";
                texExRot += (ValueTexSrtEx.Rotation.ToString());
                writer.WriteAttributeString("ValueRotationX", texExRot);
                string texExTranslation = "";
                texExTranslation += (ValueTexSrtEx.Translation.X.ToString() + ',');
                texExTranslation += (ValueTexSrtEx.Translation.Y.ToString());
                writer.WriteAttributeString("ValueTranslationXY", texExTranslation);
                writer.WriteAttributeString("MatrixPointer", ValueTexSrtEx.MatrixPointer.ToString());
                break;

            case ShaderParamType.UInt:
            case ShaderParamType.UInt2:
            case ShaderParamType.UInt3:
            case ShaderParamType.UInt4:
                ValueUint = reader.ReadUInt32s(Size / sizeof(uint));
                string tempUints = "";
                foreach (uint value in ValueUint)
                {
                    tempUints += (value.ToString() + ',');
                }
                tempUints = tempUints.Trim(',');
                writer.WriteAttributeString("Value", tempUints);
                break;

            // Invalid
            default:
                //throw new ArgumentException($"Invalid {nameof(ShaderParamType)} {type}.", nameof(type));
                break;
            }
        }