Mesa (master): mesa: do a debug check of _mesa_format_to_type_and_comps()

Brian Paul brianp at kemper.freedesktop.org
Tue Jan 11 16:37:56 UTC 2011


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

Author: Brian Paul <brianp at vmware.com>
Date:   Tue Jan 11 09:26:03 2011 -0700

mesa: do a debug check of _mesa_format_to_type_and_comps()

Make sure that all formats are handled in this function.  It's
easy to miss this function when adding new pixel formats.

See also http://bugs.freedesktop.org/show_bug.cgi?id=31544

---

 src/mesa/main/context.c |    5 +++++
 src/mesa/main/formats.c |   24 +++++++++++++++++++++++-
 2 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 2c57c8d..958ea10 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -96,6 +96,7 @@
 #include "fbobject.h"
 #include "feedback.h"
 #include "fog.h"
+#include "formats.h"
 #include "framebuffer.h"
 #include "hint.h"
 #include "hash.h"
@@ -417,6 +418,10 @@ one_time_init( struct gl_context *ctx )
 		     MESA_VERSION_STRING, __DATE__, __TIME__);
       }
 #endif
+
+#ifdef DEBUG
+      _mesa_test_formats();
+#endif
    }
 
    /* per-API one-time init */
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 514fe7a..1bc7272 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -1168,6 +1168,27 @@ _mesa_format_row_stride(gl_format format, GLsizei width)
 }
 
 
+/**
+ * Debug/test: check that all formats are handled in the
+ * _mesa_format_to_type_and_comps() function.  When new pixel formats
+ * are added to Mesa, that function needs to be updated.
+ * This is a no-op after the first call.
+ */
+static void
+check_format_to_type_and_comps(void)
+{
+   gl_format f;
+
+   for (f = MESA_FORMAT_NONE + 1; f < MESA_FORMAT_COUNT; f++) {
+      GLenum datatype = 0;
+      GLuint comps = 0;
+      /* This function will emit a problem/warning if the format is
+       * not handled.
+       */
+      _mesa_format_to_type_and_comps(f, &datatype, &comps);
+   }
+}
+
 
 /**
  * Do sanity checking of the format info table.
@@ -1251,8 +1272,9 @@ _mesa_test_formats(void)
          assert(info->LuminanceBits == 0);
          assert(info->IntensityBits > 0);
       }
-
    }
+
+   check_format_to_type_and_comps();
 }
 
 




More information about the mesa-commit mailing list