GameKit  0.0.1a
C++ gamedev tools
GLCheck.cpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: GLCheck.cpp
5  *
6  * Description:
7  *
8  * Created: 27/02/2019 01:42:04
9  *
10  * Author: SFML
11  *
12  * =====================================================================================
13  */
14 #include "gk/core/Debug.hpp"
15 #include "gk/gl/GLCheck.hpp"
16 #include "gk/gl/OpenGL.hpp"
17 
18 namespace gk {
19 
20 namespace priv {
21 
22 void glCheckError(const char* file, unsigned int line, const char* expression)
23 {
24  // Get the last error
25  GLenum errorCode = glGetError();
26 
27  if (errorCode != GL_NO_ERROR)
28  {
29  std::string fileString = file;
30  std::string error = "Unknown error";
31  std::string description = "No description";
32 
33  // Decode the error code
34  switch (errorCode)
35  {
36  case GL_INVALID_ENUM:
37  {
38  error = "GL_INVALID_ENUM";
39  description = "An unacceptable value has been specified for an enumerated argument.";
40  break;
41  }
42 
43  case GL_INVALID_VALUE:
44  {
45  error = "GL_INVALID_VALUE";
46  description = "A numeric argument is out of range.";
47  break;
48  }
49 
50  case GL_INVALID_OPERATION:
51  {
52  error = "GL_INVALID_OPERATION";
53  description = "The specified operation is not allowed in the current state.";
54  break;
55  }
56 
57  case GL_STACK_OVERFLOW:
58  {
59  error = "GL_STACK_OVERFLOW";
60  description = "This command would cause a stack overflow.";
61  break;
62  }
63 
64  case GL_STACK_UNDERFLOW:
65  {
66  error = "GL_STACK_UNDERFLOW";
67  description = "This command would cause a stack underflow.";
68  break;
69  }
70 
71  case GL_OUT_OF_MEMORY:
72  {
73  error = "GL_OUT_OF_MEMORY";
74  description = "There is not enough memory left to execute the command.";
75  break;
76  }
77 
78  default:
79  {
80  error = "GK_UNKNOWN_ERROR";
81  description = "Unknown error: " + std::to_string(errorCode);
82  break;
83  }
84 
85  // case GLEXT_GL_INVALID_FRAMEBUFFER_OPERATION:
86  // {
87  // error = "GL_INVALID_FRAMEBUFFER_OPERATION";
88  // description = "The object bound to FRAMEBUFFER_BINDING is not \"framebuffer complete\".";
89  // break;
90  // }
91  }
92 
93  // Log the error
94  std::cerr << "An internal OpenGL call failed in "
95  << fileString.substr(fileString.find_last_of("\\/") + 1) << "(" << line << ")."
96  << "\nExpression:\n " << expression
97  << "\nError description:\n " << error << "\n " << description << "\n"
98  << std::endl;
99  }
100 }
101 
102 } // namespace priv
103 
104 } // namespace gk
105 
void glCheckError(const char *file, unsigned int line, const char *expression)
Definition: GLCheck.cpp:22