X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fglsl%2Fgenerate.cpp;h=e5855e94cacb701c4ab96bec16324335fcccf910;hp=ab487a44c470bca769af032b9ce2966c7a0df5d2;hb=3a1fe833ea04df75449706f1d773f6e65521a392;hpb=1476e64621ecbd7b17b00ae2c958322fd39918de diff --git a/source/glsl/generate.cpp b/source/glsl/generate.cpp index ab487a44..e5855e94 100644 --- a/source/glsl/generate.cpp +++ b/source/glsl/generate.cpp @@ -872,6 +872,36 @@ void ExpressionResolver::visit(Assignment &assign) resolve(assign, assign.left->type, true); } +void ExpressionResolver::visit(TernaryExpression &ternary) +{ + TraversingVisitor::visit(ternary); + + BasicTypeDeclaration *basic_cond = dynamic_cast(ternary.condition->type); + if(!basic_cond || basic_cond->kind!=BasicTypeDeclaration::BOOL) + return; + + TypeDeclaration *type = 0; + if(ternary.true_expr->type==ternary.false_expr->type) + type = ternary.true_expr->type; + else + { + BasicTypeDeclaration *basic_true = dynamic_cast(ternary.true_expr->type); + BasicTypeDeclaration *basic_false = dynamic_cast(ternary.false_expr->type); + Compatibility compat = get_compatibility(*basic_true, *basic_false); + if(compat==NOT_COMPATIBLE) + return; + + type = (compat==LEFT_CONVERTIBLE ? basic_true : basic_false); + + if(compat==LEFT_CONVERTIBLE) + convert_to(ternary.true_expr, *basic_false); + else if(compat==RIGHT_CONVERTIBLE) + convert_to(ternary.false_expr, *basic_true); + } + + resolve(ternary, type, false); +} + void ExpressionResolver::visit(FunctionCall &call) { TraversingVisitor::visit(call);