Allow sized GL_RGB[A]_32F to be used for TexImage2D with the chromium extensions.

GL_CHROMIUM_color_buffer_float_rgb[a] allows these sized formats to be
used in TexImage2D even in ES2.  With this patch, the
conformance/extensions/oes-texture-float and
conformance/extensions/oes-texture-half-float tests now pass for WebGL1
and WebGL 2 contexts.

BUG=angleproject:1958

Change-Id: I568dea5da42ba310463d2690c3e764c48598311b
Reviewed-on: https://chromium-review.googlesource.com/522349
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libANGLE/validationES2.cpp b/src/libANGLE/validationES2.cpp
index 8ec453d..9bcf646 100644
--- a/src/libANGLE/validationES2.cpp
+++ b/src/libANGLE/validationES2.cpp
@@ -843,7 +843,16 @@
         return false;
     }
 
-    if (!isSubImage && !isCompressed && internalformat != format)
+    // From GL_CHROMIUM_color_buffer_float_rgb[a]:
+    // GL_RGB[A] / GL_RGB[A]32F becomes an allowable format / internalformat parameter pair for
+    // TexImage2D. The restriction in section 3.7.1 of the OpenGL ES 2.0 spec that the
+    // internalformat parameter and format parameter of TexImage2D must match is lifted for this
+    // case.
+    bool nonEqualFormatsAllowed =
+        (internalformat == GL_RGB32F && context->getExtensions().colorBufferFloatRGB) ||
+        (internalformat == GL_RGBA32F && context->getExtensions().colorBufferFloatRGBA);
+
+    if (!isSubImage && !isCompressed && internalformat != format && !nonEqualFormatsAllowed)
     {
         context->handleError(Error(GL_INVALID_OPERATION));
         return false;
@@ -1260,6 +1269,59 @@
                 break;
         }
 
+        if (!isSubImage)
+        {
+            switch (internalformat)
+            {
+                case GL_RGBA32F:
+                    if (!context->getExtensions().colorBufferFloatRGBA)
+                    {
+                        context->handleError(Error(GL_INVALID_VALUE,
+                                                   "Sized GL_RGBA32F internal format requires "
+                                                   "GL_CHROMIUM_color_buffer_float_rgba"));
+                        return false;
+                    }
+                    if (type != GL_FLOAT)
+                    {
+                        context->handleError(Error(GL_INVALID_OPERATION,
+                                                   "Invalid internal format/type combination"));
+                        return false;
+                    }
+                    if (format != GL_RGBA)
+                    {
+                        context->handleError(Error(GL_INVALID_OPERATION,
+                                                   "Invalid internal format/format combination"));
+                        return false;
+                    }
+                    break;
+
+                case GL_RGB32F:
+                    if (!context->getExtensions().colorBufferFloatRGB)
+                    {
+                        context->handleError(Error(GL_INVALID_VALUE,
+                                                   "Sized GL_RGB32F internal format requires "
+                                                   "GL_CHROMIUM_color_buffer_float_rgb"));
+                        return false;
+                    }
+                    if (type != GL_FLOAT)
+                    {
+                        context->handleError(Error(GL_INVALID_OPERATION,
+                                                   "Invalid internal format/type combination"));
+                        return false;
+                    }
+                    if (format != GL_RGB)
+                    {
+                        context->handleError(Error(GL_INVALID_OPERATION,
+                                                   "Invalid internal format/format combination"));
+                        return false;
+                    }
+                    break;
+
+                default:
+                    break;
+            }
+        }
+
         if (type == GL_FLOAT)
         {
             if (!context->getExtensions().textureFloat)