Encapsulate expressions with ternary operators with brackets. This preserves the order of precedence when ternary expressions are used in a compound expression.
BUG=20
Review URL: http://codereview.appspot.com/1894041

git-svn-id: http://angleproject.googlecode.com/svn/trunk@352 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/compiler/OutputGLSL.cpp b/src/compiler/OutputGLSL.cpp
index 6f43524..486a27a 100644
--- a/src/compiler/OutputGLSL.cpp
+++ b/src/compiler/OutputGLSL.cpp
@@ -391,13 +391,17 @@
 
     if (node->usesTernaryOperator())
     {
-        out << "(";
+        // Notice two brackets at the beginning and end. The outer ones
+        // encapsulate the whole ternary expression. This preserves the
+        // order of precedence when ternary expressions are used in a
+        // compound expression, i.e., c = 2 * (a < b ? 1 : 2).
+        out << "((";
         node->getCondition()->traverse(this);
         out << ") ? (";
         node->getTrueBlock()->traverse(this);
         out << ") : (";
         node->getFalseBlock()->traverse(this);
-        out << ")";
+        out << "))";
     }
     else
     {