Fixed validation errors in teximage3d and friends.

BUG=angleproject:1169
BUG=angleproject:1101

Change-Id: I3770335d04cafd652c2f3839afca3e4a854e6e76
Reviewed-on: https://chromium-review.googlesource.com/322381
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tryjob-Request: Jamie Madill <jmadill@chromium.org>
Tested-by: Ian Ewell <ewell@google.com>
diff --git a/src/libANGLE/validationES.cpp b/src/libANGLE/validationES.cpp
index 3c34564..66b988a 100644
--- a/src/libANGLE/validationES.cpp
+++ b/src/libANGLE/validationES.cpp
@@ -123,7 +123,7 @@
     }
 }
 
-bool ValidTextureTarget(const Context *context, GLenum target)
+bool ValidTextureTarget(const ValidationContext *context, GLenum target)
 {
     switch (target)
     {
@@ -140,6 +140,32 @@
     }
 }
 
+bool ValidTexture2DTarget(const ValidationContext *context, GLenum target)
+{
+    switch (target)
+    {
+        case GL_TEXTURE_2D:
+        case GL_TEXTURE_CUBE_MAP:
+            return true;
+
+        default:
+            return false;
+    }
+}
+
+bool ValidTexture3DTarget(const ValidationContext *context, GLenum target)
+{
+    switch (target)
+    {
+        case GL_TEXTURE_3D:
+        case GL_TEXTURE_2D_ARRAY:
+            return (context->getClientVersion() >= 3);
+
+        default:
+            return false;
+    }
+}
+
 // This function differs from ValidTextureTarget in that the target must be
 // usable as the destination of a 2D operation-- so a cube face is valid, but
 // GL_TEXTURE_CUBE_MAP is not.
@@ -156,9 +182,18 @@
       case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
       case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
         return true;
-      case GL_TEXTURE_2D_ARRAY:
+      default:
+          return false;
+    }
+}
+
+bool ValidTexture3DDestinationTarget(const ValidationContext *context, GLenum target)
+{
+    switch (target)
+    {
       case GL_TEXTURE_3D:
-        return (context->getClientVersion() >= 3);
+      case GL_TEXTURE_2D_ARRAY:
+          return true;
       default:
         return false;
     }
@@ -1315,13 +1350,6 @@
                                         GLint border,
                                         GLenum *textureFormatOut)
 {
-
-    if (!ValidTexture2DDestinationTarget(context, target))
-    {
-        context->recordError(Error(GL_INVALID_ENUM));
-        return false;
-    }
-
     if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
     {
         context->recordError(Error(GL_INVALID_VALUE));
@@ -2272,8 +2300,8 @@
     }
 
     ASSERT(context->getClientVersion() == 3);
-    return ValidateES3CopyTexImageParameters(context, target, level, internalformat, false, 0, 0, 0,
-                                             x, y, width, height, border);
+    return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0,
+                                               0, x, y, width, height, border);
 }
 
 bool ValidateFramebufferRenderbuffer(Context *context,
@@ -2374,8 +2402,8 @@
                                                  yoffset, x, y, width, height, 0);
     }
 
-    return ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset,
-                                             yoffset, 0, x, y, width, height, 0);
+    return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset,
+                                               yoffset, 0, x, y, width, height, 0);
 }
 
 }  // namespace gl