mesa: added _mesa_dump_renderbuffers() debug code
authorBrian Paul <brianp@vmware.com>
Tue, 20 Oct 2009 22:13:08 +0000 (16:13 -0600)
committerBrian Paul <brianp@vmware.com>
Wed, 21 Oct 2009 21:14:30 +0000 (15:14 -0600)
src/mesa/main/debug.c
src/mesa/main/debug.h

index 490cc9c26b75c1b85ccadceba9023667137e06cc..8b1707bab355a9206fad42dd38dd144bd03adaab 100644 (file)
@@ -27,6 +27,7 @@
 #include "attrib.h"
 #include "colormac.h"
 #include "context.h"
+#include "enums.h"
 #include "hash.h"
 #include "imports.h"
 #include "debug.h"
@@ -264,10 +265,13 @@ write_ppm(const char *filename, const GLubyte *buffer, int width, int height,
 
 
 /**
- * Write level[0] image to a ppm file.
+ * Write a texture image to a ppm file.
+ * \param face  cube face in [0,5]
+ * \param level  mipmap level
  */
 static void
-write_texture_image(struct gl_texture_object *texObj, GLuint face, GLuint level)
+write_texture_image(struct gl_texture_object *texObj,
+                    GLuint face, GLuint level)
 {
    struct gl_texture_image *img = texObj->Image[face][level];
    if (img) {
@@ -299,6 +303,45 @@ write_texture_image(struct gl_texture_object *texObj, GLuint face, GLuint level)
 }
 
 
+/**
+ * Write renderbuffer image to a ppm file.
+ */
+static void
+write_renderbuffer_image(const struct gl_renderbuffer *rb)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   GLubyte *buffer;
+   char s[100];
+   GLenum format, type;
+
+   if (rb->_BaseFormat == GL_RGB || 
+       rb->_BaseFormat == GL_RGBA) {
+      format = GL_RGBA;
+      type = GL_UNSIGNED_BYTE;
+   }
+   else if (rb->_BaseFormat == GL_DEPTH_STENCIL) {
+      format = GL_DEPTH_STENCIL;
+      type = GL_UNSIGNED_INT_24_8;
+   }
+   else {
+      return;
+   }
+
+   buffer = (GLubyte *) _mesa_malloc(rb->Width * rb->Height * 4);
+
+   ctx->Driver.ReadPixels(ctx, 0, 0, rb->Width, rb->Height,
+                          format, type, &ctx->DefaultPacking, buffer);
+
+   /* make filename */
+   _mesa_sprintf(s, "/tmp/renderbuffer%u.ppm", rb->Name);
+
+   _mesa_printf("  Writing renderbuffer image to %s\n", s);
+   write_ppm(s, buffer, rb->Width, rb->Height, 4, 0, 1, 2, GL_TRUE);
+
+   _mesa_free(buffer);
+}
+
+
 static GLboolean DumpImages;
 
 
@@ -341,6 +384,35 @@ _mesa_dump_textures(GLboolean dumpImages)
 }
 
 
+static void
+dump_renderbuffer_cb(GLuint id, void *data, void *userData)
+{
+   const struct gl_renderbuffer *rb = (const struct gl_renderbuffer *) data;
+   (void) userData;
+
+   _mesa_printf("Renderbuffer %u: %u x %u  IntFormat = %s\n",
+                rb->Name, rb->Width, rb->Height,
+                _mesa_lookup_enum_by_nr(rb->InternalFormat));
+   if (DumpImages) {
+      write_renderbuffer_image(rb);
+   }
+}
+
+
+/**
+ * Print basic info about all renderbuffers to stdout.
+ * If dumpImages is true, write PPM of level[0] image to a file.
+ */
+void
+_mesa_dump_renderbuffers(GLboolean dumpImages)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   DumpImages = dumpImages;
+   _mesa_HashWalk(ctx->Shared->RenderBuffers, dump_renderbuffer_cb, ctx);
+}
+
+
+
 void
 _mesa_dump_color_buffer(const char *filename)
 {
index bb384c43242361dae7288b31bc285b99801737d9..2a7de9c6b6ab1b850c3dc63da5ebda521c976523 100644 (file)
@@ -60,6 +60,9 @@ extern void _mesa_init_debug( GLcontext *ctx );
 extern void
 _mesa_dump_textures(GLboolean dumpImages);
 
+extern void
+_mesa_dump_renderbuffers(GLboolean dumpImages);
+
 extern void
 _mesa_dump_color_buffer(const char *filename);