]> git.tdb.fi Git - libs/gl.git/blobdiff - source/programcompiler.cpp
Add file and line information to ProgramParser errors
[libs/gl.git] / source / programcompiler.cpp
index c35fa275c2b1bbadbcfbfb8f113cf68d165d4a8a..2dabd7cd8203ff0910eb97c2528e354e0b3943ff 100644 (file)
@@ -1,4 +1,5 @@
 #include <msp/core/raii.h>
+#include <msp/gl/extensions/ext_gpu_shader4.h>
 #include <msp/strings/format.h>
 #include <msp/strings/utils.h>
 #include "error.h"
@@ -39,20 +40,25 @@ ProgramCompiler::ProgramCompiler():
        module(0)
 { }
 
-void ProgramCompiler::compile(const string &source)
+void ProgramCompiler::compile(const string &source, const string &src_name)
 {
        resources = 0;
-       module = &parser.parse(source);
+       module = &parser.parse(source, src_name);
        process();
 }
 
-void ProgramCompiler::compile(IO::Base &io, Resources *res)
+void ProgramCompiler::compile(IO::Base &io, Resources *res, const string &src_name)
 {
        resources = res;
-       module = &parser.parse(io);
+       module = &parser.parse(io, src_name);
        process();
 }
 
+void ProgramCompiler::compile(IO::Base &io, const string &src_name)
+{
+       compile(io, 0, src_name);
+}
+
 void ProgramCompiler::add_shaders(Program &program)
 {
        if(!module)
@@ -71,8 +77,11 @@ void ProgramCompiler::add_shaders(Program &program)
                else if(i->type==FRAGMENT)
                {
                        program.attach_shader_owned(new FragmentShader(apply<Formatter>(*i)));
-                       for(map<string, unsigned>::iterator j=i->locations.begin(); j!=i->locations.end(); ++j)
-                               program.bind_fragment_data(j->second, j->first);
+                       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);
+                       }
                }
        }
 }
@@ -80,7 +89,7 @@ void ProgramCompiler::add_shaders(Program &program)
 Module *ProgramCompiler::create_builtins_module()
 {
        ProgramParser parser;
-       Module *module = new Module(parser.parse(builtins_src));
+       Module *module = new Module(parser.parse(builtins_src, "<builtin>"));
        for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
        {
                VariableResolver resolver;
@@ -133,7 +142,7 @@ void ProgramCompiler::import(const string &name)
        if(!io)
                throw runtime_error(format("module %s not found", name));
        ProgramParser import_parser;
-       Module &imported_module = import_parser.parse(*io);
+       Module &imported_module = import_parser.parse(*io, fn);
 
        inject_block(module->shared.content, imported_module.shared.content);
        apply<DeclarationCombiner>(module->shared);
@@ -1678,6 +1687,8 @@ void ProgramCompiler::LegacyConverter::visit(VariableDeclaration &var)
                        }
                        else if(stage->type==FRAGMENT && var.interface=="out")
                        {
+                               if(location!=0)
+                                       static Require _req(EXT_gpu_shader4);
                                stage->locations[var.name] = location;
                                var.layout->qualifiers.erase(i);
                        }