Permalink
Browse files

Merge pull request #1024 from SickheadGames/mgfx3

More MGFX Improvements
  • Loading branch information...
2 parents 417c8f0 + 0df743b commit 96e4a7addbb213a1adf9cb4d809f64d450ce24f0 @KonajuGames KonajuGames committed Dec 6, 2012
Showing with 254 additions and 137 deletions.
  1. +45 −20 Tools/2MGFX/MGFX.tpg
  2. +53 −21 Tools/2MGFX/ParseTree.cs
  3. +50 −22 Tools/2MGFX/ParseTreeTools.cs
  4. +62 −62 Tools/2MGFX/Parser.cs
  5. +39 −8 Tools/2MGFX/Scanner.cs
  6. +5 −4 Tools/2MGFX/ShaderInfo.cs
View
@@ -9,7 +9,7 @@
[Skip] BlockComment -> @"/\*([^*]|\*[^/])*\*/";
[Skip] Comment -> @"//[^\n\r]*";
[Skip] Whitespace -> @"[ \t\n\r]+";
-[Skip] LinePragma -> @"#line[^\n]*\n";
+[FileAndLine] LinePragma -> @"^[ \t]*#line[ \t]*(?<Line>\d*)[ \t]*(\""(?<File>[^\""\\]*(?:\\.[^\""\\]*)*)\"")?\n";
// TOKENS
[IgnoreCase] Pass -> @"pass";
@@ -76,9 +76,9 @@ Render_State_Expression -> Identifier Equals (Identifier | Number) Semicolon
Microsoft.Xna.Framework.Graphics.Blend blend;
- switch (name)
+ switch (name.ToLower())
{
- case "AlphaBlendEnable":
+ case "alphablendenable":
if (!ParseTreeTools.ParseBool(value))
{
if (pass.blendState == null)
@@ -89,35 +89,60 @@ Render_State_Expression -> Identifier Equals (Identifier | Number) Semicolon
pass.blendState.AlphaDestinationBlend = Microsoft.Xna.Framework.Graphics.Blend.Zero;
}
break;
- case "SrcBlend":
+ case "srcblend":
blend = ParseTreeTools.ParseBlend(value);
if (pass.blendState == null)
pass.blendState = new Microsoft.Xna.Framework.Graphics.BlendState();
pass.blendState.AlphaSourceBlend = blend;
pass.blendState.ColorSourceBlend = blend;
break;
- case "DestBlend":
+ case "destblend":
blend = ParseTreeTools.ParseBlend(value);
if (pass.blendState == null)
pass.blendState = new Microsoft.Xna.Framework.Graphics.BlendState();
pass.blendState.AlphaDestinationBlend = blend;
pass.blendState.ColorDestinationBlend = blend;
break;
- case "BlendOp":
+ case "blendop":
if (pass.blendState == null)
pass.blendState = new Microsoft.Xna.Framework.Graphics.BlendState();
pass.blendState.AlphaBlendFunction = ParseTreeTools.ParseBlendFunction(value);
break;
- case "ZEnable":
+ case "zenable":
if (pass.depthStencilState == null)
pass.depthStencilState = new Microsoft.Xna.Framework.Graphics.DepthStencilState();
pass.depthStencilState.DepthBufferEnable = ParseTreeTools.ParseBool(value);
break;
- case "ZWriteEnable":
+ case "zwriteenable":
if (pass.depthStencilState == null)
pass.depthStencilState = new Microsoft.Xna.Framework.Graphics.DepthStencilState();
pass.depthStencilState.DepthBufferWriteEnable = ParseTreeTools.ParseBool(value);
break;
+ case "depthbias":
+ if (pass.rasterizerState == null)
+ pass.rasterizerState= new Microsoft.Xna.Framework.Graphics.RasterizerState();
+ pass.rasterizerState.DepthBias = float.Parse(value);
+ break;
+ case "cullmode":
+ if (pass.rasterizerState == null)
+ pass.rasterizerState= new Microsoft.Xna.Framework.Graphics.RasterizerState();
+ pass.rasterizerState.CullMode = ParseTreeTools.ParseCullMode(value);
+ break;
+ case "fillmode":
+ if (pass.rasterizerState == null)
+ pass.rasterizerState= new Microsoft.Xna.Framework.Graphics.RasterizerState();
+ pass.rasterizerState.FillMode = ParseTreeTools.ParseFillMode(value);
+ break;
+ case "multisampleantialias":
+ if (pass.rasterizerState == null)
+ pass.rasterizerState= new Microsoft.Xna.Framework.Graphics.RasterizerState();
+ pass.rasterizerState.MultiSampleAntiAlias = ParseTreeTools.ParseBool(value);
+ break;
+ case "slopescaledepthbias":
+ if (pass.rasterizerState == null)
+ pass.rasterizerState= new Microsoft.Xna.Framework.Graphics.RasterizerState();
+ pass.rasterizerState.SlopeScaleDepthBias = float.Parse(value);
+ break;
default:
break;
}
@@ -164,39 +189,39 @@ Sampler_State_Expression -> Identifier Equals (TextureName | Identifier | Number
var sampler = paramlist[0] as SamplerStateInfo;
var name = $Identifier[0] as string;
var value = ($TextureName[0] ?? ($Identifier[1] ?? $Number[0])) as string;
- switch (name)
+ switch (name.ToLower())
{
- case "Texture":
+ case "texture":
// Ignore
break;
- case "MinFilter":
+ case "minfilter":
sampler.MinFilter = ParseTreeTools.ParseTextureFilterType(value);
break;
- case "MagFilter":
+ case "magfilter":
sampler.MagFilter = ParseTreeTools.ParseTextureFilterType(value);
break;
- case "MipFilter":
+ case "mipfilter":
sampler.MipFilter = ParseTreeTools.ParseTextureFilterType(value);
break;
- case "Filter":
+ case "filter":
sampler.MinFilter = sampler.MagFilter = sampler.MipFilter = ParseTreeTools.ParseTextureFilterType(value);
break;
- case "AddressU":
+ case "addressu":
sampler.state.AddressU = ParseTreeTools.ParseAddressMode(value);
break;
- case "AddressV":
+ case "addressv":
sampler.state.AddressV = ParseTreeTools.ParseAddressMode(value);
break;
- case "AddressW":
+ case "addressw":
sampler.state.AddressW = ParseTreeTools.ParseAddressMode(value);
break;
- case "MaxAnisotropy":
+ case "maxanisotropy":
sampler.state.MaxAnisotropy = int.Parse(value);
break;
- case "MaxLOD":
+ case "maxlod":
sampler.state.MaxMipLevel = int.Parse(value);
break;
- case "MipLODBias":
+ case "miplodbias":
sampler.state.MipMapLevelOfDetailBias = float.Parse(value);
break;
default:
View
@@ -16,13 +16,15 @@ public class ParseErrors : List<ParseError>
[Serializable]
public class ParseError
{
+ private string file;
private string message;
private int code;
private int line;
private int col;
private int pos;
private int length;
+ public string File { get { return file; } }
public int Code { get { return code; } }
public int Line { get { return line; } }
public int Column { get { return col; } }
@@ -35,12 +37,17 @@ public ParseError()
{
}
- public ParseError(string message, int code, ParseNode node) : this(message, code, 0, node.Token.StartPos, node.Token.StartPos, node.Token.Length)
+ public ParseError(string message, int code, ParseNode node) : this(message, code, node.Token)
{
}
- public ParseError(string message, int code, int line, int col, int pos, int length)
+ public ParseError(string message, int code, Token token) : this(message, code, token.File, token.Line, token.Column, token.StartPos, token.Length)
{
+ }
+
+ public ParseError(string message, int code, string file = "", int line = 0, int col = 0, int pos = 0, int length = 0)
+ {
+ this.file = file;
this.message = message;
this.code = code;
this.line = line;
@@ -240,9 +247,9 @@ protected virtual object EvalRender_State_Expression(ParseTree tree, params obje
Microsoft.Xna.Framework.Graphics.Blend blend;
- switch (name)
+ switch (name.ToLower())
{
- case "AlphaBlendEnable":
+ case "alphablendenable":
if (!ParseTreeTools.ParseBool(value))
{
if (pass.blendState == null)
@@ -253,35 +260,60 @@ protected virtual object EvalRender_State_Expression(ParseTree tree, params obje
pass.blendState.AlphaDestinationBlend = Microsoft.Xna.Framework.Graphics.Blend.Zero;
}
break;
- case "SrcBlend":
+ case "srcblend":
blend = ParseTreeTools.ParseBlend(value);
if (pass.blendState == null)
pass.blendState = new Microsoft.Xna.Framework.Graphics.BlendState();
pass.blendState.AlphaSourceBlend = blend;
pass.blendState.ColorSourceBlend = blend;
break;
- case "DestBlend":
+ case "destblend":
blend = ParseTreeTools.ParseBlend(value);
if (pass.blendState == null)
pass.blendState = new Microsoft.Xna.Framework.Graphics.BlendState();
pass.blendState.AlphaDestinationBlend = blend;
pass.blendState.ColorDestinationBlend = blend;
break;
- case "BlendOp":
+ case "blendop":
if (pass.blendState == null)
pass.blendState = new Microsoft.Xna.Framework.Graphics.BlendState();
pass.blendState.AlphaBlendFunction = ParseTreeTools.ParseBlendFunction(value);
break;
- case "ZEnable":
+ case "zenable":
if (pass.depthStencilState == null)
pass.depthStencilState = new Microsoft.Xna.Framework.Graphics.DepthStencilState();
pass.depthStencilState.DepthBufferEnable = ParseTreeTools.ParseBool(value);
break;
- case "ZWriteEnable":
+ case "zwriteenable":
if (pass.depthStencilState == null)
pass.depthStencilState = new Microsoft.Xna.Framework.Graphics.DepthStencilState();
pass.depthStencilState.DepthBufferWriteEnable = ParseTreeTools.ParseBool(value);
break;
+ case "depthbias":
+ if (pass.rasterizerState == null)
+ pass.rasterizerState= new Microsoft.Xna.Framework.Graphics.RasterizerState();
+ pass.rasterizerState.DepthBias = float.Parse(value);
+ break;
+ case "cullmode":
+ if (pass.rasterizerState == null)
+ pass.rasterizerState= new Microsoft.Xna.Framework.Graphics.RasterizerState();
+ pass.rasterizerState.CullMode = ParseTreeTools.ParseCullMode(value);
+ break;
+ case "fillmode":
+ if (pass.rasterizerState == null)
+ pass.rasterizerState= new Microsoft.Xna.Framework.Graphics.RasterizerState();
+ pass.rasterizerState.FillMode = ParseTreeTools.ParseFillMode(value);
+ break;
+ case "multisampleantialias":
+ if (pass.rasterizerState == null)
+ pass.rasterizerState= new Microsoft.Xna.Framework.Graphics.RasterizerState();
+ pass.rasterizerState.MultiSampleAntiAlias = ParseTreeTools.ParseBool(value);
+ break;
+ case "slopescaledepthbias":
+ if (pass.rasterizerState == null)
+ pass.rasterizerState= new Microsoft.Xna.Framework.Graphics.RasterizerState();
+ pass.rasterizerState.SlopeScaleDepthBias = float.Parse(value);
+ break;
default:
break;
}
@@ -328,39 +360,39 @@ protected virtual object EvalSampler_State_Expression(ParseTree tree, params obj
var sampler = paramlist[0] as SamplerStateInfo;
var name = this.GetValue(tree, TokenType.Identifier, 0) as string;
var value = (this.GetValue(tree, TokenType.TextureName, 0) ?? (this.GetValue(tree, TokenType.Identifier, 1) ?? this.GetValue(tree, TokenType.Number, 0))) as string;
- switch (name)
+ switch (name.ToLower())
{
- case "Texture":
+ case "texture":
// Ignore
break;
- case "MinFilter":
+ case "minfilter":
sampler.MinFilter = ParseTreeTools.ParseTextureFilterType(value);
break;
- case "MagFilter":
+ case "magfilter":
sampler.MagFilter = ParseTreeTools.ParseTextureFilterType(value);
break;
- case "MipFilter":
+ case "mipfilter":
sampler.MipFilter = ParseTreeTools.ParseTextureFilterType(value);
break;
- case "Filter":
+ case "filter":
sampler.MinFilter = sampler.MagFilter = sampler.MipFilter = ParseTreeTools.ParseTextureFilterType(value);
break;
- case "AddressU":
+ case "addressu":
sampler.state.AddressU = ParseTreeTools.ParseAddressMode(value);
break;
- case "AddressV":
+ case "addressv":
sampler.state.AddressV = ParseTreeTools.ParseAddressMode(value);
break;
- case "AddressW":
+ case "addressw":
sampler.state.AddressW = ParseTreeTools.ParseAddressMode(value);
break;
- case "MaxAnisotropy":
+ case "maxanisotropy":
sampler.state.MaxAnisotropy = int.Parse(value);
break;
- case "MaxLOD":
+ case "maxlod":
sampler.state.MaxMipLevel = int.Parse(value);
break;
- case "MipLODBias":
+ case "miplodbias":
sampler.state.MipMapLevelOfDetailBias = float.Parse(value);
break;
default:
Oops, something went wrong.

0 comments on commit 96e4a7a

Please sign in to comment.