本文整理汇总了C#中Tokenizer.ReadBlock方法的典型用法代码示例。如果您正苦于以下问题:C# Tokenizer.ReadBlock方法的具体用法?C# Tokenizer.ReadBlock怎么用?C# Tokenizer.ReadBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tokenizer
的用法示例。
在下文中一共展示了Tokenizer.ReadBlock方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterSet
public RegisterSet(string header)
{
//extract the registers used...
/*
* Example header:
*
//
// Generated by Microsoft (R) D3DX9 Shader Compiler 9.15.779.0000
//
// Parameters:
//
// float2 shadowCameraNearFar;
//
//
// Registers:
//
// Name Reg Size
// ------------------- ----- ----
// shadowCameraNearFar c0 1
//
*
*/
Dictionary<string, Register> registers = new Dictionary<string, Register>();
Tokenizer tokenizer = new Tokenizer(header, false, true, true);
string[] lines = header.Split('\n');
int state = 0;
while (tokenizer.NextToken())
{
switch (tokenizer.Token)
{
case ":":
break;
case "Parameters":
state = 1;
break;
case "//":
//determine if the line has content...
if (lines[tokenizer.Line].Trim().Length > 2)
{
if (state == 1)
{
//try and extract something
// float2 shadowCameraNearFar;
tokenizer.NextToken();
string type = tokenizer.Token;
tokenizer.NextToken();
if (type == "Registers")
{
state = 2; //done, go to registers
break;
}
if (type == "struct")
{
string structContents = "";
string structName = "";
try
{
while (tokenizer.Token != "{")
tokenizer.NextToken();
tokenizer.ReadBlock();
structContents = tokenizer.Token;
tokenizer.NextToken();
structName = tokenizer.Token;
}
catch
{
}
finally
{
throw new CompileException(string.Format("Shader compiler cannot map the custom constant structure '{0} {1}' into a compatible XNA data structure", structName, structContents.Replace(Environment.NewLine, "").Replace("//","")));
}
}
string name = tokenizer.Token;
//possible array, or ;
tokenizer.NextToken();
string token = tokenizer.Token;
int array = -1;
if (token == "[")
{
tokenizer.NextToken();
array = int.Parse(tokenizer.Token);
tokenizer.NextToken(); //eat the ]
tokenizer.NextToken();
}
//should be a ;
//.........这里部分代码省略.........
示例2: ExtractTechniques
//this is a bit of a hack.
//it relies on the fact that the DirectX shader compiler
//marks up the disasembled shader with comments detailing the shader inputs.
public static AsmTechnique[] ExtractTechniques(SourceShader shader, Platform platform, out DecompiledEffect fx, string generatedPrefix)
{
//decompile the shader
fx = new DecompiledEffect(shader, platform);
//break it up into techniques
Tokenizer assemblyTokens = new Tokenizer(fx.DecompiledAsm, false, true, true);
List<AsmTechnique> techniqes = new List<AsmTechnique>();
while (assemblyTokens.NextToken())
{
if (assemblyTokens.Token.Equals("technique", StringComparison.InvariantCultureIgnoreCase))
{
//should be format:
//technique NAME
//{
//}
assemblyTokens.NextToken();
string name = assemblyTokens.Token;
if (generatedPrefix != null)
{
//only include generated techniques
if (name.EndsWith(generatedPrefix))
name = name.Substring(0, name.Length - generatedPrefix.Length);
else
continue;
}
assemblyTokens.NextToken();
//may be a line break
if (assemblyTokens.Token.Trim().Length == 0)
assemblyTokens.NextToken();
//should be a {
if (assemblyTokens.Token != "{")
throw new CompileException("Unexpected token in assembly technique declaration, expected '{': " + assemblyTokens.Token);
// read the entire technique {} block
if (!assemblyTokens.ReadBlock())
throw new CompileException("Unexpected end of string in assembly technique pass declaration");
AsmTechnique asm = new AsmTechnique(name, assemblyTokens.Token, fx.GetTechniqueDefaultValues(name));
if (!shader.SkipConstantValidation)
{
//do some extra validation to make sure pixel inputs match vertex outputs
asm.ValidatePixleShaderInput(shader, platform);
}
techniqes.Add(asm);
}
}
for (int i = 0; i < techniqes.Count; i++)
{
techniqes[i].MergeSemantics(fx.EffectRegisters);
}
return techniqes.ToArray();
}
示例3: ProcessPass
private void ProcessPass(string pass)
{
//vsListing, psListing
bool definesPixelShader = false, definesVertexShader = false;
//extract the shader code
Tokenizer tokenizer = new Tokenizer(pass, false, true, true);
while (tokenizer.NextToken())
{
if (tokenizer.Token == "vertexshader")
{
while (tokenizer.NextToken())
{
if (tokenizer.Token == "asm")
{
definesVertexShader = true;
//extract the vertex shader
tokenizer.NextToken();
if (tokenizer.Token != "{")
throw new CompileException("Expected token in asm vertexshader: '" + tokenizer.Token + "' - expected '{'");
tokenizer.ReadBlock();
ProcessShader(tokenizer.Token, out this.vsListing, out vertexShaderComment);
break;
}
}
}
if (tokenizer.Token == "pixelshader")
{
while (tokenizer.NextToken())
{
if (tokenizer.Token == "asm")
{
definesPixelShader = true;
//extract the pixel shader
tokenizer.NextToken();
if (tokenizer.Token != "{")
throw new CompileException("Expected token in asm pixelshader: '" + tokenizer.Token + "' - expected '{'");
tokenizer.ReadBlock();
ProcessShader(tokenizer.Token, out this.psListing, out pixelShaderComment);
break;
}
}
}
}
if (!definesVertexShader)
throw new CompileException(string.Format("Default pass in technique '{0}' does not define a vertex shader", this.name));
if (!definesPixelShader)
throw new CompileException(string.Format("Default pass in technique '{0}' does not define a pixel shader", this.name));
}
示例4: ProcessSupplimentaryPass
private AsmListing ProcessSupplimentaryPass(string pass)
{
if (pass == null)
return null;
//vsListing, psListing
AsmListing listing = null;
bool definesVertexShader = false;
//extract the shader code
Tokenizer tokenizer = new Tokenizer(pass, false, true, true);
while (tokenizer.NextToken())
{
if (tokenizer.Token == "vertexshader")
{
while (tokenizer.NextToken())
{
if (tokenizer.Token == "asm")
{
definesVertexShader = true;
//extract the vertex shader
tokenizer.NextToken();
if (tokenizer.Token != "{")
throw new CompileException("Expected token in asm vertexshader: '" + tokenizer.Token + "' - expected '{'");
tokenizer.ReadBlock();
string comment;
ProcessShader(tokenizer.Token, out listing, out comment);
break;
}
}
}
if (tokenizer.Token == "pixelshader")
{
throw new CompileException("A technique pass defining Animation or Instancing may not specify a pixel shader");
}
}
if (!definesVertexShader)
throw new CompileException(string.Format("Extension pass in technique '{0}' does not define a vertex shader", this.name));
return listing;
}
示例5: AsmTechnique
private AsmTechnique(string name, string source, TechniqueExtraData defaultValues)
{
Tokenizer tokenizer = new Tokenizer(source, false, true, true);
this.name = name;
this.defaultValues = defaultValues;
//parse the asm, and extract the first pass.
string pass = null;
string firstPassName = null;
string blendPass = null, instancingPass = null;
while (tokenizer.NextToken())
{
if (tokenizer.Token.Equals("pass", StringComparison.InvariantCultureIgnoreCase))
{
//may have a name next...
tokenizer.NextToken();
string token = tokenizer.Token;
string passName = null;
if (token != "{")
{
//the name is specified
passName = tokenizer.Token;
tokenizer.NextToken();
token = tokenizer.Token;
}
//may be a new line
while (token.Trim().Length == 0)
{
tokenizer.NextToken();
token = tokenizer.Token;
}
if (token != "{")
throw new CompileException("Unexpected token in assembly technique pass declaration, expected '{': " + token);
if (!tokenizer.ReadBlock())
throw new CompileException("Unexpected end of string in assembly technique pass declaration");
bool isAnimated, isInstancing;
ExtractPassType(passName, out isAnimated, out isInstancing);
string help = @"
For example:
technique TechniqueName
{
//default pass:
pass
{
VertexShader = compile vs_2_0 BaseVS();
PixelShader = compile ps_2_0 BasePS();
}
pass Animated
{
VertexShader = compile vs_2_0 AnimatedVS();
}
pass Instancing
{
VertexShader = compile vs_2_0 InstancingVS();
}
}
Note, the instancing or animation passes may only replace the vertex shader";
if (pass != null)
{
if (blendPass == null && isAnimated)
{
blendPass = tokenizer.Token;
}
else if (instancingPass == null && isInstancing)
{
instancingPass = tokenizer.Token;
}
else
throw new CompileException(@"A shader technique may only define a single Pass, or define a dedicated Animation and/or Instancing pass:" + help);
}
else
{
if (isAnimated || isInstancing)
throw new CompileException(@"A shader technique must define a default pass before defining an instancing or animation pass:" + help);
firstPassName = passName;
pass = tokenizer.Token;
}
}
}
if (pass == null)
throw new CompileException("Technique '" + name + "' does not define a pass");
ProcessPass(pass);
this.vsBlendOverride = ProcessSupplimentaryPass(blendPass);
this.vsInstancingOverride = ProcessSupplimentaryPass(instancingPass);
SetupCommonRegisters();
//.........这里部分代码省略.........