Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ShaderKeyFileHelper.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Linq;
5 using System.Text;
6 
7 using SiliconStudio.Paradox.Shaders.Parser;
8 using SiliconStudio.Paradox.Shaders.Parser.Mixins;
9 
10 namespace SiliconStudio.Paradox.VisualStudio.Commands.Shaders
11 {
13  {
14  public static byte[] GenerateCode(string inputFileName, string inputFileContent)
15  {
16  // Always output a result into the file
17  string result;
18  try
19  {
20  var parsingResult = ParadoxShaderParser.TryPreProcessAndParse(inputFileContent, inputFileName);
21 
22  // Try to generate a mixin code.
23  var shaderKeyGenerator = new ShaderMixinCodeGen(parsingResult.Shader, parsingResult);
24 
25  shaderKeyGenerator.Run();
26  result = shaderKeyGenerator.Text ?? string.Empty;
27  }
28  catch (Exception ex)
29  {
30  result = "// Unexpected exceptions occured while generating the file\n" + ex;
31  }
32 
33  // We force the UTF8 to include the BOM to match VS default
34  var data = Encoding.UTF8.GetBytes(result);
35  return Encoding.UTF8.GetPreamble().Concat(data).ToArray();
36  }
37  }
38 }
static byte[] GenerateCode(string inputFileName, string inputFileContent)
This class is responsible to generate associated C# code from an effect file (extension: pdxfx)...