Validate program changes wrt transform feedback

UseProgram can't be called while transform feedback is active and
unpaused. Validate this by checking the presence of active transform
feedback in UseProgram.

LinkProgram or ProgramBinary can't be called while transform feedback
associated with the program is active. Validate this by going through
all of the existing transform feedback objects when one of these
functions is called and checking whether they are associated with the
program being changed. A program association is added to
gl::TransformFeedback to facilitate this.

BeginTransformFeedback can't be used to unpause a transform feedback
object, so code for that is removed.

The validation of the entry points touched in this patch is refactored
to follow the current convention of separate Validate* functions,
though with LinkProgram following this convention fully isn't
practical.

This patch also makes sure that ANGLE doesn't invoke behavior that the
GL spec doesn't specify if a program object associated with a paused
transform feedback is deleted.

Tests are edited so that they don't call UseProgram when it generates
an error.

BUG=angleproject:1101
TEST=dEQP-GLES3.functional.negative_api.shader.* (2 more tests pass),
     dEQP-GLES3.functional.transform_feedback.* (no regressions),
     angle_end2end_tests

Change-Id: I2e5b3a027ced11249b762ec01a29fa41d2c0dd96
Reviewed-on: https://chromium-review.googlesource.com/332141
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/libANGLE/validationES.cpp b/src/libANGLE/validationES.cpp
index 09471a7..a994a9d 100644
--- a/src/libANGLE/validationES.cpp
+++ b/src/libANGLE/validationES.cpp
@@ -2423,6 +2423,19 @@
     return true;
 }
 
+bool ValidateLinkProgram(Context *context, GLuint program)
+{
+    if (context->hasActiveTransformFeedback(program))
+    {
+        // ES 3.0.4 section 2.15 page 91
+        context->recordError(Error(GL_INVALID_OPERATION,
+                                   "Cannot link program while program is associated with an active "
+                                   "transform feedback object."));
+        return false;
+    }
+    return true;
+}
+
 bool ValidateProgramBinaryBase(Context *context,
                                GLuint program,
                                GLenum binaryFormat,
@@ -2443,6 +2456,15 @@
         return false;
     }
 
+    if (context->hasActiveTransformFeedback(program))
+    {
+        // ES 3.0.4 section 2.15 page 91
+        context->recordError(Error(GL_INVALID_OPERATION,
+                                   "Cannot change program binary while program is associated with "
+                                   "an active transform feedback object."));
+        return false;
+    }
+
     return true;
 }
 
@@ -2468,6 +2490,45 @@
     return true;
 }
 
+bool ValidateUseProgram(Context *context, GLuint program)
+{
+    if (program != 0)
+    {
+        Program *programObject = context->getProgram(program);
+        if (!programObject)
+        {
+            // ES 3.1.0 section 7.3 page 72
+            if (context->getShader(program))
+            {
+                context->recordError(
+                    Error(GL_INVALID_OPERATION,
+                          "Attempted to use a single shader instead of a shader program."));
+                return false;
+            }
+            else
+            {
+                context->recordError(Error(GL_INVALID_VALUE, "Program invalid."));
+                return false;
+            }
+        }
+        if (!programObject->isLinked())
+        {
+            context->recordError(Error(GL_INVALID_OPERATION, "Program not linked."));
+            return false;
+        }
+    }
+    if (context->getState().isTransformFeedbackActiveUnpaused())
+    {
+        // ES 3.0.4 section 2.15 page 91
+        context->recordError(
+            Error(GL_INVALID_OPERATION,
+                  "Cannot change active program while transform feedback is unpaused."));
+        return false;
+    }
+
+    return true;
+}
+
 bool ValidateCopyTexImage2D(ValidationContext *context,
                             GLenum target,
                             GLint level,