Mesa (master): mesa: fix some incorrect error checks in _mesa_error_check_format_type()

Brian Paul brianp at kemper.freedesktop.org
Fri Aug 7 15:52:19 UTC 2009


Module: Mesa
Branch: master
Commit: 2dec62405f9e2e46997046a32211f25ba83d2600
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=2dec62405f9e2e46997046a32211f25ba83d2600

Author: Brian Paul <brianp at vmware.com>
Date:   Fri Aug  7 09:18:04 2009 -0600

mesa: fix some incorrect error checks in _mesa_error_check_format_type()

Plus, simplify the code a bit.

---

 src/mesa/main/readpix.c |   51 +++++++++++++++++++++++++++++++---------------
 1 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c
index 2326776..1753570 100644
--- a/src/mesa/main/readpix.c
+++ b/src/mesa/main/readpix.c
@@ -44,6 +44,10 @@ _mesa_error_check_format_type(GLcontext *ctx, GLenum format, GLenum type,
                               GLboolean drawing)
 {
    const char *readDraw = drawing ? "Draw" : "Read";
+   const GLboolean reading = !drawing;
+
+   /* state validation should have already been done */
+   ASSERT(ctx->NewState == 0x0);
 
    if (ctx->Extensions.EXT_packed_depth_stencil
        && type == GL_UNSIGNED_INT_24_8_EXT
@@ -73,32 +77,45 @@ _mesa_error_check_format_type(GLcontext *ctx, GLenum format, GLenum type,
    case GL_RGBA:
    case GL_BGRA:
    case GL_ABGR_EXT:
-      if (drawing && !ctx->Visual.rgbMode) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
+      if (drawing) {
+         if (!ctx->DrawBuffer->Visual.rgbMode) {
+            _mesa_error(ctx, GL_INVALID_OPERATION,
                    "glDrawPixels(drawing RGB pixels into color index buffer)");
-         return GL_TRUE;
+            return GL_TRUE;
+         }
       }
-      if (!drawing && !_mesa_dest_buffer_exists(ctx, GL_COLOR)) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glReadPixels(no color buffer)");
-         return GL_TRUE;
+      else {
+         /* reading */
+         if (!_mesa_source_buffer_exists(ctx, GL_COLOR)) {
+            _mesa_error(ctx, GL_INVALID_OPERATION,
+                        "glReadPixels(no color buffer)");
+            return GL_TRUE;
+         }
       }
       break;
    case GL_COLOR_INDEX:
-      if (!drawing && ctx->Visual.rgbMode) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                    "glReadPixels(reading color index format from RGB buffer)");
-         return GL_TRUE;
+      if (drawing) {
+         if (ctx->DrawBuffer->Visual.rgbMode &&
+             (ctx->PixelMaps.ItoR.Size == 0 ||
+              ctx->PixelMaps.ItoG.Size == 0 ||
+              ctx->PixelMaps.ItoB.Size == 0)) {
+            _mesa_error(ctx, GL_INVALID_OPERATION,
+                   "glDrawPixels(drawing color index pixels into RGB buffer)");
+            return GL_TRUE;
+         }
       }
-      if (!drawing && !_mesa_dest_buffer_exists(ctx, GL_COLOR)) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glReadPixels(no color buffer)");
-         return GL_TRUE;
+      else {
+         /* reading */
+         if (!_mesa_source_buffer_exists(ctx, GL_COLOR)) {
+            _mesa_error(ctx, GL_INVALID_OPERATION,
+                        "glReadPixels(no color buffer)");
+            return GL_TRUE;
+         }
       }
       break;
    case GL_STENCIL_INDEX:
       if ((drawing && !_mesa_dest_buffer_exists(ctx, format)) ||
-          (!drawing && !_mesa_source_buffer_exists(ctx, format))) {
+          (reading && !_mesa_source_buffer_exists(ctx, format))) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "gl%sPixels(no stencil buffer)", readDraw);
          return GL_TRUE;
@@ -118,7 +135,7 @@ _mesa_error_check_format_type(GLcontext *ctx, GLenum format, GLenum type,
          return GL_TRUE;
       }
       if ((drawing && !_mesa_dest_buffer_exists(ctx, format)) ||
-          (!drawing && !_mesa_source_buffer_exists(ctx, format))) {
+          (reading && !_mesa_source_buffer_exists(ctx, format))) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "gl%sPixels(no depth or stencil buffer)", readDraw);
          return GL_TRUE;




More information about the mesa-commit mailing list