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
parent f3a3eda7
...@@ -1564,8 +1564,9 @@ bool Context::getIntegerv(GLenum pname, GLint *params) ...@@ -1564,8 +1564,9 @@ bool Context::getIntegerv(GLenum pname, GLint *params)
case GL_IMPLEMENTATION_COLOR_READ_TYPE: case GL_IMPLEMENTATION_COLOR_READ_TYPE:
case GL_IMPLEMENTATION_COLOR_READ_FORMAT: case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
{ {
GLint internalFormat;
GLenum format, type; GLenum format, type;
if (getCurrentReadFormatType(&format, &type)) if (getCurrentReadFormatType(&internalFormat, &format, &type))
{ {
if (pname == GL_IMPLEMENTATION_COLOR_READ_FORMAT) if (pname == GL_IMPLEMENTATION_COLOR_READ_FORMAT)
*params = format; *params = format;
...@@ -2611,7 +2612,7 @@ float Context::getTextureMaxAnisotropy() const ...@@ -2611,7 +2612,7 @@ float Context::getTextureMaxAnisotropy() const
return mMaxTextureAnisotropy; return mMaxTextureAnisotropy;
} }
bool Context::getCurrentReadFormatType(GLenum *format, GLenum *type) bool Context::getCurrentReadFormatType(GLint *internalFormat, GLenum *format, GLenum *type)
{ {
Framebuffer *framebuffer = getReadFramebuffer(); Framebuffer *framebuffer = getReadFramebuffer();
if (!framebuffer || framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) if (!framebuffer || framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
...@@ -2625,6 +2626,7 @@ bool Context::getCurrentReadFormatType(GLenum *format, GLenum *type) ...@@ -2625,6 +2626,7 @@ bool Context::getCurrentReadFormatType(GLenum *format, GLenum *type)
return gl::error(GL_INVALID_OPERATION, false); return gl::error(GL_INVALID_OPERATION, false);
} }
*internalFormat = renderbuffer->getActualFormat();
*format = gl::GetFormat(renderbuffer->getActualFormat(), mClientVersion); *format = gl::GetFormat(renderbuffer->getActualFormat(), mClientVersion);
*type = gl::GetType(renderbuffer->getActualFormat(), mClientVersion); *type = gl::GetType(renderbuffer->getActualFormat(), mClientVersion);
......
...@@ -457,7 +457,7 @@ class Context ...@@ -457,7 +457,7 @@ class Context
bool supportsInstancing() const; bool supportsInstancing() const;
bool supportsTextureFilterAnisotropy() const; bool supportsTextureFilterAnisotropy() const;
bool getCurrentReadFormatType(GLenum *format, GLenum *type); bool getCurrentReadFormatType(GLint *internalFormat, GLenum *format, GLenum *type);
float getTextureMaxAnisotropy() const; float getTextureMaxAnisotropy() const;
......
...@@ -1205,7 +1205,7 @@ bool validateES3CopyTexImageParameters(gl::Context *context, GLenum target, GLin ...@@ -1205,7 +1205,7 @@ bool validateES3CopyTexImageParameters(gl::Context *context, GLenum target, GLin
} }
// check for combinations of format and type that are valid for ReadPixels // 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) switch (format)
{ {
...@@ -1235,6 +1235,52 @@ bool validReadFormatType(GLenum format, GLenum type) ...@@ -1235,6 +1235,52 @@ bool validReadFormatType(GLenum format, GLenum type)
return true; 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, bool validateInvalidateFramebufferParameters(gl::Context *context, GLenum target, GLsizei numAttachments,
const GLenum* attachments) const GLenum* attachments)
{ {
...@@ -5725,15 +5771,19 @@ void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height, ...@@ -5725,15 +5771,19 @@ void __stdcall glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
if (context) if (context)
{ {
GLint currentInternalFormat;
GLenum currentFormat, currentType; GLenum currentFormat, currentType;
// Failure in getCurrentReadFormatType indicates that no color attachment is currently bound, // 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 // and attempting to read back if that's the case is an error. The error will be registered
// by getCurrentReadFormat. // by getCurrentReadFormat.
if (!context->getCurrentReadFormatType(&currentFormat, &currentType)) if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
return; 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); return gl::error(GL_INVALID_OPERATION);
} }
...@@ -5765,15 +5815,19 @@ void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, ...@@ -5765,15 +5815,19 @@ void __stdcall glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
if (context) if (context)
{ {
GLint currentInternalFormat;
GLenum currentFormat, currentType; GLenum currentFormat, currentType;
// Failure in getCurrentReadFormatType indicates that no color attachment is currently bound, // 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 // and attempting to read back if that's the case is an error. The error will be registered
// by getCurrentReadFormat. // by getCurrentReadFormat.
if (!context->getCurrentReadFormatType(&currentFormat, &currentType)) if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
return; 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); return gl::error(GL_INVALID_OPERATION);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment