Permalink
Browse files

added CHECKGLERROR define in gltools/misc

  • Loading branch information...
dkoerner committed May 15, 2012
1 parent 5287371 commit 9bb841deb30843cd834fce10851498bbf8000cbe
Showing with 45 additions and 2 deletions.
  1. +40 −0 gltools/misc.cpp
  2. +5 −2 gltools/misc.h
View
@@ -2,6 +2,8 @@
#include "gl.h"
+#include <iostream>
+
namespace base
{
//
@@ -132,4 +134,42 @@ namespace base
glEnd();
}
}
+
+
+
+ std::string glErrorString( int glErrorCode )
+ {
+ switch(glErrorCode)
+ {
+ case GL_NO_ERROR:
+ return "No error has been recorded.";break;
+ case GL_INVALID_ENUM:
+ return "An unacceptable value is specified for an enumerated argument.";break;
+ case GL_INVALID_VALUE:
+ return "A numeric argument is out of range.";break;
+ case GL_INVALID_OPERATION:
+ return "The specified operation is not allowed in the current state.";break;
+ case GL_STACK_OVERFLOW:
+ return "This command would cause a stack overflow.";break;
+ case GL_STACK_UNDERFLOW:
+ return "This command would cause a stack underflow.";break;
+ case GL_OUT_OF_MEMORY:
+ return "There is not enough memory left to execute the command.";break;
+ case GL_TABLE_TOO_LARGE:
+ return "GL_TABLE_TOO_LARGE";break;
+ default:
+ return "";
+ };
+ return "";
+ }
+ bool checkGlError(const char *file, int line)
+ {
+ GLenum err = glGetError();
+ if (err != GL_NO_ERROR)
+ {
+ std::cerr << "OpenGL Error at " << file << " line " << line << ":" << glErrorString(err) << std::endl;
+ return true;
+ }
+ return false;
+ }
}
View
@@ -1,14 +1,17 @@
#pragma once
-
+#include <string>
#include <math/Math.h>
-
+#define CHECKGLERROR() checkGlError(__FILE__, __LINE__)
namespace base
{
void drawGrid( bool axes = true ); ///< draw a orientation grid identical to the ones used in popular dcc apps
void drawTransform( const math::Matrix44f &tm ); ///< draw orientation vectors for given transform
void headLight(); ///< sets light0 parameters accordingly
+
+ std::string glErrorString( int glErrorCode );
+ bool checkGlError(const char *file, int line); // returns true if there was an error
}

0 comments on commit 9bb841d

Please sign in to comment.