]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/output.cpp
Allow using SL::Formatter on single nodes
[libs/gl.git] / source / glsl / output.cpp
index dfd93470dd101dfac8ca4c7f8a07be588bb11e9f..f97b8cdb2e2958aeb7bee1d979bb9b0ecbbffeae 100644 (file)
@@ -9,14 +9,17 @@ namespace GL {
 namespace SL {
 
 Formatter::Formatter():
+       stage(0),
        source_index(0),
        source_line(1),
        indent(0),
        parameter_list(false)
 { }
 
-void Formatter::apply(Stage &s)
+const string &Formatter::apply(Stage &s)
 {
+       stage = &s;
+
        GLApi api = get_gl_api();
        const Version &ver = s.required_version;
 
@@ -33,7 +36,9 @@ void Formatter::apply(Stage &s)
        if(!s.required_extensions.empty())
                formatted += '\n';
 
-       StageVisitor::apply(s);
+       visit(s.content);
+
+       return formatted;
 }
 
 void Formatter::append(const string &text)
@@ -60,7 +65,7 @@ void Formatter::set_source(unsigned index, unsigned line)
                else
                {
                        unsigned l = line;
-                       if(stage->required_version<Version(3, 30))
+                       if(stage && stage->required_version<Version(3, 30))
                                --l;
                        formatted += format("#line %d %d\n", l, index);
                }
@@ -209,7 +214,7 @@ void Formatter::visit(VariableDeclaration &var)
        if(!var.interface.empty() && var.interface!=block_interface)
        {
                string interface = var.interface;
-               if(stage->required_version<Version(1, 30))
+               if(stage && stage->required_version<Version(1, 30))
                {
                        if(stage->type==Stage::VERTEX && var.interface=="in")
                                interface = "attribute";