6 using SiliconStudio.Core.Serialization;
7 using SiliconStudio.Paradox.Graphics;
8 using SiliconStudio.Paradox.Shaders;
9 using SiliconStudio.Paradox.Shaders.Compiler;
20 const string codeTemplate =
@"//------------------------------------------------------------------------------
22 // Paradox Effect Compiler File Generated:
25 // Changes to this file may cause incorrect behavior and will be lost if
26 // the code is regenerated.
28 //------------------------------------------------------------------------------
34 {4} static readonly byte[] {5} = new byte[] {{
40 var effectToGenerateText =
new StringBuilder();
41 effectToGenerateText.AppendFormat(
"// Effect [{0}]\r\n", name);
43 var buffer =
new MemoryStream();
45 serializer.Write(effectData);
48 var bufferAsText =
new StringBuilder();
49 var bufferArray = buffer.ToArray();
50 for (
int i = 0; i < bufferArray.Length; i++)
52 bufferAsText.Append(bufferArray[i]).Append(
", ");
53 if (i > 0 && (i % 64) == 0)
55 bufferAsText.AppendLine();
59 var classDeclaration = parameters.Get(EffectSourceCodeKeys.ClassDeclaration);
60 var fieldDeclaration = parameters.Get(EffectSourceCodeKeys.FieldDeclaration);
61 var nameSpace = parameters.Get(EffectSourceCodeKeys.Namespace);
62 var className = parameters.Get(EffectSourceCodeKeys.ClassName) ?? name;
63 var fieldName = parameters.Get(EffectSourceCodeKeys.FieldName);
65 var commandLine = string.Join(
" ", Environment.GetCommandLineArgs());
67 var graphicsPlatform = parameters.Get(CompilerParameters.GraphicsPlatformKey);
68 string paradoxDefine =
"undefined";
69 switch (graphicsPlatform)
71 case GraphicsPlatform.Direct3D11:
72 paradoxDefine =
"SILICONSTUDIO_PARADOX_GRAPHICS_API_DIRECT3D11";
74 case GraphicsPlatform.OpenGL:
75 paradoxDefine =
"SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLCORE";
77 case GraphicsPlatform.OpenGLES:
78 paradoxDefine =
"SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES";
82 writer.WriteLine(
"#if {0}", paradoxDefine);
83 writer.Write(codeTemplate,
93 writer.WriteLine(
"#endif");
Parameters used for compilation.
Implements SerializationStream as a binary writer.
static void Write(string name, CompilerParameters parameters, EffectBytecode effectData, TextWriter writer)
Use this class to generate a code with embedded effect bytecode.
Contains a compiled shader with bytecode for each stage.