Added ES3 validation for glReadPixels and glReadnPixelsEXT.
TRAC #22956
Signed-off-by: Jamie Madill
Signed-off-by: Shannon Woods
Author: Geoff Lang
git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2355 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libGLESv2/Context.cpp b/src/libGLESv2/Context.cpp
index a490408..b1461fe 100644
--- a/src/libGLESv2/Context.cpp
+++ b/src/libGLESv2/Context.cpp
@@ -1564,8 +1564,9 @@
case GL_IMPLEMENTATION_COLOR_READ_TYPE:
case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
{
+ GLint internalFormat;
GLenum format, type;
- if (getCurrentReadFormatType(&format, &type))
+ if (getCurrentReadFormatType(&internalFormat, &format, &type))
{
if (pname == GL_IMPLEMENTATION_COLOR_READ_FORMAT)
*params = format;
@@ -2611,7 +2612,7 @@
return mMaxTextureAnisotropy;
}
-bool Context::getCurrentReadFormatType(GLenum *format, GLenum *type)
+bool Context::getCurrentReadFormatType(GLint *internalFormat, GLenum *format, GLenum *type)
{
Framebuffer *framebuffer = getReadFramebuffer();
if (!framebuffer || framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
@@ -2625,6 +2626,7 @@
return gl::error(GL_INVALID_OPERATION, false);
}
+ *internalFormat = renderbuffer->getActualFormat();
*format = gl::GetFormat(renderbuffer->getActualFormat(), mClientVersion);
*type = gl::GetType(renderbuffer->getActualFormat(), mClientVersion);
diff --git a/src/libGLESv2/Context.h b/src/libGLESv2/Context.h
index 1c028e4..ed7ca51 100644
--- a/src/libGLESv2/Context.h
+++ b/src/libGLESv2/Context.h
@@ -457,7 +457,7 @@
bool supportsInstancing() const;
bool supportsTextureFilterAnisotropy() const;
- bool getCurrentReadFormatType(GLenum *format, GLenum *type);
+ bool getCurrentReadFormatType(GLint *internalFormat, GLenum *format, GLenum *type);
float getTextureMaxAnisotropy() const;
diff --git a/src/libGLESv2/libGLESv2.cpp b/src/libGLESv2/libGLESv2.cpp
index a615c16..ed30736 100644
--- a/src/libGLESv2/libGLESv2.cpp
+++ b/src/libGLESv2/libGLESv2.cpp
@@ -1205,7 +1205,7 @@
}
// check for combinations of format and type that are valid for ReadPixels
-bool validReadFormatType(GLenum format, GLenum type)
+bool validES2ReadFormatType(GLenum format, GLenum type)
{
switch (format)
{
@@ -1235,6 +1235,52 @@
return true;
}
+bool validES3ReadFormatType(GLenum internalFormat, GLenum format, GLenum type)
+{
+ switch (format)
+ {
+ case GL_RGBA:
+ switch (type)
+ {
+ case GL_UNSIGNED_BYTE:
+ break;
+ case GL_UNSIGNED_INT_2_10_10_10_REV:
+ if (internalFormat != GL_RGB10_A2)
+ {
+ return false;
+ }
+ break;
+ default:
+ return false;
+ }
+ break;
+ case GL_RGBA_INTEGER:
+ switch (type)
+ {
+ case GL_INT:
+ case GL_UNSIGNED_INT:
+ break;
+ default:
+ return false;
+ }
+ break;
+ case GL_BGRA_EXT:
+ switch (type)
+ {
+ case GL_UNSIGNED_BYTE:
+ case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
+ case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
+ break;
+ default:
+ return false;
+ }
+ break;
+ default:
+ return false;
+ }
+ return true;
+}
+
bool validateInvalidateFramebufferParameters(gl::Context *context, GLenum target, GLsizei numAttachments,
const GLenum* attachments)
{
@@ -5725,15 +5771,19 @@
if (context)
{
+ GLint currentInternalFormat;
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(¤tFormat, ¤tType))
+ if (!context->getCurrentReadFormatType(¤tInternalFormat, ¤tFormat, ¤tType))
return;
- if (!(currentFormat == format && currentType == type) && !validReadFormatType(format, type))
+ bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
+ validES3ReadFormatType(currentInternalFormat, format, type);
+
+ if (!(currentFormat == format && currentType == type) && !validReadFormat)
{
return gl::error(GL_INVALID_OPERATION);
}
@@ -5765,15 +5815,19 @@
if (context)
{
+ GLint currentInternalFormat;
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(¤tFormat, ¤tType))
+ if (!context->getCurrentReadFormatType(¤tInternalFormat, ¤tFormat, ¤tType))
return;
- if (!(currentFormat == format && currentType == type) && !validReadFormatType(format, type))
+ bool validReadFormat = (context->getClientVersion() < 3) ? validES2ReadFormatType(format, type) :
+ validES3ReadFormatType(currentInternalFormat, format, type);
+
+ if (!(currentFormat == format && currentType == type) && !validReadFormat)
{
return gl::error(GL_INVALID_OPERATION);
}