Re-order the error generation for ES3 TexImage calls.

Explictly check if the internal format enum is ever valid before checking
if it is valid in combination with other parameters. Some WebGL tests
expect a certain order for generated errors.

BUG=angleproject:2009
TEST=conformance2/textures/misc/tex-input-validation

Change-Id: I31166a78d00629f8281ef53eced72575497ae448
Reviewed-on: https://chromium-review.googlesource.com/486099
Commit-Queue: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/validationES3.cpp b/src/libANGLE/validationES3.cpp
index 9070a15..7460d8d 100644
--- a/src/libANGLE/validationES3.cpp
+++ b/src/libANGLE/validationES3.cpp
@@ -32,9 +32,25 @@
 {
 
     // The type and format are valid if any supported internal format has that type and format
-    if (!ValidES3Format(format) || !ValidES3Type(type))
+    if (!ValidES3Format(format))
     {
-        context->handleError(Error(GL_INVALID_ENUM));
+        context->handleError(Error(GL_INVALID_ENUM, "Invalid format."));
+        return false;
+    }
+
+    if (!ValidES3Type(type))
+    {
+        context->handleError(Error(GL_INVALID_ENUM, "Invalid type."));
+        return false;
+    }
+
+    // For historical reasons, glTexImage2D and glTexImage3D pass in their internal format as a
+    // GLint instead of a GLenum. Therefor an invalid internal format gives a GL_INVALID_VALUE
+    // error instead of a GL_INVALID_ENUM error. As this validation function is only called in
+    // the validation codepaths for glTexImage2D/3D, we record a GL_INVALID_VALUE error.
+    if (!ValidES3InternalFormat(internalFormat))
+    {
+        context->handleError(Error(GL_INVALID_VALUE, "Invalid internalFormat."));
         return false;
     }
 
@@ -51,21 +67,18 @@
         return false;
     }
 
-    // For historical reasons, glTexImage2D and glTexImage3D pass in their internal format as a
-    // GLint instead of a GLenum. Therefor an invalid internal format gives a GL_INVALID_VALUE
-    // error instead of a GL_INVALID_ENUM error. As this validation function is only called in
-    // the validation codepaths for glTexImage2D/3D, we record a GL_INVALID_VALUE error.
-    const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat, type);
-    if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions()))
-    {
-        context->handleError(Error(GL_INVALID_VALUE));
-        return false;
-    }
-
     // Check if this is a valid format combination to load texture data
     if (!ValidES3FormatCombination(format, type, internalFormat))
     {
-        context->handleError(Error(GL_INVALID_OPERATION));
+        context->handleError(
+            Error(GL_INVALID_OPERATION, "Invalid combination of format, type and internalFormat."));
+        return false;
+    }
+
+    const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat, type);
+    if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions()))
+    {
+        context->handleError(Error(GL_INVALID_VALUE, "Unsupported internal format."));
         return false;
     }