Advertisement
Kitomas

gl_err.cpp as of 2024-02-02

Feb 2nd, 2024
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. #include <SDL2/SDL.h>
  2. #include <gl.hpp>
  3.  
  4.  
  5.  
  6.  
  7. void gl::errClear(){
  8.   while(glGetError() != GL_NO_ERROR);
  9. }
  10.  
  11.  
  12.  
  13. const char* gl::errStr(Uint32 errorCode){
  14. #if defined(_DEBUG)
  15.   switch(errorCode){
  16.   case GL_NO_ERROR                     : return "GL_NO_ERROR";
  17.   case GL_INVALID_ENUM                 : return "GL_INVALID_ENUM";
  18.   case GL_INVALID_VALUE                : return "GL_INVALID_VALUE";
  19.   case GL_INVALID_OPERATION            : return "GL_INVALID_OPERATION";
  20.   case GL_INVALID_FRAMEBUFFER_OPERATION: return "GL_INVALID_FRAMEBUFFER_OPERATION";
  21.   case GL_OUT_OF_MEMORY                : return "GL_OUT_OF_MEMORY";
  22.   case GL_STACK_UNDERFLOW              : return "GL_STACK_UNDERFLOW";
  23.   case GL_STACK_OVERFLOW               : return "GL_STACK_OVERFLOW";
  24.   default: return "(unknown error code)"; //should be impossible
  25.   };
  26. #else
  27.   return "!defined(_DEBUG)";
  28. #endif
  29. }
  30.  
  31.  
  32. #define NO_INFO "\b\b\b\b\b\b"
  33.  
  34. Uint32 gl::errLog(int lineNumber, Uint32 errorCode){
  35.   if(errorCode == GL_NO_ERROR) errorCode = glGetError();
  36. #if defined(_DEBUG)
  37.   if(errorCode == GL_NO_ERROR) return errorCode;
  38.  
  39.   if(lineNumber >= 0){
  40.     SDL_Log(NO_INFO"  Line %4i: %s (0x%08X)",
  41.             lineNumber, gl::errStr(errorCode), errorCode);
  42.   } else if(lineNumber == -1){
  43.     SDL_Log(NO_INFO"  %s (0x%08X)", gl::errStr(errorCode), errorCode);
  44.   }
  45.  
  46. #endif
  47.   return errorCode;
  48. }
  49.  
  50.  
  51.  
  52. void gl::errLogAll(int lineNumber, const char* fileName){
  53.   Uint32 errorCode = gl::errLog(-2); //-2 for no print at all
  54.   if(errorCode != GL_NO_ERROR){
  55.     SDL_Log("%s : %4i:", fileName, lineNumber);
  56.     gl::errLog(-1,errorCode);
  57.     do {
  58.       gl::errLog(-1);
  59.     } while(errorCode != GL_NO_ERROR);
  60.   }
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement