protected bool ParseScriptLine( string line )
{
switch ( scriptContext.section )
{
case MaterialScriptSection.None:
if ( line == "}" )
{
LogParseError( scriptContext, "Unexpected terminating brace." );
return false;
}
else
{
// find and invoke a parser
return InvokeParser( line, rootAttribParsers );
}
case MaterialScriptSection.Material:
if ( line == "}" )
{
// end of material
// if texture aliases were found, pass them to the material
// to update texture names used in Texture unit states
if ( scriptContext.textureAliases.Count != 0 )
{
// request material to update all texture names in TUS's
// that use texture aliases in the list
scriptContext.material.ApplyTextureAliases( scriptContext.textureAliases, true );
}
scriptContext.section = MaterialScriptSection.None;
scriptContext.material = null;
// reset all levels for the next material
scriptContext.passLev = -1;
scriptContext.stateLev = -1;
scriptContext.techLev = -1;
scriptContext.textureAliases.Clear();
}
else
{
// find and invoke parser
return InvokeParser( line, materialAttribParsers );
}
break;
case MaterialScriptSection.Technique:
if ( line == "}" )
{
// end of technique
scriptContext.section = MaterialScriptSection.Material;
scriptContext.technique = null;
scriptContext.passLev = -1;
}
else
{
// find and invoke parser
return InvokeParser( line, techniqueAttribParsers );
}
break;
case MaterialScriptSection.Pass:
if ( line == "}" )
{
// end of pass
scriptContext.section = MaterialScriptSection.Technique;
scriptContext.pass = null;
scriptContext.stateLev = -1;
}
else
{
// find and invoke parser
return InvokeParser( line, passAttribParsers );
}
break;
case MaterialScriptSection.TextureUnit:
if ( line == "}" )
{
// end of texture unit
scriptContext.section = MaterialScriptSection.Pass;
scriptContext.textureUnit = null;
}
else
{
// find and invoke parser
return InvokeParser( line, textureUnitAttribParsers );
}
break;
case MaterialScriptSection.TextureSource:
// TODO: Implement
LogParseError( scriptContext, "Texture Source sections are not yet supported!" );
break;
case MaterialScriptSection.ProgramRef:
if ( line == "}" )
{
// end of program
scriptContext.section = MaterialScriptSection.Pass;
scriptContext.program = null;
}
else
{
// find and invoke a parser
return InvokeParser( line, programRefAttribParsers );
}
break;
case MaterialScriptSection.Program:
// Program definitions are slightly different, they are deferred
// until all the information required is known
if ( line == "}" )
{
// end of program
FinishProgramDefinition();
scriptContext.section = MaterialScriptSection.None;
scriptContext.defaultParamLines.Clear();
scriptContext.programDef = null;
}
else
{
// 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( line, new char[] { ' ', '\t' }, 2 );
// find attribute parser
if ( programAttribParsers.ContainsKey( splitCmd[ 0 ] ) )
{
// Use parser, make sure we have 2 params before using splitCmd[1]
string cmd = splitCmd.Length >= 2 ? splitCmd[ 1 ] : string.Empty;
//MaterialAttributeParserHandler handler = (MaterialAttributeParserHandler)programAttribParsers[ splitCmd[ 0 ] ];
MethodInfo handler = (MethodInfo)programAttribParsers[ splitCmd[ 0 ] ];
return (bool)handler.Invoke( null, new object[] { cmd, scriptContext } );
//return handler( cmd, scriptContext );
}
else
{
// custom parameter, use original line
ParseProgramCustomParameter( line, scriptContext );
}
}
break;
case MaterialScriptSection.DefaultParameters:
if ( line == "}" )
{
// End of default parameters
scriptContext.section = MaterialScriptSection.Program;
}
else
{
// Save default parameter lines up until we finalise the program
scriptContext.defaultParamLines.Add( line );
}
break;
}
return false;
}