Axiom.Serialization.MaterialSerializer.ProcessManualProgramParam C# (CSharp) Метод

ProcessManualProgramParam() защищенный статический Метод

protected static ProcessManualProgramParam ( int index, string commandName, string parameters, MaterialScriptContext context ) : void
index int
commandName string
parameters string
context MaterialScriptContext
Результат void
		protected static void ProcessManualProgramParam( int index, string commandName, string[] parameters, MaterialScriptContext context )
		{
			// NB we assume that the first element of vecparams is taken up with either
			// the index or the parameter name, which we ignore

			int dims, roundedDims;
			bool isFloat = false;
			string type = parameters[ 1 ].ToLower();

			if ( type == "matrix4x4" )
			{
				dims = 16;
				isFloat = true;
			}
			else if ( type.IndexOf( "float" ) != -1 )
			{
				if ( type == "float" )
				{
					dims = 1;
				}
				else
				{
					// the first 5 letters are "float", get the dim indicator at the end
					// this handles entries like 'float4'
					dims = int.Parse( type.Substring( 5 ) );
				}

				isFloat = true;
			}
			else if ( type.IndexOf( "int" ) != -1 )
			{
				if ( type == "int" )
				{
					dims = 1;
				}
				else
				{
					// the first 5 letters are "int", get the dim indicator at the end
					dims = int.Parse( type.Substring( 3 ) );
				}
			}
			else
			{
				LogParseError( context, "Invalid {0} attribute - unrecognized parameter type {1}.", commandName, type );
				return;
			}

			// make sure we have enough params for this type's size
			if ( parameters.Length != 2 + dims )
			{
				LogParseError( context, "Invalid {0} attribute - you need {1} parameters for a parameter of type {2}", commandName, 2 + dims, type );
				return;
			}

			// Round dims to multiple of 4
			if ( dims % 4 != 0 )
			{
				roundedDims = dims + 4 - ( dims % 4 );
			}
			else
			{
				roundedDims = dims;
			}

			int i = 0;

			// now parse all the values
			if ( isFloat )
			{
				float[] buffer = new float[ roundedDims ];

				// do specified values
				for ( i = 0; i < dims; i++ )
				{
					buffer[ i ] = StringConverter.ParseFloat( parameters[ i + 2 ] );
				}

				// fill up to multiple of 4 with zero
				for ( ; i < roundedDims; i++ )
				{
					buffer[ i ] = 0.0f;
				}

				context.programParams.SetConstant( index, buffer );
			}
			else
			{
				int[] buffer = new int[ roundedDims ];

				// do specified values
				for ( i = 0; i < dims; i++ )
				{
					buffer[ i ] = int.Parse( parameters[ i + 2 ] );
				}

				// fill up to multiple of 4 with zero
				for ( ; i < roundedDims; i++ )
				{
					buffer[ i ] = 0;
				}

				context.programParams.SetConstant( index, buffer );
			}
		}