]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/generate.cpp
Only generate or link interfaces in the correct scope
[libs/gl.git] / source / glsl / generate.cpp
index 48de1efc5992a4796411e5cadaf6618903c363e3..3ff04eb9890124f7098c015dafe1099d77d7d34e 100644 (file)
@@ -258,7 +258,8 @@ void FunctionResolver::visit(FunctionDeclaration &func)
 
 
 InterfaceGenerator::InterfaceGenerator():
-       stage(0)
+       stage(0),
+       function_scope(false)
 { }
 
 string InterfaceGenerator::get_out_prefix(Stage::Type type)
@@ -369,7 +370,9 @@ void InterfaceGenerator::visit(VariableDeclaration &var)
 {
        if(var.interface=="out")
        {
-               if(current_block!=&stage->content && generate_interface(var, "out", change_prefix(var.name, string())))
+               /* For out variables in function scope, generate a global interface and
+               replace the local declaration with an assignment. */
+               if(function_scope && generate_interface(var, "out", var.name))
                {
                        nodes_to_remove.insert(&var);
                        if(var.init_expression)
@@ -383,7 +386,9 @@ void InterfaceGenerator::visit(VariableDeclaration &var)
        }
        else if(var.interface=="in")
        {
-               if(!var.linked_declaration && stage->previous)
+               /* Try to link in variables in global scope with out variables from
+               previous stage */
+               if(current_block==&stage->content && !var.linked_declaration && stage->previous)
                {
                        const map<string, VariableDeclaration *> &prev_vars = stage->previous->content.variables;
                        map<string, VariableDeclaration *>::const_iterator i = prev_vars.find(var.name);
@@ -400,6 +405,7 @@ void InterfaceGenerator::visit(VariableDeclaration &var)
 
 void InterfaceGenerator::visit(FunctionDeclaration &func)
 {
+       SetFlag set_scope(function_scope, true);
        // Skip parameters because they're not useful here
        func.body.visit(*this);
 }