Compiler - fix mat3 conformance
TRAC #11723
Matrix elements are accessed as [col][row] in GLSL and [row][col] in HLSL. Fixed this by transposing all matrix uniforms so they have a row-major layout. Then transpose them in the shader every time they're used in matrix math.
Signed-off-by: Andrew Lewycky
Signed-off-by: Daniel Koch
Author: Nicolas Capens
git-svn-id: https://angleproject.googlecode.com/svn/trunk@96 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/compiler/OutputHLSL.cpp b/src/compiler/OutputHLSL.cpp
index 5de6c3f..785e18d 100644
--- a/src/compiler/OutputHLSL.cpp
+++ b/src/compiler/OutputHLSL.cpp
@@ -553,12 +553,24 @@
else if (visit == InVisit)
{
out << " = mul(";
+
+ if (node->getOp() == EOpMatrixTimesMatrixAssign)
+ {
+ out << "transpose(";
+ }
+
node->getLeft()->traverse(this);
- out << ", ";
+
+ if (node->getOp() == EOpMatrixTimesMatrixAssign)
+ {
+ out << ")";
+ }
+
+ out << ", transpose(";
}
else
{
- out << "))";
+ out << ")))";
}
break;
case EOpDivAssign: outputTriplet(visit, "(", " /= ", ")"); break;
@@ -631,9 +643,9 @@
case EOpGreaterThanEqual: outputTriplet(visit, "(", " >= ", ")"); break;
case EOpVectorTimesScalar: outputTriplet(visit, "(", " * ", ")"); break;
case EOpMatrixTimesScalar: outputTriplet(visit, "(", " * ", ")"); break;
- case EOpVectorTimesMatrix: outputTriplet(visit, "mul(", ", ", ")"); break;
- case EOpMatrixTimesVector: outputTriplet(visit, "mul(", ", ", ")"); break;
- case EOpMatrixTimesMatrix: outputTriplet(visit, "mul(", ", ", ")"); break;
+ case EOpVectorTimesMatrix: outputTriplet(visit, "mul(", ", transpose(", "))"); break;
+ case EOpMatrixTimesVector: outputTriplet(visit, "mul(transpose(", "), ", ")"); break;
+ case EOpMatrixTimesMatrix: outputTriplet(visit, "mul(transpose(", "), transpose(", "))"); break;
case EOpLogicalOr: outputTriplet(visit, "(", " || ", ")"); break;
case EOpLogicalXor: outputTriplet(visit, "xor(", ", ", ")"); break; // FIXME: Prevent name clashes
case EOpLogicalAnd: outputTriplet(visit, "(", " && ", ")"); break;