2012-08-09 09:45:04 +00:00
|
|
|
#region Using Statements
|
2011-11-15 12:11:24 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
2012-08-09 09:45:04 +00:00
|
|
|
using ANX.RenderSystem.Windows.DX10;
|
|
|
|
using ANX.RenderSystem.Windows.GL3;
|
2011-11-17 19:31:46 +00:00
|
|
|
using System.IO;
|
2011-12-14 11:49:04 +00:00
|
|
|
using ANX.RenderSystem.Windows.DX11;
|
2011-11-15 12:11:24 +00:00
|
|
|
|
|
|
|
#endregion // Using Statements
|
|
|
|
|
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
|
|
|
{
|
2011-11-15 12:11:24 +00:00
|
|
|
public static class Compiler
|
|
|
|
{
|
2012-02-20 08:59:13 +00:00
|
|
|
public static bool GenerateShaders()
|
2011-11-15 12:11:24 +00:00
|
|
|
{
|
|
|
|
Console.WriteLine("generating shaders...");
|
2011-10-31 05:36:24 +00:00
|
|
|
|
2011-11-15 12:11:24 +00:00
|
|
|
for (int i = 0; i < Configuration.Shaders.Count; i++)
|
|
|
|
{
|
|
|
|
Shader s = Configuration.Shaders[i];
|
2011-10-31 05:36:24 +00:00
|
|
|
|
2011-11-15 12:11:24 +00:00
|
|
|
Console.WriteLine("-> loading shader for type '{0}' (file: '{1}')", s.Type, s.Source);
|
|
|
|
String source = String.Empty;
|
2011-11-17 19:31:46 +00:00
|
|
|
if (File.Exists(s.Source))
|
2011-11-15 12:11:24 +00:00
|
|
|
{
|
2011-11-17 19:31:46 +00:00
|
|
|
source = File.ReadAllText(s.Source);
|
2011-11-15 12:11:24 +00:00
|
|
|
}
|
2011-10-31 05:36:24 +00:00
|
|
|
|
2011-11-15 12:11:24 +00:00
|
|
|
Console.Write("--> compiling shader... ");
|
|
|
|
try
|
|
|
|
{
|
2012-03-14 05:54:13 +00:00
|
|
|
s.ByteCode = CompileShader(s.RenderSystem, source, Path.GetDirectoryName(s.Source));
|
2011-11-15 12:11:24 +00:00
|
|
|
Console.WriteLine("{0} bytes compiled size", s.ByteCode.Length);
|
|
|
|
s.ShaderCompiled = true;
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
s.ShaderCompiled = false;
|
|
|
|
Console.WriteLine("--> error occured while compiling shader: {0}", ex.Message);
|
2012-02-20 08:59:13 +00:00
|
|
|
return false;
|
2011-11-15 12:11:24 +00:00
|
|
|
}
|
2011-10-31 05:36:24 +00:00
|
|
|
|
2011-11-15 12:11:24 +00:00
|
|
|
Configuration.Shaders[i] = s;
|
|
|
|
}
|
2011-10-31 05:36:24 +00:00
|
|
|
|
2011-11-15 12:11:24 +00:00
|
|
|
Console.WriteLine("finished generating shaders...");
|
2012-02-20 08:59:13 +00:00
|
|
|
return true;
|
2011-11-15 12:11:24 +00:00
|
|
|
}
|
|
|
|
|
2012-03-14 05:54:13 +00:00
|
|
|
private static Byte[] CompileShader(string RenderSystem, string sourceCode, string directory)
|
2011-11-15 12:11:24 +00:00
|
|
|
{
|
|
|
|
byte[] byteCode;
|
|
|
|
|
|
|
|
switch (RenderSystem)
|
|
|
|
{
|
|
|
|
case "ANX.Framework.Windows.DX10":
|
2012-03-14 05:54:13 +00:00
|
|
|
byteCode = Effect_DX10.CompileFXShader(sourceCode, directory);
|
2011-11-15 12:11:24 +00:00
|
|
|
break;
|
2011-12-14 11:49:04 +00:00
|
|
|
case "ANX.RenderSystem.Windows.DX11":
|
2012-03-14 05:54:13 +00:00
|
|
|
byteCode = Effect_DX11.CompileFXShader(sourceCode, directory);
|
2011-12-14 11:49:04 +00:00
|
|
|
break;
|
2011-11-15 12:11:24 +00:00
|
|
|
case "ANX.Framework.Windows.GL3":
|
2012-01-16 13:48:21 +00:00
|
|
|
byteCode = ShaderHelper.SaveShaderCode(sourceCode);
|
2011-11-15 12:11:24 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new NotImplementedException("compiling shaders for " + RenderSystem + " not yet implemented...");
|
|
|
|
}
|
|
|
|
|
|
|
|
return byteCode;
|
|
|
|
}
|
|
|
|
}
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|