]> git.tdb.fi Git - libs/gl.git/blobdiff - source/programparser.cpp
Support while loops in GLSL
[libs/gl.git] / source / programparser.cpp
index b607e1cfb8f063abfec2127b7c57247809677a81..c02adb325c25eaba6d4df7f31d9b8963506a5cd4 100644 (file)
@@ -484,7 +484,9 @@ RefPtr<Node> ProgramParser::parse_statement()
        if(token=="if")
                return parse_conditional();
        else if(token=="for")
-               return parse_iteration();
+               return parse_for();
+       else if(token=="while")
+               return parse_while();
        else if(token=="passthrough")
                return parse_passthrough();
        else if(token=="return")
@@ -843,7 +845,7 @@ RefPtr<Conditional> ProgramParser::parse_conditional()
        return cond;
 }
 
-RefPtr<Iteration> ProgramParser::parse_iteration()
+RefPtr<Iteration> ProgramParser::parse_for()
 {
        expect("for");
        expect("(");
@@ -873,6 +875,19 @@ RefPtr<Iteration> ProgramParser::parse_iteration()
        return loop;
 }
 
+RefPtr<Iteration> ProgramParser::parse_while()
+{
+       expect("while");
+       expect("(");
+       RefPtr<Iteration> loop = new Iteration;
+       loop->condition = parse_expression();
+       expect(")");
+
+       parse_block(loop->body, false);
+
+       return loop;
+}
+
 RefPtr<Passthrough> ProgramParser::parse_passthrough()
 {
        expect("passthrough");