X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprogramcompiler.cpp;h=bb77e0ea911e205c192c68cd88462f6affdf1ff6;hp=518b31e17f0d76213f2de8c52160cb3602f346b5;hb=b699b811b22450828268be7ed67e35900be7bdad;hpb=71972b08fd031e177a005eb1924a5c7a15459291 diff --git a/source/programcompiler.cpp b/source/programcompiler.cpp index 518b31e1..bb77e0ea 100644 --- a/source/programcompiler.cpp +++ b/source/programcompiler.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "error.h" #include "program.h" @@ -57,7 +58,7 @@ void ProgramCompiler::compile(const string &source, const string &src_name) delete module; module = new Module(); ProgramParser parser; - imported_names.insert(src_name); + imported_names.push_back(src_name); append_module(parser.parse(source, src_name, 1)); process(); } @@ -68,7 +69,7 @@ void ProgramCompiler::compile(IO::Base &io, Resources *res, const string &src_na delete module; module = new Module(); ProgramParser parser; - imported_names.insert(src_name); + imported_names.push_back(src_name); append_module(parser.parse(io, src_name, 1)); process(); } @@ -83,25 +84,64 @@ void ProgramCompiler::add_shaders(Program &program) if(!module) throw invalid_operation("ProgramCompiler::add_shaders"); - for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) + try { - if(i->type==VERTEX) + for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) { - program.attach_shader_owned(new VertexShader(apply(*i))); - for(map::iterator j=i->locations.begin(); j!=i->locations.end(); ++j) - program.bind_attribute(j->second, j->first); + if(i->type==VERTEX) + { + program.attach_shader_owned(new VertexShader(apply(*i))); + for(map::iterator j=i->locations.begin(); j!=i->locations.end(); ++j) + program.bind_attribute(j->second, j->first); + } + else if(i->type==GEOMETRY) + program.attach_shader_owned(new GeometryShader(apply(*i))); + else if(i->type==FRAGMENT) + { + program.attach_shader_owned(new FragmentShader(apply(*i))); + if(EXT_gpu_shader4) + { + for(map::iterator j=i->locations.begin(); j!=i->locations.end(); ++j) + program.bind_fragment_data(j->second, j->first); + } + } } - else if(i->type==GEOMETRY) - program.attach_shader_owned(new GeometryShader(apply(*i))); - else if(i->type==FRAGMENT) + } + catch(const compile_error &e) + { + static const Regex r_message("^(([0-9]+)\\(([0-9]+)\\) :|ERROR: ([0-9]+):([0-9]+):) (.*)$"); + vector lines = split(e.what(), '\n'); + string translated; + for(vector::const_iterator i=lines.begin(); i!=lines.end(); ++i) { - program.attach_shader_owned(new FragmentShader(apply(*i))); - if(EXT_gpu_shader4) + RegMatch m = r_message.match(*i); + if(m) { - for(map::iterator j=i->locations.begin(); j!=i->locations.end(); ++j) - program.bind_fragment_data(j->second, j->first); + unsigned index = 0; + unsigned line = 0; + if(m[2]) + { + index = lexical_cast(m[2].str); + line = lexical_cast(m[3].str); + } + else if(m[4]) + { + index = lexical_cast(m[4].str); + line = lexical_cast(m[5].str); + } + const char *src = ""; + if(index==0) + src = ""; + else if(index-1 io = (resources ? resources->open_raw(fn) : Resources::get_builtins().open(fn)); if(!io)