Mesa (master): mesa: added debug functions for dumping color/depth/ stencil buffers

Brian Paul brianp at kemper.freedesktop.org
Thu May 21 15:32:19 UTC 2009


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

Author: Brian Paul <brianp at vmware.com>
Date:   Thu May 21 09:12:35 2009 -0600

mesa: added debug functions for dumping color/depth/stencil buffers

---

 src/mesa/main/debug.c |  101 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/mesa/main/debug.h |    9 ++++
 2 files changed, 110 insertions(+), 0 deletions(-)

diff --git a/src/mesa/main/debug.c b/src/mesa/main/debug.c
index 2eabcda..80bc6af 100644
--- a/src/mesa/main/debug.c
+++ b/src/mesa/main/debug.c
@@ -341,3 +341,104 @@ _mesa_dump_textures(GLboolean dumpImages)
    DumpImages = dumpImages;
    _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);
+
+   glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
+   glPixelStorei(GL_PACK_ALIGNMENT, 1);
+   glPixelStorei(GL_PACK_INVERT_MESA, GL_TRUE);
+
+   glReadPixels(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);
+
+   glPopClientAttrib();
+
+   _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 */
+
+   glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
+   glPixelStorei(GL_PACK_ALIGNMENT, 1);
+   glPixelStorei(GL_PACK_INVERT_MESA, GL_TRUE);
+
+   glReadPixels(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);
+
+   glPopClientAttrib();
+
+   _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 */
+
+   glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
+   glPixelStorei(GL_PACK_ALIGNMENT, 1);
+   glPixelStorei(GL_PACK_INVERT_MESA, GL_TRUE);
+
+   glReadPixels(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);
+
+   glPopClientAttrib();
+
+   _mesa_free(buf);
+   _mesa_free(buf2);
+}
diff --git a/src/mesa/main/debug.h b/src/mesa/main/debug.h
index 1862ec7..bb384c4 100644
--- a/src/mesa/main/debug.h
+++ b/src/mesa/main/debug.h
@@ -60,4 +60,13 @@ extern void _mesa_init_debug( GLcontext *ctx );
 extern void
 _mesa_dump_textures(GLboolean dumpImages);
 
+extern void
+_mesa_dump_color_buffer(const char *filename);
+
+extern void
+_mesa_dump_depth_buffer(const char *filename);
+
+extern void
+_mesa_dump_stencil_buffer(const char *filename);
+
 #endif




More information about the mesa-commit mailing list