From 266fe93a87d5c0c21e9e7960699104e0e8bd54b4 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 7 Feb 2009 11:49:52 -0700 Subject: mesa: debug code for printing info about textures, writing teximages to disk --- src/mesa/main/debug.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/mesa/main/debug.h | 3 ++ 2 files changed, 102 insertions(+) (limited to 'src') diff --git a/src/mesa/main/debug.c b/src/mesa/main/debug.c index 65970a53a9..90a3bf1f04 100644 --- a/src/mesa/main/debug.c +++ b/src/mesa/main/debug.c @@ -24,9 +24,13 @@ #include "mtypes.h" #include "context.h" +#include "hash.h" #include "imports.h" #include "debug.h" #include "get.h" +#include "texobj.h" +#include "texformat.h" + /** * Primitive names @@ -219,3 +223,98 @@ _mesa_init_debug( GLcontext *ctx ) add_debug_flags(c); } + +/* + * Write ppm file + */ +static void +write_ppm(const char *filename, const GLubyte *buffer, int width, int height, + int comps, int rcomp, int gcomp, int bcomp) +{ + FILE *f = fopen( filename, "w" ); + if (f) { + int i, x, y; + const GLubyte *ptr = buffer; + fprintf(f,"P6\n"); + fprintf(f,"# ppm-file created by osdemo.c\n"); + fprintf(f,"%i %i\n", width,height); + fprintf(f,"255\n"); + fclose(f); + f = fopen( filename, "ab" ); /* reopen in binary append mode */ + for (y=height-1; y>=0; y--) { + for (x=0; xImage[0][0]; + if (img) { + char s[100]; + + /* make filename */ + sprintf(s, "/tmp/teximage%u.ppm", texObj->Name); + + switch (img->TexFormat->MesaFormat) { + case MESA_FORMAT_RGBA8888: + write_ppm(s, img->Data, img->Width, img->Height, 4, 3, 2, 1); + break; + case MESA_FORMAT_ARGB8888: + write_ppm(s, img->Data, img->Width, img->Height, 4, 2, 1, 0); + break; + default: + printf("XXXX unsupported mesa tex format %d in %s\n", + img->TexFormat->MesaFormat, __FUNCTION__); + } + } +} + + +static GLboolean DumpImages; + + +static void +dump_texture_cb(GLuint id, void *data, void *userData) +{ + struct gl_texture_object *texObj = (struct gl_texture_object *) data; + (void) userData; + int i; + + printf("Texture %u\n", texObj->Name); + printf(" Target 0x%x\n", texObj->Target); + for (i = 0; i < MAX_TEXTURE_LEVELS; i++) { + struct gl_texture_image *texImg = texObj->Image[0][i]; + if (texImg) { + printf(" Image %u: %d x %d x %d at %p\n", i, + texImg->Width, texImg->Height, texImg->Depth, texImg->Data); + if (DumpImages && i == 0) { + write_texture_image(texObj); + } + } + } +} + + +/** + * Print basic info about all texture objext to stdout. + * If dumpImages is true, write PPM of level[0] image to a file. + */ +void +_mesa_dump_textures(GLboolean dumpImages) +{ + GET_CURRENT_CONTEXT(ctx); + DumpImages = dumpImages; + _mesa_HashDeleteAll(ctx->Shared->TexObjects, dump_texture_cb, ctx); +} diff --git a/src/mesa/main/debug.h b/src/mesa/main/debug.h index 94d99c384b..1862ec75b7 100644 --- a/src/mesa/main/debug.h +++ b/src/mesa/main/debug.h @@ -57,4 +57,7 @@ extern void _mesa_init_debug( GLcontext *ctx ); #endif +extern void +_mesa_dump_textures(GLboolean dumpImages); + #endif -- cgit v1.2.3