Diligent Graphics > Diligent Engine > HLSL to GLSL Source Converter > Standalone Converter
Standalone Converter
Standalone HLSL2GLSLConverter allows off-line conversion of shaders authored in HLSL to GLSL. Command line options for the tool are given in the table below:
Argument | Description |
---|---|
-h | Print help message |
-i <filename> | Input file path (relative to the search directories) |
-d <dirname> | Search directory to look for input file as well as all #include files. Every search directory should be specified using -d argument |
-o <filename> | Output file to write converted GLSL source to |
-e <funcname> | Shader entry point |
-c | Compile converted GLSL shader |
-t <type> | Shader type. Allowed values: vs – vertex shader ps – pixel shader gs – geometry shader ds – domain shader hs – domain shader cs – domain shader |
-noglsldef | Do not include glsl definitions into the converted source |
Command line example:
HLSL2GLSLConverter -i ConverterTest.fx -d .\testshaders -d .\ -t vs -e TestVS -c -o .\testshaders\ConvertedShader.txt
By default, the converter includes auxiliary GLSL definitions into the converter source. This can be disabled with -noglsldef command line option, but the definitions file GLSLDefinitions.h is required for the shader file to be compiled and must be included manually.
When compiling GLSL shader, Diligent Engine adds the following lines on top of the converted GLSL source.
For desktop GL:
1 2 3 |
#version 430 core #define DESKTOP_GL 1 layout(std140) uniform; |
For GLES:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
#version 310 es #ifndef GL_ES # define GL_ES 1 #endif precision highp float; precision highp int; //"precision highp uint; // This line causes shader compilation error on NVidia! precision highp sampler2D; precision highp sampler3D; precision highp samplerCube; precision highp samplerCubeArray; precision highp samplerCubeShadow; precision highp samplerCubeArrayShadow; precision highp sampler2DShadow; precision highp sampler2DArray; precision highp sampler2DArrayShadow; precision highp sampler2DMS; // ES3.1 precision highp isampler2D; precision highp isampler3D; precision highp isamplerCube; precision highp isamplerCubeArray; precision highp isampler2DArray; precision highp isampler2DMS; // ES3.1 precision highp usampler2D; precision highp usampler3D; precision highp usamplerCube; precision highp usamplerCubeArray; precision highp usampler2DArray; precision highp usampler2DMS; // ES3.1 precision highp image2D; precision highp image3D; precision highp imageCube; precision highp image2DArray; precision highp iimage2D; precision highp iimage3D; precision highp iimageCube; precision highp iimage2DArray; precision highp uimage2D; precision highp uimage3D; precision highp uimageCube; precision highp uimage2DArray; layout(std140) uniform; |
Also on Android, the engine defines the following extension when compiling geometry shader:
1 |
#extension GL_EXT_geometry_shader : enable |
and the following extension when compiling tessellation control (hull) or tessellation evaluation (domain) shader:
1 |
#extension GL_EXT_tessellation_shader : enable |
Besides that, the engine also defines one of the following macros depending on the type of the shader being compiled: VERTEX_SHADER, FRAGMENT_SHADER, GEOMETRY_SHADER, TESS_CONTROL_SHADER, TESS_EVALUATION_SHADER, COMPUTE_SHADER. If converted source is not handled by the Diligent Engine, one of the macros above must always be defined before including GLSLDefinitions.h.