// Sample file using SLConverter.exe assembly using System; using SLConverter; namespace CustomConvertorApp { /// /// Sample program using SLConverter with 2 usecases: /// 1) Convert from an inline HLSL sourcecode and get the glsl code result back /// 2) Convert a file on the disk to GLSL files on the disk /// class Program { /// /// Main entry. /// /// Command line args static void Main(string[] args) { // Create a converter using the CafeCompiler as the main Glsl compiler var converter = new SLConverter.Converter(); // Use Cafe compiler converter.GlslCompiler = SLConverter.CafeCompiler.NewInstance(); // Uncomment the following lines to disable some features //converter.UseBindingLayout = false; //converter.UseLocationLayout = false; //converter.UseMultiThreading = true; //converter.UseSemanticForLocation = true; //converter.UseSemanticForVariable = true; //converter.NoSwapForBinaryMatrixOperation = true; //converter.IsPointSpriteShader = true; // -------------------------------------------------------------------- // Usecase 1) Convert a single HLSL inline source code to GLSL // -------------------------------------------------------------------- converter.Macros.Add(new ShaderMacro("CUSTOM_MACRO", "COLOR")); var hlslSourceCode = @" struct VS_IN { float4 pos : POSITION; float4 col : CUSTOM_MACRO; }; struct PS_IN { float4 pos : SV_POSITION; float4 col : CUSTOM_MACRO; }; float4x4 worldViewProj; PS_IN VS( VS_IN input ) { PS_IN output = (PS_IN)0; output.pos = mul(input.pos, worldViewProj); output.col = input.col; return output; } float4 PS( PS_IN input ) : SV_Target { return input.col; } "; string glslCode; var log = new TextLogger(); // Convert VertexShader VS entrypoint to GLSL if (!converter.ConvertFromText(hlslSourceCode, "VS", PipelineStage.Vertex, ShaderModel.Model40, out glslCode, log, "inlineHLSL")) { Console.WriteLine("Error while converting code: {0}", log); } Console.WriteLine("GLSL VS code:"); Console.WriteLine(glslCode); // Convert PixelShader PS entrypoint to GLSL log = new TextLogger(); if (!converter.ConvertFromText(hlslSourceCode, "PS", PipelineStage.Pixel, ShaderModel.Model40, out glslCode, log, "inlineHLSL")) { Console.WriteLine("Error while converting code: {0}", log); } Console.WriteLine("GLSL PS code:"); Console.WriteLine(glslCode); // -------------------------------------------------------------------- // Usecase 2) Convert a HLSL file to GLSL files // -------------------------------------------------------------------- log = new TextLogger(); converter.UseMultiThreading = true; converter.ConvertFromFile("test.fx", @"output\$0_$1.glsl", (isSuccess, message) => Console.WriteLine("{0} : {1}", isSuccess ? "Success" : "Error", message), log); } } }