#include <msp/gl/extensions/arb_uniform_buffer_object.h>
#include <msp/gl/extensions/ext_gpu_shader4.h>
#include <msp/strings/format.h>
+#include <msp/strings/regex.h>
#include <msp/strings/utils.h>
#include "error.h"
#include "program.h"
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();
}
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();
}
if(!module)
throw invalid_operation("ProgramCompiler::add_shaders");
- for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
+ try
{
- if(i->type==VERTEX)
+ for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
{
- program.attach_shader_owned(new VertexShader(apply<Formatter>(*i)));
- for(map<string, unsigned>::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<Formatter>(*i)));
+ for(map<string, unsigned>::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<Formatter>(*i)));
+ else if(i->type==FRAGMENT)
+ {
+ program.attach_shader_owned(new FragmentShader(apply<Formatter>(*i)));
+ if(EXT_gpu_shader4)
+ {
+ for(map<string, unsigned>::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<Formatter>(*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<string> lines = split(e.what(), '\n');
+ string translated;
+ for(vector<string>::const_iterator i=lines.begin(); i!=lines.end(); ++i)
{
- program.attach_shader_owned(new FragmentShader(apply<Formatter>(*i)));
- if(EXT_gpu_shader4)
+ RegMatch m = r_message.match(*i);
+ if(m)
{
- for(map<string, unsigned>::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<unsigned>(m[2].str);
+ line = lexical_cast<unsigned>(m[3].str);
+ }
+ else if(m[4])
+ {
+ index = lexical_cast<unsigned>(m[4].str);
+ line = lexical_cast<unsigned>(m[5].str);
+ }
+ const char *src = "<unknown>";
+ if(index==0)
+ src = "<generated>";
+ else if(index-1<imported_names.size())
+ src = imported_names[index-1].c_str();
+ translated += format("%s:%d: %s", src, line, m[6].str);
}
+ else
+ translated += *i;
+ translated += '\n';
}
+
+ throw compile_error(translated);
}
}
void ProgramCompiler::import(const string &name)
{
string fn = name+".glsl";
- if(imported_names.count(fn))
+ if(find(imported_names, fn)!=imported_names.end())
return;
- imported_names.insert(fn);
+ imported_names.push_back(fn);
RefPtr<IO::Seekable> io = (resources ? resources->open_raw(fn) : Resources::get_builtins().open(fn));
if(!io)