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) ...@@ -285,23 +285,35 @@ bool TOutputGLSL::visitSelection(Visit visit, TIntermSelection* node)
{ {
TInfoSinkBase& out = objSink(); TInfoSinkBase& out = objSink();
out << "if ("; if (node->usesTernaryOperator())
node->getCondition()->traverse(this);
out << ") {\n";
incrementDepth();
node->getTrueBlock()->traverse(this);
out << getIndentationString(depth - 2) << "}";
if (node->getFalseBlock())
{ {
out << " else {\n"; out << "(";
node->getCondition()->traverse(this);
out << ") ? (";
node->getTrueBlock()->traverse(this);
out << ") : (";
node->getFalseBlock()->traverse(this); 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; return false;
} }
......
...@@ -956,7 +956,17 @@ bool OutputHLSL::visitSelection(Visit visit, TIntermSelection *node) ...@@ -956,7 +956,17 @@ bool OutputHLSL::visitSelection(Visit visit, TIntermSelection *node)
{ {
TInfoSinkBase &out = context.infoSink.obj; 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("; out << "if(";
...@@ -979,16 +989,6 @@ bool OutputHLSL::visitSelection(Visit visit, TIntermSelection *node) ...@@ -979,16 +989,6 @@ bool OutputHLSL::visitSelection(Visit visit, TIntermSelection *node)
out << ";}\n"; 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; return false;
} }
......
...@@ -417,6 +417,7 @@ public: ...@@ -417,6 +417,7 @@ public:
TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB, const TType& type) : TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB, const TType& type) :
TIntermTyped(type), condition(cond), trueBlock(trueB), falseBlock(falseB) {} TIntermTyped(type), condition(cond), trueBlock(trueB), falseBlock(falseB) {}
virtual void traverse(TIntermTraverser*); virtual void traverse(TIntermTraverser*);
bool usesTernaryOperator() const { return getBasicType() != EbtVoid; }
virtual TIntermNode* getCondition() const { return condition; } virtual TIntermNode* getCondition() const { return condition; }
virtual TIntermNode* getTrueBlock() const { return trueBlock; } virtual TIntermNode* getTrueBlock() const { return trueBlock; }
virtual TIntermNode* getFalseBlock() const { return falseBlock; } 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