Skip to content

Commit

Permalink
Moved render state parsing to PassInfo.ParseRenderState().
Browse files Browse the repository at this point in the history
  • Loading branch information
tomspilman committed Feb 11, 2013
1 parent fe4a795 commit bc2fdf5
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 149 deletions.
77 changes: 3 additions & 74 deletions Tools/2MGFX/MGFX.tpg
Original file line number Diff line number Diff line change
Expand Up @@ -71,83 +71,12 @@ Technique_Declaration -> Technique Identifier? OpenBracket Pass_Declaration+ Clo

Render_State_Expression -> Identifier Equals (Identifier | Number) Semicolon
{
var pass = paramlist[0] as PassInfo;
var name = $Identifier[0] as string;
var value = ($Identifier[1] ?? $Number) as string;

Microsoft.Xna.Framework.Graphics.Blend blend;

switch (name.ToLower())
{
case "alphablendenable":
if (!ParseTreeTools.ParseBool(value))
{
if (pass.blendState == null)
pass.blendState = new Microsoft.Xna.Framework.Graphics.BlendState();
pass.blendState.AlphaSourceBlend = Microsoft.Xna.Framework.Graphics.Blend.One;
pass.blendState.ColorSourceBlend = Microsoft.Xna.Framework.Graphics.Blend.One;
pass.blendState.ColorDestinationBlend = Microsoft.Xna.Framework.Graphics.Blend.Zero;
pass.blendState.AlphaDestinationBlend = Microsoft.Xna.Framework.Graphics.Blend.Zero;
}
break;
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":
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":
if (pass.blendState == null)
pass.blendState = new Microsoft.Xna.Framework.Graphics.BlendState();
pass.blendState.AlphaBlendFunction = ParseTreeTools.ParseBlendFunction(value);
break;
case "zenable":
if (pass.depthStencilState == null)
pass.depthStencilState = new Microsoft.Xna.Framework.Graphics.DepthStencilState();
pass.depthStencilState.DepthBufferEnable = ParseTreeTools.ParseBool(value);
break;
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;
}

var pass = paramlist[0] as PassInfo;
pass.ParseRenderState(name, value);

return null;
};

Expand Down
79 changes: 4 additions & 75 deletions Tools/2MGFX/ParseTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,83 +245,12 @@ protected virtual object EvalTechnique_Declaration(ParseTree tree, params object

protected virtual object EvalRender_State_Expression(ParseTree tree, params object[] paramlist)
{
var pass = paramlist[0] as PassInfo;
var name = this.GetValue(tree, TokenType.Identifier, 0) as string;
var name = this.GetValue(tree, TokenType.Identifier, 0) as string;
var value = (this.GetValue(tree, TokenType.Identifier, 1) ?? this.GetValue(tree, TokenType.Number, 0)) as string;

Microsoft.Xna.Framework.Graphics.Blend blend;

switch (name.ToLower())
{
case "alphablendenable":
if (!ParseTreeTools.ParseBool(value))
{
if (pass.blendState == null)
pass.blendState = new Microsoft.Xna.Framework.Graphics.BlendState();
pass.blendState.AlphaSourceBlend = Microsoft.Xna.Framework.Graphics.Blend.One;
pass.blendState.ColorSourceBlend = Microsoft.Xna.Framework.Graphics.Blend.One;
pass.blendState.ColorDestinationBlend = Microsoft.Xna.Framework.Graphics.Blend.Zero;
pass.blendState.AlphaDestinationBlend = Microsoft.Xna.Framework.Graphics.Blend.Zero;
}
break;
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":
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":
if (pass.blendState == null)
pass.blendState = new Microsoft.Xna.Framework.Graphics.BlendState();
pass.blendState.AlphaBlendFunction = ParseTreeTools.ParseBlendFunction(value);
break;
case "zenable":
if (pass.depthStencilState == null)
pass.depthStencilState = new Microsoft.Xna.Framework.Graphics.DepthStencilState();
pass.depthStencilState.DepthBufferEnable = ParseTreeTools.ParseBool(value);
break;
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;
}

var pass = paramlist[0] as PassInfo;
pass.ParseRenderState(name, value);

return null;
}

Expand Down
74 changes: 74 additions & 0 deletions Tools/2MGFX/ShaderInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,80 @@ public void ValidateShaderModels(bool dx11Profile)
throw new Exception(String.Format("Pixel shader '{0}' must be SM 3.0 or lower!", psFunction));
}
}

public void ParseRenderState(string name, string value)
{
Blend blend;

switch (name.ToLower())
{
case "alphablendenable":
if (!ParseTreeTools.ParseBool(value))
{
if (blendState == null)
blendState = new Microsoft.Xna.Framework.Graphics.BlendState();
blendState.AlphaSourceBlend = Microsoft.Xna.Framework.Graphics.Blend.One;
blendState.ColorSourceBlend = Microsoft.Xna.Framework.Graphics.Blend.One;
blendState.ColorDestinationBlend = Microsoft.Xna.Framework.Graphics.Blend.Zero;
blendState.AlphaDestinationBlend = Microsoft.Xna.Framework.Graphics.Blend.Zero;
}
break;
case "srcblend":
blend = ParseTreeTools.ParseBlend(value);
if (blendState == null)
blendState = new Microsoft.Xna.Framework.Graphics.BlendState();
blendState.AlphaSourceBlend = blend;
blendState.ColorSourceBlend = blend;
break;
case "destblend":
blend = ParseTreeTools.ParseBlend(value);
if (blendState == null)
blendState = new Microsoft.Xna.Framework.Graphics.BlendState();
blendState.AlphaDestinationBlend = blend;
blendState.ColorDestinationBlend = blend;
break;
case "blendop":
if (blendState == null)
blendState = new Microsoft.Xna.Framework.Graphics.BlendState();
blendState.AlphaBlendFunction = ParseTreeTools.ParseBlendFunction(value);
break;
case "zenable":
if (depthStencilState == null)
depthStencilState = new Microsoft.Xna.Framework.Graphics.DepthStencilState();
depthStencilState.DepthBufferEnable = ParseTreeTools.ParseBool(value);
break;
case "zwriteenable":
if (depthStencilState == null)
depthStencilState = new Microsoft.Xna.Framework.Graphics.DepthStencilState();
depthStencilState.DepthBufferWriteEnable = ParseTreeTools.ParseBool(value);
break;
case "depthbias":
if (rasterizerState == null)
rasterizerState = new Microsoft.Xna.Framework.Graphics.RasterizerState();
rasterizerState.DepthBias = float.Parse(value);
break;
case "cullmode":
if (rasterizerState == null)
rasterizerState = new Microsoft.Xna.Framework.Graphics.RasterizerState();
rasterizerState.CullMode = ParseTreeTools.ParseCullMode(value);
break;
case "fillmode":
if (rasterizerState == null)
rasterizerState = new Microsoft.Xna.Framework.Graphics.RasterizerState();
rasterizerState.FillMode = ParseTreeTools.ParseFillMode(value);
break;
case "multisampleantialias":
if (rasterizerState == null)
rasterizerState = new Microsoft.Xna.Framework.Graphics.RasterizerState();
rasterizerState.MultiSampleAntiAlias = ParseTreeTools.ParseBool(value);
break;
case "slopescaledepthbias":
if (rasterizerState == null)
rasterizerState = new Microsoft.Xna.Framework.Graphics.RasterizerState();
rasterizerState.SlopeScaleDepthBias = float.Parse(value);
break;
}
}
}

public enum TextureFilterType
Expand Down

0 comments on commit bc2fdf5

Please sign in to comment.