Commit 60fe407c by alokp@chromium.org

Added TIntermSelection::usesTernaryOperator() to distinguish between selection…

Added TIntermSelection::usesTernaryOperator() to distinguish between selection nodes using ternary operator and if-else. Used in both OutputGLSL and OutputHLSL. Review URL: http://codereview.appspot.com/830042 git-svn-id: https://angleproject.googlecode.com/svn/trunk@82 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 1180ea73
......@@ -285,23 +285,35 @@ bool TOutputGLSL::visitSelection(Visit visit, TIntermSelection* node)
{
TInfoSinkBase& out = objSink();
out << "if (";
node->getCondition()->traverse(this);
out << ") {\n";
incrementDepth();
node->getTrueBlock()->traverse(this);
out << getIndentationString(depth - 2) << "}";
if (node->getFalseBlock())
if (node->usesTernaryOperator())
{
out << " else {\n";
out << "(";
node->getCondition()->traverse(this);
out << ") ? (";
node->getTrueBlock()->traverse(this);
out << ") : (";
node->getFalseBlock()->traverse(this);
out << getIndentationString(depth - 2) << "}";
out << ")";
}
decrementDepth();
else
{
out << "if (";
node->getCondition()->traverse(this);
out << ") {\n";
out << "\n";
incrementDepth();
node->getTrueBlock()->traverse(this);
out << getIndentationString(depth - 2) << "}";
if (node->getFalseBlock())
{
out << " else {\n";
node->getFalseBlock()->traverse(this);
out << getIndentationString(depth - 2) << "}";
}
decrementDepth();
out << "\n";
}
return false;
}
......
......@@ -956,7 +956,17 @@ bool OutputHLSL::visitSelection(Visit visit, TIntermSelection *node)
{
TInfoSinkBase &out = context.infoSink.obj;
if (node->getType().getBasicType() == EbtVoid) // if/else statement
if (node->usesTernaryOperator())
{
out << "(";
node->getCondition()->traverse(this);
out << ") ? (";
node->getTrueBlock()->traverse(this);
out << ") : (";
node->getFalseBlock()->traverse(this);
out << ")\n";
}
else // if/else statement
{
out << "if(";
......@@ -979,16 +989,6 @@ bool OutputHLSL::visitSelection(Visit visit, TIntermSelection *node)
out << ";}\n";
}
}
else // Ternary operator expression
{
out << "(";
node->getCondition()->traverse(this);
out << ") ? (";
node->getTrueBlock()->traverse(this);
out << ") : (";
node->getFalseBlock()->traverse(this);
out << ")\n";
}
return false;
}
......
......@@ -417,6 +417,7 @@ public:
TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB, const TType& type) :
TIntermTyped(type), condition(cond), trueBlock(trueB), falseBlock(falseB) {}
virtual void traverse(TIntermTraverser*);
bool usesTernaryOperator() const { return getBasicType() != EbtVoid; }
virtual TIntermNode* getCondition() const { return condition; }
virtual TIntermNode* getTrueBlock() const { return trueBlock; }
virtual TIntermNode* getFalseBlock() const { return falseBlock; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment