#include <msp/strings/format.h>
#include "compatibility.h"
#include "compiler.h"
+#include "debug.h"
#include "error.h"
#include "generate.h"
#include "optimize.h"
return module->source_map;
}
+string Compiler::get_stage_debug(Stage::Type stage_type) const
+{
+ for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
+ if(i->type==stage_type)
+ return DumpTree().apply(*i);
+ throw key_error(Stage::get_stage_name(stage_type));
+}
+
void Compiler::append_module(Module &mod, DataFile::Collection *res)
{
module->source_map.merge_from(mod.source_map);
const std::map<std::string, unsigned> &get_vertex_attributes() const;
const std::map<std::string, unsigned> &get_fragment_outputs() const;
const SourceMap &get_source_map() const;
-private:
+ std::string get_stage_debug(Stage::Type) const;
+
+private:
void append_module(Module &, DataFile::Collection *);
void append_stage(Stage &);
void import(DataFile::Collection *, const std::string &);
return features;
}
+Features Features::all()
+{
+ Features features;
+ features.gl_api = OPENGL;
+ features.glsl_version = Version(4, 60);
+ features.arb_explicit_attrib_location = true;
+ features.arb_gpu_shader5 = true;
+ features.arb_uniform_buffer_object = true;
+ features.ext_gpu_shader4 = true;
+ features.ext_texture_array = true;
+ return features;
+}
+
} // namespace SL
} // namespace GL
} // namespace Msp
--- /dev/null
+#include <msp/core/application.h>
+#include <msp/core/getopt.h>
+#include <msp/gl/glsl/compiler.h>
+#include <msp/io/print.h>
+
+class GlslCompiler: public Msp::RegisteredApplication<GlslCompiler>
+{
+private:
+ std::string source_fn;
+ bool parse_only;
+ bool combined;
+ Msp::GL::SL::Stage::Type stage;
+ bool dump_ast;
+
+public:
+ GlslCompiler(int, char **);
+
+ virtual int main();
+};
+
+using namespace std;
+using namespace Msp;
+
+GlslCompiler::GlslCompiler(int argc, char **argv):
+ parse_only(false),
+ combined(false),
+ stage(GL::SL::Stage::SHARED),
+ dump_ast(false)
+{
+ string stage_str;
+
+ GetOpt getopt;
+ getopt.add_option('c', "combined", combined, GetOpt::NO_ARG).set_help("Output combined GLSL");
+ getopt.add_option('a', "dump-ast", dump_ast, GetOpt::NO_ARG).set_help("Dump AST for debugging");
+ getopt.add_option('p', "parse_only", parse_only, GetOpt::NO_ARG).set_help("Only parse the loaded source, don't compile");
+ getopt.add_option('s', "stage", stage_str, GetOpt::REQUIRED_ARG).set_help("Output GLSL for STAGE", "STAGE");
+ getopt.add_argument("source", source_fn, GetOpt::REQUIRED_ARG).set_help("GLSL file to compile");
+ getopt(argc, argv);
+
+ if(stage_str=="vertex")
+ stage = GL::SL::Stage::VERTEX;
+ else if(stage_str=="geometry")
+ stage = GL::SL::Stage::GEOMETRY;
+ else if(stage_str=="fragment")
+ stage = GL::SL::Stage::FRAGMENT;
+ else if(!dump_ast)
+ combined = true;
+}
+
+int GlslCompiler::main()
+{
+ GL::SL::Compiler compiler(GL::SL::Features::all());
+ IO::File file(source_fn);
+ compiler.load_source(file, source_fn);
+ if(!parse_only)
+ compiler.compile(GL::SL::Compiler::PROGRAM);
+
+ if(dump_ast)
+ {
+ vector<GL::SL::Stage::Type> stages = compiler.get_stages();
+ for(vector<GL::SL::Stage::Type>::const_iterator i=stages.begin(); i!=stages.end(); ++i)
+ IO::print("%s\n", compiler.get_stage_debug(*i));
+ }
+
+ if(combined)
+ IO::print("%s\n", compiler.get_combined_glsl());
+ else if(stage!=GL::SL::Stage::SHARED)
+ IO::print("%s\n", compiler.get_stage_glsl(stage));
+
+ return 0;
+}