Only output faceforward when needed

TRAC #12042 Signed-off-by: Andrew Lewycky Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@193 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent c164135c
...@@ -32,6 +32,10 @@ OutputHLSL::OutputHLSL(TParseContext &context) : TIntermTraverser(true, true, tr ...@@ -32,6 +32,10 @@ OutputHLSL::OutputHLSL(TParseContext &context) : TIntermTraverser(true, true, tr
mUsesTexture2DProj_bias = false; mUsesTexture2DProj_bias = false;
mUsesTextureCube = false; mUsesTextureCube = false;
mUsesTextureCube_bias = false; mUsesTextureCube_bias = false;
mUsesFaceforward1 = false;
mUsesFaceforward2 = false;
mUsesFaceforward3 = false;
mUsesFaceforward4 = false;
mUsesEqualMat2 = false; mUsesEqualMat2 = false;
mUsesEqualMat3 = false; mUsesEqualMat3 = false;
mUsesEqualMat4 = false; mUsesEqualMat4 = false;
...@@ -453,8 +457,11 @@ void OutputHLSL::header() ...@@ -453,8 +457,11 @@ void OutputHLSL::header()
"{\n" "{\n"
" return x - y * floor(x / y);\n" " return x - y * floor(x / y);\n"
"}\n" "}\n"
"\n" "\n";
"float faceforward(float N, float I, float Nref)\n"
if (mUsesFaceforward1)
{
out << "float faceforward(float N, float I, float Nref)\n"
"{\n" "{\n"
" if(dot(Nref, I) < 0)\n" " if(dot(Nref, I) < 0)\n"
" {\n" " {\n"
...@@ -465,8 +472,12 @@ void OutputHLSL::header() ...@@ -465,8 +472,12 @@ void OutputHLSL::header()
" return -N;\n" " return -N;\n"
" }\n" " }\n"
"}\n" "}\n"
"\n" "\n";
"float2 faceforward(float2 N, float2 I, float2 Nref)\n" }
if (mUsesFaceforward2)
{
out << "float2 faceforward(float2 N, float2 I, float2 Nref)\n"
"{\n" "{\n"
" if(dot(Nref, I) < 0)\n" " if(dot(Nref, I) < 0)\n"
" {\n" " {\n"
...@@ -477,8 +488,12 @@ void OutputHLSL::header() ...@@ -477,8 +488,12 @@ void OutputHLSL::header()
" return -N;\n" " return -N;\n"
" }\n" " }\n"
"}\n" "}\n"
"\n" "\n";
"float3 faceforward(float3 N, float3 I, float3 Nref)\n" }
if (mUsesFaceforward3)
{
out << "float3 faceforward(float3 N, float3 I, float3 Nref)\n"
"{\n" "{\n"
" if(dot(Nref, I) < 0)\n" " if(dot(Nref, I) < 0)\n"
" {\n" " {\n"
...@@ -489,8 +504,12 @@ void OutputHLSL::header() ...@@ -489,8 +504,12 @@ void OutputHLSL::header()
" return -N;\n" " return -N;\n"
" }\n" " }\n"
"}\n" "}\n"
"\n" "\n";
"float4 faceforward(float4 N, float4 I, float4 Nref)\n" }
if (mUsesFaceforward4)
{
out << "float4 faceforward(float4 N, float4 I, float4 Nref)\n"
"{\n" "{\n"
" if(dot(Nref, I) < 0)\n" " if(dot(Nref, I) < 0)\n"
" {\n" " {\n"
...@@ -502,6 +521,7 @@ void OutputHLSL::header() ...@@ -502,6 +521,7 @@ void OutputHLSL::header()
" }\n" " }\n"
"}\n" "}\n"
"\n"; "\n";
}
if (mUsesEqualMat2) if (mUsesEqualMat2)
{ {
...@@ -1346,7 +1366,20 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1346,7 +1366,20 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
case EOpDistance: outputTriplet(visit, "distance(", ", ", ")"); break; case EOpDistance: outputTriplet(visit, "distance(", ", ", ")"); break;
case EOpDot: outputTriplet(visit, "dot(", ", ", ")"); break; case EOpDot: outputTriplet(visit, "dot(", ", ", ")"); break;
case EOpCross: outputTriplet(visit, "cross(", ", ", ")"); break; case EOpCross: outputTriplet(visit, "cross(", ", ", ")"); break;
case EOpFaceForward: outputTriplet(visit, "faceforward(", ", ", ")"); break; case EOpFaceForward:
{
switch (node->getSequence()[0]->getAsTyped()->getSize()) // Number of components in the first argument
{
case 1: mUsesFaceforward1 = true; break;
case 2: mUsesFaceforward2 = true; break;
case 3: mUsesFaceforward3 = true; break;
case 4: mUsesFaceforward4 = true; break;
default: UNREACHABLE();
}
outputTriplet(visit, "faceforward(", ", ", ")");
}
break;
case EOpReflect: outputTriplet(visit, "reflect(", ", ", ")"); break; case EOpReflect: outputTriplet(visit, "reflect(", ", ", ")"); break;
case EOpRefract: outputTriplet(visit, "refract(", ", ", ")"); break; case EOpRefract: outputTriplet(visit, "refract(", ", ", ")"); break;
case EOpMul: outputTriplet(visit, "(", " * ", ")"); break; case EOpMul: outputTriplet(visit, "(", " * ", ")"); break;
......
...@@ -69,6 +69,10 @@ class OutputHLSL : public TIntermTraverser ...@@ -69,6 +69,10 @@ class OutputHLSL : public TIntermTraverser
bool mUsesTexture2DProj_bias; bool mUsesTexture2DProj_bias;
bool mUsesTextureCube; bool mUsesTextureCube;
bool mUsesTextureCube_bias; bool mUsesTextureCube_bias;
bool mUsesFaceforward1;
bool mUsesFaceforward2;
bool mUsesFaceforward3;
bool mUsesFaceforward4;
bool mUsesEqualMat2; bool mUsesEqualMat2;
bool mUsesEqualMat3; bool mUsesEqualMat3;
bool mUsesEqualMat4; bool mUsesEqualMat4;
......
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