2011-11-15 12:11:24 +00:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
// This file is part of the ANX.Framework created by the
|
|
|
|
// "ANX.Framework developer group" and released under the Ms-PL license.
|
|
|
|
// For details see: http://anxframework.codeplex.com/license
|
2011-10-31 05:36:24 +00:00
|
|
|
|
2011-11-15 12:11:24 +00:00
|
|
|
namespace StockShaderCodeGenerator
|
2011-10-31 05:36:24 +00:00
|
|
|
{
|
2012-08-09 09:45:04 +00:00
|
|
|
public static class CodeGenerator
|
|
|
|
{
|
|
|
|
public static void Generate()
|
|
|
|
{
|
|
|
|
Console.WriteLine("generating output...");
|
2011-10-31 05:36:24 +00:00
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
using (StreamWriter target = new StreamWriter(Configuration.Target, false))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// write header
|
|
|
|
//
|
|
|
|
target.WriteLine("using System;");
|
|
|
|
target.WriteLine();
|
|
|
|
target.WriteLine(
|
|
|
|
"// This file is part of the ANX.Framework created by the");
|
|
|
|
target.WriteLine(
|
|
|
|
"// \"ANX.Framework developer group\" and released under the Ms-PL license.");
|
|
|
|
target.WriteLine(
|
|
|
|
"// For details see: http://anxframework.codeplex.com/license");
|
|
|
|
target.WriteLine();
|
|
|
|
target.WriteLine("namespace {0}", Configuration.Namespace);
|
|
|
|
target.WriteLine("{");
|
|
|
|
target.WriteLine("\tinternal static class ShaderByteCode");
|
|
|
|
target.WriteLine("\t{");
|
2011-10-31 05:36:24 +00:00
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
for (int i = 0; i < Configuration.Shaders.Count; i++)
|
|
|
|
{
|
|
|
|
Shader s = Configuration.Shaders[i];
|
2011-10-31 05:36:24 +00:00
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
target.WriteLine("\t\t#region {0}Shader", s.Type);
|
|
|
|
target.WriteLine("\t\tinternal static byte[] {0}ByteCode = new byte[]", s.Type);
|
|
|
|
target.WriteLine("\t\t{");
|
2011-11-15 12:11:24 +00:00
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
target.Write("\t\t\t");
|
|
|
|
for (int j = 0; j < s.ByteCode.Length; j++)
|
|
|
|
{
|
|
|
|
target.Write(s.ByteCode[j].ToString("D3"));
|
2012-08-16 14:03:31 +00:00
|
|
|
|
|
|
|
bool isNextLineNeeded = (j + 1) % 15 == 0;
|
2012-08-09 09:45:04 +00:00
|
|
|
if (j < s.ByteCode.Length - 1)
|
|
|
|
{
|
2012-08-16 14:03:31 +00:00
|
|
|
target.Write("," + (isNextLineNeeded ? "" : " "));
|
2012-08-09 09:45:04 +00:00
|
|
|
}
|
2011-11-15 12:11:24 +00:00
|
|
|
|
2012-08-16 14:03:31 +00:00
|
|
|
if (isNextLineNeeded)
|
2012-08-09 09:45:04 +00:00
|
|
|
{
|
|
|
|
target.WriteLine();
|
|
|
|
target.Write("\t\t\t");
|
|
|
|
}
|
|
|
|
}
|
2011-11-15 12:11:24 +00:00
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
target.WriteLine();
|
|
|
|
target.WriteLine("\t\t};");
|
|
|
|
target.WriteLine("\t\t#endregion //{0}Shader", s.Type);
|
|
|
|
target.WriteLine();
|
|
|
|
}
|
2011-11-15 12:11:24 +00:00
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
target.WriteLine("\t}");
|
|
|
|
target.WriteLine("}");
|
|
|
|
}
|
2011-11-15 12:11:24 +00:00
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
Console.WriteLine("finished generating output...");
|
|
|
|
}
|
|
|
|
}
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|