report_gl_error.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "report_gl_error.h"
  9. #include "../verbose.h"
  10. #include <cstdio>
  11. IGL_INLINE GLenum igl::opengl::report_gl_error(const std::string id)
  12. {
  13. // http://stackoverflow.com/q/28485180/148668
  14. // gluErrorString was deprecated
  15. const auto gluErrorString = [](GLenum errorCode)->const char *
  16. {
  17. switch(errorCode)
  18. {
  19. default:
  20. return "unknown error code";
  21. case GL_NO_ERROR:
  22. return "no error";
  23. case GL_INVALID_ENUM:
  24. return "invalid enumerant";
  25. case GL_INVALID_VALUE:
  26. return "invalid value";
  27. case GL_INVALID_OPERATION:
  28. return "invalid operation";
  29. #ifndef GL_VERSION_3_0
  30. case GL_STACK_OVERFLOW:
  31. return "stack overflow";
  32. case GL_STACK_UNDERFLOW:
  33. return "stack underflow";
  34. case GL_TABLE_TOO_LARGE:
  35. return "table too large";
  36. #endif
  37. case GL_OUT_OF_MEMORY:
  38. return "out of memory";
  39. #ifdef GL_EXT_framebuffer_object
  40. case GL_INVALID_FRAMEBUFFER_OPERATION_EXT:
  41. return "invalid framebuffer operation";
  42. #endif
  43. }
  44. };
  45. GLenum err = glGetError();
  46. if(GL_NO_ERROR != err)
  47. {
  48. verbose("GL_ERROR: ");
  49. fprintf(stderr,"%s%s\n",id.c_str(),gluErrorString(err));
  50. }
  51. return err;
  52. }
  53. IGL_INLINE GLenum igl::opengl::report_gl_error()
  54. {
  55. return igl::opengl::report_gl_error(std::string(""));
  56. }