X-Git-Url: https://git.ralfj.de/gltest.git/blobdiff_plain/ce1b46da645fdcac80fc9c71082bb5cb40166576..abe5b74c820514f9f5896309e0e192569db35651:/glutil.cpp diff --git a/glutil.cpp b/glutil.cpp new file mode 100644 index 0000000..0da85d5 --- /dev/null +++ b/glutil.cpp @@ -0,0 +1,48 @@ +/* gltest - small OpenGL tearing test program + * Copyright (C) 2012-2013 Ralf Jung + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "glutil.h" + +#include +#include + +static const char *glErrorToString(GLenum e) +{ +#define CASE(name) case name: return #name + switch (e) { + CASE(GL_NO_ERROR); + CASE(GL_INVALID_ENUM); + CASE(GL_INVALID_VALUE); + CASE(GL_INVALID_OPERATION); +#ifndef CON_GLES2 + CASE(GL_STACK_OVERFLOW); + CASE(GL_STACK_UNDERFLOW); +#endif + CASE(GL_OUT_OF_MEMORY); + default: return ""; + } +#undef CASE +} + +void checkGlError(const char *what) +{ + GLenum e = glGetError(); + if (e == GL_NO_ERROR) return; + fprintf(stderr, "GL error %d (%s): %s\n", e, glErrorToString(e), what); + exit(1); +}