]> git.tdb.fi Git - libs/gl.git/commitdiff
Move the StageType enum inside the Stage struct
authorMikko Rasa <tdb@tdb.fi>
Mon, 15 Feb 2021 10:12:44 +0000 (12:12 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 15 Feb 2021 10:12:44 +0000 (12:12 +0200)
14 files changed:
source/glsl/builtin.cpp
source/glsl/builtin.h
source/glsl/compatibility.cpp
source/glsl/compiler.cpp
source/glsl/generate.cpp
source/glsl/generate.h
source/glsl/optimize.cpp
source/glsl/output.cpp
source/glsl/parser.cpp
source/glsl/parser.h
source/glsl/preprocessor.cpp
source/glsl/preprocessor.h
source/glsl/syntax.cpp
source/glsl/syntax.h

index 7aecda3c244bbd31d028021687f1352bc9dd584e..ee692462299dc7397a239a994a1b57228d385c4b 100644 (file)
@@ -48,7 +48,7 @@ Module &get_builtins_module()
        return *builtins_module;
 }
 
        return *builtins_module;
 }
 
-Stage *get_builtins(StageType type)
+Stage *get_builtins(Stage::Type type)
 {
        Module &module = get_builtins_module();
        for(list<Stage>::iterator i=module.stages.begin(); i!=module.stages.end(); ++i)
 {
        Module &module = get_builtins_module();
        for(list<Stage>::iterator i=module.stages.begin(); i!=module.stages.end(); ++i)
index 59e5ed89bd99211347df8dc24eb932a85b122f3f..00cd3ff3bf194712d86e1dd22aaf5d8ffc14dcf4 100644 (file)
@@ -7,7 +7,7 @@ namespace Msp {
 namespace GL {
 namespace SL {
 
 namespace GL {
 namespace SL {
 
-Stage *get_builtins(StageType);
+Stage *get_builtins(Stage::Type);
 
 } // namespace SL
 } // namespace GL
 
 } // namespace SL
 } // namespace GL
index 0c312d022ca20f71da5818863136614647e47fd7..4e43ae9dcdd3b4241afe1d7c5c945db368834a49 100644 (file)
@@ -49,7 +49,7 @@ void DefaultPrecisionGenerator::visit(VariableDeclaration &var)
                Precision *prec = new Precision;
                if(!type.compare(0, 7, "sampler"))
                        prec->precision = "lowp";
                Precision *prec = new Precision;
                if(!type.compare(0, 7, "sampler"))
                        prec->precision = "lowp";
-               else if(stage->type==FRAGMENT)
+               else if(stage->type==Stage::FRAGMENT)
                        prec->precision = "mediump";
                else
                        prec->precision = "highp";
                        prec->precision = "mediump";
                else
                        prec->precision = "highp";
@@ -231,12 +231,12 @@ void LegacyConverter::visit(VariableDeclaration &var)
                if(i!=var.layout->qualifiers.end())
                {
                        unsigned location = lexical_cast<unsigned>(i->value);
                if(i!=var.layout->qualifiers.end())
                {
                        unsigned location = lexical_cast<unsigned>(i->value);
-                       if(stage->type==VERTEX && var.interface=="in")
+                       if(stage->type==Stage::VERTEX && var.interface=="in")
                        {
                                stage->locations[var.name] = location;
                                var.layout->qualifiers.erase(i);
                        }
                        {
                                stage->locations[var.name] = location;
                                var.layout->qualifiers.erase(i);
                        }
-                       else if(stage->type==FRAGMENT && var.interface=="out")
+                       else if(stage->type==Stage::FRAGMENT && var.interface=="out")
                        {
                                if(location!=0)
                                        static Require _req(EXT_gpu_shader4);
                        {
                                if(location!=0)
                                        static Require _req(EXT_gpu_shader4);
@@ -262,7 +262,7 @@ void LegacyConverter::visit(VariableDeclaration &var)
 
        if((var.interface=="in" || var.interface=="out") && !supports_unified_interface_syntax())
        {
 
        if((var.interface=="in" || var.interface=="out") && !supports_unified_interface_syntax())
        {
-               if(stage->type==FRAGMENT && var.interface=="out")
+               if(stage->type==Stage::FRAGMENT && var.interface=="out")
                {
                        frag_out = &var;
                        remove_node = true;
                {
                        frag_out = &var;
                        remove_node = true;
index 031ae265f52b514c93384d173218d9b400644fb9..e6c035775a89b0ff1aaa98464755d031a73fed98 100644 (file)
@@ -65,15 +65,15 @@ void Compiler::add_shaders(Program &program)
        {
                for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
                {
        {
                for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
                {
-                       if(i->type==VERTEX)
+                       if(i->type==Stage::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);
                        }
                        {
                                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)
+                       else if(i->type==Stage::GEOMETRY)
                                program.attach_shader_owned(new GeometryShader(apply<Formatter>(*i)));
                                program.attach_shader_owned(new GeometryShader(apply<Formatter>(*i)));
-                       else if(i->type==FRAGMENT)
+                       else if(i->type==Stage::FRAGMENT)
                        {
                                program.attach_shader_owned(new FragmentShader(apply<Formatter>(*i)));
                                if(EXT_gpu_shader4)
                        {
                                program.attach_shader_owned(new FragmentShader(apply<Formatter>(*i)));
                                if(EXT_gpu_shader4)
@@ -137,7 +137,7 @@ void Compiler::append_module(Module &mod)
 void Compiler::append_stage(Stage &stage)
 {
        Stage *target = 0;
 void Compiler::append_stage(Stage &stage)
 {
        Stage *target = 0;
-       if(stage.type==SHARED)
+       if(stage.type==Stage::SHARED)
                target = &module->shared;
        else
        {
                target = &module->shared;
        else
        {
index 55687924ffc1703bfb05fb0dd560f4aff255d885..69a8dfb16d1eb62cccfbbba342418c0868bff69a 100644 (file)
@@ -243,11 +243,11 @@ InterfaceGenerator::InterfaceGenerator():
        scope_level(0)
 { }
 
        scope_level(0)
 { }
 
-string InterfaceGenerator::get_out_prefix(StageType type)
+string InterfaceGenerator::get_out_prefix(Stage::Type type)
 {
 {
-       if(type==VERTEX)
+       if(type==Stage::VERTEX)
                return "_vs_out_";
                return "_vs_out_";
-       else if(type==GEOMETRY)
+       else if(type==Stage::GEOMETRY)
                return "_gs_out_";
        else
                return string();
                return "_gs_out_";
        else
                return string();
@@ -301,7 +301,7 @@ bool InterfaceGenerator::generate_interface(VariableDeclaration &var, const stri
        iface_var->type = var.type;
        iface_var->type_declaration = var.type_declaration;
        iface_var->name = name;
        iface_var->type = var.type;
        iface_var->type_declaration = var.type_declaration;
        iface_var->name = name;
-       if(stage->type==GEOMETRY)
+       if(stage->type==Stage::GEOMETRY)
                iface_var->array = ((var.array && var.interface!="in") || iface=="in");
        else
                iface_var->array = var.array;
                iface_var->array = ((var.array && var.interface!="in") || iface=="in");
        else
                iface_var->array = var.array;
@@ -411,7 +411,7 @@ void InterfaceGenerator::visit(Passthrough &pass)
                }
        }
 
                }
        }
 
-       if(stage->type==GEOMETRY)
+       if(stage->type==Stage::GEOMETRY)
        {
                VariableReference *ref = new VariableReference;
                ref->name = "gl_in";
        {
                VariableReference *ref = new VariableReference;
                ref->name = "gl_in";
index aae570c4d7ad709e8f77cafc252c31b4cb2440cf..a09c552f1fd9f05c5329edabae112ece237017b0 100644 (file)
@@ -75,7 +75,7 @@ private:
 public:
        InterfaceGenerator();
 
 public:
        InterfaceGenerator();
 
-       static std::string get_out_prefix(StageType);
+       static std::string get_out_prefix(Stage::Type);
        virtual void apply(Stage &);
        using StageVisitor::visit;
        virtual void visit(Block &);
        virtual void apply(Stage &);
        using StageVisitor::visit;
        virtual void visit(Block &);
index 25115a5975674485afb4f0b8e1368250419be451..f4d1680bccfbe76d1dd3ddb4829390fdee123f95 100644 (file)
@@ -224,7 +224,7 @@ void UnusedVariableLocator::apply(Stage &s)
        BlockVariableMap &global_variables = variables.back();
        for(BlockVariableMap::iterator i=global_variables.begin(); i!=global_variables.end(); ++i)
        {
        BlockVariableMap &global_variables = variables.back();
        for(BlockVariableMap::iterator i=global_variables.begin(); i!=global_variables.end(); ++i)
        {
-               if(i->first->interface=="out" && (s.type==FRAGMENT || i->first->linked_declaration || !i->first->name.compare(0, 3, "gl_")))
+               if(i->first->interface=="out" && (s.type==Stage::FRAGMENT || i->first->linked_declaration || !i->first->name.compare(0, 3, "gl_")))
                        continue;
                if(!i->second.referenced)
                {
                        continue;
                if(!i->second.referenced)
                {
index aaba1dc4a0a638f15145dc48726344256056727a..dfd93470dd101dfac8ca4c7f8a07be588bb11e9f 100644 (file)
@@ -211,9 +211,9 @@ void Formatter::visit(VariableDeclaration &var)
                string interface = var.interface;
                if(stage->required_version<Version(1, 30))
                {
                string interface = var.interface;
                if(stage->required_version<Version(1, 30))
                {
-                       if(stage->type==VERTEX && var.interface=="in")
+                       if(stage->type==Stage::VERTEX && var.interface=="in")
                                interface = "attribute";
                                interface = "attribute";
-                       else if((stage->type==VERTEX && var.interface=="out") || (stage->type==FRAGMENT && var.interface=="in"))
+                       else if((stage->type==Stage::VERTEX && var.interface=="out") || (stage->type==Stage::FRAGMENT && var.interface=="in"))
                                interface = "varying";
                }
                append(format("%s ", interface));
                                interface = "varying";
                }
                append(format("%s ", interface));
index eaf5706f25a6fd8b30935835efb32272943427e4..7f0f8e138629f37ee03c67e2b60a1481e5e5b458 100644 (file)
@@ -73,7 +73,7 @@ void Parser::set_required_version(const Version &ver)
        cur_stage->required_version = ver;
 }
 
        cur_stage->required_version = ver;
 }
 
-void Parser::stage_change(StageType stage)
+void Parser::stage_change(Stage::Type stage)
 {
        if(!allow_stage_change)
                throw invalid_shader_source(tokenizer.get_location(), "Changing stage not allowed here");
 {
        if(!allow_stage_change)
                throw invalid_shader_source(tokenizer.get_location(), "Changing stage not allowed here");
@@ -82,7 +82,7 @@ void Parser::stage_change(StageType stage)
 
        module->stages.push_back(stage);
 
 
        module->stages.push_back(stage);
 
-       if(cur_stage->type!=SHARED)
+       if(cur_stage->type!=Stage::SHARED)
                module->stages.back().previous = cur_stage;
        cur_stage = &module->stages.back();
 }
                module->stages.back().previous = cur_stage;
        cur_stage = &module->stages.back();
 }
@@ -254,7 +254,7 @@ RefPtr<Statement> Parser::parse_statement()
 
 RefPtr<Import> Parser::parse_import()
 {
 
 RefPtr<Import> Parser::parse_import()
 {
-       if(cur_stage->type!=SHARED)
+       if(cur_stage->type!=Stage::SHARED)
                throw invalid_shader_source(tokenizer.get_location(), "Imports are only allowed in the shared section");
 
        tokenizer.expect("import");
                throw invalid_shader_source(tokenizer.get_location(), "Imports are only allowed in the shared section");
 
        tokenizer.expect("import");
@@ -651,7 +651,7 @@ RefPtr<Passthrough> Parser::parse_passthrough()
        RefPtr<Passthrough> pass = new Passthrough;
        pass->source = source_index;
        pass->line = tokenizer.get_location().line;
        RefPtr<Passthrough> pass = new Passthrough;
        pass->source = source_index;
        pass->line = tokenizer.get_location().line;
-       if(cur_stage->type==GEOMETRY)
+       if(cur_stage->type==Stage::GEOMETRY)
        {
                tokenizer.expect("[");
                pass->subscript = parse_expression();
        {
                tokenizer.expect("[");
                pass->subscript = parse_expression();
index 6e4bb38b11dd436e4d289681abcf36f3a2687599..b6c8369debb91d379e66d8f1a2afda5f2e53bea9 100644 (file)
@@ -35,7 +35,7 @@ public:
 private:
        void parse_source(const std::string &);
        void set_required_version(const Version &);
 private:
        void parse_source(const std::string &);
        void set_required_version(const Version &);
-       void stage_change(StageType);
+       void stage_change(Stage::Type);
 
        std::string expect_type();
        std::string expect_identifier();
 
        std::string expect_type();
        std::string expect_identifier();
index bf2d4b4de0c2b226fcbb90becd48047b9c93946b..354b2a7a84b6d8f6a0fda875f8b396caaba211df 100644 (file)
@@ -64,13 +64,13 @@ void Preprocessor::preprocess_stage()
        tokenizer.expect("stage");
        tokenizer.expect("(");
        string token = tokenizer.parse_token();
        tokenizer.expect("stage");
        tokenizer.expect("(");
        string token = tokenizer.parse_token();
-       StageType stage = SHARED;
+       Stage::Type stage = Stage::SHARED;
        if(token=="vertex")
        if(token=="vertex")
-               stage = VERTEX;
+               stage = Stage::VERTEX;
        else if(token=="geometry")
        else if(token=="geometry")
-               stage = GEOMETRY;
+               stage = Stage::GEOMETRY;
        else if(token=="fragment")
        else if(token=="fragment")
-               stage = FRAGMENT;
+               stage = Stage::FRAGMENT;
        else
                throw parse_error(tokenizer.get_location(), token, "stage identifier");
        tokenizer.expect(")");
        else
                throw parse_error(tokenizer.get_location(), token, "stage identifier");
        tokenizer.expect(")");
index 969703016ec52519b20e61cf2963363c5d09f564..d812a3fa79673b87cadec95c9b1590db7cd84b98 100644 (file)
@@ -14,7 +14,7 @@ class Preprocessor
 {
 public:
        sigc::signal<void, const Version &> signal_version;
 {
 public:
        sigc::signal<void, const Version &> signal_version;
-       sigc::signal<void, StageType> signal_stage_change;
+       sigc::signal<void, Stage::Type> signal_stage_change;
 
 private:
        Tokenizer &tokenizer;
 
 private:
        Tokenizer &tokenizer;
index e508ed890c0ddc5a35c0180acdde11f7675d5f8e..b0d462a816acc854f881f0cafd7e599953ea64af 100644 (file)
@@ -262,14 +262,14 @@ void Jump::visit(NodeVisitor &visitor)
 }
 
 
 }
 
 
-Stage::Stage(StageType t):
+Stage::Stage(Stage::Type t):
        type(t),
        previous(0)
 { }
 
 
 Module::Module():
        type(t),
        previous(0)
 { }
 
 
 Module::Module():
-       shared(SHARED)
+       shared(Stage::SHARED)
 { }
 
 } // namespace SL
 { }
 
 } // namespace SL
index 549e5e895add03fb41f8b62b3c038a1be01326cb..25b7e4a0450d8d89e940579a87af356a74ee5ac1 100644 (file)
@@ -360,17 +360,17 @@ struct Jump: Statement
        virtual void visit(NodeVisitor &);
 };
 
        virtual void visit(NodeVisitor &);
 };
 
-enum StageType
-{
-       SHARED,
-       VERTEX,
-       GEOMETRY,
-       FRAGMENT
-};
-
 struct Stage
 {
 struct Stage
 {
-       StageType type;
+       enum Type
+       {
+               SHARED,
+               VERTEX,
+               GEOMETRY,
+               FRAGMENT
+       };
+
+       Type type;
        Stage *previous;
        Block content;
        std::map<std::string, VariableDeclaration *> in_variables;
        Stage *previous;
        Block content;
        std::map<std::string, VariableDeclaration *> in_variables;
@@ -379,7 +379,7 @@ struct Stage
        Version required_version;
        std::vector<const Extension *> required_extensions;
 
        Version required_version;
        std::vector<const Extension *> required_extensions;
 
-       Stage(StageType);
+       Stage(Type);
 };
 
 struct Module
 };
 
 struct Module