diff options
Diffstat (limited to 'src/mesa/main/debug.c')
-rw-r--r-- | src/mesa/main/debug.c | 111 |
1 files changed, 108 insertions, 3 deletions
diff --git a/src/mesa/main/debug.c b/src/mesa/main/debug.c index fdd10dd307..1c8c44fcb9 100644 --- a/src/mesa/main/debug.c +++ b/src/mesa/main/debug.c @@ -3,6 +3,7 @@ * Version: 6.5 * * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. + * Copyright (C) 2009 VMware, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -23,12 +24,15 @@ */ #include "mtypes.h" +#include "attrib.h" #include "colormac.h" #include "context.h" #include "hash.h" #include "imports.h" #include "debug.h" #include "get.h" +#include "pixelstore.h" +#include "readpix.h" #include "texobj.h" #include "texformat.h" @@ -262,7 +266,7 @@ static void write_texture_image(struct gl_texture_object *texObj) { const struct gl_texture_image *img = texObj->Image[0][0]; - if (img) { + if (img && img->Data) { char s[100]; /* make filename */ @@ -281,7 +285,7 @@ write_texture_image(struct gl_texture_object *texObj) case MESA_FORMAT_RGB565: { GLubyte *buf2 = (GLubyte *) _mesa_malloc(img->Width * img->Height * 3); - GLint i; + GLuint i; for (i = 0; i < img->Width * img->Height; i++) { GLint r, g, b; GLushort s = ((GLushort *) img->Data)[i]; @@ -338,5 +342,106 @@ _mesa_dump_textures(GLboolean dumpImages) { GET_CURRENT_CONTEXT(ctx); DumpImages = dumpImages; - _mesa_HashDeleteAll(ctx->Shared->TexObjects, dump_texture_cb, ctx); + _mesa_HashWalk(ctx->Shared->TexObjects, dump_texture_cb, ctx); +} + + +void +_mesa_dump_color_buffer(const char *filename) +{ + GET_CURRENT_CONTEXT(ctx); + const GLuint w = ctx->DrawBuffer->Width; + const GLuint h = ctx->DrawBuffer->Height; + GLubyte *buf; + + buf = (GLubyte *) _mesa_malloc(w * h * 4); + + _mesa_PushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); + _mesa_PixelStorei(GL_PACK_ALIGNMENT, 1); + _mesa_PixelStorei(GL_PACK_INVERT_MESA, GL_TRUE); + + _mesa_ReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, buf); + + _mesa_printf("ReadBuffer %p 0x%x DrawBuffer %p 0x%x\n", + ctx->ReadBuffer->_ColorReadBuffer, + ctx->ReadBuffer->ColorReadBuffer, + ctx->DrawBuffer->_ColorDrawBuffers[0], + ctx->DrawBuffer->ColorDrawBuffer[0]); + _mesa_printf("Writing %d x %d color buffer to %s\n", w, h, filename); + write_ppm(filename, buf, w, h, 4, 0, 1, 2); + + _mesa_PopClientAttrib(); + + _mesa_free(buf); +} + + +void +_mesa_dump_depth_buffer(const char *filename) +{ + GET_CURRENT_CONTEXT(ctx); + const GLuint w = ctx->DrawBuffer->Width; + const GLuint h = ctx->DrawBuffer->Height; + GLuint *buf; + GLubyte *buf2; + GLuint i; + + buf = (GLuint *) _mesa_malloc(w * h * 4); /* 4 bpp */ + buf2 = (GLubyte *) _mesa_malloc(w * h * 3); /* 3 bpp */ + + _mesa_PushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); + _mesa_PixelStorei(GL_PACK_ALIGNMENT, 1); + _mesa_PixelStorei(GL_PACK_INVERT_MESA, GL_TRUE); + + _mesa_ReadPixels(0, 0, w, h, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, buf); + + /* spread 24 bits of Z across R, G, B */ + for (i = 0; i < w * h; i++) { + buf2[i*3+0] = (buf[i] >> 24) & 0xff; + buf2[i*3+1] = (buf[i] >> 16) & 0xff; + buf2[i*3+2] = (buf[i] >> 8) & 0xff; + } + + _mesa_printf("Writing %d x %d depth buffer to %s\n", w, h, filename); + write_ppm(filename, buf2, w, h, 3, 0, 1, 2); + + _mesa_PopClientAttrib(); + + _mesa_free(buf); + _mesa_free(buf2); +} + + +void +_mesa_dump_stencil_buffer(const char *filename) +{ + GET_CURRENT_CONTEXT(ctx); + const GLuint w = ctx->DrawBuffer->Width; + const GLuint h = ctx->DrawBuffer->Height; + GLubyte *buf; + GLubyte *buf2; + GLuint i; + + buf = (GLubyte *) _mesa_malloc(w * h); /* 1 bpp */ + buf2 = (GLubyte *) _mesa_malloc(w * h * 3); /* 3 bpp */ + + _mesa_PushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); + _mesa_PixelStorei(GL_PACK_ALIGNMENT, 1); + _mesa_PixelStorei(GL_PACK_INVERT_MESA, GL_TRUE); + + _mesa_ReadPixels(0, 0, w, h, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, buf); + + for (i = 0; i < w * h; i++) { + buf2[i*3+0] = buf[i]; + buf2[i*3+1] = (buf[i] & 127) * 2; + buf2[i*3+2] = (buf[i] - 128) * 2; + } + + _mesa_printf("Writing %d x %d stencil buffer to %s\n", w, h, filename); + write_ppm(filename, buf2, w, h, 3, 0, 1, 2); + + _mesa_PopClientAttrib(); + + _mesa_free(buf); + _mesa_free(buf2); } |