Split vector swizzle AST nodes into a different node class
This avoids creating a weird aggregate node with a sequence of
constant union nodes to store the offsets. They're stored neatly
inside a vector instead. This makes code that needs to iterate
over the swizzle offsets much simpler.
BUG=angleproject:1490
TEST=angle_unittests
Change-Id: I156b95723529ee05a94d30295ffb6d0952a98564
Reviewed-on: https://chromium-review.googlesource.com/390832
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/OutputGLSLBase.cpp b/src/compiler/translator/OutputGLSLBase.cpp
index 899b166..731e0fd 100644
--- a/src/compiler/translator/OutputGLSLBase.cpp
+++ b/src/compiler/translator/OutputGLSLBase.cpp
@@ -280,6 +280,17 @@
writeConstantUnion(node->getType(), node->getUnionArrayPointer());
}
+bool TOutputGLSLBase::visitSwizzle(Visit visit, TIntermSwizzle *node)
+{
+ TInfoSinkBase &out = objSink();
+ if (visit == PostVisit)
+ {
+ out << ".";
+ node->writeOffsetsAsXYZW(&out);
+ }
+ return true;
+}
+
bool TOutputGLSLBase::visitBinary(Visit visit, TIntermBinary *node)
{
bool visitChildren = true;
@@ -410,40 +421,6 @@
visitChildren = false;
}
break;
- case EOpVectorSwizzle:
- if (visit == InVisit)
- {
- out << ".";
- TIntermAggregate *rightChild = node->getRight()->getAsAggregate();
- TIntermSequence *sequence = rightChild->getSequence();
- for (TIntermSequence::iterator sit = sequence->begin(); sit != sequence->end(); ++sit)
- {
- TIntermConstantUnion *element = (*sit)->getAsConstantUnion();
- ASSERT(element->getBasicType() == EbtInt);
- ASSERT(element->getNominalSize() == 1);
- const TConstantUnion& data = element->getUnionArrayPointer()[0];
- ASSERT(data.getType() == EbtInt);
- switch (data.getIConst())
- {
- case 0:
- out << "x";
- break;
- case 1:
- out << "y";
- break;
- case 2:
- out << "z";
- break;
- case 3:
- out << "w";
- break;
- default:
- UNREACHABLE();
- }
- }
- visitChildren = false;
- }
- break;
case EOpAdd:
writeTriplet(visit, "(", " + ", ")");