[Piglit] [PATCH 1/2] util: Add function piglit_get_gl_error_name
Henri Verbeet
hverbeet at gmail.com
Thu Aug 18 06:21:09 PDT 2011
On 18 August 2011 02:25, Chad Versace <chad at chad-versace.us> wrote:
> +static struct {
> + GLenum value;
> + const char *name;
> +} piglit_gl_error_table[] = {
> +#define F(x) { x, #x }
> + F(GL_NO_ERROR),
> + F(GL_INVALID_ENUM),
> + F(GL_INVALID_VALUE),
> + F(GL_INVALID_OPERATION),
> + F(GL_STACK_OVERFLOW),
> + F(GL_STACK_UNDERFLOW),
> + F(GL_OUT_OF_MEMORY)
> +#undef F
> +};
> +
> +const char* piglit_get_gl_error_name(GLenum error)
> +{
> + int i;
> + int n = sizeof(piglit_gl_error_table)
> + / sizeof(*piglit_gl_error_table);
> +
> + for (i = 0; i < n; ++i) {
> + if (error == piglit_gl_error_table[i].value) {
> + return piglit_gl_error_table[i].name;
> + }
> + }
> +
> + return NULL;
> +}
> +
Note that if you're not using the table for anything else, you might
as well just do something like the following:
const char* piglit_get_gl_error_name(GLenum error)
{
switch (error) {
#define F(x) case x: return #x
F(GL_NO_ERROR);
F(GL_INVALID_ENUM);
F(GL_INVALID_VALUE);
F(GL_INVALID_OPERATION);
F(GL_STACK_OVERFLOW);
F(GL_STACK_UNDERFLOW);
F(GL_OUT_OF_MEMORY);
#undef F
default:
return NULL;
}
}
Also, GL_INVALID_FRAMEBUFFER_OPERATION is at least one other common GL error.
More information about the Piglit
mailing list