Exemple #1
0
        private static EffectParameterCollection ReadParameters(BinaryReader reader)
        {
            var collection = new EffectParameterCollection();
            var count      = (int)reader.ReadByte();                     if (count == 0)

            {
                return(collection);
            }

            for (var i = 0; i < count; i++)
            {
                var class_ = (EffectParameterClass)reader.ReadByte();                           var type = (EffectParameterType)reader.ReadByte();
                var name        = reader.ReadString();
                var semantic    = reader.ReadString();
                var annotations = ReadAnnotations(reader);
                var rowCount    = (int)reader.ReadByte();
                var columnCount = (int)reader.ReadByte();

                var elements      = ReadParameters(reader);
                var structMembers = ReadParameters(reader);

                object data = null;
                if (elements.Count == 0 && structMembers.Count == 0)
                {
                    switch (type)
                    {
                    case EffectParameterType.Bool:
                    case EffectParameterType.Int32:                                                 { var buffer = new int[rowCount * columnCount];                                                           for (var j = 0; j < buffer.Length; j++)
                                                                                                      {
                                                                                                          buffer[j] = reader.ReadInt32();
                                                                                                      }
                                                                                                      data = buffer;                                                          break; }

                    case EffectParameterType.Single:
                    {
                        var buffer = new float[rowCount * columnCount];
                        for (var j = 0; j < buffer.Length; j++)
                        {
                            buffer[j] = reader.ReadSingle();
                        }
                        data = buffer;                                                          break;
                    }

                    case EffectParameterType.String:
                        throw new NotImplementedException();
                    }
                    ;
                }
                var param = new EffectParameter(
                    class_, type, name, rowCount, columnCount, semantic,
                    annotations, elements, structMembers, data);

                collection.Add(param);
            }

            return(collection);
        }
Exemple #2
0
        private EffectParameterCollection ReadParameters(BinaryReader reader)
        {
            EffectParameterCollection parameterCollection = new EffectParameterCollection();
            int num = (int)reader.ReadByte();

            if (num == 0)
            {
                return(parameterCollection);
            }
            for (int index1 = 0; index1 < num; ++index1)
            {
                EffectParameterClass class_ = (EffectParameterClass)reader.ReadByte();
                EffectParameterType  type   = (EffectParameterType)reader.ReadByte();
                string name     = reader.ReadString();
                string semantic = reader.ReadString();
                EffectAnnotationCollection annotations = Effect.ReadAnnotations(reader);
                int rowCount      = (int)reader.ReadByte();
                int columnCount   = (int)reader.ReadByte();
                int registerCount = this.version >= 3 ? (int)reader.ReadByte() : rowCount;
                EffectParameterCollection elements      = this.ReadParameters(reader);
                EffectParameterCollection structMembers = this.ReadParameters(reader);
                object data = (object)null;
                if (elements.Count == 0 && structMembers.Count == 0)
                {
                    switch (type)
                    {
                    case EffectParameterType.Bool:
                    case EffectParameterType.Int32:
                        int[] numArray1 = new int[rowCount * columnCount];
                        for (int index2 = 0; index2 < numArray1.Length; ++index2)
                        {
                            numArray1[index2] = reader.ReadInt32();
                        }
                        data = (object)numArray1;
                        break;

                    case EffectParameterType.Single:
                        float[] numArray2 = new float[rowCount * columnCount];
                        for (int index2 = 0; index2 < numArray2.Length; ++index2)
                        {
                            numArray2[index2] = reader.ReadSingle();
                        }
                        data = (object)numArray2;
                        break;

                    case EffectParameterType.String:
                        throw new NotImplementedException();
                    }
                }
                EffectParameter effectParameter = new EffectParameter(class_, type, name, rowCount, columnCount, registerCount, semantic, annotations, elements, structMembers, data);
                parameterCollection.Add(effectParameter);
            }
            return(parameterCollection);
        }
Exemple #3
0
        internal void ReadEffect(BinaryReader reader)
        {
            var effectPass = new EffectPass(this, "Pass", null, null, BlendState.AlphaBlend, DepthStencilState.Default, RasterizerState.CullNone, new EffectAnnotationCollection());

            effectPass._shaderProgram = new ShaderProgram(reader.ReadBytes((int)reader.BaseStream.Length));
            var shaderProgram = effectPass._shaderProgram;

            Parameters = new EffectParameterCollection();
            for (int i = 0; i < shaderProgram.UniformCount; i++)
            {
                Parameters.Add(EffectParameterForUniform(shaderProgram, i));
            }

                        #warning Hacks for BasicEffect as we don't have these parameters yet
            Parameters.Add(new EffectParameter(
                               EffectParameterClass.Vector, EffectParameterType.Single, "SpecularColor",
                               3, 1, "float3",
                               new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[3]));
            Parameters.Add(new EffectParameter(
                               EffectParameterClass.Scalar, EffectParameterType.Single, "SpecularPower",
                               1, 1, "float",
                               new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), 0.0f));
            Parameters.Add(new EffectParameter(
                               EffectParameterClass.Vector, EffectParameterType.Single, "FogVector",
                               4, 1, "float4",
                               new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[4]));
            Parameters.Add(new EffectParameter(
                               EffectParameterClass.Vector, EffectParameterType.Single, "DiffuseColor",
                               4, 1, "float4",
                               new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[4]));

            Techniques = new EffectTechniqueCollection();
            var effectPassCollection = new EffectPassCollection();
            effectPassCollection.Add(effectPass);
            Techniques.Add(new EffectTechnique(this, "Name", effectPassCollection, new EffectAnnotationCollection()));

            ConstantBuffers = new ConstantBuffer[0];

            CurrentTechnique = Techniques[0];
        }
Exemple #4
0
		internal void ReadEffect(BinaryReader reader)
		{
			var effectPass = new EffectPass(this, "Pass", null, null, BlendState.AlphaBlend, DepthStencilState.Default, RasterizerState.CullNone, new EffectAnnotationCollection());
			effectPass._shaderProgram = new ShaderProgram(reader.ReadBytes((int)reader.BaseStream.Length));
			var shaderProgram = effectPass._shaderProgram;
			Parameters = new EffectParameterCollection();
			for (int i = 0; i < shaderProgram.UniformCount; i++)
			{	
			    Parameters.Add(EffectParameterForUniform(shaderProgram, i));
			}
			
			#warning Hacks for BasicEffect as we don't have these parameters yet
            Parameters.Add (new EffectParameter(
                EffectParameterClass.Vector, EffectParameterType.Single, "SpecularColor",
                3, 1, "float3",
                new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[3]));
            Parameters.Add (new EffectParameter(
                EffectParameterClass.Scalar, EffectParameterType.Single, "SpecularPower",
                1, 1, "float",
                new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), 0.0f));
            Parameters.Add (new EffectParameter(
                EffectParameterClass.Vector, EffectParameterType.Single, "FogVector",
                4, 1, "float4",
                new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[4]));
            Parameters.Add (new EffectParameter(
                EffectParameterClass.Vector, EffectParameterType.Single, "DiffuseColor",
                4, 1, "float4",
                new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[4]));
            
            Techniques = new EffectTechniqueCollection();
            var effectPassCollection = new EffectPassCollection();
            effectPassCollection.Add(effectPass);
            Techniques.Add(new EffectTechnique(this, "Name", effectPassCollection, new EffectAnnotationCollection()));
       
            ConstantBuffers = new ConstantBuffer[0];
            
            CurrentTechnique = Techniques[0];
        }
Exemple #5
0
		private static EffectParameterCollection ReadParameters(BinaryReader reader)
		{
			var collection = new EffectParameterCollection();
			var count = (int)reader.ReadByte();			if (count == 0)				return collection;
			for (var i = 0; i < count; i++)
			{
				var class_ = (EffectParameterClass)reader.ReadByte();				var type = (EffectParameterType)reader.ReadByte();
				var name = reader.ReadString();
				var semantic = reader.ReadString();
				var annotations = ReadAnnotations(reader);
				var rowCount = (int)reader.ReadByte();
				var columnCount = (int)reader.ReadByte();

				var elements = ReadParameters(reader);
				var structMembers = ReadParameters(reader);

				object data = null;
				if (elements.Count == 0 && structMembers.Count == 0)
				{
					switch (type)
					{						case EffectParameterType.Bool:						case EffectParameterType.Int32:							{								var buffer = new int[rowCount * columnCount];								for (var j = 0; j < buffer.Length; j++)									buffer[j] = reader.ReadInt32();								data = buffer;								break;							}
						case EffectParameterType.Single:
							{
								var buffer = new float[rowCount * columnCount];
								for (var j = 0; j < buffer.Length; j++)									buffer[j] = reader.ReadSingle();								data = buffer;								break;							}
						case EffectParameterType.String:
							throw new NotImplementedException();
					};				}
				var param = new EffectParameter(
					class_, type, name, rowCount, columnCount, semantic, 
					annotations, elements, structMembers, data);

				collection.Add(param);
			}

			return collection;
		}
Exemple #6
0
 private EffectParameterCollection ReadParameters(BinaryReader reader)
 {
   EffectParameterCollection parameterCollection = new EffectParameterCollection();
   int num = (int) reader.ReadByte();
   if (num == 0)
     return parameterCollection;
   for (int index1 = 0; index1 < num; ++index1)
   {
     EffectParameterClass class_ = (EffectParameterClass) reader.ReadByte();
     EffectParameterType type = (EffectParameterType) reader.ReadByte();
     string name = reader.ReadString();
     string semantic = reader.ReadString();
     EffectAnnotationCollection annotations = Effect.ReadAnnotations(reader);
     int rowCount = (int) reader.ReadByte();
     int columnCount = (int) reader.ReadByte();
     int registerCount = this.version >= 5 ? (int) reader.ReadByte() : rowCount;
     EffectParameterCollection elements = this.ReadParameters(reader);
     EffectParameterCollection structMembers = this.ReadParameters(reader);
     object data = (object) null;
     if (elements.Count == 0 && structMembers.Count == 0)
     {
       switch (type)
       {
         case EffectParameterType.Bool:
         case EffectParameterType.Int32:
         case EffectParameterType.Single:
           float[] numArray = new float[rowCount * columnCount];
           for (int index2 = 0; index2 < numArray.Length; ++index2)
             numArray[index2] = reader.ReadSingle();
           data = (object) numArray;
           break;
         case EffectParameterType.String:
           throw new NotImplementedException();
       }
     }
     EffectParameter effectParameter = new EffectParameter(class_, type, name, rowCount, columnCount, registerCount, semantic, annotations, elements, structMembers, data);
     parameterCollection.Add(effectParameter);
   }
   return parameterCollection;
 }
Exemple #7
0
        private static EffectParameterCollection ReadParameters(BinaryReader reader)
        {
            var collection = new EffectParameterCollection();
            var count      = (int)reader.ReadByte();

            if (count == 0)
            {
                return(collection);
            }

            for (var i = 0; i < count; i++)
            {
                var class_      = (EffectParameterClass)reader.ReadByte();
                var type        = (EffectParameterType)reader.ReadByte();
                var name        = reader.ReadString();
                var semantic    = reader.ReadString();
                var annotations = ReadAnnotations(reader);
                var rowCount    = (int)reader.ReadByte();
                var columnCount = (int)reader.ReadByte();

                var elements      = ReadParameters(reader);
                var structMembers = ReadParameters(reader);

                object data = null;
                if (elements.Count == 0 && structMembers.Count == 0)
                {
                    switch (type)
                    {
                    case EffectParameterType.Bool:
                    case EffectParameterType.Int32:
#if DIRECTX
                        // Under DirectX we properly store integers and booleans
                        // in an integer type.
                        //
                        // MojoShader on the otherhand stores everything in float
                        // types which is why this code is disabled under OpenGL.
                    {
                        var buffer = new int[rowCount * columnCount];
                        for (var j = 0; j < buffer.Length; j++)
                        {
                            buffer[j] = reader.ReadInt32();
                        }
                        data = buffer;
                        break;
                    }
#endif

                    case EffectParameterType.Single:
                    {
                        var buffer = new float[rowCount * columnCount];
                        for (var j = 0; j < buffer.Length; j++)
                        {
                            buffer[j] = reader.ReadSingle();
                        }
                        data = buffer;
                        break;
                    }

                    case EffectParameterType.String:
                        throw new NotImplementedException();
                    }
                }
                var param = new EffectParameter(
                    class_, type, name, rowCount, columnCount, semantic,
                    annotations, elements, structMembers, data);

                collection.Add(param);
            }

            return(collection);
        }