From 7a16308e72aef363727b21348779673edf8e5c07 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 15 Feb 2021 12:12:44 +0200 Subject: [PATCH] Move the StageType enum inside the Stage struct --- source/glsl/builtin.cpp | 2 +- source/glsl/builtin.h | 2 +- source/glsl/compatibility.cpp | 8 ++++---- source/glsl/compiler.cpp | 8 ++++---- source/glsl/generate.cpp | 10 +++++----- source/glsl/generate.h | 2 +- source/glsl/optimize.cpp | 2 +- source/glsl/output.cpp | 4 ++-- source/glsl/parser.cpp | 8 ++++---- source/glsl/parser.h | 2 +- source/glsl/preprocessor.cpp | 8 ++++---- source/glsl/preprocessor.h | 2 +- source/glsl/syntax.cpp | 4 ++-- source/glsl/syntax.h | 20 ++++++++++---------- 14 files changed, 41 insertions(+), 41 deletions(-) diff --git a/source/glsl/builtin.cpp b/source/glsl/builtin.cpp index 7aecda3c..ee692462 100644 --- a/source/glsl/builtin.cpp +++ b/source/glsl/builtin.cpp @@ -48,7 +48,7 @@ Module &get_builtins_module() return *builtins_module; } -Stage *get_builtins(StageType type) +Stage *get_builtins(Stage::Type type) { Module &module = get_builtins_module(); for(list::iterator i=module.stages.begin(); i!=module.stages.end(); ++i) diff --git a/source/glsl/builtin.h b/source/glsl/builtin.h index 59e5ed89..00cd3ff3 100644 --- a/source/glsl/builtin.h +++ b/source/glsl/builtin.h @@ -7,7 +7,7 @@ namespace Msp { namespace GL { namespace SL { -Stage *get_builtins(StageType); +Stage *get_builtins(Stage::Type); } // namespace SL } // namespace GL diff --git a/source/glsl/compatibility.cpp b/source/glsl/compatibility.cpp index 0c312d02..4e43ae9d 100644 --- a/source/glsl/compatibility.cpp +++ b/source/glsl/compatibility.cpp @@ -49,7 +49,7 @@ void DefaultPrecisionGenerator::visit(VariableDeclaration &var) 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"; @@ -231,12 +231,12 @@ void LegacyConverter::visit(VariableDeclaration &var) if(i!=var.layout->qualifiers.end()) { unsigned location = lexical_cast(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); } - 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); @@ -262,7 +262,7 @@ void LegacyConverter::visit(VariableDeclaration &var) 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; diff --git a/source/glsl/compiler.cpp b/source/glsl/compiler.cpp index 031ae265..e6c03577 100644 --- a/source/glsl/compiler.cpp +++ b/source/glsl/compiler.cpp @@ -65,15 +65,15 @@ void Compiler::add_shaders(Program &program) { for(list::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(*i))); for(map::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(*i))); - else if(i->type==FRAGMENT) + else if(i->type==Stage::FRAGMENT) { program.attach_shader_owned(new FragmentShader(apply(*i))); if(EXT_gpu_shader4) @@ -137,7 +137,7 @@ void Compiler::append_module(Module &mod) void Compiler::append_stage(Stage &stage) { Stage *target = 0; - if(stage.type==SHARED) + if(stage.type==Stage::SHARED) target = &module->shared; else { diff --git a/source/glsl/generate.cpp b/source/glsl/generate.cpp index 55687924..69a8dfb1 100644 --- a/source/glsl/generate.cpp +++ b/source/glsl/generate.cpp @@ -243,11 +243,11 @@ InterfaceGenerator::InterfaceGenerator(): 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_"; - else if(type==GEOMETRY) + else if(type==Stage::GEOMETRY) 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; - 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; @@ -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"; diff --git a/source/glsl/generate.h b/source/glsl/generate.h index aae570c4..a09c552f 100644 --- a/source/glsl/generate.h +++ b/source/glsl/generate.h @@ -75,7 +75,7 @@ private: 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 &); diff --git a/source/glsl/optimize.cpp b/source/glsl/optimize.cpp index 25115a59..f4d1680b 100644 --- a/source/glsl/optimize.cpp +++ b/source/glsl/optimize.cpp @@ -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) { - 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) { diff --git a/source/glsl/output.cpp b/source/glsl/output.cpp index aaba1dc4..dfd93470 100644 --- a/source/glsl/output.cpp +++ b/source/glsl/output.cpp @@ -211,9 +211,9 @@ void Formatter::visit(VariableDeclaration &var) string interface = var.interface; if(stage->required_versiontype==VERTEX && var.interface=="in") + if(stage->type==Stage::VERTEX && var.interface=="in") 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)); diff --git a/source/glsl/parser.cpp b/source/glsl/parser.cpp index eaf5706f..7f0f8e13 100644 --- a/source/glsl/parser.cpp +++ b/source/glsl/parser.cpp @@ -73,7 +73,7 @@ void Parser::set_required_version(const 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"); @@ -82,7 +82,7 @@ void Parser::stage_change(StageType 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(); } @@ -254,7 +254,7 @@ RefPtr Parser::parse_statement() RefPtr 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"); @@ -651,7 +651,7 @@ RefPtr Parser::parse_passthrough() RefPtr 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(); diff --git a/source/glsl/parser.h b/source/glsl/parser.h index 6e4bb38b..b6c8369d 100644 --- a/source/glsl/parser.h +++ b/source/glsl/parser.h @@ -35,7 +35,7 @@ public: 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(); diff --git a/source/glsl/preprocessor.cpp b/source/glsl/preprocessor.cpp index bf2d4b4d..354b2a7a 100644 --- a/source/glsl/preprocessor.cpp +++ b/source/glsl/preprocessor.cpp @@ -64,13 +64,13 @@ void Preprocessor::preprocess_stage() tokenizer.expect("stage"); tokenizer.expect("("); string token = tokenizer.parse_token(); - StageType stage = SHARED; + Stage::Type stage = Stage::SHARED; if(token=="vertex") - stage = VERTEX; + stage = Stage::VERTEX; else if(token=="geometry") - stage = GEOMETRY; + stage = Stage::GEOMETRY; else if(token=="fragment") - stage = FRAGMENT; + stage = Stage::FRAGMENT; else throw parse_error(tokenizer.get_location(), token, "stage identifier"); tokenizer.expect(")"); diff --git a/source/glsl/preprocessor.h b/source/glsl/preprocessor.h index 96970301..d812a3fa 100644 --- a/source/glsl/preprocessor.h +++ b/source/glsl/preprocessor.h @@ -14,7 +14,7 @@ class Preprocessor { public: sigc::signal signal_version; - sigc::signal signal_stage_change; + sigc::signal signal_stage_change; private: Tokenizer &tokenizer; diff --git a/source/glsl/syntax.cpp b/source/glsl/syntax.cpp index e508ed89..b0d462a8 100644 --- a/source/glsl/syntax.cpp +++ b/source/glsl/syntax.cpp @@ -262,14 +262,14 @@ void Jump::visit(NodeVisitor &visitor) } -Stage::Stage(StageType t): +Stage::Stage(Stage::Type t): type(t), previous(0) { } Module::Module(): - shared(SHARED) + shared(Stage::SHARED) { } } // namespace SL diff --git a/source/glsl/syntax.h b/source/glsl/syntax.h index 549e5e89..25b7e4a0 100644 --- a/source/glsl/syntax.h +++ b/source/glsl/syntax.h @@ -360,17 +360,17 @@ struct Jump: Statement virtual void visit(NodeVisitor &); }; -enum StageType -{ - SHARED, - VERTEX, - GEOMETRY, - FRAGMENT -}; - struct Stage { - StageType type; + enum Type + { + SHARED, + VERTEX, + GEOMETRY, + FRAGMENT + }; + + Type type; Stage *previous; Block content; std::map in_variables; @@ -379,7 +379,7 @@ struct Stage Version required_version; std::vector required_extensions; - Stage(StageType); + Stage(Type); }; struct Module -- 2.43.0