///////////////////////////////////////////////////////
| 42 | { |
| 43 | //////////////////////////////////////////////////////////// |
| 44 | bool checkError(std::string_view file, unsigned int line, std::string_view expression) |
| 45 | { |
| 46 | // Additionally check if a context was active on the thread at the time of the function call |
| 47 | if (sf::Context::getActiveContextId() == 0) |
| 48 | { |
| 49 | sf::err() << "An internal OpenGL call failed in " << std::filesystem::path(file).filename() << "(" << line << ")." |
| 50 | << "\nExpression:\n " << expression |
| 51 | << "\nError description:\n No active OpenGL context on calling thread.\n" |
| 52 | << std::endl; |
| 53 | |
| 54 | #if defined(SFML_FATAL_OPENGL_ERRORS) |
| 55 | assert(false && "OpenGL error (fatal OpenGL errors enabled): No active OpenGL context on calling thread"); |
| 56 | #endif |
| 57 | |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | const auto logError = [&](const char* error, const char* description) |
| 62 | { |
| 63 | sf::err() << "An internal OpenGL call failed in " << std::filesystem::path(file).filename() << "(" << line << ")." |
| 64 | << "\nExpression:\n " << expression << "\nError description:\n " << error << "\n " |
| 65 | << description << '\n' |
| 66 | << std::endl; |
| 67 | |
| 68 | #if defined(SFML_FATAL_OPENGL_ERRORS) |
| 69 | assert(false && "OpenGL error (fatal OpenGL errors enabled)"); |
| 70 | #endif |
| 71 | |
| 72 | return false; |
| 73 | }; |
| 74 | |
| 75 | switch (glGetError()) |
| 76 | { |
| 77 | case GL_NO_ERROR: |
| 78 | return true; |
| 79 | |
| 80 | case GL_INVALID_ENUM: |
| 81 | return logError("GL_INVALID_ENUM", "An unacceptable value has been specified for an enumerated argument."); |
| 82 | |
| 83 | case GL_INVALID_VALUE: |
| 84 | return logError("GL_INVALID_VALUE", "A numeric argument is out of range."); |
| 85 | |
| 86 | case GL_INVALID_OPERATION: |
| 87 | return logError("GL_INVALID_OPERATION", "The specified operation is not allowed in the current state."); |
| 88 | |
| 89 | case GL_STACK_OVERFLOW: |
| 90 | return logError("GL_STACK_OVERFLOW", "This command would cause a stack overflow."); |
| 91 | |
| 92 | case GL_STACK_UNDERFLOW: |
| 93 | return logError("GL_STACK_UNDERFLOW", "This command would cause a stack underflow."); |
| 94 | |
| 95 | case GL_OUT_OF_MEMORY: |
| 96 | return logError("GL_OUT_OF_MEMORY", "There is not enough memory left to execute the command."); |
| 97 | |
| 98 | case GLEXT_GL_INVALID_FRAMEBUFFER_OPERATION: |
| 99 | return logError("GL_INVALID_FRAMEBUFFER_OPERATION", |
| 100 | "The object bound to FRAMEBUFFER_BINDING is not \"framebuffer complete\"."); |
| 101 |