[Mesa-dev] [PATCH 21/37] mesa: Convert texture debug dump function to using MapTextureImage().

Eric Anholt eric at anholt.net
Mon Aug 15 11:53:51 PDT 2011


From: Brian Paul <brianp at vmware.com>

---
 src/mesa/main/debug.c |   94 ++++++++++++++++++++++++++----------------------
 src/mesa/main/debug.h |    2 +-
 2 files changed, 52 insertions(+), 44 deletions(-)

diff --git a/src/mesa/main/debug.c b/src/mesa/main/debug.c
index e7f6be9..4e05a45 100644
--- a/src/mesa/main/debug.c
+++ b/src/mesa/main/debug.c
@@ -364,11 +364,10 @@ dump_texture(struct gl_texture_object *texObj, GLuint writeImages)
       for (j = 0; j < numFaces; j++) {
          struct gl_texture_image *texImg = texObj->Image[j][i];
          if (texImg) {
-            printf("  Face %u level %u: %d x %d x %d, format %s at %p\n",
+            printf("  Face %u level %u: %d x %d x %d, format %s\n",
 		   j, i,
 		   texImg->Width, texImg->Height, texImg->Depth,
-		   _mesa_get_format_name(texImg->TexFormat),
-		   texImg->Data);
+		   _mesa_get_format_name(texImg->TexFormat));
             if (writeImages == WRITE_ALL ||
                 (writeImages == WRITE_ONE && !written)) {
                write_texture_image(texObj, j, i);
@@ -577,58 +576,67 @@ _mesa_dump_image(const char *filename, const void *image, GLuint w, GLuint h,
  * Quick and dirty function to "print" a texture to stdout.
  */
 void
-_mesa_print_texture(struct gl_context *ctx, const struct gl_texture_image *img)
+_mesa_print_texture(struct gl_context *ctx, struct gl_texture_image *img)
 {
 #if CHAN_TYPE != GL_UNSIGNED_BYTE
    _mesa_problem(NULL, "PrintTexture not supported");
 #else
+   const GLint slice = 0;
+   GLint srcRowStride;
    GLuint i, j, c;
-   const GLubyte *data = (const GLubyte *) img->Data;
+   GLubyte *data;
+
+   ctx->Driver.MapTextureImage(ctx, img, slice,
+                               0, 0, img->Width, img->Height, GL_MAP_READ_BIT,
+                               &data, &srcRowStride);
 
    if (!data) {
       printf("No texture data\n");
-      return;
    }
+   else {
+      /* XXX add more formats or make into a new format utility function */
+      switch (img->TexFormat) {
+         case MESA_FORMAT_A8:
+         case MESA_FORMAT_L8:
+         case MESA_FORMAT_I8:
+         case MESA_FORMAT_CI8:
+            c = 1;
+            break;
+         case MESA_FORMAT_AL88:
+         case MESA_FORMAT_AL88_REV:
+            c = 2;
+            break;
+         case MESA_FORMAT_RGB888:
+         case MESA_FORMAT_BGR888:
+            c = 3;
+            break;
+         case MESA_FORMAT_RGBA8888:
+         case MESA_FORMAT_ARGB8888:
+            c = 4;
+            break;
+         default:
+            _mesa_problem(NULL, "error in PrintTexture\n");
+            return;
+      }
 
-   /* XXX add more formats or make into a new format utility function */
-   switch (img->TexFormat) {
-      case MESA_FORMAT_A8:
-      case MESA_FORMAT_L8:
-      case MESA_FORMAT_I8:
-      case MESA_FORMAT_CI8:
-         c = 1;
-         break;
-      case MESA_FORMAT_AL88:
-      case MESA_FORMAT_AL88_REV:
-         c = 2;
-         break;
-      case MESA_FORMAT_RGB888:
-      case MESA_FORMAT_BGR888:
-         c = 3;
-         break;
-      case MESA_FORMAT_RGBA8888:
-      case MESA_FORMAT_ARGB8888:
-         c = 4;
-         break;
-      default:
-         _mesa_problem(NULL, "error in PrintTexture\n");
-         return;
-   }
+      for (i = 0; i < img->Height; i++) {
+         for (j = 0; j < img->Width; j++) {
+            if (c==1)
+               printf("%02x  ", data[0]);
+            else if (c==2)
+               printf("%02x%02x  ", data[0], data[1]);
+            else if (c==3)
+               printf("%02x%02x%02x  ", data[0], data[1], data[2]);
+            else if (c==4)
+               printf("%02x%02x%02x%02x  ", data[0], data[1], data[2], data[3]);
+            data += (srcRowStride - img->Width) * c;
+         }
+         /* XXX use img->ImageStride here */
+         printf("\n");
 
-   for (i = 0; i < img->Height; i++) {
-      for (j = 0; j < img->Width; j++) {
-         if (c==1)
-            printf("%02x  ", data[0]);
-         else if (c==2)
-            printf("%02x%02x  ", data[0], data[1]);
-         else if (c==3)
-            printf("%02x%02x%02x  ", data[0], data[1], data[2]);
-         else if (c==4)
-            printf("%02x%02x%02x%02x  ", data[0], data[1], data[2], data[3]);
-         data += (img->RowStride - img->Width) * c;
       }
-      /* XXX use img->ImageStride here */
-      printf("\n");
    }
+
+   ctx->Driver.UnmapTextureImage(ctx, img, slice);
 #endif
 }
diff --git a/src/mesa/main/debug.h b/src/mesa/main/debug.h
index d7c53b6..bc64a83 100644
--- a/src/mesa/main/debug.h
+++ b/src/mesa/main/debug.h
@@ -89,6 +89,6 @@ _mesa_dump_image(const char *filename, const void *image, GLuint w, GLuint h,
                  GLenum format, GLenum type);
 
 extern void
-_mesa_print_texture(struct gl_context *ctx, const struct gl_texture_image *img);
+_mesa_print_texture(struct gl_context *ctx, struct gl_texture_image *img);
 
 #endif
-- 
1.7.5.4



More information about the mesa-dev mailing list