]> git.tdb.fi Git - libs/gl.git/commitdiff
Properly handle the legacy replacement of fragment shader output
authorMikko Rasa <tdb@tdb.fi>
Fri, 6 Jan 2017 13:18:42 +0000 (15:18 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 6 Jan 2017 13:27:23 +0000 (15:27 +0200)
Assignment targets to the output variable need to be cleared, lest the
unused variable locator tries to access deleted nodes.

source/programcompiler.cpp
source/programcompiler.h

index f9a14f2f00a119ffbd7ba7604fd36a84e5a96585..fd27839da25e1f7cb377a7fdf46079bfb1e862f3 100644 (file)
@@ -1494,11 +1494,13 @@ void ProgramCompiler::NodeRemover::visit(VariableDeclaration &var)
 
 
 ProgramCompiler::LegacyConverter::LegacyConverter():
-       target_version(get_glsl_version())
+       target_version(get_glsl_version()),
+       frag_out(0)
 { }
 
 ProgramCompiler::LegacyConverter::LegacyConverter(const Version &v):
-       target_version(v)
+       target_version(v),
+       frag_out(0)
 { }
 
 bool ProgramCompiler::LegacyConverter::check_version(const Version &feature_version)
@@ -1513,7 +1515,7 @@ bool ProgramCompiler::LegacyConverter::check_version(const Version &feature_vers
 
 void ProgramCompiler::LegacyConverter::visit(VariableReference &var)
 {
-       if(var.name==frag_out_name && !check_version(Version(1, 30)))
+       if(var.declaration==frag_out && !check_version(Version(1, 30)))
        {
                var.name = "gl_FragColor";
                var.declaration = 0;
@@ -1525,6 +1527,13 @@ void ProgramCompiler::LegacyConverter::visit(VariableReference &var)
                type = string();
 }
 
+void ProgramCompiler::LegacyConverter::visit(Assignment &assign)
+{
+       TraversingVisitor::visit(assign);
+       if(assign.target_declaration==frag_out && !check_version(Version(1, 30)))
+               assign.target_declaration = 0;
+}
+
 void ProgramCompiler::LegacyConverter::visit(FunctionCall &call)
 {
        if(call.name=="texture" && !call.declaration && !check_version(Version(1, 30)))
@@ -1581,7 +1590,7 @@ void ProgramCompiler::LegacyConverter::visit(VariableDeclaration &var)
        {
                if(stage->type==FRAGMENT && var.interface=="out")
                {
-                       frag_out_name = var.name;
+                       frag_out = &var;
                        remove_node = true;
                }
        }
index 5bb7147496b3190f730db4a878395f81fe2fb519..e159078a647a4aea0573e7f03f9b8c423fc0db84 100644 (file)
@@ -330,7 +330,7 @@ private:
        {
                Version target_version;
                std::string type;
-               std::string frag_out_name;
+               ProgramSyntax::VariableDeclaration *frag_out;
 
                LegacyConverter();
                LegacyConverter(const Version &);
@@ -338,6 +338,7 @@ private:
                bool check_version(const Version &);
                using Visitor::visit;
                virtual void visit(ProgramSyntax::VariableReference &);
+               virtual void visit(ProgramSyntax::Assignment &);
                virtual void visit(ProgramSyntax::FunctionCall &);
                virtual void visit(ProgramSyntax::VariableDeclaration &);
                virtual void visit(ProgramSyntax::InterfaceBlock &);