]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/compatibility.cpp
Refactor the way of applying visitors to stages
[libs/gl.git] / source / glsl / compatibility.cpp
index a3b2882dc538b0db82d603c12f792c3846ca36b5..398a7bd30a76eaa4b141b400d9cd4e08d0e87958 100644 (file)
@@ -14,9 +14,16 @@ namespace GL {
 namespace SL {
 
 DefaultPrecisionGenerator::DefaultPrecisionGenerator():
+       stage_type(Stage::SHARED),
        toplevel(true)
 { }
 
+void DefaultPrecisionGenerator::apply(Stage &stage)
+{
+       SetForScope<Stage::Type> set_stage(stage_type, stage.type);
+       visit(stage.content);
+}
+
 void DefaultPrecisionGenerator::visit(Block &block)
 {
        if(toplevel)
@@ -25,7 +32,7 @@ void DefaultPrecisionGenerator::visit(Block &block)
                BlockModifier::visit(block);
        }
        else
-               StageVisitor::visit(block);
+               TraversingVisitor::visit(block);
 }
 
 void DefaultPrecisionGenerator::visit(Precision &prec)
@@ -49,7 +56,7 @@ void DefaultPrecisionGenerator::visit(VariableDeclaration &var)
                Precision *prec = new Precision;
                if(!type.compare(0, 7, "sampler"))
                        prec->precision = "lowp";
-               else if(stage->type==Stage::FRAGMENT)
+               else if(stage_type==Stage::FRAGMENT)
                        prec->precision = "mediump";
                else
                        prec->precision = "highp";
@@ -106,6 +113,12 @@ bool LegacyConverter::check_extension(const Extension &extension) const
        return true;
 }
 
+void LegacyConverter::apply(Stage &s)
+{
+       SetForScope<Stage *> set_stage(stage, &s);
+       visit(s.content);
+}
+
 bool LegacyConverter::supports_unified_interface_syntax() const
 {
        if(target_api==OPENGL_ES2)