15 #ifndef vtkOpenGLError_h
16 #define vtkOpenGLError_h
19 #include "vtkSetGet.h"
23 #define VTK_REPORT_OPENGL_ERRORS
27 #if defined(VTK_REPORT_OPENGL_ERRORS_IN_RELEASE_BUILDS)
28 #define VTK_REPORT_OPENGL_ERRORS
29 #endif // defined(VTK_REPORT_OPENGL_ERRORS_IN_RELEASE_BUILDS)
70 switch(static_cast<GLenum>(code))
75 return "Invalid enum";
76 case GL_INVALID_VALUE:
77 return "Invalid value";
78 case GL_INVALID_OPERATION:
79 return "Invalid operation";
80 case GL_STACK_OVERFLOW:
81 return "Stack overflow";
82 case GL_STACK_UNDERFLOW:
83 return "Stack underflow";
84 case GL_OUT_OF_MEMORY:
85 return "Out of memory";
86 case vtkgl::TABLE_TOO_LARGE:
87 return "Table too large";
88 case vtkgl::INVALID_FRAMEBUFFER_OPERATION_EXT:
89 return "Invalid framebuffer operation";
90 case vtkgl::TEXTURE_TOO_LARGE_EXT:
91 return "Texture too large";
93 return "Unknown error";
103 #if defined(VTK_REPORT_OPENGL_ERRORS)
107 unsigned int *errCode,
108 const char **errDesc)
111 GLenum code = glGetError();
114 errCode[i] =
static_cast<unsigned int>(code);
117 while (code != GL_NO_ERROR && i < maxNum)
123 errCode[i] =
static_cast<unsigned int>(code);
133 unsigned int *errCode,
134 const char **errDesc)
148 #if defined(VTK_REPORT_OPENGL_ERRORS)
154 unsigned int *errCode,
155 const char **errDesc)
157 os << numErrors <<
" OpenGL errors detected" << endl;
158 for (
int i=0; (i<numErrors)&&(i<maxErrors); ++i)
160 os <<
" " << i <<
" : (" << errCode[i] <<
") " << errDesc[i] << endl;
162 if (numErrors>maxErrors)
165 <<
"More than " << maxErrors
166 <<
" detected! The remainder are not reported"
176 unsigned int *errCode,
177 const char **errDesc)
189 #if defined(VTK_REPORT_OPENGL_ERRORS)
197 glError = glGetError();
200 while(i < maxErrors && glError != GL_NO_ERROR);
210 #if !defined(VTK_REPORT_OPENGL_ERRORS)
211 # define vtkOpenGLClearErrorMacro()
212 # define vtkOpenGLCheckErrorMacro(message)
213 # define vtkOpenGLStaticCheckErrorMacro(message)
215 # define vtkOpenGLClearErrorMacro() vtkClearOpenGLErrors(16);
217 # define vtkOpenGLCheckErrorMacroImpl(ostr, message) \
219 const int maxErrors = 16; \
220 unsigned int errCode[maxErrors] = {0}; \
221 const char *errDesc[maxErrors] = {NULL}; \
224 = vtkGetOpenGLErrors( \
231 std::ostringstream oss; \
232 vtkPrintOpenGLErrors( \
239 ostr(<< message << " " << oss.str().c_str()); \
242 # define vtkOpenGLCheckErrorMacro(message) \
243 vtkOpenGLCheckErrorMacroImpl(vtkErrorMacro, message)
244 # define vtkOpenGLStaticCheckErrorMacro(message) \
245 vtkOpenGLCheckErrorMacroImpl(vtkGenericWarningMacro, message)
251 # define vtkOpenGLDebugClearErrorMacro()
252 # define vtkOpenGLDebugCheckErrorMacro(message)
254 # define vtkOpenGLDebugClearErrorMacro() \
255 vtkOpenGLClearErrorMacro()
256 # define vtkOpenGLDebugCheckErrorMacro(message) \
257 vtkOpenGLStaticCheckErrorMacro(message)
void vtkClearOpenGLErrors(const unsigned int maxErrors=16)
int vtkGetOpenGLErrors(int maxNum, unsigned int *errCode, const char **errDesc)
const char * vtkOpenGLStrError(unsigned int code)
void vtkPrintOpenGLErrors(ostream &os, int maxErrors, int numErrors, unsigned int *errCode, const char **errDesc)