Refactor GLSL version calculations for emulated functions.

Pass the target GLSL version to InitBuiltInFunctionEmulatorForGLSL so that
it can be updated to generate emulated functions for multiple versions.

BUG=angleproject:1044

Change-Id: I34c408df52fd0f7d6c2f66d0579ac854afd93b87
Reviewed-on: https://chromium-review.googlesource.com/277700
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/compiler/translator/VersionGLSL.cpp b/src/compiler/translator/VersionGLSL.cpp
index acb46dc..4364c2e 100644
--- a/src/compiler/translator/VersionGLSL.cpp
+++ b/src/compiler/translator/VersionGLSL.cpp
@@ -6,11 +6,17 @@
 
 #include "compiler/translator/VersionGLSL.h"
 
-static const int GLSL_VERSION_110 = 110;
-static const int GLSL_VERSION_120 = 120;
-static const int GLSL_VERSION_130 = 130;
-static const int GLSL_VERSION_410 = 410;
-static const int GLSL_VERSION_420 = 420;
+int ShaderOutputTypeToGLSLVersion(ShShaderOutput output)
+{
+    switch (output)
+    {
+      case SH_GLSL_130_OUTPUT:           return GLSL_VERSION_130;
+      case SH_GLSL_410_CORE_OUTPUT:      return GLSL_VERSION_410;
+      case SH_GLSL_420_CORE_OUTPUT:      return GLSL_VERSION_420;
+      case SH_GLSL_COMPATIBILITY_OUTPUT: return GLSL_VERSION_110;
+      default: UNREACHABLE();            return 0;
+    }
+}
 
 // We need to scan for the following:
 // 1. "invariant" keyword: This can occur in both - vertex and fragment shaders
@@ -34,32 +40,19 @@
                            ShShaderOutput output)
     : TIntermTraverser(true, false, false)
 {
-    if (output == SH_GLSL_130_OUTPUT)
+    mVersion = ShaderOutputTypeToGLSLVersion(output);
+    if (pragma.stdgl.invariantAll)
     {
-        mVersion = GLSL_VERSION_130;
-    }
-    else if (output == SH_GLSL_410_CORE_OUTPUT)
-    {
-        mVersion = GLSL_VERSION_410;
-    }
-    else if (output == SH_GLSL_420_CORE_OUTPUT)
-    {
-        mVersion = GLSL_VERSION_420;
-    }
-    else
-    {
-      ASSERT(output == SH_GLSL_COMPATIBILITY_OUTPUT);
-      if (pragma.stdgl.invariantAll)
-          mVersion = GLSL_VERSION_120;
-      else
-          mVersion = GLSL_VERSION_110;
+        ensureVersionIsAtLeast(GLSL_VERSION_120);
     }
 }
 
 void TVersionGLSL::visitSymbol(TIntermSymbol *node)
 {
     if (node->getSymbol() == "gl_PointCoord")
-        updateVersion(GLSL_VERSION_120);
+    {
+        ensureVersionIsAtLeast(GLSL_VERSION_120);
+    }
 }
 
 bool TVersionGLSL::visitAggregate(Visit, TIntermAggregate *node)
@@ -77,12 +70,12 @@
             const TIntermSequence &sequence = *(node->getSequence());
             if (sequence.front()->getAsTyped()->getType().isInvariant())
             {
-                updateVersion(GLSL_VERSION_120);
+                ensureVersionIsAtLeast(GLSL_VERSION_120);
             }
             break;
         }
       case EOpInvariantDeclaration:
-        updateVersion(GLSL_VERSION_120);
+        ensureVersionIsAtLeast(GLSL_VERSION_120);
         break;
       case EOpParameters:
         {
@@ -96,7 +89,7 @@
                     TQualifier qualifier = param->getQualifier();
                     if ((qualifier == EvqOut) || (qualifier ==  EvqInOut))
                     {
-                        updateVersion(GLSL_VERSION_120);
+                        ensureVersionIsAtLeast(GLSL_VERSION_120);
                         break;
                     }
                 }
@@ -115,7 +108,7 @@
                 TIntermTyped *typed = sequence.front()->getAsTyped();
                 if (typed && typed->isMatrix())
                 {
-                    updateVersion(GLSL_VERSION_120);
+                    ensureVersionIsAtLeast(GLSL_VERSION_120);
                 }
             }
             break;
@@ -127,7 +120,7 @@
     return visitChildren;
 }
 
-void TVersionGLSL::updateVersion(int version)
+void TVersionGLSL::ensureVersionIsAtLeast(int version)
 {
     mVersion = std::max(version, mVersion);
 }