]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/output.cpp
Implement the ternary operator in GLSL
[libs/gl.git] / source / glsl / output.cpp
index 43f337cabc3e6296e9afdc1f91130e3d8bd7b56f..364e5e4b23c02356a2c72743103ba212a32abd91 100644 (file)
@@ -13,12 +13,14 @@ Formatter::Formatter():
        source_index(0),
        source_line(1),
        indent(0),
-       parameter_list(false)
+       parameter_list(false),
+       omit_builtin(false)
 { }
 
 const string &Formatter::apply(Stage &s)
 {
        stage = &s;
+       omit_builtin = true;
 
        const Version &ver = s.required_features.glsl_version;
 
@@ -92,7 +94,7 @@ void Formatter::visit(Block &block)
        bool first = true;
        for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); ++i)
        {
-               if((*i)->source<=BUILTIN_SOURCE)
+               if(omit_builtin && (*i)->source<=BUILTIN_SOURCE)
                        continue;
                if(!first)
                        append('\n');
@@ -165,6 +167,16 @@ void Formatter::visit(Assignment &assign)
        assign.right->visit(*this);
 }
 
+void Formatter::visit(TernaryExpression &ternary)
+{
+       ternary.condition->visit(*this);
+       append(ternary.oper->token);
+       ternary.true_expr->visit(*this);
+       if(ternary.oper->token[0]=='?')
+               append(':');
+       ternary.false_expr->visit(*this);
+}
+
 void Formatter::visit(FunctionCall &call)
 {
        append(format("%s(", call.name));