diff options
Diffstat (limited to 'src/mesa/main/debug.c')
-rw-r--r-- | src/mesa/main/debug.c | 125 |
1 files changed, 122 insertions, 3 deletions
diff --git a/src/mesa/main/debug.c b/src/mesa/main/debug.c index 77fef32558..fdd10dd307 100644 --- a/src/mesa/main/debug.c +++ b/src/mesa/main/debug.c @@ -23,10 +23,15 @@ */ #include "mtypes.h" +#include "colormac.h" #include "context.h" +#include "hash.h" #include "imports.h" #include "debug.h" #include "get.h" +#include "texobj.h" +#include "texformat.h" + /** * Primitive names @@ -164,9 +169,7 @@ static void add_debug_flags( const char *debug ) { "api", VERBOSE_API }, { "list", VERBOSE_DISPLAY_LIST }, { "lighting", VERBOSE_LIGHTING }, - { "disassem", VERBOSE_DISASSEM }, - { "glsl", VERBOSE_GLSL }, /* report GLSL compile/link errors */ - { "glsl_dump", VERBOSE_GLSL_DUMP } /* print shader GPU instructions */ + { "disassem", VERBOSE_DISASSEM } }; GLuint i; @@ -221,3 +224,119 @@ _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; x<width; x++) { + i = (y*width + x) * comps; + fputc(ptr[i+rcomp], f); /* write red */ + fputc(ptr[i+gcomp], f); /* write green */ + fputc(ptr[i+bcomp], f); /* write blue */ + } + } + fclose(f); + } +} + + +/** + * Write level[0] image to a ppm file. + */ +static void +write_texture_image(struct gl_texture_object *texObj) +{ + const struct gl_texture_image *img = texObj->Image[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; + case MESA_FORMAT_RGB888: + write_ppm(s, img->Data, img->Width, img->Height, 3, 2, 1, 0); + break; + case MESA_FORMAT_RGB565: + { + GLubyte *buf2 = (GLubyte *) _mesa_malloc(img->Width * img->Height * 3); + GLint i; + for (i = 0; i < img->Width * img->Height; i++) { + GLint r, g, b; + GLushort s = ((GLushort *) img->Data)[i]; + r = UBYTE_TO_CHAN( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) ); + g = UBYTE_TO_CHAN( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) ); + b = UBYTE_TO_CHAN( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) ); + buf2[i*3+1] = r; + buf2[i*3+2] = g; + buf2[i*3+3] = b; + } + write_ppm(s, buf2, img->Width, img->Height, 3, 2, 1, 0); + _mesa_free(buf2); + } + 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; + int i; + (void) userData; + + 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); +} |