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

Ian Romanick idr at freedesktop.org
Mon Aug 22 00:36:06 PDT 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 08/19/2011 12:00 PM, Chad Versace wrote:
> 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;
> +    }
> +}
> +

If I were to use this function, I would do something like:

	printf("Got the error %s (0x%04x)\n",
		piglit_get_gl_error_name(err), err);

and that would get angry about the potential NULL return.  Returning ""
or "unrecognized error" would be better.

>  /* 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);

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAk5SBuUACgkQX1gOwKyEAw9j4wCcCGW6OEwyf6ju+2JaoqXg0ThK
LU8AnjgSTc5KcgLXBnYyqQluLeljUQre
=m0K+
-----END PGP SIGNATURE-----


More information about the Piglit mailing list