]> git.tdb.fi Git - libs/gl.git/commitdiff
Check for existence of required version in Formatter
authorMikko Rasa <tdb@tdb.fi>
Wed, 10 Mar 2021 10:03:24 +0000 (12:03 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 10 Mar 2021 13:33:37 +0000 (15:33 +0200)
This way it doesn't depend on whether get_combined_glsl or get_stage_glsl
was called.

source/glsl/compiler.cpp
source/glsl/output.cpp
source/glsl/output.h

index c5f0a9a3d05b6fd640f9afe5a5cba5a05e0ec5ab..3516048ca7e62ae9fa83dc52c0f14a7fb0329745 100644 (file)
@@ -108,7 +108,7 @@ string Compiler::get_combined_glsl() const
        for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
        {
                glsl += format("#pragma MSP stage(%s)\n", Stage::get_stage_name(i->type));
-               glsl += Formatter().apply(*i, MODULE);
+               glsl += Formatter().apply(*i);
                glsl += '\n';
        }
 
@@ -128,7 +128,7 @@ string Compiler::get_stage_glsl(Stage::Type stage_type) const
 {
        for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
                if(i->type==stage_type)
-                       return Formatter().apply(*i, PROGRAM);
+                       return Formatter().apply(*i);
        throw key_error(Stage::get_stage_name(stage_type));
 }
 
index b277ba8ee09fef2b2c38c4152dc136982c16d68f..43f337cabc3e6296e9afdc1f91130e3d8bd7b56f 100644 (file)
@@ -10,16 +10,14 @@ namespace SL {
 
 Formatter::Formatter():
        stage(0),
-       mode(Compiler::PROGRAM),
        source_index(0),
        source_line(1),
        indent(0),
        parameter_list(false)
 { }
 
-const string &Formatter::apply(Stage &s, Compiler::Mode m)
+const string &Formatter::apply(Stage &s)
 {
-       mode = m;
        stage = &s;
 
        const Version &ver = s.required_features.glsl_version;
@@ -73,7 +71,7 @@ void Formatter::set_source(unsigned index, unsigned line)
                else
                {
                        unsigned l = line;
-                       if(mode==Compiler::PROGRAM && stage && stage->required_features.glsl_version<Version(3, 30))
+                       if(stage && stage->required_features.glsl_version && stage->required_features.glsl_version<Version(3, 30))
                                --l;
                        formatted += format("#line %d %d\n", l, index);
                }
@@ -238,7 +236,7 @@ void Formatter::visit(VariableDeclaration &var)
        if(!var.interface.empty())
        {
                string interface = var.interface;
-               if(mode==Compiler::PROGRAM && stage && stage->required_features.glsl_version<Version(1, 30))
+               if(stage && stage->required_features.glsl_version && stage->required_features.glsl_version<Version(1, 30))
                {
                        if(stage->type==Stage::VERTEX && var.interface=="in")
                                interface = "attribute";
index 61c02caada72aed11f5e7361c55b639ccde449b9..58983fcab68176faff98ed7666ff4c9aa6891d3b 100644 (file)
@@ -14,7 +14,6 @@ class Formatter: private TraversingVisitor
 {
 private:
        Stage *stage;
-       Compiler::Mode mode;
        std::string formatted;
        unsigned source_index;
        unsigned source_line;
@@ -24,7 +23,7 @@ private:
 public:
        Formatter();
 
-       const std::string &apply(Stage &, Compiler::Mode);
+       const std::string &apply(Stage &);
        const std::string &apply(Node &n) { n.visit(*this); return formatted; }
 
 private: