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

FinishProgramDefinition() защищенный Метод

Internal method for saving a program definition which has been built up.
protected FinishProgramDefinition ( ) : void
Результат void
		protected void FinishProgramDefinition()
		{
			MaterialScriptProgramDefinition def = scriptContext.programDef;
			GpuProgram gp = null;

			if ( def.language == "asm" )
			{
				// native assembler
				// validate
				if ( def.source == string.Empty )
				{
					LogParseError( scriptContext, "Invalid program definition for {0}, you must specify a source file.", def.name );
				}
				if ( def.syntax == string.Empty )
				{
					LogParseError( scriptContext, "Invalid program definition for {0}, you must specify a syntax code.", def.name );
				}

				// create
				gp = GpuProgramManager.Instance.CreateProgram( def.name, scriptContext.groupName, def.source, def.progType, def.syntax );
			}
			else
			{
				// high level program
				// validate
				if ( def.source == string.Empty && def.language != "unified" )
				{
					LogParseError( scriptContext, "Invalid program definition for {0}, you must specify a source file.", def.name );
				}
				// create
				try
				{
					HighLevelGpuProgram hgp = HighLevelGpuProgramManager.Instance.CreateProgram( def.name, scriptContext.groupName, def.language, def.progType );
					gp = hgp;
					// set source file
					hgp.SourceFile = def.source;

					// set custom parameters
					foreach ( KeyValuePair<string, string> entry in def.customParameters )
					{
						string param = entry.Key;
						string val = entry.Value;

						if ( !hgp.SetParam( param, val ) )
						{
							LogParseError( scriptContext, "Error in program {0} parameter {1} is not valid.", def.name, param );
						}
					}
				}
				catch ( Exception ex )
				{
					LogManager.Instance.Write( "Could not create GPU program '{0}'. error reported was: {1}.", def.name, ex.Message );
					return;
				}
			}
			if ( gp == null )
			{
				LogManager.Instance.Write( string.Format( "Failed to create {0} {1} GPU program named '{2}' using syntax {3}.  This is likely due to your hardware not supporting advanced high-level shaders.",
					def.language, def.progType, def.name, def.syntax ) );
				return;
			}

			// set skeletal animation option
			gp.IsSkeletalAnimationIncluded = def.supportsSkeletalAnimation;
			gp.IsMorphAnimationIncluded = def.supportsMorphAnimation;
			gp.PoseAnimationCount = def.poseAnimationCount;

			// set up to receive default parameters
			if ( gp.IsSupported && scriptContext.defaultParamLines.Count > 0 )
			{
				scriptContext.programParams = gp.DefaultParameters;
				scriptContext.program = gp;

				for ( int i = 0; i < scriptContext.defaultParamLines.Count; i++ )
				{
					// find & invoke a parser
					// do this manually because we want to call a custom
					// routine when the parser is not found
					// First, split line on first divisor only
					string[] splitCmd = StringConverter.Split( scriptContext.defaultParamLines[ i ], new char[] { ' ', '\t' }, 2 );

					// find attribute parser
					if ( programDefaultParamAttribParsers.ContainsKey( splitCmd[ 0 ] ) )
					{
						string cmd = splitCmd.Length >= 2 ? splitCmd[ 1 ] : string.Empty;

						//MaterialAttributeParserHandler handler = (MaterialAttributeParserHandler)programDefaultParamAttribParsers[ splitCmd[ 0 ] ];
						MethodInfo handler = (MethodInfo)programDefaultParamAttribParsers[ splitCmd[ 0 ] ];
						// Use parser, make sure we have 2 params before using splitCmd[1]
						handler.Invoke( null, new object[] { cmd, scriptContext } );
						//handler( cmd, scriptContext );
					}
				}

				// reset
				scriptContext.program = null;
				scriptContext.programParams = null;
			}
		}