[Piglit] [PATCH 1/2] util: Add function piglit_get_gl_error_name

Chad Versace chad at chad-versace.us
Fri Aug 19 12:00:47 PDT 2011


It maps the error's GLenum to a string. For example, given
GL_INVALID_ENUM, it returns "GL_INVALID_ENUM".

----
v2:
    - Add GL_INVALID_FRAMEBUFFER_OPERATION to list of errors.
    - Replace the error table with a switch statement.
----

CC: Henri Verbeet <hverbeet at gmail.com>
Signed-off-by: Chad Versace <chad at chad-versace.us>
---
 tests/util/piglit-util.c |   18 ++++++++++++++++++
 tests/util/piglit-util.h |   11 +++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index 78722d9..84f6942 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -150,6 +150,24 @@ void piglit_require_not_extension(const char *name)
 	}
 }
 
+const char* piglit_get_gl_error_name(GLenum error)
+{
+    switch (error) {
+#define CASE(x) case x: return #x; 
+    CASE(GL_INVALID_ENUM)
+    CASE(GL_INVALID_FRAMEBUFFER_OPERATION)
+    CASE(GL_INVALID_OPERATION)
+    CASE(GL_INVALID_VALUE)
+    CASE(GL_NO_ERROR)
+    CASE(GL_OUT_OF_MEMORY)
+    CASE(GL_STACK_OVERFLOW)
+    CASE(GL_STACK_UNDERFLOW)
+#undef CASE
+    default:
+        return NULL;
+    }
+}
+
 /* These texture coordinates should have 1 or -1 in the major axis selecting
  * the face, and a nearly-1-or-negative-1 value in the other two coordinates
  * which will be used to produce the s,t values used to sample that face's
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index 015f960..2173148 100644
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -115,6 +115,17 @@ void piglit_get_glsl_version(bool *es, int* major, int* minor);
  */
 bool piglit_is_extension_supported(const char *name);
 
+/**
+ * \brief Convert a GL error to a string.
+ *
+ * For example, given GL_INVALID_ENUM, return "GL_INVALID_ENUM".
+ *
+ * Return null if the enum is not recognized.
+ *
+ * \todo Create a more general function that stringifies any GLenum.
+ */
+const char* piglit_get_gl_error_name(GLenum error);
+
 int FindLine(const char *program, int position);
 void piglit_report_result(enum piglit_result result);
 void piglit_require_extension(const char *name);
-- 
1.7.6



More information about the Piglit mailing list