[Mesa-dev] [PATCH 15/23] readpix: add error checking for GLES3

Jordan Justen jordan.l.justen at intel.com
Fri Jan 4 18:41:38 PST 2013


Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
---
 src/mesa/main/readpix.c |   54 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c
index 8e99bfb..8b1113c 100644
--- a/src/mesa/main/readpix.c
+++ b/src/mesa/main/readpix.c
@@ -679,12 +679,57 @@ _mesa_readpixels(struct gl_context *ctx,
 }
 
 
+static GLenum
+read_pixels_es3_error_check(GLenum format, GLenum type,
+                            GLenum internalFormat)
+{
+   GLboolean is_unsigned_int = GL_FALSE;
+   GLboolean is_signed_int = GL_FALSE;
+
+   if (!_mesa_is_color_format(internalFormat)) {
+      return GL_INVALID_OPERATION;
+   }
+
+   is_unsigned_int = _mesa_is_enum_format_unsigned_int(internalFormat);
+   if (!is_unsigned_int) {
+      is_signed_int = _mesa_is_enum_format_signed_int(internalFormat);
+   }
+
+   switch (format) {
+   case GL_RGBA:
+      if (type == GL_UNSIGNED_BYTE)
+         return GL_NO_ERROR;
+      if (internalFormat == GL_RGB10_A2 &&
+          type == GL_UNSIGNED_INT_2_10_10_10_REV)
+         return GL_NO_ERROR;
+      if (internalFormat == GL_RGB10_A2UI && type == GL_UNSIGNED_BYTE)
+         return GL_NO_ERROR;
+      break;
+   case GL_BGRA:
+      /* GL_EXT_read_format_bgra */
+      if (type == GL_UNSIGNED_BYTE ||
+          type == GL_UNSIGNED_SHORT_4_4_4_4_REV ||
+          type == GL_UNSIGNED_SHORT_1_5_5_5_REV)
+         return GL_NO_ERROR;
+      break;
+   case GL_RGBA_INTEGER:
+      if ((is_signed_int && type == GL_INT) ||
+          (is_unsigned_int && type == GL_UNSIGNED_INT))
+         return GL_NO_ERROR;
+      break;
+   }
+
+   return GL_INVALID_OPERATION;
+}
+
+
 void GLAPIENTRY
 _mesa_ReadnPixelsARB( GLint x, GLint y, GLsizei width, GLsizei height,
 		      GLenum format, GLenum type, GLsizei bufSize,
                       GLvoid *pixels )
 {
    GLenum err = GL_NO_ERROR;
+   struct gl_renderbuffer *rb;
 
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
@@ -704,6 +749,13 @@ _mesa_ReadnPixelsARB( GLint x, GLint y, GLsizei width, GLsizei height,
       return;
    }
 
+   rb = _mesa_get_read_renderbuffer(ctx, format);
+   if (rb == NULL) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glReadPixels(read buffer)");
+      return;
+   }
+
    /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
     * combinations of format and type that can be used.
     *
@@ -720,6 +772,8 @@ _mesa_ReadnPixelsARB( GLint x, GLint y, GLsizei width, GLsizei height,
                err = GL_INVALID_OPERATION;
             }
          }
+      } else {
+         err = read_pixels_es3_error_check(format, type, rb->InternalFormat);
       }
 
       if (err == GL_NO_ERROR && (format == GL_DEPTH_COMPONENT
-- 
1.7.10.4



More information about the mesa-dev mailing list