opengles emulator: forced GLSL version to be 120.

GLSL ES 1.0.17 spec states that its written against
OpenGL GLSL version 1.2, that means that #version 100
in GLSL ES should be mapped to #version 120 in OpenGL
GLSL.
We now force "$version 120" in all shaders except if
higher version has been requested in the shader source
or when GOOGLE_GLES_FORCE_GLSL_VERSION is defines.
(Note that GOOGLE_GLES_DEFAULT_GLSL_VERSION is renamed
 to GOOGLE_GLES_FORCE_GLSL_VERSION).

That fixes "Aqua Slash GL Demo" application !!

Change-Id: I0f61ba3aa1c5591df3dacd3afd7f216dba13b56e
diff --git a/tools/emulator/opengl/host/libs/Translator/GLES_V2/ShaderParser.cpp b/tools/emulator/opengl/host/libs/Translator/GLES_V2/ShaderParser.cpp
index 6c9d1fe..2f27639 100644
--- a/tools/emulator/opengl/host/libs/Translator/GLES_V2/ShaderParser.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/GLES_V2/ShaderParser.cpp
@@ -58,7 +58,8 @@
     // That token should be the first non-comment or blank token
     //
     const char *src = m_src.c_str();
-    int glslVersion = 0;
+    const int minGLSLVersion = 120;
+    int glslVersion = minGLSLVersion;
     enum {
         PARSE_NONE,
         PARSE_IN_C_COMMENT,
@@ -98,16 +99,8 @@
             // token does not exist in this shader source.
             //
             if (!strncmp(c,"#version",8)) {
-                if (sscanf(c+8,"%d",&glslVersion) != 1) {
-                    //
-                    // #version found but failed to parse the version value!
-                    // this must be an error, set glslVersion to -1 to flag
-                    // that we do not want to override the version, just let
-                    // the shader compiler handle it.
-                    //
-                    glslVersion = -1;
-                }
-                else {
+                int ver;
+                if (sscanf(c+8,"%d",&ver) == 1) {
                     //
                     // parsed version string correctly, blank out the
                     // version token from the source, we will add it later at
@@ -117,6 +110,10 @@
                     for (int i=0; i<8; i++,cc++) *cc = ' ';
                     while (*cc < '0' || *cc > '9') { *cc = ' '; cc++; }
                     while (*cc >= '0' && *cc <= '9') { *cc = ' '; cc++; }
+
+                    // Use the version from the source but only if
+                    // it is larger than our minGLSLVersion
+                    if (ver > minGLSLVersion) glslVersion = ver;
                 }
             }
 
@@ -127,16 +124,13 @@
     }
 
     //
-    // if no version token found, check if default glsl version
-    // has been requested through environment variable.
+    // allow to force GLSL version through environment variable
     //
-    if (glslVersion == 0) {
-        const char *defVersion = getenv("GOOGLE_GLES_DEFAULT_GLSL_VERSION");
-        if (defVersion) {
-            if (sscanf(defVersion,"%d",&glslVersion) != 1) {
-                fprintf(stderr,"Wrong value to GOOGLE_GLES_DEFAULT_GLSL_VERSION, should be an integer\n");
-                glslVersion = 0;
-            }
+    const char *forceVersion = getenv("GOOGLE_GLES_FORCE_GLSL_VERSION");
+    if (forceVersion) {
+        int ver;
+        if (sscanf(forceVersion,"%d",&ver) == 1) {
+            glslVersion = ver;
         }
     }