]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/optimize.cpp
Transform interface block contents into structs
[libs/gl.git] / source / glsl / optimize.cpp
index f938314814ea9cd4211279d5e94ff817c2a92fcc..c1431f2b6e9d9e33ed522cd853bcd326bbb3414a 100644 (file)
@@ -668,6 +668,11 @@ void UnusedTypeRemover::visit(VariableDeclaration &var)
        unused_nodes.erase(var.type_declaration);
 }
 
+void UnusedTypeRemover::visit(InterfaceBlock &iface)
+{
+       unused_nodes.erase(iface.type_declaration);
+}
+
 void UnusedTypeRemover::visit(FunctionDeclaration &func)
 {
        unused_nodes.erase(func.return_type_declaration);
@@ -690,9 +695,19 @@ bool UnusedVariableRemover::apply(Stage &stage)
        BlockVariableMap &global_variables = variables.back();
        for(BlockVariableMap::iterator i=global_variables.begin(); i!=global_variables.end(); ++i)
        {
+               string interface = i->first->interface;
+               bool linked = i->first->linked_declaration;
+               map<VariableDeclaration *, Node *>::iterator j = aggregates.find(i->first);
+               if(j!=aggregates.end())
+                       if(InterfaceBlock *iface = dynamic_cast<InterfaceBlock *>(j->second))
+                       {
+                               interface = iface->interface;
+                               linked = iface->linked_block;
+                       }
+
                /* Don't remove output variables which are used by the next stage or the
                graphics API. */
-               if(i->first->interface=="out" && (stage.type==Stage::FRAGMENT || i->first->linked_declaration || !i->first->name.compare(0, 3, "gl_")))
+               if(interface=="out" && (stage.type==Stage::FRAGMENT || linked || !i->first->name.compare(0, 3, "gl_")))
                        continue;
 
                // Mark other unreferenced global variables as unused.
@@ -833,7 +848,7 @@ void UnusedVariableRemover::visit(InterfaceBlock &iface)
 {
        SetForScope<Node *> set(aggregate, &iface);
        unused_nodes.insert(&iface);
-       TraversingVisitor::visit(iface);
+       iface.struct_declaration->members.visit(*this);
 }
 
 void UnusedVariableRemover::visit(FunctionDeclaration &func)