Shader and Compiler track uses of gl_FragCoord and gl_FragData and MRT extension usage.

TRAC #22668

Signed-off-by: Jamie Madill
Signed-off-by: Shannon Woods
Author: Geoff Lang

git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2084 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/compiler/OutputHLSL.cpp b/src/compiler/OutputHLSL.cpp
index 4b314ef..39c5983 100644
--- a/src/compiler/OutputHLSL.cpp
+++ b/src/compiler/OutputHLSL.cpp
@@ -48,6 +48,8 @@
     mUsesTexture2DProjLod0_bias = false;
     mUsesTextureCubeLod0 = false;
     mUsesTextureCubeLod0_bias = false;
+    mUsesFragColor = false;
+    mUsesFragData = false;
     mUsesDepthRange = false;
     mUsesFragCoord = false;
     mUsesPointCoord = false;
@@ -82,6 +84,8 @@
     mUsesAtan2_3 = false;
     mUsesAtan2_4 = false;
 
+    mNumRenderTargets = resources.EXT_draw_buffers ? resources.MaxDrawBuffers : 1;
+
     mScopeDepth = 0;
 
     mUniqueIndex = 0;
@@ -205,6 +209,11 @@
 
     if (shaderType == SH_FRAGMENT_SHADER)
     {
+        TExtensionBehavior::const_iterator iter = mContext.extensionBehavior().find("GL_EXT_draw_buffers");
+        bool usingMRTExtension = iter != mContext.extensionBehavior().end() && iter->second == EBhEnable;
+
+        unsigned int numColorValues = usingMRTExtension ? mNumRenderTargets : 1;
+
         out << "// Varyings\n";
         out <<  varyings;
         out << "\n"
@@ -582,6 +591,21 @@
             }
             else UNREACHABLE();
         }
+
+        if (usingMRTExtension && mNumRenderTargets > 1)
+        {
+            out << "#define GL_USES_MRT\n";
+        }
+
+        if (mUsesFragColor)
+        {
+            out << "#define GL_USES_FRAG_COLOR\n";
+        }
+
+        if (mUsesFragData)
+        {
+            out << "#define GL_USES_FRAG_DATA\n";
+        }
     }
     else   // Vertex shader
     {
@@ -1099,10 +1123,12 @@
     if (name == "gl_FragColor")
     {
         out << "gl_Color[0]";
+        mUsesFragColor = true;
     }
     else if (name == "gl_FragData")
     {
         out << "gl_Color";
+        mUsesFragData = true;
     }
     else if (name == "gl_DepthRange")
     {
diff --git a/src/compiler/OutputHLSL.h b/src/compiler/OutputHLSL.h
index 8438681..4a6d12a 100644
--- a/src/compiler/OutputHLSL.h
+++ b/src/compiler/OutputHLSL.h
@@ -102,6 +102,8 @@
     bool mUsesTexture2DProjLod0_bias;
     bool mUsesTextureCubeLod0;
     bool mUsesTextureCubeLod0_bias;
+    bool mUsesFragColor;
+    bool mUsesFragData;
     bool mUsesDepthRange;
     bool mUsesFragCoord;
     bool mUsesPointCoord;
@@ -136,6 +138,8 @@
     bool mUsesAtan2_3;
     bool mUsesAtan2_4;
 
+    int mNumRenderTargets;
+
     typedef std::set<TString> Constructors;
     Constructors mConstructors;