Fix bugs with drawbuffer state.

 * IsAttachmentEnabled was checking the wrong draw buffer state.  Instead
   of checking that drawbuffer[colorAttachment] is in use, it should have
   been scanning for a drawbuffer state that points to colorAttachment.
 * Allow for maxDrawBuffer != maxColorAttachments.  Tested by the GL
   backend on some systems that don't have the draw buffers extension.

Fixed by updating the helpers and adding a new getDrawBuffer helper.

BUG=angleproject:1121

Change-Id: Idd1b0a9ec4a3f944d332c708364408bf5d59e1fd
Reviewed-on: https://chromium-review.googlesource.com/292740
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Tryjob-Request: Geoff Lang <geofflang@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libANGLE/validationES.cpp b/src/libANGLE/validationES.cpp
index 66b988a..745f342 100644
--- a/src/libANGLE/validationES.cpp
+++ b/src/libANGLE/validationES.cpp
@@ -682,11 +682,14 @@
             GLenum readInternalFormat = readColorBuffer->getInternalFormat();
             const InternalFormat &readFormatInfo = GetInternalFormatInfo(readInternalFormat);
 
-            for (size_t i = 0; i < drawFramebuffer->getNumColorBuffers(); i++)
+            for (size_t drawbufferIdx = 0;
+                 drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx)
             {
-                if (drawFramebuffer->isEnabledColorAttachment(i))
+                const FramebufferAttachment *attachment =
+                    drawFramebuffer->getDrawBuffer(drawbufferIdx);
+                if (attachment)
                 {
-                    GLenum drawInternalFormat = drawFramebuffer->getColorbuffer(i)->getInternalFormat();
+                    GLenum drawInternalFormat            = attachment->getInternalFormat();
                     const InternalFormat &drawFormatInfo = GetInternalFormatInfo(drawInternalFormat);
 
                     // The GL ES 3.0.2 spec (pg 193) states that: