Re-implement GL_APPLE_texture_format_BGRA8888.

GL_APPLE_texture_format_BGRA8888 specifies that when using the BGRA_EXT
format, it "must have an RGBA internal format". Note that
GL_EXT_texture_format_BGRA8888 also allows BGRA_EXT as internalformat.

Change-Id: I27e032054240efe96c32e27ebbdfb3c28213b1d8
Reviewed-on: https://swiftshader-review.googlesource.com/16248
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/OpenGL/libGLESv2/libGLESv2.cpp b/src/OpenGL/libGLESv2/libGLESv2.cpp
index 93f8e4c..9ac2e58 100644
--- a/src/OpenGL/libGLESv2/libGLESv2.cpp
+++ b/src/OpenGL/libGLESv2/libGLESv2.cpp
@@ -4953,6 +4953,14 @@
 
 	if(context)
 	{
+		// Core OpenGL ES 2.0 requires format and internalformat to be equal (checked below),
+		// but GL_APPLE_texture_format_BGRA8888 allows (only) GL_BGRA_EXT / GL_RGBA, while
+		// GL_EXT_texture_format_BGRA8888 also allows GL_BGRA_EXT / GL_BGRA_EXT.
+		if(format == GL_BGRA_EXT && internalformat == GL_RGBA)
+		{
+			internalformat = GL_BGRA_EXT;
+		}
+
 		GLint clientVersion = context->getClientVersion();
 		if(clientVersion < 3)
 		{