Move more draw call validation to the API.

The GL expects us to reject invalid draw calls before we start
doing any work, so we can prevent internal unnecessary state
changes.

Also update the program binary's cached sampler data when we
validate. The previous patch was breaking draw calls in Google
Earth WebGL.

BUG=angle:571
BUG=390412

Change-Id: I1c4e204ae2467afc36b76af975a3a49e26349639
Reviewed-on: https://chromium-review.googlesource.com/206482
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libGLESv2/validationES.cpp b/src/libGLESv2/validationES.cpp
index 2324a4b..6ee4cae 100644
--- a/src/libGLESv2/validationES.cpp
+++ b/src/libGLESv2/validationES.cpp
@@ -19,6 +19,7 @@
 #include "libGLESv2/Query.h"
 #include "libGLESv2/ProgramBinary.h"
 #include "libGLESv2/TransformFeedback.h"
+#include "libGLESv2/VertexArray.h"
 
 #include "common/mathutil.h"
 #include "common/utilities.h"
@@ -1346,6 +1347,17 @@
         return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
     }
 
+    if (!context->getCurrentProgram())
+    {
+        return gl::error(GL_INVALID_OPERATION, false);
+    }
+
+    gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
+    if (!programBinary->validateSamplers(NULL))
+    {
+        return gl::error(GL_INVALID_OPERATION, false);
+    }
+
     // No-op if zero count
     return (count > 0);
 }
@@ -1422,6 +1434,12 @@
         return gl::error(GL_INVALID_OPERATION, false);
     }
 
+    gl::VertexArray *vao = context->getCurrentVertexArray();
+    if (!indices && !vao->getElementArrayBuffer())
+    {
+        return gl::error(GL_INVALID_OPERATION, false);
+    }
+
     if (!ValidateDrawBase(context, mode, count))
     {
         return false;