1 #include <msp/core/application.h>
2 #include <msp/core/getopt.h>
3 #include <msp/gl/glsl/compiler.h>
4 #include <msp/io/print.h>
6 class GlslCompiler: public Msp::RegisteredApplication<GlslCompiler>
12 Msp::GL::SL::Stage::Type stage;
16 GlslCompiler(int, char **);
24 GlslCompiler::GlslCompiler(int argc, char **argv):
27 stage(GL::SL::Stage::SHARED),
33 getopt.add_option('c', "combined", combined, GetOpt::NO_ARG).set_help("Output combined GLSL");
34 getopt.add_option('a', "dump-ast", dump_ast, GetOpt::NO_ARG).set_help("Dump AST for debugging");
35 getopt.add_option('p', "parse_only", parse_only, GetOpt::NO_ARG).set_help("Only parse the loaded source, don't compile");
36 getopt.add_option('s', "stage", stage_str, GetOpt::REQUIRED_ARG).set_help("Output GLSL for STAGE", "STAGE");
37 getopt.add_argument("source", source_fn, GetOpt::REQUIRED_ARG).set_help("GLSL file to compile");
40 if(stage_str=="vertex")
41 stage = GL::SL::Stage::VERTEX;
42 else if(stage_str=="geometry")
43 stage = GL::SL::Stage::GEOMETRY;
44 else if(stage_str=="fragment")
45 stage = GL::SL::Stage::FRAGMENT;
50 int GlslCompiler::main()
52 GL::SL::Compiler compiler(GL::SL::Features::all());
53 IO::File file(source_fn);
54 compiler.load_source(file, source_fn);
56 compiler.compile(GL::SL::Compiler::PROGRAM);
60 vector<GL::SL::Stage::Type> stages = compiler.get_stages();
61 for(vector<GL::SL::Stage::Type>::const_iterator i=stages.begin(); i!=stages.end(); ++i)
62 IO::print("%s\n", compiler.get_stage_debug(*i));
66 IO::print("%s\n", compiler.get_combined_glsl());
67 else if(stage!=GL::SL::Stage::SHARED)
68 IO::print("%s\n", compiler.get_stage_glsl(stage));