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

Chad Versace chad at chad-versace.us
Mon Aug 22 14:33:32 PDT 2011


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

On 08/22/2011 12:36 AM, Ian Romanick wrote:
> 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.

Ah, good catch. I'll replace NULL with "(unrecognized error)".

> 
>>  /* 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 Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJOUsssAAoJEAIvNt057x8i24YQALezT01EExXxpOYJRe1Dk1oq
OSwys6u9H0/PgtObeU66qFbroscmdboCglbfZ6oVlTwTXRB3YX18Nd0XY+P7GFyv
bAssZP/t9rhJnjvsXp/cww8hohlkAydKXPxfsdGCgEtDYAJz3UZyJgID+Pm9rn1O
Ejv8RXzpiwWKq3R1ayNbcS29bWhZM9KthrZDswmLlW37xei+zJZG/wosOA3usWk8
8+26moEz6od9pfvQ3wqsymsxP4jYKWt8h89NEDC6CPAHRO/AZgjHUq1m11/+eiRF
LlKcoFL0dI3LIVaTc+nECLuLJG8Izt4ZVce3jgJhPF9A95npADfS1//88k0JhpgX
8iDmNRABXK7AphyV5dNJcSlHwto6hXOAGwLwuONaV1OXCZLNit8VPaAWsnHbS8GD
2bnENjYQvrb2xBTOuyLjvZwcKpJr/UJbn+5JVBluPQWbg2ol9StzuXMDOYWMUIhk
BqJX8j8yDARnBbPqJWUQn22yuCf9MtQd+nuqGy0yAf2oUc6ulOCuPRBi6q5h1mxv
/RRFGZGjfRQmYJM0xPD3bnrcYdqNwMcQz6HOI3xdYyL0syvAFNiTjHRtTnts10KV
H+552YCEngShUqudI4bE22YnBYvEihCDpB2hvuQlGXNd7DaNsBxhSFmtCD4830CE
jxtzVLZgCA1htnfQ2RWS
=7iix
-----END PGP SIGNATURE-----


More information about the Piglit mailing list