Adds support for per-framebuffer IMPLEMENTATION_COLOR_READ_FORMAT and TYPE

TRAC #21607

Signed-off-by: Nicolas Capens
Signed-off-by: Daniel Koch

Author:    Shannon Woods

git-svn-id: https://angleproject.googlecode.com/svn/trunk@1283 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libGLESv2/libGLESv2.cpp b/src/libGLESv2/libGLESv2.cpp
index 40a7067..62bf20f 100644
--- a/src/libGLESv2/libGLESv2.cpp
+++ b/src/libGLESv2/libGLESv2.cpp
@@ -247,15 +247,6 @@
             return false;
         }
         break;
-      case gl::IMPLEMENTATION_COLOR_READ_FORMAT:
-        switch (type)
-        {
-          case gl::IMPLEMENTATION_COLOR_READ_TYPE:
-            break;
-          default:
-            return false;
-        }
-        break;
       default:
         return false;
     }
@@ -4720,15 +4711,23 @@
             return error(GL_INVALID_VALUE);
         }
 
-        if (!validReadFormatType(format, type))
-        {
-            return error(GL_INVALID_OPERATION);
-        }
-
         gl::Context *context = gl::getNonLostContext();
 
         if (context)
         {
+            GLenum currentFormat, currentType;
+    
+            // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
+            // and attempting to read back if that's the case is an error. The error will be registered
+            // by getCurrentReadFormat.
+            if (!context->getCurrentReadFormatType(&currentFormat, &currentType))
+                return;
+
+            if (!(currentFormat == format && currentType == type) && !validReadFormatType(format, type))
+            {
+                return error(GL_INVALID_OPERATION);
+            }
+
             context->readPixels(x, y, width, height, format, type, &bufSize, data);
         }
     }
@@ -4752,15 +4751,23 @@
             return error(GL_INVALID_VALUE);
         }
 
-        if (!validReadFormatType(format, type))
-        {
-            return error(GL_INVALID_OPERATION);
-        }
-
         gl::Context *context = gl::getNonLostContext();
 
         if (context)
         {
+            GLenum currentFormat, currentType;
+    
+            // Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
+            // and attempting to read back if that's the case is an error. The error will be registered
+            // by getCurrentReadFormat.
+            if (!context->getCurrentReadFormatType(&currentFormat, &currentType))
+                return;
+
+            if (!(currentFormat == format && currentType == type) && !validReadFormatType(format, type))
+            {
+                return error(GL_INVALID_OPERATION);
+            }
+
             context->readPixels(x, y, width, height, format, type, NULL, pixels);
         }
     }