From: Ralf Jung Date: Fri, 27 Sep 2013 10:54:38 +0000 (+0200) Subject: make checkGlError generally available X-Git-Url: https://git.ralfj.de/gltest.git/commitdiff_plain/abe5b74c820514f9f5896309e0e192569db35651?ds=inline make checkGlError generally available --- diff --git a/Makefile b/Makefile index c69fff7..0322bfb 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CFLAGS := -Wall -g -O1 -COMMON_SRC = gltest.cpp glwindow.cpp +COMMON_SRC = gltest.cpp glwindow.cpp glutil.cpp COMMON_HDR = glwindow.h glutil.h COMMON_LD = -lX11 -lboost_program_options 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); +} diff --git a/glutil.h b/glutil.h index 688ee29..3c1a6d2 100644 --- a/glutil.h +++ b/glutil.h @@ -29,5 +29,6 @@ typedef T_proc (*T_glGetProcAddress)(char const * procname); void resolveFunctionPointers(T_glGetProcAddress p_glGetProcAddress); /* The actual utility functions */ +void checkGlError(const char *what); void initialise2dProjection(); void drawQuad(GLfloat red, GLfloat green, GLfloat blue, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2); diff --git a/glutil_gl2.cpp b/glutil_gl2.cpp index 666ede9..68a789b 100644 --- a/glutil_gl2.cpp +++ b/glutil_gl2.cpp @@ -16,13 +16,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "glutil.h" + #include #include #include #include -#include "glutil.h" - // extension functions we use typedef GLuint (*GLCREATESHADERPROC) (GLenum type); typedef void (*GLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params); @@ -127,32 +127,6 @@ void resolveFunctionPointers(T_glGetProcAddress p_glGetProcAddress) p_glDeleteBuffers = (GLDELETEBUFFERSPROC)resolveFunctionPointer(p_glGetProcAddress, "glDeleteBuffers"); } -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 -} - -static 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); -} - // shaders static const char *vertex_shader_source = "#version 100 \n\