]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/optimize.cpp
Fix function inlining in iteration init statement
[libs/gl.git] / source / glsl / optimize.cpp
index a999a654db84ac8ac072ef7fb817d5107643a584..0af24e3e8f88df55e0d449e0044f6007fafe0275 100644 (file)
@@ -289,11 +289,15 @@ void FunctionInliner::visit(Conditional &cond)
 
 void FunctionInliner::visit(Iteration &iter)
 {
-       SetForScope<Block *> set_block(current_block, &iter.body);
+       /* Visit the initialization statement before entering the loop body so the
+       inlined statements get inserted outside. */
        if(iter.init_statement)
                iter.init_statement->visit(*this);
-       /* Skip the condition and loop expression parts because they're executed on
-       every iteration of the loop */
+
+       SetForScope<Block *> set_block(current_block, &iter.body);
+       /* Skip the condition and loop expression parts because they're not properly
+       inside the body block.  Inlining anything into them will require a more
+       comprehensive transformation. */
        iter.body.visit(*this);
 }