report_gl_error.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 <cstdio>
  10. #include "../verbose.h"
  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. case GL_STACK_OVERFLOW:
  30. return "stack overflow";
  31. case GL_STACK_UNDERFLOW:
  32. return "stack underflow";
  33. case GL_OUT_OF_MEMORY:
  34. return "out of memory";
  35. case GL_TABLE_TOO_LARGE:
  36. return "table too large";
  37. #ifdef GL_EXT_framebuffer_object
  38. case GL_INVALID_FRAMEBUFFER_OPERATION_EXT:
  39. return "invalid framebuffer operation";
  40. #endif
  41. }
  42. };
  43. GLenum err = glGetError();
  44. if(GL_NO_ERROR != err)
  45. {
  46. verbose("GL_ERROR: ");
  47. fprintf(stderr,"%s%s\n",id.c_str(),gluErrorString(err));
  48. }
  49. return err;
  50. }
  51. IGL_INLINE GLenum igl::opengl::report_gl_error()
  52. {
  53. return igl::opengl::report_gl_error(std::string(""));
  54. }